From cf8201dbe37a24d2cc5d1b517e870dea61c4b031 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Sun, 18 Sep 2016 13:53:17 -0400 Subject: [PATCH] Fix mapper 183 Notes: This game sounds different in Nestopia and punes, are we missing a sound component? --- .../Consoles/Nintendo/NES/Boards/Mapper183.cs | 79 ++++++++++++++++--- 1 file changed, 67 insertions(+), 12 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/Mapper183.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/Mapper183.cs index c035458b65..8820a28f1e 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/Mapper183.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/Mapper183.cs @@ -1,5 +1,7 @@ using BizHawk.Common; - +using BizHawk.Common.NumberExtensions; +using System; + namespace BizHawk.Emulation.Cores.Nintendo.NES { // Adpated from FCEUX src @@ -8,7 +10,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES private ByteBuffer prg = new ByteBuffer(4); private ByteBuffer chr = new ByteBuffer(8); - private int prg_bank_mask_8k, chr_bank_mask_1k; + private int IRQLatch = 0; + private int IRQCount = 0; + private bool IRQMode; + private bool IRQa = false; + private bool IRQr = false; + + private int prg_bank_mask_8k, chr_bank_mask_1k, IRQPre=341; public override bool Configure(NES.EDetectionOrigin origin) { @@ -40,10 +48,43 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES case 0: SetMirrorType(EMirrorType.Vertical); break; case 1: SetMirrorType(EMirrorType.Horizontal); break; case 2: SetMirrorType(EMirrorType.OneScreenA); break; - case 3: SetMirrorType(EMirrorType.Vertical); break; + case 3: SetMirrorType(EMirrorType.OneScreenB); break; } } + public override void ClockCPU() + { + if (IRQa) + { + if (IRQMode) + { + IRQCount++; + if (IRQCount == 0xFF) + { + IRQSignal = true; + IRQCount = IRQLatch; + } + } + else + { + IRQPre -= 3; + if (IRQPre <= 0) + { + IRQPre += 341; + IRQCount++; + if (IRQCount >= 0x100) + { + IRQSignal = IRQa; + IRQCount = IRQLatch; + } + } + } + + } + } + + + public override void WriteWRAM(int addr, byte value) { WriteReg(addr + 0x6000, value); @@ -70,13 +111,27 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES case 0x8800: prg[0] = value; break; case 0xA800: prg[1] = value; break; case 0xA000: prg[2] = value; break; - case 0x9800: SetMirroring(value & 3); break; - - // TODO: IRQ - case 0xF000: break; - case 0xF004: break; - case 0xF008: break; - case 0xF00C: break; + case 0x9800: SetMirroring(value & 3); break; + + // TODO: IRQ + case 0xF000: IRQLatch = ((IRQLatch & 0xF0) | (value & 0xF)); break; + case 0xF004: IRQLatch = ((IRQLatch & 0x0F) | ((value & 0xF) << 4)); break; + case 0xF008: + IRQMode = value.Bit(2); + IRQa = value.Bit(1);//value>0 ? true:false; + IRQr = value.Bit(0); + if (IRQa) + { + IRQPre = 341; + IRQCount = IRQLatch; + } + IRQSignal = false; + break; + case 0xF00C: + IRQSignal = false; + IRQa = IRQr; + break; + } } @@ -93,8 +148,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES } public override byte ReadWRAM(int addr) - { - return ROM[((prg[3] & prg_bank_mask_8k)) << 13 + (addr & 0x1FFF)]; + { + return ROM[(((prg[3] & prg_bank_mask_8k)) << 13) + (addr & 0x1FFF)]; } public override byte ReadPRG(int addr)