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 > Questions concerning usage of maps (mode 0 and others).

#90774 - Dark Knight ez - Sun Jul 02, 2006 9:53 am

As far as I understand things, in mode 0 you can use maps which have references to 8x8 tiles. These tiles should be stored in VRAM, right? Would it be okay to put them in a VRAM assigned for sprites?

Looking at the code of the example called "Complex_2D", I note a different use of maps than I expected to see.
Code:
   BG_PALETTE_SUB[0] = RGB15(10,10,10);
   BG_PALETTE_SUB[1] = RGB15(0,16,0);
   BG_PALETTE_SUB[2] = RGB15(0,0,31);

   //load the maps with alternating tiles (0,1 for bg0 and 0,2 for bg1)
   for(iy = 0; iy < 32; iy++)
      for(ix = 0; ix <32; ix++) {
         map0[iy * 32 + ix] = (ix ^ iy) & 1;
         map1[iy * 32 + ix] = ((ix ^ iy) & 1)<<1;
      }   

In here it seems that the colour (read: palette entry) of an entire tile is assigned to a map entry. Noting that the for-loops do both go up to 32, I can tell that it is using 8x8 tiles.
So my question regarding this would be how I can give a location to a 8x8 tile stored in VRAM to a map instead of a direct palette entry (which would be used for the entire tile, it seems).
Please correct me on any wrong assumptions I made here.l

Thanks in advance.


edit:
Also, how would I go about flipping a tile horizontally or vertically using maps? (Or is that not possible?)


2nd edit:
I've found TONC's explanation on the subject. It clears up some stuff like how flipping the tiles is done.
I don't quite understand where to put the maps and the actual graphics (read: tiles) though. TONC mentions that they overlap in memory so caution is needed.
I'd like to use 3, or if possible all 4 backgrounds of mode 0 for displaying tiles. What place(s) would be best to put the graphics (the tiles) and the maps?

#90902 - Dark Knight ez - Mon Jul 03, 2006 10:32 am

I got this far by experimenting myself.
The problem is, that the screen now only shows the colour FF00FF (first palette entry). The environment_bin is a tried one, does not contain an entire FF00FF tile, and consists out of approx 40 8x8 tiles. So that should not be the cause.
It's probably me not using the map properly. Or it could be that I'm copying in the environment_bin in a wrong manner, I don't know. Please help me out here. Point out my mistake.


Code:
int i;
uint16* mapBG0 = (uint16*)SCREEN_BASE_BLOCK(28);



videoSetMode(MODE_0_2D |  DISPLAY_BG0_ACTIVE);
BG0_CR = BG_PRIORITY_3 | BG_TILE_BASE(0) | BG_MOSAIC_OFF | BG_256_COLOR | BG_MAP_BASE(28) | BG_WRAP_ON | BG_32x32;

BG0_X0 = 0;
BG0_Y0 = 0;
memcpy((void *)BG_PALETTE, palette_bin, palette_bin_size);
memcpy((void *)CHAR_BASE_BLOCK(0), environment_bin, environment_bin_size);

for (i=0; i<32*32; i++)
    mapBG0[i] = 2;

#90962 - Dark Knight ez - Mon Jul 03, 2006 7:01 pm

Can nobody help me out?
I've tried everything I can think of.
Having compared this code to GBA examples didn't help either.
I can't find a difference (apart from naming and such, that is).

Copying the environment_bin as uint16s into CHAR_BASE_BLOCK(0) instead of regular memcopying didn't help either.
The only thing which I actually affected the screen with, was leaving out the copying of the palette... making the screen black instead of pink (which was the first palette entry).
Leaving out everything except "videoSetMod(MODE_0_2D)" and the palette copying has exactly the same end result as with the code for maps added. Very dissapointing.

Please help, because I'm genuinly stuck.
Does anyone know of a current homebrew game on the NDS which also uses tiled backgrounds of which I could take a look in the source code? Tutorials even? Anything?

#91025 - gladius - Tue Jul 04, 2006 1:38 am

You are misunderstanding what complex_2d is doing. Those are not references to the color, they are indeed references to a tile. The tile is a just initialized to be an 8x8 block of that color.

You need to allocate a bank of VRAM to be your tile store, I believe the libnds way of doing this is vramSetBanks(), or something along those lines.

Once you have done that, setting up the map and tile base is quite similar to the GBA, you just have more RAM in which to do it.

#91063 - Dark Knight ez - Tue Jul 04, 2006 10:34 am

I see. I was under the impression it was already reserved for things such as this.
Setting VRAM Bank A to be background fixed my problems.
Thank you so much, gladius. I really appreciate it. :)

I assume this also means that I'll have 128kB to work with instead of just 64kB as mentioned in TONC. Nice.