# play-gb The Game Boy and Game Boy Color in the browser, for play-gb.supertux.com. The board is [gameboy-rust-fast](../gameboy-rust-fast) (held cycle for cycle to gameboy-python through gameboy-rust) behind wasm-bindgen; the page is play-nes's, and through it play-2600's and play-md's. scripts/build-wasm.sh # web/pkg/ (wasm-bindgen 0.2.128 and wasm-opt on PATH) scripts/build-dist.sh # dist/, the static site ROM=game.gbc node scripts/check-browser.mjs # headless Chromium: speed, sound, rewind, the page's # keys, a faked controller, touch, phone layouts ROM=game.gbc FRAMES=600 node scripts/bench-node.mjs scripts/deploy.sh [--no-build] ## What it does - A cartridge from a file, a drop, a link or `?rom=` (a .gb/.gbc, or a .zip/.7z holding one); the last twelve are kept on the device (IndexedDB) with their battery saves and a save state each. Nothing is uploaded. - The console is a Game Boy Color for a game that knows one (header byte $0143 bit 7), a Super Game Boy for a game made for one ($0146 = $03: its border and colours, 256 x 224), and the original Game Boy otherwise; Settings changes it per game. The SGB is gameboy-python's HLE (`sgb.py`, judged pixel-exact against the real SGB program on snes-python), through gameboy-rust's `sgb.rs`; the SGB's own default border and palettes are Nintendo's and not included, so its palettes start as the chosen Game Boy screen colours. A new border fades in as the real SGB's program fades it (measured on snes-python's low-level SGB, gameboy-python ac01aff). A Game Boy's screen can be the original's green, a Pocket's grey, or black and white. - No boot ROM is shipped (Nintendo's): games start from the state it leaves. An MBC3's clock is the page's `Date.now()` at power-on plus the game's time since (the board's `Clock::BoardFrom`; wasm has no wall clock to call), so the time between visits passes as on the cartridge; battery saves carry the 48-byte clock trailer BGB, SameBoy and mGBA share. - A Game Boy Color's colours are as its screen shows them, by SameBoy's model ("modern balanced": the LCD's brightness curve, then green mixed with a quarter of blue at gamma 1.6; Core/display.c, Lior Halphon, Expat, notice in src/lib.rs), or raw in Settings. - On a Super Game Boy, controller N is player N (up to four: Bomberman's battles and other MLT_REQ games); the keyboard and touch join player 1. - Keyboard: arrows or WASD, Z/X (or J/K) for B/A, Shift for Select, Enter for Start; F5/F7 save/load a state; P or Pause pauses; R or Backspace (held) rewinds; F9 sound on and off. Controllers go by position (bottom B, right A); an unmapped pad's hat-switch d-pad (Firefox on Windows with a Switch Pro controller) is read as play-nes reads it; the left trigger rewinds and the right stick pressed (R3) pauses. Touch: the 8-way round d-pad, B and A, Select and Start; in landscape the picture takes the full height and the pad floats over the margins. Settings can buzz on each touch press (Android; off at first). - 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 it came from; play-nes's `scripts/controls-drift.sh` says whether it has drifted. ## Run-ahead and rewind (play-nes's) - **Run-ahead** (Settings: Off, 1 or 2 frames): the real frame runs and gives the sound; then a save state, `n` frames more with the same buttons, paint, and the state back. - **Rewind** (hold R or Backspace, a controller's left trigger, or the bar's ⏪): a deflate-fast save state every 4 frames, about a minute kept (48 MB cap); holding loads the newest each frame and forgets it, so it goes back 4x as fast as the game ran. A Game Boy save state is 110-180 KB and takes about 0.1 ms each way natively, so both are cheap. Under Node the wasm runs 5.9x (Pokemon Crystal) to 8.7x (Tobu Tobu Girl Deluxe on a Game Boy) real time, rewind snapshots included; headless Chromium holds 59.6 frames a second at 3.0 ms a frame. The release profile (fat LTO, one codegen unit) matters to the board's speed and must stay: Cargo uses this crate's profile, not the board's. ## Included game [Tobu Tobu Girl Deluxe](https://tangramgames.itch.io/tobu-tobu-girl-deluxe) by Tangram Games (Simon Larsen, Lukas Erlandsson, Lukas Erlinghagen): code under the MIT licence, pictures, text, sound and music under CC BY 4.0 ([source](https://github.com/SimonLarsen/tobutobugirl-dx)). The file is the release build, as No-Intro's aftermarket set holds it ("Tobu Tobu Girl Deluxe (World) (GB Compatible) (Aftermarket) (Unl).gbc", SHA-1 of the zip 5196324506fbbb7420defd4928e2f2bacacbbb5e). Add a game: drop it in `web/games/` and add a line to `INCLUDED` in `web/app.js`. ## Notices `scripts/build-dist.sh` first writes `web/notices.html` (`python3 -I scripts/notices.py`): every component the wasm is built from, its licence, and its LICENSE and NOTICE files and the licence notices kept in its sources, verbatim (SameBoy's Expat notice beside the colour curve in `src/lib.rs` and in gb-apu-rust-fast, docboy's MIT notice in gameboy-rust-fast's `src/pixels.rs`), linked from the start panel and Settings, About. It stops the build when a family crate has no LICENSE file. A notice a pinned crate owes but does not carry goes in `notices/` (none here). The page opens with the included game's terms and attribution (`notices/games.json`; its MIT LICENSE is served beside it as `web/games/tobu-tobu-girl-deluxe-LICENSE.txt`). The build stops when a file in `web/games/` or `INCLUDED` has no entry there, or a game's SHA-1 is not its entry's. ## Status The board comes by path from `../gameboy-rust-fast` (private, alewman/gameboy-rust-fast; its own sound and CPU cores come by path too, so a git pin needs them pinned first); dist's version.json records the board's commit. Not done: the SGB's sound effects (SNES-side: Nintendo's BIOS data), the fade-out of the SGB's own startup border (Nintendo's artwork), the Game Boy Printer and link cable.