From 514d2adb7907e44d9f096d40042888472afe885a Mon Sep 17 00:00:00 2001 From: tomcw Date: Sat, 26 Feb 2022 21:10:42 +0000 Subject: [PATCH] 6522: Fix IFR.T2 when counter.b15=1 --- source/6522.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/6522.cpp b/source/6522.cpp index 587d6e50..90be685e 100644 --- a/source/6522.cpp +++ b/source/6522.cpp @@ -292,8 +292,10 @@ bool SY6522::IsTimer1Underflowed(BYTE reg) bool SY6522::IsTimer2Underflowed(BYTE reg) { - // FIXME: "m_regs.TIMER2_COUNTER.w >= 0" is always true! So function returns true when GetTimer2Counter() returns with b15==1 - return m_regs.TIMER2_COUNTER.w >= 0 && (short)GetTimer2Counter(reg) < 0; + USHORT counter = m_regs.TIMER2_COUNTER.w; // NB. don't update the real T2C + int timerIrqDelay = m_timer2IrqDelay; // NB. don't update the real timer2IrqDelay + const UINT opcodeCycleAdjust = GetOpcodeCyclesForRead(reg); // to compensate for the 4/5/6 cycle read opcode + return CheckTimerUnderflow(counter, timerIrqDelay, opcodeCycleAdjust); } //-----------------------------------------------------------------------------