diff --git a/BizHawk.Emulation/BizHawk.Emulation.csproj b/BizHawk.Emulation/BizHawk.Emulation.csproj index f28b353438..117d3149fc 100644 --- a/BizHawk.Emulation/BizHawk.Emulation.csproj +++ b/BizHawk.Emulation/BizHawk.Emulation.csproj @@ -177,6 +177,7 @@ + diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper50.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper50.cs new file mode 100644 index 0000000000..ee87270a06 --- /dev/null +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper50.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BizHawk.Emulation.Consoles.Nintendo +{ + class Mapper50 : NES.NESBoardBase + { + //http://wiki.nesdev.com/w/index.php/INES_Mapper_050 + + byte prg_bank; + int prg_bank_mask_8k; + + public override bool Configure(NES.EDetectionOrigin origin) + { + //analyze board type + switch (Cart.board_type) + { + case "MAPPER050": + break; + default: + return false; + } + prg_bank = 0; + prg_bank_mask_8k = Cart.prg_size / 8 - 1; + + return true; + } + + public override void SyncState(Serializer ser) + { + ser.Sync("prg_bank", ref prg_bank); + base.SyncState(ser); + } + + public override void WriteEXP(int addr, byte value) + { + addr &= 0x0120; + if (addr == 0x0020) + { + //byte low = (byte)((value >> 1) & 0x03); + //byte middle = (byte)(value & 0x01); + //byte high = (byte)((value >> 3) & 0x01); + //prg_bank = (byte)(low | (middle << 2) | (high << 3)); + + prg_bank = (byte)(((value & 1) << 2) | ((value & 2) >> 1) | ((value & 4) >> 1) | (value & 8)); + + Console.WriteLine(prg_bank); + } + base.WriteEXP(addr, value); + } + + public override byte ReadPRG(int addr) + { + if (addr < 0x2000) + { + return ROM[(0x08 * 0x2000) + (addr & 0x1FFF)]; + } + else if (addr < 0x4000) + { + return ROM[(0x09 * 0x2000) + (addr & 0x1FFF)]; + } + else if (addr < 0x6000) + { + int bank = (prg_bank & prg_bank_mask_8k); + return ROM[(bank * 0x2000) + (addr & 0x1FFF)]; + } + else + { + return ROM[(0x0B * 0x2000) + (addr & 0x1FFF)]; + } + } + + public override byte ReadPPU(int addr) + { + return ROM[(0x0F * 0x2000) + (addr & 0x1FFF)]; + } + } +}