Core S2 Software Solutions

Core Gameboy – A C99 Gameboy Emulator

Imran Nazar has written a great GameBoy emulation tutorial for the Javascript programming language, using new features of the HTML5 standard (mainly canvas). I’ve gone through six out of the 10 articles, and have posted my code onto GitHub for others to use. I chose to develop the code in pure C (the 1999 standard) for the sake of multi-platform support, and to allow component-integration with other apps I have (the OpenGL bitmap rendering system is being ported to a desktop version of CoreBasic).

The GameBoy device is essentially a custom Intel 8080 / Z80 processor, with a 160 x 144 4-color LCD screen, and 8 button input. From the outside perspective, the device seems easy to emulator, but internally, it is much more complex. The instruction set is not particularly complex, though it does allow for single and double byte instructions (which can complicate emulation), and RAM / ROM is mixed in the same continuous memory layout. What really has been challenging to implement has been the graphics architecture: the LCD screen is not directly mapped in memory in the sense that it is the content which the processor should manipulate. Instead, it is a special formatted buffer that expects definitions of sprites (small bitmaps) and sprite-maps (how these sprites are to be laid out on-screen). To make things even worse, there are several layers and a pseudo-mixed buffer for the sprite sources and maps. Regardless, it’s been a blast to figure out the basic mechanics and implement each of Imran’s articles in C.

One of Imran’s article’s best feature is the¬†addition¬†of some visualization graphics. The outlines and details of how memory is mapped, how sprites are laid out in memory, and others are really powerful in their ability to get the main points across. Thinking back, I still feel as though I should of have put more graphics and helpful diagrams in my computer-graphics book. I’ll absolutely work on that, especially in the new “introduction to matrices” chapter for the second edition.


An example graphic from Imran’s site: the general memory-layout of the Gameboy device.

As of right now, I have the basic emulator up and running in OSX, with I/O and graphics support. I’ll continue developing over the holidays on this system and hopefully get more and more features (such as the window sprite layer and ROM bank-switching) implemented. Others can easily integrate it with Visual Studio (Windows) and GCC (Linux). Check out the source code from here, on GitHub!

For those that would like to develop their own Gameboy Emulator (a great programming exercise), check out the following links that I’ve used to compliment Imran’s work, and to help me better understand the system as a whole:

This entry was posted in News & Updates. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


Sites map