diff --git a/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs b/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs index aba70c6915..67a3a08823 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs @@ -75,6 +75,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64 */ api.set_buttons(0, ReadController(1), x, y); api.frame_advance(); + IsLagFrame = api.IsLagFrame(); + if (IsLagFrame) LagCount++; Frame++; } diff --git a/BizHawk.Emulation/Consoles/Nintendo/N64/mupen64plusApi.cs b/BizHawk.Emulation/Consoles/Nintendo/N64/mupen64plusApi.cs index d2363ef707..9c55dbff03 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/N64/mupen64plusApi.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/N64/mupen64plusApi.cs @@ -288,6 +288,21 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64 private delegate int SetKeys(int num, int keys, sbyte X, sbyte Y); SetKeys InpSetKeys; + /// <summary> + /// Resets the internal lag indicator to true. + /// </summary> + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void ResetLagFlag(); + ResetLagFlag InpResetLagFlag; + + /// <summary> + /// Checks the internal lag indicator. It will be set to 0 if the input has been read since it was last reset + /// </summary> + /// <returns></returns> + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int CheckLagFlag(); + CheckLagFlag InpCheckLagFlag; + // These are common for all four plugins @@ -488,6 +503,8 @@ namespace BizHawk.Emulation.Consoles.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)); + InpResetLagFlag = (ResetLagFlag)Marshal.GetDelegateForFunctionPointer(GetProcAddress(InpDll, "ResetLagFlag"), typeof(ResetLagFlag)); + InpCheckLagFlag = (CheckLagFlag)Marshal.GetDelegateForFunctionPointer(GetProcAddress(InpDll, "CheckLagFlag"), typeof(CheckLagFlag)); RspPluginStartup = (PluginStartup)Marshal.GetDelegateForFunctionPointer(GetProcAddress(RspDll, "PluginStartup"), typeof(PluginStartup)); RspPluginShutdown = (PluginShutdown)Marshal.GetDelegateForFunctionPointer(GetProcAddress(RspDll, "PluginShutdown"), typeof(PluginShutdown)); @@ -594,10 +611,16 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64 public void frame_advance() { + InpResetLagFlag(); m64pCoreDoCommandPtr(m64p_command.M64CMD_ADVANCE_FRAME, 0, IntPtr.Zero); m64pFrameComplete.WaitOne(); } + public bool IsLagFrame() + { + return (InpCheckLagFlag() == 1 ? true : false); + } + public int SaveState(byte[] buffer) { return m64pCoreSaveState(buffer); diff --git a/BizHawk.MultiClient/output/dll/mupen64plus-input-bkm.dll b/BizHawk.MultiClient/output/dll/mupen64plus-input-bkm.dll index daf98f6132..aa2b6c7cf4 100644 Binary files a/BizHawk.MultiClient/output/dll/mupen64plus-input-bkm.dll and b/BizHawk.MultiClient/output/dll/mupen64plus-input-bkm.dll differ diff --git a/libmupen64plus/mupen64plus-input-bkm/plugin.c b/libmupen64plus/mupen64plus-input-bkm/plugin.c index 794dbc7c6c..083521be62 100644 --- a/libmupen64plus/mupen64plus-input-bkm/plugin.c +++ b/libmupen64plus/mupen64plus-input-bkm/plugin.c @@ -91,6 +91,8 @@ static unsigned char myKeyState[SDL_NUM_SCANCODES]; BUTTONS controllers[4]; +int LagFlag = 1; + #ifdef __linux__ static struct ff_effect ffeffect[3]; static struct ff_effect ffstrong[3]; @@ -369,6 +371,7 @@ EXPORT void CALL ControllerCommand(int Control, unsigned char *Command) EXPORT void CALL GetKeys( int Control, BUTTONS *Keys ) { (*Keys).Value = controllers[Control].Value; + LagFlag = 0; } /****************************************************************** @@ -483,4 +486,14 @@ EXPORT void CALL SetKeys(int num, int keys, char X, char Y) controllers[num].X_AXIS = X; controllers[num].Y_AXIS = Y; +} + +EXPORT void CALL ResetLagFlag() +{ + LagFlag = 1; +} + +EXPORT int CALL CheckLagFlag() +{ + return LagFlag; } \ No newline at end of file