-unsigned long wait_for_input(unsigned int interesting, int is_key_config)
-{
- unsigned int ret;
- static int repeats = 0, wait = 20;
- int release = 0, count, i;
-
- if (!is_key_config)
- interesting |= (interesting & 0xf0) << 24; // also use analog
-
- if (repeats == 2) wait = 3;
- else if (repeats == 4) wait = 2;
- else if (repeats == 6) wait = 1;
-
- for (i = 0; i < wait && inp_prev == psp_pad_read(1); i++) {
- if (i == 0) repeats++;
- psp_msleep(30);
- }
-
- for (count = 0; !((ret = psp_pad_read(1)) & interesting) && count < 100; count++) {
- psp_msleep(50);
- release = 1;
- }
-
- if (release || ret != inp_prev) {
- repeats = 0;
- wait = 20;
- }
- inp_prev = ret;
-
- if (!is_key_config)
- ret |= (ret & 0xf0000000) >> 24; // use analog as d-pad
- if (wait > 6 && (ret&(PBTN_UP|PBTN_LEFT|PBTN_DOWN|PBTN_RIGHT|PBTN_L|PBTN_R)))
- wait = 6;
-
- // 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;
-}
-