gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Video Memory

#73526 - gustav05 - Sun Feb 26, 2006 9:38 am

Hello!

I have a question.

In the header file "gba.h" there are 2 constants defined:
#define VideoBuffer ((u16*)0x6000000)
#define FrontBuffer ((u16*)0x6000000)
Both are pointers, which points to the video memory, the VRAM.
Is there any difference between these 2 pointers?
And it is correct, that the VRAM begins at 0x6000000?
Is FrontBuffer and VideoBuffer only a pointer or a pointer-array?

I hope you can help me.
Thanks.

#73547 - strager - Sun Feb 26, 2006 4:04 pm

The reason there are two pointers is because one is supposed to be used with modes 0, 1, and 2, while the other is meant to be used with 3, 4, and 5. Since the latter three modes are bitmap modes, they use the video buffer concept. Mode 3 only has one buffer, so it would make sense to use the FrontBuffer define. On the others, the name could be misleading; they merely define the two buffers, and not which one is currently active. More accurate names would be "VideoBuffer1" and "VideoBuffer2", but that's besides the point. :P
So, if you choose to use the last three modes, using the FrontBuffer and BackBuffer defines would work best.

Here's how to reference them:
Code:

void putpixel_back(int x, int y, u16 color)
{
    u16 *address = &FrontBuffer[x + (y * SCREEN_WIDTH)];

    if(!REG_DISPCNT & FRAME_SELECT)
    {
        address += 0xA000;
    }

    *address = color;
}


Hope that helps.