At a glance

Crates
legaia-web-play (the play runtime, over legaia-web-minigames, the minigames runtime) and legaia-web-patcher (the ROM patcher) under legaia-web-viewer (the inspectors and the tool bundle’s cdylib); legaia-web-play-bundle is the play bundle’s, which the play, minigames and modes pages load: two wasm bundles
Session
legaia_engine_session::BootSession over the page’s audio output - the type the native window runs
Frame
tick_frame() calls the session’s tick in the native frame order and returns the scene a door just walked into
Draw side
Resolved against the same scene resources the host built at scene entry; nothing is decoded twice
Parity
Disc-gated tests pair this host against the native window; a source-derived gate fails when a screen reaches one host only

Module map

engine-session::BootSession the native window's own session web-play - play page: wraps the session runtime load, pad, tick, state play map, player, NPC draws play_dialog reading box play_cutscene / play_fmv prologue, movies play_camera follow + orbit play_menu pause menu play_battle* live fights, 3D, effects play_shop merchant, banners play_sfx / bgm / xa sound play_minigames in-world minigames same bundle, no session minigames web-minigames: standalone playable page field_scene / field_npc web-viewer: assembled maps, NPC pages arts_view / equipment_view web-viewer: viewer pages scene_export web-viewer: .glb export rom_patcher web-patcher: client-side, nothing uploaded
The play runtime is the engine, not a re-implementation of it: it holds the same session type the native window runs, built over a scene host assembled in memory from the visitor’s own disc image. The other surfaces share the format crates and the render kernels but run no session. Four crates build the bundle: web-play holds the play runtime, web-minigames the minigames runtime, web-patcher the ROM patcher, and web-viewer the inspectors; web-viewer depends on web-play and web-patcher, and web-play on web-minigames, never the reverse. wasm-bindgen collects the exports of every crate the bundle links, so which crate an export lives in is invisible to the site’s JavaScript.

Simulation and draw are split on purpose

The page hands each animation frame’s sim ticks to play_frame_ticks (runtime/frame_ticks.rs), which gives each tick to the owner BootSession::claim_tick names - the field, the pause menu, a shop or name entry - in the order the native window’s sim_tick uses. Menus, shops and name entry therefore step on the sim tick, not the display frame, and the whole frame body is compared state by state against the native window in engine-shell/tests/host_frame_parity.rs.

Much of a frame’s work has an answer nothing reads, since at a town’s camera most bodies are off screen. Outside PSX mode the page leaves out a draw wholly past the side of the clip volume, keeping the others in their order, and holds a posed actor or a morph’s mesh build until the camera or a light can reach it. The overlay canvas and the HUD’s text repaint only when what they show has changed. The picture stays the one the unconditional work gives, which the frame-hash oracle pins.

The map and NPC layers make the native window’s exact resolver calls. NPC clip playback runs in simulation-tick time - one clip player per placed slot, advanced once per tick - so cadence does not depend on the display’s refresh rate and scripted actors perform their cued beats.

What each play module carries

ModuleCovers
play_dialogthe retail dialog reading box
play_cutscene / play_fmvthe opening prologue chain and the movie beats
play_camerathe follow camera and the debug orbit
play_menuthe retail pause menu
play_battle, play_battle_render, play_battle_fxlive battles: rules tick, the 3D scene, effects
play_shopfield merchants, the inn prompt, banners
play_sfx / play_bgm / play_xasound effects, scene music, voice clips
play_minigames, play_fishingthe in-world minigames reached through the scene’s own door warps
boot_title, play_name_entrythe boot title screen and name entry
session_save, cardssession saves and the two memory-card ports
play_dev_menuthe retail developer menu, behind a session-only checkbox that is never persisted
play_hotkeysthe native window’s option / cheat / camera keys, through the shared engine-session::hotkeys table

The quality step-down

No code on the page looks at the device, so on a GPU short of the defaults the page steps its own picture down. The decision is site/js/play-quality-ladder.js, with no GL, DOM or engine in it.

