A CHIP-8 emulator implementation in C++ using SDL2 for graphics and input handling.
This project implements a CHIP-8 virtual machine emulator. CHIP-8 is an interpreted programming language that was originally used on 8-bit microcomputers in the 1970s. The emulator recreates the CHIP-8 virtual machine, allowing you to run classic CHIP-8 programs and games.
- C++ compiler (GCC, Clang, or MSVC)
- SDL2 development libraries
- Make (usually pre-installed on Unix systems)
macOS:
brew install sdl2Linux (Ubuntu/Debian):
sudo apt-get install libsdl2-devLinux (Fedora):
sudo dnf install SDL2-develWindows: Download SDL2 development libraries from libsdl.org
The project includes a Makefile that automatically detects your system and SDL2 installation. Simply run:
makeThis will:
- Detect your operating system
- Automatically find SDL2 using
pkg-configor platform-specific paths - Compile all source files
- Link everything into the
chip8_sdl2executable
If you prefer to compile manually or the Makefile doesn't work on your system:
Using g++/clang++ directly:
g++ -std=c++11 main.cpp src/Chip8.cpp -o chip8_sdl2 $(pkg-config --cflags --libs sdl2)Using clang++:
clang++ -std=c++11 main.cpp src/Chip8.cpp -o chip8_sdl2 $(pkg-config --cflags --libs sdl2)On macOS with Homebrew SDL2:
clang++ -std=c++11 main.cpp src/Chip8.cpp -o chip8_sdl2 -I/opt/homebrew/include -L/opt/homebrew/lib -lSDL2On Windows (MinGW):
g++ -std=c++11 main.cpp src/Chip8.cpp -o chip8_sdl2.exe -I<SDL2_PATH>/include -L<SDL2_PATH>/lib -lSDL2main -lSDL2The emulator requires three command-line parameters:
./chip8_sdl2 <Scale> <Delay> <ROM>-
Scale (integer)
- Window size multiplier
- Original CHIP-8 resolution is 64x32 pixels
- Example:
Scale = 10creates a 640x320 pixel window - Recommended values: 8-20 depending on your screen size
- Higher values = larger window, easier to see
-
Delay (integer, milliseconds)
- Cycle delay between instruction executions
- Controls emulation speed/timing
- Lower values = faster emulation
- Recommended values: 1-5 for normal speed, 10-20 for slower/debugging
- Example:
Delay = 2waits 2ms between cycles
-
ROM (file path)
- Path to the CHIP-8 ROM file (.ch8)
- ROM files are loaded into memory starting at address 0x200
- Example:
test_opcode.ch8ortetris.ch8
Run test_opcode.ch8:
Using Makefile (easiest):
make testOr manually:
./chip8_sdl2 10 2 test_opcode.ch8This runs the test ROM with:
- Window scale of 10x (640x320 pixels)
- 2ms delay between cycles
- ROM file:
test_opcode.ch8