2

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 Emu8086

With DosBox: Wtih DosBox

mov ax,0012h
int 10h

mov ah,9
mov al,31h
mov bl,1fh
int 10h
1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
  • @MichaelPetch Thanks for the reply, CX is non-zero in the emulator so it prints bunch of characters, but not with the background color i needed. It prints with black background. That problem only occurs in DosBox –  May 19 '19 at 16:25
  • @MichaelPetch No problem at all. I uploaded some screenshots for clearance sir. –  May 19 '19 at 16:34
  • 1
    First off are you intending to do this in graphics mode? (mode 12h is 16 color 640x480) (I suspect that EMU8086 is implementing things in a non standard way and DOSBox is handling it correctly). – Michael Petch May 19 '19 at 16:34
  • @MichaelPetch Yeah, i do intend to do this in 640x480 pixel graphics mode. I want to know if the problem is general or not. If it is, i have to do more research about DosBox, maybe i have to change something in DosBox's configuration files. –  May 19 '19 at 16:37
  • In graphics mode set the background color separately with int 10h/ah=0bh. But that will change the background color for the entire screen. – Michael Petch May 19 '19 at 16:53
  • @MichaelPetch That worked for my situation, thanks again for solving my problem. –  May 19 '19 at 17:04
  • 2
    You're not loading a character count into `cx` to set the number of characters to write. I think the attribute byte (`bl`) only applies to the character (foreground) in graphic modes and does not change the background for the character. `int 10h/ah=0bh` will set the background (pixel 0) color. – 1201ProgramAlarm May 19 '19 at 17:41
  • @1201ProgramAlarm So isn't there a register that change background color of a single character in graphics mode? –  May 19 '19 at 17:47

1 Answers1

3

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.

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
  • 2
    Regarding this statement _This is not possible in the graphics video modes_ . Some BIOSes in a time long gone would be smart enough to wrap the output (even in graphics) while others didn't. The issue is that you couldn't rely on a specific behaviour so you essentially had to assume that there was no wrapping. That ended up being a BIOS implementation behaviour. – Michael Petch May 19 '19 at 18:46