1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-11-30 15:52:22 +00:00
Ryujinx/Ryujinx.HLE/Input/HidNpadController.cs

87 lines
3.3 KiB
C#
Raw Normal View History

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