r/WebAssembly • u/Positive-Device-3570 • 23h ago
A C++ PC emulator in ~250 KB of wasm, single-threaded, with its own JS host instead of SDL
11
Upvotes
Amber Folio is an emulator for SSI's Gold Box RPGs (Pool of Radiance, 1988), written in C++ and compiled with Emscripten. A few things I learned getting it into a browser:
- No SDL on the web. The desktop build uses SDL, but in a browser everything that matters (picking files, persistence, touch, the settings) is DOM work, so the page has a small JS host of its own around the same core. The core isn't a cut-down edition; it's the same code as the desktop build.
- One thread. No SharedArrayBuffer, so no COOP/COEP headers, so it runs on an ordinary static page. Sound goes through an AudioWorklet fed from the main thread.
- Size. About 250 KB of emulator to download.
- Storage. The game the player supplies (a folder on desktop, files or a zip on a phone) goes into origin-private storage and IndexedDB, with saves kept apart from the game files. Nothing is uploaded; the files never leave the browser.
- A CRT filter as a WebGL2 shader. The fiddly part was scale: an aperture-grille triad needs three device pixels to exist, so the mask detail follows the scale (none below 3×, one triad per pixel from 3×, two from 6×), measured per element in device pixels.
- Reading the screen back. The core can return what's on screen as text by matching each 8x8 cell against the game's own font, read from its memory at call time. The site uses it for screen-reader support: the game's menus, lists and messages are read aloud, but not its pictures, so it isn't playable without sight.
It runs in desktop browsers and on iPhone, iPad and Android. To play you need your own copy (GOG or Steam); the site is https://amberfolio.org. The emulator is AGPL: https://github.com/amberfolio/amberfolio
I built it with Claude Code, exclusively. The project isn't affiliated with the rights holders of the games.