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 > Sprite won't show

#19317 - CyberSlag5k - Sat Apr 17, 2004 4:55 am

I'm just starting to develop for the GBA but am having a bit of a problem. I cannot seem to get my sprite to show up on the screen. Relavent code is as follows:

Code:

u16* videoBuffeer = ((u16*)0x6000000);
u16* paletteMem = ((u16*)0x5000000);
u16* OAM = ((u16*)0x7000000);

OAMEntry sprites[128];
pRotData rotData = (pRotData)sprites;

void copyOAM()
{
   u16* temp;
   temp = (u16*)sprites;
   for(u16 i = 0; i < 128*4; i++)
      OAM[i] = temp[i];
}

void initializeSprites()
{
   for(u16 i = 0; i < 128; i++)
   {
      sprites[i].attribute0 = 160;
      sprites[i].attribute1 = 240;
   }
   
}

void VSync()
{
   while((volatile u16)REG_VCOUNT != 160)
   {
   }
}


void plotPixel(int x, int y, unsigned short int c)
{
   videoBuffeer[(y) * 120 + (x)] = (c);
}

void setMode(u16 mode)
{
   REG_DISPCNT = mode;
}

int main()
{


   s16 x = 100, y = 60;

   setMode(MODE_1 | OBJ_ENABLE | OBJ_MAP_1D);

   for(int i = 0; i < 256; i++)
      OBJPaletteMem[i] = mySpritePalette[i];

   initializeSprites();

   sprites[0].attribute0 = COLOR_256 | SQUARE | x;
   sprites[0].attribute1 = SIZE_64 | y;
   sprites[0].attribute2 = 0;


   setMode(MODE_4 | BG2_ENABLE);
   
   for(int i = 0; i < 128; i++)
      OAMdata[i] = mySpriteData[i];

   for(int i = 0; i < 256; i++)
      paletteMem[i] = FFPalette[i];

   for(int i = 0; i < 120; i++)
      for(int j = 0; j < 160; j++)
         plotPixel(i, j, FFData[j * 120 + i]);

   while(1)
   {
      VSync();
      copyOAM();
       
   }




   return 0;
}



The background image shows, but no sprite. Interestingly enough, if I move the mode 4 stuff (the background image) to the beginning of main, the background image appears for 1 second and then the screen goes white. Is it possible that my sprite is being displayed but is for some reason taking up the whole screen (and is white)?

Any help would be appreacited.

#19319 - sajiimori - Sat Apr 17, 2004 5:36 am

You are setting the mode twice, and the second time you are not enabling sprites or setting 1D mapping. Also, mode 4 takes up half the sprite character RAM. You have to start at the 512th character.

#19321 - CyberSlag5k - Sat Apr 17, 2004 6:03 am

sajiimori wrote:
You are setting the mode twice, and the second time you are not enabling sprites or setting 1D mapping. Also, mode 4 takes up half the sprite character RAM. You have to start at the 512th character.


Is using 2 different modes bad? The sprite didn't display even if I remove all the background image stuff. The screen is just all black. And I am not sure what you mean by starting at the 512th character or how I would do it. Would you mind elaborating?

Thank you.

#19322 - sajiimori - Sat Apr 17, 2004 6:15 am

I think you're going to have to read up more about GBA. Visit the Pern tutorials, then the GBATek and Cowbite documents. These sources all illustrate the layout of sprite RAM.

There's nothing wrong with using 2 different modes at different times, but you are apparently switching modes for no particular reason, and you are expecting the old settings to still apply. They don't. As such, the OBJ_ENABLE and OBJ_MAP_1D flags are no longer set after your second setMode() call.

#19323 - CyberSlag5k - Sat Apr 17, 2004 6:23 am

Alright. Thank you.