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.

Beginners > SHowing sprites on GBA

#11430 - HolyHoppsan - Mon Oct 06, 2003 7:43 pm

HI!
I have a problem. I?m using the pern tutorials, to learn how to display sprites. Althou I almost copied the sourcecode it does not work, whats wrong, heres my code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include "gba.h"
#include "dispcnt.h"
#include "mode.h"
#include "pacsprite.h"
#include "palette.h"
#include "sprites.h"

u16* SpritePaletteMem = (u16*)0x5000200;
u16* ScreenBuffer = (u16*)0x6000000;
u16* OAM = (u16*)0x7000000;
u16* SpriteData = (u16*)0x6100000;
OAMEntry sprites[128];

pRotData rotData = (pRotData)sprites;

//Kopiera sprites till sk?rmen
void CopyOAM()
{
   u16 loop;//looping variable for loops
   u16* temp;//pointer to sprites
   temp = (u16*)sprites;
   //loop trough sprites
   for(loop = 0; loop < 128*4; loop++)
   {
      OAM[loop] = temp[loop];
   }
}//end copyOam

//initialize Sprites(set them offscreen)
void InitializeSprites()
{
   u16 loop; //loop variable
   for(loop = 0; loop < 128; loop++)
   {
      sprites[loop].attribute0 = 160;//set y offscreen
      sprites[loop].attribute1 = 240;//set x to offscreen
   }
}

//sync screen drawing
void WaitForVsync()
{
   while((volatile u16)REG_VCOUNT != 160){}
}

void PlotPixel(int x, int y, unsigned short int c);

int main()
{
   int loop;
   s16 x = 40;
   s16 y = 40;
   SetMode(MODE_1 | OBJ_ENABLE | OBJ_MAP_1D);

   for(loop = 0; loop < 256; loop++)
   {
   OBJPaletteMem[loop] = palette[loop];
   }
   
   InitializeSprites();

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

            for(loop = 0; loop < 128; loop++)
            {
            SpriteData[loop] = pacspriteData[loop];
            }

   while(1)
   {   
      WaitForVsync();
      CopyOAM();
   }
   return(0);
}

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

#11432 - tepples - Mon Oct 06, 2003 7:56 pm

Here's a step-by-step procedure I use to isolate "It doesn't appear!" problems using VisualBoyAdvance's debugging tools:
  1. Try to find your palette data in the Palette Viewer.
  2. Try to find your sprite cel data in the Tile Viewer.
  3. Try to find your sprites in the OAM Viewer.

Find which step fails, and you're one step closer to finding the responsible lines of code.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#11435 - yaustar - Mon Oct 06, 2003 10:49 pm

First off, you dont need
Code:

#include <stdio.h>
#include <stdlib.h>


because they are windows specific

second you dont need
Code:

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

because we are using tile modes not bitmap.

Can you elaborate on 'It does not work', does it compile? blank screen etc
_________________
[Blog] [Portfolio]

#11436 - sajiimori - Mon Oct 06, 2003 11:54 pm

stdio.h and stdlib.h are *not* Windows-specific. They are part of the Standard C Library. stdio.h is not very useful on GBA, but stdlib.h contains abs(), atoi(), malloc(), free(), rand(), and qsort(), which can be handy sometimes.

#11439 - yaustar - Tue Oct 07, 2003 12:39 am

ahhhh..fair enough, I stand corrected (feeling like a moron).
In that case, the code should work....something wrong with the sprite data file maybe?

edit: Found it! yours said
Code:
u16* SpriteData = (u16*)0x6100000;


when it should be
Code:
u16* SpriteData = (u16*)0x6010000;


notice the value
_________________
[Blog] [Portfolio]

#11523 - HolyHoppsan - Thu Oct 09, 2003 1:25 pm

with it doesn?t wor i mean that the sprite isn?t show, not in the OAM viewer not in paletteViewer and not in tileviewer!

#11527 - yaustar - Thu Oct 09, 2003 2:46 pm

Check my previous post, 'u16* SpriteData' was defined to the wrong value.
_________________
[Blog] [Portfolio]