thomblog

Tom 'voxel' Purnell's notes

Developing GBA games on Raspberry Pi

This is a log of how I set up a GBA development environment on a raspberry pi. It’s not intended to teach game development, just the process of installing and configuring the tools so I can refer to it later.

Why

At the time of writing, ‘GBA JAM 24’ is running. Entrants create a new game compatible with the handheld Game Boy Advance console from 2001. I’ve never made a game for this platform before, and I’d like to give it a try! Currently my only ‘desktop computer’ is a raspberry pi 4, so that’s what I’ll be using. More information on my hardware setup is available here if you’re interested.

Game boy advance console

DevKitPro

The very good people at DevKitPro maintain a free toolchain of cross compilers and libraries targeting multiple platforms, including the Game Boy Advance. This handles most of the difficult configuration and setup for us, and reduces the scope of my own work to ‘making the game’ rather than having to spend a long time creating special compilers and so on. They provide a fairly straightforward Getting started guide.

Though not available directly from the debian repositories that I’m using on my raspberry pi, devkitpro make their own debian compatible repository available. We just need to configure apt to use it.

# wget https://apt.devkitpro.org/install-devkitpro-pacman
# chmod +x ./install-devkitpro-pacman
# sudo ./install-devkitpro-pacman

This configures the repository and installs devkitpro-pacman, the devkitpro package manager tool - which we can now use to automatically install everything we need for gba dev

# sudo dkp-pacman -S gba-dev

This installs gba compilers, libraries, examples, a debugger and probably more.

Hell(o) World

As a special treat we’re going to actually use the tools this time. In a new terminal window (to ensure the new devkitpro environment vars are set), create a folder for the project and add this Makefile (borrowed from the devkitpro examples). There’s quite a lot of configuration to the devkitpro environment and the Makefile handles it all on our behalf. Finally create a c source file.

# mkdir hell_world
# cd hell_world
# vim main.c

Edit in your favourite editor:

#include <gba_console.h>
#include <gba_video.h>
#include <gba_interrupt.h>
#include <gba_systemcalls.h>
#include <stdio.h>

int main( void ){
    irqInit();
    irqEnable( IRQ_VBLANK );

    consoleDemoInit();

    iprintf("\x1b[10;10HHell World!");  

    while( 1 ){
        VBlankIntrWait(); 
    }
}

Finally, from within this project directory, run Make

# Make
main.c
linking cartridge
built ... hell_world.gba
ROM fixed!

This gives us hell_world.gba, ready to run in an emulator or on a real Game Boy Advance if you have a method of putting it onto a cartridge.

mesen.png