# chipx
A CHIP-8 emulator built in C using SDL2.
## About this project
CHIP-8 emulator in C using SDL2. If you don't know what that is, CHIP-8 is an old interpreted language from the 70s that a bunch of simple games were built on (Tetris, Pong, Space Invaders, etc), and building it forces you to actually understand how a CPU works instead of just knowing it in theory. I learnt a lot from this project, especially around bitwise operations, memory addressing, and what a program counter and stack actually do instead of just being words in a textbook. At one point I spent way too long debugging a bug where my call stack was silently chopping 16-bit addresses down to 8 bits because I typed uint8_t instead of uint16_t in one line, which broke everything and took real log digging to catch. I relied a lot on Cowgod's CHIP-8 technical reference and Columbia University's CHIP-8 design specification PDF to get the instruction set, timing behavior, and overall structure right. Also ended up building a little CLI tool so I could just run chipx <game name> from any terminal on the system instead of dealing with paths every time, which covered some shell scripting and PATH stuff along the way.
## Repository
š README.md
CHIP-8 Emulator
A CHIP-8 interpreter written in C using SDL2 for graphics, input, and audio.
Features
- Full CHIP-8 instruction set (all 35 opcodes)
- SDL2-based display, keyboard input, and square-wave audio for the sound timer
- Configurable emulation speed (instructions per frame)
- A
chipxcommand-line tool for launching ROMs from anywhere on your system, with fuzzy name matching and a numbered ROM browser - Built-in test targets for validating opcode correctness against the Timendus CHIP-8 test suite and the IBM logo test ROM
Demo
https://github.com/user-attachments/assets/fcc2e3ee-be03-496d-ba1d-31d5049c34c7
Requirements
gcc(or another C17-compatible compiler)make- SDL2 development libraries
On Arch Linux:
sudo pacman -S sdl2
On Debian/Ubuntu:
sudo apt install libsdl2-dev
Building
make
This produces the emulator binary at build/program.
Running a ROM directly
make run ROM="rom/Tetris [Fran Dachille, 1991].ch8"
or by fuzzy name:
make run rom=tetris
Installing chipx (recommended)
To install the emulator as a global command, callable from any terminal or directory:
./install.sh
This will:
- Build the project
- Copy the compiled binary and ROM library to
~/.local/share/chip8 - Install a
chipxcommand to~/.local/bin - Add
~/.local/binto your shell'sPATHif it isn't already there (fish, bash, and zsh are detected automatically)
Restart your terminal (or run exec fish / source ~/.bashrc, depending on your shell) after installing for the chipx command to become available.
Usage
chipx # numbered menu of every ROM
chipx tetris # fuzzy-match by name and launch directly
chipx space # multiple matches -> prompts you to pick one
chipx -h # help
Uninstalling
make uninstall
Controls
CHIP-8 uses a 16-key hexadecimal keypad, mapped to the following keys:
Keypad: Keyboard:
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
Controls vary per game ā check each ROM's accompanying .txt file where available, since key bindings are not standardized across CHIP-8 programs.
Press Backspace to quit the emulator at any time.
Testing
Run the full opcode/quirks test suite:
make test
Run an individual numbered test (e.g. the flags test):
make test-4
List all available ROMs:
make list
Project Structure
.
āāā main.c
āāā src/ # Core emulator implementation
ā āāā emulator_core.c
ā āāā emulator_operations.c
ā āāā emulator_display.c
ā āāā emulator_audio.c
āāā include/ # Headers
āāā rom/ # ROM library (see Credits)
āāā install.sh # One-step build + install script
āāā emu-runner.sh # The chipx command dispatcher (installed as `chipx`)
āāā Makefile
Credits
ROMs included in the rom/ directory are sourced from kripod/chip8-roms, a public domain compilation of CHIP-8 programs originally assembled by Revival Studios. Original authorship of individual games belongs to their respective creators, credited where known in each ROM's filename or accompanying .txt file.
The Timendus CHIP-8 test suite and the IBM logo test ROM are used for opcode/quirks validation during development.
References
This emulator's instruction set and behavior were implemented primarily based on:
- Cowgod's CHIP-8 Technical Reference ā the de facto standard opcode reference used by most CHIP-8 implementations
- Columbia University's CHIP-8 Design Specification ā used as a secondary reference for architecture and timing behavior
License
This project is licensed under the MIT License ā see LICENSE for details.
ROMs in the rom/ directory retain their own original licensing/public domain status as documented by their respective sources and are not covered by this project's license.