API: make keyboard key events actually reach the emulated C64; add run/frames for deterministic replay - #121
Open
arekbr wants to merge 1 commit into
Open
Conversation
…dpoint
- input keyDown/keyUp (legacy and key/down|key/up) resolve the MTKEY code
through C64KeyMap and press the resolved matrix position inside the queued
CPU-interrupt task, using the same immediate-latch sequence as the virtual
keyboard view (no randomized KEYBOARD_RAND latch delay). Unmapped keys and
missing params return 406; queued events return 202 {queued:true}.
- CDebugInterfaceVice::KeyboardDown/Up report queueing success instead of
always returning false.
- new <platform>/run/frames {count:N}: runs exactly N frames from a paused
machine and pauses again (generalizes the existing frame-step mechanism);
blocks until finished and returns frameStart/frame counters.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem 1: keyboard endpoints never pressed a key
input/keyDown/input/keyUpreplied 200 but no key ever reached the emulated machine ($CB stayed $40), and the newerinput/key/down/input/key/upalways replied 406 becauseCDebugInterfaceVice::KeyboardDown/Upunconditionally returnedfalseafter queueing the task.Two root causes:
keyboard_key_pressed(mtKeyCode), which is a silent no-op when the keyconvmap lookup misses, and even on a hit the latch goes through the randomizedKEYBOARD_RAND()alarm — bad for cycle-deterministic tooling;Fix
KeyboardDown/Upresolve the MTKEY code throughC64KeyMapGetDefault()->FindKeyCode()at queue time and pass the resolved(matrixRow, matrixCol, shift)into the task.ExecuteTaskpresses the matrix position using the same immediate-latch sequence the virtual keyboard view already uses (CViewC64KeyMap::SelectKey):keyboard_key_pressed_matrix+keyboard_set_latch_keyarr+c64d_keyboard_key_down_latch(negative rows go throughkeyboard_set_keyarr_any). Unmapped keys and missing/invalid params now return 406; successfully queued events return 202{"queued":true}. Both endpoint families are fixed (the legacy names are also used by the MCP bridge).Problem 2: no deterministic N-frame run
There was no API way to run an exact number of frames (external tooling had to drive VICE with
-limitcyclesinstead of this debugger).Fix
New
<platform>/run/frames {"count":N}generalizes the existing frame-step mechanism:RunEmulationForFrames(numFrames)setsframeStepTargetFrameNumber = current + N(RunEmulationForOneFramenow delegates with N=1, so GUI/test behavior is unchanged; the completion-wait budget scales with N). The endpoint is synchronous — the reply arrives after the frames have run, carryingframeStartand the finalframecounter — and requires a paused machine (406 otherwise, since computing current+N on a running machine would race the emulation thread).Verification (macOS arm64, Xcode 16.4,
build-macos.sh)14-point WebSocket gate against the built app, including negative controls:
run/frames {count:50}twice from pause: frame counter advances exactly +50 each time,frameStart/frameconsistent withcpu/counters/read; called while running → 406input/keyDown {keyCode:97}→ 202{queued:true}; afterrun/frames {count:3}zeropage $CB reads 10 ('A' matrix code);keyUp→ $CB back to 64 (no key)keyCode→ 406; missing param → 406screen/snapshot(PNG + metadata) unaffectedCommit is on top of current master (af8f1d2).