CHIP-8 for Gamebuino
Posted: Thu May 25, 2017 8:36 pm
I have ported a CHIP-8 interpreter. It can load CHIP-8 roms off the SD card, and controls can be configured to play most CHIP-8 games. Unfortunately the performance is too slow to be all that usable.
The ram of the CHIP-8 is 4kb, while the Gamebuino only has 2kb. This means that I had to swap out CHIP-8 ram to SD constantly, and keep a tiny buffer on the Gamebuino for that ram. The SD library and screen buffer together take up about half the available ram, and the other globals, plus extra space for stack variables, means that there is very little room for the buffer. I started with the smallest buffer I was comfortable with using at 156 bytes. This translates to 26 "pages" of memory, which I wrote out to up to 26 separate files on the SD card, each indexed by a different letter (hence 26). This kept the code for swapping to and from the SD card very simple. I tried increasing the buffer size, but performance actually appeared to be worse (perhaps because of the increased cost of reading and writing a larger buffer). Therefore, I don't think there is an easy way to improve performance much without redesigning the way I swap the ram. I know I could do a read-only buffer for code, but I would need to have room for two buffers, and I can't increase the size of the existing buffer very much before it starts to corrupt ram. If anybody has any other ideas about improving performance, I would be glad to hear them.
The way roms are selected to be loaded from the SD card is by using a modified version of the Gamebuino menu library function that displays strings stored in ram instead of progmem. I actually reuse the buffer for the CHIP-8 memory for the strings, so there is not that much space for them. I wouldn't put more than 10 roms on the Gamebuino at a time, because it will start corrupting data after about 10 full-length filenames. This file selector menu might be useful if it could be made more generic, and I might try to use it for my AttoTracker if I can get it working. Reading and writing to the SD card is frustrating because of how many resources it uses...
Since the CHIP-8 has 16 keys, and the Gamebuino only has 7, I knew that not all CHIP-8 games would work on the Gamebuino, but most games seem to use a small subset of the keys. I decided to make it so that the key bindings can be chosen before loading a game, reserving C for the menu. The current set of bindings is saved in EEPROM.
While somebody has already started work on a CHIP-8 interpreter for the Gamebuino previously, I was interested in the challenge of being able to support loading roms from the SD and supporting the full address range of the CHIP-8. I guess I succeeded in everything except it being usable for anything...
Download binary: CHIP8.zip
Source code: https://github.com/wuuff/chip-8-gamebuino