forked from Cpasjuste/uae4all2
-
Notifications
You must be signed in to change notification settings - Fork 10
/
menu_controls.cpp
executable file
·1319 lines (1275 loc) · 36.9 KB
/
menu_controls.cpp
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
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sysconfig.h"
#include "sysdeps.h"
#include "config.h"
#include "menu.h"
#include <sys/stat.h>
#include <unistd.h>
#if defined(__PSP2__) // NOT __SWITCH__
#include "psp2-dirent.h"
#else
#include <dirent.h>
#endif
#include "uae.h"
#include "options.h"
#include "sound.h"
#include <SDL.h>
#include "gp2x.h"
#include <SDL_ttf.h>
#include "menu_config.h"
#if defined(__PSP2__) || defined(__SWITCH__)
#define SDL_PollEvent PSP2_PollEvent
#endif
#define MAX_CUSTOM_ID 96
#define MIN_CUSTOM_ID -28
const char *text_str_controls_separator="---------------------------------------";
const char *text_str_controls_title= " Custom Controls -";
char tmpchar[256];
char mapping[32]="";
int menuControls = 0;
extern int quit_pressed_in_submenu;
extern int emulating;
extern int nr_joysticks;
extern void close_joystick();
extern void init_joystick();
enum {
MENUCONTROLS_RETURNMAIN = 0,
#ifdef ANDROIDSDL
MENUCONTROLS_ONSCREEN,
#endif
MENUCONTROLS_CUSTOM_ON_OFF,
#if defined(__PSP2__) || defined(__SWITCH__)
MENUCONTROLS_CUSTOM_CONTROLLER_NR,
MENUCONTROLS_CUSTOMSET,
#else
MENUCONTROLS_DPAD,
#endif
MENUCONTROLS_UP,
MENUCONTROLS_DOWN,
MENUCONTROLS_LEFT,
MENUCONTROLS_RIGHT,
MENUCONTROLS_A,
MENUCONTROLS_Y,
MENUCONTROLS_X,
MENUCONTROLS_B,
MENUCONTROLS_L,
MENUCONTROLS_R,
#ifdef __SWITCH__
MENUCONTROLS_L2,
MENUCONTROLS_R2,
#endif
MENUCONTROLS_END
};
// remember to also edit MIN_CUSTOM_ID and MAX_CUSTOM_ID
static void getMapping(int customId)
{
switch(customId)
{
case -28: strcpy(mapping, "Quick Load"); break;
case -27: strcpy(mapping, "Quick Save"); break;
case -26: strcpy(mapping, "Speed Up Mouse"); break;
case -25: strcpy(mapping, "Slow Down Mouse"); break;
case -24: strcpy(mapping, "4th Joystick RIGHT"); break;
case -23: strcpy(mapping, "4th Joystick LEFT"); break;
case -22: strcpy(mapping, "4th Joystick DOWN"); break;
case -21: strcpy(mapping, "4th Joystick UP"); break;
case -20: strcpy(mapping, "4th Joystick Fire 2"); break;
case -19: strcpy(mapping, "4th Joystick Fire 1"); break;
case -18: strcpy(mapping, "3rd Joystick RIGHT"); break;
case -17: strcpy(mapping, "3rd Joystick LEFT"); break;
case -16: strcpy(mapping, "3rd Joystick DOWN"); break;
case -15: strcpy(mapping, "3rd Joystick UP"); break;
case -14: strcpy(mapping, "3rd Joystick Fire 2"); break;
case -13: strcpy(mapping, "3rd Joystick Fire 1"); break;
case -12: strcpy(mapping, "2nd Joystick RIGHT"); break;
case -11: strcpy(mapping, "2nd Joystick LEFT"); break;
case -10: strcpy(mapping, "2nd Joystick DOWN"); break;
case -9: strcpy(mapping, "2nd Joystick UP"); break;
case -8: strcpy(mapping, "Joystick RIGHT"); break;
case -7: strcpy(mapping, "Joystick LEFT"); break;
case -6: strcpy(mapping, "Joystick DOWN"); break;
case -5: strcpy(mapping, "Joystick UP (Jump)"); break;
case -4: strcpy(mapping, "Joystick Fire Button 2"); break;
case -3: strcpy(mapping, "Joystick Fire Button 1"); break;
case -2: strcpy(mapping, "Mouse Right Btn (Joy2 Btn2)"); break;
case -1: strcpy(mapping, "Mouse Left Btn (Joy2 Btn1)"); break;
case 0: strcpy(mapping, "---"); break;
case 1: strcpy(mapping, "arrow UP"); break;
case 2: strcpy(mapping, "arrow DOWN"); break;
case 3: strcpy(mapping, "arrow LEFT"); break;
case 4: strcpy(mapping, "arrow RIGHT"); break;
case 5: strcpy(mapping, "numpad 0"); break;
case 6: strcpy(mapping, "numpad 1"); break;
case 7: strcpy(mapping, "numpad 2"); break;
case 8: strcpy(mapping, "numpad 3"); break;
case 9: strcpy(mapping, "numpad 4"); break;
case 10: strcpy(mapping, "numpad 5"); break;
case 11: strcpy(mapping, "numpad 6"); break;
case 12: strcpy(mapping, "numpad 7"); break;
case 13: strcpy(mapping, "numpad 8"); break;
case 14: strcpy(mapping, "numpad 9"); break;
case 15: strcpy(mapping, "numpad ENTER"); break;
case 16: strcpy(mapping, "numpad DIVIDE"); break;
case 17: strcpy(mapping, "numpad MULTIPLY"); break;
case 18: strcpy(mapping, "numpad MINUS"); break;
case 19: strcpy(mapping, "numpad PLUS"); break;
case 20: strcpy(mapping, "numpad DELETE"); break;
case 21: strcpy(mapping, "numpad LEFT PARENTHESIS"); break;
case 22: strcpy(mapping, "numpad RIGHT PARENTHESIS"); break;
case 23: strcpy(mapping, "SPACE"); break;
case 24: strcpy(mapping, "BACKSPACE"); break;
case 25: strcpy(mapping, "TAB"); break;
case 26: strcpy(mapping, "RETURN"); break;
case 27: strcpy(mapping, "ESCAPE"); break;
case 28: strcpy(mapping, "DELETE"); break;
case 29: strcpy(mapping, "left SHIFT"); break;
case 30: strcpy(mapping, "right SHIFT"); break;
case 31: strcpy(mapping, "CAPS LOCK"); break;
case 32: strcpy(mapping, "CTRL"); break;
case 33: strcpy(mapping, "left ALT"); break;
case 34: strcpy(mapping, "right ALT"); break;
case 35: strcpy(mapping, "left AMIGA key"); break;
case 36: strcpy(mapping, "right AMIGA key"); break;
case 37: strcpy(mapping, "HELP"); break;
case 38: strcpy(mapping, "left bracket"); break;
case 39: strcpy(mapping, "right bracket"); break;
case 40: strcpy(mapping, "semicolon"); break;
case 41: strcpy(mapping, "comma"); break;
case 42: strcpy(mapping, "period"); break;
case 43: strcpy(mapping, "slash"); break;
case 44: strcpy(mapping, "backslash"); break;
case 45: strcpy(mapping, "quote"); break;
case 46: strcpy(mapping, "numbersign"); break;
case 47: strcpy(mapping, "less than - greater than"); break;
case 48: strcpy(mapping, "backquote"); break;
case 49: strcpy(mapping, "minus"); break;
case 50: strcpy(mapping, "equal"); break;
case 51: strcpy(mapping, "A"); break;
case 52: strcpy(mapping, "B"); break;
case 53: strcpy(mapping, "C"); break;
case 54: strcpy(mapping, "D"); break;
case 55: strcpy(mapping, "E"); break;
case 56: strcpy(mapping, "F"); break;
case 57: strcpy(mapping, "G"); break;
case 58: strcpy(mapping, "H"); break;
case 59: strcpy(mapping, "I"); break;
case 60: strcpy(mapping, "J"); break;
case 61: strcpy(mapping, "K"); break;
case 62: strcpy(mapping, "L"); break;
case 63: strcpy(mapping, "M"); break;
case 64: strcpy(mapping, "N"); break;
case 65: strcpy(mapping, "O"); break;
case 66: strcpy(mapping, "P"); break;
case 67: strcpy(mapping, "Q"); break;
case 68: strcpy(mapping, "R"); break;
case 69: strcpy(mapping, "S"); break;
case 70: strcpy(mapping, "T"); break;
case 71: strcpy(mapping, "U"); break;
case 72: strcpy(mapping, "V"); break;
case 73: strcpy(mapping, "W"); break;
case 74: strcpy(mapping, "X"); break;
case 75: strcpy(mapping, "Y"); break;
case 76: strcpy(mapping, "Z"); break;
case 77: strcpy(mapping, "1"); break;
case 78: strcpy(mapping, "2"); break;
case 79: strcpy(mapping, "3"); break;
case 80: strcpy(mapping, "4"); break;
case 81: strcpy(mapping, "5"); break;
case 82: strcpy(mapping, "6"); break;
case 83: strcpy(mapping, "7"); break;
case 84: strcpy(mapping, "8"); break;
case 85: strcpy(mapping, "9"); break;
case 86: strcpy(mapping, "0"); break;
case 87: strcpy(mapping, "F1"); break;
case 88: strcpy(mapping, "F2"); break;
case 89: strcpy(mapping, "F3"); break;
case 90: strcpy(mapping, "F4"); break;
case 91: strcpy(mapping, "F5"); break;
case 92: strcpy(mapping, "F6"); break;
case 93: strcpy(mapping, "F7"); break;
case 94: strcpy(mapping, "F8"); break;
case 95: strcpy(mapping, "F9"); break;
case 96: strcpy(mapping, "F10");
}
/*
-28 quick load savestate
-27 quick save savestate
-26 fast mouse modifier
-25 slow mouse modifier
-12 2nd joy right
-11 2nd joy left
-10 2nd joy down
-9 2nd joy up
-8 joy right
-7 joy left
-6 joy down
-5 joy up
-4 joy fire button 2
-3 joy fire button 1
-2 mouse right button
-1 mouse left button
0 ---
1 AK_UP 0x4C
2 AK_DN 0x4D
3 AK_LF 0x4F
4 AK_RT 0x4E
5 AK_NP0 0x0F
6 AK_NP1 0x1D
7 AK_NP2 0x1E
8 AK_NP3 0x1F
9 AK_NP4 0x2D
10 AK_NP5 0x2E
11 AK_NP6 0x2F
12 AK_NP7 0x3D
13 AK_NP8 0x3E
14 AK_NP9 0x3F
15 AK_ENT 0x43
16 AK_NPDIV 0x5C
17 AK_NPMUL 0x5D
18 AK_NPSUB 0x4A
19 AK_NPADD 0x5E
20 AK_NPDEL 0x3C
21 AK_NPLPAREN 0x5A
22 AK_NPRPAREN 0x5B
23 AK_SPC 0x40
24 AK_BS 0x41
25 AK_TAB 0x42
26 AK_RET 0x44
27 AK_ESC 0x45
28 AK_DEL 0x46
29 AK_LSH 0x60
30 AK_RSH 0x61
31 AK_CAPSLOCK 0x62
32 AK_CTRL 0x63
33 AK_LALT 0x64
34 AK_RALT 0x65
35 AK_LAMI 0x66
36 AK_RAMI 0x67
37 AK_HELP 0x5F
38 AK_LBRACKET 0x1A
39 AK_RBRACKET 0x1B
40 AK_SEMICOLON 0x29
41 AK_COMMA 0x38
42 AK_PERIOD 0x39
43 AK_SLASH 0x3A
44 AK_BACKSLASH 0x0D
45 AK_QUOTE 0x2A
46 AK_NUMBERSIGN 0x2B
47 AK_LTGT 0x30
48 AK_BACKQUOTE 0x00
49 AK_MINUS 0x0B
50 AK_EQUAL 0x0C
51 AK_A 0x20
52 AK_B 0x35
53 AK_C 0x33
54 AK_D 0x22
55 AK_E 0x12
56 AK_F 0x23
57 AK_G 0x24
58 AK_H 0x25
59 AK_I 0x17
60 AK_J 0x26
61 AK_K 0x27
62 AK_L 0x28
63 AK_M 0x37
64 AK_N 0x36
65 AK_O 0x18
66 AK_P 0x19
67 AK_Q 0x10
68 AK_R 0x13
69 AK_S 0x21
70 AK_T 0x14
71 AK_U 0x16
72 AK_V 0x34
73 AK_W 0x11
74 AK_X 0x32
75 AK_Y 0x15
76 AK_Z 0x31
77 AK_0 0x0A
78 AK_1 0x01
79 AK_2 0x02
80 AK_3 0x03
81 AK_4 0x04
82 AK_5 0x05
83 AK_6 0x06
84 AK_7 0x07
85 AK_8 0x08
86 AK_9 0x09
87 AK_F1 0x50
88 AK_F2 0x51
89 AK_F3 0x52
90 AK_F4 0x53
91 AK_F5 0x54
92 AK_F6 0x55
93 AK_F7 0x56
94 AK_F8 0x57
95 AK_F9 0x58
96 AK_F10 0x59*/
}
#if defined(__PSP2__) || defined(__SWITCH__)
void mapback_custom_controls() // assign currently used custom set to custom control set
//This is called after whenever the user changes the currently displayed controls
//or the currently displayed controller Nr
{
int i = mainMenu_custom_currentlyEditingControllerNr;
switch (mainMenu_custom_controlSet)
{
case 0:
mainMenu_custom1_up[i] = mainMenu_custom_up[i];
mainMenu_custom1_down[i] = mainMenu_custom_down[i];
mainMenu_custom1_left[i] = mainMenu_custom_left[i];
mainMenu_custom1_right[i] = mainMenu_custom_right[i];
mainMenu_custom1_A[i] = mainMenu_custom_A[i];
mainMenu_custom1_B[i] = mainMenu_custom_B[i];
mainMenu_custom1_X[i] = mainMenu_custom_X[i];
mainMenu_custom1_Y[i] = mainMenu_custom_Y[i];
mainMenu_custom1_L[i] = mainMenu_custom_L[i];
mainMenu_custom1_R[i] = mainMenu_custom_R[i];
#ifdef __SWITCH__
mainMenu_custom1_L2[i] = mainMenu_custom_L2[i];
mainMenu_custom1_R2[i] = mainMenu_custom_R2[i];
mainMenu_custom1_L3[i] = mainMenu_custom_L3[i];
mainMenu_custom1_R3[i] = mainMenu_custom_R3[i];
#endif
break;
case 1:
mainMenu_custom2_up[i] = mainMenu_custom_up[i];
mainMenu_custom2_down[i] = mainMenu_custom_down[i];
mainMenu_custom2_left[i] = mainMenu_custom_left[i];
mainMenu_custom2_right[i] = mainMenu_custom_right[i];
mainMenu_custom2_A[i] = mainMenu_custom_A[i];
mainMenu_custom2_B[i] = mainMenu_custom_B[i];
mainMenu_custom2_X[i] = mainMenu_custom_X[i];
mainMenu_custom2_Y[i] = mainMenu_custom_Y[i];
mainMenu_custom2_L[i] = mainMenu_custom_L[i];
mainMenu_custom2_R[i] = mainMenu_custom_R[i];
#ifdef __SWITCH__
mainMenu_custom2_L2[i] = mainMenu_custom_L2[i];
mainMenu_custom2_R2[i] = mainMenu_custom_R2[i];
mainMenu_custom2_L3[i] = mainMenu_custom_L3[i];
mainMenu_custom2_R3[i] = mainMenu_custom_R3[i];
#endif
break;
case 2:
mainMenu_custom3_up[i] = mainMenu_custom_up[i];
mainMenu_custom3_down[i] = mainMenu_custom_down[i];
mainMenu_custom3_left[i] = mainMenu_custom_left[i];
mainMenu_custom3_right[i] = mainMenu_custom_right[i];
mainMenu_custom3_A[i] = mainMenu_custom_A[i];
mainMenu_custom3_B[i] = mainMenu_custom_B[i];
mainMenu_custom3_X[i] = mainMenu_custom_X[i];
mainMenu_custom3_Y[i] = mainMenu_custom_Y[i];
mainMenu_custom3_L[i] = mainMenu_custom_L[i];
mainMenu_custom3_R[i] = mainMenu_custom_R[i];
#ifdef __SWITCH__
mainMenu_custom3_L2[i] = mainMenu_custom_L2[i];
mainMenu_custom3_R2[i] = mainMenu_custom_R2[i];
mainMenu_custom3_L3[i] = mainMenu_custom_L3[i];
mainMenu_custom3_R3[i] = mainMenu_custom_R3[i];
#endif
break;
default:
break;
}
}
#endif //__PSP2__
static void draw_controlsMenu(int c)
{
#if defined(__PSP2__) || defined(__SWITCH__)
mainMenu_custom_dpad=0; //on Vita, always use full custom configs that remap the dpad
#endif
int ctrlNr = mainMenu_custom_currentlyEditingControllerNr;
int leftMargin=3;
int tabstop1 = 17;
int tabstop2 = 19;
int tabstop3 = 21;
int tabstop4 = 23;
int tabstop5 = 25;
int tabstop6 = 27;
int tabstop7 = 29;
int tabstop8 = 31;
int tabstop9 = 33;
int menuLine = 3;
static int b=0;
int bb=(b%6)/3;
SDL_Rect r;
extern SDL_Surface *text_screen;
r.x=80-64; r.y=0; r.w=110+64+64; r.h=240;
text_draw_background();
text_draw_window(2,2,41,30,text_str_controls_title);
// MENUCONTROLS_RETURNMAIN
if (menuControls == MENUCONTROLS_RETURNMAIN && bb)
write_text_inv(3, menuLine, "Return to main menu");
else
write_text(3, menuLine, "Return to main menu");
menuLine++;
write_text(leftMargin,menuLine,text_str_controls_separator);
menuLine++;
#ifdef ANDROIDSDL
// MENUCONTROLS_ONSCREEN
write_text(leftMargin,menuLine,"On-Screen Control");
if ((mainMenu_onScreen==1)&&((menuControls!=MENUCONTROLS_ONSCREEN)||(bb)))
write_text_inv(tabstop3,menuLine,"Show");
else
write_text(tabstop3,menuLine,"Show");
if ((mainMenu_onScreen==0)&&((menuControls!=MENUCONTROLS_ONSCREEN)||(bb)))
write_text_inv(tabstop6,menuLine,"Hide");
else
write_text(tabstop6,menuLine,"Hide");
menuLine++;
write_text(leftMargin,menuLine,text_str_controls_separator);
menuLine++;
#endif
// MENUCONTROLS_CUSTOM_ON_OFF
write_text(leftMargin,menuLine,"Custom Controls");
if ((mainMenu_customControls==1)&&((menuControls!=MENUCONTROLS_CUSTOM_ON_OFF)||(bb)))
write_text_inv(tabstop3,menuLine,"On");
else
write_text(tabstop3,menuLine,"On");
if ((mainMenu_customControls==0)&&((menuControls!=MENUCONTROLS_CUSTOM_ON_OFF)||(bb)))
write_text_inv(tabstop6,menuLine,"Off");
else
write_text(tabstop6,menuLine,"Off");
#if defined(__PSP2__) || defined(__SWITCH__)
menuLine+=2;
// MENUCONTROLS_CUSTOM_CONTROLLER_NR
write_text(leftMargin,menuLine,"Edit Map for Controller");
if ((mainMenu_custom_currentlyEditingControllerNr==0)&&((menuControls!=MENUCONTROLS_CUSTOM_CONTROLLER_NR)||(bb)))
write_text_inv(tabstop6,menuLine,"1");
else
write_text(tabstop6,menuLine,"1");
if ((mainMenu_custom_currentlyEditingControllerNr==1)&&((menuControls!=MENUCONTROLS_CUSTOM_CONTROLLER_NR)||(bb)))
write_text_inv(tabstop7,menuLine,"2");
else
write_text(tabstop7,menuLine,"2");
if ((mainMenu_custom_currentlyEditingControllerNr==2)&&((menuControls!=MENUCONTROLS_CUSTOM_CONTROLLER_NR)||(bb)))
write_text_inv(tabstop8,menuLine,"3");
else
write_text(tabstop8,menuLine,"3");
if ((mainMenu_custom_currentlyEditingControllerNr==3)&&((menuControls!=MENUCONTROLS_CUSTOM_CONTROLLER_NR)||(bb)))
write_text_inv(tabstop9,menuLine,"4");
else
write_text(tabstop9,menuLine,"4");
#ifdef __SWITCH__
if ((mainMenu_custom_currentlyEditingControllerNr==4)&&((menuControls!=MENUCONTROLS_CUSTOM_CONTROLLER_NR)||(bb)))
write_text_inv(tabstop9+2,menuLine,"5");
else
write_text(tabstop9+2,menuLine,"5");
if ((mainMenu_custom_currentlyEditingControllerNr==5)&&((menuControls!=MENUCONTROLS_CUSTOM_CONTROLLER_NR)||(bb)))
write_text_inv(tabstop9+4,menuLine,"6");
else
write_text(tabstop9+4,menuLine,"6");
if ((mainMenu_custom_currentlyEditingControllerNr==6)&&((menuControls!=MENUCONTROLS_CUSTOM_CONTROLLER_NR)||(bb)))
write_text_inv(tabstop9+6,menuLine,"7");
else
write_text(tabstop9+6,menuLine,"7");
if ((mainMenu_custom_currentlyEditingControllerNr==7)&&((menuControls!=MENUCONTROLS_CUSTOM_CONTROLLER_NR)||(bb)))
write_text_inv(tabstop9+8,menuLine,"8");
else
write_text(tabstop9+8,menuLine,"8");
#endif
menuLine++;
write_text(leftMargin,menuLine,text_str_controls_separator);
menuLine++;
// MENUCONTROLS_CUSTOMSET
write_text(leftMargin,menuLine," DPAD");
if ((mainMenu_custom_controlSet==0)&&((menuControls!=MENUCONTROLS_CUSTOMSET)||(bb)))
write_text_inv(tabstop1-6,menuLine,"Custom1");
else
write_text(tabstop1-6,menuLine,"Custom1");
if ((mainMenu_custom_controlSet==1)&&((menuControls!=MENUCONTROLS_CUSTOMSET)||(bb)))
write_text_inv(tabstop2,menuLine,"Custom2");
else
write_text(tabstop2,menuLine,"Custom2");
if ((mainMenu_custom_controlSet==2)&&((menuControls!=MENUCONTROLS_CUSTOMSET)||(bb)))
write_text_inv(tabstop6+2,menuLine,"Custom3");
else
write_text(tabstop6+2,menuLine,"Custom3");
#else
menuLine++;
write_text(leftMargin,menuLine,text_str_controls_separator);
menuLine++;
// MENUCONTROLS_DPAD
write_text(leftMargin,menuLine," DPAD");
if ((mainMenu_custom_dpad==0)&&((menuControls!=MENUCONTROLS_DPAD)||(bb)))
write_text_inv(tabstop1-6,menuLine,"Custom");
else
write_text(tabstop1-6,menuLine,"Custom");
if ((mainMenu_custom_dpad==1)&&((menuControls!=MENUCONTROLS_DPAD)||(bb)))
write_text_inv(tabstop2,menuLine,"Joystick");
else
write_text(tabstop2,menuLine,"Joystick");
if ((mainMenu_custom_dpad==2)&&((menuControls!=MENUCONTROLS_DPAD)||(bb)))
write_text_inv(tabstop6+2,menuLine,"Mouse");
else
write_text(tabstop6+2,menuLine,"Mouse");
#endif
if (mainMenu_custom_dpad==0)
{
// MENUCONTROLS_UP
menuLine+=2;
write_text(leftMargin,menuLine," Up");
getMapping(mainMenu_custom_up[ctrlNr]);
if ((menuControls!=MENUCONTROLS_UP)||(bb))
write_text_inv(tabstop1-4,menuLine,mapping);
else
write_text(tabstop1-4,menuLine,mapping);
// MENUCONTROLS_DOWN
menuLine+=2;
write_text(leftMargin,menuLine," Down");
getMapping(mainMenu_custom_down[ctrlNr]);
if ((menuControls!=MENUCONTROLS_DOWN)||(bb))
write_text_inv(tabstop1-4,menuLine,mapping);
else
write_text(tabstop1-4,menuLine,mapping);
// MENUCONTROLS_LEFT
menuLine+=2;
write_text(leftMargin,menuLine," Left");
getMapping(mainMenu_custom_left[ctrlNr]);
if ((menuControls!=MENUCONTROLS_LEFT)||(bb))
write_text_inv(tabstop1-4,menuLine,mapping);
else
write_text(tabstop1-4,menuLine,mapping);
// MENUCONTROLS_RIGHT
menuLine+=2;
write_text(leftMargin,menuLine," Right");
getMapping(mainMenu_custom_right[ctrlNr]);
if ((menuControls!=MENUCONTROLS_RIGHT)||(bb))
write_text_inv(tabstop1-4,menuLine,mapping);
else
write_text(tabstop1-4,menuLine,mapping);
}
// MENUCONTROLS_A
#ifdef __SWITCH__
menuLine+=2;
#else
menuLine+=3;
#endif
#if defined(__PSP2__)
write_text(leftMargin,menuLine,"Square");
#elif defined(__SWITCH__)
write_text(leftMargin,menuLine," Y");
#else
write_text(leftMargin,menuLine," (A)");
#endif
getMapping(mainMenu_custom_A[ctrlNr]);
if ((menuControls!=MENUCONTROLS_A)||(bb))
write_text_inv(tabstop1-4,menuLine,mapping);
else
write_text(tabstop1-4,menuLine,mapping);
// MENUCONTROLS_Y
menuLine+=2;
#if defined(__PSP2__)
write_text(leftMargin,menuLine,"Triangle");
#elif defined(__SWITCH__)
write_text(leftMargin,menuLine," X");
#else
write_text(leftMargin,menuLine," (Y)");
#endif
getMapping(mainMenu_custom_Y[ctrlNr]);
if ((menuControls!=MENUCONTROLS_Y)||(bb))
write_text_inv(tabstop1-4,menuLine,mapping);
else
write_text(tabstop1-4,menuLine,mapping);
// MENUCONTROLS_X
menuLine+=2;
#if defined(__PSP2__)
write_text(leftMargin,menuLine,"Cross");
#elif defined(__SWITCH__)
write_text(leftMargin,menuLine," B");
#else
write_text(leftMargin,menuLine," (X)");
#endif
getMapping(mainMenu_custom_X[ctrlNr]);
if ((menuControls!=MENUCONTROLS_X)||(bb))
write_text_inv(tabstop1-4,menuLine,mapping);
else
write_text(tabstop1-4,menuLine,mapping);
// MENUCONTROLS_B
menuLine+=2;
#if defined(__PSP2__)
write_text(leftMargin,menuLine,"Circle");
#elif defined(__SWITCH__)
write_text(leftMargin,menuLine," A");
#else
write_text(leftMargin,menuLine," (B)");
#endif
getMapping(mainMenu_custom_B[ctrlNr]);
if ((menuControls!=MENUCONTROLS_B)||(bb))
write_text_inv(tabstop1-4,menuLine,mapping);
else
write_text(tabstop1-4,menuLine,mapping);
// MENUCONTROLS_L
#ifdef __SWITCH__
menuLine+=2;
#else
menuLine+=3;
#endif
write_text(leftMargin,menuLine," L");
getMapping(mainMenu_custom_L[ctrlNr]);
if ((menuControls!=MENUCONTROLS_L)||(bb))
write_text_inv(tabstop1-4,menuLine,mapping);
else
write_text(tabstop1-4,menuLine,mapping);
// MENUCONTROLS_R
menuLine+=2;
write_text(leftMargin,menuLine," R");
getMapping(mainMenu_custom_R[ctrlNr]);
if ((menuControls!=MENUCONTROLS_R)||(bb))
write_text_inv(tabstop1-4,menuLine,mapping);
else
write_text(tabstop1-4,menuLine,mapping);
#ifdef __SWITCH__
// MENUCONTROLS_L2
menuLine+=2;
write_text(leftMargin,menuLine," ZL");
getMapping(mainMenu_custom_L2[ctrlNr]);
if ((menuControls!=MENUCONTROLS_L2)||(bb))
write_text_inv(tabstop1-4,menuLine,mapping);
else
write_text(tabstop1-4,menuLine,mapping);
// MENUCONTROLS_R2
menuLine+=2;
write_text(leftMargin,menuLine," ZR");
getMapping(mainMenu_custom_R2[ctrlNr]);
if ((menuControls!=MENUCONTROLS_R2)||(bb))
write_text_inv(tabstop1-4,menuLine,mapping);
else
write_text(tabstop1-4,menuLine,mapping);
#endif
#if defined(__PSP2__)
menuLine++;
write_text(leftMargin,menuLine,text_str_controls_separator);
menuLine++;
if (nr_joysticks==1)
write_text(leftMargin,menuLine,"1 Controller found (L-trigger rescan)");
else
{
snprintf(tmpchar, 255, "%d Controllers found (L-trigger rescan)",nr_joysticks);
write_text(leftMargin,menuLine,tmpchar);
}
#endif
text_flip();
b++;
}
static int key_controlsMenu(int *c)
{
int end=0;
static int delay=0;
int left=0, right=0, up=0, down=0, hit0=0, hit1=0, hit2=0, hit3=0, del=0;
int ctrlNr = mainMenu_custom_currentlyEditingControllerNr;
SDL_Event event;
#if !defined(__PSP2__) && !defined(__SWITCH__) // this can be snappy on Vita no need to worry about touch
delay ++;
if (delay<5) return end;
delay=0;
#endif
static int holdingUp=0;
static int holdingDown=0;
static int holdingRight=0;
static int holdingLeft=0;
static Uint32 menu_last_press_time=0;
static Uint32 menu_last_move_time=0;
Uint32 now=SDL_GetTicks();
if (holdingLeft || holdingRight || holdingUp || holdingDown)
{
if (now-menu_last_press_time>MENU_MIN_HOLDING_TIME && now-menu_last_move_time>MENU_MOVE_DELAY)
{
menu_last_move_time=now;
SDL_Event ev;
ev.type = SDL_KEYDOWN;
if (holdingLeft)
ev.key.keysym.sym = SDLK_LEFT;
else if (holdingRight)
ev.key.keysym.sym = SDLK_RIGHT;
else if (holdingUp)
ev.key.keysym.sym = SDLK_UP;
else if (holdingDown)
ev.key.keysym.sym = SDLK_DOWN;
SDL_PushEvent(&ev);
}
}
while (SDL_PollEvent(&event) > 0)
{
left=right=up=down=hit0=hit1=hit2=hit3=del=0;
if (event.type == SDL_KEYDOWN)
{
uae4all_play_click();
switch(event.key.keysym.sym)
{
case SDLK_RIGHT: right=1; break;
case SDLK_LEFT: left=1; break;
case SDLK_UP: up=1; break;
case SDLK_DOWN: down=1; break;
case SDLK_PAGEUP: del=1; break; //Note: PAGEUP is Triangle on Vita
case SDLK_LCTRL: hit2=1; break; //allow user to quit menu completely at any time
//note SDLK_CTRL corresponds to ButtonSelect on Vita
#if defined(__PSP2__) || defined(__SWITCH__)
case SDLK_RSHIFT: hit3=1; break; //SDLK_RSHIFT is triggerL on Vita
case SDLK_PAGEDOWN: hit0=1; break; //SDLK_PAGEDOWN is the ok button on Vita
case SDLK_END: hit1=1; break; // SDLK_END is the cancel button on Vita
#else
case SDLK_HOME: hit0=1; break;
case SDLK_PAGEDOWN: hit0=1; break;
case SDLK_LALT: hit1=1; break;
case SDLK_END: hit0=1; break;
#endif
}
}
if (event.type == SDL_KEYUP)
{
switch(event.key.keysym.sym)
{
case SDLK_RIGHT:
holdingRight=0;
break;
case SDLK_LEFT:
holdingLeft=0;
break;
case SDLK_UP:
holdingUp=0;
break;
case SDLK_DOWN:
holdingDown=0;
break;
default:
break;
}
}
if (left && !holdingLeft)
{
holdingLeft=1;
menu_last_press_time=now;
}
if (right && !holdingRight)
{
holdingRight=1;
menu_last_press_time=now;
}
if (up && !holdingUp)
{
holdingUp=1;
menu_last_press_time=now;
}
if (down && !holdingDown)
{
holdingDown=1;
menu_last_press_time=now;
}
if (hit2) //Does the user want to cancel the menu completely?
{
if (emulating)
{
end = -1;
quit_pressed_in_submenu = 1; //Tell the mainMenu to cancel, too
}
}
#if defined(__PSP2__) || defined(__SWITCH__)
else if (hit3) // L pressed on Vita?
{
//See if new joysticks have been paired
close_joystick();
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
init_joystick();
}
#endif
#if !defined(__PSP2__) && !defined(__SWITCH__)
else if (hit0)
{
end = -1;
}
#endif
else if (hit1)
{
end = -1;
}
else if (up)
{
#if !defined(__PSP2__) && !defined(__SWITCH__)
if (menuControls==MENUCONTROLS_A && mainMenu_custom_dpad>0) menuControls=MENUCONTROLS_DPAD;
else
#endif
#ifdef __SWITCH__
if (menuControls==MENUCONTROLS_RETURNMAIN) menuControls=MENUCONTROLS_R2;
#else
if (menuControls==MENUCONTROLS_RETURNMAIN) menuControls=MENUCONTROLS_R;
#endif
else menuControls--;
}
else if (down)
{
#if !defined(__PSP2__) && !defined(__SWITCH__)
if (menuControls==MENUCONTROLS_DPAD && mainMenu_custom_dpad>0) menuControls=MENUCONTROLS_A;
else
#endif
#ifdef __SWITCH__
if (menuControls==MENUCONTROLS_R2) menuControls=MENUCONTROLS_RETURNMAIN;
#else
if (menuControls==MENUCONTROLS_R) menuControls=MENUCONTROLS_RETURNMAIN;
#endif
else menuControls++;
}
switch (menuControls)
{
#ifdef ANDROIDSDL
case MENUCONTROLS_ONSCREEN:
if ((left)||(right))
mainMenu_onScreen = !mainMenu_onScreen;
break;
#endif
case MENUCONTROLS_RETURNMAIN:
if (hit0)
end = -1;
break;
case MENUCONTROLS_CUSTOM_ON_OFF:
if ((left)||(right))
{
mainMenu_customControls = !mainMenu_customControls;
remap_custom_controls();
}
break;
#if defined(__PSP2__) || defined(__SWITCH__)
case MENUCONTROLS_CUSTOM_CONTROLLER_NR:
if (left)
{
if (mainMenu_custom_currentlyEditingControllerNr>0)
{
mainMenu_custom_currentlyEditingControllerNr--;
remap_custom_controls();
}
}
else if (right)
{
if (mainMenu_custom_currentlyEditingControllerNr<(MAX_NUM_CONTROLLERS-1))
{
mainMenu_custom_currentlyEditingControllerNr++;
remap_custom_controls();
}
}
break;
case MENUCONTROLS_CUSTOMSET:
if (left)
{
if (mainMenu_custom_controlSet>0)
mainMenu_custom_controlSet--;
else
mainMenu_custom_controlSet=2;
remap_custom_controls();
}
else if (right)
{
if (mainMenu_custom_controlSet<2)
mainMenu_custom_controlSet++;
else
mainMenu_custom_controlSet=0;
remap_custom_controls();
}
break;
#else
case MENUCONTROLS_DPAD:
if (left)
{
if (mainMenu_custom_dpad>0)
mainMenu_custom_dpad--;
else
mainMenu_custom_dpad=2;
}
else if (right)
{
if (mainMenu_custom_dpad<2)
mainMenu_custom_dpad++;
else
mainMenu_custom_dpad=0;
}
break;
#endif
case MENUCONTROLS_UP:
if (left)
{
if (mainMenu_custom_up[ctrlNr]>MIN_CUSTOM_ID)
mainMenu_custom_up[ctrlNr]--;
else
mainMenu_custom_up[ctrlNr]=MAX_CUSTOM_ID;
#if defined(__PSP2__) || defined(__SWITCH__)
mapback_custom_controls(); //record this change in custom control set
#endif
}
else if (right)
{
if (mainMenu_custom_up[ctrlNr]<MAX_CUSTOM_ID)
mainMenu_custom_up[ctrlNr]++;
else
mainMenu_custom_up[ctrlNr]=MIN_CUSTOM_ID;
#if defined(__PSP2__) || defined(__SWITCH__)
mapback_custom_controls(); //record this change in custom control set
#endif
}
else if (del)
{
mainMenu_custom_up[ctrlNr]=0;
#if defined(__PSP2__) || defined(__SWITCH__)
mapback_custom_controls(); //record this change in custom control set
#endif
}
break;
case MENUCONTROLS_DOWN:
if (left)
{
if (mainMenu_custom_down[ctrlNr]>MIN_CUSTOM_ID)
mainMenu_custom_down[ctrlNr]--;
else
mainMenu_custom_down[ctrlNr]=MAX_CUSTOM_ID;
#if defined(__PSP2__) || defined(__SWITCH__)
mapback_custom_controls(); //record this change in custom control set
#endif
}
else if (right)
{
if (mainMenu_custom_down[ctrlNr]<MAX_CUSTOM_ID)
mainMenu_custom_down[ctrlNr]++;
else
mainMenu_custom_down[ctrlNr]=MIN_CUSTOM_ID;
#if defined(__PSP2__) || defined(__SWITCH__)
mapback_custom_controls(); //record this change in custom control set
#endif
}
else if (del)
{
mainMenu_custom_down[ctrlNr]=0;
#if defined(__PSP2__) || defined(__SWITCH__)
mapback_custom_controls(); //record this change in custom control set
#endif
}
break;
case MENUCONTROLS_LEFT:
if (left)
{
if (mainMenu_custom_left[ctrlNr]>MIN_CUSTOM_ID)
mainMenu_custom_left[ctrlNr]--;
else
mainMenu_custom_left[ctrlNr]=MAX_CUSTOM_ID;
#if defined(__PSP2__) || defined(__SWITCH__)
mapback_custom_controls(); //record this change in custom control set
#endif
}
else if (right)
{
if (mainMenu_custom_left[ctrlNr]<MAX_CUSTOM_ID)