Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

putpixel via memory in mode 13h

Status
Not open for further replies.

kismetlafiete

Programmer
Oct 13, 2004
8
US
So, I can get into mode 13h and use BIOS interrupts to handle drawing pixels, but it seems to be pretty slow. After doing a bit of internet research, I have read that it would be faster to do it in memory by using the equation

"Mem [VGA:X+(Y*320)]=Color;
where VGA is the starting point $a000, the base of the VGA's
memory"

so, how do I do this in assembly, assuming the calculation for x+y*320 has already been performed and the result stored in some arbitrary register, say bx.


According to my textbook, something like this should be as simple as storing a000h in ES (a000 is the segment I need, correct?), then doing something like
mov[es:bx], color

I can't get this to work correctly though, so what am I doing wrong?
I am using NASM, if that helps any.
 
This is a nice one :)

Once you have set video mode to 13h, the video memory starts at address A000:0000 and it extends for 64000 addresses to the A000:F7FF. ( Remember that in DOS, memory is segmented so you have to use segment register, which is a bit tricky)

So rule 1: check that the address that you want to change is between the range described above

rule 2: Now effectively the equation you have allow you to change a pixel value (or color) regarding its coordinates, because the screen is set to a 320x200 pixels, you have to add x+y*320 to base address A000:0000, in order to change the pixel you have selected.

assuming everything try the following:
Code:
     mov es, 0A000h    ; segment address 0A000h
     mov di, 640       ; 2*320 second row
     add di, 160       ; column 160
     mov al, 1         ; load colour in registry
     mov es:[di], al   ; change colour of the pixel
                       ; change di value
                       ; for more pixels
     ;example
     inc di            ; next pixel
     mov al, 2         ; different colour
     mov es:[di], al   ; change colour of other pixel
     .
     .

Hope this helps,

Rick
 
Got it to work, thanks!

Now, if I can only figure out page-flipping in asm :)
 
Shouldn't the first line be:
Code:
mov ax, 0A000h
mov es, ax
I thought that you couldn't load a value directly into a segment register without placing the value in another register first?
 
Yes, you are correct... here is the working code for drawing a pixel (assembler used was NASM):

[ORG 0100h] ; set code start at 100h (COM file)

[SECTION .text] ; code section follows

START:

mov ax,13h ; move the number of the mode to ax
int 10h ; and enter the mode using int 10h

mov ax,0a000h; you cant move a value directly to es
mov es,ax ; move the screenadress to es

putpixel:
mov bx,[y]
imul bx,320
add bx,[x]
mov di,bx; and the calculated offset to di
mov al,50 ; and the colorbyte to al
mov [es:di],al; finally move the pixel to the screen

quit:
mov ah,0 ;readkey
int 22 ;call BIOS for readkey
mov ah,00 ;setting up ax to go back to text
mov al,03
int 10h ;put us back in text mode!
mov ax, 04c00h ;get ready to give control to DOS
int 33 ;call to DOS

[SECTION .data]

x dd 160
y dd 100


What I really need now is to figure out double-buffering to kill the flicker in my program. I understand the concept behind it, but how can I put my buffer in memory? I have never needed to use anything other than double-word or word sized variables, so how do I declare a section of memory that is 64k bytes large?
 
Yes, there is a way to change start address to a second memory page instead of A000:0000, lets say A000:F800, and switching between these two memory spaces.
Michael Abrash´s Black Book have useful information about how to do that and many things more. There is a second edition available and also there are a few links around the web pointing to online copies of the first edition. Personally i recommend you to buy the book, because is still a great reference an a must to every decent assembly programmer, but feel free to use the online copy, there are several links in this forum,

regards,

Rick
 
Can I underline how good the black book is if you want to pursue this. 256-colour modes are simple compared to the 16-colour modes, and if you ever want to use them, Abrash is superb. It's also worth it on general efficient assembler programming.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top