-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathclassic.c
704 lines (622 loc) · 27.8 KB
/
classic.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
/* Extenmote : NES, SNES, N64 and Gamecube to Wii remote adapter firmware
* Copyright (C) 2012-2014 Raphael Assenat <raph@raphnet.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include "classic.h"
#include "eeprom.h"
#include "analog.h"
#include "rlut.h"
#include "tripleclick.h"
#define C_DEFLECTION 100
/* | Bit |
* Byte | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
* ------+---------------+-------+----------------------------+
* 0 | RX<4:3> | LX<5:0> |
* 1 | RX<2:1> | LY<5:0> |
* 2 | RX<0> | LT<4:3> | RY<4:0> |
* 3 | LT<2:0> | RT<4:0> |
* 4 | BDR | BDD | BLT | B- | BH | B+ | BRT | 1 |
* 5 | BZL | BB | BY | BA | BX | BZR | BDL | BDU |
*
* 6 | 0x52 ('R') |
* 7 | Controller ID byte 0 |
* 8 | Controller ID byte 1 |
*
* 9 | Controller specific data 0 |
* 10 | Controller specific data 1 |
* 11 | Controller specific data 2 |
* 12 | Controller specific data 3 |
* 13 | Controller specific data 4 |
* 14 | Controller specific data 5 |
* 15 | Controller specific data 6 |
* 16 | Controller specific data 7 |
*
* Controller ID:
*
* 0 | 1
* -----+-----
* '6' | '4' N64 controller
* 'G' | 'C' Gamecube controller
* 'S' | 'F' SNES
* 'F' | 'C' NES
*
* Writing at byte 6 might one day control the rumble motor. Rumbles on when non-zero.
*/
void pack_classic_data_mode1(classic_pad_data *src, unsigned char dst[PACKED_CLASSIC_DATA_SIZE], int analog_style)
{
unsigned char rx,ry,lx=0x20,ly=0x20; // down sized
unsigned char shoulder_left=0, shoulder_right=0; // lower 5 bits only
memset(dst, 0x00, PACKED_CLASSIC_DATA_SIZE);
if (analog_style == ANALOG_STYLE_N64)
{
if (g_current_config.g_n64_mapping_mode != MODE_TEST) {
#ifdef WITH_N64
lx = applyCurve(src->lx, g_current_config.g_n64_curve_id);
ly = applyCurve(src->ly, g_current_config.g_n64_curve_id);
#endif
} else {
lx = 0x20 + src->lx;
ly = 0x20 + src->ly;
}
} else if (analog_style == ANALOG_STYLE_GC) {
#ifdef WITH_GAMECUBE
lx = applyCurve(src->lx, RLUT_GC1);
ly = applyCurve(src->ly, RLUT_GC1);
#endif
}
else {
lx = ((0x80 + src->lx) >> 2) & 0x3F;
ly = ((0x80 + src->ly) >> 2) & 0x3F;
}
rx = ((0x80 + src->rx) >> 3) & 0x1F;
ry = ((0x80 + src->ry) >> 3) & 0x1F;
shoulder_left = (src->lt >> 3);
shoulder_right = (src->rt >> 3);
dst[0] = ((rx<<3) & 0xC0) | lx;
dst[1] = ((rx<<5) & 0xC0) | ly;
dst[2] = rx<<7 | ry | (shoulder_left & 0x18) << 2;
dst[3] = (shoulder_left << 5) | (shoulder_right & 0x1F);
dst[4] = (src->buttons >> 8) ^ 0xFF;
dst[5] = (src->buttons) ^ 0xFF;
dst[6] = 'R';
memcpy(dst+7, src->controller_id, 2);
memcpy(dst+9, src->controller_raw_data, 8);
}
void pack_classic_data_mode2(classic_pad_data *src, unsigned char dst[PACKED_CLASSIC_DATA_SIZE], int analog_style)
{
unsigned char rx=0x80,ry=0x80,lx=0x80,ly=0x80;
unsigned char shoulder_left=0, shoulder_right=0;
memset(dst, 0x00, PACKED_CLASSIC_DATA_SIZE);
if (analog_style == ANALOG_STYLE_N64) {
// Provide a way to get the old 2.1.0 direct translation
if (g_current_config.g_n64_curve_id == RLUT_V1_4) {
lx = 0x80 + src->lx;
ly = 0x80 + src->ly;
} else {
// Classic controllers in this mode return -100 to +100
// N64 controllers are -80 to +80
lx = 0x80 + (src->lx * 128 / 95);
ly = 0x80 + (src->ly * 128 / 95);
}
} else {
lx = 0x80 + src->lx;
ly = 0x80 + src->ly;
}
rx = 0x80 + src->rx;
ry = 0x80 + src->ry;
shoulder_left = src->lt;
shoulder_right = src->rt;
dst[0] = lx;
dst[1] = rx;
dst[2] = ly;
dst[3] = ry;
dst[4] = 0; // I think this can hold extra bits for the axes
dst[5] = shoulder_left;
dst[6] = shoulder_right;
dst[7] = (src->buttons >> 8) ^ 0xFF;
dst[8] = (src->buttons) ^ 0xFF;
}
void pack_classic_data_mode3(classic_pad_data *src, unsigned char dst[PACKED_CLASSIC_DATA_SIZE], int analog_style)
{
unsigned char rx=0x80,ry=0x80,lx=0x80,ly=0x80;
unsigned char shoulder_left=0, shoulder_right=0;
memset(dst, 0x00, PACKED_CLASSIC_DATA_SIZE);
if (analog_style == ANALOG_STYLE_N64) {
// Provide a way to get the old 2.1.0 direct translation
if (g_current_config.g_n64_curve_id == RLUT_V1_4) {
lx = 0x80 + src->lx;
ly = 0x80 + src->ly;
}
else {
// Classic controllers in this mode return -100 to +100
// N64 controllers are -80 to +80, but +/- 75 is typical
lx = 0x80 + (src->lx * 128 / 95);
ly = 0x80 + (src->ly * 128 / 95);
}
} else {
lx = 0x80 + src->lx;
ly = 0x80 + src->ly;
}
rx = 0x80 + src->rx;
ry = 0x80 + src->ry;
shoulder_left = src->lt;
shoulder_right = src->rt;
dst[0] = lx;
dst[1] = rx;
dst[2] = ly;
dst[3] = ry;
dst[4] = shoulder_left;
dst[5] = shoulder_right;
dst[6] = (src->buttons >> 8) ^ 0xFF;
dst[7] = (src->buttons) ^ 0xFF;
}
void pack_classic_data(classic_pad_data *src, unsigned char dst[PACKED_CLASSIC_DATA_SIZE], int analog_style, int mode)
{
switch (mode)
{
default:
case CLASSIC_MODE_1:
pack_classic_data_mode1(src, dst, analog_style);
break;
case CLASSIC_MODE_2:
pack_classic_data_mode2(src, dst, analog_style);
break;
case CLASSIC_MODE_3:
pack_classic_data_mode3(src, dst, analog_style);
break;
}
}
void dataToClassic(const gamepad_data *src, classic_pad_data *dst, char first_read)
{
static char test_x = 0, test_y = 0;
unsigned short buttons_zl_zr = CPAD_BTN_ZR;
static char waiting_release = 0;
// Prior to version 2.1.1, whenever the button mapping called for Z being pressed
// on the classic controller, ZL and ZR were used (i.e. They were pushed down together
// on the virtual classic controller).
//
// But in Super Smash Bros Ultimate on the Switch through the 8BitDo GBros.,
// it has been observed that one cannot roll when both Z triggers are down. So starting
// with version 2.1.1, only ZR is used.
if (g_current_config.merge_zl_zr) {
buttons_zl_zr |= CPAD_BTN_ZL;
}
memset(dst, 0, sizeof(classic_pad_data));
switch (src->pad_type)
{
case PAD_TYPE_NONE:
break;
case PAD_TYPE_SNES:
dst->controller_id[0] = 'S';
dst->controller_id[1] = 'F';
memcpy(dst->controller_raw_data, src->snes.raw_data, SNES_RAW_SIZE);
if (g_current_config.g_snes_nes_mode) {
if (src->snes.buttons & SNES_BTN_Y) { dst->buttons |= CPAD_BTN_B; }
if (src->snes.buttons & SNES_BTN_B) { dst->buttons |= CPAD_BTN_A; }
} else {
if (src->snes.buttons & SNES_BTN_B) { dst->buttons |= CPAD_BTN_B; }
if (src->snes.buttons & SNES_BTN_Y) { dst->buttons |= CPAD_BTN_Y; }
if (src->snes.buttons & SNES_BTN_A) { dst->buttons |= CPAD_BTN_A; }
if (src->snes.buttons & SNES_BTN_X) { dst->buttons |= CPAD_BTN_X; }
}
if (g_current_config.g_snes_analog_dpad) {
if (src->snes.buttons & SNES_BTN_DPAD_UP) { dst->ly = 100; }
if (src->snes.buttons & SNES_BTN_DPAD_DOWN) { dst->ly = -100; }
if (src->snes.buttons & SNES_BTN_DPAD_LEFT) { dst->lx = -100; }
if (src->snes.buttons & SNES_BTN_DPAD_RIGHT) { dst->lx = 100; }
} else {
if (src->snes.buttons & SNES_BTN_DPAD_UP) { dst->buttons |= CPAD_BTN_DPAD_UP; }
if (src->snes.buttons & SNES_BTN_DPAD_DOWN) { dst->buttons |= CPAD_BTN_DPAD_DOWN; }
if (src->snes.buttons & SNES_BTN_DPAD_LEFT) { dst->buttons |= CPAD_BTN_DPAD_LEFT; }
if (src->snes.buttons & SNES_BTN_DPAD_RIGHT) { dst->buttons |= CPAD_BTN_DPAD_RIGHT; }
}
if (src->snes.buttons & SNES_BTN_SELECT) { dst->buttons |= CPAD_BTN_MINUS; }
if (src->snes.buttons & SNES_BTN_START) { dst->buttons |= CPAD_BTN_PLUS; }
if (src->snes.buttons & SNES_BTN_L) { dst->buttons |= CPAD_BTN_TRIG_LEFT; }
if (src->snes.buttons & SNES_BTN_R) { dst->buttons |= CPAD_BTN_TRIG_RIGHT; }
if (IS_SIMULTANEOUS(src->snes.buttons, SNES_BTN_START|SNES_BTN_SELECT|SNES_BTN_L|SNES_BTN_R|SNES_BTN_DPAD_UP)) {
g_current_config.g_snes_nes_mode = 0;
g_current_config.g_snes_analog_dpad = 0;
sync_config();
}
if (IS_SIMULTANEOUS(src->snes.buttons, SNES_BTN_START|SNES_BTN_SELECT|SNES_BTN_L|SNES_BTN_R|SNES_BTN_DPAD_DOWN)) {
g_current_config.g_snes_nes_mode = 1;
g_current_config.g_snes_analog_dpad = 0;
sync_config();
}
if (IS_SIMULTANEOUS(src->snes.buttons, SNES_BTN_START|SNES_BTN_SELECT|SNES_BTN_L|SNES_BTN_R|SNES_BTN_DPAD_LEFT)) {
g_current_config.g_snes_analog_dpad = 1;
g_current_config.g_snes_nes_mode = 0;
sync_config();
}
if (isTripleClick(src->snes.buttons & SNES_BTN_START)) {
dst->buttons |= CPAD_BTN_HOME;
}
// Simulate L/R fully pressed values (like the analogue-less classic controller pro does)
if (dst->buttons & CPAD_BTN_TRIG_LEFT) {
dst->lt = 0xff;
}
if (dst->buttons & CPAD_BTN_TRIG_RIGHT) {
dst->rt = 0xff;
}
break;
case PAD_TYPE_NES:
// if (first_read && src->nes.buttons & NES_BTN_START) {
// disable_config = 1;
// }
dst->controller_id[0] = 'F';
dst->controller_id[1] = 'C';
memcpy(dst->controller_raw_data, src->nes.raw_data, NES_RAW_SIZE);
if (src->nes.buttons & NES_BTN_A) { dst->buttons |= CPAD_BTN_A; }
if (src->nes.buttons & NES_BTN_B) { dst->buttons |= CPAD_BTN_B; }
if (src->nes.buttons & NES_BTN_SELECT) { dst->buttons |= CPAD_BTN_MINUS; }
if (src->nes.buttons & NES_BTN_START) { dst->buttons |= CPAD_BTN_PLUS; }
if (src->nes.buttons & NES_BTN_DPAD_UP) { dst->buttons |= CPAD_BTN_DPAD_UP; }
if (src->nes.buttons & NES_BTN_DPAD_DOWN) { dst->buttons |= CPAD_BTN_DPAD_DOWN; }
if (src->nes.buttons & NES_BTN_DPAD_LEFT) { dst->buttons |= CPAD_BTN_DPAD_LEFT; }
if (src->nes.buttons & NES_BTN_DPAD_RIGHT) { dst->buttons |= CPAD_BTN_DPAD_RIGHT; }
if (isTripleClick(src->nes.buttons & NES_BTN_START)) {
dst->buttons |= CPAD_BTN_HOME;
}
break;
#ifdef WITH_GAMECUBE
case PAD_TYPE_GAMECUBE:
/* Raw data */
dst->controller_id[0] = 'G';
dst->controller_id[1] = 'C';
memcpy(dst->controller_raw_data, src->gc.raw_data, GC_RAW_SIZE);
if (first_read && src->gc.buttons & GC_BTN_START) {
disable_config = 1;
}
switch (g_current_config.g_gc_mapping_mode) {
case MODE_GC_STANDARD:
if (src->gc.buttons & GC_BTN_A) { dst->buttons |= CPAD_BTN_A; }
if (src->gc.buttons & GC_BTN_B) { dst->buttons |= CPAD_BTN_B; }
if (src->gc.buttons & GC_BTN_X) { dst->buttons |= CPAD_BTN_X; }
if (src->gc.buttons & GC_BTN_Y) { dst->buttons |= CPAD_BTN_Y; }
if (src->gc.buttons & GC_BTN_Z) { dst->buttons |= buttons_zl_zr; }
if (src->gc.buttons & GC_BTN_L) { dst->buttons |= CPAD_BTN_TRIG_LEFT; }
if (src->gc.buttons & GC_BTN_R) { dst->buttons |= CPAD_BTN_TRIG_RIGHT; }
break;
case MODE_GC_SNES:
if (src->gc.buttons & GC_BTN_B) { dst->buttons |= CPAD_BTN_Y; }
if (src->gc.buttons & GC_BTN_A) { dst->buttons |= CPAD_BTN_B; }
if (src->gc.buttons & GC_BTN_Y) { dst->buttons |= CPAD_BTN_X; }
if (src->gc.buttons & GC_BTN_X) { dst->buttons |= CPAD_BTN_A; }
if (src->gc.buttons & GC_BTN_Z) { dst->buttons |= CPAD_BTN_MINUS; }
if (src->gc.buttons & GC_BTN_L) { dst->buttons |= CPAD_BTN_TRIG_LEFT; }
if (src->gc.buttons & GC_BTN_R) { dst->buttons |= CPAD_BTN_TRIG_RIGHT; }
break;
case MODE_GC_ZLR:
if (src->gc.buttons & GC_BTN_A) { dst->buttons |= CPAD_BTN_A; }
if (src->gc.buttons & GC_BTN_B) { dst->buttons |= CPAD_BTN_B; }
if (src->gc.buttons & GC_BTN_X) { dst->buttons |= CPAD_BTN_X; }
if (src->gc.buttons & GC_BTN_Y) { dst->buttons |= CPAD_BTN_Y; }
if (src->gc.buttons & GC_BTN_Z) { dst->buttons |= CPAD_BTN_TRIG_RIGHT; }
if (src->gc.buttons & GC_BTN_L) { dst->buttons |= CPAD_BTN_ZL; }
if (src->gc.buttons & GC_BTN_R) { dst->buttons |= CPAD_BTN_ZR; }
break;
case MODE_GC_ASR:
if (src->gc.buttons & GC_BTN_A) { dst->buttons |= CPAD_BTN_ZR; } // Gas
if (src->gc.buttons & GC_BTN_B) { dst->buttons |= CPAD_BTN_A; } // Exchange item
if (src->gc.buttons & GC_BTN_X) { dst->buttons |= CPAD_BTN_B; } // Use item
if (src->gc.buttons & GC_BTN_Y) { dst->buttons |= CPAD_BTN_X; } // ?
if (src->gc.buttons & GC_BTN_Z) { dst->buttons |= CPAD_BTN_B; } // Use item
if (src->gc.buttons & GC_BTN_L) { dst->buttons |= CPAD_BTN_ZL; }// Break/reverse
if (src->gc.buttons & GC_BTN_R) { dst->buttons |= CPAD_BTN_Y; } // Rear view
break;
case MODE_GC_DEV:
if (src->gc.buttons & GC_BTN_A) { dst->buttons |= CPAD_BTN_B; }
if (src->gc.buttons & GC_BTN_B) { dst->buttons |= CPAD_BTN_Y; }
if (src->gc.buttons & GC_BTN_X) { dst->buttons |= CPAD_BTN_A; }
if (src->gc.buttons & GC_BTN_Y) { dst->buttons |= CPAD_BTN_X; }
if (src->gc.buttons & GC_BTN_L) { dst->buttons |= CPAD_BTN_TRIG_LEFT; }
if (src->gc.buttons & GC_BTN_R) { dst->buttons |= CPAD_BTN_TRIG_RIGHT; }
if (src->gc.buttons & GC_BTN_Z) { dst->buttons |= CPAD_BTN_ZR; }
break;
case MODE_GC_EXTRA1:
/* This was suggested for Super mario 3D World */
if (src->gc.buttons & GC_BTN_A) { dst->buttons |= CPAD_BTN_A; } // Jump/accept
if (src->gc.buttons & GC_BTN_B) { dst->buttons |= CPAD_BTN_X; } // Run/ability
if (src->gc.buttons & GC_BTN_X) { dst->buttons |= CPAD_BTN_TRIG_RIGHT; } // Bubble
if (src->gc.buttons & GC_BTN_Y) { dst->buttons |= CPAD_BTN_B; } // Cancel/Change character
if (src->gc.buttons & GC_BTN_L) { dst->buttons |= CPAD_BTN_ZL; } // Stomp/Long jump
if (src->gc.buttons & GC_BTN_R) { dst->buttons |= CPAD_BTN_ZR; } // Stomp/Long jump
if (src->gc.buttons & GC_BTN_Z) { dst->buttons |= CPAD_BTN_MINUS; } // Stored power
// Main stick -> Movement
// C-Stick -> Camera
break;
}
if (src->gc.buttons & GC_BTN_START) { dst->buttons |= CPAD_BTN_PLUS; }
if (src->gc.buttons & GC_BTN_DPAD_UP) { dst->buttons |= CPAD_BTN_DPAD_UP; }
if (src->gc.buttons & GC_BTN_DPAD_DOWN) { dst->buttons |= CPAD_BTN_DPAD_DOWN; }
if (src->gc.buttons & GC_BTN_DPAD_LEFT) { dst->buttons |= CPAD_BTN_DPAD_LEFT; }
if (src->gc.buttons & GC_BTN_DPAD_RIGHT) { dst->buttons |= CPAD_BTN_DPAD_RIGHT; }
// Main/Left stick to classic left stick
dst->lx = src->gc.x;
dst->ly = src->gc.y;
// C-Stick/right stick to classic right stick
dst->rx = src->gc.cx;
dst->ry = src->gc.cy;
// Left/right triggers
dst->lt = src->gc.lt;
dst->rt = src->gc.rt;
if (IS_SIMULTANEOUS(src->gc.buttons, GC_BTN_A|GC_BTN_B|GC_BTN_X|GC_BTN_Y|GC_BTN_DPAD_UP)) {
chgMap(&g_current_config.g_gc_mapping_mode, MODE_GC_STANDARD);
}
else if (IS_SIMULTANEOUS(src->gc.buttons, GC_BTN_A|GC_BTN_B|GC_BTN_X|GC_BTN_Y|GC_BTN_DPAD_DOWN)) {
chgMap(&g_current_config.g_gc_mapping_mode, MODE_GC_SNES);
}
else if (IS_SIMULTANEOUS(src->gc.buttons, GC_BTN_A|GC_BTN_B|GC_BTN_X|GC_BTN_Y|GC_BTN_DPAD_LEFT)) {
chgMap(&g_current_config.g_gc_mapping_mode, MODE_GC_ZLR);
}
else if (IS_SIMULTANEOUS(src->gc.buttons, GC_BTN_A|GC_BTN_B|GC_BTN_X|GC_BTN_Y|GC_BTN_DPAD_RIGHT)) {
chgMap(&g_current_config.g_gc_mapping_mode, MODE_GC_ASR);
}
else if (IS_SIMULTANEOUS(src->gc.buttons, GC_BTN_A|GC_BTN_B|GC_BTN_X|GC_BTN_Y|GC_BTN_DPAD_RIGHT)) {
chgMap(&g_current_config.g_gc_mapping_mode, MODE_GC_ASR);
}
else if (IS_SIMULTANEOUS(src->gc.buttons, GC_BTN_A|GC_BTN_B|GC_BTN_X|GC_BTN_Y|GC_BTN_Z)) {
if (src->gc.cx < -64) { // A + B + X + Y + Z + C-Left
chgMap(&g_current_config.g_gc_mapping_mode, MODE_GC_DEV);
}
if (src->gc.cx > 64) { // A + B + X + Y + Z + C-Right
chgMap(&g_current_config.g_gc_mapping_mode, MODE_GC_EXTRA1);
}
/*
// Combo for HOME
if (src->gc.cy < -64) {
dst->buttons |= CPAD_BTN_HOME;
}*/
} else if (IS_SIMULTANEOUS(src->gc.buttons, GC_BTN_A|GC_BTN_B|GC_BTN_X|GC_BTN_Y|GC_BTN_L)) {
if (!waiting_release) {
g_current_config.easy_triggers = !g_current_config.easy_triggers;
sync_config();
waiting_release = 1;
}
} else {
if (!IS_SIMULTANEOUS(src->gc.buttons, GC_BTN_A|GC_BTN_B|GC_BTN_X|GC_BTN_Y)) {
waiting_release = 0;
}
}
if (isTripleClick(src->gc.buttons & GC_BTN_START)) {
dst->buttons |= CPAD_BTN_HOME;
}
break;
#endif
#ifdef WITH_N64
case PAD_TYPE_N64:
dst->controller_id[0] = '6';
dst->controller_id[1] = '4';
memcpy(dst->controller_raw_data, src->n64.raw_data, N64_RAW_SIZE);
if (first_read && src->n64.buttons & N64_BTN_START) {
disable_config = 1;
}
if (IS_SIMULTANEOUS(src->n64.buttons, N64_BTN_L|N64_BTN_R|N64_BTN_Z|N64_BTN_DPAD_UP)) {
chgMap(&g_current_config.g_n64_mapping_mode, MODE_N64_STANDARD);
} else if (IS_SIMULTANEOUS(src->n64.buttons, N64_BTN_L|N64_BTN_R|N64_BTN_Z|N64_BTN_DPAD_DOWN)) {
chgMap(&g_current_config.g_n64_mapping_mode, MODE_MARIOKART64);
} else if (IS_SIMULTANEOUS(src->n64.buttons, N64_BTN_L|N64_BTN_R|N64_BTN_Z|N64_BTN_DPAD_LEFT)) {
chgMap(&g_current_config.g_n64_mapping_mode, MODE_OCARINA);
} else if (IS_SIMULTANEOUS(src->n64.buttons, N64_BTN_L|N64_BTN_R|N64_BTN_Z|N64_BTN_DPAD_RIGHT)) {
chgMap(&g_current_config.g_n64_mapping_mode, MODE_SSMB);
} else if (IS_SIMULTANEOUS(src->n64.buttons, N64_BTN_L|N64_BTN_R|N64_BTN_Z|N64_BTN_C_UP)) {
chgMap(&g_current_config.g_n64_mapping_mode, MODE_SIN_AND_PUNISHMENT);
} else if (IS_SIMULTANEOUS(src->n64.buttons, N64_BTN_L|N64_BTN_R|N64_BTN_Z|N64_BTN_C_DOWN)) {
chgMap(&g_current_config.g_n64_mapping_mode, MODE_OGRE_BATTLE);
}
else if (IS_SIMULTANEOUS(src->n64.buttons, N64_BTN_L|N64_BTN_R|N64_BTN_Z|N64_BTN_C_LEFT)) {
chgMap(&g_current_config.g_n64_mapping_mode, MODE_F_ZERO_X);
} else if (IS_SIMULTANEOUS(src->n64.buttons, N64_BTN_L|N64_BTN_R|N64_BTN_Z|N64_BTN_C_RIGHT)) {
chgMap(&g_current_config.g_n64_mapping_mode, MODE_YOSHI_STORY);
} else if (IS_SIMULTANEOUS(src->n64.buttons, N64_BTN_L|N64_BTN_R|N64_BTN_Z)) {
if (src->n64.y < -50) { // Stick Down
chgMap(&g_current_config.g_n64_mapping_mode, MODE_ODYSSEY);
}
}
// Curves
if (!disable_config) {
if (IS_SIMULTANEOUS(src->n64.buttons, N64_BTN_L|N64_BTN_R|N64_BTN_Z|N64_BTN_A)) {
// Default
g_current_config.g_n64_curve_id = RLUT_V1_5;
sync_config();
} else if (IS_SIMULTANEOUS(src->n64.buttons, N64_BTN_L|N64_BTN_R|N64_BTN_Z|N64_BTN_B)) {
// Alternate
g_current_config.g_n64_curve_id = RLUT_V1_4;
sync_config();
}
// Toggle the old ZL+ZR behaviour
if (IS_SIMULTANEOUS(src->n64.buttons, N64_BTN_L|N64_BTN_R|N64_BTN_Z))
{
if (src->n64.y > +50) { // Stick Up
if (!waiting_release) {
g_current_config.merge_zl_zr = !g_current_config.merge_zl_zr;
sync_config();
waiting_release = 1;
}
}
} else {
waiting_release = 0;
}
}
if (src->n64.buttons & N64_BTN_A) { dst->buttons |= CPAD_BTN_A; }
if (src->n64.buttons & N64_BTN_B) { dst->buttons |= CPAD_BTN_B; }
if (src->n64.buttons & N64_BTN_START) { dst->buttons |= CPAD_BTN_PLUS; }
if (g_current_config.g_n64_mapping_mode != MODE_TEST) {
if (src->n64.buttons & N64_BTN_DPAD_UP) { dst->buttons |= CPAD_BTN_DPAD_UP; }
if (src->n64.buttons & N64_BTN_DPAD_DOWN) { dst->buttons |= CPAD_BTN_DPAD_DOWN; }
if (src->n64.buttons & N64_BTN_DPAD_LEFT) { dst->buttons |= CPAD_BTN_DPAD_LEFT; }
if (src->n64.buttons & N64_BTN_DPAD_RIGHT) { dst->buttons |= CPAD_BTN_DPAD_RIGHT; }
}
//g_current_config.g_n64_mapping_mode = MODE_TEST;
switch (g_current_config.g_n64_mapping_mode)
{
case MODE_TEST:
case MODE_N64_STANDARD:
if (src->n64.buttons & N64_BTN_Z) { dst->buttons |= buttons_zl_zr; }
if (src->n64.buttons & N64_BTN_R) { dst->buttons |= CPAD_BTN_TRIG_RIGHT; }
if (src->n64.buttons & N64_BTN_L) { dst->buttons |= CPAD_BTN_TRIG_LEFT; }
// Pushing all C directions at once sends X and Y down (wii64 menu)
// This is made to work only in standard mode because that is the mode
// suitable for wii64.
if (IS_SIMULTANEOUS(src->n64.buttons,
N64_BTN_C_RIGHT | N64_BTN_C_LEFT | N64_BTN_C_UP | N64_BTN_C_DOWN | N64_BTN_DPAD_LEFT | N64_BTN_Z)) {
dst->buttons |= CPAD_BTN_Y|CPAD_BTN_X;
}
break;
case MODE_MARIOKART64:
if (src->n64.buttons & N64_BTN_Z) { dst->buttons |= CPAD_BTN_TRIG_LEFT; }
if (src->n64.buttons & N64_BTN_R) { dst->buttons |= CPAD_BTN_TRIG_RIGHT; }
if (src->n64.buttons & N64_BTN_L) { dst->buttons |= buttons_zl_zr; }
break;
case MODE_OCARINA:
if (src->n64.buttons & N64_BTN_Z) { dst->buttons |= CPAD_BTN_TRIG_LEFT; }
if (src->n64.buttons & N64_BTN_R) { dst->buttons |= CPAD_BTN_TRIG_RIGHT; }
if (src->n64.buttons & N64_BTN_L) { dst->buttons |= CPAD_BTN_DPAD_DOWN; }
break;
case MODE_SSMB:
if (src->n64.buttons & N64_BTN_L) { dst->buttons |= CPAD_BTN_DPAD_DOWN; }
if (src->n64.buttons & N64_BTN_R) { dst->buttons |= buttons_zl_zr; }
if (src->n64.buttons & N64_BTN_Z) { dst->buttons |= CPAD_BTN_TRIG_LEFT | CPAD_BTN_TRIG_RIGHT; }
if (src->n64.buttons & N64_BTN_C_LEFT) { dst->buttons |= CPAD_BTN_Y; }
if (src->n64.buttons & N64_BTN_C_DOWN) { dst->buttons |= CPAD_BTN_X; }
break;
case MODE_SIN_AND_PUNISHMENT:
if (src->n64.buttons & N64_BTN_L) { dst->buttons |= buttons_zl_zr; }
if (src->n64.buttons & N64_BTN_R) { dst->buttons |= CPAD_BTN_TRIG_RIGHT; }
if (src->n64.buttons & N64_BTN_Z) { dst->buttons |= CPAD_BTN_TRIG_LEFT; }
if (src->n64.buttons & N64_BTN_C_LEFT) { dst->buttons |= CPAD_BTN_Y; }
if (src->n64.buttons & N64_BTN_C_RIGHT) { dst->buttons |= CPAD_BTN_X; }
break;
case MODE_OGRE_BATTLE:
if (src->n64.buttons & N64_BTN_L) { dst->buttons |= CPAD_BTN_TRIG_LEFT; }
if (src->n64.buttons & N64_BTN_R) { dst->buttons |= CPAD_BTN_TRIG_RIGHT; }
if (src->n64.buttons & N64_BTN_Z) { dst->buttons |= CPAD_BTN_TRIG_LEFT; }
break;
case MODE_F_ZERO_X: // Mapping 6
if (src->n64.buttons & N64_BTN_L) { dst->buttons |= CPAD_BTN_DPAD_RIGHT; }
if (src->n64.buttons & N64_BTN_R) { dst->buttons |= CPAD_BTN_TRIG_RIGHT; }
if (src->n64.buttons & N64_BTN_Z) { dst->buttons |= CPAD_BTN_TRIG_LEFT; }
if (src->n64.buttons & N64_BTN_C_DOWN) { dst->buttons |= CPAD_BTN_X; }
if (src->n64.buttons & N64_BTN_C_LEFT) { dst->buttons |= CPAD_BTN_Y; }
if (src->n64.buttons & N64_BTN_C_RIGHT) { dst->buttons |= buttons_zl_zr; }
break;
case MODE_YOSHI_STORY: // Mapping 7
if (src->n64.buttons & N64_BTN_L) { dst->buttons |= buttons_zl_zr; }
if (src->n64.buttons & N64_BTN_R) { dst->buttons |= CPAD_BTN_TRIG_RIGHT; }
if (src->n64.buttons & N64_BTN_Z) { dst->buttons |= CPAD_BTN_X | CPAD_BTN_Y; }
break;
case MODE_ODYSSEY: // Mapping 8
if (src->n64.buttons & N64_BTN_Z) { dst->buttons |= buttons_zl_zr; }
if (src->n64.buttons & N64_BTN_R) { dst->buttons |= CPAD_BTN_TRIG_RIGHT; }
if (src->n64.buttons & N64_BTN_L) { dst->buttons |= CPAD_BTN_TRIG_LEFT; }
// Undo the AB buttons
dst->buttons &= ~(CPAD_BTN_B|CPAD_BTN_A);
if (src->n64.buttons & N64_BTN_A) { dst->buttons |= CPAD_BTN_B; }
if (src->n64.buttons & N64_BTN_B) { dst->buttons |= CPAD_BTN_Y; }
if (src->n64.buttons & N64_BTN_C_LEFT) { dst->buttons |= CPAD_BTN_X; }
if (src->n64.buttons & N64_BTN_C_DOWN) { dst->buttons |= CPAD_BTN_A; }
// anything better to do with those?
if (src->n64.buttons & N64_BTN_C_UP) { dst->ry = C_DEFLECTION; }
if (src->n64.buttons & N64_BTN_C_RIGHT) { dst->rx = C_DEFLECTION; }
break;
}
if (g_current_config.g_n64_mapping_mode != MODE_TEST)
{
switch (g_current_config.g_n64_mapping_mode)
{
case MODE_SIN_AND_PUNISHMENT:
// In sin and punishment, both the left and right analog sticks on the wii classic
// controller are used for aim. On a N64 controller, C-left and C-right are used to
// move. Up down are not used and we do not want accidental button presses there to
// mess with aiming!
case MODE_F_ZERO_X:
// In F-Zero, 3 of the C-stick directions are mapped to buttons.
break;
case MODE_ODYSSEY:
// all done above
break;
default:
if (src->n64.buttons & N64_BTN_C_UP) { dst->ry = C_DEFLECTION; }
if (src->n64.buttons & N64_BTN_C_DOWN) { dst->ry = -C_DEFLECTION; }
if (src->n64.buttons & N64_BTN_C_LEFT) { dst->rx = -C_DEFLECTION; }
if (src->n64.buttons & N64_BTN_C_RIGHT) { dst->rx = C_DEFLECTION; }
}
}
else {
static char active;
// Special test mode
if (src->n64.buttons & N64_BTN_C_UP) { if (!(active&1)) { test_y++; active |= 1; } } else { active &= ~1; }
if (src->n64.buttons & N64_BTN_C_DOWN) { if (!(active&2)) { test_y--; active |= 2; } } else { active &= ~2; }
if (src->n64.buttons & N64_BTN_C_LEFT) { if (!(active&4)) { test_x++; active |= 4; } } else { active &= ~4; }
if (src->n64.buttons & N64_BTN_C_RIGHT) { if (!(active&8)) { test_x--; active |= 8; } } else { active &= ~8; }
}
if (g_current_config.g_n64_mapping_mode != MODE_TEST) {
dst->lx = src->n64.x;
dst->ly = src->n64.y;
} else {
if (src->n64.buttons & N64_BTN_DPAD_UP) { dst->ly = test_y; }
if (src->n64.buttons & N64_BTN_DPAD_DOWN) { dst->ly = -test_y; }
if (src->n64.buttons & N64_BTN_DPAD_LEFT) { dst->lx = test_x; }
if (src->n64.buttons & N64_BTN_DPAD_RIGHT) { dst->lx = -test_x; }
}
if (isTripleClick(src->n64.buttons & N64_BTN_START)) {
dst->buttons |= CPAD_BTN_HOME;
}
// Simulate L/R fully pressed values (like the analogue-less classic controller pro does)
if (dst->buttons & CPAD_BTN_TRIG_LEFT) {
dst->lt = 0xff;
}
if (dst->buttons & CPAD_BTN_TRIG_RIGHT) {
dst->rt = 0xff;
}
/*
if (src->n64.buttons & N64_BTN_C_UP) { dst->ly = 100; }
if (src->n64.buttons & N64_BTN_C_DOWN) { dst->ly = -100; }
if (src->n64.buttons & N64_BTN_C_LEFT) { dst->lx = -100; }
if (src->n64.buttons & N64_BTN_C_RIGHT) { dst->lx = 100; }
*/
break;
#endif
#ifdef WITH_DB9
case PAD_TYPE_SMS:
if (src->db9.buttons & DB9_BTN_DPAD_UP) { dst->buttons |= CPAD_BTN_DPAD_UP; }
if (src->db9.buttons & DB9_BTN_DPAD_DOWN) { dst->buttons |= CPAD_BTN_DPAD_DOWN; }
if (src->db9.buttons & DB9_BTN_DPAD_LEFT) { dst->buttons |= CPAD_BTN_DPAD_LEFT; }
if (src->db9.buttons & DB9_BTN_DPAD_RIGHT) { dst->buttons |= CPAD_BTN_DPAD_RIGHT; }
if (src->db9.buttons & DB9_BTN_1) { dst->buttons |= CPAD_BTN_B; }
if (src->db9.buttons & DB9_BTN_2) { dst->buttons |= CPAD_BTN_A; }
break;
case PAD_TYPE_MD:
if (src->db9.buttons & DB9_BTN_DPAD_UP) { dst->buttons |= CPAD_BTN_DPAD_UP; }
if (src->db9.buttons & DB9_BTN_DPAD_DOWN) { dst->buttons |= CPAD_BTN_DPAD_DOWN; }
if (src->db9.buttons & DB9_BTN_DPAD_LEFT) { dst->buttons |= CPAD_BTN_DPAD_LEFT; }
if (src->db9.buttons & DB9_BTN_DPAD_RIGHT) { dst->buttons |= CPAD_BTN_DPAD_RIGHT; }
if (src->db9.buttons & DB9_BTN_A) { dst->buttons |= CPAD_BTN_Y; }
if (src->db9.buttons & DB9_BTN_B) { dst->buttons |= CPAD_BTN_B; }
if (src->db9.buttons & DB9_BTN_C) { dst->buttons |= CPAD_BTN_A; }
if (src->db9.buttons & DB9_BTN_X) { dst->buttons |= CPAD_BTN_TRIG_LEFT; }
if (src->db9.buttons & DB9_BTN_Y) { dst->buttons |= CPAD_BTN_X; }
if (src->db9.buttons & DB9_BTN_Z) { dst->buttons |= CPAD_BTN_TRIG_RIGHT; }
if (src->db9.buttons & DB9_BTN_START) { dst->buttons |= CPAD_BTN_PLUS; }
if (src->db9.buttons & DB9_BTN_MODE) { dst->buttons |= CPAD_BTN_ZR; }
if (isTripleClick(src->db9.buttons & DB9_BTN_START)) {
dst->buttons |= CPAD_BTN_HOME;
}
break;
#endif
}
}