A modern C++ implementation of the CHIP-8 virtual machine, built with clean architecture and modular design. This emulator accurately recreates the behavior of the original CHIP-8 system from the 1970s.
- Complete CHIP-8 instruction set implementation
- 64x32 pixel monochrome display with configurable scaling
- 16-key hexadecimal keypad support
- 4KB memory management
- Delay and sound timer emulation
- Raylib-based graphics rendering
- Cross-platform compatibility (macOS, Linux, Windows)
- C++17 compatible compiler (GCC, Clang, or MSVC)
- CMake 3.16 or higher
- Raylib graphics library
macOS (using Homebrew):
brew install raylibLinux (Ubuntu/Debian):
sudo apt-get install libraylib-devWindows: Follow the official Raylib installation guide at https://github.com/raysan5/raylib
- Clone the repository:
git clone https://github.com/Axel84727/Chip-8-Emulator.git
cd Chip-8-Emulator- Create and navigate to build directory:
mkdir build && cd build- Configure and build with CMake:
cmake ..
make- The executable will be created at
build/bin/chip_8_emulator
./bin/chip_8_emulator <rom_file>Example:
./bin/chip_8_emulator games/pong.ch8
./bin/chip_8_emulator roms/tetris.ch8The CHIP-8 keypad is mapped to your keyboard as follows:
CHIP-8 Keypad Keyboard Mapping
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
- ESC: Exit emulator
- Window can be closed normally through OS controls
The emulator is built with a modular architecture consisting of four main components:
- File:
src/CPU.cpp,include/CPU.hpp - Purpose: Handles instruction fetching, decoding, and execution
- Features: Complete CHIP-8 instruction set, registers, timers, stack
- File:
src/Memory.cpp,include/Memory.hpp - Purpose: Manages 4KB system memory and ROM loading
- Features: Memory read/write operations, ROM file loading, bounds checking
- File:
src/Graphics.cpp,include/Graphics.hpp - Purpose: Handles display rendering and window management
- Features: 64x32 pixel display, configurable scaling, Raylib integration
- File:
src/Input.cpp,include/Input.hpp - Purpose: Manages keyboard input and keypad state
- Features: Real-time key state tracking, CHIP-8 keypad mapping
- Memory: 4KB (4096 bytes)
- Display: 64x32 pixels, monochrome
- Registers: 16 8-bit general-purpose registers (V0-VF)
- Index Register: 16-bit register (I)
- Program Counter: 16-bit register (PC)
- Stack: 16 levels of 16-bit values
- Timers: 8-bit delay timer and sound timer (60Hz)
- Instruction Set: 35 instructions, 2 bytes each
- CPU Speed: Configurable (default: ~540 Hz)
- Timer Frequency: 60 Hz (as per specification)
- Display Refresh: 60 FPS
- Rendering: Hardware-accelerated via Raylib
- Input Polling: Real-time keyboard state checking
chip-8-emulator/
├── CMakeLists.txt # Build configuration
├── README.md # This file
├── include/ # Header files
│ ├── CPU.hpp # CPU class definition
│ ├── Graphics.hpp # Graphics class definition
│ ├── Input.hpp # Input class definition
│ └── Memory.hpp # Memory class definition
├── src/ # Source files
│ ├── CPU.cpp # CPU implementation
│ ├── Graphics.cpp # Graphics implementation
│ ├── Input.cpp # Input implementation
│ ├── Memory.cpp # Memory implementation
│ └── main.cpp # Main program entry point
└── build/ # Build output directory
└── bin/chip_8_emulator # Compiled executable
This emulator is compatible with standard CHIP-8 ROM files (.ch8 format). Popular games include:
- Pong
- Tetris
- Space Invaders
- Breakout
- Pac-Man variants
ROM files should be placed in the project directory or specify the full path when running.
The modular design makes it easy to extend functionality:
- CPU Enhancements: Modify
CPU.cppfor instruction set extensions - Graphics Features: Extend
Graphics.cppfor display enhancements - Input Methods: Update
Input.cppfor additional input devices - Memory Management: Enhance
Memory.cppfor advanced memory features
The emulator includes basic error handling and bounds checking. For development:
- Enable debug symbols:
cmake -DCMAKE_BUILD_TYPE=Debug .. - Use debugger tools like GDB or LLDB
- Add logging statements in individual modules as needed
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes with appropriate tests
- Ensure code follows the existing style
- Submit a pull request with a clear description
This project is open source. See the LICENSE file for details.
Created by Axel84727
- Original CHIP-8 specification by Joseph Weisbecker
- Raylib graphics library by Ramon Santamaria
- CHIP-8 community for ROM preservation and documentation