This is an interpreter for the CHIP-8 CPU that runs (almost) entirely on a CUDA kernel. Simple as that.
This is literally the first time I'm working with CUDA (besides cryptomining). Be aware that the code might be very, very bad, as well as the performance. The way I'm moving memory in and out of the GPU is slow and there are probably better ways of doing so. Also, Python might screw up the performance a bit.
I don't think I have to say this, but don't use this in any kind of production environment. This was just for fun and a way of learning new stuff. And, finally, feel free to contribute if you want to.
I was on vacation (at home due to the pandemic outside) and was wondering what can a GPU do (besides math). Computers are basically powerful calculators, so I was wondering if I could emulate another architecture inside a GPU. I thought at first about targeting a GameBoy CPU, or maybe an AVR which I'm familiar with, but they require some I/O i wasn't willing to implement. So I googled for "the simplest CPU to create an emulator for" (for real), and CHIP-8 came up.
The implementation is heavily based on Cowgod's Chip-8 Technical Reference and Werner Stoop's implementation.
Assuming you want to run this, all you gotta pass as argument is the path of a .ch8 file (CHIP-8 binary code). The code requires Numba, NumPy and SDL2 (for the display) to work. It has a few flags that help debugging and dealing with weird code, such as exiting on 0x0000
, infinite loops and even VF
compatibility mode for some test programs.
Right now there are a few test programs that more or less run on it:
- BC_TEST (passes)
- C8_TEST (error 16)
- chip8-test-rom (runs fine)
- SCTEST (error)
And a few programs that actually load:
The ROMs above have links to the repository I got them from if you want a copy.
- Keyboard is not implemented yet, so keyboard-related instructions will fail.
- Timer/delays/sound/etc do nothing. They still need to be coded.
- Display has a single mode (the original).
- RND crashes the CUDA interface when using a device different than 0. Seems to be a bug on Numba actually.
- Code runs on a single thread (I guess), so the GPU is just an expensive single-core CPU.
- The SDL code is messy and the performance is bad.