Simplified N64 controller input retrieval

This commit is contained in:
null_ptr 2014-01-23 02:06:39 +00:00
parent 3c7292f8ab
commit 15b95f6f40
5 changed files with 22 additions and 53 deletions

View File

@ -141,32 +141,32 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
}
/// <summary>
/// Translates controller inputs from EmuHawk and
/// shoves them into mupen64plus
/// Translates controller input from EmuHawk into
/// N64 controller data
/// </summary>
public void setControllers()
/// <param name="i">Id of controller to update and shove</param>
public int GetControllerInput(int i)
{
CoreComm.InputCallback.Call();
IsLagFrame = false;
// Analog stick right = +X
// 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++)
{
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"); }
sbyte y;
if (Controller.IsPressed(p + " A Up")) { y = 127; }
else if (Controller.IsPressed(p + " A Down")) { y = -127; }
else { y = (sbyte)Controller.GetFloat(p + " Y Axis"); }
sbyte y;
if (Controller.IsPressed(p + " A Up")) { y = 127; }
else if (Controller.IsPressed(p + " A Down")) { y = -127; }
else { y = (sbyte)Controller.GetFloat(p + " Y Axis"); }
api.set_buttons(i, ReadController(i+1), x, y);
}
int value = ReadController(i + 1);
value |= (x & 0xFF) << 16;
value |= (y & 0xFF) << 24;
return value;
}
/// <summary>
@ -456,7 +456,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
}
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);
videoProvider = new N64VideoProvider(api);

View File

@ -316,18 +316,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
// 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>
/// Sets a callback to use when the mupen core wants controller buttons
/// </summary>
@ -337,7 +325,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
SetInputCallback InpSetInputCallback;
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void InputCallback();
public delegate int InputCallback(int i);
InputCallback InpInputCallback;
@ -600,7 +588,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
InpPluginStartup = (PluginStartup)Marshal.GetDelegateForFunctionPointer(GetProcAddress(InpDll, "PluginStartup"), typeof(PluginStartup));
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));
RspPluginStartup = (PluginStartup)Marshal.GetDelegateForFunctionPointer(GetProcAddress(RspDll, "PluginStartup"), typeof(PluginStartup));
@ -692,11 +679,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
return m64pDebugMemGetPointer(id);
}
public void set_buttons(int num, int keys, sbyte X, sbyte Y)
{
InpSetKeys(num, keys, X, Y);
}
public void soft_reset()
{
m64pCoreDoCommandPtr(m64p_command.M64CMD_RESET, 0, IntPtr.Zero);

View File

@ -47,7 +47,7 @@ static void (*l_DebugCallback)(void *, int, const char *) = NULL;
static void *l_DebugCallContext = NULL;
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
@ -272,22 +272,10 @@ EXPORT void CALL SDL_KeyUp(int keymod, int keysym)
*******************************************************************/
EXPORT void CALL GetKeys( int Control, BUTTONS *Keys )
{
(*l_inputCallback)();
Keys->Value = controller[Control].buttons.Value;
Keys->Value = (*l_inputCallback)(Control);
}
/* ----------------------------------------------------------------------
----------- 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)())
EXPORT void CALL SetInputCallback(int (*inputCallback)(int i))
{
l_inputCallback = inputCallback;
}

View File

@ -31,7 +31,6 @@
typedef struct
{
CONTROL *control; // pointer to CONTROL struct in Core library
BUTTONS buttons;
} SController;
/* global data definitions */

Binary file not shown.