console-controller
Skill92 starsChanged 21 days agoMITView on GitHub
Controller Mapper. Hooks the game up to any controller: DualSense, Xbox, Switch Pro, keyboard or touch, remapped how you like. Reads a mapping in console/controls.json (a layout preset plus per-button overrides, radial deadzone, invert Y, stick swap, analog trigger threshold, keyboard keys, two players, Android touch zones) and writes console/ps2_pad.cpp, a drop-in replacement for PS2Recomp's ps2xRuntime/src/lib/ps2_pad.cpp with the same class, signature and DualShock 2 report. Optional input replay and recording for scripted test runs. Backs up the stock file before installing and only touches the PS2Recomp checkout you name. Use when the user says "my controller doesn't work", "remap the buttons", "use my Xbox pad", "Switch Pro buttons are swapped", "invert the camera", "keyboard controls", "two players", "touch controls on Android", or when /console-tester needs scripted input.
In this repository10 other files it gives its agents.
- console-anywhereSkill
- console-backendSkill
- console-graphicsSkill
- console-levelsSkill
- console-modSkill
- console-physicsSkill
- console-reverseSkill
- console-savesSkill
- console-soundSkill
- console-testerSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 87
Test with the controller in hand: Run the port, press every button once in a menu that reacts to all of them (or a game's controller test …
- Distinctive: line 108
Bring your own game: Only games you own, dumped from your own disc.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
console-controller
The recompiled game asks the runtime for the pad state many times a second through
PSPadBackend::readState(int port, int slot, uint8_t *data, size_t size) in
ps2xRuntime/src/lib/ps2_pad.cpp. The stock file maps raylib's gamepad 0 and a fixed keyboard
layout onto the 32-byte DualShock 2 report. This skill replaces that one file with a generated one
built from your console/controls.json, so any controller raylib can see becomes a DualShock 2,
mapped your way. Nothing else in the runtime changes, so the rebuild is incremental.
Honest limits: rumble is not wired in the runtime, pressure-sensitive buttons are reported as fully pressed or not pressed, and touch zones on Android are invisible (the runtime draws no overlay).
${CLAUDE_SKILL_DIR} below is this skill's folder (where this SKILL.md lives).
python3 "${CLAUDE_SKILL_DIR}/padmap.py" init --layout xbox # writes console/controls.json
python3 "${CLAUDE_SKILL_DIR}/padmap.py" check # every DS2 button bound, no clashes
python3 "${CLAUDE_SKILL_DIR}/padmap.py" gen --replay # writes console/ps2_pad.cpp
python3 "${CLAUDE_SKILL_DIR}/padmap.py" install --repo ~/PS2Recomp # backs up, then copies it in
python3 "${CLAUDE_SKILL_DIR}/padmap.py" restore --repo ~/PS2Recomp # puts the stock file back
python3 "${CLAUDE_SKILL_DIR}/padmap.py" presets switch-labels # playstation xbox switch switch-labels keyboard
python3 "${CLAUDE_SKILL_DIR}/padmap.py" table # the DS2 bit table
python3 "${CLAUDE_SKILL_DIR}/padmap.py" check --script console/inputs/menu.txt # validate a replay scriptFlags: --config FILE (default console/controls.json; the preset alone is used if it is missing),
--layout NAME, --out FILE (- for stdout), --json, --strict (warnings fail check),
--backups DIR (default console/backups). Exit codes: 0 ok, 1 check found a problem, 2 bad input.
What it reads and writes
| file | what |
console/controls.json | your mapping: layout + overrides. Full format: reference/controls-json.md |
console/ps2_pad.cpp | the generated drop-in pad file (from gen) |
<PS2Recomp>/ps2xRuntime/src/lib/ps2_pad.cpp | replaced by install, only when you pass --repo |
console/backups/ps2_pad.cpp.orig | the stock file, saved once and never overwritten; later installs also keep a timestamped copy |
templates/menu-walk.txt | an example input replay script to copy and edit |
The DualShock 2 report the file fills
data[0] = 0x01, data[1] = 0x73 (analog), buttons ACTIVE-LOW in data[2] (low byte) and
data[3] (high byte), so 0xFFFF means nothing pressed. Sticks: data[4] RX, data[5] RY,
data[6] LX, data[7] LY, 0x80 centre, 0x00 full left or up. Bits: SELECT 0x0001, L3 0x0002,
R3 0x0004, START 0x0008, UP 0x0010, RIGHT 0x0020, DOWN 0x0040, LEFT 0x0080, L2 0x0100, R2 0x0200,
L1 0x0400, R1 0x0800, TRIANGLE 0x1000, CIRCLE 0x2000, CROSS 0x4000, SQUARE 0x8000.
Kernel/Stubs/Pad.cpp copies bytes 2 to 7 into the game's pad buffer, sets the mode byte itself
(digital 0x41 until the game switches the pad to analog) and fills the pressure bytes as 0xFF or 0.
Method
- Find out what they play with. Controller model, how it connects (USB or Bluetooth), which OS, one or two players, and whether they want keyboard or touch. If a button already lands in the wrong place, ask which physical button they pressed and what the game did.
- Start from a preset.
init --layout playstation|xbox|switch|switch-labels|keyboard. raylib reports pads by POSITION: the bottom face button is Cross on every pad (Xbox A, Nintendo B).switch-labelsmatches Nintendo's printed letters instead (A, on the right, is Cross). Details and why some Switch Pro setups arrive already swapped: reference/controllers.md. - Apply the user's changes in
controls.json:buttonsoverrides,keyboardkeys,deadzone(radial, default 0.15),invert_y(truemeans the right stick, the camera in most games),stick_swap,trigger_threshold(reads L2/R2 from the analog trigger axes),players: 2(port 2 gets the second pad),touchzones for Android. Keep it a mapping, never game code. - Check.
padmap.py check. Fix every ERROR. Read the warnings out: Escape quits the game (raylib's default exit key; the runtime never changes it) and F1 opens the debug panel on desktop builds with the debug UI. - Generate.
padmap.py gen(add--replaywhen /console-tester will drive scripted runs). - Install.
padmap.py install --repo <their PS2Recomp checkout>backs the stock file up toconsole/backups/ps2_pad.cpp.origand copies the new one in. Then the normal incremental build (cmake --build <build dir>, the same command recorded inconsole/STATE.md). One.cppchanges and no header does, so it is quick. Never clean the build for this. - Test with the controller in hand. Run the port, press every button once in a menu that
reacts to all of them (or a game's controller test screen). If one is wrong, change
controls.json,gen,install, rebuild. Log the result inconsole/STATE.md. - Scripted input for tests (with
--replay): setPS2X_INPUT_RECORD=console/inputs/run1.txt, play the bit you want to repeat, quit; that file replays withPS2X_INPUT_SCRIPT(which/console-tester'srun.py --inputsets for you). The format is in reference/controls-json.md. Frame numbers count the game's reads of pad port 0, so a script stays in step with the game, not with the wall clock.
Rumble, pressure, analog, touch
| feature | status in this PS2Recomp checkout |
| Rumble | not wired: scePadSetActDirect and scePadSetActAlign in Kernel/Stubs/Pad.cpp return 1 and do nothing (scePadInfoAct reports two motors). Adding it is runtime C++ work for /console-backend, not a mapping |
| Pressure-sensitive buttons | digital: when a game turns pressure mode on, Pad.cpp reports 0xFF for a pressed button and 0 otherwise |
| Analog mode | the game switches it (scePadSetMainMode); sticks are always sent and the game ignores them in digital mode |
| Touch (Android) | ps2_android_runtime.cpp is only a TODO for an on-screen overlay, so the stock port has no touch controls. touch zones work as invisible areas; a Bluetooth controller is the better answer |
| Two players | the stock file feeds the same pad to both ports; the generated one gives port 2 its own pad with players: 2, or a released pad otherwise |
Guard rails
- Bring your own game. Only games you own, dumped from your own disc. Never download ISOs, ELFs or BIOS files, never help find them. PS2Recomp needs no BIOS.
- Nothing from the game gets published. The disc, ELF, IRX modules, assets and the recompiled
runner/*.cppstay on your machine. Acontrols.json, a generatedps2_pad.cppand replay scripts you wrote are yours to share. - Not affiliated with Sony. PlayStation and DualShock are trademarks of Sony Interactive Entertainment. DualSense, Xbox and Nintendo Switch belong to their owners.
- Back up, then replace one file.
installrefuses a source it did not generate, never overwrites the.origbackup, and touches only the checkout you name. Never edit headers (ps2_pad.hincluded: a header change rebuilds every generated file) and never clean the build.
Hands off to
/console-testerto run the port with a replay script (run.py boot --input ...)./console-anywhereto build for the device the controller is for (Steam Deck, Android, Vita)./console-backendif the game needs rumble or a pad call the runtime does not implement yet.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

