From 15b95f6f40dbbb04d869cf3926864e51741a7f9c Mon Sep 17 00:00:00 2001 From: null_ptr Date: Thu, 23 Jan 2014 02:06:39 +0000 Subject: [PATCH] Simplified N64 controller input retrieval --- .../Consoles/Nintendo/N64/N64.cs | 36 +++++++++--------- .../Consoles/Nintendo/N64/mupen64plusApi.cs | 20 +--------- libmupen64plus/mupen64plus-input-bkm/plugin.c | 18 ++------- libmupen64plus/mupen64plus-input-bkm/plugin.h | 1 - output/dll/mupen64plus-input-bkm.dll | Bin 7680 -> 7680 bytes 5 files changed, 22 insertions(+), 53 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs index 83228cedb4..65d8db3c4e 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs @@ -141,32 +141,32 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 } /// - /// Translates controller inputs from EmuHawk and - /// shoves them into mupen64plus + /// Translates controller input from EmuHawk into + /// N64 controller data /// - public void setControllers() + /// Id of controller to update and shove + 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; } /// @@ -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); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/mupen64plusApi.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/mupen64plusApi.cs index 7d1076d2d8..55da55b39b 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/mupen64plusApi.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/mupen64plusApi.cs @@ -316,18 +316,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 // Input plugin specific - /// - /// Sets the buttons for a controller - /// - /// The controller number to set buttons for (0-3) - /// The button data - /// The value for the X axis - /// The value for the Y axis - /// - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate int SetKeys(int num, int keys, sbyte X, sbyte Y); - SetKeys InpSetKeys; - /// /// Sets a callback to use when the mupen core wants controller buttons /// @@ -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); diff --git a/libmupen64plus/mupen64plus-input-bkm/plugin.c b/libmupen64plus/mupen64plus-input-bkm/plugin.c index 486673fb1f..78fa15452a 100644 --- a/libmupen64plus/mupen64plus-input-bkm/plugin.c +++ b/libmupen64plus/mupen64plus-input-bkm/plugin.c @@ -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; } \ No newline at end of file diff --git a/libmupen64plus/mupen64plus-input-bkm/plugin.h b/libmupen64plus/mupen64plus-input-bkm/plugin.h index 46899380f3..596712288e 100644 --- a/libmupen64plus/mupen64plus-input-bkm/plugin.h +++ b/libmupen64plus/mupen64plus-input-bkm/plugin.h @@ -31,7 +31,6 @@ typedef struct { CONTROL *control; // pointer to CONTROL struct in Core library - BUTTONS buttons; } SController; /* global data definitions */ diff --git a/output/dll/mupen64plus-input-bkm.dll b/output/dll/mupen64plus-input-bkm.dll index 9e891c985b47721ecb858361d3435cb16e4c9639..8820d992ca6669db552558320a72780cef43c08b 100644 GIT binary patch delta 1981 zcmd6n|8G-O6u|F&v}?=S<=Iizxy`k#+sb6H_q|^ROtX=RLkdhXgpm;kDGjhioa^l2`<`0JvVo(J}h}Hi8bgJ51 zgwRH4T|hc;0d6Pz@Or$FOyXjEo;aCe+)18cR^pRG?=m|ut|W7H4xw5=Y;V`pKdKs7 zwOX}RLNzjKkFJ;!&L!IzgrdLHkDS%M=cD71adTvG4cV&8H_(pVmTIzB*As4ra;$}l zb}Dv&Na$-of-4VAAjG|zwKeS+Z5WBsIbzg-80{Q;#56+u{^HaFa6pJZqF0!WRv9(> zXW%gEt~L(RsS-$AzRDPhn>FvCA!?&;CYT2;cFkovgt{KmKNu8xF@z&=mljNLn-hYC z(H0t7un%gXSqV%hNhYUNhYA_fvXs!*LI*ITl-pXIv0BoWwyh9+45+pMv`1H%Bcr-* zJd@Z|Xf%cZ@fb?ojnF670HW)5t6qp#Y#fOcp`=@nP_W*P*rWkU37u;@=`}c7juK|g_Mf4-ZeI*stJ8F zbj5Hg2B9&Njk%zj(Az0oXiP@1Br^PrFbIA?!fi$)N z4pIl%Z@Gax$eS5knRC{m=?onv7n!E;L;*rFTxAEq0=Ekh`W`q190K+L?LZ^23|IoV zfg0#*2W583cv%D0IUmMm{IZ?o5@|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