#168367 - penjuin - Sat Apr 25, 2009 1:21 pm
Hey all,
This is my first foray into GBA programming, but it is not my first time at C (or embedded-style C either). I am trying to write code to display a sprite; I have read a multitude of tutorials and I just cannot get this to work. According to VBA, my palette is loaded fine, my tiles are loaded as well and the OAM viewer says that my object is visible at 5,5. The sprite in the OAM viewer is of the correct dimensions (8x32) but it shows up as a black square (not my sprite). Any help would be very much appreciated.
This is my first foray into GBA programming, but it is not my first time at C (or embedded-style C either). I am trying to write code to display a sprite; I have read a multitude of tutorials and I just cannot get this to work. According to VBA, my palette is loaded fine, my tiles are loaded as well and the OAM viewer says that my object is visible at 5,5. The sprite in the OAM viewer is of the correct dimensions (8x32) but it shows up as a black square (not my sprite). Any help would be very much appreciated.
Code: |
#include <gba.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <pcx.h> // include sprites #include "black_pcx.h" #include "blue_pcx.h" #include "brown_pcx.h" #include "green_pcx.h" #include "purple_pcx.h" #include "red_pcx.h" #include "resistor_pcx.h" OBJATTR sprites[128]; // Object Attribute memory, for manipulating the sprites u16 PaletteBuffer[256]; //--------------------------------------------------------------------------------- // Program entry point //--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- // the vblank interrupt must be enabled for VBlankIntrWait() to work // since the default dispatcher handles the bios flags no vblank handler // is required irqInit(); irqEnable(IRQ_VBLANK); REG_IME = 1; // Interrupt enable // set up sprites DecodePCX(black_pcx, (u16*)VRAM , PaletteBuffer); u16 *palette_pointer; palette_pointer = BG_COLORS; u32 i=0; for (i=0; i<255; i++) *palette_pointer++ = PaletteBuffer[i]; sprites[0].attr0 = ATTR0_COLOR_256 | (1<<15) | 5 ; // 8 width sprites[0].attr1 = (1<<14) | 5; // 32 long sprites[0].attr2 = 0; //Copy OAM u16 *temp; temp = (u16*)sprites; u16 *temp2; temp2 = (u16 *)OAM; for (i=0;i<4;i++) *temp2++ = temp[i]; // screen mode & background to display SetMode( MODE_4 | BG0_ON | OBJ_ENABLE | 0x40); while (1) { VBlankIntrWait(); } } |