/wasm-chip8

💾 WebAssembly CHIP-8 emulator

Primary LanguageRust

💾 CHIP-8

A CHIP-8 emulator written in Rust, compiled to WebAssembly through wasm-pack, and exposed with Typescript thanks to wasm-bindgen.

CHIP-8 is an interpreted programming language, developed by Joseph Weisbecker. It was initially used on the COSMAC VIP and Telmac 1800 8-bit microcomputers in the mid-1970s. CHIP-8 programs are run on a CHIP-8 virtual machine. It was made to allow video games to be more easily programmed for these computers.

Overview

Timing

The emulator synchronizes to video with the requestAnimationFrame function, which usually matches the refresh rate of the display.

  • CPU runs at 500Hz
  • Timers run at 60Hz

At every repaint, enough emulator cycles are run to simulate that the duration for one frame has passed. Given an ideal refresh rate of 60FPS, that is 1/60s.

ASI

✅ All 35 opcodes are implemented.

Known limitations

Extensions are not implemented.

Tests

Usage

Sample code

import { Chip8 } from '@kabukki/wasm-chip8';

const canvas = document.querySelector('canvas');
canvas.width = Chip8.VIDEO_WIDTH;
canvas.height = Chip8.VIDEO_HEIGHT;

const input = document.querySelector('input');
input.addEventListener('change', async (e) => {
    try {
        const rom = new Uint8Array(await e.target.files[0]?.arrayBuffer());
        const emulator = await Chip8.new(rom)
        emulator.canvas = canvas;
        emulator.start();
    } catch (err) {
        console.error(err);
    }
});

API

The full API is documented on the wiki!

Resources

Chip-8 reference

Tooling

Examples & tutorials

ROMs