Skip to content

Refactor/dos console driver#2095

Merged
maximilien-noal merged 6 commits intomasterfrom
refactor/dos_console_driver
Apr 19, 2026
Merged

Refactor/dos console driver#2095
maximilien-noal merged 6 commits intomasterfrom
refactor/dos_console_driver

Conversation

@maximilien-noal
Copy link
Copy Markdown
Member

@maximilien-noal maximilien-noal commented Apr 19, 2026

Description of Changes

Refactors the DOS console driver from FreeDOS code.

Rationale behind Changes

The current console driver was derived from DOSBox, and was hard to follow.

New code is object oriented, documented, and actually understood.

Suggested Testing Steps

Already tested against master with FreeDOS's EDIT.EXE program without issue.
Some integration tests were added.

Added INT 16h AH=05h (Store Keystroke) support and refactored input handling to use a device-level stuffahead buffer for synthesized input (e.g., DSR responses), matching NANSI priority and bypassing key reassignment. ConsoleDevice now flushes both stuffahead and BIOS keyboard buffers. Improved extended key and backspace handling. ESC[0p now installs the default Ctrl+PrintScreen→Ctrl+P mapping. Added integration tests for key reassignment, buffer flushing, and DSR response correctness.
Implemented support for NANSI-specific modes in SetResetMode:
- Mode 99 toggles pseudo cursor behavior via _vga.CursorEmulation.
- Mode 43 reinitializes text mode, loads 8x8 font for 80x43 layout, sets cursor shape, and homes the cursor.
@maximilien-noal maximilien-noal self-assigned this Apr 19, 2026
@maximilien-noal maximilien-noal added the DOS Related to DOS label Apr 19, 2026
Copilot AI review requested due to automatic review settings April 19, 2026 10:04
Comment thread src/Spice86.Core/Emulator/OperatingSystem/Devices/ConsoleDevice.cs Fixed
maximilien-noal and others added 2 commits April 19, 2026 12:09
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the DOS CON device implementation to follow FreeDOS/NANSI semantics (ANSI escape parsing, key reassignment, and “stuffahead” input), and adds integration tests to validate key parts of the new console behavior.

Changes:

  • Reworks ConsoleDevice into an ANSI-aware console driver with a parser state machine and a shared “stuffahead” queue for synthesized input.
  • Adds an AnsiState + AnsiSequenceHandler split to separate parsing state from CSI command execution (cursor, erase, insert/delete, DSR, key reassignment).
  • Extends INT 16h support (AH=05h “Store Keystroke”) and updates INT 21h AH=0Ch flushing to clear device-level buffered input.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/Spice86.Tests/Dos/DosInt21IntegrationTests.cs Adds integration tests covering keyboard reassignment reset, INT 21h flush behavior, and DSR cursor position responses.
src/Spice86.Core/Emulator/OperatingSystem/Devices/ConsoleDevice.cs Major console driver refactor: ANSI parser phases, stuffahead buffering, key reassignment lookup, and updated read/write behavior.
src/Spice86.Core/Emulator/OperatingSystem/Devices/AnsiState.cs Introduces shared mutable state for ANSI parsing/execution (params, attributes, wrap flag, key redefinitions).
src/Spice86.Core/Emulator/OperatingSystem/Devices/AnsiSequenceHandler.cs Implements CSI command execution against VGA + injects DSR responses into the stuffahead buffer.
src/Spice86.Core/Emulator/InterruptHandlers/Input/Keyboard/KeyboardInt16Handler.cs Adds INT 16h AH=05h handler to enqueue keystrokes into the BIOS keyboard buffer.
src/Spice86.Core/Emulator/InterruptHandlers/Dos/DosInt21Handler.cs Extends AH=0Ch flushing to also flush stdin device buffers (clearing console stuffahead).

Comment thread src/Spice86.Core/Emulator/OperatingSystem/Devices/ConsoleDevice.cs Outdated
Comment thread src/Spice86.Core/Emulator/OperatingSystem/Devices/ConsoleDevice.cs Outdated
Comment thread tests/Spice86.Tests/Dos/DosInt21IntegrationTests.cs Outdated
Comment thread tests/Spice86.Tests/Dos/DosInt21IntegrationTests.cs Outdated
Comment thread src/Spice86.Core/Emulator/OperatingSystem/Devices/ConsoleDevice.cs Outdated
Comment thread src/Spice86.Core/Emulator/OperatingSystem/Devices/ConsoleDevice.cs Outdated
@maximilien-noal
Copy link
Copy Markdown
Member Author

@copilot apply changes based on the comments in this thread and double check with https://github.com/FDOS/ansi before doing any fix or "enhancement".

@maximilien-noal maximilien-noal added refactoring Involves refactoring existing code tests About unit or integration testing labels Apr 19, 2026
…am, doc comments

Agent-Logs-Url: https://github.com/OpenRakis/Spice86/sessions/e68cc385-7468-48b5-a8ce-faf00c55ba4b

Co-authored-by: maximilien-noal <1087524+maximilien-noal@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 19, 2026

@copilot apply changes based on the comments in this thread and double check with https://github.com/FDOS/ansi before doi...

Applied all changes from the review thread in commit 10b1edf, cross-checked against the FreeDOS NANSI source (source/nansi.asm):

  1. Stuffahead echo (line 170-171): stuffahead bytes are now echoed when Echo is true, matching NANSI's behavior where the DOS kernel echoes whatever getchar returns for key reassignment.
  2. Unused asciiCode param (line 272): removed from both HandleExtendedKey0xE0 signature and its call site.
  3. Backspace underflow (line 247-248): guard changed from index > 0 to bytesRead > 0; index-- now happens before clearing the slot.
  4. Spurious echo in DrainExtendedKeyCache (line 221-223): removed the Echo block — extended key scan codes cached from a split read are not echoed, consistent with how the primary 0x00 byte skips the echo path.
  5. Test doc comments (lines 1563-1567, 1618-1622): corrected to match what the bytecode actually does (no ESC[0;114;16p send, and AL=01h not AL=08h for the flush call).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • av-build-tel-api-v1.avaloniaui.net
    • Triggering command: /usr/share/dotnet/dotnet dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/avalonia.buildservices/11.3.2/tools/netstandard2.0/runtimeconfig.json /home/REDACTED/.nuget/packages/avalonia.buildservices/11.3.2/tools/netstandard2.0/Avalonia.BuildServices.Collector.dll (dns block)
  • https://api.github.com/repos/FDOS/ansi/contents/
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (http block)

If you need me to access, download, or install something from one of these locations, you can either:

@maximilien-noal maximilien-noal merged commit ff2bfef into master Apr 19, 2026
5 checks passed
@maximilien-noal maximilien-noal deleted the refactor/dos_console_driver branch April 19, 2026 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DOS Related to DOS refactoring Involves refactoring existing code tests About unit or integration testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants