2018-11-20 01:01:36 +01:00
|
|
|
|
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; }
|
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
public HidControllerBase(HidControllerType ControllerType, Switch Device)
|
2018-11-20 01:01:36 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
this.Device = Device;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
HidControllerType = ControllerType;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
public virtual void Connect(HidControllerId ControllerId)
|
2018-11-20 01:01:36 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
this.ControllerId = ControllerId;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
Offset = Device.Hid.HidPosition + HidControllersOffset + (int)ControllerId * HidControllerSize;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
|
|
|
|
Device.Memory.FillWithZeros(Offset, 0x5000);
|
|
|
|
|
|
|
|
|
|
Device.Memory.WriteInt32(Offset + 0x00, (int)HidControllerType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract void SendInput(
|
2018-12-05 01:52:39 +01:00
|
|
|
|
HidControllerButtons Buttons,
|
|
|
|
|
HidJoystickPosition LeftStick,
|
|
|
|
|
HidJoystickPosition RightStick);
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
|
|
|
|
protected long WriteInput(
|
2018-12-05 01:52:39 +01:00
|
|
|
|
HidControllerButtons Buttons,
|
|
|
|
|
HidJoystickPosition LeftStick,
|
|
|
|
|
HidJoystickPosition RightStick,
|
|
|
|
|
HidControllerLayouts ControllerLayout)
|
2018-11-20 01:01:36 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
long ControllerOffset = Offset + HidControllerHeaderSize;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
ControllerOffset += (int)ControllerLayout * HidControllerLayoutsSize;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
long LastEntry = Device.Memory.ReadInt64(ControllerOffset + 0x10);
|
|
|
|
|
long CurrEntry = (LastEntry + 1) % HidEntryCount;
|
|
|
|
|
long Timestamp = GetTimestamp();
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
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);
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
ControllerOffset += HidControllersLayoutHeaderSize;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
long LastEntryOffset = ControllerOffset + LastEntry * HidControllersInputEntrySize;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
ControllerOffset += CurrEntry * HidControllersInputEntrySize;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
long SampleCounter = Device.Memory.ReadInt64(LastEntryOffset) + 1;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
Device.Memory.WriteInt64(ControllerOffset + 0x00, SampleCounter);
|
|
|
|
|
Device.Memory.WriteInt64(ControllerOffset + 0x08, SampleCounter);
|
|
|
|
|
Device.Memory.WriteInt64(ControllerOffset + 0x10, (uint)Buttons);
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
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);
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
return ControllerOffset;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|