CHIP-8: 40 Games on an Arduino Uno

Back in 1977, you could pick up COSMAC VIP for just $275. After you had assembled it, you had a home computer with 2K of RAM, 512 bytes of ROM, a hex keyboard and TV output.

BASIC was not considered practical, given the lack of keyboard and memory. Instead a tiny virtual machine was squeezed into the first 512 bytes of RAM. So instead of writing code in hex instructions, you could write hex bytecodes for the virtual machine. Because the VIP itself was fairly slow, the CHIP-8 virtual machine ran amazingly slowly by modern standards -- about 1200 instructions per second. Today this makes CHIP-8 incredibly easy to emulate on almost anything. An Arduino can run CHIP-8 games using a fraction of its CPU -- not surprising given that the Arduino is about 100 times faster than the RCA 1802 in the COSMAC VIP.

I wondered how many of these games could fit on a 32K Arduino, using the Gameduino 2 for the display and controls. The answer is about 40, although some of the "games" are really just demos.

Starting with Corey Prophitt's open-source CHIP-8 emulator (https://github.com/prophittcorey/iC8) I ported it the the Arduino and added a UI for the Gameduino 2. The CHIP-8 VM runs in 4K -- too large to fit in the Arduino's 2K RAM. But there is plenty of memory on the FT800 GPU, so this implementation keeps the CHIP-8 memory in FT800 video RAM. In fact the games are each assigned 4K, and stored consecutively in memory, so the first 160K of FT800 memory holds the 40 games. A single pointer selects the base address of the current game, and the + and - buttons change this pointer.

The code is in the gd2-lib project in github (https://github.com/jamesbowman/gd2-lib/blob/master/chip8.ino), and the demo is included in the latest Gameduino 2 release

The bottom window on the screen shows the 4K of the CHIP-8 virtual machine - each byte is a colored pixel. For some games you can see them modifying memory as they run.

There are many collections of CHIP-8 games out there, so finding 40 is easy enough. The 40 games take 160K of FT800 memory, but after zipping need only 18K of Arduino flash. The code for the emulator and the UI take about 10K, so the total executable size is 29K.