Skip to content

Commit

Permalink
fix on_bus_read issue for genplus-gx core
Browse files Browse the repository at this point in the history
- related to issue TASEmulators#3813
- update signatures, create new value variable in each of the memory read core functions, pass it to the callback and return it instead of the inline calculations. Also, pass val to write and exec callbacks in IDebuggable since they all use the same mem_cb signature and it would break otherwise. I want to update write and exec callbacks in next commit though to ensure nothing unexpected happens.
  • Loading branch information
VelpaChallenger committed Nov 5, 2023
1 parent d842b5d commit 819cbb8
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 21 deletions.
Binary file modified Assets/dll/gpgx.wbx.zst
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,23 @@ 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");
}
});
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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion waterbox/gpgx/cinterface/callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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_readcb)(unsigned addr, unsigned int value);
extern ECL_ENTRY void (*biz_writecb)(unsigned addr);
extern CDCallback biz_cdcallback;
extern unsigned biz_lastpc;
Expand Down
2 changes: 1 addition & 1 deletion waterbox/gpgx/cinterface/cinterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static uint8_t brm_format[0x40] =
};

ECL_ENTRY void (*biz_execcb)(unsigned addr);
ECL_ENTRY void (*biz_readcb)(unsigned addr);
ECL_ENTRY void (*biz_readcb)(unsigned addr, unsigned int value);
ECL_ENTRY void (*biz_writecb)(unsigned addr);
CDCallback biz_cdcallback = NULL;
unsigned biz_lastpc = 0;
Expand Down
38 changes: 24 additions & 14 deletions waterbox/gpgx/core/m68k/m68kcpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -920,8 +924,14 @@ 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)
Expand Down

0 comments on commit 819cbb8

Please sign in to comment.