Mercurial > repos > blastem
annotate controller_info.c @ 2624:6bd492b8172e
Update gamecontrollerdb.txt and tweak the entries and controller type heuristics so they work out of the box (at least on Win/Linux)
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 22 Feb 2025 22:14:03 -0800 |
parents | 639561060a28 |
children | 36aa9ead0e62 |
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> |
2215
a8af8d898a7c
Fix windows build for real
Michael Pavone <pavone@retrodev.com>
parents:
2018
diff
changeset
|
3 #include "render.h" |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
4 #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
|
5 #include "render_sdl.h" |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
6 #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
|
7 #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
|
8 #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
|
9 #include "util.h" |
1852
a4cae960fd08
Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents:
1779
diff
changeset
|
10 #include "blastem.h" |
1861
fc05f49075c2
Reprocess bindings when SDL2 mappings, controller types or controller order change
Michael Pavone <pavone@retrodev.com>
parents:
1859
diff
changeset
|
11 #include "bindings.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
|
12 |
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 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
|
14 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
|
15 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
|
16 } 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
|
17 |
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
|
18 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
|
19 //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
|
20 {"DualShock 4", {.type = TYPE_PSX, .subtype = SUBTYPE_PS4}}, |
2220
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
21 {"PS5", {.type = TYPE_PSX, .subtype = SUBTYPE_PS5}}, |
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
|
22 {"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
|
23 {"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
|
24 {"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
|
25 {"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
|
26 {"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
|
27 {"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
|
28 {"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
|
29 {"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
|
30 {"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
|
31 {"Nintendo Switch", {.type = TYPE_NINTENDO, .subtype = SUBTYPE_SWITCH}}, |
2547
8675663d4984
Add controller heuristic for M30 so the BT version works out of the box
Michael Pavone <pavone@retrodev.com>
parents:
2526
diff
changeset
|
32 {"Saturn", {.type = TYPE_SEGA, .subtype = SUBTYPE_SATURN}}, |
2624
6bd492b8172e
Update gamecontrollerdb.txt and tweak the entries and controller type heuristics so they work out of the box (at least on Win/Linux)
Michael Pavone <pavone@retrodev.com>
parents:
2573
diff
changeset
|
33 {"8BitDo M30", {.type = TYPE_SEGA, .subtype = SUBTYPE_GENESIS, .variant = VARIANT_8BUTTON}}, |
6bd492b8172e
Update gamecontrollerdb.txt and tweak the entries and controller type heuristics so they work out of the box (at least on Win/Linux)
Michael Pavone <pavone@retrodev.com>
parents:
2573
diff
changeset
|
34 {"Mini 3B Controller", {.type = TYPE_SEGA, .subtype = SUBTYPE_GENESIS, .variant = VARIANT_3BUTTON}}, |
6bd492b8172e
Update gamecontrollerdb.txt and tweak the entries and controller type heuristics so they work out of the box (at least on Win/Linux)
Michael Pavone <pavone@retrodev.com>
parents:
2573
diff
changeset
|
35 {"Mini 6B Controller", {.type = TYPE_SEGA, .subtype = SUBTYPE_GENESIS, .variant = VARIANT_6B_BUMPERS}} |
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
|
36 }; |
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
|
37 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
|
38 |
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
|
39 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
|
40 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
|
41 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
|
42 "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
|
43 "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
|
44 "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
|
45 "xbone", |
2220
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
46 "xbox elite", |
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
|
47 "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
|
48 "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
|
49 "ps4", |
2220
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
50 "ps5", |
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
|
51 "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
|
52 "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
|
53 "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
|
54 "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
|
55 }; |
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
|
56 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
|
57 "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
|
58 "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
|
59 "Xbox 360", |
2220
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
60 "Xbox One/Series", |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
61 "Xbox Elite", |
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
|
62 "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
|
63 "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
|
64 "PS4", |
2220
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
65 "PS5", |
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
|
66 "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
|
67 "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
|
68 "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
|
69 "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
|
70 }; |
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
|
71 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
|
72 "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
|
73 "6b bumpers", |
2015
8a64d86cc362
Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
74 "6b right", |
8a64d86cc362
Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
75 "3button", |
8a64d86cc362
Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
76 "8button" |
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
|
77 }; |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
78 |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
79 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
|
80 { |
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 if (!loaded) { |
1852
a4cae960fd08
Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents:
1779
diff
changeset
|
82 info_config = load_overrideable_config("controller_types.cfg", "controller_types.cfg", NULL); |
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
|
83 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
|
84 } |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
85 } |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
86 |
2317
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
87 #define DEFAULT_DEADZONE 4000 |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
88 #define DEFAULT_DEADZONE_STR "4000" |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
89 |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
90 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
|
91 { |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
92 #ifndef USE_FBDEV |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
93 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
|
94 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
|
95 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
|
96 SDL_GameController *control = render_get_controller(joystick); |
2573
639561060a28
Do a little work towards eventual support for building against SDL3
Michael Pavone <pavone@retrodev.com>
parents:
2561
diff
changeset
|
97 #if SDL_VERSION_ATLEAST(3, 2, 0) |
639561060a28
Do a little work towards eventual support for building against SDL3
Michael Pavone <pavone@retrodev.com>
parents:
2561
diff
changeset
|
98 SDL_GUIDToString(SDL_JoystickGetGUID(stick), guid_string, sizeof(guid_string)); |
639561060a28
Do a little work towards eventual support for building against SDL3
Michael Pavone <pavone@retrodev.com>
parents:
2561
diff
changeset
|
99 #else |
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
|
100 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(stick), guid_string, sizeof(guid_string)); |
2573
639561060a28
Do a little work towards eventual support for building against SDL3
Michael Pavone <pavone@retrodev.com>
parents:
2561
diff
changeset
|
101 #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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 { |
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 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
|
111 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
|
112 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
|
113 } |
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 } |
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 } |
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 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
|
117 { |
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 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
|
119 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
|
120 case SUBTYPE_XBONE: |
2292
7df357522c49
Fix saved controller type loading for Xbox Elite controllers
Michael Pavone <pavone@retrodev.com>
parents:
2220
diff
changeset
|
121 case SUBTYPE_XBOX_ELITE: |
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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 } |
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
|
141 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
|
142 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
|
143 if (variant) { |
2624
6bd492b8172e
Update gamecontrollerdb.txt and tweak the entries and controller type heuristics so they work out of the box (at least on Win/Linux)
Michael Pavone <pavone@retrodev.com>
parents:
2573
diff
changeset
|
144 int i; |
6bd492b8172e
Update gamecontrollerdb.txt and tweak the entries and controller type heuristics so they work out of the box (at least on Win/Linux)
Michael Pavone <pavone@retrodev.com>
parents:
2573
diff
changeset
|
145 for (i = 0; i < VARIANT_NUM; i++) |
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
|
146 { |
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
|
147 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
|
148 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
|
149 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
|
150 } |
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
|
151 } |
2624
6bd492b8172e
Update gamecontrollerdb.txt and tweak the entries and controller type heuristics so they work out of the box (at least on Win/Linux)
Michael Pavone <pavone@retrodev.com>
parents:
2573
diff
changeset
|
152 if (i == VARIANT_NUM && !strcmp("6button", variant)) { |
6bd492b8172e
Update gamecontrollerdb.txt and tweak the entries and controller type heuristics so they work out of the box (at least on Win/Linux)
Michael Pavone <pavone@retrodev.com>
parents:
2573
diff
changeset
|
153 //workaround for some bad saved configs caused by a silly bug |
6bd492b8172e
Update gamecontrollerdb.txt and tweak the entries and controller type heuristics so they work out of the box (at least on Win/Linux)
Michael Pavone <pavone@retrodev.com>
parents:
2573
diff
changeset
|
154 res.variant = VARIANT_8BUTTON; |
6bd492b8172e
Update gamecontrollerdb.txt and tweak the entries and controller type heuristics so they work out of the box (at least on Win/Linux)
Michael Pavone <pavone@retrodev.com>
parents:
2573
diff
changeset
|
155 } |
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
|
156 } |
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
|
157 res.name = control ? SDL_GameControllerName(control) : SDL_JoystickName(stick); |
2317
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
158 res.stick_deadzone = atoi(tern_find_ptr_default(info, "stick_deadzone", DEFAULT_DEADZONE_STR)); |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
159 res.trigger_deadzone = atoi(tern_find_ptr_default(info, "trigger_deadzone", DEFAULT_DEADZONE_STR)); |
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
|
160 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
|
161 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
|
162 } |
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
|
163 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
|
164 } |
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
|
165 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
|
166 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
|
167 .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
|
168 .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
|
169 .variant = VARIANT_NORMAL, |
2317
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
170 .name = SDL_JoystickName(stick), |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
171 .stick_deadzone = DEFAULT_DEADZONE, |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
172 .trigger_deadzone = DEFAULT_DEADZONE |
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
|
173 }; |
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
|
174 } |
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
|
175 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
|
176 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
|
177 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
|
178 { |
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
|
179 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
|
180 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
|
181 res.name = name; |
2317
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
182 res.stick_deadzone = DEFAULT_DEADZONE; |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
183 res.trigger_deadzone = DEFAULT_DEADZONE; |
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
|
184 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
|
185 } |
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
|
186 } |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
187 #else |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
188 const char *name = "Unknown"; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
189 #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
|
190 //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
|
191 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
|
192 .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
|
193 .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
|
194 .variant = VARIANT_NORMAL, |
2317
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
195 .name = name, |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
196 .stick_deadzone = DEFAULT_DEADZONE, |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
197 .trigger_deadzone = DEFAULT_DEADZONE |
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
|
198 }; |
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
|
199 } |
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
|
200 |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
201 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
|
202 { |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
203 #ifndef USE_FBDEV |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
204 if (valtype != TVAL_NODE) { |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
205 return; |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
206 } |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
207 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
|
208 if (mapping) { |
2561
8dc8eb079584
Workaround for weird controller mapping bug on Windows
Michael Pavone <pavone@retrodev.com>
parents:
2547
diff
changeset
|
209 const char *parts[] = {key, ",", mapping, ","}; |
8dc8eb079584
Workaround for weird controller mapping bug on Windows
Michael Pavone <pavone@retrodev.com>
parents:
2547
diff
changeset
|
210 #if SDL_VERSION_ATLEAST(2,0,10) |
8dc8eb079584
Workaround for weird controller mapping bug on Windows
Michael Pavone <pavone@retrodev.com>
parents:
2547
diff
changeset
|
211 //For reasons that are unclear, in some cases the last mapping element |
8dc8eb079584
Workaround for weird controller mapping bug on Windows
Michael Pavone <pavone@retrodev.com>
parents:
2547
diff
changeset
|
212 //seems to get dropped unless there is a trailing comma |
8dc8eb079584
Workaround for weird controller mapping bug on Windows
Michael Pavone <pavone@retrodev.com>
parents:
2547
diff
changeset
|
213 char * full = alloc_concat_m(4, parts); |
8dc8eb079584
Workaround for weird controller mapping bug on Windows
Michael Pavone <pavone@retrodev.com>
parents:
2547
diff
changeset
|
214 #else |
8dc8eb079584
Workaround for weird controller mapping bug on Windows
Michael Pavone <pavone@retrodev.com>
parents:
2547
diff
changeset
|
215 //In SDL 2.0.9 and below, it is not legal to have a trailing comma |
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
|
216 char * full = alloc_concat_m(3, parts); |
2561
8dc8eb079584
Workaround for weird controller mapping bug on Windows
Michael Pavone <pavone@retrodev.com>
parents:
2547
diff
changeset
|
217 #endif |
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
|
218 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
|
219 free(full); |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
220 } |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
221 #endif |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
222 } |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
223 |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
224 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
|
225 { |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
226 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
|
227 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
|
228 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
|
229 } |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
230 } |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
231 |
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
|
232 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
|
233 { |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
234 #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
|
235 char guid_string[33]; |
2573
639561060a28
Do a little work towards eventual support for building against SDL3
Michael Pavone <pavone@retrodev.com>
parents:
2561
diff
changeset
|
236 #if SDL_VERSION_ATLEAST(3, 2, 0) |
639561060a28
Do a little work towards eventual support for building against SDL3
Michael Pavone <pavone@retrodev.com>
parents:
2561
diff
changeset
|
237 SDL_GUIDToString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string)); |
639561060a28
Do a little work towards eventual support for building against SDL3
Michael Pavone <pavone@retrodev.com>
parents:
2561
diff
changeset
|
238 #else |
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
|
239 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string)); |
2573
639561060a28
Do a little work towards eventual support for building against SDL3
Michael Pavone <pavone@retrodev.com>
parents:
2561
diff
changeset
|
240 #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
|
241 tern_node *existing = tern_find_node(info_config, guid_string); |
1859
52f136052ab0
Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
242 existing = tern_insert_ptr(existing, "subtype", strdup(subtype_names[info->subtype])); |
52f136052ab0
Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents:
1852
diff
changeset
|
243 existing = tern_insert_ptr(existing, "variant", strdup(variant_names[info->variant])); |
2317
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
244 char buffer[32]; |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
245 snprintf(buffer, sizeof(buffer), "%d", info->stick_deadzone); |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
246 buffer[31] = 0; |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
247 existing = tern_insert_ptr(existing, "stick_deadzone", strdup(buffer)); |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
248 snprintf(buffer, sizeof(buffer), "%d", info->trigger_deadzone); |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
249 buffer[31] = 0; |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2315
diff
changeset
|
250 existing = tern_insert_ptr(existing, "trigger_deadzone", strdup(buffer)); |
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
|
251 info_config = tern_insert_node(info_config, guid_string, existing); |
1852
a4cae960fd08
Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents:
1779
diff
changeset
|
252 persist_config_at(config, info_config, "controller_types.cfg"); |
1861
fc05f49075c2
Reprocess bindings when SDL2 mappings, controller types or controller order change
Michael Pavone <pavone@retrodev.com>
parents:
1859
diff
changeset
|
253 handle_joy_added(joystick); |
2215
a8af8d898a7c
Fix windows build for real
Michael Pavone <pavone@retrodev.com>
parents:
2018
diff
changeset
|
254 #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
|
255 } |
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
|
256 |
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
|
257 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
|
258 { |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
259 #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
|
260 char guid_string[33]; |
2573
639561060a28
Do a little work towards eventual support for building against SDL3
Michael Pavone <pavone@retrodev.com>
parents:
2561
diff
changeset
|
261 #if SDL_VERSION_ATLEAST(3, 2, 0) |
639561060a28
Do a little work towards eventual support for building against SDL3
Michael Pavone <pavone@retrodev.com>
parents:
2561
diff
changeset
|
262 SDL_GUIDToString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string)); |
639561060a28
Do a little work towards eventual support for building against SDL3
Michael Pavone <pavone@retrodev.com>
parents:
2561
diff
changeset
|
263 #else |
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
|
264 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string)); |
2573
639561060a28
Do a little work towards eventual support for building against SDL3
Michael Pavone <pavone@retrodev.com>
parents:
2561
diff
changeset
|
265 #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
|
266 tern_node *existing = tern_find_node(info_config, guid_string); |
2218
58774a77f2e0
Fix crash when rebinding a controller
Michael Pavone <pavone@retrodev.com>
parents:
2215
diff
changeset
|
267 existing = tern_insert_ptr(existing, "mapping", strdup(mapping_string)); |
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
|
268 info_config = tern_insert_node(info_config, guid_string, existing); |
1852
a4cae960fd08
Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents:
1779
diff
changeset
|
269 persist_config_at(config, info_config, "controller_types.cfg"); |
2561
8dc8eb079584
Workaround for weird controller mapping bug on Windows
Michael Pavone <pavone@retrodev.com>
parents:
2547
diff
changeset
|
270 const char *parts[] = {guid_string, ",", mapping_string, ","}; |
8dc8eb079584
Workaround for weird controller mapping bug on Windows
Michael Pavone <pavone@retrodev.com>
parents:
2547
diff
changeset
|
271 #if SDL_VERSION_ATLEAST(2,0,10) |
8dc8eb079584
Workaround for weird controller mapping bug on Windows
Michael Pavone <pavone@retrodev.com>
parents:
2547
diff
changeset
|
272 //For reasons that are unclear, in some cases the last mapping element |
8dc8eb079584
Workaround for weird controller mapping bug on Windows
Michael Pavone <pavone@retrodev.com>
parents:
2547
diff
changeset
|
273 //seems to get dropped unless there is a trailing comma |
8dc8eb079584
Workaround for weird controller mapping bug on Windows
Michael Pavone <pavone@retrodev.com>
parents:
2547
diff
changeset
|
274 char * full = alloc_concat_m(4, parts); |
8dc8eb079584
Workaround for weird controller mapping bug on Windows
Michael Pavone <pavone@retrodev.com>
parents:
2547
diff
changeset
|
275 #else |
8dc8eb079584
Workaround for weird controller mapping bug on Windows
Michael Pavone <pavone@retrodev.com>
parents:
2547
diff
changeset
|
276 //In SDL 2.0.9 and below, it is not legal to have a trailing comma |
1861
fc05f49075c2
Reprocess bindings when SDL2 mappings, controller types or controller order change
Michael Pavone <pavone@retrodev.com>
parents:
1859
diff
changeset
|
277 char * full = alloc_concat_m(3, parts); |
2561
8dc8eb079584
Workaround for weird controller mapping bug on Windows
Michael Pavone <pavone@retrodev.com>
parents:
2547
diff
changeset
|
278 #endif |
2315
b67e4e930fa4
Workaround for SDL2 being unreliable in updating mapping for already "open" game controller
Michael Pavone <pavone@retrodev.com>
parents:
2292
diff
changeset
|
279 uint8_t gc_events = render_are_gamepad_events_enabled(); |
b67e4e930fa4
Workaround for SDL2 being unreliable in updating mapping for already "open" game controller
Michael Pavone <pavone@retrodev.com>
parents:
2292
diff
changeset
|
280 render_enable_gamepad_events(0); |
1861
fc05f49075c2
Reprocess bindings when SDL2 mappings, controller types or controller order change
Michael Pavone <pavone@retrodev.com>
parents:
1859
diff
changeset
|
281 SDL_GameControllerAddMapping(full); |
2315
b67e4e930fa4
Workaround for SDL2 being unreliable in updating mapping for already "open" game controller
Michael Pavone <pavone@retrodev.com>
parents:
2292
diff
changeset
|
282 render_enable_gamepad_events(gc_events); |
1861
fc05f49075c2
Reprocess bindings when SDL2 mappings, controller types or controller order change
Michael Pavone <pavone@retrodev.com>
parents:
1859
diff
changeset
|
283 free(full); |
fc05f49075c2
Reprocess bindings when SDL2 mappings, controller types or controller order change
Michael Pavone <pavone@retrodev.com>
parents:
1859
diff
changeset
|
284 handle_joy_added(joystick); |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
285 #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
|
286 } |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
287 |
2018
193b804c9845
Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents:
2015
diff
changeset
|
288 void delete_controller_info(void) |
193b804c9845
Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents:
2015
diff
changeset
|
289 { |
193b804c9845
Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents:
2015
diff
changeset
|
290 delete_custom_config_at("controller_types.cfg"); |
193b804c9845
Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents:
2015
diff
changeset
|
291 loaded = 0; |
193b804c9845
Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents:
2015
diff
changeset
|
292 tern_free(info_config); |
193b804c9845
Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents:
2015
diff
changeset
|
293 info_config = NULL; |
193b804c9845
Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents:
2015
diff
changeset
|
294 render_reset_mappings(); |
193b804c9845
Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents:
2015
diff
changeset
|
295 } |
193b804c9845
Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents:
2015
diff
changeset
|
296 |
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
|
297 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
|
298 "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
|
299 }; |
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
|
300 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
|
301 "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
|
302 }; |
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
|
303 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
|
304 "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
|
305 }; |
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
|
306 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
|
307 "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
|
308 }; |
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
|
309 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
|
310 "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
|
311 }; |
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
|
312 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
|
313 "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
|
314 }; |
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
|
315 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
|
316 "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
|
317 }; |
2015
8a64d86cc362
Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
318 static char const *labels_genesis_3button[] = { |
8a64d86cc362
Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
319 "A", "B", NULL, NULL, NULL, NULL, "Start", NULL, NULL, NULL, "C", NULL, "Mode" |
8a64d86cc362
Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
320 }; |
8a64d86cc362
Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
321 static char const *labels_genesis_8button[] = { |
8a64d86cc362
Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
322 "A", "B", "X", "Y", "Mode", NULL, "Start", NULL, NULL, "Z", "C", "L", "R" |
8a64d86cc362
Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
323 }; |
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
|
324 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
|
325 "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
|
326 }; |
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
|
327 |
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
|
328 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
|
329 { |
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
|
330 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
|
331 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
|
332 } 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
|
333 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
|
334 } else if (info->type == TYPE_PSX) { |
2220
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
335 if (info->subtype >= SUBTYPE_PS4) { |
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
|
336 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
|
337 } 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
|
338 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
|
339 } |
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
|
340 } else if (info->type == TYPE_XBOX) { |
2220
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
341 if (info->subtype >= SUBTYPE_XBONE) { |
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
|
342 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
|
343 } 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
|
344 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
|
345 } |
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
|
346 } 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
|
347 if (info->subtype == SUBTYPE_GENESIS) { |
2015
8a64d86cc362
Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
348 if (info->variant == VARIANT_8BUTTON) { |
8a64d86cc362
Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
349 return labels_genesis_8button; |
8a64d86cc362
Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
350 } else if (info->variant == VARIANT_3BUTTON) { |
8a64d86cc362
Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
351 return labels_genesis_3button; |
8a64d86cc362
Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
352 } else { |
8a64d86cc362
Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
353 return labels_genesis; |
8a64d86cc362
Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
354 } |
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
|
355 } 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
|
356 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
|
357 } |
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
|
358 } |
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
|
359 } |
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
|
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
|
361 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
|
362 { |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
363 #ifndef USE_FBDEV |
2526
9c6f53425140
Fix SDL version guard for paddle buttons
Michael Pavone <pavone@retrodev.com>
parents:
2317
diff
changeset
|
364 #if SDL_VERSION_ATLEAST(2,0,14) |
2220
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
365 if (info->subtype == SUBTYPE_XBOX_ELITE && button >= SDL_CONTROLLER_BUTTON_PADDLE1 && button <= SDL_CONTROLLER_BUTTON_PADDLE4) { |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
366 static char const * names[] = {"Paddle 1", "Paddle 2", "Paddle 3", "Paddle 4"}; |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
367 return names[button - SDL_CONTROLLER_BUTTON_PADDLE1]; |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
368 } |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
369 if (button == SDL_CONTROLLER_BUTTON_TOUCHPAD && (info->subtype == SUBTYPE_PS4 || info->subtype == SUBTYPE_PS5)) { |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
370 return "Touchpad"; |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
371 } |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
372 if (button == SDL_CONTROLLER_BUTTON_MISC1) { |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
373 switch (info->subtype) |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
374 { |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
375 case SUBTYPE_XBONE: |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
376 case SUBTYPE_XBOX_ELITE: |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
377 return "Share"; |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
378 case SUBTYPE_PS5: |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
379 return "Microphone"; |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
380 case SUBTYPE_SWITCH: |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
381 return "Capture"; |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
382 } |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
383 } |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
384 #endif |
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
|
385 if (button >= SDL_CONTROLLER_BUTTON_DPAD_UP) { |
2220
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
386 if (button <= SDL_CONTROLLER_BUTTON_DPAD_RIGHT) { |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
387 static char const * dirs[] = {"Up", "Down", "Left", "Right"}; |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
388 return dirs[button - SDL_CONTROLLER_BUTTON_DPAD_UP]; |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
389 } |
dd9d43c67986
Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents:
2218
diff
changeset
|
390 return NULL; |
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
|
391 } |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
392 #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
|
393 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
|
394 } |
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
|
395 |
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
|
396 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
|
397 "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
|
398 }; |
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
|
399 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
|
400 { |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
401 #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
|
402 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
|
403 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
|
404 } 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
|
405 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
|
406 } |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
407 #else |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
408 return NULL; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
409 #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
|
410 } |
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
|
411 |
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
|
412 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
|
413 { |
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
|
414 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
|
415 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
|
416 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
|
417 { |
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
|
418 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
|
419 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
|
420 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
|
421 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
|
422 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
|
423 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
|
424 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
|
425 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
|
426 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
|
427 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
|
428 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
|
429 } |
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
|
430 } 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
|
431 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
|
432 } |
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
|
433 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
|
434 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
|
435 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
|
436 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
|
437 { |
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
|
438 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
|
439 { |
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
|
440 *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
|
441 } |
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
|
442 } |
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
|
443 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
|
444 } |
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
|
445 |
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
|
446 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
|
447 { |
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
|
448 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
|
449 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
|
450 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
|
451 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
|
452 } 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
|
453 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
|
454 #ifdef USE_FBDEV |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
455 parts[1] = parts[3] = "??"; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
456 #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
|
457 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
|
458 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
|
459 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
|
460 } 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
|
461 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
|
462 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
|
463 } |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
1645
diff
changeset
|
464 #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
|
465 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
|
466 } |
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
|
467 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
|
468 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
|
469 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
|
470 } |
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
|
471 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
|
472 } |
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
|
473 |