Skip to content

Preserve GB/GBC LCD-off bootstrap state for multiplayer rollback - #7

Merged
deviankim merged 6 commits into
browser-environmentfrom
fix/multiplayer-lcd-state
Oct 1, 2026
Merged

deviankim merged 6 commits into
browser-environmentfrom
fix/multiplayer-lcd-state

Conversation

@deviankim

@deviankim deviankim commented Oct 1, 2026 •

Copy link
Copy Markdown

GB/GBC rollback from the pre-world bootstrap was not deterministic while the LCD was off. Gambatte reconstructed the native blit deadline, reset the blank-LCD phase, and retained dormant sprite entries from a later frame. With the original M1 payload, restoring the fixture changes the first subsequent CPU frame and its causal digest.

Preserve the blit deadline and blank-LCD phase in deterministic snapshots, restore captured sprite attributes/words, and retain current/next sprite cursors when the native loader skips them. This covers LCD-off bootstrap and inactive LCD-on fetch phases. Disabled STAT mode-0 deadlines are normalized only where the loader ignores them; active deadlines remain causal. The deterministic envelope grows from 64 to 80 bytes, with schema 0x47420102; old deterministic envelopes are rejected. Ordinary disk states retain their format and behavior.

Self-review of the M2 whole-bundle checkpoint undo path exposed a second actual defect: restoring an active frame after the boot-off state could inherit a 0xff sprite cursor rather than captured 0, because loadSpriteList skips reconstruction during vblank/right-edge phases. The follow-up preserves both cursors in those phases only in deterministic mode. No app-side state byte filter is used.

Regression cartridges restore differently aged LCD-off boot checkpoints after playing ahead. They also restore active states through the LCD-off checkpoint at five distinct boundaries. Every restoration compares native registers, RAM, pixels, audio and causal digest for 40 subsequent frames. Mutations of active STAT/timing fields and rejected schema/flags/envelopes remain covered. The browser harness runs the same bootstrap and active-restore checks.

Tracks https://github.com/ssk-play/chiptoy/issues/96. Merged M1 #6 (5c728f95) has been brought in with a merge commit. This is a lower-core prerequisite for ssk-play/romdev-browser#16, not a claim that the M2 physical-phone performance gate passes.

Validation after self-review:

  • Gambatte rebuilt using the pinned Docker recipe: ROMDEV_BUILD_CWD=packages/romdevtools build-image/build-wasm.sh build-gambatte.sh.
  • Core/compiler, browser-surface, legacy disk-state, auto-snapshot, cheat restoration and state-path suites: 70 passed, 2 existing skips, 0 failed. Legacy pre-M1 GB/GBC/NES blobs still restore with the expected future execution.
  • ESLint on changed JavaScript: passed.
  • Consumer build/typecheck/tests: 52/52, including actual 1/2/3/4-player GB/GBC/NES bundles, gapped seats, correction and verified whole-bundle undo/retirement.
  • Dev host build/tests: 108/108. Chrome and Android emulator dev core harnesses report PASS for every platform and the new active-through-LCD-off tests. Android 200ms direction holds for each P1–P4 moved only that actor and stopped on release (initial positions 48/80/112/144, final 60/92/125/156). Consumer diagnostics on Chrome, iOS Simulator and Android emulator each completed 15/15 deterministic cases with private result upload; emulator timing does not qualify as real-phone performance.

Reproducible payload:

Dev deployment:

  • Worker 550e9118-9bce-4d5a-af84-5b34006232f6.
  • App commit 22201ca, https://github.com/ssk-play/chiptoy/pull/104, based on current feat/multiplayer-fastpath-server (c8d6d3a). Existing rooms/ICE/SFU migrations and routes are retained; valid signed-out ICE/SFU requests return 401 rather than 404.
  • The core harness is a separately served static GPL program with exact corresponding source and license links. It needs no login and uploads nothing. The companion automatic benchmark is a different program with an explicitly documented private dev collector.

External procedure:

  1. Open https://dev.chiptoy.com/lib/m1-lcd-3a51e4c8/ in Windows Chrome/Edge at phone width. No login is needed; these fixed fixtures contain no account/game data.
  2. Expect PASS · GB, GBC and NES rollback checks. The report must identify source 3a51e4c8..., GB/GBC schema 1195507970, and both LCD-off bootstrap and resume (4 checkpoints × 40 frames) and active restore through LCD-off (5 checkpoints × 40 frames).
  3. Select P1–P4 in turn and hold Left/Right for at least 50ms (100–200ms recommended). Only the selected colored NES actor moves; releasing stops it. Reload and expect PASS again.
  4. Copy the report and return browser/device information plus the input result. All report data stays client-side.

The current deployment supersedes the old m1-lcd-41a1c156 deployment; use the new URL/version above. No merge or production deployment has been performed.

Review follow-up (45b35010): the patch now documents why the saved blit deadline fits u32: CPU::runFor rebases at bit 31 through Memory::resetCounters, including the blit event; the disabled sentinel is 0xfffffffful. This is a comment-only change. The published payload and external harness above remain unchanged. Validation: multiplayer-core and legacy disk-state tests 24/24, git diff --check, and applying the revised patch with the build recipe’s git apply --recount flags to the pinned native sources. No new deployment. Future dev deployments will include the current origin/feat/multiplayer-cable-ui head to preserve checkpoint and cable routes.

@deviankim
deviankim merged commit 96b1107 into browser-environment Oct 1, 2026
1 of 2 checks passed
deviankim added a commit that referenced this pull request Oct 1, 2026
# Conflicts:
#	packages/romdevtools/scripts/patches/gambatte-multiplayer-state.patch
@deviankim
deviankim deleted the fix/multiplayer-lcd-state branch October 29, 2026 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant