ganasis: support memory callbacks (exec, read, write). writes and reads don't fire on a certain class of PC relative load\store which includes immediates but possibly other stuff and i didn't unravel it all...

This commit is contained in:
goyuken 2014-06-21 17:20:18 +00:00
parent 10c48bb3f8
commit e520b11552
9 changed files with 79 additions and 0 deletions

View File

@ -147,6 +147,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
if (CD != null)
CoreComm.UsesDriveLed = true;
InitMemCallbacks();
KillMemCallbacks();
}
catch
{
@ -366,6 +369,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
IsLagFrame = true;
Frame++;
drivelight = false;
RefreshMemCallbacks();
LibGPGX.gpgx_advance();
update_video();
update_audio();
@ -598,6 +604,30 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
LibGPGX.gpgx_get_vdp_view(view);
}
LibGPGX.mem_cb ExecCallback;
LibGPGX.mem_cb ReadCallback;
LibGPGX.mem_cb WriteCallback;
void InitMemCallbacks()
{
ExecCallback = new LibGPGX.mem_cb(a => CoreComm.MemoryCallbackSystem.CallExecute(a));
ReadCallback = new LibGPGX.mem_cb(a => CoreComm.MemoryCallbackSystem.CallRead(a));
WriteCallback = new LibGPGX.mem_cb(a => CoreComm.MemoryCallbackSystem.CallWrite(a));
}
void RefreshMemCallbacks()
{
LibGPGX.gpgx_set_mem_callback(
CoreComm.MemoryCallbackSystem.HasReads ? ReadCallback : null,
CoreComm.MemoryCallbackSystem.HasWrites ? WriteCallback : null,
CoreComm.MemoryCallbackSystem.HasExecutes ? ExecCallback : null);
}
void KillMemCallbacks()
{
LibGPGX.gpgx_set_mem_callback(null, null, null);
}
#endregion
public void Dispose()
@ -608,6 +638,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
throw new Exception();
if (SaveRamModified)
DisposedSaveRam = ReadSaveRam();
KillMemCallbacks();
AttachedCore = null;
disposed = true;
}

View File

@ -115,6 +115,12 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
[DllImport("libgenplusgx.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void gpgx_set_input_callback(input_cb cb);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void mem_cb(uint addr);
[DllImport("libgenplusgx.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void gpgx_set_mem_callback(mem_cb read, mem_cb write, mem_cb exec);
/// <summary>
/// not every flag is valid for every device!
/// </summary>

View File

@ -0,0 +1,8 @@
#ifndef CALLBACKS_H
#define CALLBACKS_H
extern void (*biz_execcb)(unsigned addr);
extern void (*biz_readcb)(unsigned addr);
extern void (*biz_writecb)(unsigned addr);
#endif

View File

@ -1,6 +1,7 @@
#include <stddef.h>
#include <stdarg.h>
#include <stdio.h>
#include "callbacks.h"
#ifdef _MSC_VER
#define snprintf _snprintf
@ -48,6 +49,10 @@ static uint8_t brm_format[0x40] =
extern void zap(void);
void (*biz_execcb)(unsigned addr) = NULL;
void (*biz_readcb)(unsigned addr) = NULL;
void (*biz_writecb)(unsigned addr) = NULL;
static void update_viewport(void)
{
vwidth = bitmap.viewport.w + (bitmap.viewport.x * 2);
@ -519,6 +524,13 @@ GPGX_EX void gpgx_reset(int hard)
gen_reset(0);
}
GPGX_EX void gpgx_set_mem_callback(void (*read)(unsigned), void (*write)(unsigned), void (*exec)(unsigned))
{
biz_readcb = read;
biz_writecb = write;
biz_execcb = exec;
}
typedef struct
{
unsigned int value;

View File

@ -1,3 +1,5 @@
#include "../cinterface/callbacks.h"
/* ======================================================================== */
/* MAIN 68K CORE */
/* ======================================================================== */
@ -289,6 +291,9 @@ void m68k_run(unsigned int cycles)
/* Set the address space for reads */
m68ki_use_data_space() /* auto-disable (see m68kcpu.h) */
if (biz_execcb)
biz_execcb(REG_PC);
/* Decode next instruction */
REG_IR = m68ki_read_imm_16();

View File

@ -14,6 +14,7 @@
#endif /* M68K_EMULATE_ADDRESS_ERROR */
#include "m68k.h"
#include "../cinterface/callbacks.h"
/* ======================================================================== */
@ -867,6 +868,8 @@ 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);
m68ki_set_fc(fc) /* auto-disable (see m68kcpu.h) */
@ -877,6 +880,8 @@ INLINE uint m68ki_read_8_fc(uint address, uint fc)
INLINE uint m68ki_read_16_fc(uint address, uint fc)
{
cpu_memory_map *temp;
if (biz_readcb)
biz_readcb(address);
m68ki_set_fc(fc) /* auto-disable (see m68kcpu.h) */
m68ki_check_address_error(address, MODE_READ, fc) /* auto-disable (see m68kcpu.h) */
@ -889,6 +894,8 @@ INLINE uint m68ki_read_16_fc(uint address, uint fc)
INLINE uint m68ki_read_32_fc(uint address, uint fc)
{
cpu_memory_map *temp;
if (biz_readcb)
biz_readcb(address);
m68ki_set_fc(fc) /* auto-disable (see m68kcpu.h) */
m68ki_check_address_error(address, MODE_READ, fc) /* auto-disable (see m68kcpu.h) */
@ -901,6 +908,8 @@ INLINE uint m68ki_read_32_fc(uint address, uint fc)
INLINE void m68ki_write_8_fc(uint address, uint fc, uint value)
{
cpu_memory_map *temp;
if (biz_writecb)
biz_writecb(address);
m68ki_set_fc(fc) /* auto-disable (see m68kcpu.h) */
@ -912,6 +921,8 @@ INLINE void m68ki_write_8_fc(uint address, uint fc, uint value)
INLINE void m68ki_write_16_fc(uint address, uint fc, uint value)
{
cpu_memory_map *temp;
if (biz_writecb)
biz_writecb(address);
m68ki_set_fc(fc) /* auto-disable (see m68kcpu.h) */
m68ki_check_address_error(address, MODE_WRITE, fc); /* auto-disable (see m68kcpu.h) */
@ -924,6 +935,8 @@ INLINE void m68ki_write_16_fc(uint address, uint fc, uint value)
INLINE void m68ki_write_32_fc(uint address, uint fc, uint value)
{
cpu_memory_map *temp;
if (biz_writecb)
biz_writecb(address);
m68ki_set_fc(fc) /* auto-disable (see m68kcpu.h) */
m68ki_check_address_error(address, MODE_WRITE, fc) /* auto-disable (see m68kcpu.h) */

View File

@ -63,6 +63,7 @@
<ClCompile Include="..\..\scrc32.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\cinterface\callbacks.h" />
<ClInclude Include="..\..\..\core\cart_hw\areplay.h" />
<ClInclude Include="..\..\..\core\cart_hw\eeprom_93c.h" />
<ClInclude Include="..\..\..\core\cart_hw\eeprom_i2c.h" />

View File

@ -392,5 +392,8 @@
<ClInclude Include="..\..\..\core\cart_hw\svp\svp.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\cinterface\callbacks.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

Binary file not shown.