From 518368b8d2087887d701050c8b16ead7702a8aa9 Mon Sep 17 00:00:00 2001 From: zakk4223 Date: Mon, 23 Dec 2024 08:52:56 -0600 Subject: [PATCH] fix gamecontrollerdb mappings for entries that map dpad to analog stick axis instead of hats (#944) --- gamecontroller_db.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/gamecontroller_db.cpp b/gamecontroller_db.cpp index b84a0e9..fab15ec 100644 --- a/gamecontroller_db.cpp +++ b/gamecontroller_db.cpp @@ -437,6 +437,29 @@ static bool parse_mapping_string(char *map_str, char *guid, int dev_fd, uint32_t } if (fill_map[SYS_BTN_OSD_KTGL+2] == 0) fill_map[SYS_BTN_OSD_KTGL+2] = fill_map[SYS_BTN_OSD_KTGL+1]; + + + //Some controllers without analog sticks use the left stick axes for the dpad instead of using the hat axes + //When these are mapped to dpad directions in an entry, it results in the mister + //having no mapping for the corresponding analog axis. + //any analog axis that isn't mapped to either SYS_AXIS1 or SYS_AXIS2 is treated like a trigger and only generates + //'fake' digital inputs on the axis max. This results in only two dpad directions working. + //Populate the entries for SYS_AXIS1 based on what the dpad was mapped to, but only if the entry didn't map the analog + //axes itself. + + if (!fill_map[SYS_AXIS1_X] && fill_map[SYS_BTN_RIGHT] > KEY_EMU) + { + uint16_t axis_idx = (fill_map[SYS_BTN_RIGHT] - KEY_EMU) >> 1; + fill_map[SYS_AXIS1_X] = axis_idx | 0x20000; + } + + if (!fill_map[SYS_AXIS1_Y] && fill_map[SYS_BTN_UP] > KEY_EMU) + { + uint16_t axis_idx = (fill_map[SYS_BTN_UP] - KEY_EMU) >> 1; + fill_map[SYS_AXIS1_Y] = axis_idx | 0x20000; + } + + if (fill_map[SYS_AXIS_X] == 0) fill_map[SYS_AXIS_X] = fill_map[SYS_AXIS1_X]; if (fill_map[SYS_AXIS_Y] == 0) fill_map[SYS_AXIS_Y] = fill_map[SYS_AXIS1_Y]; }