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.

DS development > trouble with grit and tile maps

#169981 - 0xdeadbeef - Thu Aug 20, 2009 3:24 pm

I was experimenting a little with grit and had moderate success converting bitmaps for use in an NDS project. However when I started using grit for converting a bitmap to a tiled map I ran into some trouble.

The image I'm feeding grit is a 256x192 png file. I'm processing the image wth the following parameters:

Code:

-gt
-gB8
-ps0
-pe31
-m
-mu16
-mLf
-mu16


I'm using the following code to copy the map, tiles and palette into their respective memory:
Code:

void copyTileMap() {
  const int DMA_CHANNEL = 3;

  DC_FlushAll();
  dmaCopyHalfWords(DMA_CHANNEL, tileMap, (u16*) BG_MAP_RAM(0), tileMapLen);
  dmaCopyHalfWords(DMA_CHANNEL, tile, (u16*) BG_BMP_RAM(1), tileLen);
  dmaCopyHalfWords(DMA_CHANNEL, tilePal, BG_PALETTE, tilePalLen);
}


I've initialised the background as follows:
Code:

void initTileMap() {
  videoSetMode(MODE_5_2D | DISPLAY_BG2_ACTIVE);
  vramSetBAnkA(VRAM_A_MAIN_BG_0x06000000);
  REG_BG2CNT = BG_BMP8_256x256, | BG_BMP_BASE(1) | BG_MAP_BASE(0) | BG_PRIORITY(2);
  REG_BG2PA = 1 << 8;
  REG_BG2PB = 0;
  REG_BG2PC = 0;
  REG_BG2PD = 1 << 8;
}


So I basicly call initTileMap() first followed by a call to copyTileMap. The results is garbled output on the main screen. The only peculiar thing I'm trying right now is to use only the first 32 entries in the palette, since I want to set up another background with a bitmap that will need other colors.

The other thing I'm doing is copying some bitmaps to memory every 15 frames on the subscreen, but that works and disabling those calls doesn't seem to make a difference.

Do any of you see where I'm doing something wrong?

#169990 - Cearn - Thu Aug 20, 2009 8:12 pm

There are two issues that I can see right now.

First, bitmaps aren't tilemaps. The flags you're giving grit are for tilemaps, but the background is set up for bitmaps, and copyTileMap() again assumes tilemaps.

Second, be careful when using the BG_TILE_x, BG_MAP_x and BG_BMP_x macros. There is some overlap in what they actually do. In BGxCNT, the map and bmp fields use the same bits (8-12). `BG_MAP_BASE(0) | BG_BMP_BASE(1) ' is the same as just BG_MAP_BASE(1) or BG_BMP_BASE(1), namely (1<<8). For the x_RAM() macros, BG_TILE_RAM() and BG_BMP_RAM() give the same results (0x06000000+(n)*0x4000).

Decide which one you want: bitmaps or tilemaps. Then choose your settings accordingly.

For tilemaps, use BG_TILE_x() and BG_MAP_x(); for bitmaps, only use BG_BMP_x().

#169992 - 0xdeadbeef - Thu Aug 20, 2009 8:55 pm

Cearn wrote:
First, bitmaps aren't tilemaps. The flags you're giving grit are for tilemaps, but the background is set up for bitmaps, and copyTileMap() again assumes tilemaps.


The moment I read this I figured out what I did wrong.

Code:
REG_BG2CNT = BG_RS_32x32 | BG_TILE_BASE(1) | BG_MAP_BASE(0) | BG_PRIORITY(2)



And then

Cearn wrote:
For tilemaps, use BG_TILE_x() and BG_MAP_x(); for bitmaps, only use BG_BMP_x().


Code:
dmaCopyHalfWords(DMA_CHANNEL, tile, (u16*) BG_TILE_RAM(1), tileLen);


That fixed my problems. Thanks a lot, I was getting pretty frustrated by this.

Would you know if it's possible to debug using arm-eabi-gdb ? At the moment what I do is program -> compile -> test on no$gba, but I'm pretty sure that at some point in the future I'm going to make a bug where a debugger might be handy.