#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...
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...