In this article we will prepare the necessary development environment to program games in C using GBDK . For this, we will use the Linux binary compatibility layer since GBDK requires a patched version of SDCC and compiling it on FreeBSD is very complicated, believe me, I’ve tried. We will also install the Emulicious emulator/debugger which will help us visualize the state of the microprocessor, the system memory, and the video memory graphically.
The manual is divided into several sections:
Linuxulator
We enable linuxulator, the easiest way is to use mrclksr’s script.
First, we make sure that generic compatibility is not enabled:
Now we clone mrclksr’s script and install the chroot:
cd linux-browser-installer
./linux-browser-installer install chrome
We enable the chroot at boot:
Now every time we run a Linux binary, it will run with the Linux compatibility layer.
GBDK
In reality, GBDK is a set of C libraries for programming in GameBoy, the compiler itself is SDCC, and when we download GBDK, a patched version of SDCC is already included.
We install the compiler/libraries:
cd ~/GBDEV
wget https://github.com/gbdk-2020/gbdk-2020/releases/download/4.0.6/gbdk-linux64.tar.gz
tar xvzf gbdk-linux64.tar.gz
cd gbdk/examples/gb/
make
Example
A simple example could be this, it shows a text on the screen and waits for us to press START:
vi ~/GBDEV/code/00.c
#include <gb/gb.h>
#include <stdio.h>
void main()
{
printf("Welcome to GAMEBOY\nProgramming");
printf("\nPress Start");
waitpad(J_START); // other keys are J_A, J_UP, J_SELECT, etc.
printf("\nIsn't it easy!");
}
We compile the example:
NOTE: We can find all the documentation about GBDK functions in this link .
Debugger Emulator
Emulicious is written in Java so we will have to download the JAR file and run it.
We download the emulator/debugger:
https://emulicious.net/downloads/
We run it:
cd ~/GBDK/Emulicious
unzip Emulicious.zip
java -jar Emulicious.jar
We tweak some parameters, in my case I prefer to see the display with colors that remind me of the gameboy pocket:
Options -> Emulation -> Game boy -> Color scheme -> Green
A little problem I had with Emulicious is that it doesn’t recognize the USB controller, but with a software called
antimicro
we can map the controller to keys:
We just check the keys of Emulicious:
Options -> Configure Input
Now we go to antimicro:
And we map each of the keys, for example the up/down arrows:
As we can see there are predefined presets, normal buttons are mapped in the same way by selecting the key to simulate:
We leave antimicro in the systray and open the ROM from Emulicious:
/compat/ubuntu/gbdk_code/00.gb
It will load the ROM and if we press the Start key the message will appear:
The most interesting thing about Emulicious is that it is also a debugger, very useful for detecting and debugging bugs:
Another option is to use bgb through wine, this emulator is well known as it appears in most videos and tutorials: