【问题标题】:TASM 1.4 - Changing background color without clearing the screen?TASM 1.4 - 在不清除屏幕的情况下更改背景颜色?
【发布时间】:2015-12-13 16:01:57
【问题描述】:

我正在使用 Tasm 1.4。 我试图在不清除以前的文本的情况下更改背景和文本的颜色,但它总是以清除以前的文本而结束,尽管颜色已更改。

例如:

mov ah,09h
lea dx,text1
int 21h             ;displays text1
mov ah,01h
int 21h             ;I input a character
mov ah,06h
mov bh,42h
mov cx,0000h
mov dx,184fh
int 10h             ;I use this to change the text and background color
mov ah,02h
mov bh,00h
mov dh,0ch
mov dl,20h
int 10h             ;along with this
mov ah,09h
lea dx,text2
int 21h             ;displays text2
mov ah,02h
mov dl,al
int 21h             ;displays the inputted character

现在发生了什么......

  • 它显示文本1
  • 它要求输入
  • 我输入一个输入
  • 它会在输入字符后显示text2,背景颜色变为红色,文本颜色变为绿色。但是,text1 已从屏幕上清除。

我也应该说text1和text2绝对可以放在同一个屏幕上。

那么我如何获得相同的输出但 text1 没有从屏幕上清除?

【问题讨论】:

  • 嗨!谢谢。编辑。 :)
  • 你想用那个颜色清除整个屏幕吗?通过滚动,将会发生什么。但我不确定您希望输出是什么样的。
  • 嗨!谢谢。我实际上并不想用颜色清除整个屏幕,而是只更改背景和文本颜色而不清除屏幕。
  • 所以您真的只希望text2 中的内容后跟输入的字符以显示在新配色方案中。
  • @PeterCordes 正确,如果您看到int 21h,那么它肯定不是裸机(无操作系统),必须存在 DOS 或 DOS 仿真层。在仍支持 16 位代码的 32 位 Windows 环境中,您可以使用int 21h 和许多不会造成安全威胁的 BIOS 调用(读取硬盘的 BIOS 调用不会返回数据)。模拟 Windows NT(或更高版本)命令提示下的 BIOS 调用。 大多数 BIOS 调用在保护模式下不可用。 BIOS 调用不依赖于操作系统。

标签: assembly x86 dos tasm 16-bit


【解决方案1】:

直接写入显存即可。如果您处于 03h 模式,那么屏幕上有 80x25 个字符。每个字符都有 16 位与之关联。 8 位用于文本/背景颜色,另外 8 位用于显示的字符。

要显示的字符是第一个字节,属性是第二个字节。 您可以在此处找到内存组织和属性位的简要说明:http://www.shikadi.net/moddingwiki/B800_Text

这里有一些代码将保持文本内容不变,并且只会为 80x25 屏幕上的所有文本设置属性字节。这些天我使用 nasm,距离我上次使用 tasm 已经 15 年了 - 我不确定是否需要更改任何语法。

;********************************************************
; 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

【讨论】:

    猜你喜欢
    • 2022-10-13
    • 2021-02-07
    • 1970-01-01
    • 1970-01-01
    • 2019-11-15
    • 1970-01-01
    • 2010-11-12
    • 2014-09-22
    • 1970-01-01
    相关资源
    最近更新 更多