Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/Input/NX/NXInputDevice.cpp
1168 views
1
2
// NOTE: I'm using enums & structs from the libNX homebrew lib, but they should have the same values as the official APIs
3
4
using namespace RSDK::SKU;
5
6
HidNpadIdType npadTypes[5] = { HidNpadIdType_Handheld, HidNpadIdType_No1, HidNpadIdType_No2, HidNpadIdType_No3, HidNpadIdType_No4 };
7
int32 nxVibrateDeviceCount = 0;
8
9
int32 lastNPadType = -1;
10
int activeNPadTypes[5] = { -1, -1, -1, -1, -1 };
11
12
uint8 activeNPadCount = 8;
13
uint8 nPadIDs[] = { 2, 3, 4, 5, 6, 7, 8, 9 };
14
uint8 storedNPadIDs[] = { 0, 0, 0, 0, 0 };
15
16
int32 RSDK::SKU::currentNXControllerType = (DEVICE_API_NONE << 16) | (DEVICE_TYPE_CONTROLLER << 8) | (DEVICE_SWITCH_HANDHELD << 0);
17
18
void UpdateInputNX(InputDeviceNX *device, u64 *buttonMasks, int32 *hDelta, int32 *vDelta)
19
{
20
int32 prevButtonMasks = device->buttonMasks;
21
device->buttonMasks = *buttonMasks;
22
23
device->hDelta_L = hDelta[0] + 128.0;
24
device->vDelta_L = vDelta[0] + 128.0;
25
26
float div = sqrtf((device->hDelta_L * device->hDelta_L) + (device->vDelta_L * device->vDelta_L));
27
device->hDelta_L = device->hDelta_L / div;
28
device->vDelta_L = device->vDelta_L / div;
29
if (div <= 15728.0) {
30
device->hDelta_L = 0.0;
31
device->vDelta_L = 0.0;
32
}
33
else {
34
device->hDelta_L = device->hDelta_L * ((fminf(div, 127.0) + -15728.0) / 17039.0);
35
device->vDelta_L = device->vDelta_L * ((fminf(div, 127.0) + -15728.0) / 17039.0);
36
}
37
38
device->hDelta_R = hDelta[1] + 128.0;
39
device->vDelta_R = vDelta[1] + 128.0;
40
41
div = sqrtf((device->hDelta_R * device->hDelta_R) + (device->vDelta_R * device->vDelta_R));
42
device->hDelta_R = device->hDelta_R / div;
43
device->vDelta_R = device->vDelta_R / div;
44
if (div <= 15728.0) {
45
device->hDelta_R = 0.0;
46
device->vDelta_R = 0.0;
47
}
48
else {
49
device->hDelta_R = device->hDelta_R * ((fminf(div, 127.0) + -15728.0) / 17039.0);
50
device->vDelta_R = device->vDelta_R * ((fminf(div, 127.0) + -15728.0) / 17039.0);
51
}
52
53
int32 changedButtons = device->buttonMasks & ~prevButtonMasks;
54
55
if (changedButtons) {
56
currentNXControllerType = device->gamepadType;
57
device->inactiveTimer[0] = 0;
58
}
59
else {
60
++device->inactiveTimer[0];
61
}
62
63
if ((changedButtons & KEYMASK_A) || (changedButtons & KEYMASK_START))
64
device->inactiveTimer[1] = 0;
65
else
66
++device->inactiveTimer[1];
67
68
device->anyPress = changedButtons;
69
70
device->ProcessInput(CONT_ANY);
71
}
72
73
void InputDeviceNXHandheld::UpdateInput()
74
{
75
int32 vDelta[2];
76
int32 hDelta[2];
77
HidNpadHandheldState state;
78
79
hidGetNpadStatesHandheld(this->npadType, &state, 1);
80
hDelta[0] = -state.analog_stick_l.x;
81
hDelta[1] = -state.analog_stick_r.x;
82
vDelta[0] = -state.analog_stick_l.y;
83
vDelta[1] = -state.analog_stick_r.y;
84
85
UpdateInputNX(this, &state.buttons, hDelta, vDelta);
86
}
87
88
void InputDeviceNXJoyL::UpdateInput()
89
{
90
int32 vDelta[2];
91
int32 hDelta[2];
92
HidNpadHandheldState state;
93
94
hidGetNpadStatesJoyLeft(this->npadType, &state, 1);
95
hDelta[0] = -state.analog_stick_l.x;
96
hDelta[1] = -state.analog_stick_r.x;
97
vDelta[0] = -state.analog_stick_l.y;
98
vDelta[1] = -state.analog_stick_r.y;
99
100
u64 correctedButtonMasks = state.buttons;
101
102
// "Rotate" the buttons
103
correctedButtonMasks |= (state.buttons & HidNpadButton_Down) ? HidNpadButton_A : 0;
104
correctedButtonMasks |= (state.buttons & HidNpadButton_Left) ? HidNpadButton_B : 0;
105
correctedButtonMasks |= (state.buttons & HidNpadButton_Right) ? HidNpadButton_X : 0;
106
correctedButtonMasks |= (state.buttons & HidNpadButton_Up) ? HidNpadButton_Y : 0;
107
correctedButtonMasks |= (state.buttons & HidNpadButton_StickL) ? HidNpadButton_StickL : 0;
108
correctedButtonMasks |= (state.buttons & HidNpadButton_Plus) ? HidNpadButton_Plus : 0;
109
110
correctedButtonMasks &= ~HidNpadButton_L;
111
if (state.buttons & HidNpadButton_LeftSL)
112
correctedButtonMasks |= HidNpadButton_L;
113
114
correctedButtonMasks &= ~HidNpadButton_R;
115
if (state.buttons & HidNpadButton_LeftSR)
116
correctedButtonMasks |= HidNpadButton_R;
117
118
UpdateInputNX(this, &correctedButtonMasks, hDelta, vDelta);
119
if (state.buttons & HidNpadButton_L) {
120
// if (this->npadType >= HidNpadIdType_No4)
121
// OnAssertionFailure(2, "", "", "", 0);
122
123
if (lastNPadType <= 3 && activeNPadTypes[lastNPadType] == 4)
124
hidMergeSingleJoyAsDualJoy((HidNpadIdType)activeNPadTypes[lastNPadType], this->npadType);
125
else
126
lastNPadType = this->npadType;
127
}
128
}
129
130
void InputDeviceNXJoyR::UpdateInput()
131
{
132
int32 vDelta[2];
133
int32 hDelta[2];
134
HidNpadHandheldState state;
135
136
hidGetNpadStatesJoyRight(this->npadType, &state, 1);
137
hDelta[0] = -state.analog_stick_l.x;
138
hDelta[1] = -state.analog_stick_r.x;
139
vDelta[0] = -state.analog_stick_l.y;
140
vDelta[1] = -state.analog_stick_r.y;
141
142
u64 correctedButtonMasks = state.buttons;
143
144
// "Rotate" the buttons
145
correctedButtonMasks |= (state.buttons & HidNpadButton_A) ? HidNpadButton_B : 0;
146
correctedButtonMasks |= (state.buttons & HidNpadButton_B) ? HidNpadButton_Y : 0;
147
correctedButtonMasks |= (state.buttons & HidNpadButton_X) ? HidNpadButton_A : 0;
148
correctedButtonMasks |= (state.buttons & HidNpadButton_Y) ? HidNpadButton_X : 0;
149
correctedButtonMasks |= (state.buttons & HidNpadButton_StickR) ? HidNpadButton_StickL : 0;
150
correctedButtonMasks |= (state.buttons & HidNpadButton_Plus) ? HidNpadButton_Plus : 0;
151
152
correctedButtonMasks &= ~HidNpadButton_L;
153
if (state.buttons & HidNpadButton_RightSL)
154
correctedButtonMasks |= HidNpadButton_L;
155
156
correctedButtonMasks &= ~HidNpadButton_R;
157
if (state.buttons & HidNpadButton_RightSR)
158
correctedButtonMasks |= HidNpadButton_R;
159
160
UpdateInputNX(this, &correctedButtonMasks, hDelta, vDelta);
161
if (state.buttons & HidNpadButton_R) {
162
// if (this->npadType >= HidNpadIdType_No4)
163
// OnAssertionFailure(2, "", "", "", 0);
164
165
if (lastNPadType <= 3 && activeNPadTypes[lastNPadType] == 3)
166
hidMergeSingleJoyAsDualJoy((HidNpadIdType)activeNPadTypes[lastNPadType], this->npadType);
167
else
168
lastNPadType = this->npadType;
169
}
170
}
171
172
void InputDeviceNXJoyGrip::UpdateInput()
173
{
174
int32 vDelta[2];
175
int32 hDelta[2];
176
HidNpadHandheldState state;
177
178
hidGetNpadStatesJoyDual(this->npadType, &state, 1);
179
hDelta[0] = -state.analog_stick_l.x;
180
hDelta[1] = -state.analog_stick_r.x;
181
vDelta[0] = -state.analog_stick_l.y;
182
vDelta[1] = -state.analog_stick_r.y;
183
184
UpdateInputNX(this, &state.buttons, hDelta, vDelta);
185
186
// if (this->npadType >= HidNpadIdType_No4)
187
// OnAssertionFailure(2, "", "", "", 0);
188
189
int32 masks = (int32)state.buttons;
190
if ((masks & HidNpadButton_LeftSL) && (masks & HidNpadButton_LeftSR)) {
191
for (int32 id = HidNpadIdType_No1; id <= HidNpadIdType_No4; ++id) {
192
if (!hidGetNpadStyleSet((HidNpadIdType)id)) {
193
hidSetNpadJoyAssignmentModeSingleByDefault((HidNpadIdType)id);
194
return;
195
}
196
}
197
198
hidSetNpadJoyAssignmentModeSingle(this->npadType, HidNpadJoyDeviceType_Left);
199
}
200
else if ((masks & HidNpadButton_RightSL) && (masks & HidNpadButton_RightSR)) {
201
for (int32 id = HidNpadIdType_No1; id <= HidNpadIdType_No4; ++id) {
202
if (!hidGetNpadStyleSet((HidNpadIdType)id)) {
203
hidSetNpadJoyAssignmentModeSingleByDefault((HidNpadIdType)id);
204
return;
205
}
206
}
207
208
hidSetNpadJoyAssignmentModeSingle(this->npadType, HidNpadJoyDeviceType_Right);
209
}
210
}
211
212
void InputDeviceNXPro::UpdateInput()
213
{
214
int32 vDelta[2];
215
int32 hDelta[2];
216
HidNpadHandheldState state;
217
218
hidGetNpadStatesFullKey(this->npadType, &state, 1);
219
hDelta[0] = -state.analog_stick_l.x;
220
hDelta[1] = -state.analog_stick_r.x;
221
vDelta[0] = -state.analog_stick_l.y;
222
vDelta[1] = -state.analog_stick_r.y;
223
224
UpdateInputNX(this, &state.buttons, hDelta, vDelta);
225
}
226
227
void InputDeviceNX::ProcessInput(int32 controllerID)
228
{
229
int32 buttonMasks = (int32)this->buttonMasks;
230
231
controller[controllerID].keyUp.press |= (buttonMasks & HidNpadButton_Up) != 0;
232
controller[controllerID].keyDown.press |= (buttonMasks & HidNpadButton_Down) != 0;
233
controller[controllerID].keyLeft.press |= (buttonMasks & HidNpadButton_Left) != 0;
234
controller[controllerID].keyRight.press |= (buttonMasks & HidNpadButton_Right) != 0;
235
controller[controllerID].keyA.press |= (buttonMasks & HidNpadButton_B) != 0;
236
controller[controllerID].keyB.press |= (buttonMasks & HidNpadButton_A) != 0;
237
controller[controllerID].keyX.press |= (buttonMasks & HidNpadButton_Y) != 0;
238
controller[controllerID].keyY.press |= (buttonMasks & HidNpadButton_X) != 0;
239
controller[controllerID].keyStart.press |= (buttonMasks & HidNpadButton_Plus) != 0;
240
controller[controllerID].keySelect.press |= (buttonMasks & HidNpadButton_Minus) != 0;
241
242
#if RETRO_REV02
243
stickL[controllerID].keyStick.press |= (buttonMasks & HidNpadButton_StickL) != 0;
244
stickL[controllerID].hDelta = this->hDelta_L;
245
stickL[controllerID].vDelta = this->vDelta_L;
246
stickL[controllerID].keyUp.press |= this->vDelta_L > INPUT_DEADZONE;
247
stickL[controllerID].keyDown.press |= this->vDelta_L < -INPUT_DEADZONE;
248
stickL[controllerID].keyLeft.press |= this->hDelta_L < -INPUT_DEADZONE;
249
stickL[controllerID].keyRight.press |= this->hDelta_L > INPUT_DEADZONE;
250
251
stickR[controllerID].keyStick.press |= (buttonMasks & HidNpadButton_StickR) != 0;
252
stickR[controllerID].hDelta = this->hDelta_R;
253
stickR[controllerID].vDelta = this->vDelta_R;
254
stickR[controllerID].keyUp.press |= this->vDelta_R > INPUT_DEADZONE;
255
stickR[controllerID].keyDown.press |= this->vDelta_R < -INPUT_DEADZONE;
256
stickR[controllerID].keyLeft.press |= this->hDelta_R < -INPUT_DEADZONE;
257
stickR[controllerID].keyRight.press |= this->hDelta_R > INPUT_DEADZONE;
258
259
triggerL[controllerID].keyBumper.press |= (buttonMasks & HidNpadButton_L) != 0;
260
triggerL[controllerID].keyTrigger.press |= (buttonMasks & HidNpadButton_ZL) != 0;
261
triggerL[controllerID].bumperDelta = triggerL[controllerID].keyBumper.press ? 1.0 : 0.0;
262
triggerL[controllerID].triggerDelta = triggerL[controllerID].keyTrigger.press ? 1.0 : 0.0;
263
264
triggerR[controllerID].keyBumper.press |= (buttonMasks & HidNpadButton_R) != 0;
265
triggerR[controllerID].keyTrigger.press |= (buttonMasks & HidNpadButton_ZR) != 0;
266
triggerR[controllerID].bumperDelta = triggerR[controllerID].keyBumper.press ? 1.0 : 0.0;
267
triggerR[controllerID].triggerDelta = triggerR[controllerID].keyTrigger.press ? 1.0 : 0.0;
268
#else
269
controller[controllerID].keyStickL.press |= (buttonMasks & HidNpadButton_StickL) != 0;
270
stickL[controllerID].hDeltaL = this->hDelta_L;
271
stickL[controllerID].vDeltaL = this->vDelta_L;
272
stickL[controllerID].keyUp.press |= this->vDelta_L > INPUT_DEADZONE;
273
stickL[controllerID].keyDown.press |= this->vDelta_L < -INPUT_DEADZONE;
274
stickL[controllerID].keyLeft.press |= this->hDelta_L < -INPUT_DEADZONE;
275
stickL[controllerID].keyRight.press |= this->hDelta_L > INPUT_DEADZONE;
276
277
controller[controllerID].keyStickR.press |= (buttonMasks & HidNpadButton_StickR) != 0;
278
stickL[controllerID].hDeltaL = this->hDelta_R;
279
stickL[controllerID].vDeltaL = this->vDelta_R;
280
281
controller[controllerID].keyBumperL.press |= (buttonMasks & HidNpadButton_L) != 0;
282
controller[controllerID].keyTriggerL.press |= (buttonMasks & HidNpadButton_ZL) != 0;
283
stickL[controllerID].triggerDeltaL = controller[controllerID].keyTriggerL.press ? 1.0 : 0.0;
284
285
controller[controllerID].keyBumperR.press |= (buttonMasks & HidNpadButton_R) != 0;
286
controller[controllerID].keyTriggerR.press |= (buttonMasks & HidNpadButton_ZR) != 0;
287
stickL[controllerID].triggerDeltaR = controller[controllerID].keyTriggerR.press ? 1.0 : 0.0;
288
#endif
289
}
290
291
InputDeviceNXHandheld *RSDK::SKU::InitNXHandheldInputDevice(uint32 id, HidNpadIdType type)
292
{
293
if (inputDeviceCount == INPUTDEVICE_COUNT)
294
return NULL;
295
296
if (inputDeviceList[inputDeviceCount] && inputDeviceList[inputDeviceCount]->active)
297
return NULL;
298
299
if (inputDeviceList[inputDeviceCount])
300
delete inputDeviceList[inputDeviceCount];
301
302
inputDeviceList[inputDeviceCount] = new InputDeviceNXHandheld();
303
304
InputDeviceNXHandheld *device = (InputDeviceNXHandheld *)inputDeviceList[inputDeviceCount];
305
306
device->gamepadType = (DEVICE_API_NONE << 16) | (DEVICE_TYPE_CONTROLLER << 8) | (DEVICE_SWITCH_HANDHELD << 0);
307
device->disabled = false;
308
device->id = id;
309
device->active = true;
310
device->npadType = type;
311
312
for (int32 i = 0; i < PLAYER_COUNT; ++i) {
313
if (inputSlots[i] == id) {
314
inputSlotDevices[i] = device;
315
device->isAssigned = true;
316
}
317
}
318
319
inputDeviceCount++;
320
return device;
321
}
322
323
InputDeviceNXJoyL *RSDK::SKU::InitNXJoyLInputDevice(uint32 id, HidNpadIdType type)
324
{
325
if (inputDeviceCount == INPUTDEVICE_COUNT)
326
return NULL;
327
328
if (inputDeviceList[inputDeviceCount] && inputDeviceList[inputDeviceCount]->active)
329
return NULL;
330
331
if (inputDeviceList[inputDeviceCount])
332
delete inputDeviceList[inputDeviceCount];
333
334
inputDeviceList[inputDeviceCount] = new InputDeviceNXJoyL();
335
336
InputDeviceNXJoyL *device = (InputDeviceNXJoyL *)inputDeviceList[inputDeviceCount];
337
338
device->gamepadType = (DEVICE_API_NONE << 16) | (DEVICE_TYPE_CONTROLLER << 8) | (DEVICE_SWITCH_JOY_L << 0);
339
device->disabled = false;
340
device->id = id;
341
device->active = true;
342
device->npadType = type;
343
344
for (int32 i = 0; i < PLAYER_COUNT; ++i) {
345
if (inputSlots[i] == id) {
346
inputSlotDevices[i] = device;
347
device->isAssigned = true;
348
}
349
}
350
351
inputDeviceCount++;
352
return device;
353
}
354
InputDeviceNXJoyR *RSDK::SKU::InitNXJoyRInputDevice(uint32 id, HidNpadIdType type)
355
{
356
if (inputDeviceCount == INPUTDEVICE_COUNT)
357
return NULL;
358
359
if (inputDeviceList[inputDeviceCount] && inputDeviceList[inputDeviceCount]->active)
360
return NULL;
361
362
if (inputDeviceList[inputDeviceCount])
363
delete inputDeviceList[inputDeviceCount];
364
365
inputDeviceList[inputDeviceCount] = new InputDeviceNXJoyR();
366
367
InputDeviceNXJoyR *device = (InputDeviceNXJoyR *)inputDeviceList[inputDeviceCount];
368
369
device->gamepadType = (DEVICE_API_NONE << 16) | (DEVICE_TYPE_CONTROLLER << 8) | (DEVICE_SWITCH_JOY_R << 0);
370
device->disabled = false;
371
device->id = id;
372
device->active = true;
373
device->npadType = type;
374
375
for (int32 i = 0; i < PLAYER_COUNT; ++i) {
376
if (inputSlots[i] == id) {
377
inputSlotDevices[i] = device;
378
device->isAssigned = true;
379
}
380
}
381
382
inputDeviceCount++;
383
return device;
384
}
385
InputDeviceNXJoyGrip *RSDK::SKU::InitNXJoyGripInputDevice(uint32 id, HidNpadIdType type)
386
{
387
if (inputDeviceCount == INPUTDEVICE_COUNT)
388
return NULL;
389
390
if (inputDeviceList[inputDeviceCount] && inputDeviceList[inputDeviceCount]->active)
391
return NULL;
392
393
if (inputDeviceList[inputDeviceCount])
394
delete inputDeviceList[inputDeviceCount];
395
396
inputDeviceList[inputDeviceCount] = new InputDeviceNXJoyGrip();
397
398
InputDeviceNXJoyGrip *device = (InputDeviceNXJoyGrip *)inputDeviceList[inputDeviceCount];
399
400
device->gamepadType = (DEVICE_API_NONE << 16) | (DEVICE_TYPE_CONTROLLER << 8) | (DEVICE_SWITCH_JOY_GRIP << 0);
401
device->disabled = false;
402
device->id = id;
403
device->active = true;
404
device->npadType = type;
405
406
for (int32 i = 0; i < PLAYER_COUNT; ++i) {
407
if (inputSlots[i] == id) {
408
inputSlotDevices[i] = device;
409
device->isAssigned = true;
410
}
411
}
412
413
inputDeviceCount++;
414
return device;
415
}
416
InputDeviceNXPro *RSDK::SKU::InitNXProInputDevice(uint32 id, HidNpadIdType type)
417
{
418
if (inputDeviceCount == INPUTDEVICE_COUNT)
419
return NULL;
420
421
if (inputDeviceList[inputDeviceCount] && inputDeviceList[inputDeviceCount]->active)
422
return NULL;
423
424
if (inputDeviceList[inputDeviceCount])
425
delete inputDeviceList[inputDeviceCount];
426
427
inputDeviceList[inputDeviceCount] = new InputDeviceNXPro();
428
429
InputDeviceNXPro *device = (InputDeviceNXPro *)inputDeviceList[inputDeviceCount];
430
431
device->gamepadType = (DEVICE_API_NONE << 16) | (DEVICE_TYPE_CONTROLLER << 8) | (DEVICE_SWITCH_PRO << 0);
432
device->disabled = false;
433
device->id = id;
434
device->active = true;
435
device->npadType = type;
436
437
for (int32 i = 0; i < PLAYER_COUNT; ++i) {
438
if (inputSlots[i] == id) {
439
inputSlotDevices[i] = device;
440
device->isAssigned = true;
441
}
442
}
443
444
inputDeviceCount++;
445
return device;
446
}
447
448
void RSDK::SKU::InitNXInputAPI()
449
{
450
hidInitializeNpad();
451
hidInitializeTouchScreen();
452
hidSetSupportedNpadStyleSet(HidNpadStyleTag_NpadFullKey | HidNpadStyleTag_NpadHandheld | HidNpadStyleTag_NpadJoyDual | HidNpadStyleTag_NpadJoyLeft
453
| HidNpadStyleTag_NpadJoyRight);
454
hidSetSupportedNpadIdType(npadTypes, 5);
455
456
hidSetNpadJoyHoldType(HidNpadJoyHoldType_Horizontal);
457
458
ProcessInput();
459
460
// Unsure about this one, hope its right :)
461
HidVibrationDeviceHandle handles[8];
462
hidInitializeVibrationDevices(handles, 8, HidNpadIdType_No3, HidNpadStyleTag_NpadFullKey);
463
nxVibrateDeviceCount = 8;
464
}
465
466
void RSDK::SKU::ProcessNXInputDevices()
467
{
468
lastNPadType = -1;
469
470
// check for lost connections
471
for (int32 d = 4; d >= 1; --d) {
472
int32 type = activeNPadTypes[d];
473
474
// if no controller (and there was one before), remove!
475
if (type != -1 && !hidGetNpadStyleSet(npadTypes[d])) {
476
int32 prevID = storedNPadIDs[d];
477
storedNPadIDs[d] = 0;
478
if (prevID)
479
nPadIDs[activeNPadCount++] = prevID;
480
481
InputDevice *device = InputDeviceFromID(prevID);
482
if (device)
483
RemoveInputDevice(device);
484
485
activeNPadTypes[d] = -1;
486
}
487
}
488
489
// check for changed controller types
490
for (int32 d = 4; d >= 1; --d) {
491
int32 type = activeNPadTypes[d];
492
493
// if what it is now, isn't what we "remembered", change!
494
if (type != -1 && !(hidGetNpadStyleSet(npadTypes[d]) & (1 << (type & 0x1F)))) {
495
int32 prevID = storedNPadIDs[d];
496
storedNPadIDs[d] = 0;
497
if (prevID)
498
nPadIDs[activeNPadCount++] = prevID;
499
500
InputDevice *device = InputDeviceFromID(prevID);
501
if (device)
502
RemoveInputDevice(device);
503
504
activeNPadTypes[d] = -1;
505
}
506
}
507
508
// update input device states & etc
509
for (int32 c = 0; c < 5; ++c) {
510
uint32 styleSet = hidGetNpadStyleSet(npadTypes[c]);
511
512
if (activeNPadTypes[c] == -1) {
513
InputDevice *device = NULL;
514
uint32 id = 0;
515
516
if (!device && (styleSet & HidNpadStyleTag_NpadHandheld)) {
517
id = 0;
518
if (activeNPadCount) {
519
id = nPadIDs[--activeNPadCount];
520
storedNPadIDs[c] = id;
521
}
522
523
device = InputDeviceFromID(id);
524
if (!device)
525
device = InitNXHandheldInputDevice(id, npadTypes[c]);
526
527
activeNPadTypes[c] = 1;
528
}
529
530
if (!device && (styleSet & HidNpadStyleTag_NpadJoyLeft)) {
531
id = 0;
532
if (activeNPadCount) {
533
id = nPadIDs[--activeNPadCount];
534
storedNPadIDs[c] = id;
535
}
536
537
device = InputDeviceFromID(id);
538
if (!device)
539
device = InitNXJoyLInputDevice(id, npadTypes[c]);
540
541
if (device) {
542
hidSetNpadJoyAssignmentModeSingleByDefault(npadTypes[c]);
543
hidSetNpadJoyHoldType(HidNpadJoyHoldType_Horizontal);
544
}
545
546
activeNPadTypes[c] = 3;
547
}
548
549
if (!device && (styleSet & HidNpadStyleTag_NpadJoyRight)) {
550
id = 0;
551
if (activeNPadCount) {
552
id = nPadIDs[--activeNPadCount];
553
storedNPadIDs[c] = id;
554
}
555
556
device = InputDeviceFromID(id);
557
if (!device)
558
device = InitNXJoyRInputDevice(id, npadTypes[c]);
559
560
if (device) {
561
hidSetNpadJoyAssignmentModeSingleByDefault(npadTypes[c]);
562
hidSetNpadJoyHoldType(HidNpadJoyHoldType_Horizontal);
563
}
564
565
activeNPadTypes[c] = 4;
566
}
567
568
if (!device && (styleSet & HidNpadStyleTag_NpadJoyDual)) {
569
id = 0;
570
if (activeNPadCount) {
571
id = nPadIDs[--activeNPadCount];
572
storedNPadIDs[c] = id;
573
}
574
575
device = InputDeviceFromID(id);
576
if (!device)
577
device = InitNXJoyGripInputDevice(id, npadTypes[c]);
578
579
activeNPadTypes[c] = 2;
580
}
581
582
if (!device && (styleSet & HidNpadStyleTag_NpadFullKey)) {
583
id = 0;
584
if (activeNPadCount) {
585
id = nPadIDs[--activeNPadCount];
586
storedNPadIDs[c] = id;
587
}
588
589
device = InputDeviceFromID(id);
590
if (!device)
591
device = InitNXProInputDevice(id, npadTypes[c]);
592
593
activeNPadTypes[c] = 0;
594
}
595
}
596
}
597
598
HidTouchScreenState touchState;
599
hidGetTouchScreenStates(&touchState, 1);
600
601
touchInfo.count = 0;
602
for (int32 f = 0; f < touchState.count; ++f) {
603
if (!touchState.touches[f].finger_id) {
604
touchInfo.down[0] = true;
605
touchInfo.x[0] = touchState.touches[0].x / 1280.0;
606
touchInfo.y[0] = touchState.touches[0].y / 720.0;
607
touchInfo.count++;
608
}
609
}
610
}
611