3 minutes
Creating a Gameboy Assembler + Linker (Part 1)
Introduction
Some time ago I’ve written a simple gameboy emulator in go. After I knew this little machine a little better, I thought why not write a game for it. I’ve done some FlappyBird clone with gbdk and C but the game had very poor perfomance. Most people writing gameboy games simply use assembler which gives you much better control over the whole thing.
After that, I’ve designed a very simple language which was explicitly designed for the gameboy which should be able to generate better gameboy assembler code then a generic C compiler. A few times I’ve tried to create a compiler for that language but I had no real idea how to do so, and so I failed… :|
A few weeks ago I thought: Just try a bottom-up approach instead of top-down? Thats why I started looking at linkers and assemblers.
The Linker
My first plan was to only create the assembler and use the linker from RGBDS which documented the format for the object files. But with that information, writing a linker should be trivial.
That whole thing, with a fixed input (the object file) and a static transformation of that input sounded like a job for F#. First of all: I’m very new to F# and have barely used it, so forgive me my naive implementation.
The job of the linker is to take blocks of code or data from the assembler, arrange them, so they all fit into the rom file and patch jumps, calls and other stuff to match the actual addresses.
In general we will have the following input:
|
|
Next time we will have a look at the CartridgeHeader of the gameboy and how this influences the linking process. Stay tuned.
Continue with Part 2