diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.cs b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.cs index b20a975033..f32b48acd4 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.cs @@ -23,6 +23,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx bool disposed = false; LibGPGX.load_archive_cb LoadCallback = null; + LibGPGX.input_cb InputCallback = null; LibGPGX.InputData input = new LibGPGX.InputData(); @@ -111,6 +112,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx update_video(); SetMemoryDomains(); + + InputCallback = new LibGPGX.input_cb(input_callback); + LibGPGX.gpgx_set_input_callback(InputCallback); } catch { @@ -285,6 +289,13 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx ControllerDefinition = ControlConverter.ControllerDef; } + // core callback for input + void input_callback() + { + CoreComm.InputCallback.Call(); + IsLagFrame = false; + } + #endregion // TODO: use render and rendersound @@ -310,7 +321,6 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx update_video(); update_audio(); - IsLagFrame = false; // TODO if (IsLagFrame) LagCount++; } @@ -485,6 +495,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx #endregion + #region debugging tools + public MemoryDomainList MemoryDomains { get; private set; } unsafe void SetMemoryDomains() @@ -524,6 +536,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx return new List>(); } + #endregion + public void Dispose() { if (!disposed) diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/LibGPGX.cs b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/LibGPGX.cs index b733498523..699c8392a2 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/LibGPGX.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/LibGPGX.cs @@ -122,6 +122,12 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx DEVICE_ACTIVATOR = 0x0a,// Activator }; + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void input_cb(); + + [DllImport("libgenplusgx.dll", CallingConvention = CallingConvention.Cdecl)] + public static extern void gpgx_set_input_callback(input_cb cb); + /// /// not every flag is valid for every device! /// diff --git a/genplus-gx/cinterface/cinterface.c b/genplus-gx/cinterface/cinterface.c index b75353be28..654376ce15 100644 --- a/genplus-gx/cinterface/cinterface.c +++ b/genplus-gx/cinterface/cinterface.c @@ -136,6 +136,19 @@ void osd_input_update(void) { } +void (*input_callback_cb)(void); + +void real_input_callback(void) +{ + if (input_callback_cb) + input_callback_cb(); +} + +GPGX_EX void gpgx_set_input_callback(void (*fecb)(void)) +{ + input_callback_cb = fecb; +} + int (*load_archive_cb)(const char *filename, unsigned char *buffer, int maxsize); // return 0 on failure, else actual loaded size diff --git a/genplus-gx/core/io_ctrl.c b/genplus-gx/core/io_ctrl.c index f221bf5835..a0baa1a3c9 100644 --- a/genplus-gx/core/io_ctrl.c +++ b/genplus-gx/core/io_ctrl.c @@ -377,8 +377,10 @@ unsigned int io_68k_read(unsigned int offset) case 0x02: /* Port B Data */ case 0x03: /* Port C Data */ { - unsigned int mask = 0x80 | io_reg[offset + 3]; - unsigned int data = port[offset-1].data_r(); + unsigned int mask, data; + real_input_callback(); + mask = 0x80 | io_reg[offset + 3]; + data = port[offset-1].data_r(); return (io_reg[offset] & mask) | (data & ~mask); } @@ -452,11 +454,13 @@ void io_z80_write(unsigned int offset, unsigned int data, unsigned int cycles) unsigned int io_z80_read(unsigned int offset) { + unsigned int data, ctrl; + real_input_callback(); /* Read port A & port B input data */ - unsigned int data = (port[0].data_r()) | (port[1].data_r() << 8); + data = (port[0].data_r()) | (port[1].data_r() << 8); /* I/O control register value */ - unsigned int ctrl = io_reg[0x0F]; + ctrl = io_reg[0x0F]; /* I/O ports */ if (offset) diff --git a/genplus-gx/libretro/osd.h b/genplus-gx/libretro/osd.h index e84d0f404f..4642b9b5e6 100644 --- a/genplus-gx/libretro/osd.h +++ b/genplus-gx/libretro/osd.h @@ -80,5 +80,6 @@ extern char MS_BIOS_JP[256]; void osd_input_update(void); int load_archive(const char *filename, unsigned char *buffer, int maxsize, char *extension); +void real_input_callback(void); #endif /* _OSD_H */ diff --git a/output/dll/libgenplusgx.dll b/output/dll/libgenplusgx.dll index 83e230cd3e..57b88b2ac2 100644 Binary files a/output/dll/libgenplusgx.dll and b/output/dll/libgenplusgx.dll differ