aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/Input/HidBaseController.cs
diff options
context:
space:
mode:
authoremmauss <emmausssss@gmail.com>2018-11-20 02:01:36 +0200
committerAc_K <Acoustik666@gmail.com>2018-11-20 01:01:36 +0100
commitdc02ac08caa84456e8b280a3347ac8907b5249ff (patch)
treeef71cf05cba18da65c930328f955352f4859e67f /Ryujinx.HLE/Input/HidBaseController.cs
parent0c36835f6de563cd6b4a4c82cac25fbcfb0a6231 (diff)
Support other switch controller types (#487)
* Make controllers modular, support changing controller type * return readable events * signal hid events * fix style
Diffstat (limited to 'Ryujinx.HLE/Input/HidBaseController.cs')
-rw-r--r--Ryujinx.HLE/Input/HidBaseController.cs76
1 files changed, 76 insertions, 0 deletions
diff --git a/Ryujinx.HLE/Input/HidBaseController.cs b/Ryujinx.HLE/Input/HidBaseController.cs
new file mode 100644
index 00000000..9b9bb7ea
--- /dev/null
+++ b/Ryujinx.HLE/Input/HidBaseController.cs
@@ -0,0 +1,76 @@
+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)
+ {
+ this.Device = Device;
+
+ HidControllerType = ControllerType;
+ }
+
+ public virtual void Connect(HidControllerId ControllerId)
+ {
+ this.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;
+ }
+ }
+}