From: chaoskagami Date: Fri, 15 Jul 2016 06:29:46 +0000 (-0400) Subject: Use libctr9_io's input functionality X-Git-Tag: v0.2.0~18 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=1662f5ff86a0cb08af08174ee558ddfb93738819;p=corbenik%2Fcorbenik.git Use libctr9_io's input functionality --- diff --git a/source/display.c b/source/display.c index ffcd83d..dba9481 100644 --- a/source/display.c +++ b/source/display.c @@ -114,35 +114,35 @@ show_menu(struct options_s *options, uint8_t *toggles) uint32_t key = wait_key(1); switch (key) { - case BUTTON_UP: + case CTR_HID_UP: if (cursor_min == cursor_max) break; cursor_y -= 1; while ((options[cursor_y].allowed == not_option || (options[cursor_y].allowed == boolean_val_n3ds && !is_n3ds)) && cursor_y >= cursor_min && !less_mode) cursor_y--; break; - case BUTTON_DOWN: + case CTR_HID_DOWN: if (cursor_min == cursor_max) break; cursor_y += 1; while ((options[cursor_y].allowed == not_option || (options[cursor_y].allowed == boolean_val_n3ds && !is_n3ds)) && cursor_y < cursor_max && !less_mode) cursor_y++; break; - case BUTTON_LEFT: + case CTR_HID_LEFT: if (cursor_min == cursor_max) break; cursor_y -= 5; while ((options[cursor_y].allowed == not_option || (options[cursor_y].allowed == boolean_val_n3ds && !is_n3ds)) && cursor_y >= cursor_min && !less_mode) cursor_y--; break; - case BUTTON_RIGHT: + case CTR_HID_RIGHT: if (cursor_min == cursor_max) break; cursor_y += 5; while ((options[cursor_y].allowed == not_option || (options[cursor_y].allowed == boolean_val_n3ds && !is_n3ds)) && cursor_y < cursor_max && !less_mode) cursor_y++; break; - case BUTTON_A: + case CTR_HID_A: if (less_mode) break; @@ -161,7 +161,7 @@ show_menu(struct options_s *options, uint8_t *toggles) cursor_y = cursor_min; } break; - case BUTTON_X: + case CTR_HID_X: if (options[cursor_y].allowed == ranged_val) { if (toggles[options[cursor_y].index] == options[cursor_y].a) toggles[options[cursor_y].index] = options[cursor_y].b; @@ -169,12 +169,12 @@ show_menu(struct options_s *options, uint8_t *toggles) toggles[options[cursor_y].index]--; } break; - case BUTTON_B: + case CTR_HID_B: exit = 1; clear_disp(TOP_SCREEN); cursor_y = cursor_min; break; - case BUTTON_SEL: + case CTR_HID_SELECT: if (options[cursor_y].desc[0] != 0) { show_help(options[cursor_y].desc); clear_disp(TOP_SCREEN); diff --git a/source/input.c b/source/input.c index 0fbdd26..deb998b 100644 --- a/source/input.c +++ b/source/input.c @@ -5,41 +5,37 @@ extern void waitcycles(uint32_t cycles); +#define ARM9_APPROX_DELAY_MAX 134058675 / 95 + uint32_t wait_key(_UNUSED int sleep) { - // If your dpad has issues, please add this to the makefile. - if (sleep) { - #define ARM9_APPROX_DELAY_MAX 134058675 / 95 - waitcycles(ARM9_APPROX_DELAY_MAX); // Approximately what a human can input - fine tuning needed (sorry, TASers!) - } - uint32_t ret = 0, get = 0; while (ret == 0) { - get = HID_PAD; + get = ctr_hid_get_buttons(); - if ((get & (BUTTON_L | BUTTON_R | BUTTON_STA)) == (BUTTON_L | BUTTON_R | BUTTON_STA)) { + if ((get & (CTR_HID_LT | CTR_HID_RT | CTR_HID_START)) == (CTR_HID_LT | CTR_HID_RT | CTR_HID_START)) { screenshot(); waitcycles(ARM9_APPROX_DELAY_MAX); // Approximately what a human can input - fine tuning needed (sorry, TASers!) - } else if (get & BUTTON_UP) - ret = BUTTON_UP; - else if (get & BUTTON_DOWN) - ret = BUTTON_DOWN; - else if (get & BUTTON_RIGHT) - ret = BUTTON_RIGHT; - else if (get & BUTTON_LEFT) - ret = BUTTON_LEFT; - else if (get & BUTTON_A) - ret = BUTTON_A; - else if (get & BUTTON_B) - ret = BUTTON_B; - else if (get & BUTTON_X) - ret = BUTTON_X; - else if (get & BUTTON_SEL) - ret = BUTTON_SEL; + } else if (get & CTR_HID_UP) + ret = CTR_HID_UP; + else if (get & CTR_HID_DOWN) + ret = CTR_HID_DOWN; + else if (get & CTR_HID_RIGHT) + ret = CTR_HID_RIGHT; + else if (get & CTR_HID_LEFT) + ret = CTR_HID_LEFT; + else if (get & CTR_HID_A) + ret = CTR_HID_A; + else if (get & CTR_HID_B) + ret = CTR_HID_B; + else if (get & CTR_HID_X) + ret = CTR_HID_X; + else if (get & CTR_HID_SELECT) + ret = CTR_HID_SELECT; } - while (HID_PAD & ret); + while (ctr_hid_get_buttons()); return ret; } diff --git a/source/input.h b/source/input.h index 4051a83..c09c217 100644 --- a/source/input.h +++ b/source/input.h @@ -1,24 +1,7 @@ #ifndef __INPUT_H #define __INPUT_H -#define BUTTON_A (1 << 0) -#define BUTTON_B (1 << 1) -#define BUTTON_SEL (1 << 2) -#define BUTTON_STA (1 << 3) -#define BUTTON_RIGHT (1 << 4) -#define BUTTON_LEFT (1 << 5) -#define BUTTON_UP (1 << 6) -#define BUTTON_DOWN (1 << 7) -#define BUTTON_R (1 << 8) -#define BUTTON_L (1 << 9) -#define BUTTON_X (1 << 10) -#define BUTTON_Y (1 << 11) -/* FIXME - I had ZR and ZL in, but they don't appear to - behave rationally without some initialization. */ - -#define BUTTON_ANY 0xFFF - -#define HID_PAD ((*(volatile uint32_t *)0x10146000) ^ BUTTON_ANY) +#include uint32_t wait_key(_UNUSED int sleep); diff --git a/source/main.c b/source/main.c index 2d52f4e..63572fb 100644 --- a/source/main.c +++ b/source/main.c @@ -1,3 +1,5 @@ +#include + #include "common.h" #include "firm/firm.h" #include "input.h" @@ -5,11 +7,10 @@ #include "screeninit.h" #include "std/abort.h" -int menu_handler(); - int is_n3ds = 0; - int doing_autoboot = 0; + +int menu_handler(); void shut_up(); int @@ -50,7 +51,7 @@ main(int argc, char** argv) } // Autoboot. Non-standard code path. - if (config.options[OPTION_AUTOBOOT] && !(HID_PAD & BUTTON_R)) { + if (config.options[OPTION_AUTOBOOT] && (ctr_hid_get_buttons() & CTR_HID_RT)) { if (config.options[OPTION_SILENCE]) shut_up(); // This does exactly what it sounds like. doing_autoboot = 1;