forked from MiSTer-devel/Main_MiSTer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.cpp
3618 lines (3267 loc) · 86.9 KB
/
input.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 <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <sys/inotify.h>
#include <sys/poll.h>
#include <sys/sysinfo.h>
#include <dirent.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/input.h>
#include <linux/uinput.h>
#include <sys/time.h>
#include <sys/types.h>
#include <stdarg.h>
#include "input.h"
#include "user_io.h"
#include "menu.h"
#include "hardware.h"
#include "cfg.h"
#include "fpga_io.h"
#include "osd.h"
#include "video.h"
#include "joymapping.h"
#include "support.h"
#define NUMDEV 30
#define NUMPLAYERS 6
#define UINPUT_NAME "MiSTer virtual input"
char joy_bnames[NUMBUTTONS][32] = {};
int joy_bcount = 0;
static int ev2amiga[] =
{
NONE, //0 KEY_RESERVED
0x45, //1 KEY_ESC
0x01, //2 KEY_1
0x02, //3 KEY_2
0x03, //4 KEY_3
0x04, //5 KEY_4
0x05, //6 KEY_5
0x06, //7 KEY_6
0x07, //8 KEY_7
0x08, //9 KEY_8
0x09, //10 KEY_9
0x0a, //11 KEY_0
0x0b, //12 KEY_MINUS
0x0c, //13 KEY_EQUAL
0x41, //14 KEY_BACKSPACE
0x42, //15 KEY_TAB
0x10, //16 KEY_Q
0x11, //17 KEY_W
0x12, //18 KEY_E
0x13, //19 KEY_R
0x14, //20 KEY_T
0x15, //21 KEY_Y
0x16, //22 KEY_U
0x17, //23 KEY_I
0x18, //24 KEY_O
0x19, //25 KEY_P
0x1a, //26 KEY_LEFTBRACE
0x1b, //27 KEY_RIGHTBRACE
0x44, //28 KEY_ENTER
0x63, //29 KEY_LEFTCTRL
0x20, //30 KEY_A
0x21, //31 KEY_S
0x22, //32 KEY_D
0x23, //33 KEY_F
0x24, //34 KEY_G
0x25, //35 KEY_H
0x26, //36 KEY_J
0x27, //37 KEY_K
0x28, //38 KEY_L
0x29, //39 KEY_SEMICOLON
0x2a, //40 KEY_APOSTROPHE
0x00, //41 KEY_GRAVE
0x60, //42 KEY_LEFTSHIFT
0x0d, //43 KEY_BACKSLASH
0x31, //44 KEY_Z
0x32, //45 KEY_X
0x33, //46 KEY_C
0x34, //47 KEY_V
0x35, //48 KEY_B
0x36, //49 KEY_N
0x37, //50 KEY_M
0x38, //51 KEY_COMMA
0x39, //52 KEY_DOT
0x3a, //53 KEY_SLASH
0x61, //54 KEY_RIGHTSHIFT
0x5d, //55 KEY_KPASTERISK
0x64, //56 KEY_LEFTALT
0x40, //57 KEY_SPACE
0x62 | CAPS_TOGGLE, //58 KEY_CAPSLOCK
0x50, //59 KEY_F1
0x51, //60 KEY_F2
0x52, //61 KEY_F3
0x53, //62 KEY_F4
0x54, //63 KEY_F5
0x55, //64 KEY_F6
0x56, //65 KEY_F7
0x57, //66 KEY_F8
0x58, //67 KEY_F9
0x59, //68 KEY_F10
NONE, //69 KEY_NUMLOCK
NONE, //70 KEY_SCROLLLOCK
0x3d, //71 KEY_KP7
0x3e, //72 KEY_KP8
0x3f, //73 KEY_KP9
0x4a, //74 KEY_KPMINUS
0x2d, //75 KEY_KP4
0x2e, //76 KEY_KP5
0x2f, //77 KEY_KP6
0x5e, //78 KEY_KPPLUS
0x1d, //79 KEY_KP1
0x1e, //80 KEY_KP2
0x1f, //81 KEY_KP3
0x0f, //82 KEY_KP0
0x3c, //83 KEY_KPDOT
NONE, //84 ???
NONE, //85 KEY_ZENKAKU
0x30, //86 KEY_102ND, '<' on most keyboards
0x5f, //87 KEY_F11
NONE, //88 KEY_F12
NONE, //89 KEY_RO
NONE, //90 KEY_KATAKANA
NONE, //91 KEY_HIRAGANA
NONE, //92 KEY_HENKAN
NONE, //93 KEY_KATAKANA
NONE, //94 KEY_MUHENKAN
NONE, //95 KEY_KPJPCOMMA
0x43, //96 KEY_KPENTER
0x63, //97 KEY_RIGHTCTRL
0x5c, //98 KEY_KPSLASH
NONE, //99 KEY_SYSRQ
0x65, //100 KEY_RIGHTALT
NONE, //101 KEY_LINEFEED
0x6a, //102 KEY_HOME
0x4c, //103 KEY_UP
0x5b, //104 KEY_PAGEUP
0x4f, //105 KEY_LEFT
0x4e, //106 KEY_RIGHT
NONE, //107 KEY_END
0x4d, //108 KEY_DOWN
0x5a, //109 KEY_PAGEDOWN
0x0d, //110 KEY_INSERT
0x46, //111 KEY_DELETE
NONE, //112 KEY_MACRO
NONE, //113 KEY_MUTE
NONE, //114 KEY_VOLUMEDOWN
NONE, //115 KEY_VOLUMEUP
NONE, //116 KEY_POWER
NONE, //117 KEY_KPEQUAL
NONE, //118 KEY_KPPLUSMINUS
NONE, //119 KEY_PAUSE
NONE, //120 KEY_SCALE
NONE, //121 KEY_KPCOMMA
NONE, //122 KEY_HANGEUL
NONE, //123 KEY_HANJA
NONE, //124 KEY_YEN
0x66, //125 KEY_LEFTMETA
0x67, //126 KEY_RIGHTMETA
NONE, //127 KEY_COMPOSE
NONE, //128 KEY_STOP
NONE, //129 KEY_AGAIN
NONE, //130 KEY_PROPS
NONE, //131 KEY_UNDO
NONE, //132 KEY_FRONT
NONE, //133 KEY_COPY
NONE, //134 KEY_OPEN
NONE, //135 KEY_PASTE
NONE, //136 KEY_FIND
NONE, //137 KEY_CUT
NONE, //138 KEY_HELP
NONE, //139 KEY_MENU
NONE, //140 KEY_CALC
NONE, //141 KEY_SETUP
NONE, //142 KEY_SLEEP
NONE, //143 KEY_WAKEUP
NONE, //144 KEY_FILE
NONE, //145 KEY_SENDFILE
NONE, //146 KEY_DELETEFILE
NONE, //147 KEY_XFER
NONE, //148 KEY_PROG1
NONE, //149 KEY_PROG2
NONE, //150 KEY_WWW
NONE, //151 KEY_MSDOS
NONE, //152 KEY_SCREENLOCK
NONE, //153 KEY_DIRECTION
NONE, //154 KEY_CYCLEWINDOWS
NONE, //155 KEY_MAIL
NONE, //156 KEY_BOOKMARKS
NONE, //157 KEY_COMPUTER
NONE, //158 KEY_BACK
NONE, //159 KEY_FORWARD
NONE, //160 KEY_CLOSECD
NONE, //161 KEY_EJECTCD
NONE, //162 KEY_EJECTCLOSECD
NONE, //163 KEY_NEXTSONG
NONE, //164 KEY_PLAYPAUSE
NONE, //165 KEY_PREVIOUSSONG
NONE, //166 KEY_STOPCD
NONE, //167 KEY_RECORD
NONE, //168 KEY_REWIND
NONE, //169 KEY_PHONE
NONE, //170 KEY_ISO
NONE, //171 KEY_CONFIG
NONE, //172 KEY_HOMEPAGE
NONE, //173 KEY_REFRESH
NONE, //174 KEY_EXIT
NONE, //175 KEY_MOVE
NONE, //176 KEY_EDIT
NONE, //177 KEY_SCROLLUP
NONE, //178 KEY_SCROLLDOWN
NONE, //179 KEY_KPLEFTPAREN
NONE, //180 KEY_KPRIGHTPAREN
NONE, //181 KEY_NEW
NONE, //182 KEY_REDO
0x5a, //183 KEY_F13
0x5b, //184 KEY_F14
NONE, //185 KEY_F15
0x5f, //186 KEY_F16
NONE, //187 KEY_F17
NONE, //188 KEY_F18
NONE, //189 KEY_F19
NONE, //190 KEY_F20
NONE, //191 KEY_F21
NONE, //192 KEY_F22
NONE, //193 KEY_F23
0x2b, //194 # on German keyboard, was 0x63 (CTRL on Amiga), 194 KEY_F24
NONE, //195 ???
NONE, //196 ???
NONE, //197 ???
NONE, //198 ???
NONE, //199 ???
NONE, //200 KEY_PLAYCD
NONE, //201 KEY_PAUSECD
NONE, //202 KEY_PROG3
NONE, //203 KEY_PROG4
NONE, //204 KEY_DASHBOARD
NONE, //205 KEY_SUSPEND
NONE, //206 KEY_CLOSE
NONE, //207 KEY_PLAY
NONE, //208 KEY_FASTFORWARD
NONE, //209 KEY_BASSBOOST
NONE, //210 KEY_PRINT
NONE, //211 KEY_HP
NONE, //212 KEY_CAMERA
NONE, //213 KEY_SOUND
NONE, //214 KEY_QUESTION
NONE, //215 KEY_EMAIL
NONE, //216 KEY_CHAT
NONE, //217 KEY_SEARCH
NONE, //218 KEY_CONNECT
NONE, //219 KEY_FINANCE
NONE, //220 KEY_SPORT
NONE, //221 KEY_SHOP
NONE, //222 KEY_ALTERASE
NONE, //223 KEY_CANCEL
NONE, //224 KEY_BRIGHT_DOWN
NONE, //225 KEY_BRIGHT_UP
NONE, //226 KEY_MEDIA
NONE, //227 KEY_SWITCHVIDEO
NONE, //228 KEY_DILLUMTOGGLE
NONE, //229 KEY_DILLUMDOWN
NONE, //230 KEY_DILLUMUP
NONE, //231 KEY_SEND
NONE, //232 KEY_REPLY
NONE, //233 KEY_FORWARDMAIL
NONE, //234 KEY_SAVE
NONE, //235 KEY_DOCUMENTS
NONE, //236 KEY_BATTERY
NONE, //237 KEY_BLUETOOTH
NONE, //238 KEY_WLAN
NONE, //239 KEY_UWB
NONE, //240 KEY_UNKNOWN
NONE, //241 KEY_VIDEO_NEXT
NONE, //242 KEY_VIDEO_PREV
NONE, //243 KEY_BRIGHT_CYCLE
NONE, //244 KEY_BRIGHT_AUTO
NONE, //245 KEY_DISPLAY_OFF
NONE, //246 KEY_WWAN
NONE, //247 KEY_RFKILL
NONE, //248 KEY_MICMUTE
NONE, //249 ???
NONE, //250 ???
NONE, //251 ???
NONE, //252 ???
NONE, //253 ???
NONE, //254 ???
NONE //255 ???
};
static const int ev2ps2[] =
{
NONE, //0 KEY_RESERVED
0x76, //1 KEY_ESC
0x16, //2 KEY_1
0x1e, //3 KEY_2
0x26, //4 KEY_3
0x25, //5 KEY_4
0x2e, //6 KEY_5
0x36, //7 KEY_6
0x3d, //8 KEY_7
0x3e, //9 KEY_8
0x46, //10 KEY_9
0x45, //11 KEY_0
0x4e, //12 KEY_MINUS
0x55, //13 KEY_EQUAL
0x66, //14 KEY_BACKSPACE
0x0d, //15 KEY_TAB
0x15, //16 KEY_Q
0x1d, //17 KEY_W
0x24, //18 KEY_E
0x2d, //19 KEY_R
0x2c, //20 KEY_T
0x35, //21 KEY_Y
0x3c, //22 KEY_U
0x43, //23 KEY_I
0x44, //24 KEY_O
0x4d, //25 KEY_P
0x54, //26 KEY_LEFTBRACE
0x5b, //27 KEY_RIGHTBRACE
0x5a, //28 KEY_ENTER
LCTRL | 0x14, //29 KEY_LEFTCTRL
0x1c, //30 KEY_A
0x1b, //31 KEY_S
0x23, //32 KEY_D
0x2b, //33 KEY_F
0x34, //34 KEY_G
0x33, //35 KEY_H
0x3b, //36 KEY_J
0x42, //37 KEY_K
0x4b, //38 KEY_L
0x4c, //39 KEY_SEMICOLON
0x52, //40 KEY_APOSTROPHE
0x0e, //41 KEY_GRAVE
LSHIFT | 0x12, //42 KEY_LEFTSHIFT
0x5d, //43 KEY_BACKSLASH
0x1a, //44 KEY_Z
0x22, //45 KEY_X
0x21, //46 KEY_C
0x2a, //47 KEY_V
0x32, //48 KEY_B
0x31, //49 KEY_N
0x3a, //50 KEY_M
0x41, //51 KEY_COMMA
0x49, //52 KEY_DOT
0x4a, //53 KEY_SLASH
RSHIFT | 0x59, //54 KEY_RIGHTSHIFT
0x7c, //55 KEY_KPASTERISK
LALT | 0x11, //56 KEY_LEFTALT
0x29, //57 KEY_SPACE
0x58, //58 KEY_CAPSLOCK
0x05, //59 KEY_F1
0x06, //60 KEY_F2
0x04, //61 KEY_F3
0x0c, //62 KEY_F4
0x03, //63 KEY_F5
0x0b, //64 KEY_F6
0x83, //65 KEY_F7
0x0a, //66 KEY_F8
0x01, //67 KEY_F9
0x09, //68 KEY_F10
EMU_SWITCH_2 | 0x77, //69 KEY_NUMLOCK
EMU_SWITCH_1 | 0x7E, //70 KEY_SCROLLLOCK
0x6c, //71 KEY_KP7
0x75, //72 KEY_KP8
0x7d, //73 KEY_KP9
0x7b, //74 KEY_KPMINUS
0x6b, //75 KEY_KP4
0x73, //76 KEY_KP5
0x74, //77 KEY_KP6
0x79, //78 KEY_KPPLUS
0x69, //79 KEY_KP1
0x72, //80 KEY_KP2
0x7a, //81 KEY_KP3
0x70, //82 KEY_KP0
0x71, //83 KEY_KPDOT
NONE, //84 ???
NONE, //85 KEY_ZENKAKU
0x56, //86 KEY_102ND
0x78, //87 KEY_F11
0x07, //88 KEY_F12
NONE, //89 KEY_RO
NONE, //90 KEY_KATAKANA
NONE, //91 KEY_HIRAGANA
NONE, //92 KEY_HENKAN
NONE, //93 KEY_KATAKANA
NONE, //94 KEY_MUHENKAN
NONE, //95 KEY_KPJPCOMMA
EXT | 0x5a, //96 KEY_KPENTER
RCTRL | EXT | 0x14, //97 KEY_RIGHTCTRL
EXT | 0x4a, //98 KEY_KPSLASH
0xE2, //99 KEY_SYSRQ
RALT | EXT | 0x11, //100 KEY_RIGHTALT
NONE, //101 KEY_LINEFEED
EXT | 0x6c, //102 KEY_HOME
EXT | 0x75, //103 KEY_UP
EXT | 0x7d, //104 KEY_PAGEUP
EXT | 0x6b, //105 KEY_LEFT
EXT | 0x74, //106 KEY_RIGHT
EXT | 0x69, //107 KEY_END
EXT | 0x72, //108 KEY_DOWN
EXT | 0x7a, //109 KEY_PAGEDOWN
EXT | 0x70, //110 KEY_INSERT
EXT | 0x71, //111 KEY_DELETE
NONE, //112 KEY_MACRO
NONE, //113 KEY_MUTE
NONE, //114 KEY_VOLUMEDOWN
NONE, //115 KEY_VOLUMEUP
NONE, //116 KEY_POWER
NONE, //117 KEY_KPEQUAL
NONE, //118 KEY_KPPLUSMINUS
0xE1, //119 KEY_PAUSE
NONE, //120 KEY_SCALE
NONE, //121 KEY_KPCOMMA
NONE, //122 KEY_HANGEUL
NONE, //123 KEY_HANJA
NONE, //124 KEY_YEN
LGUI | EXT | 0x1f, //125 KEY_LEFTMETA
RGUI | EXT | 0x27, //126 KEY_RIGHTMETA
NONE, //127 KEY_COMPOSE
NONE, //128 KEY_STOP
NONE, //129 KEY_AGAIN
NONE, //130 KEY_PROPS
NONE, //131 KEY_UNDO
NONE, //132 KEY_FRONT
NONE, //133 KEY_COPY
NONE, //134 KEY_OPEN
NONE, //135 KEY_PASTE
NONE, //136 KEY_FIND
NONE, //137 KEY_CUT
NONE, //138 KEY_HELP
NONE, //139 KEY_MENU
NONE, //140 KEY_CALC
NONE, //141 KEY_SETUP
NONE, //142 KEY_SLEEP
NONE, //143 KEY_WAKEUP
NONE, //144 KEY_FILE
NONE, //145 KEY_SENDFILE
NONE, //146 KEY_DELETEFILE
NONE, //147 KEY_XFER
NONE, //148 KEY_PROG1
NONE, //149 KEY_PROG2
NONE, //150 KEY_WWW
NONE, //151 KEY_MSDOS
NONE, //152 KEY_SCREENLOCK
NONE, //153 KEY_DIRECTION
NONE, //154 KEY_CYCLEWINDOWS
NONE, //155 KEY_MAIL
NONE, //156 KEY_BOOKMARKS
NONE, //157 KEY_COMPUTER
NONE, //158 KEY_BACK
NONE, //159 KEY_FORWARD
NONE, //160 KEY_CLOSECD
NONE, //161 KEY_EJECTCD
NONE, //162 KEY_EJECTCLOSECD
NONE, //163 KEY_NEXTSONG
NONE, //164 KEY_PLAYPAUSE
NONE, //165 KEY_PREVIOUSSONG
NONE, //166 KEY_STOPCD
NONE, //167 KEY_RECORD
NONE, //168 KEY_REWIND
NONE, //169 KEY_PHONE
NONE, //170 KEY_ISO
NONE, //171 KEY_CONFIG
NONE, //172 KEY_HOMEPAGE
NONE, //173 KEY_REFRESH
NONE, //174 KEY_EXIT
NONE, //175 KEY_MOVE
NONE, //176 KEY_EDIT
NONE, //177 KEY_SCROLLUP
NONE, //178 KEY_SCROLLDOWN
NONE, //179 KEY_KPLEFTPAREN
NONE, //180 KEY_KPRIGHTPAREN
NONE, //181 KEY_NEW
NONE, //182 KEY_REDO
NONE, //183 KEY_F13
NONE, //184 KEY_F14
NONE, //185 KEY_F15
NONE, //186 KEY_F16
EMU_SWITCH_1 | 1, //187 KEY_F17
EMU_SWITCH_1 | 2, //188 KEY_F18
EMU_SWITCH_1 | 3, //189 KEY_F19
EMU_SWITCH_1 | 4, //190 KEY_F20
NONE, //191 KEY_F21
NONE, //192 KEY_F22
NONE, //193 KEY_F23
0x5D, //194 U-mlaut on DE mapped to backslash
NONE, //195 ???
NONE, //196 ???
NONE, //197 ???
NONE, //198 ???
NONE, //199 ???
NONE, //200 KEY_PLAYCD
NONE, //201 KEY_PAUSECD
NONE, //202 KEY_PROG3
NONE, //203 KEY_PROG4
NONE, //204 KEY_DASHBOARD
NONE, //205 KEY_SUSPEND
NONE, //206 KEY_CLOSE
NONE, //207 KEY_PLAY
NONE, //208 KEY_FASTFORWARD
NONE, //209 KEY_BASSBOOST
NONE, //210 KEY_PRINT
NONE, //211 KEY_HP
NONE, //212 KEY_CAMERA
NONE, //213 KEY_SOUND
NONE, //214 KEY_QUESTION
NONE, //215 KEY_EMAIL
NONE, //216 KEY_CHAT
NONE, //217 KEY_SEARCH
NONE, //218 KEY_CONNECT
NONE, //219 KEY_FINANCE
NONE, //220 KEY_SPORT
NONE, //221 KEY_SHOP
NONE, //222 KEY_ALTERASE
NONE, //223 KEY_CANCEL
NONE, //224 KEY_BRIGHT_DOWN
NONE, //225 KEY_BRIGHT_UP
NONE, //226 KEY_MEDIA
NONE, //227 KEY_SWITCHVIDEO
NONE, //228 KEY_DILLUMTOGGLE
NONE, //229 KEY_DILLUMDOWN
NONE, //230 KEY_DILLUMUP
NONE, //231 KEY_SEND
NONE, //232 KEY_REPLY
NONE, //233 KEY_FORWARDMAIL
NONE, //234 KEY_SAVE
NONE, //235 KEY_DOCUMENTS
NONE, //236 KEY_BATTERY
NONE, //237 KEY_BLUETOOTH
NONE, //238 KEY_WLAN
NONE, //239 KEY_UWB
NONE, //240 KEY_UNKNOWN
NONE, //241 KEY_VIDEO_NEXT
NONE, //242 KEY_VIDEO_PREV
NONE, //243 KEY_BRIGHT_CYCLE
NONE, //244 KEY_BRIGHT_AUTO
NONE, //245 KEY_DISPLAY_OFF
NONE, //246 KEY_WWAN
NONE, //247 KEY_RFKILL
NONE, //248 KEY_MICMUTE
NONE, //249 ???
NONE, //250 ???
NONE, //251 ???
NONE, //252 ???
NONE, //253 ???
NONE, //254 ???
NONE //255 ???
};
static int ev2archie[] =
{
NONE, //0 KEY_RESERVED
0x00, //1 KEY_ESC
0x11, //2 KEY_1
0x12, //3 KEY_2
0x13, //4 KEY_3
0x14, //5 KEY_4
0x15, //6 KEY_5
0x16, //7 KEY_6
0x17, //8 KEY_7
0x18, //9 KEY_8
0x19, //10 KEY_9
0x1a, //11 KEY_0
0x1b, //12 KEY_MINUS
0x1c, //13 KEY_EQUAL
0x1e, //14 KEY_BACKSPACE
0x26, //15 KEY_TAB
0x27, //16 KEY_Q
0x28, //17 KEY_W
0x29, //18 KEY_E
0x2a, //19 KEY_R
0x2b, //20 KEY_T
0x2c, //21 KEY_Y
0x2d, //22 KEY_U
0x2e, //23 KEY_I
0x2f, //24 KEY_O
0x30, //25 KEY_P
0x31, //26 KEY_LEFTBRACE
0x32, //27 KEY_RIGHTBRACE
0x47, //28 KEY_ENTER
0x3b, //29 KEY_LEFTCTRL
0x3c, //30 KEY_A
0x3d, //31 KEY_S
0x3e, //32 KEY_D
0x3f, //33 KEY_F
0x40, //34 KEY_G
0x41, //35 KEY_H
0x42, //36 KEY_J
0x43, //37 KEY_K
0x44, //38 KEY_L
0x45, //39 KEY_SEMICOLON
0x46, //40 KEY_APOSTROPHE
0x10, //41 KEY_GRAVE
0x4c, //42 KEY_LEFTSHIFT
0x33, //43 KEY_BACKSLASH
0x4e, //44 KEY_Z
0x4f, //45 KEY_X
0x50, //46 KEY_C
0x51, //47 KEY_V
0x52, //48 KEY_B
0x53, //49 KEY_N
0x54, //50 KEY_M
0x55, //51 KEY_COMMA
0x56, //52 KEY_DOT
0x57, //53 KEY_SLASH
0x58, //54 KEY_RIGHTSHIFT
0x24, //55 KEY_KPASTERISK
0x5e, //56 KEY_LEFTALT
0x5f, //57 KEY_SPACE
0x5d, //58 KEY_CAPSLOCK
0x01, //59 KEY_F1
0x02, //60 KEY_F2
0x03, //61 KEY_F3
0x04, //62 KEY_F4
0x05, //63 KEY_F5
0x06, //64 KEY_F6
0x07, //65 KEY_F7
0x08, //66 KEY_F8
0x09, //67 KEY_F9
0x0a, //68 KEY_F10
0x22, //69 KEY_NUMLOCK
NONE, //70 KEY_SCROLLLOCK
0x37, //71 KEY_KP7
0x38, //72 KEY_KP8
0x39, //73 KEY_KP9
0x3a, //74 KEY_KPMINUS
0x48, //75 KEY_KP4
0x49, //76 KEY_KP5
0x4a, //77 KEY_KP6
0x4b, //78 KEY_KPPLUS
0x5a, //79 KEY_KP1
0x5b, //80 KEY_KP2
0x5c, //81 KEY_KP3
0x65, //82 KEY_KP0
0x66, //83 KEY_KPDOT
NONE, //84 ???
NONE, //85 KEY_ZENKAKU
NONE, //86 KEY_102ND
0x0b, //87 KEY_F11
0x0c, //88 KEY_F12
NONE, //89 KEY_RO
NONE, //90 KEY_KATAKANA
NONE, //91 KEY_HIRAGANA
NONE, //92 KEY_HENKAN
NONE, //93 KEY_KATAKANA
NONE, //94 KEY_MUHENKAN
NONE, //95 KEY_KPJPCOMMA
0x67, //96 KEY_KPENTER
0x61, //97 KEY_RIGHTCTRL
0x23, //98 KEY_KPSLASH
0x0D, //99 KEY_SYSRQ
0x60, //100 KEY_RIGHTALT
NONE, //101 KEY_LINEFEED
0x20, //102 KEY_HOME
0x59, //103 KEY_UP
0x21, //104 KEY_PAGEUP
0x62, //105 KEY_LEFT
0x64, //106 KEY_RIGHT
0x35, //107 KEY_END
0x63, //108 KEY_DOWN
0x36, //109 KEY_PAGEDOWN
0x1f, //110 KEY_INSERT
0x34, //111 KEY_DELETE
NONE, //112 KEY_MACRO
NONE, //113 KEY_MUTE
NONE, //114 KEY_VOLUMEDOWN
NONE, //115 KEY_VOLUMEUP
NONE, //116 KEY_POWER
NONE, //117 KEY_KPEQUAL
NONE, //118 KEY_KPPLUSMINUS
0x0f, //119 KEY_PAUSE
NONE, //120 KEY_SCALE
NONE, //121 KEY_KPCOMMA
NONE, //122 KEY_HANGEUL
NONE, //123 KEY_HANJA
NONE, //124 KEY_YEN
NONE, //125 KEY_LEFTMETA
NONE, //126 KEY_RIGHTMETA
0x71, //127 KEY_COMPOSE
NONE, //128 KEY_STOP
NONE, //129 KEY_AGAIN
NONE, //130 KEY_PROPS
NONE, //131 KEY_UNDO
NONE, //132 KEY_FRONT
NONE, //133 KEY_COPY
NONE, //134 KEY_OPEN
NONE, //135 KEY_PASTE
NONE, //136 KEY_FIND
NONE, //137 KEY_CUT
NONE, //138 KEY_HELP
NONE, //139 KEY_MENU
NONE, //140 KEY_CALC
NONE, //141 KEY_SETUP
NONE, //142 KEY_SLEEP
NONE, //143 KEY_WAKEUP
NONE, //144 KEY_FILE
NONE, //145 KEY_SENDFILE
NONE, //146 KEY_DELETEFILE
NONE, //147 KEY_XFER
NONE, //148 KEY_PROG1
NONE, //149 KEY_PROG2
NONE, //150 KEY_WWW
NONE, //151 KEY_MSDOS
NONE, //152 KEY_SCREENLOCK
NONE, //153 KEY_DIRECTION
NONE, //154 KEY_CYCLEWINDOWS
NONE, //155 KEY_MAIL
NONE, //156 KEY_BOOKMARKS
NONE, //157 KEY_COMPUTER
NONE, //158 KEY_BACK
NONE, //159 KEY_FORWARD
NONE, //160 KEY_CLOSECD
NONE, //161 KEY_EJECTCD
NONE, //162 KEY_EJECTCLOSECD
NONE, //163 KEY_NEXTSONG
NONE, //164 KEY_PLAYPAUSE
NONE, //165 KEY_PREVIOUSSONG
NONE, //166 KEY_STOPCD
NONE, //167 KEY_RECORD
NONE, //168 KEY_REWIND
NONE, //169 KEY_PHONE
NONE, //170 KEY_ISO
NONE, //171 KEY_CONFIG
NONE, //172 KEY_HOMEPAGE
NONE, //173 KEY_REFRESH
NONE, //174 KEY_EXIT
NONE, //175 KEY_MOVE
NONE, //176 KEY_EDIT
NONE, //177 KEY_SCROLLUP
NONE, //178 KEY_SCROLLDOWN
NONE, //179 KEY_KPLEFTPAREN
NONE, //180 KEY_KPRIGHTPAREN
NONE, //181 KEY_NEW
NONE, //182 KEY_REDO
NONE, //183 KEY_F13
NONE, //184 KEY_F14
NONE, //185 KEY_F15
NONE, //186 KEY_F16
NONE, //187 KEY_F17
NONE, //188 KEY_F18
NONE, //189 KEY_F19
NONE, //190 KEY_F20
NONE, //191 KEY_F21
NONE, //192 KEY_F22
NONE, //193 KEY_F23
NONE, //194 KEY_F24
NONE, //195 ???
NONE, //196 ???
NONE, //197 ???
NONE, //198 ???
NONE, //199 ???
NONE, //200 KEY_PLAYCD
NONE, //201 KEY_PAUSECD
NONE, //202 KEY_PROG3
NONE, //203 KEY_PROG4
NONE, //204 KEY_DASHBOARD
NONE, //205 KEY_SUSPEND
NONE, //206 KEY_CLOSE
NONE, //207 KEY_PLAY
NONE, //208 KEY_FASTFORWARD
NONE, //209 KEY_BASSBOOST
NONE, //210 KEY_PRINT
NONE, //211 KEY_HP
NONE, //212 KEY_CAMERA
NONE, //213 KEY_SOUND
NONE, //214 KEY_QUESTION
NONE, //215 KEY_EMAIL
NONE, //216 KEY_CHAT
NONE, //217 KEY_SEARCH
NONE, //218 KEY_CONNECT
NONE, //219 KEY_FINANCE
NONE, //220 KEY_SPORT
NONE, //221 KEY_SHOP
NONE, //222 KEY_ALTERASE
NONE, //223 KEY_CANCEL
NONE, //224 KEY_BRIGHT_DOWN
NONE, //225 KEY_BRIGHT_UP
NONE, //226 KEY_MEDIA
NONE, //227 KEY_SWITCHVIDEO
NONE, //228 KEY_DILLUMTOGGLE
NONE, //229 KEY_DILLUMDOWN
NONE, //230 KEY_DILLUMUP
NONE, //231 KEY_SEND
NONE, //232 KEY_REPLY
NONE, //233 KEY_FORWARDMAIL
NONE, //234 KEY_SAVE
NONE, //235 KEY_DOCUMENTS
NONE, //236 KEY_BATTERY
NONE, //237 KEY_BLUETOOTH
NONE, //238 KEY_WLAN
NONE, //239 KEY_UWB
NONE, //240 KEY_UNKNOWN
NONE, //241 KEY_VIDEO_NEXT
NONE, //242 KEY_VIDEO_PREV
NONE, //243 KEY_BRIGHT_CYCLE
NONE, //244 KEY_BRIGHT_AUTO
NONE, //245 KEY_DISPLAY_OFF
NONE, //246 KEY_WWAN
NONE, //247 KEY_RFKILL
NONE, //248 KEY_MICMUTE
NONE, //249 ???
NONE, //250 ???
NONE, //251 ???
NONE, //252 ???
NONE, //253 ???
NONE, //254 ???
NONE //255 ???
};
uint32_t get_ps2_code(uint16_t key)
{
if (key > 255) return NONE;
return ev2ps2[key];
}
uint32_t get_amiga_code(uint16_t key)
{
if (key > 255) return NONE;
return ev2amiga[key];
}
uint32_t get_archie_code(uint16_t key)
{
if (key > 255) return NONE;
return ev2archie[key];
}
static uint32_t modifier = 0;
uint32_t get_key_mod()
{
return modifier & MODMASK;
}
enum QUIRK
{
QUIRK_NONE = 0,
QUIRK_CWIID,
QUIRK_WIIMOTE,
QUIRK_DS3,
QUIRK_DS4,
QUIRK_DS4TOUCH,
QUIRK_MADCATZ360,
QUIRK_PDSP,
QUIRK_PDSP_ARCADE,
QUIRK_JAMMA,
};
typedef struct
{
uint16_t vid, pid;
char idstr[256];
uint8_t led;
uint8_t mouse;
uint8_t axis_edge[256];
int8_t axis_pos[256];
uint8_t num;
uint8_t has_map;
uint32_t map[NUMBUTTONS];
uint8_t osd_combo;
uint8_t has_mmap;
uint32_t mmap[NUMBUTTONS];
uint16_t jkmap[1024];
uint8_t has_kbdmap;
uint8_t kbdmap[256];
uint16_t guncal[4];
int accx, accy;
int quirk;
int misc_flags;
int mc_a;
int lightgun_req;
int lightgun;
int bind;
char devname[32];
char id[32];
char name[128];
} devInput;
static devInput input[NUMDEV] = {};
#define BTN_NUM (sizeof(devInput::map) / sizeof(devInput::map[0]))
int mfd = -1;
int mwd = -1;
static int set_watch()
{
mwd = -1;
mfd = inotify_init();
if (mfd < 0)
{
printf("ERR: inotify_init");
return -1;
}
mwd = inotify_add_watch(mfd, "/dev/input", IN_MODIFY | IN_CREATE | IN_DELETE);
if (mwd < 0)
{
printf("ERR: inotify_add_watch");
return -1;
}
return mfd;
}
#define EVENT_SIZE ( sizeof (struct inotify_event) )
#define BUF_LEN ( 1024 * ( EVENT_SIZE + 16 ) )
static int check_devs()
{
int result = 0;
int length, i = 0;
char buffer[BUF_LEN];
length = read(mfd, buffer, BUF_LEN);
if (length < 0)
{
printf("ERR: read\n");
return 0;
}
while (i<length)
{
struct inotify_event *event = (struct inotify_event *) &buffer[i];
if (event->len)
{
if (event->mask & IN_CREATE)
{
result = 1;
if (event->mask & IN_ISDIR)
{
printf("The directory %s was created.\n", event->name);
}
else
{
printf("The file %s was created.\n", event->name);
}
}
else if (event->mask & IN_DELETE)
{
result = 1;
if (event->mask & IN_ISDIR)
{
printf("The directory %s was deleted.\n", event->name);
}
else
{
printf("The file %s was deleted.\n", event->name);
}
}
/*
else if ( event->mask & IN_MODIFY )
{
result = 1;
if ( event->mask & IN_ISDIR )
{
printf( "The directory %s was modified.\n", event->name );
}
else
{
printf( "The file %s was modified.\n", event->name );
}
}
*/
}
i += EVENT_SIZE + event->len;
}
return result;
}
static void INThandler(int code)
{
(void)code;
printf("\nExiting...\n");
if (mwd >= 0) inotify_rm_watch(mfd, mwd);
if (mfd >= 0) close(mfd);