Mercurial > repos > blastem
annotate controller_info.c @ 1603:c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 31 Jul 2018 23:08:52 -0700 |
parents | 7f39c40b4b25 |
children | 68b05322d971 |
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> |
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
|
2 #include "render_sdl.h" |
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
|
3 #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
|
4 #include "config.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
|
5 |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 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
|
7 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
|
8 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
|
9 } 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
|
10 |
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
|
11 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
|
12 //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
|
13 {"DualShock 4", {.type = TYPE_PSX, .subtype = SUBTYPE_PS4}}, |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 {"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
|
15 {"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
|
16 {"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
|
17 {"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
|
18 {"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
|
19 {"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
|
20 {"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
|
21 {"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
|
22 {"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
|
23 {"Nintendo Switch", {.type = TYPE_NINTENDO, .subtype = SUBTYPE_SWITCH}}, |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 {"Saturn", {.type = TYPE_SEGA, .subtype = SUBTYPE_SATURN}} |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 }; |
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 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
|
27 |
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
|
28 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
|
29 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
|
30 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
|
31 "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
|
32 "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
|
33 "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
|
34 "xbone", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
35 "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
|
36 "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
|
37 "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
|
38 "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
|
39 "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
|
40 "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
|
41 "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
|
42 }; |
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 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
|
44 "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
|
45 "6b bumpers", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
46 "6b right" |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
47 }; |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
48 |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
49 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
|
50 { |
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 if (!loaded) { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
52 info_config = load_overrideable_config("controller_types.cfg", "controller_types.cfg"); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
53 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
|
54 } |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
55 } |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
56 |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
57 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
|
58 { |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
59 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
|
60 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
|
61 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
|
62 SDL_GameController *control = render_get_controller(joystick); |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
63 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(stick), guid_string, sizeof(guid_string)); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
64 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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 { |
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 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
|
73 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
|
74 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
|
75 } |
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
|
76 } |
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 } |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
78 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
|
79 { |
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
|
80 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
|
81 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
|
82 case SUBTYPE_XBONE: |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
83 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 } |
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 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
|
103 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
|
104 if (variant) { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
105 for (int i = 0; i < VARIANT_NUM; i++) |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
106 { |
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 (!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
|
108 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
|
109 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
|
110 } |
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 } |
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 } |
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 res.name = control ? SDL_GameControllerName(control) : SDL_JoystickName(stick); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
114 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
|
115 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
|
116 } |
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 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
|
118 } |
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
|
119 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
|
120 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
|
121 .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
|
122 .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
|
123 .variant = VARIANT_NORMAL, |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
124 .name = SDL_JoystickName(stick) |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 }; |
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
|
126 } |
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
|
127 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
|
128 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
|
129 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
|
130 { |
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
|
131 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
|
132 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
|
133 res.name = name; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 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
|
135 } |
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
|
136 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 //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
|
138 return (controller_info){ |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 .type = TYPE_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
|
140 .subtype = SUBTYPE_UNKNOWN, |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 .variant = VARIANT_NORMAL, |
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
|
142 .name = name |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 }; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
146 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
|
147 { |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
148 if (valtype != TVAL_NODE) { |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
149 return; |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
150 } |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
151 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
|
152 if (mapping) { |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
153 SDL_GameControllerAddMapping(mapping); |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
154 } |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
155 } |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
156 |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
157 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
|
158 { |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
159 load_ctype_config(); |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
160 tern_foreach(info_config, mappings_iter, NULL); |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
161 } |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
162 |
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
|
163 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
|
164 { |
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
|
165 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
|
166 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string)); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
167 tern_node *existing = tern_find_node(info_config, guid_string); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
168 existing = tern_insert_ptr(existing, "subtype", (void *)subtype_names[info->subtype]); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
169 existing = tern_insert_ptr(existing, "variant", (void *)variant_names[info->variant]); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
170 info_config = tern_insert_node(info_config, guid_string, existing); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
171 persist_config_at(info_config, "controller_types.cfg"); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1597
diff
changeset
|
172 |
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
|
173 } |
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
|
174 |
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
|
175 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
|
176 { |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
177 char guid_string[33]; |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
178 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string)); |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
179 tern_node *existing = tern_find_node(info_config, guid_string); |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
180 existing = tern_insert_ptr(existing, "mapping", mapping_string); |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
181 info_config = tern_insert_node(info_config, guid_string, existing); |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
182 persist_config_at(info_config, "controller_types.cfg"); |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
183 } |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
184 |
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
|
185 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
|
186 "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
|
187 }; |
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
|
188 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
|
189 "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
|
190 }; |
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 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
|
192 "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
|
193 }; |
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 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
|
195 "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
|
196 }; |
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
|
197 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
|
198 "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
|
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 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
|
201 "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
|
202 }; |
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
|
203 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
|
204 "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
|
205 }; |
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
|
206 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
|
207 "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
|
208 }; |
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
|
209 |
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
|
210 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
|
211 { |
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
|
212 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
|
213 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
|
214 } 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
|
215 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
|
216 } else if (info->type == TYPE_PSX) { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
217 if (info->subtype == SUBTYPE_PS4) { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
218 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
|
219 } 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
|
220 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
|
221 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
222 } else if (info->type == TYPE_XBOX) { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
223 if (info->subtype == SUBTYPE_XBONE) { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
224 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
|
225 } 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
|
226 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
|
227 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
228 } 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
|
229 if (info->subtype == SUBTYPE_GENESIS) { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
230 return labels_genesis; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
231 } 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
|
232 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
|
233 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
234 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
235 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
236 |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
237 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
|
238 { |
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
|
239 if (button >= SDL_CONTROLLER_BUTTON_DPAD_UP) { |
75aa418d0227
Use better names for "Guide" button on PS and Xbox controllers, handle d-pad directions in get_button_label
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
240 static char const * dirs[] = {"Up", "Down", "Left", "Right"}; |
75aa418d0227
Use better names for "Guide" button on PS and Xbox controllers, handle d-pad directions in get_button_label
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
241 return dirs[button - SDL_CONTROLLER_BUTTON_DPAD_UP]; |
75aa418d0227
Use better names for "Guide" button on PS and Xbox controllers, handle d-pad directions in get_button_label
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
242 } |
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
|
243 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
|
244 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
245 |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
246 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
|
247 "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
|
248 }; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
249 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
|
250 { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 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
|
252 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
|
253 } 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
|
254 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
|
255 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
256 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
257 |