changeset 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
author Michael Pavone <pavone@retrodev.com>
date Fri, 02 Sep 2022 22:53:41 -0700
parents ff700f50541c
children bb1bcdb027e0
files controller_info.c controller_info.h nuklear_ui/blastem_nuklear.c
diffstat 3 files changed, 40 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/controller_info.c	Thu Sep 01 22:43:02 2022 -0700
+++ b/controller_info.c	Fri Sep 02 22:53:41 2022 -0700
@@ -18,6 +18,7 @@
 static heuristic heuristics[] = {
 	//TODO: Add more heuristic rules
 	{"DualShock 4", {.type = TYPE_PSX, .subtype = SUBTYPE_PS4}},
+	{"PS5", {.type = TYPE_PSX, .subtype = SUBTYPE_PS5}},
 	{"PS4", {.type = TYPE_PSX, .subtype = SUBTYPE_PS4}},
 	{"PS3", {.type = TYPE_PSX, .subtype = SUBTYPE_PS3}},
 	{"X360", {.type = TYPE_XBOX, .subtype = SUBTYPE_X360}},
@@ -39,9 +40,11 @@
 	"xbox",
 	"xbox 360",
 	"xbone",
+	"xbox elite",
 	"ps2",
 	"ps3",
 	"ps4",
+	"ps5",
 	"wiiu",
 	"switch",
 	"genesis",
@@ -51,10 +54,12 @@
 	"unknown",
 	"Xbos",
 	"Xbox 360",
-	"Xbox One",
+	"Xbox One/Series",
+	"Xbox Elite",
 	"PS2",
 	"PS3",
 	"PS4",
+	"PS5",
 	"Wii-U",
 	"Switch",
 	"Genesis",
@@ -272,13 +277,13 @@
 	} else if (info->type == TYPE_NINTENDO) {
 		return labels_nintendo;
 	} else if (info->type == TYPE_PSX) {
-		if (info->subtype == SUBTYPE_PS4) {
+		if (info->subtype >= SUBTYPE_PS4) {
 			return labels_ps4;
 		} else {
 			return labels_ps3;
 		}
 	} else if (info->type == TYPE_XBOX) {
-		if (info->subtype == SUBTYPE_XBONE) {
+		if (info->subtype >= SUBTYPE_XBONE) {
 			return labels_xbone;
 		} else {
 			return labels_xbox;
@@ -301,9 +306,33 @@
 const char *get_button_label(controller_info *info, int button)
 {
 #ifndef USE_FBDEV
+#if SDL_VERSION_ATLEAST(2,0,12)
+	if (info->subtype == SUBTYPE_XBOX_ELITE && button >= SDL_CONTROLLER_BUTTON_PADDLE1 && button <= SDL_CONTROLLER_BUTTON_PADDLE4) {
+		static char const * names[] = {"Paddle 1", "Paddle 2", "Paddle 3", "Paddle 4"};
+		return names[button - SDL_CONTROLLER_BUTTON_PADDLE1];
+	}
+	if (button == SDL_CONTROLLER_BUTTON_TOUCHPAD && (info->subtype == SUBTYPE_PS4 || info->subtype == SUBTYPE_PS5)) {
+		return "Touchpad";
+	}
+	if (button == SDL_CONTROLLER_BUTTON_MISC1) {
+		switch (info->subtype)
+		{
+		case SUBTYPE_XBONE:
+		case SUBTYPE_XBOX_ELITE:
+			return "Share";
+		case SUBTYPE_PS5:
+			return "Microphone";
+		case SUBTYPE_SWITCH:
+			return "Capture";
+		}
+	}
+#endif
 	if (button >= SDL_CONTROLLER_BUTTON_DPAD_UP) {
-		static char const * dirs[] = {"Up", "Down", "Left", "Right"};
-		return dirs[button - SDL_CONTROLLER_BUTTON_DPAD_UP];
+		if (button <= SDL_CONTROLLER_BUTTON_DPAD_RIGHT) {
+			static char const * dirs[] = {"Up", "Down", "Left", "Right"};
+			return dirs[button - SDL_CONTROLLER_BUTTON_DPAD_UP];
+		}
+		return NULL;
 	}
 #endif
 	return label_source(info)[button];
--- a/controller_info.h	Thu Sep 01 22:43:02 2022 -0700
+++ b/controller_info.h	Fri Sep 02 22:53:41 2022 -0700
@@ -16,9 +16,11 @@
 	SUBTYPE_XBOX,
 	SUBTYPE_X360,
 	SUBTYPE_XBONE,
+	SUBTYPE_XBOX_ELITE,
 	SUBTYPE_PS2,
 	SUBTYPE_PS3,
 	SUBTYPE_PS4,
+	SUBTYPE_PS5,
 	SUBTYPE_WIIU,
 	SUBTYPE_SWITCH,
 	SUBTYPE_GENESIS,
--- a/nuklear_ui/blastem_nuklear.c	Thu Sep 01 22:43:02 2022 -0700
+++ b/nuklear_ui/blastem_nuklear.c	Fri Sep 02 22:53:41 2022 -0700
@@ -1467,11 +1467,11 @@
 {
 	if (nk_begin(context, "Controller Type", nk_rect(0, 0, render_width(), render_height()), 0)) {
 		controller_type_group(context, "Xbox", TYPE_XBOX, SUBTYPE_XBOX, (const char *[]){
-			"Original", "Xbox 360", "Xbox One"
-		}, 3);
+			"Original", "Xbox 360", "Xbox One/Series", "Xbox Elite"
+		}, 4);
 		controller_type_group(context, "Playstation", TYPE_PSX, SUBTYPE_PS3, (const char *[]){
-			"PS3", "PS4"
-		}, 2);
+			"PS3", "PS4", "PS5"
+		}, 3);
 		controller_type_group(context, "Sega", TYPE_SEGA, SUBTYPE_GENESIS, (const char *[]){
 			"Genesis", "Saturn"
 		}, 2);