+ }\r
+ smalltext_out16(5, max_cnt/2 * me_sfont_h, ">", 0xffff);\r
+ menu_draw_end();\r
+}\r
+\r
+static int scandir_cmp(const void *p1, const void *p2)\r
+{\r
+ const struct dirent **d1 = (const struct dirent **)p1;\r
+ const struct dirent **d2 = (const struct dirent **)p2;\r
+ if ((*d1)->d_type == (*d2)->d_type)\r
+ return alphasort(d1, d2);\r
+ if ((*d1)->d_type == DT_DIR)\r
+ return -1; // put before\r
+ if ((*d2)->d_type == DT_DIR)\r
+ return 1;\r
+\r
+ return alphasort(d1, d2);\r
+}\r
+\r
+static int scandir_filter(const struct dirent *ent)\r
+{\r
+ const char *p;\r
+ int i;\r
+\r
+ if (ent == NULL || ent->d_name == NULL) return 0;\r
+ if (strlen(ent->d_name) < 5) return 1;\r
+\r
+ p = ent->d_name + strlen(ent->d_name) - 4;\r
+\r
+ for (i = 0; i < array_size(filter_exts); i++)\r
+ if (strcmp(p, filter_exts[i]) == 0)\r
+ return 0;\r
+\r
+ return 1;\r
+}\r
+\r
+static int dirent_seek_char(struct dirent **namelist, int len, int sel, char c)\r
+{\r
+ int i;\r
+\r
+ sel++;\r
+ for (i = sel + 1; i != sel; i++) {\r
+ if (i >= len)\r
+ i = 1;\r
+\r
+ if (tolower_simple(namelist[i]->d_name[0]) == c)\r
+ break;\r
+ }\r
+\r
+ return i - 1;\r
+}\r
+\r
+static char *menu_loop_romsel(char *curr_path, int len)\r
+{\r
+ struct dirent **namelist;\r
+ int n, inp, sel = 0;\r
+ char *ret = NULL, *fname = NULL;\r
+ char cinp;\r
+\r
+rescan:\r
+ // is this a dir or a full path?\r
+ if (!plat_is_dir(curr_path)) {\r
+ char *p = curr_path + strlen(curr_path) - 1;\r
+ for (; p > curr_path && *p != '/'; p--)\r
+ ;\r
+ *p = 0;\r
+ fname = p+1;\r
+ }\r
+\r
+ n = scandir(curr_path, &namelist, scandir_filter, (void *)scandir_cmp);\r
+ if (n < 0) {\r
+ char *t;\r
+ lprintf("menu_loop_romsel failed, dir: %s\n", curr_path);\r
+\r
+ // try root\r
+ t = getcwd(curr_path, len);\r
+ if (t == NULL)\r
+ plat_get_root_dir(curr_path, len);\r
+ n = scandir(curr_path, &namelist, scandir_filter, (void *)scandir_cmp);\r
+ if (n < 0) {\r
+ // oops, we failed\r
+ lprintf("menu_loop_romsel failed, dir: %s\n", curr_path);\r
+ return NULL;\r