2018-11-20 00:01:36 +00:00
|
|
|
|
namespace Ryujinx.HLE.Input
|
|
|
|
|
{
|
|
|
|
|
public class HidNpadController : HidControllerBase
|
|
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
|
private (NpadColor Left, NpadColor Right) NpadBodyColors;
|
|
|
|
|
private (NpadColor Left, NpadColor Right) NpadButtonColors;
|
2018-11-20 00:01:36 +00:00
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
|
private HidControllerLayouts CurrentLayout;
|
2018-11-20 00:01:36 +00:00
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
|
private bool IsHalf;
|
2018-11-20 00:01:36 +00:00
|
|
|
|
|
|
|
|
|
public HidNpadController(
|
2018-12-05 00:52:39 +00:00
|
|
|
|
HidControllerType ControllerType,
|
|
|
|
|
Switch Device,
|
|
|
|
|
(NpadColor, NpadColor) NpadBodyColors,
|
|
|
|
|
(NpadColor, NpadColor) NpadButtonColors) : base(ControllerType, Device)
|
2018-11-20 00:01:36 +00:00
|
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
|
this.NpadBodyColors = NpadBodyColors;
|
|
|
|
|
this.NpadButtonColors = NpadButtonColors;
|
2018-11-20 00:01:36 +00:00
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
|
CurrentLayout = HidControllerLayouts.Handheld_Joined;
|
2018-11-20 00:01:36 +00:00
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
|
switch (ControllerType)
|
2018-11-20 00:01:36 +00:00
|
|
|
|
{
|
|
|
|
|
case HidControllerType.NpadLeft:
|
2018-12-05 00:52:39 +00:00
|
|
|
|
CurrentLayout = HidControllerLayouts.Left;
|
2018-11-20 00:01:36 +00:00
|
|
|
|
break;
|
|
|
|
|
case HidControllerType.NpadRight:
|
2018-12-05 00:52:39 +00:00
|
|
|
|
CurrentLayout = HidControllerLayouts.Right;
|
2018-11-20 00:01:36 +00:00
|
|
|
|
break;
|
|
|
|
|
case HidControllerType.NpadPair:
|
2018-12-05 00:52:39 +00:00
|
|
|
|
CurrentLayout = HidControllerLayouts.Joined;
|
2018-11-20 00:01:36 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
|
public override void Connect(HidControllerId ControllerId)
|
2018-11-20 00:01:36 +00:00
|
|
|
|
{
|
|
|
|
|
if(HidControllerType != HidControllerType.NpadLeft && HidControllerType != HidControllerType.NpadRight)
|
|
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
|
IsHalf = false;
|
2018-11-20 00:01:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
|
base.Connect(CurrentLayout == HidControllerLayouts.Handheld_Joined ? HidControllerId.CONTROLLER_HANDHELD : ControllerId);
|
2018-11-20 00:01:36 +00:00
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
|
HidControllerColorDesc SingleColorDesc =
|
|
|
|
|
HidControllerColorDesc.ColorDesc_ColorsNonexistent;
|
2018-11-20 00:01:36 +00:00
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
|
HidControllerColorDesc SplitColorDesc = 0;
|
2018-11-20 00:01:36 +00:00
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
|
NpadColor SingleColorBody = NpadColor.Black;
|
|
|
|
|
NpadColor SingleColorButtons = NpadColor.Black;
|
2018-11-20 00:01:36 +00:00
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
|
Device.Memory.WriteInt32(Offset + 0x04, IsHalf ? 1 : 0);
|
2018-11-20 00:01:36 +00:00
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
|
if (IsHalf)
|
2018-11-20 00:01:36 +00:00
|
|
|
|
{
|
2018-12-05 00:52:39 +00: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 00:01:36 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-12-05 00:52:39 +00: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 00:01:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Connected = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void SendInput
|
2018-12-05 00:52:39 +00:00
|
|
|
|
(HidControllerButtons Buttons,
|
|
|
|
|
HidJoystickPosition LeftStick,
|
|
|
|
|
HidJoystickPosition RightStick)
|
2018-11-20 00:01:36 +00:00
|
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
|
long ControllerOffset = WriteInput(Buttons, LeftStick, RightStick, CurrentLayout);
|
2018-11-20 00:01:36 +00:00
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
|
Device.Memory.WriteInt64(ControllerOffset + 0x28,
|
|
|
|
|
(Connected ? (uint)HidControllerConnState.Controller_State_Connected : 0) |
|
|
|
|
|
(CurrentLayout == HidControllerLayouts.Handheld_Joined ? (uint)HidControllerConnState.Controller_State_Wired : 0));
|
2018-11-20 00:01:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|