wolfgang ziegler


„make stuff and blog about it“

Game Boy Programming in 2024

December 31, 2023

Before we get started:

  • I'm well aware it's not 2024 yet, but we're almost there - hence the title.
  • I tried all this on Ubuntu Linux 23.10. So, if you are using a different OS, your mileage will vary.

The Game Boy is the game console that was and always will be the most special one to me. It was the first console I ever owned and probably the one I spent the most time on (followed closely by the XBox many years later).

Hence, programming for the Game Boy is something I had always wanted to do but never followed through. As a kid, I did not have the resources, let alone the technical competence to do so. In my later life, I kind of forgot about that and even later I never made time for it. So hopefully this year will be the year that I dive deep into this topic.

So far, I looked into a couple of approaches to Game Boy programming that I will quickly introduce in this blog post.

  • Assembler
  • C
  • Turbo Rascal

Emulator

However, before we think about programming models, let's take a step back and have a look at where to run the demos and tutorials. While, of course, it would be possible to do so on the actual hardware, this would be rather cumbersome and inefficient. So let's find an emulator for this.

The de-facto standard (as far as I could find out) seems to be mGBA. It's available for Windows, macOS and Linux (I even managed to run it on a Raspberry Pi) and so far it was able to run every ROM I fed into it.

My initial test was with the ROM I extracted from the first Game Boy game that I ever owned (besides Tetris, of course) - Kung Fu Master. I found that quite fitting.

Note: here's my blog post on ROM extraction.

Kung Fu Master running on the mGBA emulator

Assembler

So, for the first approach we go really low-level and use assembler as our programming language. As always with assembler, this has the potential to be the most efficient approach but also the most error-prone and complex.

The tool chain I used is called RGBDS (Rednex Game Boy Development System) and it is a free assembler/linker package for the Game Boy.

I installed and built it from GitHub.

git clone https://github.com/gbdev/rgbds.git 

For a successful build it really depends on what you already have installed on your systems (e.g. make, cmake, ...). Installing build-essential is definitely a good idea.

sudo apt install build-essential  

I my case, bison was still missing and needed to be installed.

sudo apt install bison

From this point on it was smooth sailing and I simply followed the project's build instructions.

make
sudo make install

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
cmake --install build

Then I found this Hello World tutorial which also compiled and linked flawlessly and gave me the first Game Boy ROM file to run on the emulator.

The "Hello World" tutorial running on mGBA

Here is the same ROM running on an actual Game Boy with the help of an EZ-Flash cartridge.

"Hello World" running on a Game Boy

C

Another approach that's slightly less low-level, is using the C programming language with the GameBoy Developer's Kit (GBDK).

Again, I installed and built it directly from GitHub.

git clone https://github.com/gbdk-2020/gbdk-2020.git
cd gbdk-2020
make

Most likely, the first attempt will result in this error ...

... Makefile:340: *** SDCCDIR is undefined.  Stop

... unless you read the instructions closer than I did and already set up the patched SDCC binaries for GBDK as outlined here.

  • Download the binaries from here.
  • Add the missing environment variable like this:
    export SDCCDIR=<PATH_TO_DOWNLOAD_DIRECTORY>.

Then, the next make attempt should be successful.

The gbdk-2020/build/gbdk/examples/gb folder contains many tutorials and example programs that you can just make and run.

This is e.g. the "Space" example running on mGBA.

The "Space" example running on mGBA

This development kits comes with a very detailed documentation.

Turbo Rascal

This one was knew for me and I only found out about it during this initial research. Apparently, the Turbo Rascal IDE is a thing that's going on for quite a while already, and it acts as an abstraction for programming all kinds of retro game systems.

The Turbo Rascal IDE supports all kinds of tretro consoles

Since I grew up programming Borland Turbo Pascal (to which this IDE obviously pays homage) I definitely need to check this out.

A first real quick try-out was already very promising. The IDE only needs to be configured so it finds the installed Game Boy assembler rgbasm and the emulator mGBA ...

Configuring Turbo Rascal IDE for Game Boy development

... and the the tutorials are already running.

A Turbo Rascal Game Boy tutorial running in mGBA

Resources

The most time I will spend initially is probably getting more familiar with the hardware and the programming models.

Luckily, the documentation is great. On this page e.g., there are dozens of tutorials and videos for getting started with Game Boy programming.

Will 2024 be the my year of the Game Boy 😆?