TASM 1.4 - 显示特定颜色的字符串?

xTa*_*Tan 5 assembly text colors tasm x86-16

我正在使用 TASM 1.4,我正在尝试制作一个输出,该输出将在同一屏幕上显示不同颜色的句子。我可以制作一些显示彩色文本的东西,但所有单词都具有相同的颜色。如何制作显示不同颜色的字符串/句子的东西?例如,类似:

Hi, what group would you like to join?
The Founders
The Vox Populi
Run Code Online (Sandbox Code Playgroud)

“嗨,您想加入哪个小组?” 颜色为绿色。“创始人”的颜色是蓝色。“The Vox Populi”被涂成红色,也许我想要另一个闪烁的句子?我只能将它们全部显示为蓝色、红色或绿色。有什么帮助吗?谢谢。

rkh*_*khb 5

INT 10h / AH=13h您可以为此目的使用:

.MODEL small
.STACK 1000h

.DATA
    msg1 db "Hi, what group would you like to join?", 13, 10
    msg1_len = $ - msg1
    msg2 db "The Founders", 13, 10
    msg2_len = $ - msg2
    msg3 db "The Vox Populi", 13, 10
    msg3_len = $ - msg3
    msg4 db "Blinkers", 13, 10
    msg4_len = $ - msg4

.CODE

main PROC
    mov ax, @data
    mov ds, ax              ; Don't forget to initialize DS!
    mov es, ax              ; Segment needed for Int 10h/AH=13h

    lea bp, msg1            ; ES:BP = Far pointer to string
    mov cx, msg1_len        ; CX = Length of string
    mov bl, 2               ; green (http://stackoverflow.com/q/12556973/3512216)
    call print

    lea bp, msg2            ; ES:BP = Far pointer to string
    mov cx, msg2_len        ; CX = Length of string
    mov bl, 3               ; blue (http://stackoverflow.com/q/12556973/3512216)
    call print

    lea bp, msg3            ; ES:BP = Far pointer to string
    mov cx, msg3_len        ; CX = Length of string
    mov bl, 4               ; red (http://stackoverflow.com/q/12556973/3512216)
    call print

    lea bp, msg4            ; ES:BP = Far pointer to string
    mov cx, msg4_len        ; CX = Length of string
    mov bl, 8Eh             ; blinking yellow (Bit7 set, works at least in DOSBox)
    call print

    mov ax, 4C00h           ; Return 0
    int 21h
main ENDP

print PROC                  ; Arguments:
                            ;   ES:BP   Pointer to string
                            ;   CX      Length of string
                            ;   BL      Attribute (color)

    ; http://www.ctyme.com/intr/rb-0088.htm
    push cx                 ; Save CX (needed for Int 10h/AH=13h below)
    mov ah, 03h             ; VIDEO - GET CURSOR POSITION AND SIZE
    xor bh, bh              ; Page 0
    int 10h                 ; Call Video-BIOS => DX is current cursor position
    pop cx                  ; Restore CX

    ; http://www.ctyme.com/intr/rb-0210.htm
    mov ah, 13h             ; VIDEO - WRITE STRING (AT and later,EGA)
    mov al, 1               ; Mode 1: move cursor
    xor bh, bh              ; Page 0
    int 10h                 ; Call Video-BIOS

    ret
print ENDP

END main
Run Code Online (Sandbox Code Playgroud)