A complete CHIP-8 emulator implementation written in C++ with SDL2 and OpenGL rendering.
CHIP-8 is an interpreted programming language developed in the 1970s for early microcomputers. It was designed to make game programming easier by providing a simple virtual machine with 35 opcodes. This emulator accurately replicates the CHIP-8 system, allowing you to run classic CHIP-8 programs and games.
- Full implementation of all 35 CHIP-8 opcodes
- 64x32 monochrome display with configurable scaling
- 16-key hexadecimal keypad input
- Configurable CPU cycle delay for game speed control
- SDL2-based graphics rendering
- Cross-platform support
- CMake 3.14 or higher
- C++17 compatible compiler
- SDL2
- GLUT (OpenGL Utility Toolkit)
- ImGui (included in external/)
macOS:
brew install sdl2 cmakeUbuntu/Debian:
sudo apt-get install libsdl2-dev cmake freeglut3-devFedora:
sudo dnf install SDL2-devel cmake freeglut-develmkdir build
cd build
cmake ..
makeThis will create an executable named main in the build directory.
./main <scale> <delay> <rom>Arguments:
scale: Video scale factor (e.g., 10 for 640x320 window)delay: CPU cycle delay in milliseconds (lower = faster, typical: 1-5)rom: Path to CHIP-8 ROM file
Example:
./main 10 2 ../chip8-test-rom.ch8The CHIP-8 keypad is mapped to your keyboard as follows:
CHIP-8 Keypad Keyboard Layout
┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐
│ 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 │
└───┴───┴───┴───┘ └───┴───┴───┴───┘
Press ESC to quit the emulator.
chip-8/
├── includes/
│ ├── chip8.h # CHIP-8 CPU and memory definitions
│ └── platform.h # SDL2 platform layer
├── src/
│ ├── chip8.cpp # CHIP-8 emulator core implementation
│ └── platform.cpp # Platform-specific rendering and input
├── external/
│ └── imgui/ # ImGui library files
├── main.cpp # Entry point and main loop
├── CMakeLists.txt # Build configuration
├── chip8-test-rom.ch8 # Test ROM
└── README.md
- Memory: 4KB RAM (4096 bytes)
- Display: 64x32 pixels, monochrome
- Registers: 16 8-bit general-purpose registers (V0-VF)
- Stack: 16 levels for subroutine calls
- Timers: 60Hz delay and sound timers
- Instruction Set: 35 opcodes with table-based dispatch
- CHIP-8 Test ROM - Included test ROM for verification
- More CHIP-8 Games
- CHIP-8 Technical Reference
This project is open source and available for educational purposes.