MSAA is not a rung: it is fixed when a context is created, and it is the smallest of the measured costs, so the context keeps it. ?autoquality=0 leaves the ladder unarmed. The native window has no ladder.

A capped page does not stall on a slow GPU the way an uncapped bench run does: the browser holds back requestAnimationFrame while frames are pending, so cost spreads evenly and the main thread stays free for the audio pump. Below 15 fps the world itself runs slow, since a display frame runs at most four ticks and drops the rest.

Keeping two hosts in step

The play page and the native window are two framebuffers over one engine, and the failure that costs most is quiet: a screen is wired natively and the web host drifts behind with nothing in any diff to say so.

Every screen’s geometry is a draw-list builder in engine-ui, and a host has that screen exactly when it calls the builder. So the feature surface can be derived from source, and a gate fails when a builder reaches the native window but not this crate. One-host cases live in a waiver file, each with a reason, validated in both directions so it cannot decay into a stale list.

A screen can be fully wired and connected to nothing. The gate answers “does this host call the builder”; it cannot answer “does this host feed it the same model”. The options screen was drawn on both hosts with the gate green while one of them rebuilt its session from defaults on every open and dropped the result on close.

AreaState against the native window
Seru-trade shop screensclosed: one shared composition
Options screenclosed: edits persist across reloads in localStorage, the browser twin of the native window’s legaia-options.toml
Inn promptclosed
Load / Save rowsclosed: both hosts browse two memory-card ports, each a mounted card image, through one card kernel and one slot summary
In-world minigamesclosed: both hosts enter them from the scene’s door warps
Field music, effects, voiceclosed
Memory-card containersclosed: the page imports every container the window mounts, RetroArch’s .srm included
Fullscreen keysclosed: F11 puts the picture full screen, as in the window
Bloom in the minigame venuesclosed: the page tied bloom to the ground fog’s field-and-battle rule; the window blooms every scene
A pass the driver cannot buildclosed: ambient occlusion, bloom or fog that cannot start on a browser says so, where it used to turn off silently
Movie sound before the engine’s output is upclosed in part: follows the volume slider and the sound switch, not yet the mono and mute options
Pixel-exact presentationclosed for PSX rasterisation: the page draws the 320x240 picture at the largest whole multiple of device pixels its layout offers, letterboxed, as the window does; the clean mode still stretches

The disc image

The play page reads a disc in three stages (js/play-disc.js), so a visitor is not waiting on movies they may never play and the wasm memory, which never shrinks, does not hold a whole image.

1. Before the engine find PROT.DAT, read up to its end while the wasm module compiles 2. The load disc_image_missing, then load_disc_spans copies only what the runtime keeps 3. By span XA and movies stay in the Blob, read when a consumer names them on the retail image, stage 1 is under a third of the file
Anything that is not a Mode 2/2352 image with a PROT.DAT in its root (a bare PROT.DAT, say) is read whole and goes to load_disc_image, as is a source with no Blob behind it.

A consumer that polls every frame asks span(lba, sectors), which answers from what is resident or null, and prefetch on null; it installs on the first frame after the read lands. A window asked through prefetch is held until its consumer calls release, so eviction cannot take it between the read and the install. read is the form for a consumer that uses the bytes once and right away (the voice banks): it answers with the bytes themselves and keeps nothing.

span answers only from one block that covers the whole window. Neighbours are not stitched: a window across two blocks is read again, and the wider block replaces any it covers. What is left once released stays under RESIDENT_CAP, oldest use out first. The cap (32 MiB) holds the largest XA file beside the largest set of clips one scene reads ahead. A read landing with nobody waiting is dropped.

Movies. The window is read when the beat asks and dropped at the install, which copies it and demuxes once. The engine holds the world until then, bounded by INSTALL_TIMEOUT_FRAMES (600 ticks, wall time unless the page runs below about 15 fps), which is about 3 MB/s for MV1.STR. A read past it finishes the beat unplayed and the hand-off runs, as a page with no disc does.

