From bbf5be7d74b5d73ee0f567633567c55daf86b375 Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 17 Jul 2012 04:06:48 +0000 Subject: [PATCH] NES - add mappers 200 & 231, PRG mapping isn't quite right on either but some games work --- BizHawk.Emulation/BizHawk.Emulation.csproj | 2 + .../Consoles/Nintendo/NES/Boards/Mapper200.cs | 109 ++++++++++++++++++ .../Consoles/Nintendo/NES/Boards/Mapper231.cs | 97 ++++++++++++++++ 3 files changed, 208 insertions(+) create mode 100644 BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper200.cs create mode 100644 BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper231.cs diff --git a/BizHawk.Emulation/BizHawk.Emulation.csproj b/BizHawk.Emulation/BizHawk.Emulation.csproj index cc3b616974..048a84b5ab 100644 --- a/BizHawk.Emulation/BizHawk.Emulation.csproj +++ b/BizHawk.Emulation/BizHawk.Emulation.csproj @@ -156,8 +156,10 @@ + + diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper200.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper200.cs new file mode 100644 index 0000000000..0e17077ead --- /dev/null +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper200.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BizHawk.Emulation.Consoles.Nintendo +{ + class Mapper200 : NES.NESBoardBase + { + /* + Here are Disch's original notes: + ======================== + = Mapper 200 = + ======================== + + Example Games: + -------------------------- + 1200-in-1 + 36-in-1 + + + Registers: + --------------------------- + + + $8000-FFFF: A~[.... .... .... MRRR] + M = Mirroring (0=Vert, 1=Horz) + R = PRG/CHR Reg + + + CHR Setup: + --------------------------- + + $0000 $0400 $0800 $0C00 $1000 $1400 $1800 $1C00 + +---------------------------------------------------------------+ + | $8000 | + +---------------------------------------------------------------+ + + + PRG Setup: + --------------------------- + + $8000 $A000 $C000 $E000 + +---------------+---------------+ + | $8000 | $8000 | + +---------------+---------------+ + */ + int reg; + int prg_bank_mask_16k; + bool low; + public override bool Configure(NES.EDetectionOrigin origin) + { + switch (Cart.board_type) + { + case "MAPPER200": + case "MAPPER229": + break; + default: + return false; + } + + prg_bank_mask_16k = Cart.prg_size / 16 - 1; + + return true; + } + + public override void SyncState(Serializer ser) + { + ser.Sync("reg", ref reg); + base.SyncState(ser); + } + + public override void WritePRG(int addr, byte value) + { + if (addr.Bit(3)) + { + SetMirrorType(EMirrorType.Horizontal); + } + else + { + SetMirrorType(EMirrorType.Vertical); + } + reg = addr & 0x07; + low = addr.Bit(0); + } + + public override byte ReadPRG(int addr) + { + if (addr < 0x4000) + { + return ROM[(reg * 0x4000) + addr]; + } + else + { + int bank = reg >> 1; + return ROM[(bank * 0x4000) + addr]; + } + } + + public override byte ReadPPU(int addr) + { + if (addr < 0x2000) + { + return VROM[(reg * 0x2000) + addr]; + } + return base.ReadPPU(addr); + } + } +} diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper231.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper231.cs new file mode 100644 index 0000000000..a219e7ded2 --- /dev/null +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper231.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BizHawk.Emulation.Consoles.Nintendo +{ + class Mapper231 : NES.NESBoardBase + { + /* + * Here are Disch's original notes: + ======================== + = Mapper 231 = + ======================== + + Example Game: + -------------------------- + 20-in-1 + + + + Registers: + --------------------------- + + $8000-FFFF: A~[.... .... M.LP PPP.] + M = Mirroring (0=Vert, 1=Horz) + L = Low bit of PRG + P = High bits of PRG + + + + PRG Setup: + --------------------------- + + Note that 'L' and 'P' bits make up the PRG reg, and the 'L' is the low bit. + + + $8000 $A000 $C000 $E000 + +---------------+---------------+ + | $8000 AND $1E | $8000 | + +---------------+---------------+ + */ + public int reg; + public bool low; + public int prg_bank_mask_16k; + + public override bool Configure(NES.EDetectionOrigin origin) + { + switch (Cart.board_type) + { + case "MAPPER231": + break; + default: + return false; + } + + prg_bank_mask_16k = Cart.prg_size / 16 - 1; + return true; + } + + public override void SyncState(Serializer ser) + { + ser.Sync("reg", ref reg); + ser.Sync("low", ref low); + base.SyncState(ser); + } + + public override void WritePRG(int addr, byte value) + { + if (addr.Bit(7)) + { + SetMirrorType(EMirrorType.Horizontal); + } + else + { + SetMirrorType(EMirrorType.Vertical); + } + + low = addr.Bit(5); + reg = addr & 0x1E; + } + + public override byte ReadPRG(int addr) + { + if (low) + { + int bank = ((reg >> 1) & 0x0F) & (prg_bank_mask_16k >> 1); + return ROM[(bank * 0x8000) + addr]; + } + else + { + return ROM[((reg & prg_bank_mask_16k) * 0x4000) + addr]; + + } + } + } +}