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.

Graphics > loading map data into a text background

#65495 - christosterone - Tue Jan 03, 2006 6:06 pm

i have a map headerfile that holds data for a 256x256 map. when i load the data into a ROTBG, it looks fine. However, i want to use MODE0 so i need to use a TEXTBG.

heres the code for the map headerfile
Code:

const u8 map[ 32 * 32 ] = {
0x44,0x44,0x44, ..............};


here's the code for loading map data that works fine for the ROTBG but not for the TEXTBG.
Code:

   temp = (u16*)map;
   for(loop = 0; loop < 32*32/2; loop++)
         bg2.mapData[loop] = temp[loop];


if anybody could tell me what to do differently when loading mapdata for a TEXTBG that would be great.

thanks
chris

#65519 - Cearn - Tue Jan 03, 2006 8:01 pm

The reason it doesn't work is because rotational backgrounds are fundamentally different than text backgrounds. The former uses 8-bit data, while the latter uses 16-bit data for their screen entries.
By casting the source to a u16 pointer, you're filling the screenblock with 0x4444 in this case, which would work fine for rot bgs, but not for text bgs. As a simple solution: just scrap the cast and work from the map data directly. Note, this only works because the map array is in bytes.
Code:
for(loop = 0; loop < 32*32; loop++)
    bg2.mapData[loop] = map[loop];


Also, for what it's worth: don't keep map data (or any data or code) in header files. Don't use u16 for loop-variables, or indeed any variables unless you have to. Ints if you can, chars/shorts if you have to.

#65520 - christosterone - Tue Jan 03, 2006 8:15 pm

ahhh thanks so much. i got rid of the pointer and it runs swimmingly.

thanks
chris