From 7da2ede59da38a86b8e927e8584599c8a538c322 Mon Sep 17 00:00:00 2001 From: pjgat09 Date: Sat, 11 May 2013 23:44:20 +0000 Subject: [PATCH] N64: Refactor some input code to use callbacks and (hopefully) be compatible with on_snoop --- .../Consoles/Nintendo/N64/N64.cs | 18 +++++++++---- .../Consoles/Nintendo/N64/mupen64plusApi.cs | 24 ++++++++---------- .../output/dll/mupen64plus-input-bkm.dll | Bin 9728 -> 9728 bytes libmupen64plus/mupen64plus-input-bkm/plugin.c | 15 ++++------- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs b/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs index b883d23443..29787c0eb4 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs @@ -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(); MemoryDomains.Add(new MemoryDomain("RDRAM", 0x400000, Endian.Little, api.getRDRAMByte, api.setRDRAMByte)); diff --git a/BizHawk.Emulation/Consoles/Nintendo/N64/mupen64plusApi.cs b/BizHawk.Emulation/Consoles/Nintendo/N64/mupen64plusApi.cs index 0a3b1d62ca..38392edb99 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/N64/mupen64plusApi.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/N64/mupen64plusApi.cs @@ -312,19 +312,16 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64 SetKeys InpSetKeys; /// - /// Resets the internal lag indicator to true. + /// Sets a callback to use when the mupen core wants controller buttons /// + /// The delegate to use [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void ResetLagFlag(); - ResetLagFlag InpResetLagFlag; + private delegate void SetInputCallback(InputCallback inputCallback); + SetInputCallback InpSetInputCallback; - /// - /// Checks the internal lag indicator. It will be set to 0 if the input has been read since it was last reset - /// - /// [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) diff --git a/BizHawk.MultiClient/output/dll/mupen64plus-input-bkm.dll b/BizHawk.MultiClient/output/dll/mupen64plus-input-bkm.dll index aa2b6c7cf4c5c8e3c17845112ced4647d200c4e1..266255aa8a62bdfb283d6c66b88bafa80941f2af 100644 GIT binary patch delta 1409 zcmY*YeN01*mP#W4K+i-*pTN(;>RCz$r#Ub3;f|te)pbt ze&?QZetGAP2gifSzsh&se&Z0@TC0dFw_r0uc5oDKI?Z$!eo|Lw!?XpL;}IIdHCUwy z9K%Vvi>tx2)XTNuy0pSw!&pdn=vz5FPR|vTmW?+e`)3WvK5sCJ$i9%bk_6dr<*nlV z=^qQ8!Vp_(d>-~;V`xlsh;S$FH^%vi7n#+`E9Tzp*ZI{M|07%my+u%%WmX>n8$uHS zUa_(Qi9nTNE#8mpDMlySixmf}c9{bmO28O*upp(?c%FG9hR9&v$u2~2SYHX89>{Up zWqQKlgA7dmX6a8bm?wuT7%|mZG^tMvfHhf^ z7=)v5yZLPe&~S=r?4{G@y{;fwsQ_#fcV&Y+)6|!ZRU_49Kq%}i0f{@nn%7sk>6*C- zAEY&weXw^~Tw_geC&KkjWJXPqQnkDQq2ImXnKEP#zXjX8f$^+q6#>=LGm)`P9M?20 zoMa)VVN-vG)ICZg3v}P<@%Hkvv7=jaGyvyywu5)HB+L$VT@Qg!$g0WqE=@LSj`l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J?CZTRcFe%;QYmz zCzu7hP%Zd`9^s&HT%f`k;hgZ1a79Q9*M%ivMOYKCXc6xdJz|IG7mtgl#Ixc%;@9H0 z;=Fi6{7L*vM6NQ|c2}$GwCi(MK4~Rh(n+2mPm(^;PmYo>d4WX8C>bYjK1e3WB>9kB zB`GpZX2~M?jjWO^(Mr6uMJkc%B&XCYbx6I^)6%ojE7B?Hg7m4Bmeg*Yd%L@io~Ufa KD0!{2k^2v9*MCj` diff --git a/libmupen64plus/mupen64plus-input-bkm/plugin.c b/libmupen64plus/mupen64plus-input-bkm/plugin.c index 083521be62..c54db479ad 100644 --- a/libmupen64plus/mupen64plus-input-bkm/plugin.c +++ b/libmupen64plus/mupen64plus-input-bkm/plugin.c @@ -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; } \ No newline at end of file