Mercurial > repos > blastem
annotate controller_info.c @ 1780:fc9bea5ee079
Fix off-by-one error in evdev init code and allow ALSA device to be specified in config
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 10 Mar 2019 22:11:32 -0700 |
parents | 3a8c4ee68568 |
children | a4cae960fd08 |
rev | line source |
---|---|
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include <string.h> |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
2 #include <stdlib.h> |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
3 #ifndef USE_FBDEV |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include "render_sdl.h" |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
5 #endif |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include "controller_info.h" |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
7 #include "config.h" |
1604
68b05322d971
Don't redundantly store controller GUID when saving a mapping. Remove illegal chars from controller name
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
8 #include "util.h" |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 typedef struct { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 char const *name; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 controller_info info; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 } heuristic; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
15 static heuristic heuristics[] = { |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 //TODO: Add more heuristic rules |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 {"DualShock 4", {.type = TYPE_PSX, .subtype = SUBTYPE_PS4}}, |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 {"PS4", {.type = TYPE_PSX, .subtype = SUBTYPE_PS4}}, |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 {"PS3", {.type = TYPE_PSX, .subtype = SUBTYPE_PS3}}, |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 {"X360", {.type = TYPE_XBOX, .subtype = SUBTYPE_X360}}, |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 {"Xbox 360", {.type = TYPE_XBOX, .subtype = SUBTYPE_X360}}, |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 {"X-box 360", {.type = TYPE_XBOX, .subtype = SUBTYPE_X360}}, |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 {"Xbox One", {.type = TYPE_XBOX, .subtype = SUBTYPE_XBONE}}, |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 {"X-box One", {.type = TYPE_XBOX, .subtype = SUBTYPE_XBONE}}, |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 {"WiiU", {.type = TYPE_NINTENDO, .subtype = SUBTYPE_WIIU}}, |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 {"Wii U", {.type = TYPE_NINTENDO, .subtype = SUBTYPE_WIIU}}, |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 {"Nintendo Switch", {.type = TYPE_NINTENDO, .subtype = SUBTYPE_SWITCH}}, |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 {"Saturn", {.type = TYPE_SEGA, .subtype = SUBTYPE_SATURN}} |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 }; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 const uint32_t num_heuristics = sizeof(heuristics)/sizeof(*heuristics); |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
32 static tern_node *info_config; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
33 static uint8_t loaded; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
34 static const char *subtype_names[] = { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
35 "unknown", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
36 "xbox", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
37 "xbox 360", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
38 "xbone", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
39 "ps2", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
40 "ps3", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
41 "ps4", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
42 "wiiu", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
43 "switch", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
44 "genesis", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
45 "saturn" |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
46 }; |
1645
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
47 static const char *subtype_human_names[] = { |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
48 "unknown", |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
49 "Xbos", |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
50 "Xbox 360", |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
51 "Xbox One", |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
52 "PS2", |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
53 "PS3", |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
54 "PS4", |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
55 "Wii-U", |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
56 "Switch", |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
57 "Genesis", |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
58 "Saturn" |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
59 }; |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
60 static const char *variant_names[] = { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
61 "normal", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
62 "6b bumpers", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
63 "6b right" |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
64 }; |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
65 |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
66 static void load_ctype_config(void) |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 { |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
68 if (!loaded) { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
69 info_config = load_overrideable_config("controller_types.cfg", "controller_types.cfg"); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
70 loaded = 1; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
71 } |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
72 } |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
73 |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
74 controller_info get_controller_info(int joystick) |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
75 { |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
76 #ifndef USE_FBDEV |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
77 load_ctype_config(); |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
78 char guid_string[33]; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
79 SDL_Joystick *stick = render_get_joystick(joystick); |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 SDL_GameController *control = render_get_controller(joystick); |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
81 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(stick), guid_string, sizeof(guid_string)); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
82 tern_node *info = tern_find_node(info_config, guid_string); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
83 if (info) { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
84 controller_info res; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
85 char *subtype = tern_find_ptr(info, "subtype"); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
86 res.subtype = SUBTYPE_UNKNOWN; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
87 if (subtype) { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
88 for (int i = 0; i < SUBTYPE_NUM; i++) |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
89 { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
90 if (!strcmp(subtype_names[i], subtype)) { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
91 res.subtype = i; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
92 break; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
93 } |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
94 } |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
95 } |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
96 switch (res.subtype) |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
97 { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
98 case SUBTYPE_XBOX: |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
99 case SUBTYPE_X360: |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
100 case SUBTYPE_XBONE: |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
101 res.type = TYPE_XBOX; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
102 break; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
103 case SUBTYPE_PS2: |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
104 case SUBTYPE_PS3: |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
105 case SUBTYPE_PS4: |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
106 res.type = TYPE_PSX; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
107 break; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
108 case SUBTYPE_WIIU: |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
109 case SUBTYPE_SWITCH: |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
110 res.type = TYPE_NINTENDO; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
111 break; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
112 case SUBTYPE_GENESIS: |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
113 case SUBTYPE_SATURN: |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
114 res.type = TYPE_SEGA; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
115 break; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
116 default: |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
117 res.type = TYPE_UNKNOWN; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
118 break; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
119 } |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
120 char *variant = tern_find_ptr(info, "variant"); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
121 res.variant = VARIANT_NORMAL; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
122 if (variant) { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
123 for (int i = 0; i < VARIANT_NUM; i++) |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
124 { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
125 if (!strcmp(variant_names[i], variant)) { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
126 res.variant = i; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
127 break; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
128 } |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
129 } |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
130 } |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
131 res.name = control ? SDL_GameControllerName(control) : SDL_JoystickName(stick); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
132 if (control) { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
133 SDL_GameControllerClose(control); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
134 } |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
135 return res; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
136 } |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 if (!control) { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 return (controller_info) { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 .type = TYPE_UNKNOWN, |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 .subtype = SUBTYPE_UNKNOWN, |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 .variant = VARIANT_NORMAL, |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
142 .name = SDL_JoystickName(stick) |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 }; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 const char *name = SDL_GameControllerName(control); |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 SDL_GameControllerClose(control); |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 for (uint32_t i = 0; i < num_heuristics; i++) |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 if (strstr(name, heuristics[i].name)) { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 controller_info res = heuristics[i].info; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 res.name = name; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 return res; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 } |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
155 #else |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
156 const char *name = "Unknown"; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
157 #endif |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 //default to a 360 |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 return (controller_info){ |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 .type = TYPE_GENERIC_MAPPING, |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 .subtype = SUBTYPE_UNKNOWN, |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 .variant = VARIANT_NORMAL, |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 .name = name |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 }; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
167 static void mappings_iter(char *key, tern_val val, uint8_t valtype, void *data) |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
168 { |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
169 #ifndef USE_FBDEV |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
170 if (valtype != TVAL_NODE) { |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
171 return; |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
172 } |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
173 char *mapping = tern_find_ptr(val.ptrval, "mapping"); |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
174 if (mapping) { |
1604
68b05322d971
Don't redundantly store controller GUID when saving a mapping. Remove illegal chars from controller name
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
175 const char *parts[] = {key, ",", mapping}; |
68b05322d971
Don't redundantly store controller GUID when saving a mapping. Remove illegal chars from controller name
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
176 char * full = alloc_concat_m(3, parts); |
68b05322d971
Don't redundantly store controller GUID when saving a mapping. Remove illegal chars from controller name
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
177 SDL_GameControllerAddMapping(full); |
68b05322d971
Don't redundantly store controller GUID when saving a mapping. Remove illegal chars from controller name
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
178 free(full); |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
179 } |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
180 #endif |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
181 } |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
182 |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
183 void controller_add_mappings(void) |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
184 { |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
185 load_ctype_config(); |
1604
68b05322d971
Don't redundantly store controller GUID when saving a mapping. Remove illegal chars from controller name
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
186 if (info_config) { |
68b05322d971
Don't redundantly store controller GUID when saving a mapping. Remove illegal chars from controller name
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
187 tern_foreach(info_config, mappings_iter, NULL); |
68b05322d971
Don't redundantly store controller GUID when saving a mapping. Remove illegal chars from controller name
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
188 } |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
189 } |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
190 |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
191 void save_controller_info(int joystick, controller_info *info) |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
192 { |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
193 #ifndef USE_FBDEV |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
194 char guid_string[33]; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
195 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string)); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
196 tern_node *existing = tern_find_node(info_config, guid_string); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
197 existing = tern_insert_ptr(existing, "subtype", (void *)subtype_names[info->subtype]); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
198 existing = tern_insert_ptr(existing, "variant", (void *)variant_names[info->variant]); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
199 info_config = tern_insert_node(info_config, guid_string, existing); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
200 persist_config_at(info_config, "controller_types.cfg"); |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
201 #endif |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
202 } |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
203 |
1600
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
204 void save_controller_mapping(int joystick, char *mapping_string) |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
205 { |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
206 #ifndef USE_FBDEV |
1600
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
207 char guid_string[33]; |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
208 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string)); |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
209 tern_node *existing = tern_find_node(info_config, guid_string); |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
210 existing = tern_insert_ptr(existing, "mapping", mapping_string); |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
211 info_config = tern_insert_node(info_config, guid_string, existing); |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
212 persist_config_at(info_config, "controller_types.cfg"); |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
213 #endif |
1600
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
214 } |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
215 |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
216 char const *labels_xbox[] = { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
217 "A", "B", "X", "Y", "Back", NULL, "Start", "Click", "Click", "White", "Black", "LT", "RT" |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
218 }; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
219 char const *labels_360[] = { |
1597
75aa418d0227
Use better names for "Guide" button on PS and Xbox controllers, handle d-pad directions in get_button_label
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
220 "A", "B", "X", "Y", "Back", "Xbox", "Start", "Click", "Click", "LB", "RB", "LT", "RT" |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
221 }; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
222 static char const *labels_xbone[] = { |
1597
75aa418d0227
Use better names for "Guide" button on PS and Xbox controllers, handle d-pad directions in get_button_label
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
223 "A", "B", "X", "Y", "View", "Xbox", "Menu", "Click", "Click", "LB", "RB", "LT", "RT" |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
224 }; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
225 static char const *labels_ps3[] = { |
1597
75aa418d0227
Use better names for "Guide" button on PS and Xbox controllers, handle d-pad directions in get_button_label
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
226 "cross", "circle", "square", "triangle", "Select", "PS", "Start", "L3", "R3", "L1", "R1", "L2", "R2" |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
227 }; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
228 static char const *labels_ps4[] = { |
1597
75aa418d0227
Use better names for "Guide" button on PS and Xbox controllers, handle d-pad directions in get_button_label
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
229 "cross", "circle", "square", "triangle", "Share", "PS", "Options", "L3", "R3", "L1", "R1", "L2", "R2" |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
230 }; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
231 static char const *labels_nintendo[] = { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
232 "B", "A", "Y", "X", "-", "Home", "+", "Click", "Click", "L", "R", "ZL", "ZR" |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
233 }; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
234 static char const *labels_genesis[] = { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
235 "A", "B", "X", "Y", NULL, NULL, "Start", NULL, NULL, "Z", "C", NULL, "Mode" |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
236 }; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
237 static char const *labels_saturn[] = { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
238 "A", "B", "X", "Y", NULL, NULL, "Start", NULL, NULL, "Z", "C", "LT", "RT" |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
239 }; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
240 |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
241 static const char** label_source(controller_info *info) |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
242 { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
243 if (info->type == TYPE_UNKNOWN || info->type == TYPE_GENERIC_MAPPING || info->subtype ==SUBTYPE_X360) { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
244 return labels_360; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
245 } else if (info->type == TYPE_NINTENDO) { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
246 return labels_nintendo; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
247 } else if (info->type == TYPE_PSX) { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
248 if (info->subtype == SUBTYPE_PS4) { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
249 return labels_ps4; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
250 } else { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 return labels_ps3; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
252 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
253 } else if (info->type == TYPE_XBOX) { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
254 if (info->subtype == SUBTYPE_XBONE) { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
255 return labels_xbone; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
256 } else { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
257 return labels_xbox; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
258 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
259 } else { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
260 if (info->subtype == SUBTYPE_GENESIS) { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
261 return labels_genesis; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
262 } else { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
263 return labels_saturn; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
265 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
266 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
267 |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
268 const char *get_button_label(controller_info *info, int button) |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
269 { |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
270 #ifndef USE_FBDEV |
1597
75aa418d0227
Use better names for "Guide" button on PS and Xbox controllers, handle d-pad directions in get_button_label
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
271 if (button >= SDL_CONTROLLER_BUTTON_DPAD_UP) { |
75aa418d0227
Use better names for "Guide" button on PS and Xbox controllers, handle d-pad directions in get_button_label
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
272 static char const * dirs[] = {"Up", "Down", "Left", "Right"}; |
75aa418d0227
Use better names for "Guide" button on PS and Xbox controllers, handle d-pad directions in get_button_label
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
273 return dirs[button - SDL_CONTROLLER_BUTTON_DPAD_UP]; |
75aa418d0227
Use better names for "Guide" button on PS and Xbox controllers, handle d-pad directions in get_button_label
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
274 } |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
275 #endif |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
276 return label_source(info)[button]; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
277 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
278 |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
279 static char const *axis_labels[] = { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
280 "Left X", "Left Y", "Right X", "Right Y" |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
281 }; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
282 const char *get_axis_label(controller_info *info, int axis) |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
283 { |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
284 #ifndef USE_FBDEV |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
285 if (axis < SDL_CONTROLLER_AXIS_TRIGGERLEFT) { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
286 return axis_labels[axis]; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
287 } else { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
288 return label_source(info)[axis - SDL_CONTROLLER_AXIS_TRIGGERLEFT + SDL_CONTROLLER_BUTTON_RIGHTSHOULDER + 1]; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
289 } |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
290 #else |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
291 return NULL; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
292 #endif |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
293 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
294 |
1608
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
295 char *make_controller_type_key(controller_info *info) |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
296 { |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
297 const char *subtype; |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
298 if (info->subtype == SUBTYPE_UNKNOWN) { |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
299 switch(info->type) |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
300 { |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
301 case TYPE_XBOX: |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
302 subtype = subtype_names[SUBTYPE_X360]; |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
303 break; |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
304 case TYPE_PSX: |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
305 subtype = subtype_names[SUBTYPE_PS4]; |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
306 break; |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
307 case TYPE_NINTENDO: |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
308 subtype = subtype_names[SUBTYPE_SWITCH]; |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
309 break; |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
310 default: |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
311 subtype = "unknown"; |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
312 } |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
313 } else { |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
314 subtype = subtype_names[info->subtype]; |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
315 } |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
316 const char *variant = variant_names[info->variant]; |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
317 const char *parts[] = {subtype, "_", variant}; |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
318 char *ret = alloc_concat_m(3, parts); |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
319 for (char *cur = ret; *cur; cur++) |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
320 { |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
321 if (*cur == ' ') |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
322 { |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
323 *cur = '_'; |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
324 } |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
325 } |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
326 return ret; |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
327 } |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
328 |
1645
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
329 char *make_human_readable_type_name(controller_info *info) |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
330 { |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
331 const char *base = subtype_human_names[info->subtype]; |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
332 char *prefix; |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
333 if (info->variant == VARIANT_NORMAL) { |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
334 prefix = "Normal "; |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
335 } else { |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
336 static const char *parts[] = {"6 button (", NULL, "/", NULL, ") "}; |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
337 #ifdef USE_FBDEV |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
338 parts[1] = parts[3] = "??"; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
339 #else |
1645
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
340 if (info->variant == VARIANT_6B_BUMPERS) { |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
341 parts[1] = get_button_label(info, SDL_CONTROLLER_BUTTON_LEFTSHOULDER); |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
342 parts[3] = get_button_label(info, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
343 } else { |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
344 parts[1] = get_button_label(info, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
345 parts[3] = get_axis_label(info, SDL_CONTROLLER_AXIS_TRIGGERRIGHT); |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
346 } |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
347 #endif |
1645
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
348 prefix = alloc_concat_m(5, parts); |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
349 } |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
350 char *ret = alloc_concat(prefix, base); |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
351 if (info->variant != VARIANT_NORMAL) { |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
352 free(prefix); |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
353 } |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
354 return ret; |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
355 } |
84ef1eb2c96a
Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
356 |