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.

Coding > Text background

#4153 - Psyk - Fri Mar 21, 2003 9:17 am

I'm currently using a rotation background but i want to change it to a text background. This is the code i have at the moment

Code:
temp = ROTBG_SIZE_256x256| (0<<CHAR_SHIFT) | 8<<SCREEN_SHIFT)   | BG_COLOR_256| PRIORITY(3);

REG_BG2CNT = temp;
REG_DISPCNT |= BG2_ENABLE;


This works fine but if i change the screen mode to 0 and change the code to this it doesn't work.
Code:
temp = TEXTBG_SIZE_256x256| (0<<CHAR_SHIFT) | 8<<SCREEN_SHIFT)   | BG_COLOR_256| PRIORITY(3);

REG_BG2CNT = temp;
REG_DISPCNT |= BG2_ENABLE;


When i do this all the tile data is garbled. What else do i need to change?

#4157 - tepples - Fri Mar 21, 2003 4:04 pm

Psyk wrote:
a rotation background ... works fine but if i change the screen mode to 0 and change the code to this ... all the tile data is garbled. What else do i need to change?

My first guess is that your rotation background uses 8-bit data and you're forgetting to convert it to 16-bit data for a text background before you write it to the map.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#4163 - Psyk - Fri Mar 21, 2003 8:26 pm

Why does it need to be 16bit for a text background? And how do i change it to 16bit?

#4165 - tepples - Fri Mar 21, 2003 9:16 pm

Psyk wrote:
Why does it need to be 16bit for a text background?

Because that's how Nintendo designed the system. Text background maps and rotation background maps have a different format in VRAM. Your tutorial (thepernproject.com or gbajunkie.co.uk) should address this issue.

Code:

fedcba9876543210  Text nametable entries
||||||||||||||||
||||||++++++++++- Tile number
|||||+----------- Flip tile horizontally
||||+------------ Flip tile vertically
++++------------- Palette

fedcba9876543210  Affine nametable entries
||||||||||||||||
||||||||++++++++- Tile number of even-numbered tile
++++++++--------- Tile number of odd-numbered tile


Quote:
And how do i change it to 16bit?

It depends on which tool you used to export your map. That said, you can convert the map at runtime by copying each byte of the map to one 16-bit unit of VRAM.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#4176 - Psyk - Sat Mar 22, 2003 8:38 am

ok thanks. It doesn't seem to mention it on gbajunkie because it just explains a rotation background and says that's the one most people will want to use. And the pern project doesn't seem to be up at the moment.

#4238 - Eep - Tue Mar 25, 2003 5:58 am

I am having a similar problem with my backgrounds. I am using dovoto's background structure (modified into a class for myself) and I can get the background in mode1 as a rotation background, but when I change to mode0 and to a text background nothing shows up at all. I am using VisualBoyAdvance and the background attributes are set correctly, but it like the map isn't there. The tiles load fine. I don't know what I am doing wrong. Here is the code I use when I am in mode 0:

Code:

   SetMode(MODE_0 | OBJ_ENABLE | OBJ_MAP_1D);
   
   bg2.number = 2;            //background number 0-3
   bg2.charBaseBlock = 0;
   bg2.screenBaseBlock = 28;
   bg2.colorMode = BG_COLOR_256;
   bg2.size = TEXTBG_SIZE_256x256;
   bg2.mosiac = 0;
   bg2.x_scroll = 0;
   bg2.y_scroll = 0;

   bg2.enable();

   u16 loop;
   for(loop = 0; loop < 256; loop++)
        BGPaletteMem[loop] = TilesPalette[loop];
   
   for(loop = 0; loop < Tiles_WIDTH * Tiles_HEIGHT /2; loop++)
      bg2.tileData[loop] = TilesData[loop];

   u16 *tmpTest = (u16*)CTest;
   for(loop = 0; loop < 32*32/2; loop++)
        bg2.mapData[loop] = tmpTest[loop];
       
   while(1)
   {
      getInput();
      waitForVsync();
      bg2.update();
   }


When I am in mode 1 all I do is change the SetMode to MODE_1 instead of MODE_0 and change the bg2.size to ROTBG_SIZE_256x256 (since background 2 in mode1 is a rotation background).

Any ideas would be really helpful.

Thanks.