+/* wait for menu input, do autorepeat */
+int in_menu_wait(int interesting, int autorep_delay_ms)
+{
+ static int inp_prev = 0;
+ static int repeats = 0;
+ int ret, release = 0, wait = 666;
+
+ if (repeats)
+ wait = autorep_delay_ms;
+
+ ret = in_menu_wait_any(wait);
+ if (ret == inp_prev)
+ repeats++;
+
+ while (!(ret & interesting)) {
+ ret = in_menu_wait_any(-1);
+ release = 1;
+ }
+
+ if (release || ret != inp_prev)
+ repeats = 0;
+
+ inp_prev = ret;
+
+ /* we don't need diagonals in menus */
+ if ((ret & PBTN_UP) && (ret & PBTN_LEFT)) ret &= ~PBTN_LEFT;
+ if ((ret & PBTN_UP) && (ret & PBTN_RIGHT)) ret &= ~PBTN_RIGHT;
+ if ((ret & PBTN_DOWN) && (ret & PBTN_LEFT)) ret &= ~PBTN_LEFT;
+ if ((ret & PBTN_DOWN) && (ret & PBTN_RIGHT)) ret &= ~PBTN_RIGHT;
+
+ return ret;
+}
+