我正在做一个“乒乓游戏”,每次玩家得分时,我都会通过填充所需的颜色来清除屏幕,并再次绘制球员和球。下面是用于清除屏幕的代码:
mov ah,06h ;clear screen instruction
mov al,00h ;number of lines to scroll
mov bh,2 ;display attribute - colors
mov ch,0 ;start row
mov cl,0 ;start col
mov dh,24d ;end of row
mov dl,79d ;end of col
int 10h ;BIOS interrupt问题是我也在屏幕上打印分数。下面是设置文本颜色的代码:
mov ah,09 ; FUNCTION 9
mov bx,0004 ; PAGE 0, COLOR 4
int 10h ; INTERRUPT 10 -> BIOS以下是我如何加载文本:
mov ah,02h
mov dh,2 ;row
mov dl,16 ;column
int 10h
mov si, FirstPlayerScore
call printf
ret
printf:
lodsb
cmp al, 0
je finish
mov ah, 0eh
int 10h
jmp printf
finish:
ret那是结果。我想把分数的背景色改为绿色,而不是黑色。通过搜索,我发现我可以做这样的事情:
MOV BL,1EH ; Background = Blue, Foreground = Yellow但这并不能解决问题。我愿意接受任何暗示或答案。
发布于 2022-08-07 12:32:21
您没有指定您正在工作的视频模式,但从屏幕截图和代码片段中的数字数据判断,我得出的结论是,您正在80x25 16色文本屏幕上玩乒乓球。
BIOS函数,您说您使用“设置文本颜色”,根本不这样做!BIOS.WriteCharacterAndAttribute函数09h将字符和颜色属性(前景和背景)写入屏幕。因此,这对于您的目的来说是非常理想的,除了这个函数不会提前游标。但你自己也可以很容易做到。下面的简化代码假设字符串只属于屏幕上的一行,这在您的程序中是最有可能的。
mov dx, 0210h ; DH is Row=2, DL is Column=16
mov si, FirstPlayerScore
call printf
...
; IN (dx,si) OUT () MOD (ax,bx,cx,dx,si)
printf:
mov cx, 1 ; ReplicationCount=1
mov bx, 0024h ; BH is DisplayPage=0, BL is ColorAttribute=24h (RedOnGreen)
jmp .b
.a: mov ah, 02h ; BIOS.SetCursorPosition
int 10h
lodsb
mov ah, 09h ; BIOS.WriteCharacterAndAttribute
int 10h
inc dl ; Next column
.b: cmp byte [si], 0
jne .a
ret一种更普遍的方法允许输出字符串,这些字符串可以跨越屏幕上的几行,甚至允许滚动屏幕。我在用DOS或BIOS显示字符之前写的Q/A中提供了这样的代码。我鼓励您阅读所有这些内容,特别是研究标有WriteStringWithAttributeTVM的代码片段。TVM代表文本视频模式。
https://stackoverflow.com/questions/73261760
复制相似问题