Skip to content

MgbaLink: GRANT pacer and mGBA Pro Controller (slice 2b) - #506

Merged
dayfine merged 4 commits into
lab/toolingfrom
lab/mgba-slice2b
Nov 15, 2026
Merged

dayfine merged 4 commits into
lab/toolingfrom
lab/mgba-slice2b

Conversation

@dayfine

@dayfine dayfine commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Base: lab/tooling; the diff shows only this change (#503 has merged).

Slice 2b of the mGBA design: mGBA can now be driven by a Pro Controller, paced by the app's clock.

  • The mGBA video source publishes its connection in MgbaLink::link_registry() under its address; the controller for the same address sends on it (the bridge holds one client).
  • MgbaLink::KeySender anchors a frame clock with GRANT 0, runs the Pacer (GRANT about every 8 ms, two frames ahead, on a thread pool task), and sends each key state as KEYS at most five frames ahead, so a cancel releases the keys at once. Every KEYS lands in the InputLog. On stop it releases held keys and grants a frame it never reaches, so mGBA runs on.
  • ProController_MgbaLink plays scheduled states through MgbaLink slice 2a: key schedule, input log, Pro Controller key map #503's key map. Developer mode adds a "TCP: mGBA Link" controller interface with an address box (default 127.0.0.1:47801, the video source's).

Testing

  • New unit tests (Controllers::MgbaLink - link registry / pacer / key sender) run against a fake bridge on 127.0.0.1; Fork Draft CI runs them.
  • Locally: code health 0 failures; touched files syntax-checked with clang (-Wall -Wextra, no warnings).
  • Not yet run against real mGBA. The live check (FRLG start menu opens and closes) is a hand step.

The mGBA video source now publishes its connection in a registry keyed
by its address, so a controller for the same mGBA shares it (the bridge
holds one client). KeySender anchors a frame clock with "GRANT 0", runs
the pacer (GRANT about every 8 ms, two frames ahead of app time, on a
thread pool task) and sends each key state as KEYS at most five frames
ahead, so a cancel can still release the keys at once. Every KEYS goes
into the input log at the frame it landed on.

ProController_MgbaLink plays scheduled states through the key map and
KeySender. It registers as the Developer-only "TCP: mGBA Link"
controller interface, with the video source's address.
@dayfine
dayfine changed the base branch from lab/mgba-slice2 to lab/tooling November 15, 2026 01:54
…ib, not CoreLib

The selector widget header includes <QLineEdit>, which CoreLib (Qt-free) cannot
compile. The descriptor depends on VideoSource_MgbaLink, which is not in CoreLib
either. Both now sit in the main source list, like SysbotBase's.
Ends are placed from app time: three 80 ms states are 14.33 frames, so the
release lands on frame +14. The old expectation rounded each state to 5
frames separately, the drift KeySchedule avoids.
@dayfine
dayfine marked this pull request as ready for review November 15, 2026 03:02
@dayfine
dayfine merged commit 0e5dbd2 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