Skip to content

bernsteining/chiphuit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chiphuit

Yet another chip8 emulator, written in Rust compiled to WASM. Feel free to read the blogpost about how it works.

play

The emulator is hosted online here if you want to give it a try without building from sources, you will have to give the emulator the game you want to play, here's some chip8 games to download. Works on touchscreen devices as well.

The emulator with the debugger
The emulator playing Tetris with the debugger view next to it

The emulator also has a debugger view that allows to

  • See the emulator internal variables
  • Load a JSON VM snapshot to the emulator in order to replay from a specific snapshot
  • Copy the current VM snapshot in your clipboard in JSON format
  • Trace the VM snapshot at each CPU cycle
  • Dump all the traced VM snapshots to your clipboard in JSON format
  • Pause / play the emulator & return to gamepad view

An example of VM snapshot is avalaible in assets/tetris_snapshot.json.

build & run from sources

lazy docker way:

docker build -t chiphuit -f Dockerfile .
docker run -p 4000:4000 chiphuit:latest

And visit http://127.0.0.1:4000 with your favorite web browser.

not the lazy docker way:

Make sure you have rust toolchain installed and up to date.

If not, install Rust toolchain:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Download the wasm-bindgen-cli and basic-http-server crates.

cargo install basic-http-server wasm-bindgen-cli

wasm-bindgen and cargo versions must match, make sure cargo is up to date:

cargo update

Add wasm to rustup targets:

rustup target add wasm32-unknown-unknown

Then run,

cargo build --release

Then run wasm-bindgen to generate JS bindings for the wasm file:

wasm-bindgen ./target/wasm32-unknown-unknown/release/chiphuit.wasm \
--out-dir build \
--no-typescript \
--target no-modules \
--remove-name-section \
--remove-producers-section \
--omit-default-module-path \
--omit-imports

Finally, serve the emulator and play it on your favorite browser @ http://127.0.0.1:4000

basic-http-server build/

Demo

Here's a video of the emulator running on an iPhone.

The emulator running

Documentation

Generate & read the documentation of the project

cargo doc --document-private-items --open

Useful links that helped me understand the basics of writing an emulator:

How to write a chip8 emulator by Laurence Muller

Wikipedia page describing chip8 architecture, opcodes, display etc

Awesome chip8 rom to test opcodes correctness