Added keyboard typematic-rate command support
authorRobert Pengelly <robertapengelly@hotmail.com>
Tue, 20 Oct 2026 21:21:53 +0000 (22:21 +0100)
committerRobert Pengelly <robertapengelly@hotmail.com>
Tue, 20 Oct 2026 21:21:53 +0000 (22:21 +0100)
cpu.c
cpu.h

diff --git a/cpu.c b/cpu.c
index 72dc2989e8a6f59d01b98d936f205edc56b605b5..992c4a0abf55f5cd48f0e1f572258c37e2db8e01 100644 (file)
--- 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 dd7259d6a1ff51cb3f98b1824f629ff0a131e199..f806836557daafa73e2eb3cc8faf2bfc2ac612ff 100644 (file)
--- 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;