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 > Loading 512x256 Text BG Problem

#31617 - Celeryface - Mon Dec 13, 2004 2:54 am

Hey there,

I'm loading in a text bg of 512x256 in Mode 0 in CharBlockBase 0 and ScreenBlockBase 28. I use the following code to load in the map data, tiles and palette.

Code:

DMAFastCopy( (void*)menubg_pal_Palette, (void*)BGPaletteMem, 256, DMA_16NOW );

// Copy the tile images into the tile memory.
DMAFastCopy( (void*)menubg_Tiles, (void*)CharBaseBlock(0), 13248/4, DMA_32NOW );


for( loopY = 0; loopY < 32; loopY++ )
{

        for( loopX = 0; loopX < 64; loopX++ )
        {

            bg0map[n16++] = menubg_Map[(loopY * 32) + (loopX - 32) + 32*32];

        } // end for loopX

} // end for loopY



The map shows up in the map viewer with all the tiles filled in (64x32), but the map data doesn't look how it's suppose to. Can anyone spot where I'm going wrong in my code?

Thanks in advance. :)

#31620 - DekuTree64 - Mon Dec 13, 2004 3:54 am

I don't quite understand why you're adding (xLoop-32) + 32*32 to the source map, instead of just xLoop, but I think your problem is that xLoop goes from 0 to 64. The larger screens are layed out kind of funny, split into 256x256 blocks, so they're always 32 tiles wide, even for the larger screens.
For a 512x256, you have basically 2 regular 256x256 screens side by side. Instead of copying 64 tiles across, you copy the left 32 tiles of your source map into one block, and the right 32 into the next block.
In code, something like this:

Code:
   // Left 32 tiles to screen block 28
for(y = 0; y < 32; y++)
{
   for(x = 0; x < 32; x++)
   {
      bg0map[y*32 + x] = menubg_Map[y*64 + x];
   }
}

   // Right 32 tiles to screen block 29 (+32*32 tiles)
for(y = 0; y < 32; y++)
{
   for(x = 0; x < 32; x++)
   {
      bg0map[y*32 + x + 32*32] = menubg_Map[y*64 + (x+32)];
   }
}

_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#31643 - Celeryface - Mon Dec 13, 2004 12:35 pm

Thanks a lot, that worked! :)

I referred to the CowBite formula for 512x256 background loading but wasn't too sure how to implement it. Now I see how it's done. Thanks again :)

#31645 - Celeryface - Mon Dec 13, 2004 2:04 pm

Now that I have that background loaded, I want to load another background into BG1 -- a 256x256 background.

So far I can't get both backgrounds loaded in at the same time, as I think I'm putting in too much tile data. Can you guys spot or suggest what I can do to fix this problem?

Code:

DMAFastCopy( (void*)bgs_pal_Palette, (void*)BGPaletteMem, 256, DMA_16NOW );

// Copy the tile data into the tile memory.
DMAFastCopy( (void*)menubg_Tiles, (void*)CharBaseBlock(0), 13248/4, DMA_32NOW );

// Copy the map data into background 0.
Load512x256_TextBG(menubg_Map, bg0map);
   
// Load the game background into background 1.
   
// Copy the tile data into the tile memory.
DMAFastCopy( (void*)gamebg_Tiles, (void*)CharBaseBlock(1), 44096/4, DMA_32NOW );
   
    // Copy the map data into background 1.
    Load256x256_TextBG( gamebg_Map, bg1map );


So far only 1 background will display properly. Am I loading the tiles to the wrong CharBaseBlocks, or am I loading too many tiles?

Thanks in advance

#31649 - identitycrisisuk - Mon Dec 13, 2004 2:40 pm

What Screen Base Blocks are you using to store map data? Really need to know that to see what could be overlapping. I don't know off the top of my head how many tiles fit into a Char base block.
_________________
Code:
CanIKickIt(YES_YOU_CAN);

#31650 - Celeryface - Mon Dec 13, 2004 2:46 pm

identitycrisisuk wrote:
What Screen Base Blocks are you using to store map data? Really need to know that to see what could be overlapping. I don't know off the top of my head how many tiles fit into a Char base block.


Code:

unsigned short* bg0map = (unsigned short*)ScreenBaseBlock(28);
unsigned short* bg1map = (unsigned short*)ScreenBaseBlock(31);

REG_BG0CNT = BG_COLOR256 | TEXTBG_SIZE_512x256 | ( 28 << SCREEN_SHIFT ) | WRAPAROUND | ( 0 << CHAR_SHIFT );

// Setup background 1
REG_BG1CNT = BG_COLOR256 | TEXTBG_SIZE_256x256 | ( 31 << SCREEN_SHIFT ) | WRAPAROUND | ( 1 << CHAR_SHIFT );

SetMode( 0 | OBJ_ENABLE | OBJ_MAP_1D | BG0_ENABLE  );
   
// Load the menu background into background 0.

// Copy the palette into the background palette memory.
DMAFastCopy( (void*)bgs_pal_Palette, (void*)BGPaletteMem, 256, DMA_16NOW );

// Copy the tile data into the tile memory.
DMAFastCopy( (void*)menubg_Tiles, (void*)CharBaseBlock(0), 13248/4, DMA_32NOW );

