Im currently trying to learn a bit of GBA programming and im going insane just trying to display a simple sprite on the screen. Ive got the object palettes set and ive written the sprite data into memory but i cant get my head around writting it to the OAM?
Can anyone tell me what im doing wrong. My code is:
#include <gba_console.h>
#include <gba_video.h>
#include <gba_interrupt.h>
#include <gba_systemcalls.h>
#include <stdio.h>
#define SPRITE ((unsigned int*) 0x06010000)
#define OBJHOLDER ((unsigned int*) 0x07000000)
extern void myfunc(int* answer);
//---------------------------------------------------------------------------------
// Program entry point
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
// the vblank interrupt must be enabled for VBlankIntrWait() to work
irqInit();
irqEnable(IRQ_VBLANK);
// generic setup function
consoleDemoInit();
// Display Control Register
unsigned short* DISPCNT = (unsigned short*) 0x04000000;
DISPCNT[0] = (1<<12)|(0<<11)|(0<<10)|(0<<9)|(1<<8)|(1<<6)|(0<<2)|(0<<1)|(0<<0);
// BG Controllers
unsigned short* BG0CNT = (unsigned short*) 0x04000008;
BG0CNT [0] = (15<<0)|(14<<0)|(13<<0)|(12<<0)|(11<<9)|(10<<0)|(9<<0)|(8<<0)|(6<<0)|(2<<0)|(1<<0)|(0<<0);
unsigned short* BG1CNT = (unsigned short*) 0x0400000A;
BG1CNT [1] = (15<<0)|(14<<0)|(13<<0)|(12<<0)|(11<<0)|(10<<9)|(9<<0)|(8<<0)|(6<<0)|(2<<0)|(1<<0)|(0<<0);
unsigned short* BG2CNT = (unsigned short*) 0x0400000C;
BG2CNT [2] = (15<<0)|(14<<0)|(13<<0)|(12<<0)|(11<<0)|(10<<0)|(9<<9)|(8<<0)|(6<<0)|(2<<0)|(1<<0)|(0<<0);
unsigned short* BG3CNT = (unsigned short*) 0x0400000E;
BG3CNT [3] = (15<<0)|(14<<0)|(13<<0)|(12<<0)|(11<<0)|(10<<0)|(9<<0)|(8<<9)|(6<<0)|(2<<0)|(1<<0)|(0<<0);
// Object Colour Pallete
unsigned short* OBJPAL = (unsigned short*) 0x5000200;
OBJPAL[0] = ((15<<10)|(8<<5)|(31<<0));
OBJPAL[1] = ((0<<10)|(31<<5)|(0<<0));
OBJPAL[2] = ((15<<10)|(8<<5)|(0<<0));
OBJPAL[3] = ((5<<10)|(8<<5)|(9<<0));
//Raw Sprite Data
int n = 1;
SPRITE[(n*8)+0] = (0<<28)|(0<<24)|(1<<20)|(1<<20)|(1<<16)|(0<<12)|(0<<8)|(0<<4);
SPRITE[(n*8)+1] = (0<<28)|(1<<24)|(1<<20)|(1<<20)|(1<<16)|(1<<12)|(0<<8)|(0<<4);
SPRITE[(n*8)+2] = (0<<28)|(1<<24)|(0<<20)|(0<<20)|(0<<16)|(1<<12)|(0<<8)|(0<<4);
SPRITE[(n*8)+3] = (0<<28)|(1<<24)|(0<<20)|(0<<20)|(0<<16)|(1<<12)|(0<<8)|(0<<4);
SPRITE[(n*8)+4] = (0<<28)|(1<<24)|(0<<20)|(0<<20)|(0<<16)|(1<<12)|(0<<8)|(0<<4);
SPRITE[(n*8)+5] = (0<<28)|(1<<24)|(1<<20)|(1<<20)|(1<<16)|(1<<12)|(0<<8)|(0<<4);
SPRITE[(n*8)+6] = (0<<28)|(0<<24)|(1<<20)|(0<<20)|(1<<16)|(0<<12)|(0<<8)|(0<<4);
SPRITE[(n*8)+7] = (0<<28)|(0<<24)|(1<<20)|(0<<20)|(1<<16)|(0<<12)|(0<<8)|(0<<4);
OBJHOLDER[0] = ((0<<16)|(0<<14)|(2<<8));
OBJHOLDER[1] = ((0<<16)|(0<<14)|(0<<13)|(0<<12)|(60<<9));
OBJHOLDER[2] = ((0<<16)|(0<<12)|(1<<10));
OBJHOLDER[3] = (0);
//TEST MAP DATA
// main loop
while (1)
{
// ansi escape sequence to clear screen and home cursor
// /x1b[line;columnH
iprintf("\x1b[2J");
// ansi escape sequence to set print co-ordinates
// /x1b[line;columnH
iprintf("\x1b[10;10HDolce Gusto");
VBlankIntrWait();
}
}
Can anyone tell me what im doing wrong. My code is:
#include <gba_console.h>
#include <gba_video.h>
#include <gba_interrupt.h>
#include <gba_systemcalls.h>
#include <stdio.h>
#define SPRITE ((unsigned int*) 0x06010000)
#define OBJHOLDER ((unsigned int*) 0x07000000)
extern void myfunc(int* answer);
//---------------------------------------------------------------------------------
// Program entry point
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
// the vblank interrupt must be enabled for VBlankIntrWait() to work
irqInit();
irqEnable(IRQ_VBLANK);
// generic setup function
consoleDemoInit();
// Display Control Register
unsigned short* DISPCNT = (unsigned short*) 0x04000000;
DISPCNT[0] = (1<<12)|(0<<11)|(0<<10)|(0<<9)|(1<<8)|(1<<6)|(0<<2)|(0<<1)|(0<<0);
// BG Controllers
unsigned short* BG0CNT = (unsigned short*) 0x04000008;
BG0CNT [0] = (15<<0)|(14<<0)|(13<<0)|(12<<0)|(11<<9)|(10<<0)|(9<<0)|(8<<0)|(6<<0)|(2<<0)|(1<<0)|(0<<0);
unsigned short* BG1CNT = (unsigned short*) 0x0400000A;
BG1CNT [1] = (15<<0)|(14<<0)|(13<<0)|(12<<0)|(11<<0)|(10<<9)|(9<<0)|(8<<0)|(6<<0)|(2<<0)|(1<<0)|(0<<0);
unsigned short* BG2CNT = (unsigned short*) 0x0400000C;
BG2CNT [2] = (15<<0)|(14<<0)|(13<<0)|(12<<0)|(11<<0)|(10<<0)|(9<<9)|(8<<0)|(6<<0)|(2<<0)|(1<<0)|(0<<0);
unsigned short* BG3CNT = (unsigned short*) 0x0400000E;
BG3CNT [3] = (15<<0)|(14<<0)|(13<<0)|(12<<0)|(11<<0)|(10<<0)|(9<<0)|(8<<9)|(6<<0)|(2<<0)|(1<<0)|(0<<0);
// Object Colour Pallete
unsigned short* OBJPAL = (unsigned short*) 0x5000200;
OBJPAL[0] = ((15<<10)|(8<<5)|(31<<0));
OBJPAL[1] = ((0<<10)|(31<<5)|(0<<0));
OBJPAL[2] = ((15<<10)|(8<<5)|(0<<0));
OBJPAL[3] = ((5<<10)|(8<<5)|(9<<0));
//Raw Sprite Data
int n = 1;
SPRITE[(n*8)+0] = (0<<28)|(0<<24)|(1<<20)|(1<<20)|(1<<16)|(0<<12)|(0<<8)|(0<<4);
SPRITE[(n*8)+1] = (0<<28)|(1<<24)|(1<<20)|(1<<20)|(1<<16)|(1<<12)|(0<<8)|(0<<4);
SPRITE[(n*8)+2] = (0<<28)|(1<<24)|(0<<20)|(0<<20)|(0<<16)|(1<<12)|(0<<8)|(0<<4);
SPRITE[(n*8)+3] = (0<<28)|(1<<24)|(0<<20)|(0<<20)|(0<<16)|(1<<12)|(0<<8)|(0<<4);
SPRITE[(n*8)+4] = (0<<28)|(1<<24)|(0<<20)|(0<<20)|(0<<16)|(1<<12)|(0<<8)|(0<<4);
SPRITE[(n*8)+5] = (0<<28)|(1<<24)|(1<<20)|(1<<20)|(1<<16)|(1<<12)|(0<<8)|(0<<4);
SPRITE[(n*8)+6] = (0<<28)|(0<<24)|(1<<20)|(0<<20)|(1<<16)|(0<<12)|(0<<8)|(0<<4);
SPRITE[(n*8)+7] = (0<<28)|(0<<24)|(1<<20)|(0<<20)|(1<<16)|(0<<12)|(0<<8)|(0<<4);
OBJHOLDER[0] = ((0<<16)|(0<<14)|(2<<8));
OBJHOLDER[1] = ((0<<16)|(0<<14)|(0<<13)|(0<<12)|(60<<9));
OBJHOLDER[2] = ((0<<16)|(0<<12)|(1<<10));
OBJHOLDER[3] = (0);
//TEST MAP DATA
// main loop
while (1)
{
// ansi escape sequence to clear screen and home cursor
// /x1b[line;columnH
iprintf("\x1b[2J");
// ansi escape sequence to set print co-ordinates
// /x1b[line;columnH
iprintf("\x1b[10;10HDolce Gusto");
VBlankIntrWait();
}
}