From 95bc37a1fd4bd0c600a11163ba407b208b8d59ba Mon Sep 17 00:00:00 2001 From: seedds Date: Fri, 6 Nov 2026 15:30:23 +0530 Subject: [PATCH] DM_PAD_LABELS=1 maps a controller's face buttons by their printed letters Pads other than Nintendo's map by position, so an Xbox pad's Y sends the game's X and its A sends B. With the setting every pad maps name for name. It is off by default, and a Nintendo pad already maps this way. Checked: t_pad_apple covers the setting on and off with fake Xbox, DualSense, HID, Pro Controller and Joy-Con pads. An Xbox Wireless Controller stayed connected through about 50 minutes of Ocarina of Time on an M6 Mac with the setting on; each button was not checked by hand. --- dm/host/pad_apple.h | 14 +++++++++++--- dm/host/tests/t_pad_apple.m | 9 +++++++-- docs/env_switches.tsv | 1 + 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/dm/host/pad_apple.h b/dm/host/pad_apple.h index 65fdd53137..80be2df1e1 100644 --- a/dm/host/pad_apple.h +++ b/dm/host/pad_apple.h @@ -7,15 +7,23 @@ #pragma once #import #include +#include +#include #include "dm_input.h" static inline int dm_pad_labelled(GCController *c) { NSString *k = c.productCategory; return [k isEqualToString:@"Switch Pro Controller"] || [k containsString:@"Joy-Con"]; } -// DM_BTN_A / B / X / Y of the pad's pressed face buttons -static inline uint64_t dm_pad_face(GCExtendedGamepad *g) { +// DM_BTN_A / B / X / Y of the pad's pressed face buttons. by_label: every pad name for name, so the button marked Y on an Xbox pad is the game's Y; otherwise as above +static inline uint64_t dm_pad_face_as(GCExtendedGamepad *g, int by_label) { GCControllerButtonInput *a = g.buttonA, *b = g.buttonB, *x = g.buttonX, *y = g.buttonY; - if (!dm_pad_labelled(g.controller)) { GCControllerButtonInput *t = a; a = b; b = t; t = x; x = y; y = t; } // by position: right A, bottom B, top X, left Y + if (!by_label && !dm_pad_labelled(g.controller)) { GCControllerButtonInput *t = a; a = b; b = t; t = x; x = y; y = t; } // by position: right A, bottom B, top X, left Y return (a.isPressed ? DM_BTN_A : 0) | (b.isPressed ? DM_BTN_B : 0) | (x.isPressed ? DM_BTN_X : 0) | (y.isPressed ? DM_BTN_Y : 0); } +// DM_PAD_LABELS=1: by label on every pad; read once, as this runs for each pad on each read +static inline uint64_t dm_pad_face(GCExtendedGamepad *g) { + static int by_label = -1; + if (by_label < 0) { const char *e = getenv("DM_PAD_LABELS"); by_label = e && !strcmp(e, "1"); } + return dm_pad_face_as(g, by_label); +} diff --git a/dm/host/tests/t_pad_apple.m b/dm/host/tests/t_pad_apple.m index 56f246da36..592f2c6266 100644 --- a/dm/host/tests/t_pad_apple.m +++ b/dm/host/tests/t_pad_apple.m @@ -21,13 +21,14 @@ @implementation TestPad @end // The Switch buttons of a pad of this category with only the named GameController button pressed -static uint64_t face(NSString *category, char pressed) { +static uint64_t face_as(NSString *category, char pressed, int by_label) { TestPad *g = [TestPad new]; g.controller = [TestController new]; g.controller.productCategory = category; g.buttonA = [TestButton new]; g.buttonB = [TestButton new]; g.buttonX = [TestButton new]; g.buttonY = [TestButton new]; TestButton *b = pressed == 'A' ? g.buttonA : pressed == 'B' ? g.buttonB : pressed == 'X' ? g.buttonX : g.buttonY; b.isPressed = YES; - return dm_pad_face((GCExtendedGamepad *)(id)g); + return dm_pad_face_as((GCExtendedGamepad *)(id)g, by_label); } +static uint64_t face(NSString *category, char pressed) { return face_as(category, pressed, 0); } int main(void) { @autoreleasepool { for (NSString *k in @[@"Xbox One", @"DualSense", @"HID"]) { // by position: buttonA bottom (B), buttonB right (A), buttonX left (Y), buttonY top (X) @@ -37,6 +38,10 @@ int main(void) { @autoreleasepool { for (NSString *k in @[@"Switch Pro Controller", @"Nintendo Switch Joy-Con (L/R)", @"Nintendo Switch Joy-Con (R)"]) { // by label assert(face(k, 'A') == DM_BTN_A); assert(face(k, 'B') == DM_BTN_B); assert(face(k, 'X') == DM_BTN_X); assert(face(k, 'Y') == DM_BTN_Y); } + for (NSString *k in @[@"Xbox One", @"DualSense", @"HID", @"Switch Pro Controller", @"Nintendo Switch Joy-Con (R)"]) { // DM_PAD_LABELS=1: by label on every pad + assert(face_as(k, 'A', 1) == DM_BTN_A); assert(face_as(k, 'B', 1) == DM_BTN_B); assert(face_as(k, 'X', 1) == DM_BTN_X); assert(face_as(k, 'Y', 1) == DM_BTN_Y); + } + assert(face_as(@"Xbox One", 'Y', 0) == DM_BTN_X); // unset: as before TestPad *g = [TestPad new]; // nothing pressed, buttons nil: none assert(dm_pad_face((GCExtendedGamepad *)(id)g) == 0); printf("t_pad_apple OK\n"); diff --git a/docs/env_switches.tsv b/docs/env_switches.tsv index cbbf3a4a79..8f37269a0c 100644 --- a/docs/env_switches.tsv +++ b/docs/env_switches.tsv @@ -231,6 +231,7 @@ DM_OODLE_MODULES path The rewritten modules the Mac host's Oodle tool mode loads DM_OODLE_SERVE switch `=1`: the host answers decode requests on stdin / stdout with the game's own Oodle (or LZ5) decoder from the guest main thread before the SDK starts, until stdin ends DM_OPMODE player The operation mode the game sees: `0` handheld, `1` console (default: the profile's `op_mode`, console unless set); read once at startup DM_PAD_IDENTICAL switch `0` stops reading identical pads here when GameController lists fewer of their model than IOKit has, such as two Pro Controllers over USB (each a player of its own: a Pro Controller from its report 0x30, another model from its HID elements; `pad_hid_mac.h`, `pad_pro.h`); `DM_HID_PADS=0` stops it too; Mac only +DM_PAD_LABELS player `=1`: a controller's face buttons follow their printed letters on every pad (an Xbox pad's Y is the game's Y), instead of by position (right A, bottom B, top X, left Y) on pads other than Nintendo's (Mac and iOS) DM_PAD_MERGE switch `=1` merges every controller into player 1, as before, instead of giving each controller a player of its own (Mac and iOS) DM_PATCH_FRONT switch `=`: the size of the patch area right before the module base for a long text (`BIG_TEXT`); set only by the rewriter's own rerun with the size it needs DM_PHONE_MOTION switch On iOS, whether the phone's own device motion drives player 1's six-axis sensor: `auto` (default) while no controller supplies fresh motion, `1` phone only, `0` never; each source keeps its own orientation