Skip to content

Commit

Permalink
fix on_bus_read issue for BSNES core
Browse files Browse the repository at this point in the history
- related to issue TASEmulators#3813
- update signatures, send returned value from bus read as data to read callback
  • Loading branch information
VelpaChallenger authored and lucianoj77052012 committed Nov 5, 2023
1 parent eeb824d commit 220004d
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 11 deletions.
Binary file modified Assets/dll/bsnes.wbx.zst
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down
2 changes: 1 addition & 1 deletion waterbox/bsnescore/bsnes/emulator/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct Platform {
bool writeHookEnabled = false;
bool executeHookEnabled = false;
virtual auto cpuTrace(vector<string>) -> 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); }
Expand Down
5 changes: 2 additions & 3 deletions waterbox/bsnescore/bsnes/sfc/cpu/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion waterbox/bsnescore/bsnes/target-bsnescore/callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions waterbox/bsnescore/bsnes/target-bsnescore/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct Program : Emulator::Platform
auto notify(string text) -> void override;
auto getBackdropColor() -> uint16 override;
auto cpuTrace(vector<string>) -> 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;
Expand Down Expand Up @@ -482,9 +482,9 @@ auto Program::cpuTrace(vector<string> 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
Expand Down

0 comments on commit 220004d

Please sign in to comment.