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 > Tiled backgrounds & sprites @ one time

#133384 - Phantaseur - Thu Jul 05, 2007 9:52 pm

I'm trying to display tiled background and sprite on screen at one time, but I have problems with it, I can see only sprite or only background. It depend of thing which I assign to VRAM_A. If I write
Code:
   VRAM_A_CR=VRAM_ENABLE|VRAM_A_MAIN_SPRITE;
   VRAM_B_CR=VRAM_ENABLE|VRAM_B_MAIN_BG;
i see only sprite on the screen, if i write
Code:
   VRAM_A_CR=VRAM_ENABLE|VRAM_A_MAIN_BG;
   VRAM_B_CR=VRAM_ENABLE|VRAM_B_MAIN_SPRITE;
i see just background. What I have to do for getting sprite and backgroung at one time?

Here is code:
Code:
#include<nds.h>
#include<string.h>

u8 redTile[64] =
{
   1,1,1,1,1,1,1,1,
   1,2,2,2,2,2,2,1,
   1,2,2,2,2,2,2,1,
   1,2,2,2,2,2,2,1,
   1,2,2,2,2,2,2,1,
   1,2,2,2,2,2,2,1,
   1,2,2,2,2,2,2,1,
   1,1,1,1,1,1,1,1
};

u8 greenTile[64] =
{
   3,3,3,3,3,3,3,3,
   3,4,4,4,4,4,4,3,
   3,4,5,5,5,5,4,3,
   3,4,5,5,5,5,4,3,
   3,4,5,5,5,5,4,3,
   3,4,5,5,5,5,4,3,
   3,4,4,4,4,4,4,3,
   3,3,3,3,3,3,3,3
};

int main(){
   int id;
   SpriteEntry *spriteEntry = new SpriteEntry[128];
   SpriteRotation *spriteRotation = (SpriteRotation*)spriteEntry;

   REG_POWERCNT=POWER_ALL_2D;
   DISPLAY_CR=MODE_0_2D|DISPLAY_BG0_ACTIVE|DISPLAY_SPR_ACTIVE|DISPLAY_SPR_1D;
   BG0_CR=BG_32x32|BG_COLOR_256|BG_MAP_BASE(0)|BG_TILE_BASE(1);

   /*VRAM_A_CR=VRAM_ENABLE|VRAM_A_MAIN_SPRITE;
   VRAM_B_CR=VRAM_ENABLE|VRAM_B_MAIN_BG;*/
   VRAM_A_CR=VRAM_ENABLE|VRAM_A_MAIN_BG;
   VRAM_B_CR=VRAM_ENABLE|VRAM_B_MAIN_SPRITE;

   BG_PALETTE[1] = RGB15(31,0,0);
   BG_PALETTE[2] = RGB15(0,31,0);
   SPRITE_PALETTE[3]=RGB15(0,0,31);
   SPRITE_PALETTE[4]=RGB15(0,0,0);
   SPRITE_PALETTE[5]=RGB15(31,31,31);

   memcpy((void*)BG_TILE_RAM(1), redTile, 64);
   memcpy((void*)(BG_TILE_RAM(1)+64), greenTile, 64);

   for(int i=0;i<32*32;i++){
      (*(unsigned short*)(void*)(BG_MAP_RAM(0)+i*2))=0;
   }

   for (int i = 0; i < 128; i++) {
   spriteEntry[i].attribute[0] = ATTR0_DISABLED;
   spriteEntry[i].attribute[1] = 0;
   spriteEntry[i].attribute[2] = 0;
   }
   for (int i = 0; i < 32; i++) {
   spriteRotation[i].hdx = 256;
   spriteRotation[i].hdy = 0;
   spriteRotation[i].vdx = 0;
   spriteRotation[i].vdy = 256;
   }

   id=0;
   spriteEntry[0].attribute[0] = ATTR0_COLOR_256 | ATTR0_ROTSCALE | 128;
   spriteEntry[0].attribute[1] = ATTR1_ROTDATA(0) | ATTR1_SIZE_8 | 96;
   spriteEntry[0].attribute[2] = id;

   for(int i=0;i<8*4;i++)
      SPRITE_GFX[i+id*16]=(greenTile[2*i+1]<<8)|greenTile[2*i];

   DC_FlushRange(spriteEntry,128*sizeof(SpriteEntry));
   dmaCopy(spriteEntry,OAM, 128*sizeof(SpriteEntry));

   while(1);

   return(0);
}

#133400 - Azenris - Thu Jul 05, 2007 11:42 pm

try using this

Code:
VRAM_A_CR=VRAM_ENABLE|VRAM_A_MAIN_BG_0x06000000;
VRAM_B_CR=VRAM_ENABLE|VRAM_B_MAIN_SPRITE_0x6400000;

_________________
My Homebrew Games

#133510 - Phantaseur - Fri Jul 06, 2007 4:47 pm

It doesnt work...

#133845 - Phantaseur - Mon Jul 09, 2007 6:59 am

Is there any way to get sprite over background?
How can I do it?

#133853 - knight0fdragon - Mon Jul 09, 2007 8:36 am

can you post a place to download your code? i want to tinker with it, but idont want to setup an enviroment or anything
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#133931 - Phantaseur - Mon Jul 09, 2007 9:31 pm

Ahh.. It works, I tried it at old version of dualis and there was no expected resultat, now I copied *.nds to R4DS and it works on real hardware.
Thank you for help offering. Sorry for disturb.

#133938 - HyperHacker - Mon Jul 09, 2007 9:52 pm

Lesson learned: Don't trust emulators entirely, at least not yet. They are still all quite immature and have many bugs and/or differences from real hardware. No$GBA is most accurate if you don't need (or want to pay $5000 for <_<) a debugger, but there are still some issues (mainly sound-related).
_________________
I'm a PSP hacker now, but I still <3 DS.