From 86b1ab5282b6b550cbc01491a7280ee219e90b7f Mon Sep 17 00:00:00 2001 From: scrimpeh Date: Sat, 26 Sep 2015 15:33:56 +0200 Subject: [PATCH] NEShawk - Mapper197 --- .../Nintendo/NES/Boards/MMC3_family/MMC3.cs | 4 +- .../NES/Boards/MMC3_family/Mapper197.cs | 64 ++++++++++++++++++- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/MMC3_family/MMC3.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/MMC3_family/MMC3.cs index 60f49efc50..77265305e9 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/MMC3_family/MMC3.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/MMC3_family/MMC3.cs @@ -52,7 +52,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES } bool oldIrqType; - public void Dispose() + public virtual void Dispose() { regs.Dispose(); chr_regs_1k.Dispose(); @@ -84,7 +84,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES Sync(); } - public void Sync() + public virtual void Sync() { SyncIRQ(); if (prg_mode) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/MMC3_family/Mapper197.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/MMC3_family/Mapper197.cs index 24cb792223..1adfda1ca9 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/MMC3_family/Mapper197.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/MMC3_family/Mapper197.cs @@ -1,4 +1,6 @@ -namespace BizHawk.Emulation.Cores.Nintendo.NES +using BizHawk.Common; + +namespace BizHawk.Emulation.Cores.Nintendo.NES { public sealed class Mapper197 : MMC3Board_Base { @@ -12,8 +14,66 @@ default: return false; } - BaseSetup(); + int num_prg_banks = Cart.prg_size / 8; + prg_mask = num_prg_banks - 1; + + int num_chr_banks = (Cart.chr_size); + chr_mask = num_chr_banks - 1; + + mmc3 = new Mapper197_MMC3(this, num_prg_banks); + SetMirrorType(EMirrorType.Vertical); return true; } } + + public class Mapper197_MMC3 : MMC3 + { + //This board has 512k CHR ROM, so the ByteBuffer in the base class deosn't suffice. + public IntBuffer chr_regs_1k_512 = new IntBuffer(8); + + public Mapper197_MMC3(NES.NESBoardBase board, int num_prg_banks) : base(board, num_prg_banks) + { + + } + + public override void Sync() + { + base.Sync(); + int chr_left = regs[0] << 1; + int chr_right_upper = regs[2] << 1; + int chr_right_lower = regs[3] << 1; + + for (var i = 0; i < 4; i++) + { + chr_regs_1k_512[i] = chr_left | i; + } + + for (var i = 0; i < 2; i++) + { + chr_regs_1k_512[4 | i] = chr_right_upper | i; + chr_regs_1k_512[6 | i] = chr_right_lower | i; + } + + } + + public override void SyncState(Serializer ser) + { + base.SyncState(ser); + ser.Sync("chr_regs_1k_512", ref chr_regs_1k_512); + } + + public override void Dispose() + { + base.Dispose(); + chr_regs_1k_512.Dispose(); + } + + public override int Get_CHRBank_1K(int addr) + { + int bank_1k = addr >> 10; + bank_1k = chr_regs_1k_512[bank_1k]; + return bank_1k; + } + + } }