From d254548548398977a45dbfc03f2cc091c5a74f03 Mon Sep 17 00:00:00 2001 From: emmauss Date: Mon, 22 Jul 2019 20:15:46 +0300 Subject: Little rewrite of HID input (#723) * change hid sharedmem writing to use structures --- Ryujinx.HLE/Input/Controller/BaseController.cs | 142 ++++++++++++++++ Ryujinx.HLE/Input/Controller/NpadController.cs | 68 ++++++++ Ryujinx.HLE/Input/Controller/ProController.cs | 42 +++++ Ryujinx.HLE/Input/Controller/Types/BatteryState.cs | 12 ++ .../Input/Controller/Types/ControllerButtons.cs | 35 ++++ .../Controller/Types/ControllerColorDescription.cs | 10 ++ .../Controller/Types/ControllerConnectionState.cs | 11 ++ .../Controller/Types/ControllerDeviceState.cs | 18 ++ .../Input/Controller/Types/ControllerDeviceType.cs | 12 ++ .../Input/Controller/Types/ControllerHeader.cs | 19 +++ Ryujinx.HLE/Input/Controller/Types/ControllerId.cs | 16 ++ .../Input/Controller/Types/ControllerLayouts.cs | 13 ++ .../Input/Controller/Types/ControllerState.cs | 15 ++ .../Controller/Types/ControllerStateHeader.cs | 13 ++ .../Input/Controller/Types/ControllerStatus.cs | 14 ++ Ryujinx.HLE/Input/Controller/Types/DeviceFlags.cs | 22 +++ .../Input/Controller/Types/HotkeyButtons.cs | 10 ++ .../Input/Controller/Types/JoystickPosition.cs | 8 + Ryujinx.HLE/Input/Controller/Types/NpadColor.cs | 23 +++ Ryujinx.HLE/Input/Hid.cs | 182 ++++++++++++--------- Ryujinx.HLE/Input/HidBaseController.cs | 76 --------- Ryujinx.HLE/Input/HidControllerButtons.cs | 35 ---- Ryujinx.HLE/Input/HidControllerColorDesc.cs | 10 -- Ryujinx.HLE/Input/HidControllerConnState.cs | 11 -- Ryujinx.HLE/Input/HidControllerId.cs | 16 -- Ryujinx.HLE/Input/HidControllerLayouts.cs | 13 -- Ryujinx.HLE/Input/HidControllerType.cs | 14 -- Ryujinx.HLE/Input/HidHotkeyButtons.cs | 10 -- Ryujinx.HLE/Input/HidJoystickPosition.cs | 8 - Ryujinx.HLE/Input/HidKeyboard.cs | 8 - Ryujinx.HLE/Input/HidNpadController.cs | 92 ----------- Ryujinx.HLE/Input/HidProController.cs | 50 ------ Ryujinx.HLE/Input/HidTouchPoint.cs | 11 -- Ryujinx.HLE/Input/Keyboard/Keyboard.cs | 8 + Ryujinx.HLE/Input/Keyboard/KeyboardEntry.cs | 15 ++ Ryujinx.HLE/Input/Keyboard/KeyboardHeader.cs | 13 ++ Ryujinx.HLE/Input/NpadColor.cs | 23 --- Ryujinx.HLE/Input/Touch/TouchData.cs | 18 ++ Ryujinx.HLE/Input/Touch/TouchEntry.cs | 11 ++ Ryujinx.HLE/Input/Touch/TouchHeader.cs | 14 ++ Ryujinx.HLE/Input/Touch/TouchPoint.cs | 11 ++ 41 files changed, 702 insertions(+), 450 deletions(-) create mode 100644 Ryujinx.HLE/Input/Controller/BaseController.cs create mode 100644 Ryujinx.HLE/Input/Controller/NpadController.cs create mode 100644 Ryujinx.HLE/Input/Controller/ProController.cs create mode 100644 Ryujinx.HLE/Input/Controller/Types/BatteryState.cs create mode 100644 Ryujinx.HLE/Input/Controller/Types/ControllerButtons.cs create mode 100644 Ryujinx.HLE/Input/Controller/Types/ControllerColorDescription.cs create mode 100644 Ryujinx.HLE/Input/Controller/Types/ControllerConnectionState.cs create mode 100644 Ryujinx.HLE/Input/Controller/Types/ControllerDeviceState.cs create mode 100644 Ryujinx.HLE/Input/Controller/Types/ControllerDeviceType.cs create mode 100644 Ryujinx.HLE/Input/Controller/Types/ControllerHeader.cs create mode 100644 Ryujinx.HLE/Input/Controller/Types/ControllerId.cs create mode 100644 Ryujinx.HLE/Input/Controller/Types/ControllerLayouts.cs create mode 100644 Ryujinx.HLE/Input/Controller/Types/ControllerState.cs create mode 100644 Ryujinx.HLE/Input/Controller/Types/ControllerStateHeader.cs create mode 100644 Ryujinx.HLE/Input/Controller/Types/ControllerStatus.cs create mode 100644 Ryujinx.HLE/Input/Controller/Types/DeviceFlags.cs create mode 100644 Ryujinx.HLE/Input/Controller/Types/HotkeyButtons.cs create mode 100644 Ryujinx.HLE/Input/Controller/Types/JoystickPosition.cs create mode 100644 Ryujinx.HLE/Input/Controller/Types/NpadColor.cs delete mode 100644 Ryujinx.HLE/Input/HidBaseController.cs delete mode 100644 Ryujinx.HLE/Input/HidControllerButtons.cs delete mode 100644 Ryujinx.HLE/Input/HidControllerColorDesc.cs delete mode 100644 Ryujinx.HLE/Input/HidControllerConnState.cs delete mode 100644 Ryujinx.HLE/Input/HidControllerId.cs delete mode 100644 Ryujinx.HLE/Input/HidControllerLayouts.cs delete mode 100644 Ryujinx.HLE/Input/HidControllerType.cs delete mode 100644 Ryujinx.HLE/Input/HidHotkeyButtons.cs delete mode 100644 Ryujinx.HLE/Input/HidJoystickPosition.cs delete mode 100644 Ryujinx.HLE/Input/HidKeyboard.cs delete mode 100644 Ryujinx.HLE/Input/HidNpadController.cs delete mode 100644 Ryujinx.HLE/Input/HidProController.cs delete mode 100644 Ryujinx.HLE/Input/HidTouchPoint.cs create mode 100644 Ryujinx.HLE/Input/Keyboard/Keyboard.cs create mode 100644 Ryujinx.HLE/Input/Keyboard/KeyboardEntry.cs create mode 100644 Ryujinx.HLE/Input/Keyboard/KeyboardHeader.cs delete mode 100644 Ryujinx.HLE/Input/NpadColor.cs create mode 100644 Ryujinx.HLE/Input/Touch/TouchData.cs create mode 100644 Ryujinx.HLE/Input/Touch/TouchEntry.cs create mode 100644 Ryujinx.HLE/Input/Touch/TouchHeader.cs create mode 100644 Ryujinx.HLE/Input/Touch/TouchPoint.cs (limited to 'Ryujinx.HLE/Input') diff --git a/Ryujinx.HLE/Input/Controller/BaseController.cs b/Ryujinx.HLE/Input/Controller/BaseController.cs new file mode 100644 index 00000000..dfd54a83 --- /dev/null +++ b/Ryujinx.HLE/Input/Controller/BaseController.cs @@ -0,0 +1,142 @@ +using static Ryujinx.HLE.Input.Hid; + +namespace Ryujinx.HLE.Input +{ + public abstract class BaseController : IHidDevice + { + protected ControllerStatus HidControllerType; + protected ControllerId ControllerId; + + private long _currentLayoutOffset; + private long _mainLayoutOffset; + + protected long DeviceStateOffset => Offset + 0x4188; + + protected Switch Device { get; } + + public long Offset { get; private set; } + public bool Connected { get; protected set; } + + public ControllerHeader Header { get; private set; } + public ControllerStateHeader CurrentStateHeader { get; private set; } + public ControllerDeviceState DeviceState { get; private set; } + public ControllerLayouts CurrentLayout { get; private set; } + public ControllerState LastInputState { get; set; } + public ControllerConnectionState ConnectionState { get; protected set; } + + public BaseController(Switch device, ControllerStatus controllerType) + { + Device = device; + HidControllerType = controllerType; + } + + protected void Initialize( + bool isHalf, + (NpadColor left, NpadColor right) bodyColors, + (NpadColor left, NpadColor right) buttonColors, + ControllerColorDescription singleColorDesc = 0, + ControllerColorDescription splitColorDesc = 0, + NpadColor singleBodyColor = 0, + NpadColor singleButtonColor = 0 + ) + { + Header = new ControllerHeader() + { + IsJoyConHalf = isHalf ? 1 : 0, + LeftBodyColor = bodyColors.left, + LeftButtonColor = buttonColors.left, + RightBodyColor = bodyColors.right, + RightButtonColor = buttonColors.right, + Status = HidControllerType, + SingleBodyColor = singleBodyColor, + SingleButtonColor = singleButtonColor, + SplitColorDescription = splitColorDesc, + SingleColorDescription = singleColorDesc, + }; + + CurrentStateHeader = new ControllerStateHeader + { + EntryCount = HidEntryCount, + MaxEntryCount = HidEntryCount - 1, + CurrentEntryIndex = -1 + }; + + DeviceState = new ControllerDeviceState() + { + PowerInfo0BatteryState = BatteryState.Percent100, + PowerInfo1BatteryState = BatteryState.Percent100, + PowerInfo2BatteryState = BatteryState.Percent100, + DeviceType = ControllerDeviceType.NPadLeftController | ControllerDeviceType.NPadRightController, + DeviceFlags = DeviceFlags.PowerInfo0Connected + | DeviceFlags.PowerInfo1Connected + | DeviceFlags.PowerInfo2Connected + }; + + LastInputState = new ControllerState() + { + SamplesTimestamp = -1, + SamplesTimestamp2 = -1 + }; + } + + public virtual void Connect(ControllerId controllerId) + { + ControllerId = controllerId; + + Offset = Device.Hid.HidPosition + HidControllersOffset + (int)controllerId * HidControllerSize; + + _mainLayoutOffset = Offset + HidControllerHeaderSize + + ((int)ControllerLayouts.Main * HidControllerLayoutsSize); + + Device.Memory.FillWithZeros(Offset, 0x5000); + Device.Memory.WriteStruct(Offset, Header); + Device.Memory.WriteStruct(DeviceStateOffset, DeviceState); + + Connected = true; + } + + public void SetLayout(ControllerLayouts controllerLayout) + { + CurrentLayout = controllerLayout; + + _currentLayoutOffset = Offset + HidControllerHeaderSize + + ((int)controllerLayout * HidControllerLayoutsSize); + } + + public void SendInput( + ControllerButtons buttons, + JoystickPosition leftStick, + JoystickPosition rightStick) + { + ControllerState currentInput = new ControllerState() + { + SamplesTimestamp = (long)LastInputState.SamplesTimestamp + 1, + SamplesTimestamp2 = (long)LastInputState.SamplesTimestamp + 1, + ButtonState = buttons, + ConnectionState = ConnectionState, + LeftStick = leftStick, + RightStick = rightStick + }; + + ControllerStateHeader newInputStateHeader = new ControllerStateHeader + { + EntryCount = HidEntryCount, + MaxEntryCount = HidEntryCount - 1, + CurrentEntryIndex = (CurrentStateHeader.CurrentEntryIndex + 1) % HidEntryCount, + Timestamp = GetTimestamp(), + }; + + Device.Memory.WriteStruct(_currentLayoutOffset, newInputStateHeader); + Device.Memory.WriteStruct(_mainLayoutOffset, newInputStateHeader); + + long currentInputStateOffset = HidControllersLayoutHeaderSize + + newInputStateHeader.CurrentEntryIndex * HidControllersInputEntrySize; + + Device.Memory.WriteStruct(_currentLayoutOffset + currentInputStateOffset, currentInput); + Device.Memory.WriteStruct(_mainLayoutOffset + currentInputStateOffset, currentInput); + + LastInputState = currentInput; + CurrentStateHeader = newInputStateHeader; + } + } +} diff --git a/Ryujinx.HLE/Input/Controller/NpadController.cs b/Ryujinx.HLE/Input/Controller/NpadController.cs new file mode 100644 index 00000000..b4304b8f --- /dev/null +++ b/Ryujinx.HLE/Input/Controller/NpadController.cs @@ -0,0 +1,68 @@ +namespace Ryujinx.HLE.Input +{ + public class NpadController : BaseController + { + private (NpadColor Left, NpadColor Right) _npadBodyColors; + private (NpadColor Left, NpadColor Right) _npadButtonColors; + + private bool _isHalf; + + public NpadController( + ControllerStatus controllerStatus, + Switch device, + (NpadColor, NpadColor) npadBodyColors, + (NpadColor, NpadColor) npadButtonColors) : base(device, controllerStatus) + { + _npadBodyColors = npadBodyColors; + _npadButtonColors = npadButtonColors; + } + + public override void Connect(ControllerId controllerId) + { + if (HidControllerType != ControllerStatus.NpadLeft && HidControllerType != ControllerStatus.NpadRight) + { + _isHalf = false; + } + + ConnectionState = ControllerConnectionState.ControllerStateConnected; + + if (controllerId == ControllerId.ControllerHandheld) + ConnectionState |= ControllerConnectionState.ControllerStateWired; + + ControllerColorDescription singleColorDesc = + ControllerColorDescription.ColorDescriptionColorsNonexistent; + + ControllerColorDescription splitColorDesc = 0; + + NpadColor singleBodyColor = NpadColor.Black; + NpadColor singleButtonColor = NpadColor.Black; + + Initialize(_isHalf, + (_npadBodyColors.Left, _npadBodyColors.Right), + (_npadButtonColors.Left, _npadButtonColors.Right), + singleColorDesc, + splitColorDesc, + singleBodyColor, + singleButtonColor ); + + base.Connect(controllerId); + + var _currentLayout = ControllerLayouts.HandheldJoined; + + switch (HidControllerType) + { + case ControllerStatus.NpadLeft: + _currentLayout = ControllerLayouts.Left; + break; + case ControllerStatus.NpadRight: + _currentLayout = ControllerLayouts.Right; + break; + case ControllerStatus.NpadPair: + _currentLayout = ControllerLayouts.Joined; + break; + } + + SetLayout(_currentLayout); + } + } +} diff --git a/Ryujinx.HLE/Input/Controller/ProController.cs b/Ryujinx.HLE/Input/Controller/ProController.cs new file mode 100644 index 00000000..ae574260 --- /dev/null +++ b/Ryujinx.HLE/Input/Controller/ProController.cs @@ -0,0 +1,42 @@ +namespace Ryujinx.HLE.Input +{ + public class ProController : BaseController + { + private bool _wired = false; + + private NpadColor _bodyColor; + private NpadColor _buttonColor; + + public ProController(Switch device, + NpadColor bodyColor, + NpadColor buttonColor) : base(device, ControllerStatus.ProController) + { + _wired = true; + + _bodyColor = bodyColor; + _buttonColor = buttonColor; + } + + public override void Connect(ControllerId controllerId) + { + ControllerColorDescription singleColorDesc = + ControllerColorDescription.ColorDescriptionColorsNonexistent; + + ControllerColorDescription splitColorDesc = 0; + + ConnectionState = ControllerConnectionState.ControllerStateConnected | ControllerConnectionState.ControllerStateWired; + + Initialize(false, + (0, 0), + (0, 0), + singleColorDesc, + splitColorDesc, + _bodyColor, + _buttonColor); + + base.Connect(controllerId); + + SetLayout(ControllerLayouts.ProController); + } + } +} diff --git a/Ryujinx.HLE/Input/Controller/Types/BatteryState.cs b/Ryujinx.HLE/Input/Controller/Types/BatteryState.cs new file mode 100644 index 00000000..4279d7a0 --- /dev/null +++ b/Ryujinx.HLE/Input/Controller/Types/BatteryState.cs @@ -0,0 +1,12 @@ +namespace Ryujinx.HLE.Input +{ + public enum BatteryState : int + { + // TODO : Check if these are the correct states + Percent0 = 0, + Percent25 = 1, + Percent50 = 2, + Percent75 = 3, + Percent100 = 4 + } +} diff --git a/Ryujinx.HLE/Input/Controller/Types/ControllerButtons.cs b/Ryujinx.HLE/Input/Controller/Types/ControllerButtons.cs new file mode 100644 index 00000000..879257f2 --- /dev/null +++ b/Ryujinx.HLE/Input/Controller/Types/ControllerButtons.cs @@ -0,0 +1,35 @@ +using System; + +namespace Ryujinx.HLE.Input +{ + [Flags] + public enum ControllerButtons : long + { + A = 1 << 0, + B = 1 << 1, + X = 1 << 2, + Y = 1 << 3, + StickLeft = 1 << 4, + StickRight = 1 << 5, + L = 1 << 6, + R = 1 << 7, + Zl = 1 << 8, + Zr = 1 << 9, + Plus = 1 << 10, + Minus = 1 << 11, + DpadLeft = 1 << 12, + DpadUp = 1 << 13, + DPadRight = 1 << 14, + DpadDown = 1 << 15, + LStickLeft = 1 << 16, + LStickUp = 1 << 17, + LStickRight = 1 << 18, + LStickDown = 1 << 19, + RStickLeft = 1 << 20, + RStickUp = 1 << 21, + RStickRight = 1 << 22, + RStickDown = 1 << 23, + Sl = 1 << 24, + Sr = 1 << 25 + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/Input/Controller/Types/ControllerColorDescription.cs b/Ryujinx.HLE/Input/Controller/Types/ControllerColorDescription.cs new file mode 100644 index 00000000..c31f41a3 --- /dev/null +++ b/Ryujinx.HLE/Input/Controller/Types/ControllerColorDescription.cs @@ -0,0 +1,10 @@ +using System; + +namespace Ryujinx.HLE.Input +{ + [Flags] + public enum ControllerColorDescription : int + { + ColorDescriptionColorsNonexistent = (1 << 1) + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/Input/Controller/Types/ControllerConnectionState.cs b/Ryujinx.HLE/Input/Controller/Types/ControllerConnectionState.cs new file mode 100644 index 00000000..526da1ff --- /dev/null +++ b/Ryujinx.HLE/Input/Controller/Types/ControllerConnectionState.cs @@ -0,0 +1,11 @@ +using System; + +namespace Ryujinx.HLE.Input +{ + [Flags] + public enum ControllerConnectionState : long + { + ControllerStateConnected = (1 << 0), + ControllerStateWired = (1 << 1) + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/Input/Controller/Types/ControllerDeviceState.cs b/Ryujinx.HLE/Input/Controller/Types/ControllerDeviceState.cs new file mode 100644 index 00000000..45895a1e --- /dev/null +++ b/Ryujinx.HLE/Input/Controller/Types/ControllerDeviceState.cs @@ -0,0 +1,18 @@ +using System.Runtime.InteropServices; + +namespace Ryujinx.HLE.Input +{ + [StructLayout(LayoutKind.Sequential)] + public unsafe struct ControllerDeviceState + { + public ControllerDeviceType DeviceType; + public int Padding; + public DeviceFlags DeviceFlags; + public int UnintendedHomeButtonInputProtectionEnabled; + public BatteryState PowerInfo0BatteryState; + public BatteryState PowerInfo1BatteryState; + public BatteryState PowerInfo2BatteryState; + public fixed byte ControllerMac[16]; + public fixed byte ControllerMac2[16]; + } +} diff --git a/Ryujinx.HLE/Input/Controller/Types/ControllerDeviceType.cs b/Ryujinx.HLE/Input/Controller/Types/ControllerDeviceType.cs new file mode 100644 index 00000000..8043d8a0 --- /dev/null +++ b/Ryujinx.HLE/Input/Controller/Types/ControllerDeviceType.cs @@ -0,0 +1,12 @@ +using System; + +namespace Ryujinx.HLE.Input +{ + [Flags] + public enum ControllerDeviceType : int + { + ProController = 1 << 0, + NPadLeftController = 1 << 4, + NPadRightController = 1 << 5, + } +} diff --git a/Ryujinx.HLE/Input/Controller/Types/ControllerHeader.cs b/Ryujinx.HLE/Input/Controller/Types/ControllerHeader.cs new file mode 100644 index 00000000..cbb5b6f5 --- /dev/null +++ b/Ryujinx.HLE/Input/Controller/Types/ControllerHeader.cs @@ -0,0 +1,19 @@ +using System.Runtime.InteropServices; + +namespace Ryujinx.HLE.Input +{ + [StructLayout(LayoutKind.Sequential)] + public struct ControllerHeader + { + public ControllerStatus Status; + public int IsJoyConHalf; + public ControllerColorDescription SingleColorDescription; + public NpadColor SingleBodyColor; + public NpadColor SingleButtonColor; + public ControllerColorDescription SplitColorDescription; + public NpadColor RightBodyColor; + public NpadColor RightButtonColor; + public NpadColor LeftBodyColor; + public NpadColor LeftButtonColor; + } +} diff --git a/Ryujinx.HLE/Input/Controller/Types/ControllerId.cs b/Ryujinx.HLE/Input/Controller/Types/ControllerId.cs new file mode 100644 index 00000000..c82056c6 --- /dev/null +++ b/Ryujinx.HLE/Input/Controller/Types/ControllerId.cs @@ -0,0 +1,16 @@ +namespace Ryujinx.HLE.Input +{ + public enum ControllerId + { + ControllerPlayer1 = 0, + ControllerPlayer2 = 1, + ControllerPlayer3 = 2, + ControllerPlayer4 = 3, + ControllerPlayer5 = 4, + ControllerPlayer6 = 5, + ControllerPlayer7 = 6, + ControllerPlayer8 = 7, + ControllerHandheld = 8, + ControllerUnknown = 9 + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/Input/Controller/Types/ControllerLayouts.cs b/Ryujinx.HLE/Input/Controller/Types/ControllerLayouts.cs new file mode 100644 index 00000000..fedc0399 --- /dev/null +++ b/Ryujinx.HLE/Input/Controller/Types/ControllerLayouts.cs @@ -0,0 +1,13 @@ +namespace Ryujinx.HLE.Input +{ + public enum ControllerLayouts + { + ProController = 0, + HandheldJoined = 1, + Joined = 2, + Left = 3, + Right = 4, + MainNoAnalog = 5, + Main = 6 + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/Input/Controller/Types/ControllerState.cs b/Ryujinx.HLE/Input/Controller/Types/ControllerState.cs new file mode 100644 index 00000000..4847438d --- /dev/null +++ b/Ryujinx.HLE/Input/Controller/Types/ControllerState.cs @@ -0,0 +1,15 @@ +using System.Runtime.InteropServices; + +namespace Ryujinx.HLE.Input +{ + [StructLayout(LayoutKind.Sequential)] + public struct ControllerState + { + public long SamplesTimestamp; + public long SamplesTimestamp2; + public ControllerButtons ButtonState; + public JoystickPosition LeftStick; + public JoystickPosition RightStick; + public ControllerConnectionState ConnectionState; + } +} diff --git a/Ryujinx.HLE/Input/Controller/Types/ControllerStateHeader.cs b/Ryujinx.HLE/Input/Controller/Types/ControllerStateHeader.cs new file mode 100644 index 00000000..f885c00c --- /dev/null +++ b/Ryujinx.HLE/Input/Controller/Types/ControllerStateHeader.cs @@ -0,0 +1,13 @@ +using System.Runtime.InteropServices; + +namespace Ryujinx.HLE.Input +{ + [StructLayout(LayoutKind.Sequential)] + public struct ControllerStateHeader + { + public long Timestamp; + public long EntryCount; + public long CurrentEntryIndex; + public long MaxEntryCount; + } +} diff --git a/Ryujinx.HLE/Input/Controller/Types/ControllerStatus.cs b/Ryujinx.HLE/Input/Controller/Types/ControllerStatus.cs new file mode 100644 index 00000000..9444d7b0 --- /dev/null +++ b/Ryujinx.HLE/Input/Controller/Types/ControllerStatus.cs @@ -0,0 +1,14 @@ +using System; + +namespace Ryujinx.HLE.Input +{ + [Flags] + public enum ControllerStatus : int + { + ProController = 1 << 0, + Handheld = 1 << 1, + NpadPair = 1 << 2, + NpadLeft = 1 << 3, + NpadRight = 1 << 4 + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/Input/Controller/Types/DeviceFlags.cs b/Ryujinx.HLE/Input/Controller/Types/DeviceFlags.cs new file mode 100644 index 00000000..53913175 --- /dev/null +++ b/Ryujinx.HLE/Input/Controller/Types/DeviceFlags.cs @@ -0,0 +1,22 @@ +using System; + +namespace Ryujinx.HLE.Input +{ + [Flags] + public enum DeviceFlags : long + { + PowerInfo0Charging = 1 << 0, + PowerInfo1Charging = 1 << 1, + PowerInfo2Charging = 1 << 2, + PowerInfo0Connected = 1 << 3, + PowerInfo1Connected = 1 << 4, + PowerInfo2Connected = 1 << 5, + UnsupportedButtonPressedNpadSystem = 1 << 9, + UnsupportedButtonPressedNpadSystemExt = 1 << 10, + AbxyButtonOriented = 1 << 11, + SlSrButtonOriented = 1 << 12, + PlusButtonCapability = 1 << 13, + MinusButtonCapability = 1 << 14, + DirectionalButtonsSupported = 1 << 15 + } +} diff --git a/Ryujinx.HLE/Input/Controller/Types/HotkeyButtons.cs b/Ryujinx.HLE/Input/Controller/Types/HotkeyButtons.cs new file mode 100644 index 00000000..be76ee1e --- /dev/null +++ b/Ryujinx.HLE/Input/Controller/Types/HotkeyButtons.cs @@ -0,0 +1,10 @@ +using System; + +namespace Ryujinx.HLE.Input +{ + [Flags] + public enum HotkeyButtons + { + ToggleVSync = 1 << 0, + } +} diff --git a/Ryujinx.HLE/Input/Controller/Types/JoystickPosition.cs b/Ryujinx.HLE/Input/Controller/Types/JoystickPosition.cs new file mode 100644 index 00000000..1442bc60 --- /dev/null +++ b/Ryujinx.HLE/Input/Controller/Types/JoystickPosition.cs @@ -0,0 +1,8 @@ +namespace Ryujinx.HLE.Input +{ + public struct JoystickPosition + { + public int Dx; + public int Dy; + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/Input/Controller/Types/NpadColor.cs b/Ryujinx.HLE/Input/Controller/Types/NpadColor.cs new file mode 100644 index 00000000..a60f94aa --- /dev/null +++ b/Ryujinx.HLE/Input/Controller/Types/NpadColor.cs @@ -0,0 +1,23 @@ +namespace Ryujinx.HLE.Input +{ + public enum NpadColor : int //Thanks to CTCaer + { + Black = 0, + + BodyGrey = 0x828282, + BodyNeonBlue = 0x0AB9E6, + BodyNeonRed = 0xFF3C28, + BodyNeonYellow = 0xE6FF00, + BodyNeonPink = 0xFF3278, + BodyNeonGreen = 0x1EDC00, + BodyRed = 0xE10F00, + + ButtonsGrey = 0x0F0F0F, + ButtonsNeonBlue = 0x001E1E, + ButtonsNeonRed = 0x1E0A0A, + ButtonsNeonYellow = 0x142800, + ButtonsNeonPink = 0x28001E, + ButtonsNeonGreen = 0x002800, + ButtonsRed = 0x280A0A + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/Input/Hid.cs b/Ryujinx.HLE/Input/Hid.cs index c42f3b6c..27e6a308 100644 --- a/Ryujinx.HLE/Input/Hid.cs +++ b/Ryujinx.HLE/Input/Hid.cs @@ -7,7 +7,15 @@ namespace Ryujinx.HLE.Input { private Switch _device; - public HidControllerBase PrimaryController { get; private set; } + private long _touchScreenOffset; + private long _touchEntriesOffset; + private long _keyboardOffset; + + private TouchHeader _currentTouchHeader; + private KeyboardHeader _currentKeyboardHeader; + private KeyboardEntry _currentKeyboardEntry; + + public BaseController PrimaryController { get; private set; } internal long HidPosition; @@ -17,22 +25,42 @@ namespace Ryujinx.HLE.Input HidPosition = hidPosition; device.Memory.FillWithZeros(hidPosition, Horizon.HidSize); + + _currentTouchHeader = new TouchHeader() + { + CurrentEntryIndex = -1, + }; + + _currentKeyboardHeader = new KeyboardHeader() + { + CurrentEntryIndex = -1, + }; + + _currentKeyboardEntry = new KeyboardEntry() + { + SamplesTimestamp = -1, + SamplesTimestamp2 = -1 + }; + + _touchScreenOffset = HidPosition + HidTouchScreenOffset; + _touchEntriesOffset = _touchScreenOffset + HidTouchHeaderSize; + _keyboardOffset = HidPosition + HidKeyboardOffset; } - public void InitializePrimaryController(HidControllerType controllerType) + public void InitializePrimaryController(ControllerStatus controllerType) { - HidControllerId controllerId = controllerType == HidControllerType.Handheld ? - HidControllerId.ControllerHandheld : HidControllerId.ControllerPlayer1; + ControllerId controllerId = controllerType == ControllerStatus.Handheld ? + ControllerId.ControllerHandheld : ControllerId.ControllerPlayer1; - if (controllerType == HidControllerType.ProController) + if (controllerType == ControllerStatus.ProController) { - PrimaryController = new HidProController(_device); + PrimaryController = new ProController(_device, NpadColor.Black, NpadColor.Black); } else { - PrimaryController = new HidNpadController(controllerType, + PrimaryController = new NpadController(controllerType, _device, - (NpadColor.BodyNeonRed, NpadColor.BodyNeonRed), + (NpadColor.BodyNeonRed, NpadColor.BodyNeonRed), (NpadColor.ButtonsNeonBlue, NpadColor.ButtonsNeonBlue)); } @@ -44,124 +72,132 @@ namespace Ryujinx.HLE.Input _device.Memory.FillWithZeros(HidPosition + HidKeyboardOffset, HidKeyboardSize); } - public HidControllerButtons UpdateStickButtons( - HidJoystickPosition leftStick, - HidJoystickPosition rightStick) + public ControllerButtons UpdateStickButtons( + JoystickPosition leftStick, + JoystickPosition rightStick) { - HidControllerButtons result = 0; + ControllerButtons result = 0; if (rightStick.Dx < 0) { - result |= HidControllerButtons.RStickLeft; + result |= ControllerButtons.RStickLeft; } if (rightStick.Dx > 0) { - result |= HidControllerButtons.RStickRight; + result |= ControllerButtons.RStickRight; } if (rightStick.Dy < 0) { - result |= HidControllerButtons.RStickDown; + result |= ControllerButtons.RStickDown; } if (rightStick.Dy > 0) { - result |= HidControllerButtons.RStickUp; + result |= ControllerButtons.RStickUp; } if (leftStick.Dx < 0) { - result |= HidControllerButtons.LStickLeft; + result |= ControllerButtons.LStickLeft; } if (leftStick.Dx > 0) { - result |= HidControllerButtons.LStickRight; + result |= ControllerButtons.LStickRight; } if (leftStick.Dy < 0) { - result |= HidControllerButtons.LStickDown; + result |= ControllerButtons.LStickDown; } if (leftStick.Dy > 0) { - result |= HidControllerButtons.LStickUp; + result |= ControllerButtons.LStickUp; } return result; } - - public void SetTouchPoints(params HidTouchPoint[] points) + public void SetTouchPoints(params TouchPoint[] points) { - long touchScreenOffset = HidPosition + HidTouchScreenOffset; - long lastEntry = _device.Memory.ReadInt64(touchScreenOffset + 0x10); - long currEntry = (lastEntry + 1) % HidEntryCount; - long timestamp = GetTimestamp(); - - _device.Memory.WriteInt64(touchScreenOffset + 0x00, timestamp); - _device.Memory.WriteInt64(touchScreenOffset + 0x08, HidEntryCount); - _device.Memory.WriteInt64(touchScreenOffset + 0x10, currEntry); - _device.Memory.WriteInt64(touchScreenOffset + 0x18, HidEntryCount - 1); - _device.Memory.WriteInt64(touchScreenOffset + 0x20, timestamp); + long timestamp = GetTimestamp(); + long sampleCounter = _currentTouchHeader.SamplesTimestamp + 1; - long touchEntryOffset = touchScreenOffset + HidTouchHeaderSize; - long lastEntryOffset = touchEntryOffset + lastEntry * HidTouchEntrySize; - long sampleCounter = _device.Memory.ReadInt64(lastEntryOffset) + 1; - - touchEntryOffset += currEntry * HidTouchEntrySize; + var newTouchHeader = new TouchHeader + { + CurrentEntryIndex = (_currentTouchHeader.CurrentEntryIndex + 1) % HidEntryCount, + EntryCount = HidEntryCount, + MaxEntries = HidEntryCount - 1, + SamplesTimestamp = sampleCounter, + Timestamp = timestamp, + }; - _device.Memory.WriteInt64(touchEntryOffset + 0x00, sampleCounter); - _device.Memory.WriteInt64(touchEntryOffset + 0x08, points.Length); + long currentTouchEntryOffset = _touchEntriesOffset + newTouchHeader.CurrentEntryIndex * HidTouchEntrySize; - touchEntryOffset += HidTouchEntryHeaderSize; + TouchEntry touchEntry = new TouchEntry() + { + SamplesTimestamp = sampleCounter, + TouchCount = points.Length + }; - const int padding = 0; + _device.Memory.WriteStruct(currentTouchEntryOffset, touchEntry); - int index = 0; + currentTouchEntryOffset += HidTouchEntryHeaderSize; - foreach (HidTouchPoint point in points) + for (int i = 0; i < points.Length; i++) { - _device.Memory.WriteInt64(touchEntryOffset + 0x00, sampleCounter); - _device.Memory.WriteInt32(touchEntryOffset + 0x08, padding); - _device.Memory.WriteInt32(touchEntryOffset + 0x0c, index++); - _device.Memory.WriteInt32(touchEntryOffset + 0x10, point.X); - _device.Memory.WriteInt32(touchEntryOffset + 0x14, point.Y); - _device.Memory.WriteInt32(touchEntryOffset + 0x18, point.DiameterX); - _device.Memory.WriteInt32(touchEntryOffset + 0x1c, point.DiameterY); - _device.Memory.WriteInt32(touchEntryOffset + 0x20, point.Angle); - _device.Memory.WriteInt32(touchEntryOffset + 0x24, padding); - - touchEntryOffset += HidTouchEntryTouchSize; + TouchData touch = new TouchData() + { + Angle = points[i].Angle, + DiameterX = points[i].DiameterX, + DiameterY = points[i].DiameterY, + Index = i, + SampleTimestamp = sampleCounter, + X = points[i].X, + Y = points[i].Y + }; + + _device.Memory.WriteStruct(currentTouchEntryOffset, touch); + + currentTouchEntryOffset += HidTouchEntryTouchSize; } + + _device.Memory.WriteStruct(_touchScreenOffset, newTouchHeader); + + _currentTouchHeader = newTouchHeader; } - public void WriteKeyboard(HidKeyboard keyboard) + public unsafe void WriteKeyboard(Keyboard keyboard) { - long keyboardOffset = HidPosition + HidKeyboardOffset; - long lastEntry = _device.Memory.ReadInt64(keyboardOffset + 0x10); - long currEntry = (lastEntry + 1) % HidEntryCount; - long timestamp = GetTimestamp(); + long timestamp = GetTimestamp(); - _device.Memory.WriteInt64(keyboardOffset + 0x00, timestamp); - _device.Memory.WriteInt64(keyboardOffset + 0x08, HidEntryCount); - _device.Memory.WriteInt64(keyboardOffset + 0x10, currEntry); - _device.Memory.WriteInt64(keyboardOffset + 0x18, HidEntryCount - 1); + var newKeyboardHeader = new KeyboardHeader() + { + CurrentEntryIndex = (_currentKeyboardHeader.CurrentEntryIndex + 1) % HidEntryCount, + EntryCount = HidEntryCount, + MaxEntries = HidEntryCount - 1, + Timestamp = timestamp, + }; - long keyboardEntryOffset = keyboardOffset + HidKeyboardHeaderSize; - long lastEntryOffset = keyboardEntryOffset + lastEntry * HidKeyboardEntrySize; - long sampleCounter = _device.Memory.ReadInt64(lastEntryOffset); + _device.Memory.WriteStruct(_keyboardOffset, newKeyboardHeader); - keyboardEntryOffset += currEntry * HidKeyboardEntrySize; - _device.Memory.WriteInt64(keyboardEntryOffset + 0x00, sampleCounter + 1); - _device.Memory.WriteInt64(keyboardEntryOffset + 0x08, sampleCounter); - _device.Memory.WriteInt64(keyboardEntryOffset + 0x10, keyboard.Modifier); + long keyboardEntryOffset = _keyboardOffset + HidKeyboardHeaderSize; + keyboardEntryOffset += newKeyboardHeader.CurrentEntryIndex * HidKeyboardEntrySize; - for (int i = 0; i < keyboard.Keys.Length; i++) + var newkeyboardEntry = new KeyboardEntry() { - _device.Memory.WriteInt32(keyboardEntryOffset + 0x18 + (i * 4), keyboard.Keys[i]); - } + SamplesTimestamp = _currentKeyboardEntry.SamplesTimestamp + 1, + SamplesTimestamp2 = _currentKeyboardEntry.SamplesTimestamp2 + 1, + Keys = keyboard.Keys, + Modifier = keyboard.Modifier, + }; + + _device.Memory.WriteStruct(keyboardEntryOffset, newkeyboardEntry); + + _currentKeyboardEntry = newkeyboardEntry; + _currentKeyboardHeader = newKeyboardHeader; } internal static long GetTimestamp() diff --git a/Ryujinx.HLE/Input/HidBaseController.cs b/Ryujinx.HLE/Input/HidBaseController.cs deleted file mode 100644 index 8b29d891..00000000 --- a/Ryujinx.HLE/Input/HidBaseController.cs +++ /dev/null @@ -1,76 +0,0 @@ -using static Ryujinx.HLE.Input.Hid; - -namespace Ryujinx.HLE.Input -{ - public abstract class HidControllerBase : IHidDevice - { - protected HidControllerType HidControllerType; - protected Switch Device; - protected HidControllerId ControllerId; - - public long Offset { get; private set; } - public bool Connected { get; protected set; } - - public HidControllerBase(HidControllerType controllerType, Switch device) - { - Device = device; - - HidControllerType = controllerType; - } - - public virtual void Connect(HidControllerId controllerId) - { - ControllerId = controllerId; - - Offset = Device.Hid.HidPosition + HidControllersOffset + (int)controllerId * HidControllerSize; - - Device.Memory.FillWithZeros(Offset, 0x5000); - - Device.Memory.WriteInt32(Offset + 0x00, (int)HidControllerType); - } - - public abstract void SendInput( - HidControllerButtons buttons, - HidJoystickPosition leftStick, - HidJoystickPosition rightStick); - - protected long WriteInput( - HidControllerButtons buttons, - HidJoystickPosition leftStick, - HidJoystickPosition rightStick, - HidControllerLayouts controllerLayout) - { - long controllerOffset = Offset + HidControllerHeaderSize; - - controllerOffset += (int)controllerLayout * HidControllerLayoutsSize; - - long lastEntry = Device.Memory.ReadInt64(controllerOffset + 0x10); - long currEntry = (lastEntry + 1) % HidEntryCount; - long timestamp = GetTimestamp(); - - Device.Memory.WriteInt64(controllerOffset + 0x00, timestamp); - Device.Memory.WriteInt64(controllerOffset + 0x08, HidEntryCount); - Device.Memory.WriteInt64(controllerOffset + 0x10, currEntry); - Device.Memory.WriteInt64(controllerOffset + 0x18, HidEntryCount - 1); - - controllerOffset += HidControllersLayoutHeaderSize; - - long lastEntryOffset = controllerOffset + lastEntry * HidControllersInputEntrySize; - - controllerOffset += currEntry * HidControllersInputEntrySize; - - long sampleCounter = Device.Memory.ReadInt64(lastEntryOffset) + 1; - - Device.Memory.WriteInt64(controllerOffset + 0x00, sampleCounter); - Device.Memory.WriteInt64(controllerOffset + 0x08, sampleCounter); - Device.Memory.WriteInt64(controllerOffset + 0x10, (uint)buttons); - - Device.Memory.WriteInt32(controllerOffset + 0x18, leftStick.Dx); - Device.Memory.WriteInt32(controllerOffset + 0x1c, leftStick.Dy); - Device.Memory.WriteInt32(controllerOffset + 0x20, rightStick.Dx); - Device.Memory.WriteInt32(controllerOffset + 0x24, rightStick.Dy); - - return controllerOffset; - } - } -} diff --git a/Ryujinx.HLE/Input/HidControllerButtons.cs b/Ryujinx.HLE/Input/HidControllerButtons.cs deleted file mode 100644 index 07a3a118..00000000 --- a/Ryujinx.HLE/Input/HidControllerButtons.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; - -namespace Ryujinx.HLE.Input -{ - [Flags] - public enum HidControllerButtons - { - A = 1 << 0, - B = 1 << 1, - X = 1 << 2, - Y = 1 << 3, - StickLeft = 1 << 4, - StickRight = 1 << 5, - L = 1 << 6, - R = 1 << 7, - Zl = 1 << 8, - Zr = 1 << 9, - Plus = 1 << 10, - Minus = 1 << 11, - DpadLeft = 1 << 12, - DpadUp = 1 << 13, - DPadRight = 1 << 14, - DpadDown = 1 << 15, - LStickLeft = 1 << 16, - LStickUp = 1 << 17, - LStickRight = 1 << 18, - LStickDown = 1 << 19, - RStickLeft = 1 << 20, - RStickUp = 1 << 21, - RStickRight = 1 << 22, - RStickDown = 1 << 23, - Sl = 1 << 24, - Sr = 1 << 25 - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Input/HidControllerColorDesc.cs b/Ryujinx.HLE/Input/HidControllerColorDesc.cs deleted file mode 100644 index 85ece5f1..00000000 --- a/Ryujinx.HLE/Input/HidControllerColorDesc.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; - -namespace Ryujinx.HLE.Input -{ - [Flags] - public enum HidControllerColorDesc - { - ColorDescColorsNonexistent = (1 << 1) - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Input/HidControllerConnState.cs b/Ryujinx.HLE/Input/HidControllerConnState.cs deleted file mode 100644 index ef41cbb8..00000000 --- a/Ryujinx.HLE/Input/HidControllerConnState.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace Ryujinx.HLE.Input -{ - [Flags] - public enum HidControllerConnState - { - ControllerStateConnected = (1 << 0), - ControllerStateWired = (1 << 1) - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Input/HidControllerId.cs b/Ryujinx.HLE/Input/HidControllerId.cs deleted file mode 100644 index 60faf822..00000000 --- a/Ryujinx.HLE/Input/HidControllerId.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace Ryujinx.HLE.Input -{ - public enum HidControllerId - { - ControllerPlayer1 = 0, - ControllerPlayer2 = 1, - ControllerPlayer3 = 2, - ControllerPlayer4 = 3, - ControllerPlayer5 = 4, - ControllerPlayer6 = 5, - ControllerPlayer7 = 6, - ControllerPlayer8 = 7, - ControllerHandheld = 8, - ControllerUnknown = 9 - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Input/HidControllerLayouts.cs b/Ryujinx.HLE/Input/HidControllerLayouts.cs deleted file mode 100644 index 3548175f..00000000 --- a/Ryujinx.HLE/Input/HidControllerLayouts.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Ryujinx.HLE.Input -{ - public enum HidControllerLayouts - { - ProController = 0, - HandheldJoined = 1, - Joined = 2, - Left = 3, - Right = 4, - MainNoAnalog = 5, - Main = 6 - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Input/HidControllerType.cs b/Ryujinx.HLE/Input/HidControllerType.cs deleted file mode 100644 index 74bca365..00000000 --- a/Ryujinx.HLE/Input/HidControllerType.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace Ryujinx.HLE.Input -{ - [Flags] - public enum HidControllerType - { - ProController = 1 << 0, - Handheld = 1 << 1, - NpadPair = 1 << 2, - NpadLeft = 1 << 3, - NpadRight = 1 << 4 - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Input/HidHotkeyButtons.cs b/Ryujinx.HLE/Input/HidHotkeyButtons.cs deleted file mode 100644 index 7fa6ed6d..00000000 --- a/Ryujinx.HLE/Input/HidHotkeyButtons.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; - -namespace Ryujinx.HLE.Input -{ - [Flags] - public enum HidHotkeyButtons - { - ToggleVSync = 1 << 0, - } -} diff --git a/Ryujinx.HLE/Input/HidJoystickPosition.cs b/Ryujinx.HLE/Input/HidJoystickPosition.cs deleted file mode 100644 index a1fe1608..00000000 --- a/Ryujinx.HLE/Input/HidJoystickPosition.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Ryujinx.HLE.Input -{ - public struct HidJoystickPosition - { - public int Dx; - public int Dy; - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Input/HidKeyboard.cs b/Ryujinx.HLE/Input/HidKeyboard.cs deleted file mode 100644 index a5b042a5..00000000 --- a/Ryujinx.HLE/Input/HidKeyboard.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Ryujinx.HLE.Input -{ - public struct HidKeyboard - { - public int Modifier; - public int[] Keys; - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Input/HidNpadController.cs b/Ryujinx.HLE/Input/HidNpadController.cs deleted file mode 100644 index 0c773e86..00000000 --- a/Ryujinx.HLE/Input/HidNpadController.cs +++ /dev/null @@ -1,92 +0,0 @@ -namespace Ryujinx.HLE.Input -{ - public class HidNpadController : HidControllerBase - { - private (NpadColor Left, NpadColor Right) _npadBodyColors; - private (NpadColor Left, NpadColor Right) _npadButtonColors; - - private HidControllerLayouts _currentLayout; - - private bool _isHalf; - - public HidNpadController( - HidControllerType controllerType, - Switch device, - (NpadColor, NpadColor) npadBodyColors, - (NpadColor, NpadColor) npadButtonColors) : base(controllerType, device) - { - _npadBodyColors = npadBodyColors; - _npadButtonColors = npadButtonColors; - - _currentLayout = HidControllerLayouts.HandheldJoined; - - switch (controllerType) - { - case HidControllerType.NpadLeft: - _currentLayout = HidControllerLayouts.Left; - break; - case HidControllerType.NpadRight: - _currentLayout = HidControllerLayouts.Right; - break; - case HidControllerType.NpadPair: - _currentLayout = HidControllerLayouts.Joined; - break; - } - } - - public override void Connect(HidControllerId controllerId) - { - if (HidControllerType != HidControllerType.NpadLeft && HidControllerType != HidControllerType.NpadRight) - { - _isHalf = false; - } - - base.Connect(_currentLayout == HidControllerLayouts.HandheldJoined ? HidControllerId.ControllerHandheld : controllerId); - - HidControllerColorDesc singleColorDesc = - HidControllerColorDesc.ColorDescColorsNonexistent; - - HidControllerColorDesc splitColorDesc = 0; - - NpadColor singleColorBody = NpadColor.Black; - NpadColor singleColorButtons = NpadColor.Black; - - Device.Memory.WriteInt32(Offset + 0x04, _isHalf ? 1 : 0); - - if (_isHalf) - { - Device.Memory.WriteInt32(Offset + 0x08, (int)singleColorDesc); - Device.Memory.WriteInt32(Offset + 0x0c, (int)singleColorBody); - Device.Memory.WriteInt32(Offset + 0x10, (int)singleColorButtons); - Device.Memory.WriteInt32(Offset + 0x14, (int)splitColorDesc); - } - else - { - Device.Memory.WriteInt32(Offset + 0x18, (int)_npadBodyColors.Left); - Device.Memory.WriteInt32(Offset + 0x1c, (int)_npadButtonColors.Left); - Device.Memory.WriteInt32(Offset + 0x20, (int)_npadBodyColors.Right); - Device.Memory.WriteInt32(Offset + 0x24, (int)_npadButtonColors.Right); - } - - Connected = true; - } - - public override void SendInput - (HidControllerButtons buttons, - HidJoystickPosition leftStick, - HidJoystickPosition rightStick) - { - long controllerOffset = WriteInput(buttons, leftStick, rightStick, _currentLayout); - - Device.Memory.WriteInt64(controllerOffset + 0x28, - (Connected ? (uint)HidControllerConnState.ControllerStateConnected : 0) | - (_currentLayout == HidControllerLayouts.HandheldJoined ? (uint)HidControllerConnState.ControllerStateWired : 0)); - - controllerOffset = WriteInput(buttons, leftStick, rightStick, HidControllerLayouts.Main); - - Device.Memory.WriteInt64(controllerOffset + 0x28, - (Connected ? (uint)HidControllerConnState.ControllerStateWired : 0) | - (uint)HidControllerConnState.ControllerStateWired); - } - } -} diff --git a/Ryujinx.HLE/Input/HidProController.cs b/Ryujinx.HLE/Input/HidProController.cs deleted file mode 100644 index e30e9172..00000000 --- a/Ryujinx.HLE/Input/HidProController.cs +++ /dev/null @@ -1,50 +0,0 @@ -namespace Ryujinx.HLE.Input -{ - public class HidProController : HidControllerBase - { - bool _wired = false; - - public HidProController(Switch device) : base(HidControllerType.ProController, device) - { - _wired = true; - } - - public override void Connect(HidControllerId controllerId) - { - base.Connect(controllerId); - - HidControllerColorDesc singleColorDesc = - HidControllerColorDesc.ColorDescColorsNonexistent; - - HidControllerColorDesc splitColorDesc = 0; - - NpadColor singleColorBody = NpadColor.Black; - NpadColor singleColorButtons = NpadColor.Black; - - Device.Memory.WriteInt32(Offset + 0x08, (int)singleColorDesc); - Device.Memory.WriteInt32(Offset + 0x0c, (int)singleColorBody); - Device.Memory.WriteInt32(Offset + 0x10, (int)singleColorButtons); - Device.Memory.WriteInt32(Offset + 0x14, (int)splitColorDesc); - - Connected = true; - } - - public override void SendInput( - HidControllerButtons buttons, - HidJoystickPosition leftStick, - HidJoystickPosition rightStick) - { - long controllerOffset = WriteInput(buttons, leftStick, rightStick, HidControllerLayouts.ProController); - - Device.Memory.WriteInt64(controllerOffset + 0x28, - (Connected ? (uint)HidControllerConnState.ControllerStateConnected : 0) | - (_wired ? (uint)HidControllerConnState.ControllerStateWired : 0)); - - controllerOffset = WriteInput(buttons, leftStick, rightStick, HidControllerLayouts.Main); - - Device.Memory.WriteInt64(controllerOffset + 0x28, - (Connected ? (uint)HidControllerConnState.ControllerStateWired : 0) | - (uint)HidControllerConnState.ControllerStateWired); - } - } -} diff --git a/Ryujinx.HLE/Input/HidTouchPoint.cs b/Ryujinx.HLE/Input/HidTouchPoint.cs deleted file mode 100644 index 25412456..00000000 --- a/Ryujinx.HLE/Input/HidTouchPoint.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Ryujinx.HLE.Input -{ - public struct HidTouchPoint - { - public int X; - public int Y; - public int DiameterX; - public int DiameterY; - public int Angle; - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Input/Keyboard/Keyboard.cs b/Ryujinx.HLE/Input/Keyboard/Keyboard.cs new file mode 100644 index 00000000..7220e518 --- /dev/null +++ b/Ryujinx.HLE/Input/Keyboard/Keyboard.cs @@ -0,0 +1,8 @@ +namespace Ryujinx.HLE.Input +{ + public struct Keyboard + { + public int Modifier; + public int[] Keys; + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/Input/Keyboard/KeyboardEntry.cs b/Ryujinx.HLE/Input/Keyboard/KeyboardEntry.cs new file mode 100644 index 00000000..be7d9399 --- /dev/null +++ b/Ryujinx.HLE/Input/Keyboard/KeyboardEntry.cs @@ -0,0 +1,15 @@ +using System.Runtime.InteropServices; + +namespace Ryujinx.HLE.Input +{ + [StructLayout(LayoutKind.Sequential)] + public struct KeyboardEntry + { + public long SamplesTimestamp; + public long SamplesTimestamp2; + public long Modifier; + + [MarshalAs(UnmanagedType.ByValArray , SizeConst = 0x8)] + public int[] Keys; + } +} diff --git a/Ryujinx.HLE/Input/Keyboard/KeyboardHeader.cs b/Ryujinx.HLE/Input/Keyboard/KeyboardHeader.cs new file mode 100644 index 00000000..882ccbab --- /dev/null +++ b/Ryujinx.HLE/Input/Keyboard/KeyboardHeader.cs @@ -0,0 +1,13 @@ +using System.Runtime.InteropServices; + +namespace Ryujinx.HLE.Input +{ + [StructLayout(LayoutKind.Sequential)] + public struct KeyboardHeader + { + public long Timestamp; + public long EntryCount; + public long CurrentEntryIndex; + public long MaxEntries; + } +} diff --git a/Ryujinx.HLE/Input/NpadColor.cs b/Ryujinx.HLE/Input/NpadColor.cs deleted file mode 100644 index b15c45d8..00000000 --- a/Ryujinx.HLE/Input/NpadColor.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace Ryujinx.HLE.Input -{ - public enum NpadColor //Thanks to CTCaer - { - Black = 0, - - BodyGrey = 0x828282, - BodyNeonBlue = 0x0AB9E6, - BodyNeonRed = 0xFF3C28, - BodyNeonYellow = 0xE6FF00, - BodyNeonPink = 0xFF3278, - BodyNeonGreen = 0x1EDC00, - BodyRed = 0xE10F00, - - ButtonsGrey = 0x0F0F0F, - ButtonsNeonBlue = 0x001E1E, - ButtonsNeonRed = 0x1E0A0A, - ButtonsNeonYellow = 0x142800, - ButtonsNeonPink = 0x28001E, - ButtonsNeonGreen = 0x002800, - ButtonsRed = 0x280A0A - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Input/Touch/TouchData.cs b/Ryujinx.HLE/Input/Touch/TouchData.cs new file mode 100644 index 00000000..8489ef70 --- /dev/null +++ b/Ryujinx.HLE/Input/Touch/TouchData.cs @@ -0,0 +1,18 @@ +using System.Runtime.InteropServices; + +namespace Ryujinx.HLE.Input +{ + [StructLayout(LayoutKind.Sequential)] + public struct TouchData + { + public long SampleTimestamp; + public int Padding; + public int Index; + public int X; + public int Y; + public int DiameterX; + public int DiameterY; + public int Angle; + public int Padding2; + } +} diff --git a/Ryujinx.HLE/Input/Touch/TouchEntry.cs b/Ryujinx.HLE/Input/Touch/TouchEntry.cs new file mode 100644 index 00000000..2ef09d75 --- /dev/null +++ b/Ryujinx.HLE/Input/Touch/TouchEntry.cs @@ -0,0 +1,11 @@ +using System.Runtime.InteropServices; + +namespace Ryujinx.HLE.Input +{ + [StructLayout(LayoutKind.Sequential)] + public unsafe struct TouchEntry + { + public long SamplesTimestamp; + public long TouchCount; + } +} diff --git a/Ryujinx.HLE/Input/Touch/TouchHeader.cs b/Ryujinx.HLE/Input/Touch/TouchHeader.cs new file mode 100644 index 00000000..dd93137c --- /dev/null +++ b/Ryujinx.HLE/Input/Touch/TouchHeader.cs @@ -0,0 +1,14 @@ +using System.Runtime.InteropServices; + +namespace Ryujinx.HLE.Input +{ + [StructLayout(LayoutKind.Sequential)] + public struct TouchHeader + { + public long Timestamp; + public long EntryCount; + public long CurrentEntryIndex; + public long MaxEntries; + public long SamplesTimestamp; + } +} diff --git a/Ryujinx.HLE/Input/Touch/TouchPoint.cs b/Ryujinx.HLE/Input/Touch/TouchPoint.cs new file mode 100644 index 00000000..a9b095de --- /dev/null +++ b/Ryujinx.HLE/Input/Touch/TouchPoint.cs @@ -0,0 +1,11 @@ +namespace Ryujinx.HLE.Input +{ + public struct TouchPoint + { + public int X; + public int Y; + public int DiameterX; + public int DiameterY; + public int Angle; + } +} \ No newline at end of file -- cgit v1.2.3