From 78af60853aed4212cb7f4642f771413323e90f85 Mon Sep 17 00:00:00 2001 From: negative Date: Sun, 5 Jun 2022 18:57:15 +0800 Subject: [PATCH] FDS: Update IRQ based on latest hardware notes - IRQ updates based on latest notes. Verified with test rom. https://www.nesdev.org/wiki/Family_Computer_Disk_System#IRQ_control_($4022) Discussion and test rom file: https://forums.nesdev.org/viewtopic.php?f=3&t=16507 test rom: https://forums.nesdev.org/viewtopic.php?p=205052#p205052 - Puff Puff Golf is still problematic and unplayable. added notes for it. - Fix typo for a previous commit. --- src/fds.cpp | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/fds.cpp b/src/fds.cpp index 35924a4a4..f608436f3 100644 --- a/src/fds.cpp +++ b/src/fds.cpp @@ -223,14 +223,23 @@ void FCEU_FDSSelect(void) FCEU_DispMessage("Disk %d Side %c Selected", 0, SelectDisk >> 1, (SelectDisk & 1) ? 'B' : 'A'); } -#define IRQ_Repeat (IRQa & 0x01) -#define IRQ_Enabled (IRQa & 0x02) +#define IRQ_Repeat 0x01 +#define IRQ_Enabled 0x02 static void FDSFix(int a) { - if ((IRQa & IRQ_Enabled) && IRQCount) { + if (IRQa & IRQ_Enabled) { IRQCount -= a; if (IRQCount <= 0) { IRQCount = IRQLatch; + /* Puff Puff Golf notes: + Game freezes while music playing ingame after inserting Disk Side B. + IRQ is usually fired at scanline 169 and 183 for music to work. + + At some point after inserting disk B, an IRQ is fired at scanline 174 which + will just freeze game while music plays. + + If you ignore triggering IRQ altogether, game plays but no music + */ X6502_IRQBegin(FCEU_IQEXT); if (!(IRQa & IRQ_Repeat)) { IRQa &= ~IRQ_Enabled; @@ -574,21 +583,30 @@ void FDSSoundReset(void) { static DECLFW(FDSWrite) { switch (A) { case 0x4020: - X6502_IRQEnd(FCEU_IQEXT); IRQLatch &= 0xFF00; IRQLatch |= V; break; case 0x4021: - X6502_IRQEnd(FCEU_IQEXT); IRQLatch &= 0xFF; IRQLatch |= V << 8; break; case 0x4022: - X6502_IRQEnd(FCEU_IQEXT); - IRQCount = IRQLatch; - IRQa = V & 3; + if (FDSRegs[3] & 1) { + IRQa = V & 0x03; + if (IRQa & IRQ_Enabled) { + IRQCount = IRQLatch; + } else { + X6502_IRQEnd(FCEU_IQEXT); + } + } + break; + case 0x4023: + if (!(V & 0x01)) { + IRQa &= ~IRQ_Enabled; + X6502_IRQEnd(FCEU_IQEXT); + X6502_IRQEnd(FCEU_IQEXT2); + } break; - case 0x4023: break; case 0x4024: if (mapperFDS_diskinsert && ~mapperFDS_control & 0x04) {