Simplified N64 controller input retrieval
This commit is contained in:
parent
3c7292f8ab
commit
15b95f6f40
|
@ -141,32 +141,32 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Translates controller inputs from EmuHawk and
|
/// Translates controller input from EmuHawk into
|
||||||
/// shoves them into mupen64plus
|
/// N64 controller data
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void setControllers()
|
/// <param name="i">Id of controller to update and shove</param>
|
||||||
|
public int GetControllerInput(int i)
|
||||||
{
|
{
|
||||||
CoreComm.InputCallback.Call();
|
CoreComm.InputCallback.Call();
|
||||||
IsLagFrame = false;
|
IsLagFrame = false;
|
||||||
|
|
||||||
// Analog stick right = +X
|
// Analog stick right = +X
|
||||||
// Analog stick up = +Y
|
// Analog stick up = +Y
|
||||||
|
string p = "P" + (i + 1);
|
||||||
|
sbyte x;
|
||||||
|
if (Controller.IsPressed(p + " A Left")) { x = -127; }
|
||||||
|
else if (Controller.IsPressed(p + " A Right")) { x = 127; }
|
||||||
|
else { x = (sbyte)Controller.GetFloat(p + " X Axis"); }
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++)
|
sbyte y;
|
||||||
{
|
if (Controller.IsPressed(p + " A Up")) { y = 127; }
|
||||||
string p = "P" + (i + 1);
|
else if (Controller.IsPressed(p + " A Down")) { y = -127; }
|
||||||
sbyte x;
|
else { y = (sbyte)Controller.GetFloat(p + " Y Axis"); }
|
||||||
if (Controller.IsPressed(p + " A Left")) { x = -127; }
|
|
||||||
else if (Controller.IsPressed(p + " A Right")) { x = 127; }
|
|
||||||
else { x = (sbyte)Controller.GetFloat(p + " X Axis"); }
|
|
||||||
|
|
||||||
sbyte y;
|
int value = ReadController(i + 1);
|
||||||
if (Controller.IsPressed(p + " A Up")) { y = 127; }
|
value |= (x & 0xFF) << 16;
|
||||||
else if (Controller.IsPressed(p + " A Down")) { y = -127; }
|
value |= (y & 0xFF) << 24;
|
||||||
else { y = (sbyte)Controller.GetFloat(p + " Y Axis"); }
|
return value;
|
||||||
|
|
||||||
api.set_buttons(i, ReadController(i+1), x, y);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -456,7 +456,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
|
||||||
}
|
}
|
||||||
|
|
||||||
api = new mupen64plusApi(this, rom, this.SyncSettings.GetVPS(game), SaveType);
|
api = new mupen64plusApi(this, rom, this.SyncSettings.GetVPS(game), SaveType);
|
||||||
api.SetM64PInputCallback(new mupen64plusApi.InputCallback(setControllers));
|
api.SetM64PInputCallback(new mupen64plusApi.InputCallback(GetControllerInput));
|
||||||
|
|
||||||
audioProvider = new N64Audio(api);
|
audioProvider = new N64Audio(api);
|
||||||
videoProvider = new N64VideoProvider(api);
|
videoProvider = new N64VideoProvider(api);
|
||||||
|
|
|
@ -316,18 +316,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
|
||||||
|
|
||||||
// Input plugin specific
|
// Input plugin specific
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sets the buttons for a controller
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="num">The controller number to set buttons for (0-3)</param>
|
|
||||||
/// <param name="keys">The button data</param>
|
|
||||||
/// <param name="X">The value for the X axis</param>
|
|
||||||
/// <param name="Y">The value for the Y axis</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
||||||
private delegate int SetKeys(int num, int keys, sbyte X, sbyte Y);
|
|
||||||
SetKeys InpSetKeys;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets a callback to use when the mupen core wants controller buttons
|
/// Sets a callback to use when the mupen core wants controller buttons
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -337,7 +325,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
|
||||||
SetInputCallback InpSetInputCallback;
|
SetInputCallback InpSetInputCallback;
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
public delegate void InputCallback();
|
public delegate int InputCallback(int i);
|
||||||
InputCallback InpInputCallback;
|
InputCallback InpInputCallback;
|
||||||
|
|
||||||
|
|
||||||
|
@ -600,7 +588,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
|
||||||
|
|
||||||
InpPluginStartup = (PluginStartup)Marshal.GetDelegateForFunctionPointer(GetProcAddress(InpDll, "PluginStartup"), typeof(PluginStartup));
|
InpPluginStartup = (PluginStartup)Marshal.GetDelegateForFunctionPointer(GetProcAddress(InpDll, "PluginStartup"), typeof(PluginStartup));
|
||||||
InpPluginShutdown = (PluginShutdown)Marshal.GetDelegateForFunctionPointer(GetProcAddress(InpDll, "PluginShutdown"), typeof(PluginShutdown));
|
InpPluginShutdown = (PluginShutdown)Marshal.GetDelegateForFunctionPointer(GetProcAddress(InpDll, "PluginShutdown"), typeof(PluginShutdown));
|
||||||
InpSetKeys = (SetKeys)Marshal.GetDelegateForFunctionPointer(GetProcAddress(InpDll, "SetKeys"), typeof(SetKeys));
|
|
||||||
InpSetInputCallback = (SetInputCallback)Marshal.GetDelegateForFunctionPointer(GetProcAddress(InpDll, "SetInputCallback"), typeof(SetInputCallback));
|
InpSetInputCallback = (SetInputCallback)Marshal.GetDelegateForFunctionPointer(GetProcAddress(InpDll, "SetInputCallback"), typeof(SetInputCallback));
|
||||||
|
|
||||||
RspPluginStartup = (PluginStartup)Marshal.GetDelegateForFunctionPointer(GetProcAddress(RspDll, "PluginStartup"), typeof(PluginStartup));
|
RspPluginStartup = (PluginStartup)Marshal.GetDelegateForFunctionPointer(GetProcAddress(RspDll, "PluginStartup"), typeof(PluginStartup));
|
||||||
|
@ -692,11 +679,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
|
||||||
return m64pDebugMemGetPointer(id);
|
return m64pDebugMemGetPointer(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set_buttons(int num, int keys, sbyte X, sbyte Y)
|
|
||||||
{
|
|
||||||
InpSetKeys(num, keys, X, Y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void soft_reset()
|
public void soft_reset()
|
||||||
{
|
{
|
||||||
m64pCoreDoCommandPtr(m64p_command.M64CMD_RESET, 0, IntPtr.Zero);
|
m64pCoreDoCommandPtr(m64p_command.M64CMD_RESET, 0, IntPtr.Zero);
|
||||||
|
|
|
@ -47,7 +47,7 @@ static void (*l_DebugCallback)(void *, int, const char *) = NULL;
|
||||||
static void *l_DebugCallContext = NULL;
|
static void *l_DebugCallContext = NULL;
|
||||||
static int l_PluginInit = 0;
|
static int l_PluginInit = 0;
|
||||||
|
|
||||||
static void (*l_inputCallback)() = NULL;
|
static int (*l_inputCallback)(int i) = NULL;
|
||||||
|
|
||||||
static int romopen = 0; // is a rom opened
|
static int romopen = 0; // is a rom opened
|
||||||
|
|
||||||
|
@ -272,22 +272,10 @@ EXPORT void CALL SDL_KeyUp(int keymod, int keysym)
|
||||||
*******************************************************************/
|
*******************************************************************/
|
||||||
EXPORT void CALL GetKeys( int Control, BUTTONS *Keys )
|
EXPORT void CALL GetKeys( int Control, BUTTONS *Keys )
|
||||||
{
|
{
|
||||||
(*l_inputCallback)();
|
Keys->Value = (*l_inputCallback)(Control);
|
||||||
Keys->Value = controller[Control].buttons.Value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
EXPORT void CALL SetInputCallback(int (*inputCallback)(int i))
|
||||||
----------- Sets the internal buttons delegated to mupen64 -----------
|
|
||||||
---------------------------------------------------------------------- */
|
|
||||||
EXPORT void CALL SetKeys(int num, int keys, char X, char Y)
|
|
||||||
{
|
|
||||||
controller[num].buttons.Value = keys;
|
|
||||||
|
|
||||||
controller[num].buttons.X_AXIS = X;
|
|
||||||
controller[num].buttons.Y_AXIS = Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
EXPORT void CALL SetInputCallback(void (*inputCallback)())
|
|
||||||
{
|
{
|
||||||
l_inputCallback = inputCallback;
|
l_inputCallback = inputCallback;
|
||||||
}
|
}
|
|
@ -31,7 +31,6 @@
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
CONTROL *control; // pointer to CONTROL struct in Core library
|
CONTROL *control; // pointer to CONTROL struct in Core library
|
||||||
BUTTONS buttons;
|
|
||||||
} SController;
|
} SController;
|
||||||
|
|
||||||
/* global data definitions */
|
/* global data definitions */
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue