From af38023ba8aec87787fcd3f6c298fa0cff60e3f2 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Mon, 23 Nov 2020 17:06:49 -0500 Subject: [PATCH] GBHawk: open bus behaviour on locked SRAM --- src/BizHawk.Emulation.Cores/CPUs/LR35902/Execute.cs | 3 +++ src/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs | 1 + src/BizHawk.Emulation.Cores/CPUs/LR35902/Operations.cs | 7 ++++--- .../Consoles/Nintendo/GBHawk/GBHawk.cs | 1 + .../Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1.cs | 4 ++-- .../Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1_Multi.cs | 4 ++-- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/CPUs/LR35902/Execute.cs b/src/BizHawk.Emulation.Cores/CPUs/LR35902/Execute.cs index a1d1e3a744..1289898bd8 100644 --- a/src/BizHawk.Emulation.Cores/CPUs/LR35902/Execute.cs +++ b/src/BizHawk.Emulation.Cores/CPUs/LR35902/Execute.cs @@ -7,6 +7,9 @@ namespace BizHawk.Emulation.Cores.Components.LR35902 private int EI_pending; public bool interrupts_enabled; + // we need the last value on the bus for proper emulation of blocked SRAM + public byte bus_value; + // variables for executing instructions public int instr_pntr = 0; public ushort[] cur_instr = new ushort [60]; diff --git a/src/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs b/src/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs index be5f6eb4c1..3793e4ce21 100644 --- a/src/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs +++ b/src/BizHawk.Emulation.Cores/CPUs/LR35902/LR35902.cs @@ -815,6 +815,7 @@ namespace BizHawk.Emulation.Cores.Components.LR35902 ser.Sync(nameof(LY), ref LY); ser.Sync(nameof(FlagI), ref FlagI); ser.Sync(nameof(was_FlagI), ref was_FlagI); + ser.Sync(nameof(bus_value), ref bus_value); ser.EndSection(); } diff --git a/src/BizHawk.Emulation.Cores/CPUs/LR35902/Operations.cs b/src/BizHawk.Emulation.Cores/CPUs/LR35902/Operations.cs index 22bc73dfd6..1510b7780a 100644 --- a/src/BizHawk.Emulation.Cores/CPUs/LR35902/Operations.cs +++ b/src/BizHawk.Emulation.Cores/CPUs/LR35902/Operations.cs @@ -18,20 +18,21 @@ namespace BizHawk.Emulation.Cores.Components.LR35902 if (src_l == PCl) CDLCallback(addr, eCDLogMemFlags.FetchOperand); else CDLCallback(addr, eCDLogMemFlags.Data); } - Regs[dest] = ReadMemory(addr); + Regs[dest] = bus_value = ReadMemory(addr); } // special read for POP AF that always clears the lower 4 bits of F public void Read_Func_F(ushort dest, ushort src_l, ushort src_h) { - Regs[dest] = (ushort)(ReadMemory((ushort)(Regs[src_l] | (Regs[src_h]) << 8)) & 0xF0); + Regs[dest] = bus_value = (byte)(ReadMemory((ushort)(Regs[src_l] | (Regs[src_h]) << 8)) & 0xF0); } public void Write_Func(ushort dest_l, ushort dest_h, ushort src) { ushort addr = (ushort)(Regs[dest_l] | (Regs[dest_h]) << 8); CDLCallback?.Invoke(addr, eCDLogMemFlags.Write | eCDLogMemFlags.Data); - WriteMemory(addr, (byte)Regs[src]); + bus_value = (byte)Regs[src]; + WriteMemory(addr, bus_value); } public void TR_Func(ushort dest, ushort src) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs index 6b589baf03..ab30e20709 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.cs @@ -11,6 +11,7 @@ using System.Runtime.InteropServices; // TODO: oam_dma_start.gb does not behave as expected but test still passes through lucky coincidences / test deficiency // TODO: LYC interrupt behaves differently in GBC and GB compat mode // TODO: Window Position A6 behaves differently +// TODO: Verify open bus behaviour for bad SRAM accesses for other MBCs namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1.cs index 9b226e80c4..56e9206ae7 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1.cs @@ -59,12 +59,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } else { - return 0xFF; + return Core.cpu.bus_value; } } else { - return 0xFF; + return Core.cpu.bus_value; } } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1_Multi.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1_Multi.cs index e306c13689..dc72835e8d 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1_Multi.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Mappers/Mapper_MBC1_Multi.cs @@ -58,13 +58,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk } else { - return 0xFF; + return Core.cpu.bus_value; } } else { - return 0xFF; + return Core.cpu.bus_value; } }