From fadb4067ce555c4779eae15cdc13ac2372e56da8 Mon Sep 17 00:00:00 2001 From: Robert Pengelly Date: Tue, 20 Oct 2026 22:21:53 +0100 Subject: [PATCH] Added keyboard typematic-rate command support --- cpu.c | 35 +++++++++++++++++++++++++++++++++-- cpu.h | 1 + 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/cpu.c b/cpu.c index 72dc298..992c4a0 100644 --- a/cpu.c +++ b/cpu.c @@ -796,7 +796,14 @@ static uint8_t io_read8 (CPU8086 *cpu, uint16_t port) { case 0x60: /* keyboard data port */ - return 0x00; /* no key available unless you implement keyboard queue */ + if (cpu->kbd_ack_pending) { + + cpu->kbd_ack_pending--; + return 0xFA; /* keyboard command acknowledged */ + + } + + return 0x00; /* no scan code pending */ case 0x61: /* keyboard controller / speaker control */ @@ -804,7 +811,7 @@ static uint8_t io_read8 (CPU8086 *cpu, uint16_t port) { case 0x64: /* keyboard status port */ - return 0x00; /* bit0 clear = no output byte ready */ + return cpu->kbd_ack_pending ? 0x01 : 0x00; case 0x3B5: case 0x3D5: { /* 6845 CRT controller data */ @@ -907,6 +914,30 @@ static void io_write8 (CPU8086 *cpu, uint16_t port, uint8_t value) { } + case 0x60: /* AT keyboard data port */ + + if (cpu->kbd_typematic_pending) { + + cpu->kbd_typematic_rate = value & 0x7F; + cpu->kbd_typematic_pending = 0; + + } else if (value == 0xF3) { /* set typematic rate/delay */ + + cpu->kbd_typematic_pending = 1; + + } else { + + fprintf (stderr, "Unhandled keyboard command %02X at %04X:%04X\n", value, cpu->cs, cpu->ip); + exit (1); + + } + + if (cpu->kbd_ack_pending < 2) { + cpu->kbd_ack_pending++; + } + + break; + case 0x61: if (!(cpu->port61 & 1) && (value & 1)) { diff --git a/cpu.h b/cpu.h index dd7259d..f806836 100644 --- a/cpu.h +++ b/cpu.h @@ -40,6 +40,7 @@ typedef struct __attribute__ ((packed)) CPU8086 { int has_operand_override; int rep_type; + uint8_t kbd_typematic_pending, kbd_typematic_rate, kbd_ack_pending; uint8_t port61, vga_status_flip; uint8_t pit2_access, pit2_mode, pit2_write_high, pit2_read_high; -- 2.34.1