N64: Implemented the lag indicator and lag count

This commit is contained in:
pjgat09 2013-05-06 23:50:24 +00:00
parent 371dcc8f40
commit a6600a5c0a
4 changed files with 38 additions and 0 deletions

View File

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

View File

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

View File

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