2018-11-20 01:01:36 +01:00
|
|
|
|
namespace Ryujinx.HLE.Input
|
|
|
|
|
{
|
|
|
|
|
public class HidNpadController : HidControllerBase
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private (NpadColor Left, NpadColor Right) _npadBodyColors;
|
|
|
|
|
private (NpadColor Left, NpadColor Right) _npadButtonColors;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private HidControllerLayouts _currentLayout;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private bool _isHalf;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
|
|
|
|
public HidNpadController(
|
2018-12-06 12:16:24 +01:00
|
|
|
|
HidControllerType controllerType,
|
|
|
|
|
Switch device,
|
|
|
|
|
(NpadColor, NpadColor) npadBodyColors,
|
|
|
|
|
(NpadColor, NpadColor) npadButtonColors) : base(controllerType, device)
|
2018-11-20 01:01:36 +01:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_npadBodyColors = npadBodyColors;
|
|
|
|
|
_npadButtonColors = npadButtonColors;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_currentLayout = HidControllerLayouts.HandheldJoined;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
switch (controllerType)
|
2018-11-20 01:01:36 +01:00
|
|
|
|
{
|
|
|
|
|
case HidControllerType.NpadLeft:
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_currentLayout = HidControllerLayouts.Left;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
break;
|
|
|
|
|
case HidControllerType.NpadRight:
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_currentLayout = HidControllerLayouts.Right;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
break;
|
|
|
|
|
case HidControllerType.NpadPair:
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_currentLayout = HidControllerLayouts.Joined;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
public override void Connect(HidControllerId controllerId)
|
2018-11-20 01:01:36 +01:00
|
|
|
|
{
|
|
|
|
|
if(HidControllerType != HidControllerType.NpadLeft && HidControllerType != HidControllerType.NpadRight)
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_isHalf = false;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
base.Connect(_currentLayout == HidControllerLayouts.HandheldJoined ? HidControllerId.ControllerHandheld : controllerId);
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
HidControllerColorDesc singleColorDesc =
|
|
|
|
|
HidControllerColorDesc.ColorDescColorsNonexistent;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
HidControllerColorDesc splitColorDesc = 0;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
NpadColor singleColorBody = NpadColor.Black;
|
|
|
|
|
NpadColor singleColorButtons = NpadColor.Black;
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
Device.Memory.WriteInt32(Offset + 0x04, _isHalf ? 1 : 0);
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (_isHalf)
|
2018-11-20 01:01:36 +01:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
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);
|
2018-11-20 01:01:36 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
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);
|
2018-11-20 01:01:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Connected = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void SendInput
|
2018-12-06 12:16:24 +01:00
|
|
|
|
(HidControllerButtons buttons,
|
|
|
|
|
HidJoystickPosition leftStick,
|
|
|
|
|
HidJoystickPosition rightStick)
|
2018-11-20 01:01:36 +01:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
long controllerOffset = WriteInput(buttons, leftStick, rightStick, _currentLayout);
|
2018-11-20 01:01:36 +01:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
Device.Memory.WriteInt64(controllerOffset + 0x28,
|
|
|
|
|
(Connected ? (uint)HidControllerConnState.ControllerStateConnected : 0) |
|
|
|
|
|
(_currentLayout == HidControllerLayouts.HandheldJoined ? (uint)HidControllerConnState.ControllerStateWired : 0));
|
2018-12-07 21:59:38 +01:00
|
|
|
|
|
|
|
|
|
controllerOffset = WriteInput(buttons, leftStick, rightStick, HidControllerLayouts.Main);
|
|
|
|
|
|
|
|
|
|
Device.Memory.WriteInt64(controllerOffset + 0x28,
|
|
|
|
|
(Connected ? (uint)HidControllerConnState.ControllerStateWired : 0) |
|
|
|
|
|
(uint)HidControllerConnState.ControllerStateWired);
|
2018-11-20 01:01:36 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|