gpgx minor code cleanup

This commit is contained in:
goyuken 2014-02-02 02:05:36 +00:00
parent cae7e7fc98
commit 7a22757ca8
3 changed files with 13 additions and 31 deletions

View File

@ -284,6 +284,11 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
#region controller
/// <summary>
/// size of native input struct
/// </summary>
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;

View File

@ -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);
});
}

View File

@ -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