Skip to content

Input hub: typed events, no device reference, no direct-write MCP tools - #2599

Merged
kevinferrare merged 2 commits into
masterfrom
feature/input-event-hub
Dec 2, 2026
Merged

kevinferrare merged 2 commits into
masterfrom
feature/input-event-hub

Conversation

@kevinferrare

@kevinferrare kevinferrare commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Replaces #2585, which was merged into feature/reproducible-run-option before review; feature/reproducible-run-option was restored to f94a969cb.

  • Rename InputEventQueue.cs to InputEventHub.cs in its own commit to preserve history.
  • InputEventHub queues IInputEvent items instead of Action delegates: KeyboardEventArgs, MouseMoveEventArgs and MouseButtonEventArgs implement the new Spice86.Shared.Interfaces.IInputEvent marker and are queued as-is; ReleaseAllKeysInput and TimeMultiplierInput carry the two commands. Apply dispatches on the payload type.
  • Remove PostToEmulatorThread and InputEventHub.KeyboardDevice, expose IKeyboardInputEvents.AllKeysReleased for PS2Keyboard, and route UI ITimeMultiplier changes through InputEventHub.
  • Remove the direct-write MCP tools press_key and send_mouse_packet (and EmulatorMcpServices.Intel8042Controller / BiosKeyboardBuffer), moving pause-time key release directly into Spice86DependencyInjection.
  • Add the input_timer_keys catalogue scenario (AsmFixtureCatalog.InputTimerKeysReleaseAll): a CPU cycle breakpoint calls ReleaseAllKeys between two injected keys, and the program must record 1E 9E 2E (A make, A break, C make) in interpreted and generated mode. It is marked timing-dependent because the keyboard and timer interrupts leave different stale frame bytes on the stack in the two modes (0x18FF8, 0x18FFC); the scan-code oracle is checked in both. Two readability baseline rows were added to bounds.tsv through the tightening pass; no other rows changed.

Stack

PR 3 of 4 in the input recording stack:

PR 4 will need to drop its copy of InputEventHubTests.cs and move InputRecordingTests (which runs input_timer_keys directly) into the catalogue when it is rebased.

Test plan

  • dotnet build src/Spice86.sln: Build succeeded (0 Warning(s), 0 Error(s)).
  • dotnet test --project tests/Spice86.Tests --no-build -- --filter-class '*AsmScenarioTest*' --filter-class '*AsmFixtureGoldenKeyTests*' --filter-class '*AsmScenarioPipelineTest*' --filter-class '*GeneratedCodeMachineTest*': Passed! total: 627, failed: 0.
  • dotnet test --project tests/Spice86.Tests --no-build -- --filter-not-class '*SingleStepTest*': Passed! total: 8489, failed: 0, skipped: 0.

Gaps

  • Running McpServerToolStateTests alone (outside the full suite) triggers a pre-existing MachineLeakGuard assembly cleanup failure on VideoWritePixelAndReadPixel_ShouldRoundTripColorAsync (all test bodies pass; reproduced identically on the base branch, and passes cleanly in the full suite).

Generated with Devin

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Generated code: 0 scenarios changed, 1 new, 0 removed (+152 -0 lines). Base 01b35ed6, head 89c92018.

Scenario Change Lines
input_timer_keys new +152
Metrics fixture Changes
input_timer_keys.spec new

Full diff and dumps (zip) · Run

@kevinferrare
kevinferrare force-pushed the feature/reproducible-run-option branch from f94a969 to 68e33f4 Compare December 2, 2026 13:35
@kevinferrare
kevinferrare force-pushed the feature/input-event-hub branch from ad7b557 to 0e493ca Compare December 2, 2026 13:36
@kevinferrare

Copy link
Copy Markdown
Contributor Author

Rebased on the reworked #2583 (jitter kept, applied as a function of the emulated time). New head: 0e493ca.

@kevinferrare
kevinferrare force-pushed the feature/reproducible-run-option branch 4 times, most recently from adb468b to bbab6d6 Compare December 2, 2026 21:06
@kevinferrare
kevinferrare force-pushed the feature/input-event-hub branch from 0e493ca to d025a8f Compare December 2, 2026 21:14
Base automatically changed from feature/reproducible-run-option to master December 2, 2026 21:31
@kevinferrare
kevinferrare force-pushed the feature/input-event-hub branch 2 times, most recently from 1cd5fff to d588639 Compare December 2, 2026 21:49
@maximilien-noal
maximilien-noal self-requested a review December 2, 2026 22:45
@kevinferrare
kevinferrare marked this pull request as ready for review December 2, 2026 22:45
Copilot AI lite review requested due to automatic review settings December 2, 2026 22:45
Every host input action now passes through one inspectable pipeline, which
input recording and replay build on.

- InputEventHub queues IInputEvent items instead of Action delegates: the
  keyboard and mouse event args implement IInputEvent and are queued as-is,
  and ReleaseAllKeysInput and TimeMultiplierInput carry the two commands.
