A Game Boy was the first big investment in my life that I did with my own money. I bought a Game Boy with Super Mario Land 2 as an eight year old kid 17 years ago. Last week I’ve decided to do something new I’ve never done before: writing a Game Boy emulator.
Knowing nothing about the architecture and just a little bit of Intel assembler, I began with a Google search… there are some very helpful documents, e.g. Everything You Always Wanted To Know About GAMEBOY gives you an overview about the general architecture, how the memory map looks like, I/O, reserved memory locations and more.
By that we know that the Game Boy has a CPU based on a Z80 processor. ZiLOG, the company behind the Z80, published the document Z80 Family CPU User Manual online. But very quickly I realized that the Game Boy CPU is not exactly the Z80, so there are some differences. Gameboy (LR35902) OPCODES is an extremely useful table with the Game Boy CPU opcodes, its machine codes and other useful stuff.
For the sake of simplicity I decided to go with C and OpenGL/GLUT. At first I wanted to see something on the screen, so I wrote a simple program that just scans the binary and dumps the data into a texture in the specified Game Boy sprite format. And it worked as expected. Anyone knows what game this is? ;-)
Now I’m trying to write the CPU. At first it seems to be the most difficult part, because the Game Boy CPU seems to have over 200 instructions… apparently most of them do the same things but with different registers, so I still have to think about a way to express it in a more modular way.
My current code can at least interpret most of the initialization code of Tetris. But I have no I/O yet though… Still much to do, but I hope that I’ll see the Tetris start screen some day.