From 52ee4984fa65112c6cc1ff88676a49109e9c439e Mon Sep 17 00:00:00 2001 From: null_ptr Date: Thu, 8 May 2014 20:03:00 +0000 Subject: [PATCH] Added setting for the controller plugin type and the controller connection to N64SyncSettings --- .../Consoles/Nintendo/N64/N64.cs | 2 +- .../Consoles/Nintendo/N64/N64Input.cs | 28 +++++++- .../Consoles/Nintendo/N64/N64SyncSettings.cs | 65 ++++++++++++++++++- .../N64/NativeAPI/mupen64plusInputAPI.cs | 33 +++++++++- 4 files changed, 124 insertions(+), 4 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs index 7a2674eb7a..208761f861 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs @@ -432,7 +432,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 // Order is important because the register with the mupen core videoProvider = new N64VideoProvider(api, videosettings); audioProvider = new N64Audio(api); - inputProvider = new N64Input(api, comm); + inputProvider = new N64Input(api, comm, this.SyncSettings.Controllers); api.AttachPlugin(mupen64plusApi.m64p_plugin_type.M64PLUGIN_RSP, "mupen64plus-rsp-hle.dll"); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64Input.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64Input.cs index 5196508285..66b012e4d5 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64Input.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64Input.cs @@ -1,5 +1,6 @@ using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores.Nintendo.N64.NativeApi; +using BizHawk.Emulation.Cores.Consoles.Nintendo.N64; namespace BizHawk.Emulation.Cores.Nintendo.N64 { @@ -44,7 +45,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 } }; - public N64Input(mupen64plusApi core, CoreComm comm) + public N64Input(mupen64plusApi core, CoreComm comm, N64ControllerSettings[] controllerSettings) { api = new mupen64plusInputApi(core); CoreComm = comm; @@ -52,6 +53,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 api.SetM64PInputCallback(new mupen64plusInputApi.InputCallback(GetControllerInput)); core.VInterrupt += ShiftInputPolledBools; + for (int i = 0; i < controllerSettings.Length; ++i) + { + SetControllerConnected(i, controllerSettings[i].IsConnected); + SetControllerPakType(i, controllerSettings[i].PakType); + } } public void ShiftInputPolledBools() @@ -116,5 +122,25 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 return buttons; } + + /// + /// Sets the controller pak of the controller to the specified type + /// + /// Id of the controller + /// Type to which the controller pak is set. Currently only NO_PAK and MEMORY_CARD are supported + public void SetControllerPakType(int controller, N64ControllerSettings.N64ControllerPakType type) + { + api.SetM64PControllerPakType(controller, type); + } + + /// + /// Sets the connection status of the controller + /// + /// Id of the controller to connect or disconnect + /// New status of the controller connection + public void SetControllerConnected(int controller, bool connectionStatus) + { + api.SetM64PControllerConnected(controller, connectionStatus); + } } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64SyncSettings.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64SyncSettings.cs index 877f745c61..5128633320 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64SyncSettings.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64SyncSettings.cs @@ -10,6 +10,13 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.N64 public PLUGINTYPE VidPlugin = PLUGINTYPE.RICE; public int VideoSizeX = 320; public int VideoSizeY = 240; + public N64ControllerSettings[] Controllers = new N64ControllerSettings[4] + { + new N64ControllerSettings(), + new N64ControllerSettings(), + new N64ControllerSettings(), + new N64ControllerSettings() + }; public N64RicePluginSettings RicePlugin = new N64RicePluginSettings(); public N64GlidePluginSettings GlidePlugin = new N64GlidePluginSettings(); @@ -24,7 +31,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.N64 VideoSizeY = VideoSizeY, RicePlugin = RicePlugin.Clone(), GlidePlugin = GlidePlugin.Clone(), - Glide64mk2Plugin = Glide64mk2Plugin.Clone() + Glide64mk2Plugin = Glide64mk2Plugin.Clone(), + Controllers = System.Array.ConvertAll(Controllers, a => a.Clone()) }; } @@ -420,4 +428,59 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.N64 } } + public class N64ControllerSettings + { + /// + /// Enumeration defining the different controller pak types + /// for N64 + /// + public enum N64ControllerPakType + { + NO_PAK = 1, + MEMORY_CARD = 2, + RUMBLE_PAK = 3, + TRANSFER_PAK = 4 + } + + private N64ControllerPakType _type = N64ControllerPakType.MEMORY_CARD; + /// + /// Type of the pak inserted in the controller + /// Currently only NO_PAK and MEMORY_CARD are + /// supported. Other values may be set and + /// are recognized but they have no function + /// yet. e.g. TRANSFER_PAK makes the N64 + /// recognize a transfer pak inserted in + /// the controller but there is no + /// communication to the transfer pak. + /// + public N64ControllerPakType PakType + { + get { return _type; } + set { _type = value; } + } + + private bool _isConnected = true; + /// + /// Connection status of the controller i.e.: + /// Is the controller plugged into the N64? + /// + public bool IsConnected + { + get { return _isConnected; } + set { _isConnected = value; } + } + + /// + /// Clones this object + /// + /// New object with the same values + public N64ControllerSettings Clone() + { + return new N64ControllerSettings + { + PakType = PakType, + IsConnected = IsConnected + }; + } + } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/NativeAPI/mupen64plusInputAPI.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/NativeAPI/mupen64plusInputAPI.cs index 2b78f55ce6..18baa51b82 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/NativeAPI/mupen64plusInputAPI.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/NativeAPI/mupen64plusInputAPI.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Runtime.InteropServices; using BizHawk.Emulation.Cores.Nintendo.N64; +using BizHawk.Emulation.Cores.Consoles.Nintendo.N64; namespace BizHawk.Emulation.Cores.Nintendo.N64.NativeApi { @@ -43,6 +44,24 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64.NativeApi public delegate void RumbleCallback(int Control, int on); RumbleCallback m64pRumbleCallback; + /// + /// Sets the controller pak type + /// + /// Controller id + /// Type id according to (well documented... hurr hurr) mupen api + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void SetControllerPakType(int controller, int type); + SetControllerPakType InpSetControllerPakType; + + /// + /// Connects and disconnects controllers + /// + /// Controller id + /// 1 if controller should be connected, 0 if controller should be disconnected + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate void SetControllerConnected(int controller, int connected); + SetControllerConnected InpSetControllerConnected; + /// /// Event fired when mupen changes rumble pak status /// @@ -56,6 +75,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64.NativeApi mupen64plusApi.m64p_error result; InpSetInputCallback = (SetInputCallback)Marshal.GetDelegateForFunctionPointer(GetProcAddress(InpDll, "SetInputCallback"), typeof(SetInputCallback)); InpSetRumbleCallback = (SetRumbleCallback)Marshal.GetDelegateForFunctionPointer(GetProcAddress(InpDll, "SetRumbleCallback"), typeof(SetRumbleCallback)); + InpSetControllerPakType = (SetControllerPakType)Marshal.GetDelegateForFunctionPointer(GetProcAddress(InpDll, "SetControllerPakType"), typeof(SetControllerPakType)); + InpSetControllerConnected = (SetControllerConnected)Marshal.GetDelegateForFunctionPointer(GetProcAddress(InpDll, "SetControllerConnected"), typeof(SetControllerConnected)); m64pRumbleCallback = new RumbleCallback(FireOnRumbleChange); result = InpSetRumbleCallback(m64pRumbleCallback); @@ -67,10 +88,20 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64.NativeApi InpSetInputCallback(InpInputCallback); } - void FireOnRumbleChange(int Control, int on) + private void FireOnRumbleChange(int Control, int on) { if (OnRumbleChange != null) OnRumbleChange(Control, on); } + + public void SetM64PControllerPakType(int controller, N64ControllerSettings.N64ControllerPakType type) + { + InpSetControllerPakType(controller, (int)type); + } + + public void SetM64PControllerConnected(int controller, bool connected) + { + InpSetControllerConnected(controller, connected?1:0); + } } }