From 0a85b24b880818305a6405c3029e9a045b191cf1 Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 28 Oct 2016 12:24:40 -0500 Subject: [PATCH] NesHawk - support board UNIF_BMC-810544-C-A1 --- .../BizHawk.Emulation.Cores.csproj | 1 + .../NES/Boards/UNIF/UNIF_BMC-810544-C-A1.cs | 62 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/UNIF/UNIF_BMC-810544-C-A1.cs diff --git a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj index 569363dae2..fee0ff6fc6 100644 --- a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj +++ b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj @@ -754,6 +754,7 @@ + diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/UNIF/UNIF_BMC-810544-C-A1.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/UNIF/UNIF_BMC-810544-C-A1.cs new file mode 100644 index 0000000000..4fb8e19e80 --- /dev/null +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/UNIF/UNIF_BMC-810544-C-A1.cs @@ -0,0 +1,62 @@ +using BizHawk.Common; +using BizHawk.Common.NumberExtensions; + +namespace BizHawk.Emulation.Cores.Nintendo.NES +{ + public sealed class UNIF_BMC_810544_C_A1 : NES.NESBoardBase + { + private int latche; + private int prg_mask_32k, prg_mask_16k; + + public override bool Configure(NES.EDetectionOrigin origin) + { + switch (Cart.board_type) + { + case "UNIF_BMC-810544-C-A1": + break; + default: + return false; + } + + prg_mask_32k = Cart.prg_size / 32 - 1; + prg_mask_16k = Cart.prg_size / 16 - 1; + + return true; + } + + public override void SyncState(Serializer ser) + { + ser.Sync("latche", ref latche); + base.SyncState(ser); + } + + public override void WritePRG(int addr, byte value) + { + latche = addr & 65535; + SetMirrorType(addr.Bit(3) ? EMirrorType.Vertical : EMirrorType.Horizontal); + } + + public override byte ReadPRG(int addr) + { + int bank = latche >> 7; + if (latche.Bit(6)) + { + return ROM[((bank & prg_mask_32k) << 15) + addr]; + } + + int bank16 = (bank << 1) | ((latche >> 5) & 1); + bank16 &= prg_mask_16k; + return ROM[(bank16 << 14) + (addr & 0x3FFF)]; + } + + public override byte ReadPPU(int addr) + { + if (addr < 0x2000) + { + return VROM[((latche & 0x0F) << 13) + addr]; + } + + return base.ReadPPU(addr); + } + } +}