// Copy the map data into background 0.
Load512x256_TextBG(menubg_Map, bg0map);
   
// Load the game background into background 1.
   
// Copy the tile data into the tile memory.
DMAFastCopy( (void*)gamebg_Tiles, (void*)CharBaseBlock(1), 44096/4, DMA_32NOW );
   
// Copy the map data into background 1.
Load256x256_TextBG( gamebg_Map, bg1map );


#31652 - identitycrisisuk - Mon Dec 13, 2004 2:53 pm

Celeryface wrote:
Code:
SetMode( 0 | OBJ_ENABLE | OBJ_MAP_1D | BG0_ENABLE  );


I believe this line is your problem. The simple ones are always the best :)
_________________
Code:
CanIKickIt(YES_YOU_CAN);

#31654 - Celeryface - Mon Dec 13, 2004 3:04 pm

identitycrisisuk wrote:
Celeryface wrote:
Code:
SetMode( 0 | OBJ_ENABLE | OBJ_MAP_1D | BG0_ENABLE  );


I believe this line is your problem. The simple ones are always the best :)


You mean I'm only enabling background 0? If so, yeah I'm doing that on purpose :) Is that a problem?

I load both backgrounds in but I only want to show the first one until I enter another "area" of program. I would then turn off BG0 and enable BG1. To see if BG1 loaded properly, I just view it in the Map Viewer and view its tiles in Tile Viewer in VBA.

#31657 - identitycrisisuk - Mon Dec 13, 2004 3:12 pm

Ah right, well in VBA the tiles should be there no matter what if they are loaded correctly but I don't know if a map will be shown if it is disabled.
_________________
Code:
CanIKickIt(YES_YOU_CAN);

#31660 - Celeryface - Mon Dec 13, 2004 3:54 pm

identitycrisisuk wrote:
Ah right, well in VBA the tiles should be there no matter what if they are loaded correctly but I don't know if a map will be shown if it is disabled.


Hmm. When I enabled BG1 and BG0, I get the same result. It seems that BG0 is referencing some of BG1 and as well as its own tiles.

#31664 - identitycrisisuk - Mon Dec 13, 2004 4:13 pm

It could possibly be something to do with whatever you have used to create your maps, maybe it has tried to get rid of some tile redundancy or something and combines tiles shared by two maps. I think I'm pretty much at the end of my knowledge on the subject though, mods - help!
_________________
Code:
CanIKickIt(YES_YOU_CAN);

#31666 - Celeryface - Mon Dec 13, 2004 4:26 pm

identitycrisisuk wrote:
It could possibly be something to do with whatever you have used to create your maps, maybe it has tried to get rid of some tile redundancy or something and combines tiles shared by two maps. I think I'm pretty much at the end of my knowledge on the subject though, mods - help!


I used GIMP to convert the graphics over. They were originally bitmaps, so they probably are using way too many tiles. Any recommendations for creating backgrounds/maps from bitmaps?

#31671 - Cearn - Mon Dec 13, 2004 5:36 pm

1 screenblock is 0x0800 = 2048 bytes
1 charblock is 0x4000 = 16384 bytes

memory use (add 0x06000000 for VRAM)
screenblock 28: 0xe000 - 0xe7ff
screenblock 31: 0xf800 - 0xffff

menu tiles: 13248= 0x33c0 bytes
copy menu tiles to charblock 0 fills: 0x0000 - 0x33c0

game tiles: 44096= 0xac40 bytes
copy game tiles to charblock 1 fills: 0x4000-0xec40

That should blast screenblock 28 and a good deal of 29 out of the water. Also, 0xac40 bytes is 1378 4bit tiles, when you can only access 1024. 8bit tiles would be ok, though.

So yeah, you probably have way too many tiles. If the bitmaps aren't too complex, you could try to weed out the duplicates (I think gfx2gba or MapEd could help you there, but I may be wrong); did this just yesterday and saw my tileset shrink from 1044 to 644. If the bitmap is too complex to be reduced, you might have to start thinking about dynamic loading.

#31675 - Celeryface - Mon Dec 13, 2004 6:40 pm

Thanks for the info :)

I'll see if MapED can reduced the amount of tiles. I used gfx2gba to convert it over, and it did reduce some of the tiles. If MapED doesn't work, then I'll just make another background.

Thanks! :)


Cearn wrote:
1 screenblock is 0x0800 = 2048 bytes
1 charblock is 0x4000 = 16384 bytes

memory use (add 0x06000000 for VRAM)
screenblock 28: 0xe000 - 0xe7ff
screenblock 31: 0xf800 - 0xffff

menu tiles: 13248= 0x33c0 bytes
copy menu tiles to charblock 0 fills: 0x0000 - 0x33c0

game tiles: 44096= 0xac40 bytes
copy game tiles to charblock 1 fills: 0x4000-0xec40

That should blast screenblock 28 and a good deal of 29 out of the water. Also, 0xac40 bytes is 1378 4bit tiles, when you can only access 1024. 8bit tiles would be ok, though.

So yeah, you probably have way too many tiles. If the bitmaps aren't too complex, you could try to weed out the duplicates (I think gfx2gba or MapEd could help you there, but I may be wrong); did this just yesterday and saw my tileset shrink from 1044 to 644. If the bitmap is too complex to be reduced, you might have to start thinking about dynamic loading.