A fully-functional Chip-8 emulator built from scratch in C++ with SDL2 graphics and audio support.
- All 35 Chip-8 opcodes implemented
- 64x32 pixel display with SDL2 rendering
- Keyboard input support
- Sound effects (beep tone)
- 60 FPS rendering
Chip-8 is a virtual machine from the 1970s designed to make programming video games easier on early microcomputers.
- Memory: 4 KB (4096 bytes)
0x000-0x1FF: Reserved for interpreter and fonts0x200-0xFFF: Program/ROM space
- Registers:
- 16 8-bit general-purpose registers (V0-VF)
- VF doubles as a flag register for arithmetic operations
- 16-bit index register (I)
- 16-bit program counter (PC)
- 8-bit stack pointer (SP)
- Display: 64×32 pixels, monochrome
- Timers:
- Delay timer (counts down at 60 Hz)
- Sound timer (beeps when > 0, counts down at 60 Hz)
- Stack: 16 levels for subroutine calls
- Keypad: 16-key hexadecimal input
- SDL2 library
Arch Linux:
sudo pacman -S sdl2Ubuntu/Debian:
sudo apt-get install libsdl2-devmacOS:
brew install sdl2- Clone the repo
git clone https://github.com/eko-071/chip8-emulator.git- Make it
make./chip8 <path-to-rom-file>Example:
./chip8 roms/PONG.ch8The original Chip-8 keypad is mapped to keyboard keys:
Chip-8 Keypad: QWERTY 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:
ESC- Quit emulator- Keyboard keys as mapped above
PONG:
- Left paddle:
1(up),Q(down) - Right paddle:
4(up),R(down)
TETRIS:
Q- RotateW- DropE- Move rightA- Move left
.
├── LICENSE
├── Makefile
├── README.md
├── roms # Some ROM files (.ch8)
│ ├── Blinky.ch8
│ ├── Pong.ch8
│ └── Tetris.ch8
└── src
├── chip8.cpp # Core emulator logic and opcodes implementation
├── chip8.h # Chip-8 class declaration
└── main.cpp # SDL2 setup, rendering, input handling and stuff
The emulator implements all 35 Chip-8 instructions, including:
- Arithmetic: ADD, SUB, AND, OR, XOR, shift operations
- Graphics: Draw sprites with XOR mode, collision detection
- Flow control: Jump, call/return subroutines, conditional skips
- Memory: Load/store registers, BCD conversion
- Timers: Delay and sound timer operations
- Input: Key press detection (blocking and non-blocking)
Graphics are rendered using SDL2:
- Each Chip-8 pixel is scaled 10× for visibility (640×320 window)
- XOR-based sprite drawing for collision detection
- 60 FPS rendering
Simple square wave generation at 440 Hz (musical note A) plays when sound_timer > 0.