CHIP-8 Emulator
A CHIP-8 emulator built from scratch in Rust, featuring a complete instruction set implementation, display rendering, keyboard input, timing systems, and audio output.
Overview
This project is a complete CHIP-8 emulator written from scratch in Rust. The emulator recreates the original CHIP-8 virtual machine by implementing its memory model, registers, timers, instruction set, display system, keyboard input, and sound output.
The project was built as a systems programming exercise focused on understanding how CPUs execute instructions through the fetch-decode-execute cycle. It emulates the original 1970s architecture while providing a modern desktop interface using Rust.
Features
- Complete CHIP-8 instruction set implementation
- 4KB emulated memory system
- 16 general-purpose registers (V0-VF)
- Program counter, stack, and index register support
- 64x32 monochrome display renderer
- Pixel scaling for modern displays
- Keyboard input mapped to CHIP-8 hexadecimal keypad
- Delay timer implementation
- Sound timer with audio output
- ROM loading and execution
- Real-time FPS counter in the window title
- Font sprite loading and rendering
Concepts Demonstrated
- Emulator and virtual machine development
- CPU fetch-decode-execute architecture
- Opcode decoding using bitwise operations
- Memory management and address manipulation
- Stack operations and subroutine execution
- Register-based CPU design
- Real-time rendering and frame updates
- Keyboard input handling
- Audio generation and playback
- Timing systems and synchronization
- State management in Rust
- Modular software architecture
Architecture
The emulator executes CHIP-8 programs by repeatedly performing the CPU cycle:
- Fetch the next opcode from memory
- Decode instruction fields using bit masking
- Execute the corresponding operation
- Update timers and display state
- Render the display buffer
The display is stored as a 64x32 boolean framebuffer and scaled to a larger window for visibility. Keyboard input is continuously mapped to the CHIP-8 keypad layout, allowing ROMs to receive user input exactly as they would on the original system.
Technical Details
- CPU execution rate of approximately 600Hz
- Display refresh rate of 60Hz
- 35 CHIP-8 opcodes implemented
- 16-key hexadecimal keypad support
- 64x32 monochrome framebuffer
- Audio generated through a sine wave beeper
- Window rendering via minifb
Requirements
- Language: Rust
- Cargo package manager
- Desktop platform supporting minifb
Libraries Used
- Rust
- minifb — window creation and display rendering
- rodio — audio playback
Learning Outcomes
This project provided hands-on experience with low-level systems programming concepts including CPU architecture, instruction decoding, memory management, bitwise operations, and real-time application development. Building the emulator from scratch reinforced an understanding of how software interacts with virtual hardware and how classic computing systems execute programs.