Mercurial > repos > blastem
comparison controller_info.c @ 1931:374a5ae694e8 mame_interp
Merge from default
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 18 Apr 2020 11:42:53 -0700 |
parents | fc05f49075c2 |
children | 8a64d86cc362 |
comparison
equal
deleted
inserted
replaced
1843:13abdc98379e | 1931:374a5ae694e8 |
---|---|
4 #include "render_sdl.h" | 4 #include "render_sdl.h" |
5 #endif | 5 #endif |
6 #include "controller_info.h" | 6 #include "controller_info.h" |
7 #include "config.h" | 7 #include "config.h" |
8 #include "util.h" | 8 #include "util.h" |
9 #include "blastem.h" | |
10 #include "bindings.h" | |
9 | 11 |
10 typedef struct { | 12 typedef struct { |
11 char const *name; | 13 char const *name; |
12 controller_info info; | 14 controller_info info; |
13 } heuristic; | 15 } heuristic; |
64 }; | 66 }; |
65 | 67 |
66 static void load_ctype_config(void) | 68 static void load_ctype_config(void) |
67 { | 69 { |
68 if (!loaded) { | 70 if (!loaded) { |
69 info_config = load_overrideable_config("controller_types.cfg", "controller_types.cfg"); | 71 info_config = load_overrideable_config("controller_types.cfg", "controller_types.cfg", NULL); |
70 loaded = 1; | 72 loaded = 1; |
71 } | 73 } |
72 } | 74 } |
73 | 75 |
74 controller_info get_controller_info(int joystick) | 76 controller_info get_controller_info(int joystick) |
192 { | 194 { |
193 #ifndef USE_FBDEV | 195 #ifndef USE_FBDEV |
194 char guid_string[33]; | 196 char guid_string[33]; |
195 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string)); | 197 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string)); |
196 tern_node *existing = tern_find_node(info_config, guid_string); | 198 tern_node *existing = tern_find_node(info_config, guid_string); |
197 existing = tern_insert_ptr(existing, "subtype", (void *)subtype_names[info->subtype]); | 199 existing = tern_insert_ptr(existing, "subtype", strdup(subtype_names[info->subtype])); |
198 existing = tern_insert_ptr(existing, "variant", (void *)variant_names[info->variant]); | 200 existing = tern_insert_ptr(existing, "variant", strdup(variant_names[info->variant])); |
199 info_config = tern_insert_node(info_config, guid_string, existing); | 201 info_config = tern_insert_node(info_config, guid_string, existing); |
200 persist_config_at(info_config, "controller_types.cfg"); | 202 persist_config_at(config, info_config, "controller_types.cfg"); |
203 handle_joy_added(joystick); | |
201 #endif | 204 #endif |
202 } | 205 } |
203 | 206 |
204 void save_controller_mapping(int joystick, char *mapping_string) | 207 void save_controller_mapping(int joystick, char *mapping_string) |
205 { | 208 { |
207 char guid_string[33]; | 210 char guid_string[33]; |
208 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string)); | 211 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string)); |
209 tern_node *existing = tern_find_node(info_config, guid_string); | 212 tern_node *existing = tern_find_node(info_config, guid_string); |
210 existing = tern_insert_ptr(existing, "mapping", mapping_string); | 213 existing = tern_insert_ptr(existing, "mapping", mapping_string); |
211 info_config = tern_insert_node(info_config, guid_string, existing); | 214 info_config = tern_insert_node(info_config, guid_string, existing); |
212 persist_config_at(info_config, "controller_types.cfg"); | 215 persist_config_at(config, info_config, "controller_types.cfg"); |
216 const char *parts[] = {guid_string, ",", mapping_string}; | |
217 char * full = alloc_concat_m(3, parts); | |
218 SDL_GameControllerAddMapping(full); | |
219 free(full); | |
220 handle_joy_added(joystick); | |
213 #endif | 221 #endif |
214 } | 222 } |
215 | 223 |
216 char const *labels_xbox[] = { | 224 char const *labels_xbox[] = { |
217 "A", "B", "X", "Y", "Back", NULL, "Start", "Click", "Click", "White", "Black", "LT", "RT" | 225 "A", "B", "X", "Y", "Back", NULL, "Start", "Click", "Click", "White", "Black", "LT", "RT" |