mattkolega/zig-8
🕹️ CHIP-8 interpreter written in Zig
A rewrite of my CHIP-8 interpreter using Zig.
In 2023, I wrote a CHIP-8 interpreter in C. I recently had another look at the code and thought it would a cool exercise to rewrite it in a different language. Zig was chosen to be used because it's fairly similar to C and I thought this project would provide a good opportunity to learn it.
CHIP-8 (COSMAC VIP) and SCHIP (SUPER-CHIP 1.1) behaviours are implemented.
Sokol is used for graphics and input, and miniaudio is used for audio.
Requires version 0.13 of the Zig compiler. Tested on macOS, but it should work on any OS supported by Zig.
# Clone the repo along with submodules
git clone --recursive https://github.com/mattkolega/zig-8.git
# Navigate to the repo directory
cd zig-8
# Build and run executable
# The executable will be located in the zig-out folder
zig build run
Either run zig build run
at the root directory, or navigate to the output directory (default is zig-out) and run ./zig-8
.
Launching the interpreter will open a file dialog to load .ch8
ROM files.
Command line arguments can optionally be given to the interpreter to alter its execution.
-h, --help
Display this help message and exit.
-c, --cycles <usize>
Set the number of cycles per second for the interpreter.
-m, --machine <str>
Set the interpreter type. Possible values: chip8 | schip
Original CHIP-8 computers supported hexadecimal keypads for input. This interpreter maps those keys to the left side of a QWERTY keyboard. The keys needed to be pressed during execution depend on the ROM file.
1 2 3 C 1 2 3 4
4 5 6 D -> Q W E R
7 8 9 E A S D F
A 0 B F Z X C V