Page 1 of 2

info about write to video memery needed

Posted: Sun May 22, 2005 6:35 am
by asmboozer
hi all,
in the baby step 5, the codes write to the 0xb800,

http://www.osdev.org/osfaq2/index.php/BabyStep5

is there any info about it? thanks

Re:info about write to video memery needed

Posted: Sun May 22, 2005 6:39 am
by AR
In 80x25 text mode, the video memory at 0xA0000 - 0xBFFFF (IIRC) can be written to to draw to the framebuffer. The text mode framebuffer is at 0xB8000.

Re:info about write to video memery needed

Posted: Sun May 22, 2005 7:03 am
by asmboozer
AR wrote: In 80x25 text mode, the video memory at 0xA0000 - 0xBFFFF (IIRC) can be written to to draw to the framebuffer. The text mode framebuffer is at 0xB8000.
what 's for 0xa0000-0xb7fff?

can you give me more details? thanks

Re:info about write to video memery needed

Posted: Sun May 22, 2005 7:23 am
by GLneo
mode 13h graphics (320x200x64 good for stater gui)

Code: Select all

xor ah, ah
mov al, 13h
int 10h

after that if you put data in that memory a pixel will apere acording to where and what number you put in ;)

Re:info about write to video memery needed

Posted: Sun May 22, 2005 7:36 am
by AR
"what's for" has no specific meaning in English, what are you talking about? Why is it there? How to use it? What is it?

Re:info about write to video memery needed

Posted: Sun May 22, 2005 3:30 pm
by Pype.Clicker
you should google for a tutorial on VGA programming. There are plenty of them in various game-developing website.

Re:info about write to video memery needed

Posted: Mon May 23, 2005 5:20 am
by bubach
It's 320x200x256 for mode 0x13.. Not 64 colors. :P

Re:info about write to video memery needed

Posted: Mon May 23, 2005 1:11 pm
by viral
Hey I have a prob writing in frame buffer for 640x480x16 mode. Frame buffer starting address is 0xA0000 but i dont know how to write in it to glow a pixel?

I have used int 10h in BootLoader to initialize graphics.

Re:info about write to video memery needed

Posted: Mon May 23, 2005 2:45 pm
by GLneo
unsigned char *VGA = (unsigned char *)0x0A0000;
void pixel(int x, int y, unsigned char color)
{
VGA[ ( y * 640 ) + x ] = color;
}

P.S. (VGA[(y<<8)+(y<<6)+x] = color;) is much faster 8)

Re:info about write to video memery needed

Posted: Mon May 23, 2005 6:38 pm
by Brendan
Hi,
GLneo wrote:VGA[ ( y * 640 ) + x ] = color;
That won't work for 16 colour modes (e.g. 640*480*16 colour, which is standard VGA mode 12).

In these modes you've got 4 bits per pixel, where each bit is seperated and placed into one of 4 bit planes.

In this case (starting from a black screen), "VGA[0 ] = 0xFFFF" could result in 16 pixels at the top left of the screen, which would be either blue, green, red or dark grey depending on which plane was selected.

Drawing a single pixel is a complex and slow operation. The general idea goes like this:

Code: Select all

unsigned char *VGA = (unsigned char *)0x0A0000;

void pixel(int x, int y, unsigned char color)
{
    bit = 7 - ((x + y * 64) & 7);
    bit_mask = 0xFF - (0x01 << bit);
    plane_offset = (x + y * 64) >> 3;

    select_plane(0);
    data = VGA[plane_offset] & bit_mask;
    VGA[plane_offset] = data | ((color & 1) << bit);

    select_plane(1);
    data = VGA[plane_offset] & bit_mask;
    VGA[plane_offset] = data | ((color & 2) << bit);

    select_plane(2);
    data = VGA[plane_offset] & bit_mask;
    VGA[plane_offset] = data | ((color & 4) << bit);

    select_plane(3);
    data = VGA[plane_offset] & bit_mask;
    VGA[plane_offset] = data | ((color & 8) << bit);
}
The "select_plane()" function writes to a VGA IO port to select which plane is being operated on. I can't remember the exact details (I'll have a look when I get home).

This isn't the only way it can be done - in the video card there's about 4 different IO ports that control how reads/writes to video memory behave, with a few different masks and things to make it more confusing :).

Regardless of how it's done it's slow. For this reason I use double buffering so that I can draw each pixel into a memory buffer and then blast the 4 planes to the video card using 4 "rep stosw" instructions, each preceded by the "select_plane()" corresponding to the plane. This can be improved (depending on what your drawing) by keeping track of which planes are "dirty" so that if you add some blue pixels you only need to update the blue plane, or if you're using white text on a green background you don't have to change the green plane.


Cheers,

Brendan

Re:info about write to video memery needed

Posted: Tue May 24, 2005 4:41 am
by Candy
GLneo wrote: unsigned char *VGA = (unsigned char *)0x0A0000;
void pixel(int x, int y, unsigned char color)
{
VGA[ ( y * 640 ) + x ] = color;
}

P.S. (VGA[(y<<8)+(y<<6)+x] = color;) is much faster 8)
It is not in any way faster, any form of decent compiler will rewrite that for you.

Re:info about write to video memery needed

Posted: Tue May 24, 2005 7:26 am
by GLneo
the bottom of:
www.brackeen.com/home/vga/basics.html
says it is faster but i've never seen a difference :)

Re:info about write to video memery needed

Posted: Tue May 24, 2005 7:47 am
by bubach
Any C compiler that passed it's 0.01 release can do that optimization.. :P
Maybe he's talking about using it in asm instead of "mul"?

Re:info about write to video memery needed

Posted: Tue May 24, 2005 8:10 am
by whyme_t
Here is what GCC give me:

Code: Select all

with: VGA[(y*640)+x] = color;
<pixel1>:
<snip>
shl    $0x2,%eax
add    %edx,%eax
shl    $0x7,%eax
add    0x8(%ebp),%eax
</snip>
leave
ret

Code: Select all

with: VGA[(y<<8)+(y<<6)+x] = color;
<pixel2>:
<snip>
shl    $0x8,%edx
mov    0xc(%ebp),%eax
shl    $0x6,%eax
lea    (%eax,%edx,1),%eax
add    0x8(%ebp),%eax
</snip>
leave
ret
Seems to me the compiler does a better job optimising the original code!

Re:info about write to video memery needed

Posted: Tue May 24, 2005 8:16 am
by GLneo
wow, i did not know that, and all that time i spent optimizing might be making things slower, mabey i should trust gcc optimizers on simple things, thx :)