From ec848f2c43f81ffcd910cc3597eec517a21a0025 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Tue, 31 Oct 2017 10:36:00 -0400 Subject: [PATCH] NESHawk: Update Mapper 114 --- .../NES/Boards/MMC3_family/Mapper114.cs | 131 +++++++++--------- 1 file changed, 67 insertions(+), 64 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/MMC3_family/Mapper114.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/MMC3_family/Mapper114.cs index 9405823f0d..5786a0042d 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/MMC3_family/Mapper114.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/MMC3_family/Mapper114.cs @@ -1,60 +1,63 @@ -using BizHawk.Common; +using BizHawk.Common; using System; -namespace BizHawk.Emulation.Cores.Nintendo.NES +namespace BizHawk.Emulation.Cores.Nintendo.NES { // Mapper for Aladdin Super Game - public sealed class Mapper114 : MMC3Board_Base - { - private ByteBuffer EXPREGS = new ByteBuffer(2); - - private byte[] sec = { 0, 3, 1, 5, 6, 7, 2, 4 }; - - public override bool Configure(NES.EDetectionOrigin origin) - { - switch (Cart.board_type) - { + public sealed class Mapper114 : MMC3Board_Base + { + private ByteBuffer EXPREGS = new ByteBuffer(2); + + private int prg_mask_16; + + private byte[] sec = { 0, 3, 1, 5, 6, 7, 2, 4 }; + + public override bool Configure(NES.EDetectionOrigin origin) + { + switch (Cart.board_type) + { case "MAPPER114": - break; - default: - return false; - } - - BaseSetup(); - SetMirrorType(EMirrorType.Horizontal); - mmc3.MMC3Type = MMC3.EMMC3Type.MMC3A; - return true; - } - - public override void Dispose() - { - EXPREGS.Dispose(); - base.Dispose(); - } - - public override void SyncState(Serializer ser) - { - base.SyncState(ser); - ser.Sync("expregs", ref EXPREGS); - } - - public override void WriteEXP(int addr, byte value) + break; + default: + return false; + } + + BaseSetup(); + SetMirrorType(EMirrorType.Horizontal); + mmc3.MMC3Type = MMC3.EMMC3Type.MMC3A; + prg_mask_16 = Cart.prg_size / 16 - 1; + return true; + } + + public override void Dispose() { - if ((addr & 0x7) == 0 && addr >= 0x1000) - { - EXPREGS[0] = value; - } - } - - public override void WriteWRAM(int addr, byte value) + EXPREGS.Dispose(); + base.Dispose(); + } + + public override void SyncState(Serializer ser) { - if ((addr & 0x7) == 0) - { - EXPREGS[0] = value; - } - } - - public override void WritePRG(int addr, byte value) + base.SyncState(ser); + ser.Sync("expregs", ref EXPREGS); + } + + public override void WriteEXP(int addr, byte value) + { + if ((addr & 0x7) == 0 && addr >= 0x1000) + { + EXPREGS[0] = value; + } + } + + public override void WriteWRAM(int addr, byte value) + { + if ((addr & 0x7) == 0) + { + EXPREGS[0] = value; + } + } + + public override void WritePRG(int addr, byte value) { switch (addr & 0x6000) { @@ -85,20 +88,20 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES base.WritePRG(0x6000, value); } break; - } - } - - public override byte ReadPRG(int addr) - { - if ((EXPREGS[0] & 0x80) > 0) + } + } + + public override byte ReadPRG(int addr) + { + if ((EXPREGS[0] & 0x80) > 0) { - var bank = (EXPREGS[0] & 0x1F); - return ROM[(bank << 14) + (addr & 0x3FFF)]; - } - else + var bank = EXPREGS[0] & 0x1F & prg_mask_16; + return ROM[(bank << 14) + (addr & 0x3FFF)]; + } + else { - return base.ReadPRG(addr); - } - } - } + return base.ReadPRG(addr); + } + } + } }