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 > "Artifact" Problem when trying to display Sprite

#7613 - jcpredator - Sat Jun 21, 2003 3:22 am

I just recently got out of a C programming class and have been trying to learn how to program for the GBA. This is my first attempt at a GBA program that will display a sprite. I know there are a lot of tutorials out there for this but I wanted to figure the bulk of this on my own and not from someone else. Call me a noob if u want, lol.

I'm probably just making a easy to fix mistake on my part but I would appreciate it if anyone could tell me what I'm doing wrong. usaflag.h is my sprite header, 256 color palette, 32x32, and I also have all the typedefs above the include statement. When I compile and then run this program on VisualBoyAdvance all I see on the screen is a little picture in the top left corner that looks like a spaceship, lol, I was told this was called the "artifact". Sorry for the long and messy code.

Code Below from SpriteTest.cpp
//////////////////////////////////////////////////////////////////////
#include <usaflag.h>

#define REG_DISPLAY (*(volatile u32*)0x04000000)
#define SPRITE_PALETTE ((u16*)0x5000200)
#define REG_VCOUNT *(u16*)0x4000006

u32* OAMmem =(u32*)0x7000000;
u16* OAMData =(u16*)0x6010000;
u16* BGPaletteMem =(u16*)0x5000000;
u16* OBJPaletteMem =(u16*)0x5000200;

typedef struct
{
u16 attribute0;
u16 attribute1;
u16 attribute2;
u16 attribute3;
} OAMEntry;

OAMEntry sprites[128];

volatile u16* VideoBuffer = (volatile u16*)0x06000000;

void initGame(void);
void initSprites(void);
void waitForVSync(void);
void copyOAM(void);

void AgbMain(void)
{
u16 loop;
s16 x = 50;
s16 y = 50;
initGame();

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

initSprites();

sprites[0].attribute0 = 0x2000 | 0x0 | y;
sprites[0].attribute1 = 0x4000 | x;
sprites[0].attribute2 = 512;

for(loop=0;loop<512;loop++)
OAMData[loop] = obj0[loop];

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

void initGame(void)
{
REG_DISPLAY = 0x140A; // Mode 4, BG2, OBJ, OAM, 1D / 5220 / 0001010001100100
}

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

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

void copyOAM(void)
{
u16 loop;
u16* temp;
temp = (u16*)sprites;
for(loop=0;loop<128*4;loop++)
OAMmem[loop] = temp[loop];
}
///////////////////////////////////////////////////////////////////
_________________
There is no spoon...

#7628 - jcpredator - Sat Jun 21, 2003 5:56 pm

I failed to realize that when using mode 4 you need to set the sprite OAMData address to 0x06014000 instead of 0x6010000. As I said before it was just probably a simple mistake on my part and I already called myself a dumbarse a couple of times already, hehe. Thanks anyways,

-Jcpredator-
_________________
There is no spoon...

#8721 - jmp_eax - Fri Jul 18, 2003 5:11 pm

Just thought I'd mention that it'd be a LOT easier if you used a c header file like gba.h to define all the gba registers... and some macros as well...

You can get this at the pern project or gbajunkie's tutorials... if you can find some staringmonkey tutorials, you can get lots of other header file goodies from there too.

#8722 - jcpredator - Fri Jul 18, 2003 5:14 pm

Yeah well that was one of my first projects and a little while ago, Jun. 21st i believe. I made my own C header file with all the registers in it after fixing this problem.
_________________
There is no spoon...