- Remove PostToEmulatorThread and InputEventHub.KeyboardDevice. The hub
  raises IKeyboardInputEvents.AllKeysReleased, which PS2Keyboard subscribes
  to, and UI time multiplier changes go through the hub.
- Remove the press_key and send_mouse_packet MCP tools, which bypassed the
  hub by writing BIOS and PS/2 controller state directly, along with the
  Intel8042Controller and BiosKeyboardBuffer properties on
  EmulatorMcpServices. Pause-time key release is wired in
  Spice86DependencyInjection.
- Add the input_timer_keys catalogue scenario: a cycle breakpoint calls
  ReleaseAllKeys between two injected keys, and the program must record
  A's break code, in interpreted and generated mode.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Approval is blocked by an untested queued time-multiplier path and a remaining file-organization issue.

2 open issues
What changed in this PR

This PR refactors emulator input handling around typed, emulator-thread events and removes direct-write MCP input tools.

Changes:

  • Adds typed keyboard, mouse, release, and time-multiplier events.
  • Routes pause-time key release and UI time changes through InputEventHub.
  • Removes press_key and send_mouse_packet, and adds the input_timer_keys fixture.
File Description
tests/​Spice86.Tests/​Resources/​GeneratedCodeReadability/​bounds.tsv Adds readability bounds for the input fixture.
tests/​Spice86.Tests/​Resources/​cpuTests/​asmsrc/​input_timer_keys.asm Adds the timer and keyboard test program.
tests/​Spice86.Tests/​MouseStateTests.cs Updates mouse state tests for the revised input hub.
tests/​Spice86.Tests/​MouseInputTests.cs Updates mouse input tests for the revised input hub.
tests/​Spice86.Tests/​MouseDriverTests.cs Updates mouse driver tests for the revised input hub.
tests/​Spice86.Tests/​McpServerToolStateTests.cs Removes tests for deleted MCP input tools.
tests/​Spice86.Tests/​McpIntegrationContext.cs Removes obsolete MCP service wiring.
tests/​Spice86.Tests/​CSharpOverrideHelperTest.cs Updates coverage for queued keyboard input.
tests/​Spice86.Tests/​AsmFixtures/​AsmScenarioCatalog.cs Registers the input fixture scenario.
tests/​Spice86.Tests/​AsmFixtures/​AsmFixtureCatalog.cs Adds release-all-keys behavioral coverage.
src/​Spice86/​Spice86DependencyInjection.cs Wires input events, pause-time key release, and timing updates.
src/​Spice86.Shared/​Interfaces/​IInputEvent.cs Adds the input-event marker interface.
src/​Spice86.Shared/​Emulator/​Mouse/​MouseMoveEventArgs.cs Makes mouse movement events queueable.
src/​Spice86.Shared/​Emulator/​Mouse/​MouseButtonEventArgs.cs Makes mouse button events queueable.
src/​Spice86.Shared/​Emulator/​Keyboard/​KeyboardEventArgs.cs Makes keyboard events queueable.
src/​Spice86.Core/​Emulator/​VM/​InputEventHub.cs Queues and dispatches typed input events.
src/​Spice86.Core/​Emulator/​VM/​Input/​Events/​InputEvents.cs Defines queued input event records.
src/​Spice86.Core/​Emulator/​VM/​IKeyboardInputEvents.cs Exposes keyboard reconciliation events.
src/​Spice86.Core/​Emulator/​Mcp/​EmulatorMcpTools.cs Removes direct-write MCP input tools.
src/​Spice86.Core/​Emulator/​Mcp/​EmulatorMcpServices.cs Removes obsolete direct device references.
src/​Spice86.Core/​Emulator/​Devices/​Input/​Keyboard/​PS2Keyboard.cs Handles queued key-release requests.
src/​Spice86.Core/​Emulator/​Devices/​Input/​Keyboard/​Intel8042Controller.cs Uses the new keyboard input-event interface.
doc/​mcp.md Removes documentation for deleted MCP input tools.

Review effort: Lite

/// Thread-safe request to change the emulated clock time multiplier on the emulation thread.
/// </summary>
internal PS2Keyboard? KeyboardDevice { get; set; }
public void SetTimeMultiplier(double value) => Enqueue(new TimeMultiplierInput(value));
Comment on lines +6 to +9
public sealed record ReleaseAllKeysInput : IInputEvent;

/// <summary>A request to change the emulated clock time multiplier.</summary>
public sealed record TimeMultiplierInput(double Multiplier) : IInputEvent;
@kevinferrare
kevinferrare force-pushed the feature/input-event-hub branch from 2d8493a to 89c9201 Compare December 2, 2026 22:49
@kevinferrare
kevinferrare merged commit b557d20 into master Dec 2, 2026
6 checks passed
@kevinferrare
kevinferrare deleted the feature/input-event-hub branch December 2, 2026 23:14
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.

3 participants