From: chaoskagami Date: Tue, 14 Jun 2016 03:15:52 +0000 (-0400) Subject: Rate limit button presses to the approximate number a human can input per second... X-Git-Tag: v0.0.10~7 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=0c62bf6cd68197fa293a9634e12eb16cf0cff088;p=corbenik%2Fcorbenik.git Rate limit button presses to the approximate number a human can input per second. If anyone still has menus moving fast, something is wrong with your DPAD or hands --- diff --git a/source/menu.c b/source/menu.c index b69ffa7..b818e9b 100644 --- a/source/menu.c +++ b/source/menu.c @@ -75,28 +75,32 @@ extern void waitcycles(uint32_t cycles); uint32_t wait_key() { - waitcycles(100); // Moves too fast. Hopefully this prevents the issue. - - uint32_t get = 0; - while (get == 0) { - if (HID_PAD & BUTTON_UP) - get = BUTTON_UP; - else if (HID_PAD & BUTTON_DOWN) - get = BUTTON_DOWN; - else if (HID_PAD & BUTTON_RIGHT) - get = BUTTON_RIGHT; - else if (HID_PAD & BUTTON_LEFT) - get = BUTTON_LEFT; - else if (HID_PAD & BUTTON_A) - get = BUTTON_A; - else if (HID_PAD & BUTTON_B) - get = BUTTON_B; - else if (HID_PAD & BUTTON_X) - get = BUTTON_X; + #define ARM9_APPROX_DELAY_MAX 134058675 / 70 + 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; + + 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; + } - while (HID_PAD & get) - ; - return get; + while (HID_PAD & ret); + + return ret; } void