From 3bf90c5e42f9813041a4ac66314e89695777b246 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Sat, 29 Oct 2016 18:54:34 -0400 Subject: [PATCH] Update VRC-1 to run VS system game mirroring modes --- .../Consoles/Nintendo/NES/Boards/VRC1.cs | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/VRC1.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/VRC1.cs index b33dc810a5..b093226c55 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/VRC1.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/VRC1.cs @@ -1,5 +1,6 @@ using BizHawk.Common; using BizHawk.Common.NumberExtensions; +using System; namespace BizHawk.Emulation.Cores.Nintendo.NES { @@ -15,6 +16,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES IntBuffer chr_banks_4k = new IntBuffer(2); int[] chr_regs_4k = new int[2]; + //the VS actually does have 2 KB of nametable address space + //let's make the extra space here, instead of in the main NES to avoid confusion + byte[] CIRAM_VS = new byte[0x800]; + public override void Dispose() { base.Dispose(); @@ -27,6 +32,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES base.SyncState(ser); ser.Sync("prg_banks_8k", ref prg_banks_8k); ser.Sync("chr_banks_4k", ref chr_banks_4k); + ser.Sync("VS_CIRAM", ref CIRAM_VS, false); for (int i = 0; i < 2; i++) ser.Sync("chr_regs_4k_" + i, ref chr_regs_4k[i]); if (ser.IsReader) @@ -82,7 +88,54 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES addr = (bank_4k << 12) | ofs; return VROM[addr]; } - else return base.ReadPPU(addr); + else + { + if (NES._isVS) + { + addr = addr - 0x2000; + if (addr < 0x800) + { + return NES.CIRAM[addr]; + } + else + { + return CIRAM_VS[addr - 0x800]; + } + } + else + return base.ReadPPU(addr); + } + + } + + public override void WritePPU(int addr, byte value) + { + // The game VS Goonies apparently scans for more CIRAM then actually exists, so we have to mask out nonsensical values + addr &= 0x2FFF; + + if (NES._isVS) + { + if (addr < 0x2000) + { + if (VRAM != null) + VRAM[addr] = value; + } + else + { + Console.WriteLine(addr); + addr = addr - 0x2000; + if (addr < 0x800) + { + NES.CIRAM[addr] = value; + } + else + { + CIRAM_VS[addr - 0x800] = value; + } + } + } + else + base.WritePPU(addr, value); } void SyncCHR()