TASM 1.4 - Changing background color without clearing the screen?

↘锁芯ラ 提交于 2019-12-01 11:41:07

Just write to the video memory directly and be done with it. If you're in mode 03h, then you've got 80x25 chars on screen. Each char has 16bits associated with it. 8 bits for text/background colour and another 8 for the character displayed.

The character to display is the first byte and the attributes are the second byte. You can find a brief description of the memory organization and attribute bits here: http://www.shikadi.net/moddingwiki/B800_Text

Here's some code that will leave the text content unchanged and will just set the attribute byte for all text on an 80x25 screen. I use nasm these days, it's been 15 years since I last used tasm - I'm not sure if any of the syntax will need changing.

;********************************************************
; Sets the text-mode attributes for the whole 80x25 screen
; call  with AL = attribute (hi nibble = background, lo-nibble = foreground)
;********************************************************
setTextAttributes:
    push    es              ; save the seg register
    mov     cx, 80*25       ; # of chars to do
    mov     bx, 0xB800      ; segment of the screen memory for this video mode
    mov     es, bx
    xor     di, di          ; point to char data of screen-pos 0,0
.setTextAttributesLoop:
    inc     di              ; advance by 1 to point to the attribute, rather than the char
    stosb                   ; store our attribute byte to [es:di] and increment di. di now points to a character
    loop    .setTextAttributesLoop
    pop     es
    ret
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!