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 > Map sizing and wrap around problems

#50890 - pizzach - Sun Aug 14, 2005 7:57 am

I'm new to gameboy developement and just about over the beginning learning curve. I started programming an RPG in Java that was becoming a good FF3 nock-off but decided I would rather get some direct console development experience so I'm starting fresh and getting some good C experience to boot. I learned some things about Windows gba programmers and how they can be lazy on uppercase lowercase. (>_<) I started gba development on my Mac in devkitadvance, I'm now on a linux with devkitpro on my laptop and I have been learning by staring at windows user source code. Agh. Anyway...

My largest battle I'm fighting will right now is figuring out what tile maps should be doing. When I set the rotation map size to 128x128 the map appears to be about one screen in size. 256x256 appears to be two screens in length. 512x512 appears to be the same size as 128x128. 1024x1024 appears to be the same size as 256x256. The other thing is I can't get wrap around to turn off.

My code is below that I had used. I tried to keep it as simple as possible because I'm not trying to build anything yet. I tried to fix up some of the indent problems and hopefully I didn't screw anything up on the copy over to the forums.

Any help would be appreciated! I hope I posted this in the right section.

Code:

#include <gba.h>

volatile u16* ScanlineCounter = (volatile u16*)0x4000006;
void WaitForVblank(void);
u16* ScreenBB = (u16*)SCREEN_BASE_BLOCK(28);
u16* CharBB = (u16*) MAP_BASE_BLOCK(0);

int main() {

    u8 i, x, y;
 
    //Background setup
    REG_BG0CNT = (BG_COLOR_256 | ROTBG_SIZE_512x512 | (28 << SCREEN_SHIFT) | (0 << CHAR_SHIFT));

    SetMode(MODE_1 | BG0_ENABLE);

    // input 3 colors into the palette
    BGPaletteMem[0] = RGB16(31,31,31);//white
    BGPaletteMem[1] = RGB16(0,30,0);//green
    BGPaletteMem[2] = RGB16(0,0,25);//blue

 

// input tiles(char data)

    for(i=0; i<32; i++) {
        CharBB[i] = 0x0000; // color from palette 0(!! We have to write 2 byte at a time !!)
    }
    for(i=32; i<64; i++) {
        CharBB[i] = 0x0101; // color from palette 1((!! We have to write 2 byte at a time !!)
    }
    for(i=64; i<96; i++) {
        CharBB[i] = 0x0202; // color from palette 2(!! We have to write 2 byte at a time !!)
     }

 

    //Almost two screens of blue tiles
    int testNum;
    for (testNum=0; testNum<25*32; testNum++) {
        ScreenBB[testNum ] = 2; //tile 2 at location (15, 8);
    }
    //Some random green tiles
    x = 0;
    y = 19;
    ScreenBB[x+(32*y) ] = 1;//tile 1 at location (5, 3);

    x = 35;
    y = 3;
    ScreenBB[x+(32*y) ] = 1; //tile 2 at location (15, 8);
      
    s16 xscroll = 1;
    REG_BG0HOFS=0;
    while(1) {
            void WaitForVblank(void);   
            //buy some time
            int x = 0x0002;
            while (x < 10000) x++;

            if (!(KEY_RIGHT & REG_KEYS)) {
                xscroll++;
                REG_BG0HOFS = xscroll;
            }
            if (!(KEY_LEFT & REG_KEYS)) {
                xscroll--;
                REG_BG0HOFS = xscroll;
            }
        }
    }

void WaitForVblank(void)   // waits for the drawer to get to end before flip
{
   while(*ScanlineCounter < 160) {   // do nothing
   }//now we are in the vblank period
}

#50904 - tepples - Sun Aug 14, 2005 12:43 pm

pizzach wrote:
My largest battle I'm fighting will right now is figuring out what tile maps should be doing. When I set the rotation map size to 128x128 the map appears to be about one screen in size. 256x256 appears to be two screens in length. 512x512 appears to be the same size as 128x128. 1024x1024 appears to be the same size as 256x256. The other thing is I can't get wrap around to turn off.

[...]

Code:
 
    //Background setup
    REG_BG0CNT = (BG_COLOR_256 | ROTBG_SIZE_512x512 | (28 << SCREEN_SHIFT) | (0 << CHAR_SHIFT));

    SetMode(MODE_1 | BG0_ENABLE);


There's your problem. BG0 and BG1 are present in modes 0 and 1. They are always "text" maps, not rotation maps. Their size is set differently (256x256, 512x256, 256x512, 512x512), they always use wraparound, and the 512-pixel-wide maps are displayed in 32x32 tile (256x256 pixel) chunks.

For rotation, use BG2.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#50998 - pizzach - Mon Aug 15, 2005 6:42 am

Thanks tepples! That was a quick and really helpful reply! I found a guide after you said that and it makes sense to me now. But then what's the point of ROTBG_SIZE_512x512 etc etc if they are already predetermined by the mode?

This is my last question, really. I changed all the REG_BG0CNT, BG0_ENABLE, REG_BG0HOFS variables to REG_BG2CNT, BG2_ENABLE, and REG_BG2HOFS. I got the rotation background working. All of the sizes seem to work. But uh....I can't get the background to scroll now. It worked for BG0. I'm going to keep pondering on this and researching. (?_?)

From what I've seen, it looks like a text background makes more sense for my yet to be rpg that I may never finish. But it is really interesting how different rotation backgrounds and text backgrounds are. :)

#51006 - Cearn - Mon Aug 15, 2005 8:31 am

pizzach wrote:
Thanks tepples! That was a quick and really helpful reply! I found a guide after you said that and it makes sense to me now. But then what's the point of ROTBG_SIZE_512x512 etc etc if they are already predetermined by the mode?
Whether a background is text or rotational is determined by the video mode, not the size. ROTBG_xxx and TEXTBG_xxx actually cover the same range of values, they're just named differently because the possible sizes for text and rot bgs are different.

pizzach wrote:
This is my last question, really. I changed all the REG_BG0CNT, BG0_ENABLE, REG_BG0HOFS variables to REG_BG2CNT, BG2_ENABLE, and REG_BG2HOFS. I got the rotation background working. All of the sizes seem to work. But uh....I can't get the background to scroll now. It worked for BG0. I'm going to keep pondering on this and researching. (?_?)
Text backgrounds use REG_BGxHOFS and REG_BGxVOFS (x=0,1,2,3), while rotational backgrounds use REG_BGxX and REG_BGxY (x=2,3). Note ..HOFS and ..VOFS are normal integers, and ..X and ..Y are .8 fixed point numbers.

#51052 - pizzach - Mon Aug 15, 2005 10:34 pm

I just looked at the values of ROTBG and TEXTBG and feel a bit like an idiot now. :) Thanks eternally for the linke Cearn. I should actually be able to disiffer what the other register names are with that link.