I am making a home brew gba game just for fun and I have run into a little problem, i can draw a image on the screen fine, and i can read key input, expect when i try to display a different image when the user presses ENTER which is mapped to the START button in the Emulator I am using (Visual Boy Advanced) nothing happens, there are no errors when I compile the game so I have no clue what is wrong, please note I have only just got into this and I don't know much, I someone knows how to get this to work I would be very happy:D
Here is my code:
typedef unsigned short u16; // two type definitions
typedef unsigned long u32;
#include "ppic.h"
#include "ui.h"
#include "keypad.h"
#define REG_DISPCNT *(u32*)0x4000000
#define MODE_4 0x4
#define BG2_ENABLE 0x400
u16* paletteMem = (u16*)0x5000000;
u16* videoBuffer = (u16*)0x6000000;
void PlotPixel(int x,int y, unsigned short int c)
{
videoBuffer[(y) *120 + (x)] = (c);
}
int main(void)
{
int x, y, blockX, blockY, loop;
REG_DISPCNT = MODE_4 | BG2_ENABLE;
for(loop = 0; loop < 256; loop++)
paletteMem[loop] = ppicPalette[loop];
while (1) // run forever
{
if(!((*KEYS) & KEY_START))
PlotPixel(x,y,uiData[y*120+x]);
for(y = 0; y < 160; y++)
{
for(x = 0; x < 120; x++)
{
PlotPixel(x,y,ppicData[y*120+x]);
}
}
}
return 0;
}
ui.h is the header file for the image that I want to display, ppic.h is the header file of the image that I show on startup.
If the condition in the
if
statement is true, no looping over thex
andy
coordinate is done, instead only one pixel gets set. Furthermore, the loop below (which plots the contents ofppicData
) is executed regardless of the condition since anelse
is missing; hence this one pixel gets overwritten.