汇编语言改变字符的颜色
Assembly Language Changing Color Of Characters
这是一个基本的 DOSBox 程序,执行时会从左向右翻转屏幕。该程序运行良好。我遇到的唯一问题是我应该让所有非字母字符都是白底红字。更改非字母字符的颜色没有任何问题,但我不知道二进制红色与白色的组合。我以为是 11111100b 但这会使灰色变成红色,并且字符会闪烁。可能是非常简单的事情,但我无法弄清楚。有什么建议吗?
MyCode SEGMENT
ASSUME CS:MyCode, DS:MyData
MainProg PROC
MOV AX, MyData
MOV DS, AX
MOV AX, 0B800h
MOV ES, AX
MOV BX, (25 * 160) ;BX contains value that equals row 25, column 0
loop25:
SUB BX, 160 ;Selects next row
CALL flipRow ;Flips that row
CMP BX, 0 ;Have all rows been flipped?
JNE loop25 ;if not, repeat
MOV AH, 4Ch
INT 21h
MainProg ENDP
flipRow PROC ;PROC will flip each rown on verticle axis
MOV DI, BX ;Puts row, column 0 in DI
ADD DI, 158 ;Adds 158 to DI to select right most character
MOV SI, BX ;Puts row, column 0 in SI
loopRow: ;loop until row is finished flipping
MOV AX, ES: [DI] ;AX points to right most character
MOV CX, ES: [SI] ;CX points to left most character
MOV ES: [DI], CX ;Put left most character into right most place
;-------------------------------------------------------------------------
CMP CL, 65
JL thenPart
CMP CL, 91
JL next
CMP CL, 97
JL thenPart ;Is the character Alphebetic? If not, color red on white
CMP CL, 123
JL next
CMP CL, 122
JG next
thenPart:
MOV ES: [DI + 1], BYTE PTR 00FCh
next:
;-------------------------------------------------------------------------
MOV ES: [SI], AX ;Put right most character in left most place
;-------------------------------------------------------------------------
CMP AL, 66
JL then2
CMP AL, 91
JL next2
CMP AL, 97
JL then2 ;Is the character Alphabetic? If not, color red on white
CMP AL, 123
JL next2
CMP AL, 122
JG next2
then2:
MOV ES: [SI + 1], BYTE PTR 01111100b
next2:
;-------------------------------------------------------------------------
DEC DI
DEC DI ;Move in left
INC SI
INC SI ;Move in right
CMP SI, DI ;Is the row completely flipped?
JL loopRow ;If not, repeat
RET
flipRow ENDP
MyCode ENDS
设计此颜色系统的 CGA/EGA/VGA 屏幕适配器有两种不同的文本颜色模式。
在其默认模式下,前景颜色有一个 'bright' 位——第 3 位,其中 2-1-0 用于 RGB——但 'background' 中的相同位部分是 'blink'。所以实际上你不能有 'bright' 背景。
可以使用低级别视频中断更改默认设置:
AX = 1003h (operation code)
BL = 00h (enable bold background)
or BL = 01h (enable blinking)
INT 10h (execute operation)
(古老的记忆点动了 http://webpages.charter.net/danrollins/techhelp/0140.HTM 的 ctsy。)
这是一个基本的 DOSBox 程序,执行时会从左向右翻转屏幕。该程序运行良好。我遇到的唯一问题是我应该让所有非字母字符都是白底红字。更改非字母字符的颜色没有任何问题,但我不知道二进制红色与白色的组合。我以为是 11111100b 但这会使灰色变成红色,并且字符会闪烁。可能是非常简单的事情,但我无法弄清楚。有什么建议吗?
MyCode SEGMENT
ASSUME CS:MyCode, DS:MyData
MainProg PROC
MOV AX, MyData
MOV DS, AX
MOV AX, 0B800h
MOV ES, AX
MOV BX, (25 * 160) ;BX contains value that equals row 25, column 0
loop25:
SUB BX, 160 ;Selects next row
CALL flipRow ;Flips that row
CMP BX, 0 ;Have all rows been flipped?
JNE loop25 ;if not, repeat
MOV AH, 4Ch
INT 21h
MainProg ENDP
flipRow PROC ;PROC will flip each rown on verticle axis
MOV DI, BX ;Puts row, column 0 in DI
ADD DI, 158 ;Adds 158 to DI to select right most character
MOV SI, BX ;Puts row, column 0 in SI
loopRow: ;loop until row is finished flipping
MOV AX, ES: [DI] ;AX points to right most character
MOV CX, ES: [SI] ;CX points to left most character
MOV ES: [DI], CX ;Put left most character into right most place
;-------------------------------------------------------------------------
CMP CL, 65
JL thenPart
CMP CL, 91
JL next
CMP CL, 97
JL thenPart ;Is the character Alphebetic? If not, color red on white
CMP CL, 123
JL next
CMP CL, 122
JG next
thenPart:
MOV ES: [DI + 1], BYTE PTR 00FCh
next:
;-------------------------------------------------------------------------
MOV ES: [SI], AX ;Put right most character in left most place
;-------------------------------------------------------------------------
CMP AL, 66
JL then2
CMP AL, 91
JL next2
CMP AL, 97
JL then2 ;Is the character Alphabetic? If not, color red on white
CMP AL, 123
JL next2
CMP AL, 122
JG next2
then2:
MOV ES: [SI + 1], BYTE PTR 01111100b
next2:
;-------------------------------------------------------------------------
DEC DI
DEC DI ;Move in left
INC SI
INC SI ;Move in right
CMP SI, DI ;Is the row completely flipped?
JL loopRow ;If not, repeat
RET
flipRow ENDP
MyCode ENDS
设计此颜色系统的 CGA/EGA/VGA 屏幕适配器有两种不同的文本颜色模式。
在其默认模式下,前景颜色有一个 'bright' 位——第 3 位,其中 2-1-0 用于 RGB——但 'background' 中的相同位部分是 'blink'。所以实际上你不能有 'bright' 背景。
可以使用低级别视频中断更改默认设置:
AX = 1003h (operation code)
BL = 00h (enable bold background)
or BL = 01h (enable blinking)
INT 10h (execute operation)
(古老的记忆点动了 http://webpages.charter.net/danrollins/techhelp/0140.HTM 的 ctsy。)