Skip to content

Commit ff2bfef

Browse files
maximilien-noalgithub-advanced-security[bot]Copilot
authored
Refactor/dos console driver (#2095)
* refactor: console device based in FreeDOS * feat: INT 16h/21h input: stuffahead buffer, DSR, key mapping 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. * feat: Add NANSI mode 99 and 43 handling to AnsiSequenceHandler 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. * fix: StoreKeystroke actually updates the Carry Flag on success and error * refactor: combined if statements Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Fix review comments: echo stuffahead, backspace underflow, unused param, 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> --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: maximilien-noal <1087524+maximilien-noal@users.noreply.github.com>
1 parent 385f588 commit ff2bfef

File tree

6 files changed

+1213
-467
lines changed

6 files changed

+1213
-467
lines changed

src/Spice86.Core/Emulator/InterruptHandlers/Dos/DosInt21Handler.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,8 @@ public void ClearKeyboardBufferAndInvokeKeyboardFunction() {
724724
LoggerService.Debug("CLEAR KEYBOARD AND CALL INT 21 {Operation}", operation);
725725
}
726726
_keyboardInt16Handler.FlushKeyboardBuffer();
727+
// NANSI dosfn7: also clears all device-level stuffahead buffers.
728+
_dosFileManager.Stdin?.Flush();
727729
if (operation is not 0x0 and not 0x6 and not 0x7 and not 0x8 and not 0xA) {
728730
return;
729731
}

src/Spice86.Core/Emulator/InterruptHandlers/Input/Keyboard/KeyboardInt16Handler.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ private void FillDispatchTable() {
4848
AddAction(0x01, () => GetKeystrokeStatus(true));
4949
AddAction(0x02, GetShiftFlags);
5050
AddAction(0x03, SetTypematicRateAndDelay);
51+
AddAction(0x05, () => StoreKeystroke(true));
5152
AddAction(0x10, GetEnhancedKeystroke);
5253
AddAction(0x11, () => GetEnhancedKeystrokeStatus(true));
5354
AddAction(0x1D, () => Unsupported(0x1D));
@@ -243,6 +244,26 @@ public void GetShiftFlags() {
243244
State.AL = _biosDataArea.KeyboardStatusFlag;
244245
}
245246

247+
/// <summary>
248+
/// INT 16h, AH=05h - Store Keystroke in keyboard buffer.
249+
/// Writes the key code in CX (CH=scan code, CL=ASCII character) into the
250+
/// BIOS keyboard buffer. On success AL=0, CF=0; if the buffer is full, AL=1, CF=1.
251+
/// </summary>
252+
public void StoreKeystroke(bool calledFromVm) {
253+
ushort keyCode = State.CX;
254+
if (LoggerService.IsEnabled(LogEventLevel.Verbose)) {
255+
LoggerService.Verbose("STORE KEYSTROKE {KeyCode}", keyCode);
256+
}
257+
bool enqueued = _biosKeyboardBuffer.EnqueueKeyCode(keyCode);
258+
State.AL = enqueued ? (byte)0 : (byte)1;
259+
if(enqueued) {
260+
SetCarryFlag(false, calledFromVm);
261+
}
262+
else {
263+
SetCarryFlag(true, calledFromVm);
264+
}
265+
}
266+
246267
/// <summary>
247268
/// Tries to get the pending keycode from the BIOS keyboard buffer without removing it.
248269
/// </summary>

0 commit comments

Comments
 (0)