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.

Beginners > Problem with 512x512 background

#25628 - ChronoDK - Thu Aug 26, 2004 8:22 am

I'm having some trouble getting 512x512 text backgrounds working. I know about the special layout, and have written code that copies a 512x256 map. But somehow my code just won't work with 512x512 backgrounds.

Code:

void DrawMap512x512(const unsigned short* source, unsigned short* dest)
{
   short row, tile;

   for(row = 0; row < 32; row++)
   {
      for(tile = 0; tile < 32; tile++)
      {
         dest[0 + tile + (row << 5)] = source[(tile + 0) + (row << 6)];
         dest[1024 + tile + (row << 5)] = source[(tile + 32) + (row << 6)];
      }
   }

   for(row = 32; row < 64; row++)
   {
      for(tile = 0; tile < 32; tile++)
      {
         dest[2048 + tile + (row << 5)] = source[(tile + 0) + (row << 6)];
         dest[3072 + tile + (row << 5)] = source[(tile + 32) + (row << 6)];
      }
   }
}


Without the last loop it can copy 512x256 maps, but I can't get 512x512 maps to work.

I just get the first tile of the charbase repeated all over the screen.

There is 7552 bytes of 256-color tiles in charbase 3, and the map starts at screenbase 28. So that should not be the problem right?


Last edited by ChronoDK on Thu Aug 26, 2004 1:50 pm; edited 1 time in total

#25635 - FireOut - Thu Aug 26, 2004 12:14 pm

512x512 backgrounds can be confusing :) Like most other technical gba questions, the answer can be found in the CowBite Spec:

Quote:

For 256 x 256 and 256 x 512 backgrounds, the formula for calculating a map index is roughly,

mapEntry = tileMapAddress[(tileY * 32) + tileX]

For text mode sizes 512 x 256 and 512 x 512 backgrounds, however, the map is 64 tiles across, and these are stored in blocks of 32 * 32 tiles. This means that to calculate the map entry that would appear 33 tiles or more across the background, the following equation should be used:

mapEntry = tileMap[(tileY * 32) + (tileX - 32) + 32*32]

For entries 33 tiles or more down (in mode 11), use

mapEntry = tileMap[( (tileY-32) * 32) + tileX + 2*32*32];

And for entries 33 tiles or more down and 33 tiles or more across,

mapEntry = tileMap[( (tileY-32) * 32) + (tileX-32) + 3*32*32];


Good luck ;)

#25639 - ChronoDK - Thu Aug 26, 2004 1:47 pm

Thanks, but that didn't help - I think I'm doing it exactly as CowBite tells me to, but it just won't work.

I might need someone to tell what exactly is wrong with my code :-)

#25649 - sajiimori - Thu Aug 26, 2004 5:04 pm

Try putting one tile at the top left corner of each 256x256 area. Calculate (by hand) the correct source and destination addresses, then use VBA's console print function (see its FAQ) to see if you are getting what you expected. Alternatively, compile a similar function natively and use printf.

It's better to learn how to debug these sorts of problems now, because they certainly don't stop appearing when you move to more advanced material.

Edit: Char block 3 and screen block 28 overlap, so be careful. I'd suggest dedicating char block 0 to screen maps, so there's no chance of overlap. Also make sure you don't have other bg layers enabled that are covering the one you want to see.

#25653 - ChronoDK - Thu Aug 26, 2004 6:18 pm

Yeah, I know they overlap - but with a little care this is the way I get most out of the blocks.

I fixed the code - turns out the biggest mistake was somewhere else, but just to get the code on the board, this is working for me now:

Code:

void DrawMap512x512(const unsigned short* source, unsigned short* dest)
{
   short row, tile;

   for(row = 0; row < 32; row++)
   {
      for(tile = 0; tile < 32; tile++)
      {
         dest[0 + tile + (row << 5)] = source[tile + 0 + (row << 6)];
         dest[1024 + tile + (row << 5)] = source[tile + 32 + (row << 6)];
      }
   }

   for(row = 0; row < 32; row++)
   {
      for(tile = 0; tile < 32; tile++)
      {
         dest[2048 + tile + (row << 5)] = source[tile + 2048 + (row << 6)];
         dest[3072 + tile + (row << 5)] = source[tile + 2080 + (row << 6)];
      }
   }
}