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 > n00bish vram bank setup problem

#171176 - grapeape - Wed Nov 04, 2009 4:18 pm

Hi all,

Can anyone tell me what I'm doing wrong? I'm trying to draw some sprites on top of a background on the main screen. I can draw the sprites or draw the background but not both!

The following gets me my sprites (sprite code is omitted - let me know if I should post it):

Code:

videoSetMode(MODE_0_2D | DISPLAY_BG0_ACTIVE);
videoSetModeSub(MODE_0_2D);
vramSetBankA(VRAM_A_MAIN_SPRITE);
vramSetBankB(VRAM_B_MAIN_BG);

oamInit(&oamMain, SpriteMapping_1D_128, false);
   
int bg = bgInit(0, BgType_Text8bpp, BgSize_T_256x256, 0,1);
dmaCopy(tiles, bgGetGfxPtr(bg), sizeof(tiles));
dmaCopy(map32x32, bgGetMapPtr(bg),  sizeof(map32x32));
dmaCopy(palette, BG_PALETTE, sizeof(palette));


If I swap the vram banks for the sprites and background on the main screen like so:

Code:

vramSetBankA(VRAM_A_MAIN_BG);
vramSetBankB(VRAM_B_MAIN_SPRITE);


I can see my background, but not my sprites. Any ideas?

The documentation for libnds appears a bit thin. Am I missing some good resources?

#171177 - sverx - Wed Nov 04, 2009 4:31 pm

try this:

Code:
vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
vramSetBankB(VRAM_B_MAIN_SPRITE_0x06400000);


it's because these defines for VRAM B with no address included do map the B bank as a BG (or Sprite) 2nd bank, thus at a different address.

#171178 - grapeape - Wed Nov 04, 2009 4:35 pm

That did the trick. Can you explain (or point me to an explanation) what's going on there?

#171179 - sverx - Wed Nov 04, 2009 4:40 pm

Yeah, sorry I edited my original post but after posting it I decided a bit of explanation was needed, you see.

btw if you look at libnds video.h file, you'll see that VRAM_B_MAIN_SPRITE and VRAM_B_MAIN_BG are defined with an offset.

Code:
VRAM_B_MAIN_BG       = 1 | VRAM_OFFSET(1)
VRAM_B_MAIN_SPRITE   = 2 | VRAM_OFFSET(1)

#171180 - grapeape - Wed Nov 04, 2009 4:51 pm

Thanks. I'll spend some time poking around in the headers.

#171189 - sverx - Thu Nov 05, 2009 9:12 am

grapeape wrote:
Thanks. I'll spend some time poking around in the headers.


Time well spent :)