PC-98 keyboard ISR: On IRQ 1, assume keyboard has data available and process at least one byte, before checking status for more. The PC-98 patched version of CWSDPMI appears to read the keyboard data itself before passing control to the ISR and this is necessary for keyboard input to work at all (test case KOARMADA.EXE and DJGPP libc function kbhit())

This commit is contained in:
Jonathan Campbell 2025-01-22 14:57:01 -08:00
parent 30f0fb1881
commit 9e9e6924b2

View File

@ -926,8 +926,12 @@ static Bitu IRQ1_Handler_PC98(void) {
unsigned char status;
unsigned int patience = 32;
status = IO_ReadB(0x43); /* 8251 status */
while (status & 2/*RxRDY*/) {
/* NTS: CWSDPMI (the PC-98 patched version) has an IRQ 1 interrupt handler that reads the
* keyboard scan code byte ahead of calling this ISR. If we check status first, this
* ISR will never process keyboard input because RxRDY = 0 (CWSDPMI already read it!).
* This suggests that perhaps most PC-98 BIOSes assume a ready data byte on IRQ 1
* and that's how CWSDPMI can get away with doing that (TODO VERIFY THIS ON REAL HARDWARE) */
do {
unsigned char sc_8251 = IO_ReadB(0x41); /* 8251 data */
bool pressed = !(sc_8251 & 0x80);
@ -1156,7 +1160,7 @@ static Bitu IRQ1_Handler_PC98(void) {
}
if (--patience == 0) break; /* in case of stuck 8251 */
status = IO_ReadB(0x43); /* 8251 status */
}
} while (status & 2/*RxRDY*/);
return CBRET_NONE;
}