diff --git a/BizHawk.Emulation/BizHawk.Emulation.csproj b/BizHawk.Emulation/BizHawk.Emulation.csproj index 8395c1f06a..865f1c96d1 100644 --- a/BizHawk.Emulation/BizHawk.Emulation.csproj +++ b/BizHawk.Emulation/BizHawk.Emulation.csproj @@ -173,6 +173,7 @@ + diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper225.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper225.cs index 8dd19278eb..1150efbf4e 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper225.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper225.cs @@ -38,7 +38,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo CHR Setup: --------------------------- - $0000 $0400 $0800 $0C00 $1000 $1400 $1800 $1C00 + $0000 $0400 $0800 $0C00 $1000 $1400 $1800 $1C00 +---------------------------------------------------------------+ CHR Mode 0: | $8000 | +---------------------------------------------------------------+ @@ -58,6 +58,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo bool prg_mode = false; int chr_reg; int prg_reg; + ByteBuffer eRAM = new ByteBuffer(4); + int chr_bank_mask_8k, prg_bank_mask_16k, prg_bank_mask_32k; public override bool Configure(NES.EDetectionOrigin origin) { @@ -68,6 +70,9 @@ namespace BizHawk.Emulation.Consoles.Nintendo default: return false; } + chr_bank_mask_8k = Cart.chr_size / 8 - 1; + prg_bank_mask_16k = Cart.prg_size / 16 - 1; + prg_bank_mask_32k = Cart.prg_size / 32 - 1; SetMirrorType(EMirrorType.Vertical); @@ -79,13 +84,20 @@ namespace BizHawk.Emulation.Consoles.Nintendo ser.Sync("prg_reg", ref prg_reg); ser.Sync("chr_reg", ref chr_reg); ser.Sync("prg_mode", ref prg_mode); + ser.Sync("eRAM", ref eRAM); base.SyncState(ser); } + public override void Dispose() + { + eRAM.Dispose(); + base.Dispose(); + } + public override void WritePRG(int addr, byte value) { + addr += 0x8000; prg_mode = addr.Bit(12); - if (addr.Bit(13)) { SetMirrorType(EMirrorType.Horizontal); @@ -94,6 +106,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo { SetMirrorType(EMirrorType.Vertical); } + int high = (addr & 0x4000) >> 8; prg_reg = (addr >> 6) & 0x3F | high; chr_reg = addr & 0x3F | high; @@ -101,13 +114,14 @@ namespace BizHawk.Emulation.Consoles.Nintendo public override byte ReadPRG(int addr) { - if (prg_mode) + if (prg_mode == false) { - return ROM[((prg_reg >> 1) * 0x8000) + addr]; + int bank = (prg_reg >> 1) & prg_bank_mask_32k; + return ROM[(bank * 0x8000) + addr]; } else { - return ROM[(prg_reg * 0x4000) + (addr & 0x3FFF)]; + return ROM[((prg_reg & prg_bank_mask_16k) * 0x4000) + (addr & 0x3FFF)]; } } @@ -115,9 +129,29 @@ namespace BizHawk.Emulation.Consoles.Nintendo { if (addr < 0x2000) { - return VROM[(chr_reg * 0x2000) + addr]; + return VROM[((chr_reg & chr_bank_mask_8k) * 0x2000) + addr]; } return base.ReadPPU(addr); } + + public override void WriteEXP(int addr, byte value) + { + if (addr >= 0x1800) + { + eRAM[(addr & 0x07)] = (byte)(value & 0x0F); + } + } + + public override byte ReadEXP(int addr) + { + if (addr >= 0x1800) + { + return eRAM[(addr & 0x07)]; + } + else + { + return base.ReadEXP(addr); + } + } } }