Voice clips. A scene’s and a round’s likely lines are on play_xa_stage_requests_json before they are raised (prestage_xa_clip), so _serveXaStage reads every listed file ahead, widest span per file, and installs one row per frame, oldest first. A line whose row was served plays on the call that raises it. A line nothing listed is deferred: it plays when its row is served, a read and at least a frame after the request. Neither path reaches the simulation, which never reads the XA lane back. The listed lines are a scene’s op-0x36 clips and its minigame door’s announcer lines at scene load, a round’s at battle entry, and the scripted-scene voice line at its program’s seek-ahead, the vsyncs before that program starts it.

Failures. A read that fails is tried three times, a quarter of a second and half a second apart. Then the window is reported failed until its release: the movie finishes unplayed, the clip’s row is installed empty and dropped. The next ask reads again. Since the bytes are not in memory, a file moved or changed on disk during a session costs every movie and clip not yet read.

A trapped engine is rebuilt by reading the head again (recoverRuntime), which goes to the Blob and not through the cap, and the voice banks are read again the same way.

While a movie is up its overlay covers the GL view, and the frame skips its GL draws: the world is held, and every pass that reads the frame (bloom, fog, ambient occlusion, the transition capture) reads one drawn earlier in the same frame. The sync with the engine still runs each frame, and the 2D overlay is still drawn.

The battle edge

The frame where the transition hands over to a fight reads a lot off the disc, and all of it is known when the transition starts: the party, its equipment and the fight’s stage. So while the encounter sits in its transition, the page runs one step per frame of the scene host’s prewarm: the entries the edge reads, each member’s battle form, the stage’s resources.

The steps fill two memos and the disc index’s cache and write nothing else, so no frame or tick can see whether they ran. A key the edge then reads differently is a miss, and builds as it would have. Both hosts and the headless drivers go through the memos; only this page prewarms.

Touch pad and the bug report

The touch pad (touch-pad.js) is an on-screen PSX pad over the picture: a D-pad, the four face buttons, the shoulders and Select / Start. On a phone held upright and out of fullscreen it sits in a band under the picture instead, where it covers neither the party’s HP readout nor the scene. It does not keep an input path of its own. Each pressed button is held through a virtual source in pad-bindings.js that joins the controller poll, so every reader of a controller press - the field tick, the menus, the title card - takes a touch press with no call site and no binding table of its own. The D-pad is one surface read by angle from its centre, with a dead zone in the middle and about a 45-degree wedge per diagonal, so a thumb rolls between directions without lifting. It shows by default where the only pointer is coarse (a phone or tablet), the Touch pad button toggles it on any device and remembers the choice, and hiding it releases whatever it held.

Checked headless. The controls step of scripts/ci/check-pages.mjs drives what only a browser has, on the built bundle: a file that is not the game is refused in words and the picker still takes the next one; on a touch-only device the pad is up, its D-pad walks the lead and lets go, START opens the pause menu and the first touch has brought sound up; a controller on the standard mapping walks by D-pad and by stick and opens and closes the menu on Start; Fullscreen presents the 4:3 picture at the screen’s height with the keyboard still on the canvas.

Copy report beside the disc picker puts on the clipboard what a bug report needs: the bundle’s version, the browser and GL renderer, the window, the input devices (pointer kind, touch points, whether the touch pad shows, each connected controller and its mapping), the disc file’s name and size, the engine’s state, the stored options and the page’s last warnings and errors. It holds no disc bytes.

The other surfaces

The minigames page holds the play hosts’ AudioDirector over one WebAudioOut, opened inside a user gesture. A tab change is that game’s mode entry: the old game’s voices and armed cues go, and the new game’s banks stage as its door warp stages them. Every cue keys a live SPU voice, so its envelope, volume, pan, reverb send and closed-slot silence are the play hosts’; a disc test renders each cue against the director and requires the same samples, and a host-drift tier rejects a cue played as a decoded buffer. Only the BGM is a buffer, an offline render at the same unity gain.

See also

Every module family with its exports, the parity tests, the texture-replacement registry and the long tail of helper modules are in docs/subsystems/browser-host.md.

Reference Engine port Port renderer VR mode Play page Minigames page ROM patcher