/* * gba.h * contains graphic and input definitions and functions for the GBA */ #ifndef GBA_H #define GBA_H /* the width and height of the screen */ #define WIDTH 240 #define HEIGHT 160 /* these identifiers define different bit positions of the display control */ #define MODE4 0x0004 #define BG2 0x0400 /* this bit indicates whether to display the front or the back buffer * this allows us to refer to bit 4 of the display_control register */ #define SHOW_BACK 0x10; /* the screen is simply a pointer into memory at a specific address this * * pointer points to 16-bit colors of which there are 240x160 */ extern volatile unsigned short* screen; /* the display control pointer points to the gba graphics register */ extern volatile unsigned long* display_control; /* the address of the color palette used in graphics mode 4 */ extern volatile unsigned short* palette; /* pointers to the front and back buffers - the front buffer is the start * of the screen array and the back buffer is a pointer to the second half */ extern volatile unsigned short* front_buffer; extern volatile unsigned short* back_buffer; /* the button register holds the bits which indicate whether each button has * been pressed - this has got to be volatile as well */ extern volatile unsigned short* buttons; /* the bit positions indicate each button - the first bit is for A, second for * B, and so on, each constant below can be ANDED into the register to get the * status of any one button */ #define BUTTON_A (1 << 0) #define BUTTON_B (1 << 1) #define BUTTON_SELECT (1 << 2) #define BUTTON_START (1 << 3) #define BUTTON_RIGHT (1 << 4) #define BUTTON_LEFT (1 << 5) #define BUTTON_UP (1 << 6) #define BUTTON_DOWN (1 << 7) #define BUTTON_R (1 << 8) #define BUTTON_L (1 << 9) /* the scanline counter is a memory cell which is updated to indicate how * much of the screen has been drawn */ extern volatile unsigned short* scanline_counter; /* wait for the screen to be fully drawn so we can do something during vblank */ void wait_vblank(); /* this function checks whether a particular button has been pressed */ unsigned char button_pressed(unsigned short button); /* * function which adds a color to the palette and returns the * index to it */ unsigned char add_color(unsigned char r, unsigned char g, unsigned char b); /* put a pixel on the screen in mode 4 */ void put_pixel(volatile unsigned short* buffer, int row, int col, unsigned char color); /* this function takes a video buffer and returns to you the other one */ volatile unsigned short* flip_buffers(volatile unsigned short* buffer); /* clear the screen to black */ void clear_screen(volatile unsigned short* buffer, unsigned short color); #endif