From 2a0c6c4daf0c60b759ee50c838b3ccacbcfff207 Mon Sep 17 00:00:00 2001 From: pjgat09 Date: Thu, 2 May 2013 03:38:57 +0000 Subject: [PATCH] m64p: Configure controller 1 to be plugged in. Flesh out the plugin somewhat N64: Pass controller 1 data to the core --- .../Consoles/Nintendo/N64/N64.cs | 42 +++++++++++++++++- .../output/dll/mupen64plus-input-bkm.dll | Bin 9216 -> 9728 bytes libmupen64plus/mupen64plus-input-bkm/plugin.c | 31 ++++++++++++- 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs b/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs index 11089e386d..3a74af8f29 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs @@ -69,11 +69,34 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64 public void FrameAdvance(bool render, bool rendersound) { m64pFrameComplete = false; + InpSetKeys(0, ReadController(1), 0, 0); m64pCoreDoCommandPtr(m64p_command.M64CMD_ADVANCE_FRAME, 0, IntPtr.Zero); while (m64pFrameComplete == false) { } Frame++; } + public int ReadController(int num) + { + int buttons = 0; + + if (Controller["P1 DPad R"]) buttons |= (1 << 0); + if (Controller["P1 DPad L"]) buttons |= (1 << 1); + if (Controller["P1 DPad D"]) buttons |= (1 << 2); + if (Controller["P1 DPad U"]) buttons |= (1 << 3); + if (Controller["P1 Start"]) buttons |= (1 << 4); + if (Controller["P1 Z"]) buttons |= (1 << 5); + if (Controller["P1 B"]) buttons |= (1 << 6); + if (Controller["P1 A"]) buttons |= (1 << 7); + if (Controller["P1 C Right"]) buttons |= (1 << 8); + if (Controller["P1 C Left"]) buttons |= (1 << 9); + if (Controller["P1 C Down"]) buttons |= (1 << 10); + if (Controller["P1 C Up"]) buttons |= (1 << 11); + if (Controller["P1 R"]) buttons |= (1 << 12); + if (Controller["P1 L"]) buttons |= (1 << 13); + + return buttons; + } + public bool DeterministicEmulation { get; set; } public byte[] ReadSaveRam() { return null; } @@ -127,6 +150,9 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64 AudPluginShutdown(); FreeLibrary(AudDll); + InpPluginShutdown(); + FreeLibrary(InpDll); + RspPluginShutdown(); FreeLibrary(RspDll); @@ -253,6 +279,11 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64 private delegate int GetBufferSize(); GetBufferSize AudGetBufferSize; + // Input plugin specific + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int SetKeys(int num, int keys, byte X, byte Y); + SetKeys InpSetKeys; + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void ReadAudioBuffer(short[] dest); ReadAudioBuffer AudReadAudioBuffer; @@ -269,10 +300,12 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64 PluginStartup GfxPluginStartup; PluginStartup RspPluginStartup; PluginStartup AudPluginStartup; + PluginStartup InpPluginStartup; PluginShutdown GfxPluginShutdown; PluginShutdown RspPluginShutdown; PluginShutdown AudPluginShutdown; + PluginShutdown InpPluginShutdown; [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void DebugCallback(IntPtr Context, int level, string Message); @@ -319,6 +352,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64 IntPtr GfxDll; IntPtr RspDll; IntPtr AudDll; + IntPtr InpDll; Thread m64pEmulator; @@ -340,6 +374,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64 GfxDll = LoadLibrary("mupen64plus-video-rice.dll"); RspDll = LoadLibrary("mupen64plus-rsp-hle.dll"); AudDll = LoadLibrary("mupen64plus-audio-bkm.dll"); + InpDll = LoadLibrary("mupen64plus-input-bkm.dll"); m64pCoreStartup = (CoreStartup)Marshal.GetDelegateForFunctionPointer(GetProcAddress(CoreDll, "CoreStartup"), typeof(CoreStartup)); m64pCoreShutdown = (CoreShutdown)Marshal.GetDelegateForFunctionPointer(GetProcAddress(CoreDll, "CoreShutdown"), typeof(CoreShutdown)); @@ -361,6 +396,10 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64 AudReadAudioBuffer = (ReadAudioBuffer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(AudDll, "ReadAudioBuffer"), typeof(ReadAudioBuffer)); AudGetAudioRate = (GetAudioRate)Marshal.GetDelegateForFunctionPointer(GetProcAddress(AudDll, "GetAudioRate"), typeof(GetAudioRate)); + 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)); + RspPluginStartup = (PluginStartup)Marshal.GetDelegateForFunctionPointer(GetProcAddress(RspDll, "PluginStartup"), typeof(PluginStartup)); RspPluginShutdown = (PluginShutdown)Marshal.GetDelegateForFunctionPointer(GetProcAddress(RspDll, "PluginShutdown"), typeof(PluginShutdown)); @@ -377,7 +416,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64 result = m64pCoreAttachPlugin(m64p_plugin_type.M64PLUGIN_AUDIO, AudDll); // Set up a null input plugin - result = m64pCoreAttachPlugin(m64p_plugin_type.M64PLUGIN_INPUT, IntPtr.Zero); + result = AudPluginStartup(CoreDll, "Input", (IntPtr foo, int level, string Message) => { }); + result = m64pCoreAttachPlugin(m64p_plugin_type.M64PLUGIN_INPUT, InpDll); // Set up and connect the graphics plugin result = RspPluginStartup(CoreDll, "RSP", (IntPtr foo, int level, string Message) => { }); diff --git a/BizHawk.MultiClient/output/dll/mupen64plus-input-bkm.dll b/BizHawk.MultiClient/output/dll/mupen64plus-input-bkm.dll index f3e19c734ce14392365b56ffb8e99b7d6215031e..e82970349475a6797876cbb8d3dead96cd3365b7 100644 GIT binary patch delta 1199 zcmYk4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OU8*KM*qoPG~>$*==Fw#^=zX+6ktrjvJG z`Aq$sG7ocOWRcsN>q=AF^E-SI_rwJ75dc$@Og-roa=ip`TX*t*lH9l6Wr9WgOWQvt z*MC~Ec6)|=RFJ@WCyHmtn5N}e+GL$LTB*sSnujDj@{;CBpXCL$+-vn{HEHpw4!27I za3p}UnV<^&Hsl;Kng>wf2I$L2i)R&y;xDDNB4j?2I#1+a{u|^y@&}n-22hC1K|)9+ zvI<#;U`H1aNW)LELpo$YCO9BV-t%6So#aesq0OdTmv-Oz`18O(U?lK0@H;@Lk1`sj zHMD^?(q_7!9;Y|xJ=#nA={E{2mzA-FEXia5!@8K6&wkE3H}I<2kqR+U3_Mo7jZu?=aid# z317*pd6YNuX5Pkk@q@gbpXC?0#k+VnPx9A%kPq`Qt{54H$CzgrM#P92t;RLurt#8v zZFGdrgsz32h6Y1Jq19%!Sz|`cE#^-1gn8BcWr8RWhFB)nids=GHj55%PFxYwIz^Z0 S7D>?~`h=A%F^RlS^8W&*KI(4( diff --git a/libmupen64plus/mupen64plus-input-bkm/plugin.c b/libmupen64plus/mupen64plus-input-bkm/plugin.c index 5cc29f46de..b4790185f5 100644 --- a/libmupen64plus/mupen64plus-input-bkm/plugin.c +++ b/libmupen64plus/mupen64plus-input-bkm/plugin.c @@ -89,6 +89,8 @@ static int romopen = 0; // is a rom opened static unsigned char myKeyState[SDL_NUM_SCANCODES]; +BUTTONS controllers[4]; + #ifdef __linux__ static struct ff_effect ffeffect[3]; static struct ff_effect ffstrong[3]; @@ -355,6 +357,7 @@ EXPORT void CALL ControllerCommand(int Control, unsigned char *Command) } } + /****************************************************************** Function: GetKeys Purpose: To get the current state of the controllers buttons. @@ -365,7 +368,7 @@ EXPORT void CALL ControllerCommand(int Control, unsigned char *Command) *******************************************************************/ EXPORT void CALL GetKeys( int Control, BUTTONS *Keys ) { - // Use a call back function here, or look up a buffer + (*Keys).Value = controllers[Control].Value; } /****************************************************************** @@ -380,12 +383,18 @@ EXPORT void CALL GetKeys( int Control, BUTTONS *Keys ) EXPORT void CALL InitiateControllers(CONTROL_INFO ControlInfo) { int i; + memset( controller, 0, sizeof( SController ) * 4 ); + + for (i = 0; i < 4; i++) + controller[i].control = ControlInfo.Controls + i; for( i = 0; i < 4; i++ ) { controller[i].control->Plugin = PLUGIN_MEMPAK; } + controller[0].control->Present = 1; + DebugMessage(M64MSG_INFO, "%s version %i.%i.%i initialized.", PLUGIN_NAME, VERSION_PRINTF_SPLIT(PLUGIN_VERSION)); } @@ -455,3 +464,23 @@ EXPORT void CALL SDL_KeyUp(int keymod, int keysym) { } +EXPORT void CALL SetKeys(int num, int keys, unsigned char X, char Y) +{ + controllers[num].R_DPAD = (keys >> 0) & 0x01; + controllers[num].L_DPAD = (keys >> 1) & 0x01; + controllers[num].U_DPAD = (keys >> 2) & 0x01; + controllers[num].D_DPAD = (keys >> 3) & 0x01; + controllers[num].START_BUTTON = (keys >> 4) & 0x01; + controllers[num].Z_TRIG = (keys >> 5) & 0x01; + controllers[num].B_BUTTON = (keys >> 6) & 0x01; + controllers[num].A_BUTTON = (keys >> 7) & 0x01; + controllers[num].R_CBUTTON = (keys >> 8) & 0x01; + controllers[num].L_CBUTTON = (keys >> 9) & 0x01; + controllers[num].U_CBUTTON = (keys >> 10) & 0x01; + controllers[num].D_CBUTTON = (keys >> 11) & 0x01; + controllers[num].R_TRIG = (keys >> 12) & 0x01; + controllers[num].L_TRIG = (keys >> 13) & 0x01; + + controllers[num].X_AXIS = 0; + controllers[num].Y_AXIS = 0; +} \ No newline at end of file