CHIP-8 — written in Mere

A CHIP-8 CPU emulator compiled from Mere to WebAssembly. The same fetch-decode-execute core runs on all four Mere backends; here it renders to a <canvas> and is driven by a per-frame callback — dom_on_frame, a requestAnimationFrame binding added to contrib/dom for this emulator (the way 2048 needed dom_on_key and the ray tracer needed the canvas). The built-in ROM cycles the hex-digit glyphs 0..F, paced by the delay timer, so the screen animates on its own.

The ROM rides in the module as a bytes value; opcodes are decoded with the bitwise builtins and sprites are XOR-blitted into a 64×32 framebuffer. Keys map the CHIP-8 hex keypad (1 2 3 4 / q w e r / a s d f / z x c v).

What's happening

  1. mere -w -I . chip8.mere lowers the emulator — 4 KB of memory, 16 registers, the opcode table, a 64×32 framebuffer — to WebAssembly.
  2. dom_on_frame registers a requestAnimationFrame loop; each frame runs a burst of CPU cycles, ticks the delay timer, and redraws the changed pixels via dom_canvas_fill_rect.
  3. dom_on_key feeds key presses onto the emulated keypad.