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-06 06:16:24 -05:00
|
|
|
|
private Switch _device;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
|
|
|
|
|
public HidControllerBase PrimaryController { get; private set; }
|
|
|
|
|
|
|
|
|
|
internal long HidPosition;
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public Hid(Switch device, long hidPosition)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
_device = device;
|
|
|
|
|
HidPosition = hidPosition;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
device.Memory.FillWithZeros(hidPosition, Horizon.HidSize);
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public void InitilizePrimaryController(HidControllerType controllerType)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
HidControllerId controllerId = controllerType == HidControllerType.Handheld ?
|
|
|
|
|
HidControllerId.ControllerHandheld : HidControllerId.ControllerPlayer1;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
if (controllerType == HidControllerType.ProController)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
PrimaryController = new HidProController(_device);
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
PrimaryController = new HidNpadController(controllerType,
|
|
|
|
|
_device,
|
|
|
|
|
(NpadColor.BodyNeonRed, NpadColor.BodyNeonRed),
|
|
|
|
|
(NpadColor.ButtonsNeonBlue, NpadColor.ButtonsNeonBlue));
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
PrimaryController.Connect(controllerId);
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private HidControllerButtons UpdateStickButtons(
|
2018-12-06 06:16:24 -05:00
|
|
|
|
HidJoystickPosition leftStick,
|
|
|
|
|
HidJoystickPosition rightStick)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
HidControllerButtons result = 0;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
if (rightStick.Dx < 0)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
result |= HidControllerButtons.RStickLeft;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
if (rightStick.Dx > 0)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
result |= HidControllerButtons.RStickRight;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
if (rightStick.Dy < 0)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
result |= HidControllerButtons.RStickDown;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
if (rightStick.Dy > 0)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
result |= HidControllerButtons.RStickUp;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
if (leftStick.Dx < 0)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
result |= HidControllerButtons.LStickLeft;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
if (leftStick.Dx > 0)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
result |= HidControllerButtons.LStickRight;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
if (leftStick.Dy < 0)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
result |= HidControllerButtons.LStickDown;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
if (leftStick.Dy > 0)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
result |= HidControllerButtons.LStickUp;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
return result;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public void SetTouchPoints(params HidTouchPoint[] points)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -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-06 06:16:24 -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-06 06:16:24 -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-06 06:16:24 -05:00
|
|
|
|
touchEntryOffset += currEntry * HidTouchEntrySize;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -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-06 06:16:24 -05:00
|
|
|
|
touchEntryOffset += HidTouchEntryHeaderSize;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
const int padding = 0;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
int index = 0;
|
2018-11-19 19:01:36 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
foreach (HidTouchPoint point in points)
|
2018-11-19 19:01:36 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|