Skip to content

soumen-pradhan/chip8-wasm

Repository files navigation

chip8-wasm

A Chip 8 Emulator in Webassembly. Renderer in WebGPU.

Demo: soumen-pradhan.github.io/chip8-wasm

How does it work ?

The core logic of Chip-8 spec is implemented in Rust, compiled to WASM (WebAssembly). The compiled WASM module exposes its display ram and set_key functions.

The exposed Display ram is then used as a texture for our canvas element. This allows us to use the WebGPU API and efficiently scale and draw the display. The exposed pointer is stable, since no rellocation happens.

This decouples the emulator logic and render logic.

Building and Running

Ensure you have wasm-pack installed.

Tested on

Tool Version
chrome 115
node 18.16.0
npm 9.5.1
cargo 1.71.0
wasm-pack 0.12.1

Dev Mode (Live Reload)

npm run dev

Caution:

  • The first time you run npm run dev, a resolve error will be displayed (related to esbuild), however the packages will be served correctly. This will not happen for subsequent builds or production build.
  • You can add multiple rust crates, but vite will compile all of them regardless of which crate you modified.

Build for production

npm run build

Resources

Chip-8

WebGPU

ROMS