News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Writing in Graphics Mode

Started by amrac, December 30, 2009, 05:05:46 PM

Previous topic - Next topic

amrac

I´m writing a program in 320x200 graphics color mode. I´m new in this kind of environment and I don't know how to write text into the screen. Is it with int 21th with ah equal to 09h? I would appreciate if someone could give me detailed information.

dedndave

int 21h ah=2 (single character) and ah=9 ($-terminated string) should work in 320x200
the characters will be large, is all (40x25)

Ralf Brown's Interrupt List
http://www.masm32.com/board/index.php?topic=12926.msg100104#msg100104

amrac

I've tried int 21h with ah equal to 9h but what I don´t know is how to control the position of the letters on the screen. An how can I make the letters smaller?

dedndave

use INT 10h to position the cursor, then display the text

        MOV     DX,0       ;256 * row + column (0,0 = upper left corner)
        MOV     BH,0
        MOV     AH,2
        INT     10h

as for making the font smaller in 320 x 200 graphics modes, you can create your own font and place pixels to display text
as i recall, i used to use an 8x5 font that was fairly ledgible - you can go as small as 5x5

amrac

Thank you for your reply. I get a strange result. The letters are too big. My string is terminated by the $ character but starts by enumerous strange characters. If there was some code that I could introduce that would alter the letters size. I'm not interested in creating my own font.

dedndave

well - in 320x200 graphics modes, the text is big - that's all there is to it
the reason is, with the original CGA graphics adapter, IBM wanted it to be legible on a TV set
if you want graphics and text together, that is what you got back then - lol

there are alternatives
1) if 2 colors is enough, try using the 640x200 graphics mode
2) use one of the newer VGA graphics modes
DOS programs that write directly to the video buffer are a bit more involved in these modes
you could, however, use the BIOS set pixel function
it sounds like that might work fine for you, as you are not drawing full-screen graphics (speed shouldn't be a problem)
they have several modes - 640x480 16-color or 256-color modes would probably be adequate
640x480 is nice because pixels are "square" - they are small, though - you may want to draw 4 pixels to make a dot

amrac

I have  two different codes. The first one works and the second one doesn't. Can anyone explain why?
First code:
I have the variable initialized in the data segment:

frase1 db 'CARMA ','$'

And  then in the code segment:

push ax
      push bx
      push bx
      push dx
      sub bx,bx
      MOV     DX,0       
        MOV     BH,0
        MOV     AH,2
        INT     10h
      lea dx,frase1         ;coloca mensagem
      mov ah,09h            ;inicialização de parâmetro de interrupção
      int 21h               ;interrupção que envia frase para o ecran
      pop dx
      pop bx
      pop bx
      pop ax

I get the message "CARMA on the screen.

Second code:
In the data segment:

buffer db 5 dup(' '),'$'

And in the code segment:

push ax
      push bx
      push bx
      push dx
      sub bx,bx
      mov dx, caught_balls
      mov buffer[bx],dl
      ;por a mensagem no ecran
      MOV     DX,0       
        MOV     BH,0
        MOV     AH,2
        INT     10h
      lea dx,buffer         ;coloca mensagem
      mov ah,09h            ;inicialização de parâmetro de interrupção
      int 21h               ;interrupção que envia frase para o ecran
      pop dx
      pop bx
      pop bx
      pop ax

caught_balls is initialized with the value 0h.

dedndave

you want to convert the binary value "number of balls caught" into an ASCII numeric digit
it may be more than one digit, too, eventually
in fact, you may want the value to be as large as 65535 (the value in DX)
that means you want to convert it into an ASCII numeric string
remember, the values in registers are usually raw binary values
at the end of the string, you want a "$" character to terminate it for the INT 21h, AH=9 function

a couple other notes:
i see you have pushed and poped the BX value twice - did you mean to push/pop CX ?
instead of LEA DX,frase1, use MOV DX,offset frase1
instead of LEA DX,buffer, use MOV DX,offset buffer

dedndave

ok - i cleaned the file up, AGAIN
please use this one - i don't want to clean it up again

amrac

#9
I'm sorry but my teacher preferes that I use the other version. I'm sorry for all your trouble. Thank you once again for all your work. I use that buffer because that way I can put two values, caught_balls and left_balls separated by a "|". I've converted the value to ascii (I guess you just have to add 30h).

dedndave

well - if it is an unsigned byte value (i.e. from 0 to 255), it may have up to 3 ASCII digits
the string "255" is 3 bytes long - if you add the "$" terminator, it is 4 bytes
now, if they catch 9 balls and advance to the next level, your problems are solved - lol
but, i am guessing you want to display larger values
in fact, you may want to display values larger than 255 - i don't know