From 6a3a3114c703055fcc79a65591f04c46a5ea0e45 Mon Sep 17 00:00:00 2001 From: tomcw Date: Sat, 4 Feb 2023 12:09:19 +0000 Subject: [PATCH] MB:6522: fix edge case for IRQ not firing for very small latch values. (Fixes #1175) --- source/6522.h | 1 + source/Mockingboard.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/source/6522.h b/source/6522.h index aa25cb23..bf780b99 100644 --- a/source/6522.h +++ b/source/6522.h @@ -52,6 +52,7 @@ public: USHORT GetRegT2C(void) { return m_regs.TIMER2_COUNTER.w; } void GetRegs(BYTE regs[SIZE_6522_REGS]) { memcpy(®s[0], (BYTE*)&m_regs, SIZE_6522_REGS); } // For debugger void SetRegORA(BYTE reg) { m_regs.ORA = reg; } + bool IsTimer1IrqDelay(void) { return m_timer1IrqDelay ? true : false; } BYTE Read(BYTE nReg); void Write(BYTE nReg, BYTE nValue); diff --git a/source/Mockingboard.cpp b/source/Mockingboard.cpp index 0199f328..8a7bc810 100644 --- a/source/Mockingboard.cpp +++ b/source/Mockingboard.cpp @@ -834,6 +834,8 @@ int MockingboardCard::MB_SyncEventCallbackInternal(int id, int /*cycles*/, ULONG if ((pMB->sy6522.GetReg(SY6522::rACR) & SY6522::ACR_RUNMODE) == SY6522::ACR_RM_FREERUNNING) { pMB->sy6522.StartTimer1(); + if (pMB->sy6522.IsTimer1IrqDelay()) + return 0x0001; // T1C=0xFFFF, which is really -1, as there's 1 cycle until underflow occurs return pMB->sy6522.GetRegT1C() + SY6522::kExtraTimerCycles; }