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 > trouble using mode 2 tiles, [solved]

#21784 - tornadokick - Sat Jun 05, 2004 2:11 am

I'm having some more trouble trying to start with programming the GBA. This time I'm trying mode 2. When I try getting my file to work, It just throws tiles (and sometimes partial tiles) around the screen (or, with some variations of the options, just displays nothing).

Code:

Bg bg1;

int main(void)
{
   u16 loop, x_loop, y_loop;
   SetMode( MODE_2 | OBJ_MAP_2D | OBJ_ENABLE ); //set mode

   ... // code dealing with sprites, not relavent 'cause sprites are working fine

   bg1.number = 1;                       // set up and give information about the background
   bg1.size = TEXTBG_SIZE_256x256;
   bg1.charBaseBlock = 0;
   bg1.screenBaseBlock = 24;
   bg1.colorMode = BG_COLOR_256;
   bg1.x_scroll = 120;
   bg1.y_scroll = 80;
   EnableBackground(&bg1);

   for(loop = 0; loop < 256; loop++) // load the palette of the tiles
      BGPaletteMem[loop] = roadtilesPalette[loop];
   for(loop = 0; loop < ROADTILES_WIDTH * ROADTILES_HEIGHT /2 ; loop++)         

   bg1.tileData[loop] = roadtilesData[loop];      //  load the tiles into the Char Base Blocks

   u16* temp = (u16*)frogmap; 
   for(loop = 0; loop < 64*64 /2 ; loop++)
      bg1.mapData[loop] = temp[loop];  // load the map into the screen base blocks

// Program loop
   while(1) // don't end
   {
      ....
      UpdateBackground(&bg1);
      ....
   }

   return(0);
}


Everything compiles fine. frogmap (I'm recreating frogger) is the product of 5 tiles of 16x16 when run through GBAMapEditor. I ran the five tiles (a 16x80 256 color .bmp) through bmp2sprite.exe and exported roadtiles, giving me "roadtilesData" and "roadtilesPalette." The tutorial I'm using is the Pern Project. I've done extensive checking and experimenting to understand what is wrong. I'm now assuming that my mistake is due to my inexperience, and I am turning to better, more experienced sources.
Any help, suggestions, and comments are greatly appreciated. Thank you for your time.


Last edited by tornadokick on Wed Jun 09, 2004 9:38 pm; edited 1 time in total

#21785 - DiscoStew - Sat Jun 05, 2004 3:48 am

In mode 2, only backgrounds 2 and 3 are used, and they are both affine transformable (or in other words, rotational and scalable), so text backgrounds won't work. To use text backgrounds, you need to use either Mode 0 (for 4 text backgrounds, bgs 0-3), or Mode 1 (2 text, bgs 0-1; 1 affine, bg 2). Or perhaps you meant to use a text background (since your code is set up that way), so a simple change to Mode_0 or Mode_1 in the SetMode parameter would do it.
_________________
DS - It's all about DiscoStew

#21791 - tornadokick - Sat Jun 05, 2004 7:12 pm

I made the changes and it seems to have helped a bit. The display is a bit more jumbled but it's a change.

http://www.geocities.com/bincaster/runMe_01.bmp <- Copy and paste into your address bar. It doesn't work otherwise.

This is an example of what I see when I run that code. Ignore the frog that's there, that part runs fine.

#21825 - tornadokick - Mon Jun 07, 2004 3:44 am

ok, I finally found a solution. A special thanks to DiscoStew for leading me in the right direction.