Page 1 of 1

Ummm...it is supposed to be like that?

Posted: Wed Mar 02, 2011 11:50 pm
by wannabedeveloper
I recently found a script online that writes to video memory.

Code: Select all

    mov ax,013h    ;VGA mode
    int 10h        ;640 x 480 16 colors.
    mov ax,0A000h
    mov es,ax      ;ES points to the video memory.
    mov dx,03C4h   ;dx = indexregister
    mov ax,0102h   ;INDEX = MASK MAP, 
    out dx,ax      ;write all the bitplanes.
    mov di,0       ;DI pointer in the video memory.
    mov cx,38400   ;(640 * 480)/8 = 38400
    mov ax,0FFh    ;write to every pixel.
    rep stosb      ;fill the screen
    mov ah,4ch     ;go back
    int 21h        ;         to DOS
While most of the stuff is a little confusing since I've just started learning NASM, what I don't get is when I launch a binary COM file of this data I'll get a blue screen with weird blotchy discolored rectangular patches all over the screen. How can I fix this?

As a side note, what are the possible results of messing with video memory/video drive?

Re: Ummm...it is supposed to be like that?

Posted: Thu Mar 03, 2011 12:44 am
by Brendan
Hi,

Here's some information about Int 0x10, ah = 0x00. Notice how mode 0x13 (the mode you ask for) isn't 640 * 480 with 16 colors?

For 640 * 480 with 16 colors, you'd need access to a minimum of 153600 bytes of video display memory. The area from 0x000A0000 to 0x000AFFFF is only 65536 bytes, and isn't big enough. To get around that, for 16 colour modes they arrange display memory as 4 separate "planes". To access these planes, there's different read modes and write modes. I'm not too sure how you've setup the "write mode" exactly (too lazy to look it up), but the point is, you're not using a 16 colour mode (you are using a 256-colour mode which works in an entirely different way) and therefore you shouldn't be messing with the "write mode" to begin with.

Then you attempt to write 38400 bytes, but because you're not using 640*480 with 16 colors (and you are using something else), 38400 wouldn't be enough to cover the entire screen.
wannabedeveloper wrote:I recently found a script online that writes to video memory.
It's not a script. It's assembly language source code.
wannabedeveloper wrote:As a side note, what are the possible results of messing with video memory/video drive?
If you're not careful, you might get a blue screen with weird blotchy discolored rectangular patches all over the screen... ;)


Cheers,

Brendan

Re: Ummm...it is supposed to be like that?

Posted: Thu Mar 03, 2011 11:33 am
by wannabedeveloper
Brendan wrote:Hi,

Here's some information about Int 0x10, ah = 0x00. Notice how mode 0x13 (the mode you ask for) isn't 640 * 480 with 16 colors?

For 640 * 480 with 16 colors, you'd need access to a minimum of 153600 bytes of video display memory. The area from 0x000A0000 to 0x000AFFFF is only 65536 bytes, and isn't big enough. To get around that, for 16 colour modes they arrange display memory as 4 separate "planes". To access these planes, there's different read modes and write modes. I'm not too sure how you've setup the "write mode" exactly (too lazy to look it up), but the point is, you're not using a 16 colour mode (you are using a 256-colour mode which works in an entirely different way) and therefore you shouldn't be messing with the "write mode" to begin with.

Then you attempt to write 38400 bytes, but because you're not using 640*480 with 16 colors (and you are using something else), 38400 wouldn't be enough to cover the entire screen.
wannabedeveloper wrote:I recently found a script online that writes to video memory.
It's not a script. It's assembly language source code.
wannabedeveloper wrote:As a side note, what are the possible results of messing with video memory/video drive?
If you're not careful, you might get a blue screen with weird blotchy discolored rectangular patches all over the screen... ;)


Cheers,

Brendan
Alright, actually that's what happens (though I can change the color), but I can fix it by quitting the COM program and pressing the windows key. Where can I go for more information? Great info though, thanks!

Re: Ummm...it is supposed to be like that?

Posted: Thu Mar 03, 2011 12:26 pm
by Combuster
Where can I go for more information?
Google?