From 2116f6e26b4f1a29ea52d68c097f9c159c2e49fe Mon Sep 17 00:00:00 2001 From: Fazana <52551480+FazanaJ@users.noreply.github.com> Date: Mon, 16 Sep 2024 21:48:28 +0100 Subject: [PATCH] Add support for inputs from controller ports 2-4 (#141) Title sums it up ## Description Adds some extra logic in the controller polling to read from ports 2-4, letting those controllers input on the menu. ## Motivation and Context Port 1 no longer feels alone in the dark, cold world of menu selection. ## How Has This Been Tested? Same method I used for libdragon's error screen which had the same issue. Tested on a system with four controllers inserted. ## Screenshots ## Types of changes - [x] Improvement (non-breaking change that adds a new feature) - [ ] Bug fix (fixes an issue) - [ ] Breaking change (breaking change) - [ ] Documentation Improvement - [ ] Config and build (change in the configuration and build system, has no impact on code or features) ## Checklist: - [x] My code follows the code style of this project. - [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly. - [ ] I have added tests to cover my changes. - [ ] All new and existing tests passed. Signed-off-by: FazanaJ --------- Co-authored-by: Robin Jones --- docs/00_getting_started_sd.md | 2 +- src/menu/actions.c | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/docs/00_getting_started_sd.md b/docs/00_getting_started_sd.md index 4ee6e763..af937dfe 100644 --- a/docs/00_getting_started_sd.md +++ b/docs/00_getting_started_sd.md @@ -36,7 +36,7 @@ SD:\ │ │ ├── NDDJ2.n64 │ │ └── NDXJ0.n64 │ │ -│ └── emulators +│ └── emulators\ │ ├── neon64bu.rom │ ├── sodium64.z64 │ ├── gb.v64 diff --git a/src/menu/actions.c b/src/menu/actions.c index 14c87fb6..9c44c23e 100644 --- a/src/menu/actions.c +++ b/src/menu/actions.c @@ -25,8 +25,17 @@ static void actions_clear (menu_t *menu) { } static void actions_update_direction (menu_t *menu) { - joypad_8way_t held_dir = joypad_get_direction(JOYPAD_PORT_1, JOYPAD_2D_DPAD | JOYPAD_2D_STICK); - joypad_8way_t fast_dir = joypad_get_direction(JOYPAD_PORT_1, JOYPAD_2D_C); + joypad_8way_t held_dir; + joypad_8way_t fast_dir; + + JOYPAD_PORT_FOREACH (i) { + held_dir = joypad_get_direction(i, JOYPAD_2D_DPAD | JOYPAD_2D_STICK); + fast_dir = joypad_get_direction(i, JOYPAD_2D_C); + if (held_dir != JOYPAD_8WAY_NONE || fast_dir != JOYPAD_8WAY_NONE) { + break; + } + } + if (fast_dir != JOYPAD_8WAY_NONE) { held_dir = fast_dir; @@ -82,7 +91,14 @@ static void actions_update_direction (menu_t *menu) { } static void actions_update_buttons (menu_t *menu) { - joypad_buttons_t pressed = joypad_get_buttons_pressed(JOYPAD_PORT_1); + joypad_buttons_t pressed; + + JOYPAD_PORT_FOREACH (i) { + pressed = joypad_get_buttons_pressed(i); + if (pressed.raw) { + break; + } + } if (pressed.a) { menu->actions.enter = true;