# emu-galaga The 1981 Namco Galaga arcade board in the browser, for players, at **https://emu.supertux.com**. Three certified Z80 cores ([z80-rust-fast](https://github.com/alewman/z80-rust-fast), unchanged, by commit), a board written in Rust from the hardware documents in `docs/` and checked against MAME frame by frame, compiled to WebAssembly, behind a page that is a cabinet rather than a lab notebook. This is the successor to the Galaxian demo at https://galaxian.supertux.com (repository `z80-wasm`), which proves the pipeline on the page. This one keeps the proof in the repository and gives the visitor the game: the ROM set is verified and remembered on the device, attract mode starts on its own, free play by default, a running game is saved when the page is hidden and offered back on the next visit, keyboard, gamepad and touch, installable and offline. On a phone the controls are an arcade's: a stick on the left (left and right only; a thumb that lands on it steers wherever it slides until lifted), FIRE on the right, Start (and Coin, when free play is off) between them. Turned on its side, the picture takes the full height and the controls float in the black either side, Start and Coin in the top-left corner. The bar has pause. Rewind: hold R or Backspace, a controller's left trigger, or the bar's ⏪ button; the board keeps a deflated snapshot every 4 frames, about a minute (3.4 MB), and each held frame loads the newest one (0.19 ms under Node). Keyboard: ← → or A D move, Space, Z or X fire, Enter or 1 start (2 for two players), Shift, 5 or C coin, P or Pause pause (not Esc, which leaves full screen), F5 / F7 keep and load a state of your own beside the one saved on hide, F9 sound. A controller: any face button fires, Back coins, Start starts (held, two players), the right shoulder or the right stick pressed (R3) pauses; one the browser leaves unmapped (Firefox on Windows with a Switch Pro) has its d-pad read from its hat-switch axis. Settings can buzz on each touch press (Android; off at first), and are kept as `emu-galaga-settings` (until 2026-11-23 `settings`, read once so dip switches carry over). The controls are the family's (emulator-lineage `docs/proposals/2026-11-play-controls.md`): `web/controls.js` is a copy of play-nes's, its second line naming the play-nes commit, checked by play-nes's `scripts/controls-drift.sh`. The manifest is `manifest.json` because the server sends `.webmanifest` as octet-stream with nosniff. ## Where it stands (2026-09-11) All six stages of [docs/build-approach.md](docs/build-approach.md) are done. **The board reproduces MAME 0.285's reference runs** (`oracle/runs.json`, regenerated by `oracle/make_references.sh` through `oracle/mame_dump.lua`; the references hold RAM contents and device writes, no ROM bytes): | Run | RAM at every record | Events | Screenshots | | --- | --- | --- | --- | | boot-720 (power-on self-test) | identical, 25 records | all 421 identical | 2 of 2 pixel-identical | | attract-1800 (30 s: test, title, demo) | identical, 31 records | all 60,885 identical | 5 of 5 pixel-identical | | game-2400 (coin, start, moves, shots) | identical, 41 records | all identical | 5 of 5 pixel-identical | Nothing is pinned: the board reproduces MAME's scheduler, down to the slice boundaries its two MCUs impose (`docs/cpu-and-timing.md`). An earlier one-note difference in the sound CPU, caused by a shared-RAM race the old scheduler ordered differently, went with it (2026-10-02). **Sound**: the WSG rendered from the identical register stream correlates 0.969 sample for sample with MAME's recording of the attract demo at equal RMS. The 54xx noise chip is a hand-written model fitted to MAME's recordings of the power-on bang and a player death (envelope correlation 0.965, level within 8 %, spectrum at L1 distance 0.19); `docs/sound-hardware.md` records what was measured and where the model departs from MAME's source. **The page**: `web/`, plain ES modules, no framework. `node web/check-browser.mjs` serves `dist/`, feeds the ROM set to the page in headless Chromium, boots through the self-test into attract mode, starts a game with key events, rewinds with Backspace and R, checks the page's keys and a faked controller (R3, LT, a hat switch, every face button firing) and the settings key's move, and screenshots desktop and phone layouts. `ROMS=rom/galaga.zip node web/check-touch.mjs` puts fingers on the stick and buttons, in portrait and on its side, pauses from the bar, buzzes with haptics on, and rewinds by touch. On a busy machine give them their own `PORT=` and `DEVTOOLS=`. ## Pins | What | Value | | --- | --- | | z80-rust-fast | commit `5015d98` (`Cargo.toml`), main after PR #1 | | z80-python, whose certification the core's rests on | `cab1598` | | MAME, the board oracle | 0.285 on the build machine | | rustc | 1.93.1 (`rust-toolchain.toml`) | | wasm-bindgen | 0.2.128, crate and CLI | | wasm-opt | binaryen version_132 | | `.wasm` | 301,148 bytes built, 256,612 after `wasm-opt -Oz` (the `wasm/` crate) | ## Building and checking ``` cargo test --release # the oracle and screenshot tests need rom/galaga (extracted set); they skip without it cargo run --release --bin galaga-oracle # the comparison, with --write DIR for diffing and EMU_GALAGA_WATCH* for tracing cargo run --release --bin galaga-audio -- attract-1800 out.wav # sound of a run, to compare with MAME's -wavwrite scripts/build-dist.sh # wasm + page into dist/ node web/check-browser.mjs # the page in headless Chromium with rom/galaga.zip scripts/deploy.sh # dist/ to emu.supertux.com (this machine's docker stack) ``` CI runs fmt, clippy (native and wasm32), the tests (ROM-dependent ones skip) and builds `dist/` on every push. ## A link for phones `?rom=` fetches the set on load, from that host straight into the browser. Verified 2026-09-11: the archive.org item `galaga_1981` holds a byte-identical copy of the set (SHA-1 `bf07d0b8…`), and its `/cors/` path carries the headers browsers need (the page rewrites `/download/` to it): ``` https://emu.supertux.com/?rom=https://archive.org/download/galaga_1981/galaga.zip ``` ## ROM notice This repository contains no Galaga ROMs, PROMs, graphics, or recordings, and never will. The page runs from the visitor's own legally obtained MAME `galaga` parent set, verified member by member in the browser and never uploaded. See [docs/rom-manifest.md](docs/rom-manifest.md). ## Deploying `emu.supertux.com` is this machine's docker stack: `deploy/emu.yml` (an `nginx:alpine` container behind Traefik, a copy of the stack's Galaxian service with the name changed) and `scripts/deploy.sh`, which builds `dist/`, rsyncs it to `/docker/appdata/emu`, installs the compose file if it changed, starts the container if it is not running, and prints the deployed commit, which the page's About panel shows. ## License MIT, see `LICENSE`. Hardware facts in `docs/` are restated from MAME's source (every file consulted is BSD-3-Clause, listed in `docs/README.md`) with the source named on each; the two algorithms transcribed from it, the 05xx starfield and the MB88xx-derived 51xx reply pipeline, say so in place.