2018-11-19 19:01:36 -05:00
|
|
|
|
using Ryujinx.Common;
|
|
|
|
|
using Ryujinx.HLE.HOS;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.Input
|
|
|
|
|
{
|
|
|
|
|
public partial class Hid
|
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
private Switch Device;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
|
|
|
|
|
public HidControllerBase PrimaryController { get; private set; }
|
|
|
|
|
|
|
|
|
|
internal long HidPosition;
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
public Hid(Switch Device, long HidPosition)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
this.Device = Device;
|
|
|
|
|
this.HidPosition = HidPosition;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
Device.Memory.FillWithZeros(HidPosition, Horizon.HidSize);
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
public void InitilizePrimaryController(HidControllerType ControllerType)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
HidControllerId ControllerId = ControllerType == HidControllerType.Handheld ?
|
|
|
|
|
HidControllerId.CONTROLLER_HANDHELD : HidControllerId.CONTROLLER_PLAYER_1;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
if (ControllerType == HidControllerType.ProController)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
PrimaryController = new HidProController(Device);
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
PrimaryController = new HidNpadController(ControllerType,
|
|
|
|
|
Device,
|
|
|
|
|
(NpadColor.Body_Neon_Red, NpadColor.Body_Neon_Red),
|
|
|
|
|
(NpadColor.Buttons_Neon_Blue, NpadColor.Buttons_Neon_Blue));
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
PrimaryController.Connect(ControllerId);
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private HidControllerButtons UpdateStickButtons(
|
2018-12-04 19:52:39 -05:00
|
|
|
|
HidJoystickPosition LeftStick,
|
|
|
|
|
HidJoystickPosition RightStick)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
HidControllerButtons Result = 0;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
if (RightStick.DX < 0)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
Result |= HidControllerButtons.RStickLeft;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
if (RightStick.DX > 0)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
Result |= HidControllerButtons.RStickRight;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
if (RightStick.DY < 0)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
Result |= HidControllerButtons.RStickDown;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
if (RightStick.DY > 0)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
Result |= HidControllerButtons.RStickUp;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
if (LeftStick.DX < 0)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
Result |= HidControllerButtons.LStickLeft;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
if (LeftStick.DX > 0)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
Result |= HidControllerButtons.LStickRight;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
if (LeftStick.DY < 0)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
Result |= HidControllerButtons.LStickDown;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
if (LeftStick.DY > 0)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
Result |= HidControllerButtons.LStickUp;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
return Result;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
public void SetTouchPoints(params HidTouchPoint[] Points)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
long TouchScreenOffset = HidPosition + HidTouchScreenOffset;
|
|
|
|
|
long LastEntry = Device.Memory.ReadInt64(TouchScreenOffset + 0x10);
|
|
|
|
|
long CurrEntry = (LastEntry + 1) % HidEntryCount;
|
|
|
|
|
long Timestamp = GetTimestamp();
|
2018-11-19 19:01:36 -05:00
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
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);
|
2018-11-19 19:01:36 -05:00
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
long TouchEntryOffset = TouchScreenOffset + HidTouchHeaderSize;
|
|
|
|
|
long LastEntryOffset = TouchEntryOffset + LastEntry * HidTouchEntrySize;
|
|
|
|
|
long SampleCounter = Device.Memory.ReadInt64(LastEntryOffset) + 1;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
TouchEntryOffset += CurrEntry * HidTouchEntrySize;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
Device.Memory.WriteInt64(TouchEntryOffset + 0x00, SampleCounter);
|
|
|
|
|
Device.Memory.WriteInt64(TouchEntryOffset + 0x08, Points.Length);
|
2018-11-19 19:01:36 -05:00
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
TouchEntryOffset += HidTouchEntryHeaderSize;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
const int Padding = 0;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
int Index = 0;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
|
foreach (HidTouchPoint Point in Points)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
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;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static long GetTimestamp()
|
|
|
|
|
{
|
|
|
|
|
return PerformanceCounter.ElapsedMilliseconds * 19200;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|