Skip to content

MgbaLink slice 2a: key schedule, input log, Pro Controller key map - #503

Merged
dayfine merged 1 commit into
lab/toolingfrom
lab/mgba-slice2
Nov 15, 2026
Merged

dayfine merged 1 commit into
lab/toolingfrom
lab/mgba-slice2

Conversation

@dayfine

@dayfine dayfine commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Base: lab/tooling (slice 1, #493, is merged there). The diff shows only this change. Fork-only lab tooling.

Slice 2 of docs/design/Lab-mGBA-Console.md (agents branch), first part: the input logic the mGBA Pro Controller will sit on, all testable without mGBA or a ROM.

  • Controllers/MgbaLink/MgbaLink_Keys: GBA key bits; ms to frames (max(1, round(d * 59.7275 / 1000))); frame_at (KEYS) and grant_frame (paced GRANT, floor + lead 2); KeySchedule turns the scheduler's states-with-durations into KEYS <frame> <mask> commands: states follow each other, each holds at least one frame, ends are placed from app time so rounding does not add up, and after idle the next state starts 2 frames after now; InputLog keeps the frame each change landed on (frame + LATE) as <frame> <mask> lines for replay.
  • NintendoSwitch/Controllers/MgbaLink/NintendoSwitch_MgbaLink_KeyMap: SwitchControllerState to GBA keys (A, B, L, R; Plus = Start, Minus = Select; D-pad and split D-pad buttons; left stick past half tilt per axis), and reports buttons and the right stick that have no GBA key so the controller can log them once.
  • No bridge or protocol change: bridge.lua already serves GRANT/KEYS/FRAME/SAVE/LOAD, so there is no agents-branch PR.

Left for slice 2b: the pacer thread (GRANT every ~8 ms on the shared connection), ProController_MgbaLink on ControllerWithScheduler using this schedule and map, and its Developer-only controller entry sharing the video source's connection.

Testing: new unit suites Controllers::MgbaLink - frames for duration / frame at time / key schedule / input log and NintendoSwitch::MgbaLink - key map; expectations cross-checked with a Python model of the same math. Local compile was skipped (a console run held the heavy gate); Fork Draft CI builds and runs them.

Step 0 (user, real mGBA 0.10.5 + local ROM, not part of this PR) still has to confirm what slice 2b relies on: KEYS at frame F reads back from F (emu:getKeys), a GRANT stall holds currentFrame with the window responsive, and the FRAME cost per call. Live acceptance for slice 2 (start menu opens and closes) needs slice 2b.

KeySchedule turns controller states held for a duration into KEYS
commands on frames (at least one frame per state, no drift over many
states, a lead of 2 frames after idle); grant_frame() is the paced-mode
GRANT; InputLog keeps the frame each change landed on. The key map turns
a SwitchControllerState into GBA keys (Plus = Start, Minus = Select, left
stick past half tilt = D-pad) and reports buttons with no GBA key.
@dayfine
dayfine marked this pull request as ready for review November 15, 2026 01:53
@dayfine
dayfine merged commit c00b1af 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