diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.cs b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.cs index 89f00f6bfe..a99e9c5659 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.cs @@ -284,6 +284,11 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx #region controller + /// + /// size of native input struct + /// + int inputsize; + GPGXControlConverter ControlConverter; public ControllerDefinition ControllerDefinition { get; private set; } @@ -291,7 +296,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx void SetControllerDefinition() { - if (!LibGPGX.gpgx_get_control(input)) + inputsize = Marshal.SizeOf(typeof(LibGPGX.InputData)); + if (!LibGPGX.gpgx_get_control(input, inputsize)) throw new Exception("gpgx_get_control() failed"); ControlConverter = new GPGXControlConverter(input); @@ -316,12 +322,12 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx LibGPGX.gpgx_reset(true); // do we really have to get each time? nothing has changed - if (!LibGPGX.gpgx_get_control(input)) + if (!LibGPGX.gpgx_get_control(input, inputsize)) throw new Exception("gpgx_get_control() failed!"); ControlConverter.Convert(Controller, input); - if (!LibGPGX.gpgx_put_control(input)) + if (!LibGPGX.gpgx_put_control(input, inputsize)) throw new Exception("gpgx_put_control() failed!"); IsLagFrame = true; diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGXControlConverter.cs b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGXControlConverter.cs index d140b329f2..b51efc5716 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGXControlConverter.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGXControlConverter.cs @@ -92,8 +92,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx ControllerDef.FloatRanges.Add(FullShort); Converts.Add(delegate() { - target.analog[(2*idx)+0] = (short)source.GetFloat(NX); - target.analog[(2*idx)+1] = (short)source.GetFloat(NY); + target.analog[(2 * idx) + 0] = (short)source.GetFloat(NX); + target.analog[(2 * idx) + 1] = (short)source.GetFloat(NY); }); } diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/LibGPGX.cs b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/LibGPGX.cs index c31ea0771b..f767122380 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/LibGPGX.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/LibGPGX.cs @@ -43,9 +43,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx public static extern bool gpgx_state_load(byte[] src, int size); [DllImport("libgenplusgx.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern bool gpgx_get_control(IntPtr dest, int bytes); + public static extern bool gpgx_get_control(InputData dest, int bytes); [DllImport("libgenplusgx.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern bool gpgx_put_control(IntPtr src, int bytes); + public static extern bool gpgx_put_control(InputData src, int bytes); [DllImport("libgenplusgx.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void gpgx_get_sram(ref IntPtr area, ref int size); @@ -72,30 +72,6 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx [DllImport("libgenplusgx.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void gpgx_reset(bool hard); - public static bool gpgx_get_control(InputData dest) - { - int bytes = Marshal.SizeOf(typeof(InputData)); - IntPtr p = Marshal.AllocHGlobal(bytes); - - bool succeed = gpgx_get_control(p, bytes); - if (succeed) - Marshal.PtrToStructure(p, dest); - Marshal.FreeHGlobal(p); - return succeed; - } - - public static bool gpgx_put_control(InputData src) - { - int bytes = Marshal.SizeOf(typeof(InputData)); - IntPtr p = Marshal.AllocHGlobal(bytes); - - Marshal.StructureToPtr(src, p, false); - - bool succeed = gpgx_put_control(p, bytes); - Marshal.FreeHGlobal(p); - return succeed; - } - public const int MAX_DEVICES = 8; public enum INPUT_SYSTEM : byte