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 > How to work out screen and charBaseBlock for backgrounds

#26287 - mr_square - Sat Sep 11, 2004 4:08 pm

Hi all - I have a single 256*256 text background which works fine. When I try to add a second background, it goes all wrong - looking in the map viewer in VBA shows that the second background is present and correct, but the first is just a load of garbage made up of the 2nd one's tiles. I assume from this that I'm putting the new tiles in the wrong position in memory, and so they're overwriting the first background's tiles.

My code currently, using GBAJunkie's background definitions:

Code:

background1.number = 1;
background1.charBaseBlock = 0;
background1.screenBaseBlock = 28;
background1.colorMode = BG_COLOR_256;
background1.size = TEXTBG_SIZE_256x256;
background1.mosaic = 0;
background1.x_scroll = 0;
background1.y_scroll = 43;

background2.number = 2;
background2.charBaseBlock = 16;
background2.screenBaseBlock = 30;
background2.colorMode = BG_COLOR_256;
background2.size = TEXTBG_SIZE_256x256;
background2.mosaic = 0;
background2.x_scroll = 0;
background2.y_scroll = 43;


I'm fairly sure its either the
background2.charBaseBlock or background2.screenBaseBlock lines thats messing it up, as I just took them from an example that happened to be using the same size text backgrounds. What should they be, and how would I calculate them?

thanks


*edit* - tried setting charBaseBlock to 17 and it seems to have worked, but I'd still quite like to know why!

#26288 - Lord Graga - Sat Sep 11, 2004 4:21 pm

Char block 0 address = 0x6000000
Tile map block 0 = 0x6000000

You are overlapping somewhere.

#26289 - tepples - Sat Sep 11, 2004 4:32 pm

Char block base address can be 0, 1, 2, or 3, for pattern tables starting at 0x06000000, 0x06004000, 0x06008000, or 0x0600c000.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#26292 - mr_square - Sat Sep 11, 2004 5:03 pm

tepples wrote:
Char block base address can be 0, 1, 2, or 3, for pattern tables starting at 0x06000000, 0x06004000, 0x06008000, or 0x0600c000.


thanks

Looking in VBA, I now have background 0 at CharBase 0x06000000, and background 1 at CharBase 0x06004000, which seems to be right

However, the graphics are still dodgy on background 1 - the tiles all come from the right tile data, but they're slightly out of place. Background 0's MapBase is set at 28 (which is 0x0600E000) and Background 1's is at 29 (0x0600E800) - does that sound right? It could simply be my map editor playing up - its being doing dodgy things to its output recently so this might just be that.

#26294 - sajiimori - Sat Sep 11, 2004 5:33 pm

Unless you've changed your code since your initial post, you're setting one of your char base blocks to 16, which is much too high. Like tepples said, your options are 0-3. Char block 0 corresponds to screen blocks 0-7, 1 corresponds to 8-15, and so on.