N64: Refactor some input code to use callbacks and (hopefully) be compatible with on_snoop
This commit is contained in:
parent
ba3feac259
commit
7da2ede59d
BizHawk.Emulation/Consoles/Nintendo/N64
BizHawk.MultiClient/output/dll
libmupen64plus/mupen64plus-input-bkm
|
@ -71,7 +71,18 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64
|
|||
{
|
||||
api.hard_reset();
|
||||
}
|
||||
|
||||
|
||||
IsLagFrame = true;
|
||||
api.frame_advance();
|
||||
if (IsLagFrame) LagCount++;
|
||||
Frame++;
|
||||
}
|
||||
|
||||
public void setControllers()
|
||||
{
|
||||
if (CoreComm.InputCallback != null) CoreComm.InputCallback();
|
||||
IsLagFrame = false;
|
||||
|
||||
sbyte x = 0;
|
||||
sbyte y = 0;
|
||||
/*
|
||||
|
@ -91,10 +102,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64
|
|||
y = (sbyte)Y_Axis;
|
||||
|
||||
api.set_buttons(0, ReadController(1), x, y);
|
||||
api.frame_advance();
|
||||
IsLagFrame = api.IsLagFrame();
|
||||
if (IsLagFrame) LagCount++;
|
||||
Frame++;
|
||||
}
|
||||
|
||||
public int ReadController(int num)
|
||||
|
@ -232,6 +239,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64
|
|||
this.game = game;
|
||||
|
||||
api = new mupen64plusApi(this, rom, video_settings);
|
||||
api.SetM64PInputCallback(new mupen64plusApi.InputCallback(setControllers));
|
||||
|
||||
MemoryDomains = new List<MemoryDomain>();
|
||||
MemoryDomains.Add(new MemoryDomain("RDRAM", 0x400000, Endian.Little, api.getRDRAMByte, api.setRDRAMByte));
|
||||
|
|
|
@ -312,19 +312,16 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64
|
|||
SetKeys InpSetKeys;
|
||||
|
||||
/// <summary>
|
||||
/// Resets the internal lag indicator to true.
|
||||
/// Sets a callback to use when the mupen core wants controller buttons
|
||||
/// </summary>
|
||||
/// <param name="inputCallback">The delegate to use</param>
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate void ResetLagFlag();
|
||||
ResetLagFlag InpResetLagFlag;
|
||||
private delegate void SetInputCallback(InputCallback inputCallback);
|
||||
SetInputCallback InpSetInputCallback;
|
||||
|
||||
/// <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;
|
||||
public delegate void InputCallback();
|
||||
InputCallback InpInputCallback;
|
||||
|
||||
|
||||
// These are common for all four plugins
|
||||
|
@ -547,8 +544,7 @@ 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));
|
||||
InpSetInputCallback = (SetInputCallback)Marshal.GetDelegateForFunctionPointer(GetProcAddress(InpDll, "SetInputCallback"), typeof(SetInputCallback));
|
||||
|
||||
RspPluginStartup = (PluginStartup)Marshal.GetDelegateForFunctionPointer(GetProcAddress(RspDll, "PluginStartup"), typeof(PluginStartup));
|
||||
RspPluginShutdown = (PluginShutdown)Marshal.GetDelegateForFunctionPointer(GetProcAddress(RspDll, "PluginShutdown"), typeof(PluginShutdown));
|
||||
|
@ -686,14 +682,14 @@ 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()
|
||||
public void SetM64PInputCallback(InputCallback inputCallback)
|
||||
{
|
||||
return (InpCheckLagFlag() == 1 ? true : false);
|
||||
InpInputCallback = inputCallback;
|
||||
InpSetInputCallback(InpInputCallback);
|
||||
}
|
||||
|
||||
public int SaveState(byte[] buffer)
|
||||
|
|
Binary file not shown.
|
@ -66,6 +66,8 @@ 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 unsigned short button_bits[] = {
|
||||
0x0001, // R_DPAD
|
||||
0x0002, // L_DPAD
|
||||
|
@ -91,8 +93,6 @@ 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];
|
||||
|
@ -370,8 +370,8 @@ EXPORT void CALL ControllerCommand(int Control, unsigned char *Command)
|
|||
*******************************************************************/
|
||||
EXPORT void CALL GetKeys( int Control, BUTTONS *Keys )
|
||||
{
|
||||
(*l_inputCallback)();
|
||||
(*Keys).Value = controllers[Control].Value;
|
||||
LagFlag = 0;
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
|
@ -488,12 +488,7 @@ EXPORT void CALL SetKeys(int num, int keys, char X, char Y)
|
|||
controllers[num].Y_AXIS = Y;
|
||||
}
|
||||
|
||||
EXPORT void CALL ResetLagFlag()
|
||||
EXPORT void CALL SetInputCallback(void (*inputCallback)())
|
||||
{
|
||||
LagFlag = 1;
|
||||
}
|
||||
|
||||
EXPORT int CALL CheckLagFlag()
|
||||
{
|
||||
return LagFlag;
|
||||
l_inputCallback = inputCallback;
|
||||
}
|
Loading…
Reference in New Issue