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 > BG0CNT

#25495 - strider - Tue Aug 24, 2004 2:14 am

thanks to everyone for their replies on my previous posts...everyone's been really helpful!

had a question about the following line:
REG_BG0CNT = BG_COLOR_256 | TEXTBG_SIZE_256x256 | (8 << SCREEN_SHIFT) | (0 << CHAR_SHIFT);

What exactly is BG0CNT? i'm thinking it's just used to set various options for the different backgrounds? also I've read a couple of different tutorials and i still don't really know what the (8 << SCREEN_SHIFT) and the (0 <<CHAR_SHIFT) does....I've seen different values too (i.e. pern does (31 << SCREEN_SHIFT)) can anyone explain what the shifts are used for? thanks!

#25496 - Darmstadium - Tue Aug 24, 2004 2:39 am

you're right about REG_BG0CNT being a register to set options for your background, in fact it stands for "background 0 control". There are 4 identical registers for each of the 4 backgrounds that are named in the same way (REG_BGxCNT).

gba backgrounds store the data for the background in things called screen blocks. There are 32 different screen blocks that you can store the data for your background in.

backgrounds wouldn't be much fun without any graphics. All the image data for your background (called tiles) is stored in something called a character block, and there are 4 of them.

I'll mention that the screen blocks and the character blocks use the same memory, but you should really look at a tutorial for more detailed info.

anyway, you have to tell the gba where to find the data for the map and the tiles are by putting the numbers of the screen block and character block that you plan to use in REG_BGxCNT. You have to shift it because there are specific bits in REG_BGxCNT that are used to store the screen block and character block numbers and it is neccesary to shift the numbers so that your OR operation affects the correct bits. If that doesn't make any sense i would suggest looking up the C bitwise operators and make sure you are very comfortable with them. Also look at this page:
http://www.cs.rit.edu/~tjh8300/CowBite/CowBiteSpec.htm#REG_BG0
It contains a TON of info about the gba and every gba programmer should read it over. You can see what the REG_BGxCNT registers look like there.

hope that helped!