By Josep Valls
http://josep.valls.name
Introduction to hardware-level programming and the C language using the Gameboy Advance as the reference architecture
Coded for CMPS105 UNIX Programming with Scott Brandt at UCSC winter 2008
Notes by guest lecturer Michael Mateas
http://www-static.cc.gatech.edu/classes/AY2006/cs2260_spring/
The syllabus includes slides, pointers to the GBA development environment we used (HAM - this includes Visualboy Advance, a hardware accurate GBA emulator for Windows), and several ebooks for download (including "Programming the Nintendo Gameboy Advance: The Unofficial Guide" - unfortunately, the author is wrong about several details of the GBA architecture, leading to long nights for me while I tried to figure out what various bits in the DMA control registers *really* do). The TONC GBA Guide (also linked), is more accurate about GBA systems programming details, but is very much a hacker guide rather than a textbook.
Hello World for the GBA (draws a single pixel on the screen)
// entry point to program
int main(void)
{
// create a pointer to the video buffer
unsigned short* videoBuffer = (unsigned short*)0x6000000;
// switch to video mode 3 (240x160 16-bit) by
// setting a memory register to a specific value
*(unsigned long*)0x4000000 = (0x3 | 0x400);
// draw a white pixel (16 bits) directly to video memory
// pixel location is centered on the screen (120,80)
videoBuffer[80 * 240 + 120] = 0xFFFF;
// continuous loop
while(1) { }
return 0; // end program
Source code
Sample #1, binary
Sample #1, C source
Sample #2, binary
Sample #2, C source