From c5a2d0f8f0033acc8f82af5b2f3080f85029ae9a Mon Sep 17 00:00:00 2001 From: zeromus Date: Sun, 27 May 2012 07:42:13 +0000 Subject: [PATCH] nes-fix bug in base board class wram functionality (forgot to add masking to wram size configured in the Cart struct by the derived board Configure method) --- .../Consoles/Nintendo/NES/BoardSystem.cs | 13 ++++++++++++- BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs index da8f136b58..1ce50b7f86 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs @@ -14,8 +14,12 @@ namespace BizHawk.Emulation.Consoles.Nintendo { public interface INESBoard : IDisposable { + //base class pre-configuration void Create(NES nes); + //one-time inherited classes configuration bool Configure(NES.EDetectionOrigin origin); + //one-time base class configuration (which can take advantage of any information setup by the more-informed Configure() method) + void PostConfigure(); //gets called once per PPU clock, for boards with complex behaviour which must be monitoring clock (i.e. mmc3 irq counter) void ClockPPU(); @@ -132,9 +136,16 @@ namespace BizHawk.Emulation.Consoles.Nintendo if(wram != null) wram[addr] = value; } + + private int wram_mask; + public virtual void PostConfigure() + { + wram_mask = (Cart.wram_size * 1024) - 1; + } + public virtual byte ReadWRAM(int addr) { if (wram != null) - return wram[addr]; + return wram[addr & wram_mask]; else return 0xFF; } diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs index 9e9d473fa4..3bf5ecee63 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs @@ -530,6 +530,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo cart = choice; board.Create(this); board.Configure(origin); + board.PostConfigure(); if (origin == EDetectionOrigin.BootGodDB) {