A simple CHIP-8 emulator implementation using Rust and SDL2 for graphics and input handling.
This project implements a CHIP-8 emulator with:
- 4KB of memory
- 64x32 monochrome display
- 16 general-purpose registers
- 16-key hexadecimal keypad
- Two timers (delay and sound)
The project is split into two main components:
The core emulator handles:
- CPU emulation
- Memory management
- Display buffer
- Input processing
- Timer management
Handles:
- Window creation and rendering
- Input processing
- Timing control
- Display scaling (15x)
Below is the detailed class diagram showing the relationship between Frontend and Emulator components:
0x000-0x1FF: Reserved for interpreter (includes font data)
0x200-0xFFF: Program ROM and work RAM
- Resolution: 64x32 pixels
- Monochrome (black and white)
- Scaled 15x in the window (960x480)
Original CHIP-8 Keypad mapping to modern keyboard:
1 2 3 4 → 1 2 3 C
Q W E R → 4 5 6 D
A S D F → 7 8 9 E
Z X C V → A 0 B F
The emulator runs in a continuous loop at 60 FPS, with each frame consisting of:
-
Input Processing
- Detect key presses/releases
- Map modern keys to CHIP-8 keys
- Update emulator key states
-
CPU Execution
- Execute 10 instructions per frame
- Fetch opcode from memory
- Decode and execute instruction
- Update system state
-
Timer Updates
- Update delay timer
- Update sound timer
- Handle sound when timer > 0
-
Display Update
- Clear screen
- Draw active pixels
- Scale display output
- Present frame
Below is a sequence diagram showing what happens when a key is pressed (e.g., 'W' key):
- Build the project:
cargo build --release- Run a ROM:
cargo run path/to/rom- Use the keyboard mapping shown above
- ESC to quit
- Each key maps to its corresponding CHIP-8 key
- Full CHIP-8 instruction set support
- Accurate timing (60 Hz)
- Sound support (beep when sound timer > 0)
- Configurable CPU speed (10 instructions per frame)
- Uses SDL2 for graphics
- Each CHIP-8 pixel is rendered as a 15x15 rectangle
- Black background with white pixels
- VSync enabled for smooth rendering
The emulator follows the original CHIP-8 specifications:
- Instructions are 2 bytes long
- Programs start at memory address 0x200
- Built-in font set for hexadecimal digits
- Stack limited to 16 levels
- No floating-point operations
- Rust
- SDL2
- rand (for random number generation)
Requires:
- Rust toolchain
- SDL2 development libraries
- Cargo package manager
- Audio implementation
- Configuration file support
- Save state functionality
- Debug mode
- Custom key mapping support
- Performance monitoring