I wrote my assembly code just to write a character with a blue background and white foreground. It works in emu8086's emulator but when I open it on DosBox it does not show the background color.
With Emu8086:
With DosBox:
mov ax,0012h
int 10h
mov ah,9
mov al,31h
mov bl,1fh
int 10h
In the graphics video modes, the BL
parameter for BIOS function 09h only defines the foreground color. It is always applied to a black background.
Below is my implementation of an extension of the functionality of this function. Now BL
holds an attribute (foreground color and background color) just like in the text video modes.
only valid in a graphics video mode
; IN (al,bl,cx) OUT ()
EnhancedWriteCharacterWithAttribute:
pusha
mov bh, 0 ;Display page 0
mov bp, bx
push ax
shr bl, 4 ;Get background color (high nibble)
mov ax, 09DBh ;ASCII DBh is full block character
int 10h ;BIOS.WriteCharacterAndAttribute
xor bx, bp ;Anticipate upcoming 'xor'
and bl, 15 ;Get foreground color (low nibble)
or bl, 128 ;Have BIOS 'xor' it
pop ax
int 10h ;BIOS.WriteCharacterAndAttribute
popa
ret
Use it like this:
mov ax, 0012h ; BIOS.SetVideo 640x480x16
int 10h
mov al, "1" ; Character
mov bl, 1Fh ; Attribute
mov cx, 80 ; Repetition count
call EnhancedWriteCharacterWithAttribute
Take note
In the text video modes providing a large repetition count in CX
can write the whole screen at once. This is not possible in the graphics video modes because BIOS will stop at the right edge of the screen.
You might want to read Displaying characters with DOS or BIOS for more on how to achieve your current and future goals.
来源:https://stackoverflow.com/questions/56209683/dosbox-how-to-fix-character-attribute