diff --git a/Assets/dll/bsnes.wbx.zst b/Assets/dll/bsnes.wbx.zst index a43f9bba32..58cb59c09a 100644 Binary files a/Assets/dll/bsnes.wbx.zst and b/Assets/dll/bsnes.wbx.zst differ diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesApi.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesApi.cs index a4e5a3fb5b..41f193ea2c 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesApi.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesApi.cs @@ -199,8 +199,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES public delegate void snes_no_lag_t(bool sgb_poll); public delegate string snes_path_request_t(int slot, string hint, bool required); public delegate void snes_trace_t(string disassembly, string register_info); - public delegate void snes_read_hook_t(uint address); - public delegate void snes_write_hook_t(uint address, byte value); + public delegate void snes_read_hook_t(uint address, ref byte value); + public delegate void snes_write_hook_t(uint address, ref byte value); public delegate void snes_exec_hook_t(uint address); public delegate long snes_time_t(); public delegate bool snes_msu_open_t(ushort track_id); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs index f21946ee1c..7f9e925656 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs @@ -323,19 +323,19 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES private void snes_trace(string disassembly, string registerInfo) => _tracer.Put(new(disassembly: disassembly, registerInfo: registerInfo)); - private void ReadHook(uint addr) + private void ReadHook(uint addr, ref byte value) { if (MemoryCallbacks.HasReads) { - MemoryCallbacks.CallMemoryCallbacks(addr, 0, (uint) MemoryCallbackFlags.AccessRead, "System Bus"); + value = (byte) MemoryCallbacks.CallMemoryCallbacks(addr, value, (uint) MemoryCallbackFlags.AccessRead, "System Bus"); } } - private void WriteHook(uint addr, byte value) + private void WriteHook(uint addr, ref byte value) { if (MemoryCallbacks.HasWrites) { - MemoryCallbacks.CallMemoryCallbacks(addr, value, (uint) MemoryCallbackFlags.AccessWrite, "System Bus"); + value = (byte) MemoryCallbacks.CallMemoryCallbacks(addr, value, (uint) MemoryCallbackFlags.AccessWrite, "System Bus"); } } diff --git a/waterbox/bsnescore/bsnes/emulator/platform.hpp b/waterbox/bsnescore/bsnes/emulator/platform.hpp index 2c4074e5e4..608d03424b 100644 --- a/waterbox/bsnescore/bsnes/emulator/platform.hpp +++ b/waterbox/bsnescore/bsnes/emulator/platform.hpp @@ -30,8 +30,8 @@ struct Platform { bool writeHookEnabled = false; bool executeHookEnabled = false; virtual auto cpuTrace(vector) -> void {} - virtual auto readHook(uint address) -> void {} - virtual auto writeHook(uint address, uint8 value) -> void {} + virtual auto readHook(uint address, uint8& value) -> void {} + virtual auto writeHook(uint address, uint8& value) -> void {} virtual auto execHook(uint address) -> void {} virtual auto time() -> int64 { return ::time(0); } }; diff --git a/waterbox/bsnescore/bsnes/sfc/cpu/memory.cpp b/waterbox/bsnescore/bsnes/sfc/cpu/memory.cpp index ecc3d0f690..806f7bd0b3 100644 --- a/waterbox/bsnescore/bsnes/sfc/cpu/memory.cpp +++ b/waterbox/bsnescore/bsnes/sfc/cpu/memory.cpp @@ -7,8 +7,6 @@ auto CPU::idle() -> void { } auto CPU::read(uint address) -> uint8 { - if (__builtin_expect(platform->readHookEnabled, 0)) - platform->readHook(address); if(address & 0x408000) { if(address & 0x800000 && io.fastROM) { @@ -41,6 +39,8 @@ auto CPU::read(uint address) -> uint8 { status.irqLock = 0; auto data = bus.read(address, r.mdr); + if (__builtin_expect(platform->readHookEnabled, 0)) + platform->readHook(address, data); step<4,0>(); aluEdge(); //$00-3f,80-bf:4000-43ff reads are internal to CPU, and do not update the MDR diff --git a/waterbox/bsnescore/bsnes/target-bsnescore/callbacks.h b/waterbox/bsnescore/bsnes/target-bsnescore/callbacks.h index d2490b8005..d54c79630c 100644 --- a/waterbox/bsnescore/bsnes/target-bsnescore/callbacks.h +++ b/waterbox/bsnescore/bsnes/target-bsnescore/callbacks.h @@ -9,8 +9,8 @@ typedef void (*snes_controller_latch_t)(void); typedef void (*snes_no_lag_t)(bool sgb_poll); typedef char* (*snes_path_request_t)(int slot, const char* hint, bool required); typedef void (*snes_trace_t)(const char* disassembly, const char* register_info); -typedef void (*snes_read_hook_t)(uint32_t address); -typedef void (*snes_write_hook_t)(uint32_t address, uint8_t value); +typedef void (*snes_read_hook_t)(uint32_t address, uint8_t& value); +typedef void (*snes_write_hook_t)(uint32_t address, uint8_t& value); typedef void (*snes_exec_hook_t)(uint32_t address); typedef int64_t (*snes_time_t)(void); typedef void (*snes_msu_open_t)(uint16_t track_id); diff --git a/waterbox/bsnescore/bsnes/target-bsnescore/program.cpp b/waterbox/bsnescore/bsnes/target-bsnescore/program.cpp index 853f62a92d..a73a753034 100644 --- a/waterbox/bsnescore/bsnes/target-bsnescore/program.cpp +++ b/waterbox/bsnescore/bsnes/target-bsnescore/program.cpp @@ -26,8 +26,8 @@ struct Program : Emulator::Platform auto notify(string text) -> void override; auto getBackdropColor() -> uint16 override; auto cpuTrace(vector) -> void override; - auto readHook(uint address) -> void override; - auto writeHook(uint address, uint8 value) -> void override; + auto readHook(uint address, uint8& value) -> void override; + auto writeHook(uint address, uint8& value) -> void override; auto execHook(uint address) -> void override; auto time() -> int64 override; @@ -482,12 +482,12 @@ auto Program::cpuTrace(vector parts) -> void snesCallbacks.snes_trace(parts[0], parts[1]); } -auto Program::readHook(uint address) -> void +auto Program::readHook(uint address, uint8& value) -> void { - snesCallbacks.snes_read_hook(address); + snesCallbacks.snes_read_hook(address, value); } -auto Program::writeHook(uint address, uint8 value) -> void +auto Program::writeHook(uint address, uint8& value) -> void { snesCallbacks.snes_write_hook(address, value); }