diff --git a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj index 0c26ffa910..2e39d7e125 100644 --- a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj +++ b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj @@ -533,6 +533,7 @@ + diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/Mapper147.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/Mapper147.cs new file mode 100644 index 0000000000..99cea04bbd --- /dev/null +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/Mapper147.cs @@ -0,0 +1,76 @@ +using BizHawk.Common; + +namespace BizHawk.Emulation.Cores.Nintendo.NES +{ + // Challenge of the Dragon (Sachen) [!] + // Chinese KungFu (Sachen-JAP) [!] + public sealed class Mapper147 : NES.NESBoardBase + { + private int _chrBankMask_8k; + private int _prgBankMask_32k; + + private int _chrRegister; + + public override bool Configure(NES.EDetectionOrigin origin) + { + //configure + switch (Cart.board_type) + { + case "MAPPER147": + break; + default: + return false; + } + + _chrBankMask_8k = Cart.chr_size / 8 - 1; + _prgBankMask_32k = Cart.prg_size / 32 - 1; + + return true; + } + + public override void WriteEXP(int addr, byte value) + { + if ((addr & 0x103) == 0x102) + { + _chrRegister = value; + } + else + { + base.WriteEXP(addr, value); + } + } + + public override void WritePRG(int addr, byte value) + { + if ((addr & 0x103) == 0x102) + { + _chrRegister = value; + } + } + + public override byte ReadPPU(int addr) + { + if (addr < 0x2000) + { + int bank = _chrRegister >> 3 & 0x0F; + bank &= _chrBankMask_8k; + return VROM[(bank * 0x2000) + (addr & 0x1FFF)]; + } + + return base.ReadPPU(addr); + } + + public override byte ReadPRG(int addr) + { + int bank = ((_chrRegister & 0x80) >> 6) | ((_chrRegister >> 2) & 1); + bank &= _prgBankMask_32k; + return ROM[(bank * 0x8000) + (addr & 0x7FFF)]; + } + + public override void SyncState(Serializer ser) + { + base.SyncState(ser); + ser.Sync("chrRegister", ref _chrRegister); + } + } +}