diff --git a/Assets/dll/bsnes.wbx.zst b/Assets/dll/bsnes.wbx.zst index bd846747348..c90967077c7 100644 Binary files a/Assets/dll/bsnes.wbx.zst and b/Assets/dll/bsnes.wbx.zst differ diff --git a/Assets/dll/gpgx.wbx.zst b/Assets/dll/gpgx.wbx.zst index c30aa68375a..e7087375a97 100644 Binary files a/Assets/dll/gpgx.wbx.zst and b/Assets/dll/gpgx.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 8c75ef3fe05..0de1e204896 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesApi.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesApi.cs @@ -196,7 +196,7 @@ public void Dispose() 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_read_hook_t(uint address, byte value); public delegate void snes_write_hook_t(uint address, byte value); public delegate void snes_exec_hook_t(uint address); public delegate long snes_time_t(); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs index ecdc2af37f5..52b70f0ad30 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs @@ -323,11 +323,11 @@ private void InitAudio() 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, byte value) { if (MemoryCallbacks.HasReads) { - MemoryCallbacks.CallMemoryCallbacks(addr, 0, (uint) MemoryCallbackFlags.AccessRead, "System Bus"); + MemoryCallbacks.CallMemoryCallbacks(addr, value, (uint) MemoryCallbackFlags.AccessRead, "System Bus"); } } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IDebuggable.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IDebuggable.cs index 6647386c465..a88bb2ce26d 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IDebuggable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IDebuggable.cs @@ -59,28 +59,28 @@ public void SetCpuRegister(string register, int value) private void InitMemCallbacks() { - ExecCallback = new LibGPGX.mem_cb(a => + ExecCallback = new LibGPGX.mem_cb((a, val) => { if (MemoryCallbacks.HasExecutes) { uint flags = (uint)MemoryCallbackFlags.AccessExecute; - MemoryCallbacks.CallMemoryCallbacks(a, 0, flags, "M68K BUS"); + MemoryCallbacks.CallMemoryCallbacks(a, val, flags, "M68K BUS"); } }); - ReadCallback = new LibGPGX.mem_cb(a => + ReadCallback = new LibGPGX.mem_cb((a, val) => { if (MemoryCallbacks.HasReads) { uint flags = (uint)MemoryCallbackFlags.AccessRead; - MemoryCallbacks.CallMemoryCallbacks(a, 0, flags, "M68K BUS"); + MemoryCallbacks.CallMemoryCallbacks(a, val, flags, "M68K BUS"); } }); - WriteCallback = new LibGPGX.mem_cb(a => + WriteCallback = new LibGPGX.mem_cb((a, val) => { if (MemoryCallbacks.HasWrites) { uint flags = (uint)MemoryCallbackFlags.AccessWrite; - MemoryCallbacks.CallMemoryCallbacks(a, 0, flags, "M68K BUS"); + MemoryCallbacks.CallMemoryCallbacks(a, val, flags, "M68K BUS"); } }); _memoryCallbacks.ActiveChanged += RefreshMemCallbacks; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/LibGPGX.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/LibGPGX.cs index d2aeddbc601..bdcd862ea14 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/LibGPGX.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/LibGPGX.cs @@ -148,7 +148,7 @@ public enum CDLog_Flags public abstract void gpgx_set_input_callback(input_cb cb); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void mem_cb(uint addr); + public delegate void mem_cb(uint addr, uint value); //value MUST be uint, since the value will be trimmed if the type is byte (8-bit) or ushort (16-bit) and the value read/written/executed is bigger than that (i.e 32 bits). [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void CDCallback(int addr, CDLog_AddrType addrtype, CDLog_Flags flags); diff --git a/waterbox/bsnescore/bsnes/emulator/platform.hpp b/waterbox/bsnescore/bsnes/emulator/platform.hpp index 2c4074e5e4f..e6ca64d5876 100644 --- a/waterbox/bsnescore/bsnes/emulator/platform.hpp +++ b/waterbox/bsnescore/bsnes/emulator/platform.hpp @@ -30,7 +30,7 @@ struct Platform { bool writeHookEnabled = false; bool executeHookEnabled = false; virtual auto cpuTrace(vector) -> void {} - virtual auto readHook(uint address) -> 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 ecc3d0f6908..0bbc3de50f4 100644 --- a/waterbox/bsnescore/bsnes/sfc/cpu/memory.cpp +++ b/waterbox/bsnescore/bsnes/sfc/cpu/memory.cpp @@ -7,9 +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) { status.clockCount = 6; @@ -41,6 +38,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 d2490b80057..fc66ff5ca78 100644 --- a/waterbox/bsnescore/bsnes/target-bsnescore/callbacks.h +++ b/waterbox/bsnescore/bsnes/target-bsnescore/callbacks.h @@ -9,7 +9,7 @@ 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_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); diff --git a/waterbox/bsnescore/bsnes/target-bsnescore/program.cpp b/waterbox/bsnescore/bsnes/target-bsnescore/program.cpp index 853f62a92d4..1c32fe8dcf2 100644 --- a/waterbox/bsnescore/bsnes/target-bsnescore/program.cpp +++ b/waterbox/bsnescore/bsnes/target-bsnescore/program.cpp @@ -26,7 +26,7 @@ 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 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,9 +482,9 @@ 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 diff --git a/waterbox/gpgx/cinterface/callbacks.h b/waterbox/gpgx/cinterface/callbacks.h index b2b37edd34e..c5ab692a29c 100644 --- a/waterbox/gpgx/cinterface/callbacks.h +++ b/waterbox/gpgx/cinterface/callbacks.h @@ -7,9 +7,9 @@ typedef ECL_ENTRY void (*CDCallback)(int32 addr, int32 addrtype, int32 flags); -extern ECL_ENTRY void (*biz_execcb)(unsigned addr); -extern ECL_ENTRY void (*biz_readcb)(unsigned addr); -extern ECL_ENTRY void (*biz_writecb)(unsigned addr); +extern ECL_ENTRY void (*biz_execcb)(unsigned addr, unsigned int value); +extern ECL_ENTRY void (*biz_readcb)(unsigned addr, unsigned int value); +extern ECL_ENTRY void (*biz_writecb)(unsigned addr, unsigned int value); extern CDCallback biz_cdcallback; extern unsigned biz_lastpc; diff --git a/waterbox/gpgx/cinterface/cinterface.c b/waterbox/gpgx/cinterface/cinterface.c index 1fdd924c7a4..bb3065f42a0 100644 --- a/waterbox/gpgx/cinterface/cinterface.c +++ b/waterbox/gpgx/cinterface/cinterface.c @@ -55,9 +55,9 @@ static uint8_t brm_format[0x40] = 0x52,0x41,0x4d,0x5f,0x43,0x41,0x52,0x54,0x52,0x49,0x44,0x47,0x45,0x5f,0x5f,0x5f }; -ECL_ENTRY void (*biz_execcb)(unsigned addr); -ECL_ENTRY void (*biz_readcb)(unsigned addr); -ECL_ENTRY void (*biz_writecb)(unsigned addr); +ECL_ENTRY void (*biz_execcb)(unsigned addr, unsigned int value); +ECL_ENTRY void (*biz_readcb)(unsigned addr, unsigned int value); +ECL_ENTRY void (*biz_writecb)(unsigned addr, unsigned int value); CDCallback biz_cdcallback = NULL; unsigned biz_lastpc = 0; ECL_ENTRY void (*cdd_readcallback)(int lba, void *dest, int audio); diff --git a/waterbox/gpgx/core/m68k/m68kcpu.c b/waterbox/gpgx/core/m68k/m68kcpu.c index d3a6ae23a08..a408274ab9f 100644 --- a/waterbox/gpgx/core/m68k/m68kcpu.c +++ b/waterbox/gpgx/core/m68k/m68kcpu.c @@ -340,7 +340,7 @@ void m68k_run(unsigned int cycles) m68ki_use_data_space() /* auto-disable (see m68kcpu.h) */ if (biz_execcb) - biz_execcb(REG_PC); + biz_execcb(REG_PC, 0); //All read/write/exec callbacks require address and value, but for exec the functionality is not fully implemented, so I am passing 0 as value. if(biz_cdcallback) { diff --git a/waterbox/gpgx/core/m68k/m68kcpu.h b/waterbox/gpgx/core/m68k/m68kcpu.h index eaf747e9b22..e5abf48dcba 100644 --- a/waterbox/gpgx/core/m68k/m68kcpu.h +++ b/waterbox/gpgx/core/m68k/m68kcpu.h @@ -870,24 +870,25 @@ INLINE uint m68ki_read_imm_32(void) INLINE uint m68ki_read_8_fc(uint address, uint fc) { cpu_memory_map *temp = &m68ki_cpu.memory_map[((address)>>16)&0xff];; - if (biz_readcb) - biz_readcb(address); if(biz_cdcallback) CDLog68k(address,eCDLog_Flags_Data68k); m68ki_set_fc(fc) /* auto-disable (see m68kcpu.h) */ - if (temp->read8) return (*temp->read8)(ADDRESS_68K(address)); - else return READ_BYTE(temp->base, (address) & 0xffff); + uint value; + if (temp->read8) + value = (*temp->read8)(ADDRESS_68K(address)); + else + value = READ_BYTE(temp->base, (address) & 0xffff); + if (biz_readcb) + biz_readcb(address, value); + return value; } INLINE uint m68ki_read_16_fc(uint address, uint fc) { cpu_memory_map *temp; - if (biz_readcb) - biz_readcb(address); - if(biz_cdcallback) { CDLog68k(address,eCDLog_Flags_Data68k); @@ -898,16 +899,19 @@ INLINE uint m68ki_read_16_fc(uint address, uint fc) m68ki_check_address_error(address, MODE_READ, fc) /* auto-disable (see m68kcpu.h) */ temp = &m68ki_cpu.memory_map[((address)>>16)&0xff]; - if (temp->read16) return (*temp->read16)(ADDRESS_68K(address)); - else return *(uint16 *)(temp->base + ((address) & 0xffff)); + uint value; + if (temp->read16) + value = (*temp->read16)(ADDRESS_68K(address)); + else + value = *(uint16 *)(temp->base + ((address) & 0xffff)); + if (biz_readcb) + biz_readcb(address, value); + return value; } INLINE uint m68ki_read_32_fc(uint address, uint fc) { cpu_memory_map *temp; - if (biz_readcb) - biz_readcb(address); - if(biz_cdcallback) { CDLog68k(address,eCDLog_Flags_Data68k); @@ -920,15 +924,21 @@ INLINE uint m68ki_read_32_fc(uint address, uint fc) m68ki_check_address_error(address, MODE_READ, fc) /* auto-disable (see m68kcpu.h) */ temp = &m68ki_cpu.memory_map[((address)>>16)&0xff]; - if (temp->read16) return ((*temp->read16)(ADDRESS_68K(address)) << 16) | ((*temp->read16)(ADDRESS_68K(address + 2))); - else return m68k_read_immediate_32(address); + uint value; + if (temp->read16) + value = ((*temp->read16)(ADDRESS_68K(address)) << 16) | ((*temp->read16)(ADDRESS_68K(address + 2))); + else + value = m68k_read_immediate_32(address); + if (biz_readcb) + biz_readcb(address, value); + return value; } INLINE void m68ki_write_8_fc(uint address, uint fc, uint value) { cpu_memory_map *temp; if (biz_writecb) - biz_writecb(address); + biz_writecb(address, value); m68ki_set_fc(fc) /* auto-disable (see m68kcpu.h) */ @@ -941,7 +951,7 @@ INLINE void m68ki_write_16_fc(uint address, uint fc, uint value) { cpu_memory_map *temp; if (biz_writecb) - biz_writecb(address); + biz_writecb(address, value); m68ki_set_fc(fc) /* auto-disable (see m68kcpu.h) */ m68ki_check_address_error(address, MODE_WRITE, fc); /* auto-disable (see m68kcpu.h) */ @@ -955,7 +965,7 @@ INLINE void m68ki_write_32_fc(uint address, uint fc, uint value) { cpu_memory_map *temp; if (biz_writecb) - biz_writecb(address); + biz_writecb(address, value); m68ki_set_fc(fc) /* auto-disable (see m68kcpu.h) */ m68ki_check_address_error(address, MODE_WRITE, fc) /* auto-disable (see m68kcpu.h) */