Skip to content

Let the player remap controller buttons, with tap, toggle and aim modes - #35

Merged
ly05010419 merged 3 commits into
ly05010419:mainfrom
zecaro:feat/controller-remap
Oct 19, 2026
Merged

ly05010419 merged 3 commits into
ly05010419:mainfrom
zecaro:feat/controller-remap

Conversation

@zecaro

@zecaro zecaro commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Mac players could not change which controller button does what. On a DualSense the Switch layout feels backwards, and holding a button to run is tiring.

Change

  • runtime/controller_map.h (pure C, shared by the launcher and the runtime): physical buttons are named by position (south east west north, l1 r1 l2 r2 l3 r3, menu, view, d-pad, and touchpad, the DualSense / DualShock 4 touchpad click, unused by default), and each one drives a Switch button or none. With no file, the map is the identity, so nothing changes for existing players.
  • ~/Library/Application Support/MacNativeGames/TOTK/controls.txt: one physical = switch [mode] line per change. # starts a comment, and names are case-insensitive.
  • Modes, applied to the physical buttons so that two buttons sharing one Switch button keep their own edges:
    • hold (default): held while the button is down.
    • tap: held for 400 ms after each press, so tapping keeps the player running. A dispatch_after releases it when the controller sends no further event.
    • toggle: one press turns it on. It ends when the left stick returns to center after moving, so a click at rest waits for the first move. Other buttons do not end it.
    • aim <fire>: held while the button is down, except while the fire button is down. l2 = zr aim r2 draws the bow with L2 and shoots with R2, and R2's own line applies only while L2 is up.
  • app/launcher.m: points TOTK_CONTROLS at the file and checks it before the game starts. A bad line opens an alert with its number, so the game never closes at start over a typo.
  • runtime/gamepad.m: loads the layout and applies it to every Mac controller.
  • README (EN, ZH): the format, the Switch layout by position, and the climbing caveat: a held B lets go of a wall, so a toggle still on while climbing drops the player.

Tested

Check Result
tests/test_controller_map.c with UBSan (also a new CI step) 26 cases: default, Nintendo layout, comments, CRLF, case, none, repeated lines, every mode, and each kind of bad line
gamepad.m, launcher.m with -Wall -Wextra -Werror, rebased on main 33d7a12 v0, v112, v121, v143
python -m unittest discover -s tests 76 tests pass
1.4.3 app, DualSense, layout with tap, toggle and aim lines log controller layout: ... (7 buttons changed); jump, attack, confirm, back, run on L3 and the bow on L2/R2 work in game

In game

1.4.3 on a Mac with a DualSense and this layout: south = x (jump), north = a (action), east = b, west = y, l2 = zr aim r2, r2 = zl. The PlayStation button icons come from a local RomFS mod generated from the same controls.txt (not part of this PR); they show that every action lands on the button the file names.

Basic controls screen with the remapped layout

Not tested

  • Xbox and other non-DualSense controllers in game (the names come from GCExtendedGamepad, so they should map the same way).
  • iOS: the file is set up by the Mac launcher only.

- runtime/controller_map.h: physical buttons named by position (south, east, west, north,
  shoulders, triggers, stick presses, menu, view, d-pad) map to Switch buttons or none.
  The default map keeps macOS's names, as before. Pure C, shared by launcher and runtime.
- runtime/gamepad.m: applies the layout from TOTK_CONTROLS to every Mac controller.
- app/launcher.m: points TOTK_CONTROLS at <data>/controls.txt and checks it before the
  game starts; a bad line shows an alert with its number instead of the game closing.
- tests/test_controller_map.c (+ CI step with UBSan): default, Nintendo layout by position,
  comments, CRLF, case, none, repeated lines and each kind of bad line.
- README: the file format and the Switch layout by position.
- tap: the Switch button is held for 400 ms after each press (run by tapping, as in GTA);
  a dispatch_after releases it even when the controller sends no further event.
- toggle: one press turns it on, it ends when the left stick returns to center after moving
  (a click at rest waits for the first move); attacking while running does not stop it.
- aim <fire>: held while the button is down except while the fire button is down
  ("l2 = zr aim r2": L2 draws the bow, R2 shoots); the fire button's own line applies
  only while the aim button is up.
- Modes act on physical buttons, so two buttons sharing one Switch button keep their edges.
- Tests for each mode and its errors; README (EN, ZH) with the climbing caveat of a held B.
@zecaro
zecaro force-pushed the feat/controller-remap branch from 4301224 to 6e5425e Compare October 19, 2026 10:28
DualSense and DualShock 4 touchpad clicks are physical button 16, unused by default
("touchpad = minus" opens the Purah Pad). The aim mode keeps the fire button in 5 bits.
@ly05010419
ly05010419 merged commit f55df0c into ly05010419:main Oct 19, 2026
1 check passed
ly05010419 added a commit that referenced this pull request Oct 20, 2026
…ultrawide HUD, 1.4.3 survey, mods, controls.txt) into the Breath of the Wild branch

Resolved by hand: nvn_mtl.m (PR #34's paged-bitmap serial sets keep the serial forgetting of 635fb31: totk_serial_del
clears a bit; the memory line shows both; the BotW frame reset stays in mtl_present), build_app.py (make -j and the
per-game launcher defines), the Makefile (the BotW targets and the Opus test), loader.c (the #57 stale-reference handler
and 1.4.3's survey return address are TOTK-only: Breath of the Wild has no GAME_ADDR for them), world_survey.c (BotW
keeps its stub, with runtime_survey_sync), README (both update-history rows).

Found by the merged build: Breath of the Wild lacked runtime_output_size_current (frontend.m's shortcut text) and
runtime_survey_sync (hle_nvn.c); and the add-on content file handles shared fs_host.c's 0x200000000 range, so closing a
host file at the title ended the game ("close invalid add-on content handle"): they now start at 0x400000000.

Tested on the merged binaries: TOTK 1.2.1 jump session (anomalies 0, occlusion normal, serial set 48,606 / 13 pages),
Breath of the Wild DLC + key 3 (k3a6) and key 2 (k2c, 11 of 12 pairs within 5 px).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants