GB101:Hello Background
GB101 Class Notes | |
---|---|
|
Introduction[edit]
In this example we'll try to get acquainted with the GBA by using simple mode 3 to fill the screen with red pixels. In mode 3 each 16-bit short represents a RGB value. We use the RGB5 macro to convert r,g and b into a 16-bit short. We create a pointer to the video buffer which starts at 0x6000000 and then use a couple of simple loops to set the pixels. Obviously there are more efficient ways...
Implementation[edit]
#include <gba_video.h>
#include <gba_systemcalls.h>
int main(void) {
// Memory location of video buffer
unsigned short* VideoBuffer = (unsigned short*)0x6000000;
unsigned char x,y;
// Turn on mode 3 with background 2
SetMode(MODE_3 | BG2_ENABLE);
// Fill the video buffer with red pixels
for(x = 0; x < SCREEN_WIDTH; x++)
for(y = 0; y < SCREEN_HEIGHT; y++)
VideoBuffer [x + y * SCREEN_WIDTH] = RGB5(31,0,0);
// Loop indefinitely
while(1){}
}