ETHAN CROOKS

GBA Programming - Setting up the environment

2021-03-03

A Gameboy Advance SP. Friend shaped :)

I want to make games that run on this little thing. But first I need a developer environment to start coding for the Gameboy Advance.

Toolchain

Unsurprisingly, any official toolchains that Nintendo provided to developers back in the early 2000s are not publicly available. Thankfully, there are community made alternatives.

DevKitPro is an initiative of homebrew toolchains to develop on a variety of Nintendo consoles, from the GBA all the way up to the Switch. To develop on the GBA I shall be using their DevKitARM toolchain, a collection of headers, makefiles, linker scripts and miscellaneous tools to make a ROM that is compatible with the GBA.

There were a couple example projects included in the download, including a barebones blank template that demonstrates how to set up the initial program.

#include <gba_systemcalls.h>

int main(void) {

    // Set up interrupts
    irqInit();
    irqEnable(IRQ_VBLANK);

    // Setup code goes here :)

    while (1) {
    	// Game goes here (:

    	// Wait for the next frame
    	VBlankIntrWait();
    }
}

I also found an extended example setup with VS Code. Jamie Stewart's GBA_VSCode_Basic repo, as well as providing a better Makefile that includes a debug flag, also showed that the mGBA emulator can serve a GDB server. This allows me to set breakpoints and peek at memory while my game is running. I wonder if even official developers could do that back in the day?

Included in Jamie's repo are the VS Code launch.json and tasks.json files defining how VS Code sets everything up and debugs the program. I tweaked these a bunch, you can find my versions here.

There's still some stuff I want to change with this setup. I'm currently including the build directory when building my program to work with some auto-generated binary headers, which is weird to say the least. Since I've learned a lot about how makefiles are constructed, and alternative build systems, hopefully I'll soon be able to make the build process nice and neat.

Emulators

The example repo included task setups for two different emulators, mGBA and no$gba. After playing around with them both, I can see why. mGBA's GDB server is just too useful to pass up, and no$gba's disassembler and VRAM viewer are excellent.

Below are a few screenshots of these debugging tools in action (click them for a closer look).

Debugging using VS Code and mGBA
Looking at the disassembly with no$gba.
Looking at sprites in OAM with no$gba.

Documentation

The primary source of documentation will be GBATEK programming specs included with no$gba, including detailed and exact information about every inch of the GBA.

I also found Tonc by Jasper Vijn, a tutorial on GBA programming aiming to be as complete as possible. I will always try to leave Tonc as a last resort: I will be trying to get as far as I can while only looking at the raw specs in gbatek so that I can produce my own solution. However, if stuff isn't working and I can't figure out why, there always seems to be some footnote somewhere in Tonc predicting my mistake. Short of an actual GBA expert mentor of my own, it's an excellent backup if I get stuck.

Actually getting started!

That's about all there is to say about my setup at the moment. I've been working with background tiles and maps, and I'm now looking into affine sprites. I'll try to keep this space updated with my progress.

View my source code here.