Skip to content

MgbaLink: re-anchor the controller clock across LOAD and RESET - #508

Merged
dayfine merged 3 commits into
lab/toolingfrom
lab/mgba-reanchor
Nov 15, 2026
Merged

dayfine merged 3 commits into
lab/toolingfrom
lab/mgba-reanchor

Conversation

@dayfine

@dayfine dayfine commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Depends on #506 (base lab/mgba-slice2b; the diff shows only this change).

Keeps the mGBA controller's frame clock right when a save-state LOAD or a RESET moves the emulator to another frame, and adds the controller-side commands for them (design: docs/design/Lab-mGBA-Console.md on agents).

  • Before this, the pacer kept granting frames of the old timeline: after a jump ahead mGBA stalled, after a jump back it ran free, and the key schedule stayed anchored to the old frame.
  • KeySender::jump(JumpCommand) stops the pacer, drops states not sent yet (a waiting push() returns), sends LOAD <file> or RESET, reads the new frame with GRANT 0, anchors a new clock, schedule and input log there, releases held keys on that frame, and grants again. A refused command keeps the old clock and pacer.
  • ProController_MgbaLink::load_state() and reset_console() clear the scheduler and call it.

Testing: new fake-bridge cases in the key sender suite (load ahead, load back, load before any key, reset, a waiting state dropped by a load, a refused load) check that every KEYS and GRANT after the jump is on the new timeline. Compiled with -fsyntax-only locally; Fork Draft CI builds and runs them. Not yet tried against a live mGBA.

A save-state LOAD or a RESET moves mGBA to another frame under the
pacer's and the key schedule's anchor: old grants would stall the
emulator after a jump ahead or let it run free after a jump back, and
queued KEYS would land on the wrong timeline.

KeySender::jump() stops the pacer, drops states not sent yet, sends
LOAD or RESET, reads the new frame with "GRANT 0", anchors a new clock,
schedule and input log there, releases held keys on that frame and
starts granting again. A refused command keeps the old clock and pacer.
ProController_MgbaLink exposes load_state() and reset_console().

Tests: fake-bridge cases for load ahead, load back, load before any
key, reset, a waiting state dropped by a load, and a refused load.
@dayfine
dayfine changed the base branch from lab/mgba-slice2b to lab/tooling November 15, 2026 03:02
@dayfine
dayfine marked this pull request as ready for review November 15, 2026 03:02
@dayfine
dayfine merged commit 42e9c2d into lab/tooling Nov 15, 2026
8 of 9 checks passed
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