NivSlu
NivSlu

Reputation: 23

Assembly - Printing a char on graphical mode

I'm trying to print a character while on graphical mode. Usually when I print a character I'm doing:


mov ah,14   ; ah=14
mov al,'x' 
int 10h     ; print the character

This time it doesn't work. I guess that the problem is that I switch to graphical mode:


push ax
mov ah, 0
mov al, 13h
int 10h
pop ax
ret

So how can i still use graphical mode (i need it) and print a char? I'm using nasm compiler, bochs debugger, and 8086 platform.

Thanks alot!

Upvotes: 2

Views: 2884

Answers (2)

Margaret Bloom
Margaret Bloom

Reputation: 44046

Always have Ralf Brown Interrupt List handy.

The service int 10h/AH=0Eh requires the page number in BH and the color to use in BL.

This snippet works

mov ah, 0eh           ;0eh = 14
mov al, 'x'
xor bx, bx            ;Page number zero
mov bl, 0ch           ;Color is red
int 10h

In text mode the BL is not used, however in graphical mode it is.
Not properly setting it may end up writing "black on black".

Upvotes: 8

Ped7g
Ped7g

Reputation: 16596

You have to draw it (at least if you want to polish the look of it).

IIRC the BIOS or DOS interrupt actually was capable to print characters in gfx mode, but the font was ugly, and it did destroy other content around, so when I did need to print text in 13h mode, I had to do it on my own.

If you are new to this, start like this:

  1. create 6x8 bytes array with some picture ( *1 )
  2. draw it = create PutSprite(source, width=6, height=8, posx=10, posy=10) function
  3. create basic ASCII font in 6x8 256 color (or search internet for some asm font with fixed size)
  4. create your own "print" function calling the PutSprite with correct font glyph, and moving destination coordinates for each char.
  5. (optional) if you want to have proportional fonts, you have to store width of each glyph together with font graphics, and advance positions according to it
  6. (optional) extend PutSprite to check for transparency colour defined, for example as 255, so it will copy source byte only for non-transparent pixels.

*1) For the first step you can use some debug gfx like this (with default DOS palette):

testSprite:   ; testing gfx glyph, size 6x8 pixels for 13h mode
    times 6 db 15 ; white line at top
    times 6*6 db 2 ; dark green middle
    times 6 db 13 ; violet line at bottom

In second step you have to copy values from source address to 0xA000:320*posy+posx memory area, correctly advancing pointers: source++ after each byte copied, destination++ at single line (for width bytes), then destination+=320-width to advance to next line for height lines.

Upvotes: 0

Related Questions