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.

C/C++ > Copying to VRAM and Datatypes

#6907 - einhaender - Wed Jun 04, 2003 1:50 pm

Iam lost with C datatypes. I have a code snipped that copies Background Palette, Tile Data and Map Data like this:

for(loop = 0; loop < 256; loop++) {
PalMem[loop] = Palette[loop];
}
for(loop = 0; loop < 160*69 / 2; loop++) {
bg2.tileData[loop] = Tiles[loop];
}
temp = (u16*)up_map;
for(loop = 0; loop < 32*8 / 2; loop++) {
bg2.mapData[loop] = temp[loop];
}

as described at gbajunkies and it works.
up_map is a u8 array and Tiles is a u16 array

Now iam using a different tool to create palette, map and tiles and the output has changed to up_map being a u16 and Tiles being a u8 array.
Whenever I use the exact same loops the Background looks broken, I guess the for loops has to be adapted, but how?

Another thing is, the "old" code works only if I use Rotation Background 2 in Mode 1, as soon as I wanna use another Rotation Background the Graphic looks broken too.

#6914 - Sweex - Wed Jun 04, 2003 2:46 pm

Assuming that Palette is the u16 array, try this:

u8* u8palette = (u8*) Palette;

Now use u8palette instead of Palette in your loops.

(Now hope that I got the syntax right as I often screw this up first time!)

#7015 - mpowell - Fri Jun 06, 2003 6:58 am

and remember that...

if you are reading or writing u8's, addresses go up by one each loop,
if you are reading or writing u16's, addresses go up by 2 each loop,
if you are reading or writing u32's, addresses go up by 4 each loop.

I forgot this and it took me 4 hours of debugging to remember that...

Addresses are always in bytes!