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
mere -w -I . chip8.merelowers the emulator — 4 KB of memory, 16 registers, the opcode table, a 64×32 framebuffer — to WebAssembly.dom_on_frameregisters arequestAnimationFrameloop; each frame runs a burst of CPU cycles, ticks the delay timer, and redraws the changed pixels viadom_canvas_fill_rect.dom_on_keyfeeds key presses onto the emulated keypad.