Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions dm/host/pad_apple.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@
#pragma once
#import <GameController/GameController.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#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);
}
9 changes: 7 additions & 2 deletions dm/host/tests/t_pad_apple.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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");
Expand Down
1 change: 1 addition & 0 deletions docs/env_switches.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -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 `=<bytes>`: 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
Expand Down
Loading