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 > address question~

#25518 - black - Tue Aug 24, 2004 10:38 am

hi all~

i followed the tuto which draw certain color onto screen with macro named FontBuffer like this:
Code:

#define FrontBuffer     ((u16*)0x6000000)

for(x=0; x<(240*160); x++)
{
    FrontBuffer[x]=RGB(31, 0, 0);
}

my question comes, is the address 0x6000000 fixed to be the beginning when drawing the screen ? can we start drawing the screen from other adress point ?
_________________
Never end on learning~

#25519 - black - Tue Aug 24, 2004 10:55 am

oh i got it, 0x6000000 is the magic number we can not beyond, but somethin strange is FrontBuffer[1] points to 0x6000002 not 0x6000001 ?
_________________
Never end on learning~

#25521 - Krakken - Tue Aug 24, 2004 12:15 pm

It's because the memory is written in 16-bit values.
16-bits is 2 bytes. The memory in your case refers to the memory by bytes so to get to the next one you increment by 16-bits (2 bytes).

#25539 - sajiimori - Tue Aug 24, 2004 6:05 pm

It's not related to the memory itself, but rather the pointer type. Recall that array[index] is shorthand for *(array + index). The way pointer math works is: when you add or subtract from a pointer, it moves in increments of the size of the object it points to. Your pointer points to objects that are 2 bytes in size, because it's a u16*.

Just imagine if C wasn't like that. Then if you had an array:
Code:
int array[20];
You would have to be careful about typing things like this:
Code:
x = array[2];
If C moved in increments of bytes rather than the size of an int, you wouldn't get the 3rd int -- you'd land in between the first one and the second one, which doesn't make much sense.

#25560 - black - Wed Aug 25, 2004 4:10 am

[quote="sajiimori"]It's not related to the memory itself, but rather the pointer type. Recall that array[index] is shorthand for *(array + index). The way pointer math works is: when you add or subtract from a pointer, it moves in increments of the size of the object it points to. Your pointer points to objects that are 2 bytes in size, because it's a u16*.
quote]

thanx, since the reason is u16 pointer, can we write graphic to screen with u8 pointer instead ? ie if possible, what's the difference between FrontBuffer be implemented u16 and u8 pointer when drawing the screen ?
_________________
Never end on learning~

#25563 - dagamer34 - Wed Aug 25, 2004 4:24 am

[quote="black"]
sajiimori wrote:
It's not related to the memory itself, but rather the pointer type. Recall that array[index] is shorthand for *(array + index). The way pointer math works is: when you add or subtract from a pointer, it moves in increments of the size of the object it points to. Your pointer points to objects that are 2 bytes in size, because it's a u16*.
quote]

thanx, since the reason is u16 pointer, can we write graphic to screen with u8 pointer instead ? ie if possible, what's the difference between FrontBuffer be implemented u16 and u8 pointer when drawing the screen ?


Nope. The memory controller on the GBA doesn't allow 8-bit writes to VRAM. Trust me, lots of people have asked about it. :)
_________________
Little kids and Playstation 2's don't mix. :(