Skip to content

CHIP-8 emulator in Rust with desktop (SDL2) and web (WASM) frontends.

License

Notifications You must be signed in to change notification settings

Minipliy/chip8_rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CHIP-8 Rust Emulator

CI

A CHIP-8 emulator written in Rust with multiple frontends: desktop application using SDL2 and web version with WebAssembly for browser-based gameplay.

Features

  • Full CHIP-8 instruction set implementation
  • Desktop frontend with SDL2
  • Web frontend with WebAssembly (coming soon)
  • Keyboard input support
  • Play classic CHIP-8 games

Building and Running

Prerequisites

  • Rust (latest stable version)
  • SDL2 library
  • wasm-pack (for web version)

Installing SDL2

macOS:

brew install sdl2

Linux (Ubuntu/Debian):

sudo apt-get install libsdl2-dev

Windows: Follow the SDL2 installation guide

Installing wasm-pack

curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

Desktop Version

# Clone the repository
git clone https://github.com/yourusername/chip8_rust.git
cd chip8_rust/desktop

# Run with a ROM file
cargo run --release path/to/rom

Web Version

# Build the WebAssembly package
cd chip8_rust/wasm
wasm-pack build --target web

# Copy WASM files to website directory
cp pkg/wasm.js pkg/wasm_bg.wasm ../website/

# Serve the web version locally
cd ../website
python3 -m http.server 8000

# Open your browser to http://localhost:8000

Controls

The CHIP-8 uses a 16-key hexadecimal keypad. This emulator maps them to your keyboard (QWERTZ layout only):

Keyboard                    CHIP-8
+---+---+---+---+           +---+---+---+---+
| 1 | 2 | 3 | 4 |           | 1 | 2 | 3 | C |
+---+---+---+---+           +---+---+---+---+
| Q | W | E | R |           | 4 | 5 | 6 | D |
+---+---+---+---+     =>    +---+---+---+---+
| A | S | D | F |           | 7 | 8 | 9 | E |
+---+---+---+---+           +---+---+---+---+
| Y | X | C | V |           | A | 0 | B | F |
+---+---+---+---+           +---+---+---+---+

ESC - Exit emulator (desktop)

Finding ROMs

You can find public domain CHIP-8 ROMs here:

Technical Details

CHIP-8 Specifications

  • CPU: 16 8-bit registers (V0-VF)
  • Memory: 4KB RAM
  • Display: 64x32 monochrome
  • Stack: 16 levels
  • Timers: 60Hz delay and sound timers
  • Input: 16-key hexadecimal keypad

Implementation

The emulator consists of:

  • chip8_core: Platform-agnostic interpreter implementing the full CHIP-8 instruction set
  • desktop: SDL2-based frontend for native desktop execution
  • web: WebAssembly frontend for browser-based play

Resources

License

MIT License - feel free to use this project for learning and development.

Credits

This project was built following the CHIP-8 tutorial by aquova. The original tutorial code is licensed under CC0 1.0 Universal.


Made with Love and Rust