From b5d2baccd4cd0076be4a883a11bc0d5423f104a1 Mon Sep 17 00:00:00 2001 From: Ben Campbell Date: Wed, 6 Dec 2023 20:19:03 +1300 Subject: [PATCH] Generate Start Of Frame (SOF) interrupts. --- emulator/include/hardware.h | 1 - emulator/src/hardware.cpp | 23 ++++++++++++++++++++--- emulator/src/hw_8042.cpp.unused | 8 -------- emulator/src/hw_fifo.cpp | 14 -------------- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/emulator/include/hardware.h b/emulator/include/hardware.h index b17ecd2..412d483 100644 --- a/emulator/include/hardware.h +++ b/emulator/include/hardware.h @@ -28,6 +28,5 @@ BYTE8 HWReadKeyboardHardware(WORD16 address); void HWWriteKeyboardHardware(WORD16 address,BYTE8 data); void HWResetKeyboardHardware(void); void HWKeyboardHardwareDequeue(int key); -int HWCheckKeyboardInterruptEnabled(void); #endif \ No newline at end of file diff --git a/emulator/src/hardware.cpp b/emulator/src/hardware.cpp index d19e4f5..06aa5f6 100644 --- a/emulator/src/hardware.cpp +++ b/emulator/src/hardware.cpp @@ -118,9 +118,12 @@ void HWSync(void) { int key = HWQueueRemove(&keyboardQueue); HWKeyboardHardwareDequeue(key); //printf("Dequeue %x\n",key); - if (HWCheckKeyboardInterruptEnabled()) { - //printf("Interrupt\n"); - CPUInterruptMaskable(); // fire IRQ + // Trigger a kbd interrupt (if it's not masked). + if ((IOReadMemory(0,0xD66C) & 0x04) == 0) { + // mark it pending + BYTE8 pending = IOReadMemory(0, 0xD660); + pending |= 0x04; + IOWriteMemory(0, 0xD660, pending); } } if (IOReadMemory(0,0xD658) & 1) { // Timer on. @@ -133,6 +136,20 @@ void HWSync(void) { a++; } } + + // Trigger an SOF interrupt (if it's not masked). + if ((IOReadMemory(0,0xD66C) & 0x01) == 0) { + // mark it pending + BYTE8 pending = IOReadMemory(0, 0xD660); + pending |= 0x01; + IOWriteMemory(0, 0xD660, pending); + } + + // if there are any interrupts pending, tell the CPU to run the handler. + if (IOReadMemory(0, 0xD660) != 0) { + CPUInterruptMaskable(); + } + } // ******************************************************************************************************************************* diff --git a/emulator/src/hw_8042.cpp.unused b/emulator/src/hw_8042.cpp.unused index 95e38bf..4255260 100644 --- a/emulator/src/hw_8042.cpp.unused +++ b/emulator/src/hw_8042.cpp.unused @@ -57,11 +57,3 @@ void HWWriteKeyboardHardware(WORD16 address,BYTE8 data) { if (data == 0x60) {} // TODO: Enable interrupt ? } } - -int HWCheckKeyboardInterruptEnabled(void) { - if ((IOReadMemory(0,0xD66C) & 0x04) == 0) { // Bit masked zero ? - IOWriteMemory(0,0xD660,4); // Set Pending Reg Bit 2 - return -1; - } - return 0; -} \ No newline at end of file diff --git a/emulator/src/hw_fifo.cpp b/emulator/src/hw_fifo.cpp index 8d5c01e..76ebe28 100644 --- a/emulator/src/hw_fifo.cpp +++ b/emulator/src/hw_fifo.cpp @@ -75,17 +75,3 @@ BYTE8 HWReadKeyboardHardware(WORD16 address) { void HWWriteKeyboardHardware(WORD16 address,BYTE8 data) { // Should clear the queue here. Not really required ? } - -// ******************************************************************************************************************************* -// -// Interrupt for new key enabled ? -// -// ******************************************************************************************************************************* - -int HWCheckKeyboardInterruptEnabled(void) { - if ((IOReadMemory(0,0xD66C) & 0x04) == 0) { // Bit masked zero ? - IOWriteMemory(0,0xD660,4); // Set Pending Reg Bit 2 - return -1; - } - return 0; -} \ No newline at end of file