diff --git a/src/boards/vrc2and4.cpp b/src/boards/vrc2and4.cpp index 97e6e535..3b7974b1 100644 --- a/src/boards/vrc2and4.cpp +++ b/src/boards/vrc2and4.cpp @@ -23,7 +23,7 @@ static bool isPirate; static uint8 is22, reg1mask, reg2mask; static uint16 IRQCount; -static uint8 IRQLatch, IRQa; +static uint8 IRQLatch, IRQa, IRQMode; static uint8 prgreg[2], chrreg[8]; static uint16 chrhi[8]; static uint8 regcmd, irqcmd, mirr, big_bank; @@ -45,6 +45,7 @@ static SFORMAT StateRegs[] = { &IRQCount, 2, "IRQC" }, { &IRQLatch, 1, "IRQL" }, { &IRQa, 1, "IRQA" }, + { &IRQMode, 1, "IRQM" }, { 0 } }; @@ -115,7 +116,7 @@ static DECLFW(VRC24Write) { case 0x9003: regcmd = V; Sync(); break; case 0xF000: X6502_IRQEnd(FCEU_IQEXT); IRQLatch &= 0xF0; IRQLatch |= V & 0xF; break; case 0xF001: X6502_IRQEnd(FCEU_IQEXT); IRQLatch &= 0x0F; IRQLatch |= V << 4; break; - case 0xF002: X6502_IRQEnd(FCEU_IQEXT); acount = 0; IRQCount = IRQLatch; IRQa = V & 2; irqcmd = V & 1; break; + case 0xF002: X6502_IRQEnd(FCEU_IQEXT); acount = 0; IRQCount = IRQLatch; IRQMode = V & 4; IRQa = V & 2; irqcmd = V & 1; break; case 0xF003: X6502_IRQEnd(FCEU_IQEXT); IRQa = irqcmd; break; } } @@ -136,16 +137,28 @@ static void VRC24Power(void) { void VRC24IRQHook(int a) { #define LCYCS 341 if (IRQa) { - acount += a * 3; - if (acount >= LCYCS) { - while (acount >= LCYCS) { - acount -= LCYCS; + if (IRQMode) { + acount += a; + while (acount > 0) { + acount--; IRQCount++; if (IRQCount & 0x100) { X6502_IRQBegin(FCEU_IQEXT); IRQCount = IRQLatch; } } + } else { + acount += a * 3; + if (acount >= LCYCS) { + while (acount >= LCYCS) { + acount -= LCYCS; + IRQCount++; + if (IRQCount & 0x100) { + X6502_IRQBegin(FCEU_IQEXT); + IRQCount = IRQLatch; + } + } + } } } } diff --git a/src/boards/vrc6.cpp b/src/boards/vrc6.cpp index 43cd3824..51f58ebb 100644 --- a/src/boards/vrc6.cpp +++ b/src/boards/vrc6.cpp @@ -25,7 +25,7 @@ static uint8 is26; static uint8 prg[2], chr[8], mirr; -static uint8 IRQLatch, IRQa, IRQd; +static uint8 IRQLatch, IRQa, IRQd, IRQMode; static int32 IRQCount, CycleCount; static uint8 *WRAM = NULL; static uint32 WRAMSIZE; @@ -40,6 +40,7 @@ static SFORMAT StateRegs[] = { &IRQLatch, 1, "IRQL" }, { &IRQCount, 4, "IRQC" }, { &CycleCount, 4, "CYCC" }, + { &IRQMode, 1, "IRQM" }, { 0 } }; @@ -109,6 +110,7 @@ static DECLFW(VRC6Write) { case 0xE003: chr[7] = V; Sync(); break; case 0xF000: IRQLatch = V; X6502_IRQEnd(FCEU_IQEXT); break; case 0xF001: + IRQMode = V & 4; IRQa = V & 2; IRQd = V & 1; if (V & 2) @@ -132,13 +134,25 @@ static void VRC6Power(void) { static void VRC6IRQHook(int a) { if (IRQa) { - CycleCount += a * 3; - while(CycleCount >= 341) { - CycleCount -= 341; - IRQCount++; - if (IRQCount == 0x100) { - IRQCount = IRQLatch; - X6502_IRQBegin(FCEU_IQEXT); + if (IRQMode) { + CycleCount += a; + while (CycleCount > 0) { + CycleCount--; + IRQCount++; + if (IRQCount & 0x100) { + X6502_IRQBegin(FCEU_IQEXT); + IRQCount = IRQLatch; + } + } + } else { + CycleCount += a * 3; + while(CycleCount >= 341) { + CycleCount -= 341; + IRQCount++; + if (IRQCount == 0x100) { + IRQCount = IRQLatch; + X6502_IRQBegin(FCEU_IQEXT); + } } } } diff --git a/src/boards/vrc7.cpp b/src/boards/vrc7.cpp index d4df33a9..38e5d83b 100644 --- a/src/boards/vrc7.cpp +++ b/src/boards/vrc7.cpp @@ -21,7 +21,7 @@ #include "mapinc.h" static uint8 vrc7idx, preg[3], creg[8], mirr; -static uint8 IRQLatch, IRQa, IRQd; +static uint8 IRQLatch, IRQa, IRQd, IRQMode; static int32 IRQCount, CycleCount; static uint8 *WRAM = NULL; static uint32 WRAMSIZE; @@ -44,6 +44,7 @@ static SFORMAT StateRegs[] = { &IRQCount, 4, "IRQC" }, { &CycleCount, 4, "CYCC" }, { (void**)VRC7Sound_saveptr, sizeof(*VRC7Sound) | FCEUSTATE_INDIRECT, "VRC7" }, + { &IRQMode, 1, "IRQM" }, {0} }; @@ -134,6 +135,7 @@ static DECLFW(VRC7Write) { case 0xE000: mirr = V & 3; Sync(); break; case 0xE010: IRQLatch = V; X6502_IRQEnd(FCEU_IQEXT); break; case 0xF000: + IRQMode = V & 4; IRQa = V & 2; IRQd = V & 1; if (V & 2) @@ -165,13 +167,25 @@ static void VRC7Close(void) static void VRC7IRQHook(int a) { if (IRQa) { - CycleCount += a * 3; - while(CycleCount >= 341) { - CycleCount -= 341; - IRQCount++; - if (IRQCount == 0x100) { - IRQCount = IRQLatch; - X6502_IRQBegin(FCEU_IQEXT); + if (IRQMode) { + CycleCount += a; + while (CycleCount > 0) { + CycleCount--; + IRQCount++; + if (IRQCount & 0x100) { + X6502_IRQBegin(FCEU_IQEXT); + IRQCount = IRQLatch; + } + } + } else { + CycleCount += a * 3; + while(CycleCount >= 341) { + CycleCount -= 341; + IRQCount++; + if (IRQCount == 0x100) { + IRQCount = IRQLatch; + X6502_IRQBegin(FCEU_IQEXT); + } } } }