in_sdl: give names to gamepad buttons
[libpicofe.git] / menu.c
CommitLineData
95a2ec38 1/*\r
675d1d36 2 * (C) GraÅžvydas "notaz" Ignotas, 2006-2012\r
95a2ec38 3 *\r
4 * This work is licensed under the terms of any of these licenses\r
5 * (at your option):\r
6 * - GNU GPL, version 2 or later.\r
7 * - GNU LGPL, version 2.1 or later.\r
f89d8471 8 * - MAME license.\r
95a2ec38 9 * See the COPYING file in the top-level directory.\r
10 */\r
c7a4ff64 11\r
12#include <stdio.h>\r
13#include <string.h>\r
14#include <stdlib.h>\r
15#include <stdarg.h>\r
8b8d9463 16#include <time.h>\r
17#include <locale.h> // savestate date\r
c7a4ff64 18\r
19#include "menu.h"\r
20#include "fonts.h"\r
21#include "readpng.h"\r
22#include "lprintf.h"\r
fce20e73 23#include "input.h"\r
24b24674 24#include "plat.h"\r
049a6b3e 25#include "posix.h"\r
c7a4ff64 26\r
795b71c5 27#if defined(__GNUC__) && __GNUC__ >= 7\r
28#pragma GCC diagnostic ignored "-Wformat-truncation"\r
29#endif\r
30\r
049a6b3e 31static char static_buff[64];\r
3ffee69c 32static int menu_error_time = 0;\r
d2f29611 33char menu_error_msg[64] = { 0, };\r
68c85e2a 34// g_menuscreen is the current output buffer the menu is rendered to.\r
c66f49e6 35void *g_menuscreen_ptr;\r
68c85e2a 36// g_menubg is the menu background and has the same w/h as g_menuscreen, but\r
37// pp=w. It is filled on menu entry from file or from g_menubg_src if available.\r
d2f29611 38void *g_menubg_ptr;\r
68c85e2a 39// g_menubg_src points to a buffer containing a bg image. This is usually either\r
40// the emulator screen buffer or the host frame buffer.\r
41void *g_menubg_src_ptr;\r
367b6f1f 42\r
94a1d22e 43int g_menuscreen_w;\r
44int g_menuscreen_h;\r
2b27288e 45int g_menuscreen_pp;\r
68c85e2a 46int g_menubg_src_w;\r
47int g_menubg_src_h;\r
48int g_menubg_src_pp;\r
c66f49e6 49\r
9089665c 50int g_autostateld_opt;\r
51\r
3ffee69c 52static unsigned char *menu_font_data = NULL;\r
7b0a2985 53static int menu_text_color = 0xfffe; // default to white\r
c7a4ff64 54static int menu_sel_color = -1; // disabled\r
f15ca4db 55\r
56/* note: these might become non-constant in future */\r
3ffee69c 57#if MENU_X2\r
81d25800 58const int me_mfont_w = 16, me_mfont_h = 20;\r
59const int me_sfont_w = 12, me_sfont_h = 20;\r
3ffee69c 60#else\r
81d25800 61const int me_mfont_w = 8, me_mfont_h = 10;\r
62const int me_sfont_w = 6, me_sfont_h = 10;\r
3ffee69c 63#endif\r
c7a4ff64 64\r
8a0998fb 65static int g_menu_filter_off;\r
675d1d36 66static int g_border_style;\r
67static int border_left, border_right, border_top, border_bottom;\r
68\r
2b27288e 69void menuscreen_memset_lines(unsigned short *dst, int c, int l)\r
70{\r
71 for (; l > 0; l--, dst += g_menuscreen_pp)\r
72 memset(dst, c, g_menuscreen_w * 2);\r
73}\r
74\r
c7a4ff64 75// draws text to current bbp16 screen\r
76static void text_out16_(int x, int y, const char *text, int color)\r
77{\r
d5d59eb4 78 int i, lh, tr, tg, tb, len;\r
2b27288e 79 unsigned short *dest = (unsigned short *)g_menuscreen_ptr + x + y * g_menuscreen_pp;\r
ff8abddd 80 tr = PXGETR(color);\r
81 tg = PXGETG(color);\r
82 tb = PXGETB(color);\r
c7a4ff64 83\r
84 if (text == (void *)1)\r
85 {\r
86 // selector symbol\r
87 text = "";\r
88 len = 1;\r
89 }\r
90 else\r
049a6b3e 91 {\r
92 const char *p;\r
93 for (p = text; *p != 0 && *p != '\n'; p++)\r
94 ;\r
95 len = p - text;\r
96 }\r
c7a4ff64 97\r
d5d59eb4 98 lh = me_mfont_h;\r
c66f49e6 99 if (y + lh > g_menuscreen_h)\r
100 lh = g_menuscreen_h - y;\r
d5d59eb4 101\r
c7a4ff64 102 for (i = 0; i < len; i++)\r
103 {\r
3ffee69c 104 unsigned char *src = menu_font_data + (unsigned int)text[i] * me_mfont_w * me_mfont_h / 2;\r
c7a4ff64 105 unsigned short *dst = dest;\r
d5d59eb4 106 int u, l;\r
107\r
2b27288e 108 for (l = 0; l < lh; l++, dst += g_menuscreen_pp - me_mfont_w)\r
c7a4ff64 109 {\r
3ffee69c 110 for (u = me_mfont_w / 2; u > 0; u--, src++)\r
c7a4ff64 111 {\r
112 int c, r, g, b;\r
113 c = *src >> 4;\r
ff8abddd 114 r = PXGETR(*dst);\r
115 g = PXGETG(*dst);\r
116 b = PXGETB(*dst);\r
c7a4ff64 117 r = (c^0xf)*r/15 + c*tr/15;\r
118 g = (c^0xf)*g/15 + c*tg/15;\r
119 b = (c^0xf)*b/15 + c*tb/15;\r
ff8abddd 120 *dst++ = PXMAKE(r, g, b);\r
c7a4ff64 121 c = *src & 0xf;\r
ff8abddd 122 r = PXGETR(*dst);\r
123 g = PXGETG(*dst);\r
124 b = PXGETB(*dst);\r
c7a4ff64 125 r = (c^0xf)*r/15 + c*tr/15;\r
126 g = (c^0xf)*g/15 + c*tg/15;\r
127 b = (c^0xf)*b/15 + c*tb/15;\r
ff8abddd 128 *dst++ = PXMAKE(r, g, b);\r
c7a4ff64 129 }\r
130 }\r
3ffee69c 131 dest += me_mfont_w;\r
c7a4ff64 132 }\r
675d1d36 133\r
134 if (x < border_left)\r
135 border_left = x;\r
136 if (x + i * me_mfont_w > border_right)\r
137 border_right = x + i * me_mfont_w;\r
138 if (y < border_top)\r
139 border_top = y;\r
140 if (y + me_mfont_h > border_bottom)\r
141 border_bottom = y + me_mfont_h;\r
c7a4ff64 142}\r
143\r
144void text_out16(int x, int y, const char *texto, ...)\r
145{\r
146 va_list args;\r
24b24674 147 char buffer[256];\r
c66f49e6 148 int maxw = (g_menuscreen_w - x) / me_mfont_w;\r
c7a4ff64 149\r
73a85369 150 if (maxw < 0)\r
151 return;\r
152\r
24b24674 153 va_start(args, texto);\r
154 vsnprintf(buffer, sizeof(buffer), texto, args);\r
c7a4ff64 155 va_end(args);\r
156\r
73a85369 157 if (maxw > sizeof(buffer) - 1)\r
158 maxw = sizeof(buffer) - 1;\r
24b24674 159 buffer[maxw] = 0;\r
160\r
c7a4ff64 161 text_out16_(x,y,buffer,menu_text_color);\r
162}\r
163\r
f15ca4db 164/* draws in 6x8 font, might multiply size by integer */\r
049a6b3e 165static void smalltext_out16_(int x, int y, const char *texto, int color)\r
c7a4ff64 166{\r
c7a4ff64 167 unsigned char *src;\r
168 unsigned short *dst;\r
f15ca4db 169 int multiplier = me_sfont_w / 6;\r
170 int i;\r
c7a4ff64 171\r
f15ca4db 172 for (i = 0;; i++, x += me_sfont_w)\r
c7a4ff64 173 {\r
174 unsigned char c = (unsigned char) texto[i];\r
175 int h = 8;\r
176\r
f15ca4db 177 if (!c || c == '\n')\r
178 break;\r
c7a4ff64 179\r
180 src = fontdata6x8[c];\r
2b27288e 181 dst = (unsigned short *)g_menuscreen_ptr + x + y * g_menuscreen_pp;\r
c7a4ff64 182\r
183 while (h--)\r
184 {\r
f15ca4db 185 int m, w2, h2;\r
186 for (h2 = multiplier; h2 > 0; h2--)\r
c7a4ff64 187 {\r
f15ca4db 188 for (m = 0x20; m; m >>= 1) {\r
189 if (*src & m)\r
190 for (w2 = multiplier; w2 > 0; w2--)\r
191 *dst++ = color;\r
192 else\r
193 dst += multiplier;\r
194 }\r
195\r
2b27288e 196 dst += g_menuscreen_pp - me_sfont_w;\r
c7a4ff64 197 }\r
198 src++;\r
c7a4ff64 199 }\r
200 }\r
201}\r
202\r
81d25800 203void smalltext_out16(int x, int y, const char *texto, int color)\r
c7a4ff64 204{\r
e31266dd 205 char buffer[128];\r
c66f49e6 206 int maxw = (g_menuscreen_w - x) / me_sfont_w;\r
73a85369 207\r
208 if (maxw < 0)\r
209 return;\r
73a85369 210 if (maxw > sizeof(buffer) - 1)\r
211 maxw = sizeof(buffer) - 1;\r
cfb49ab9 212\r
213 strncpy(buffer, texto, maxw);\r
73a85369 214 buffer[maxw] = 0;\r
c7a4ff64 215\r
049a6b3e 216 smalltext_out16_(x, y, buffer, color);\r
c7a4ff64 217}\r
218\r
049a6b3e 219static void menu_draw_selection(int x, int y, int w)\r
c7a4ff64 220{\r
221 int i, h;\r
222 unsigned short *dst, *dest;\r
223\r
224 text_out16_(x, y, (void *)1, (menu_sel_color < 0) ? menu_text_color : menu_sel_color);\r
225\r
226 if (menu_sel_color < 0) return; // no selection hilight\r
227\r
228 if (y > 0) y--;\r
2b27288e 229 dest = (unsigned short *)g_menuscreen_ptr + x + y * g_menuscreen_pp + me_mfont_w * 2 - 2;\r
3ffee69c 230 for (h = me_mfont_h + 1; h > 0; h--)\r
c7a4ff64 231 {\r
232 dst = dest;\r
f6eaae4f 233 for (i = w - (me_mfont_w * 2 - 2); i > 0; i--)\r
c7a4ff64 234 *dst++ = menu_sel_color;\r
2b27288e 235 dest += g_menuscreen_pp;\r
c7a4ff64 236 }\r
237}\r
238\r
239static int parse_hex_color(char *buff)\r
240{\r
241 char *endp = buff;\r
242 int t = (int) strtoul(buff, &endp, 16);\r
703e4c7b 243 if (endp != buff)\r
ff8abddd 244 return PXMAKE((t>>16)&0xff, (t>>8)&0xff,t&0xff);\r
c7a4ff64 245 return -1;\r
246}\r
247\r
9934732a 248static char tolower_simple(char c)\r
249{\r
250 if ('A' <= c && c <= 'Z')\r
251 c = c - 'A' + 'a';\r
252 return c;\r
253}\r
254\r
675d1d36 255void menu_init_base(void)\r
c7a4ff64 256{\r
c52e6628 257 int i, c, l, pos;\r
3ffee69c 258 unsigned char *fd, *fds;\r
c7a4ff64 259 char buff[256];\r
260 FILE *f;\r
261\r
3ffee69c 262 if (menu_font_data != NULL)\r
263 free(menu_font_data);\r
264\r
265 menu_font_data = calloc((MENU_X2 ? 256 * 320 : 128 * 160) / 2, 1);\r
266 if (menu_font_data == NULL)\r
267 return;\r
268\r
269 // generate default 8x10 font from fontdata8x8\r
d1453cf7 270 for (c = 0, fd = menu_font_data; c < 128; c++)\r
c7a4ff64 271 {\r
272 for (l = 0; l < 8; l++)\r
273 {\r
274 unsigned char fd8x8 = fontdata8x8[c*8+l];\r
795b71c5 275 if (fd8x8&0x80) { *fd = 0xf0; }\r
276 if (fd8x8&0x40) { *fd |= 0x0f; }; fd++;\r
277 if (fd8x8&0x20) { *fd = 0xf0; }\r
278 if (fd8x8&0x10) { *fd |= 0x0f; }; fd++;\r
279 if (fd8x8&0x08) { *fd = 0xf0; }\r
280 if (fd8x8&0x04) { *fd |= 0x0f; }; fd++;\r
281 if (fd8x8&0x02) { *fd = 0xf0; }\r
282 if (fd8x8&0x01) { *fd |= 0x0f; }; fd++;\r
c7a4ff64 283 }\r
284 fd += 8*2/2; // 2 empty lines\r
285 }\r
286\r
3ffee69c 287 if (MENU_X2) {\r
288 // expand default font\r
289 fds = menu_font_data + 128 * 160 / 2 - 4;\r
290 fd = menu_font_data + 256 * 320 / 2 - 1;\r
291 for (c = 255; c >= 0; c--)\r
292 {\r
293 for (l = 9; l >= 0; l--, fds -= 4)\r
294 {\r
295 for (i = 3; i >= 0; i--) {\r
296 int px = fds[i] & 0x0f;\r
297 *fd-- = px | (px << 4);\r
298 px = (fds[i] >> 4) & 0x0f;\r
299 *fd-- = px | (px << 4);\r
300 }\r
301 for (i = 3; i >= 0; i--) {\r
302 int px = fds[i] & 0x0f;\r
303 *fd-- = px | (px << 4);\r
304 px = (fds[i] >> 4) & 0x0f;\r
305 *fd-- = px | (px << 4);\r
306 }\r
307 }\r
308 }\r
309 }\r
310\r
c7a4ff64 311 // load custom font and selector (stored as 1st symbol in font table)\r
c52e6628
PC
312 pos = plat_get_skin_dir(buff, sizeof(buff));\r
313 strcpy(buff + pos, "font.png");\r
f6eaae4f 314 readpng(menu_font_data, buff, READPNG_FONT,\r
315 MENU_X2 ? 256 : 128, MENU_X2 ? 320 : 160);\r
3ffee69c 316 // default selector symbol is '>'\r
317 memcpy(menu_font_data, menu_font_data + ((int)'>') * me_mfont_w * me_mfont_h / 2,\r
318 me_mfont_w * me_mfont_h / 2);\r
c52e6628 319 strcpy(buff + pos, "selector.png");\r
209a7eff 320 readpng(menu_font_data, buff, READPNG_SELECTOR, me_mfont_w, me_mfont_h);\r
c7a4ff64 321\r
322 // load custom colors\r
c52e6628 323 strcpy(buff + pos, "skin.txt");\r
45deb409 324 f = fopen(buff, "r");\r
c7a4ff64 325 if (f != NULL)\r
326 {\r
327 lprintf("found skin.txt\n");\r
328 while (!feof(f))\r
329 {\r
5f7b5155 330 if (fgets(buff, sizeof(buff), f) == NULL)\r
331 break;\r
c7a4ff64 332 if (buff[0] == '#' || buff[0] == '/') continue; // comment\r
333 if (buff[0] == '\r' || buff[0] == '\n') continue; // empty line\r
334 if (strncmp(buff, "text_color=", 11) == 0)\r
335 {\r
336 int tmp = parse_hex_color(buff+11);\r
337 if (tmp >= 0) menu_text_color = tmp;\r
338 else lprintf("skin.txt: parse error for text_color\n");\r
339 }\r
340 else if (strncmp(buff, "selection_color=", 16) == 0)\r
341 {\r
342 int tmp = parse_hex_color(buff+16);\r
343 if (tmp >= 0) menu_sel_color = tmp;\r
344 else lprintf("skin.txt: parse error for selection_color\n");\r
345 }\r
346 else\r
347 lprintf("skin.txt: parse error: %s\n", buff);\r
348 }\r
349 fclose(f);\r
350 }\r
8b8d9463 351\r
352 // use user's locale for savestate date display\r
353 setlocale(LC_TIME, "");\r
c7a4ff64 354}\r
355\r
d2f29611 356static void menu_darken_bg(void *dst, void *src, int pixels, int darker)\r
357{\r
358 unsigned int *dest = dst;\r
359 unsigned int *sorc = src;\r
360 pixels /= 2;\r
361 if (darker)\r
362 {\r
363 while (pixels--)\r
364 {\r
365 unsigned int p = *sorc++;\r
ff8abddd 366 *dest++ = (PXMASKH(p,1)>>1) - (PXMASKH(p,3)>>3);\r
d2f29611 367 }\r
368 }\r
369 else\r
370 {\r
371 while (pixels--)\r
372 {\r
373 unsigned int p = *sorc++;\r
ff8abddd 374 *dest++ = (PXMASKH(p,1)>>1);\r
d2f29611 375 }\r
376 }\r
377}\r
378\r
675d1d36 379static void menu_darken_text_bg(void)\r
380{\r
381 int x, y, xmin, xmax, ymax, ls;\r
382 unsigned short *screen = g_menuscreen_ptr;\r
383\r
384 xmin = border_left - 3;\r
385 if (xmin < 0)\r
386 xmin = 0;\r
387 xmax = border_right + 2;\r
388 if (xmax > g_menuscreen_w - 1)\r
389 xmax = g_menuscreen_w - 1;\r
390\r
391 y = border_top - 3;\r
392 if (y < 0)\r
393 y = 0;\r
394 ymax = border_bottom + 2;\r
395 if (ymax > g_menuscreen_h - 1)\r
396 ymax = g_menuscreen_h - 1;\r
397\r
398 for (x = xmin; x <= xmax; x++)\r
ff8abddd 399 screen[y * g_menuscreen_pp + x] = PXMAKE(0xa0, 0xa0, 0xa0);\r
675d1d36 400 for (y++; y < ymax; y++)\r
401 {\r
2b27288e 402 ls = y * g_menuscreen_pp;\r
675d1d36 403 screen[ls + xmin] = 0xffff;\r
404 for (x = xmin + 1; x < xmax; x++)\r
405 {\r
406 unsigned int p = screen[ls + x];\r
7b0a2985 407 if (p != menu_text_color)\r
ff8abddd 408 screen[ls + x] = (PXMASKH(p,1)>>1) - (PXMASKH(p,3)>>3);\r
675d1d36 409 }\r
410 screen[ls + xmax] = 0xffff;\r
411 }\r
2b27288e 412 ls = y * g_menuscreen_pp;\r
675d1d36 413 for (x = xmin; x <= xmax; x++)\r
414 screen[ls + x] = 0xffff;\r
415}\r
416\r
417static int borders_pending;\r
418\r
419static void menu_reset_borders(void)\r
420{\r
421 border_left = g_menuscreen_w;\r
422 border_right = 0;\r
423 border_top = g_menuscreen_h;\r
424 border_bottom = 0;\r
425}\r
426\r
427static void menu_draw_begin(int need_bg, int no_borders)\r
428{\r
2b27288e 429 int y;\r
430\r
675d1d36 431 plat_video_menu_begin();\r
432\r
433 menu_reset_borders();\r
434 borders_pending = g_border_style && !no_borders;\r
435\r
436 if (need_bg) {\r
437 if (g_border_style && no_borders) {\r
2b27288e 438 for (y = 0; y < g_menuscreen_h; y++)\r
439 menu_darken_bg((short *)g_menuscreen_ptr + g_menuscreen_pp * y,\r
f8cd6a08 440 (short *)g_menubg_ptr + g_menuscreen_w * y, g_menuscreen_w, 1);\r
675d1d36 441 }\r
442 else {\r
2b27288e 443 for (y = 0; y < g_menuscreen_h; y++)\r
444 memcpy((short *)g_menuscreen_ptr + g_menuscreen_pp * y,\r
f8cd6a08 445 (short *)g_menubg_ptr + g_menuscreen_w * y, g_menuscreen_w * 2);\r
675d1d36 446 }\r
447 }\r
448}\r
449\r
450static void menu_draw_end(void)\r
451{\r
452 if (borders_pending)\r
453 menu_darken_text_bg();\r
454 plat_video_menu_end();\r
455}\r
456\r
457static void menu_separation(void)\r
458{\r
459 if (borders_pending) {\r
460 menu_darken_text_bg();\r
461 menu_reset_borders();\r
462 }\r
463}\r
464\r
049a6b3e 465static int me_id2offset(const menu_entry *ent, menu_id id)\r
c7a4ff64 466{\r
467 int i;\r
24b24674 468 for (i = 0; ent->name; ent++, i++)\r
469 if (ent->id == id) return i;\r
c7a4ff64 470\r
471 lprintf("%s: id %i not found\n", __FUNCTION__, id);\r
472 return 0;\r
473}\r
474\r
049a6b3e 475static void me_enable(menu_entry *entries, menu_id id, int enable)\r
c7a4ff64 476{\r
24b24674 477 int i = me_id2offset(entries, id);\r
d23f5773 478 entries[i].enabled = !!enable;\r
c7a4ff64 479}\r
480\r
049a6b3e 481static int me_count(const menu_entry *ent)\r
c7a4ff64 482{\r
24b24674 483 int ret;\r
c7a4ff64 484\r
24b24674 485 for (ret = 0; ent->name; ent++, ret++)\r
486 ;\r
c7a4ff64 487\r
488 return ret;\r
489}\r
490\r
92bef70f 491static unsigned int me_read_onoff(const menu_entry *ent)\r
492{\r
62128bad 493 return *(unsigned int *)ent->var & ent->mask;\r
92bef70f 494}\r
495\r
496static void me_toggle_onoff(menu_entry *ent)\r
497{\r
62128bad 498 *(unsigned int *)ent->var ^= ent->mask;\r
92bef70f 499}\r
500\r
053bef76 501static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void))\r
24b24674 502{\r
f6eaae4f 503 const menu_entry *ent, *ent_sel = entries;\r
24b24674 504 int x, y, w = 0, h = 0;\r
8e77275e 505 int offs, col2_offs = 27 * me_mfont_w;\r
f6eaae4f 506 int vi_sel_ln = 0;\r
24b24674 507 const char *name;\r
24b24674 508 int i, n;\r
509\r
510 /* calculate size of menu rect */\r
511 for (ent = entries, i = n = 0; ent->name; ent++, i++)\r
512 {\r
513 int wt;\r
514\r
515 if (!ent->enabled)\r
516 continue;\r
517\r
f6eaae4f 518 if (i == sel) {\r
519 ent_sel = ent;\r
520 vi_sel_ln = n;\r
521 }\r
24b24674 522\r
523 name = NULL;\r
3ffee69c 524 wt = strlen(ent->name) * me_mfont_w;\r
24b24674 525 if (wt == 0 && ent->generate_name)\r
049a6b3e 526 name = ent->generate_name(ent->id, &offs);\r
24b24674 527 if (name != NULL)\r
3ffee69c 528 wt = strlen(name) * me_mfont_w;\r
24b24674 529\r
530 if (ent->beh != MB_NONE)\r
531 {\r
8e77275e 532 if (wt > col2_offs)\r
533 col2_offs = wt + me_mfont_w;\r
534 wt = col2_offs;\r
24b24674 535\r
536 switch (ent->beh) {\r
209a7eff 537 case MB_NONE:\r
538 break;\r
24b24674 539 case MB_OPT_ONOFF:\r
209a7eff 540 case MB_OPT_RANGE:\r
541 wt += me_mfont_w * 3;\r
542 break;\r
24b24674 543 case MB_OPT_CUSTOM:\r
049a6b3e 544 case MB_OPT_CUSTONOFF:\r
545 case MB_OPT_CUSTRANGE:\r
24b24674 546 name = NULL;\r
049a6b3e 547 offs = 0;\r
24b24674 548 if (ent->generate_name != NULL)\r
049a6b3e 549 name = ent->generate_name(ent->id, &offs);\r
24b24674 550 if (name != NULL)\r
3ffee69c 551 wt += (strlen(name) + offs) * me_mfont_w;\r
24b24674 552 break;\r
0c9ae592 553 case MB_OPT_ENUM:\r
554 wt += 10 * me_mfont_w;\r
555 break;\r
24b24674 556 }\r
557 }\r
558\r
559 if (wt > w)\r
560 w = wt;\r
561 n++;\r
562 }\r
3ffee69c 563 h = n * me_mfont_h;\r
564 w += me_mfont_w * 2; /* selector */\r
24b24674 565\r
c66f49e6 566 if (w > g_menuscreen_w) {\r
567 lprintf("width %d > %d\n", w, g_menuscreen_w);\r
568 w = g_menuscreen_w;\r
24b24674 569 }\r
c66f49e6 570 if (h > g_menuscreen_h) {\r
571 lprintf("height %d > %d\n", w, g_menuscreen_h);\r
572 h = g_menuscreen_h;\r
24b24674 573 }\r
574\r
95a2ec38 575 x = g_menuscreen_w / 2 - w / 2;\r
c66f49e6 576 y = g_menuscreen_h / 2 - h / 2;\r
95a2ec38 577#ifdef MENU_ALIGN_LEFT\r
578 if (x > 12) x = 12;\r
579#endif\r
24b24674 580\r
581 /* draw */\r
675d1d36 582 menu_draw_begin(1, 0);\r
f6eaae4f 583 menu_draw_selection(x, y + vi_sel_ln * me_mfont_h, w);\r
3ffee69c 584 x += me_mfont_w * 2;\r
24b24674 585\r
586 for (ent = entries; ent->name; ent++)\r
587 {\r
0c9ae592 588 const char **names;\r
f12e492f 589 int len, leftname_end = 0;\r
0c9ae592 590\r
24b24674 591 if (!ent->enabled)\r
592 continue;\r
593\r
594 name = ent->name;\r
595 if (strlen(name) == 0) {\r
596 if (ent->generate_name)\r
049a6b3e 597 name = ent->generate_name(ent->id, &offs);\r
24b24674 598 }\r
f12e492f 599 if (name != NULL) {\r
cfb49ab9 600 text_out16(x, y, "%s", name);\r
f12e492f 601 leftname_end = x + (strlen(name) + 1) * me_mfont_w;\r
602 }\r
24b24674 603\r
604 switch (ent->beh) {\r
605 case MB_NONE:\r
606 break;\r
607 case MB_OPT_ONOFF:\r
cfb49ab9 608 text_out16(x + col2_offs, y, "%s", me_read_onoff(ent) ? "ON" : "OFF");\r
24b24674 609 break;\r
610 case MB_OPT_RANGE:\r
8e77275e 611 text_out16(x + col2_offs, y, "%i", *(int *)ent->var);\r
24b24674 612 break;\r
613 case MB_OPT_CUSTOM:\r
049a6b3e 614 case MB_OPT_CUSTONOFF:\r
615 case MB_OPT_CUSTRANGE:\r
24b24674 616 name = NULL;\r
049a6b3e 617 offs = 0;\r
24b24674 618 if (ent->generate_name)\r
049a6b3e 619 name = ent->generate_name(ent->id, &offs);\r
24b24674 620 if (name != NULL)\r
8e77275e 621 text_out16(x + col2_offs + offs * me_mfont_w, y, "%s", name);\r
24b24674 622 break;\r
0c9ae592 623 case MB_OPT_ENUM:\r
624 names = (const char **)ent->data;\r
0c9ae592 625 for (i = 0; names[i] != NULL; i++) {\r
f12e492f 626 offs = x + col2_offs;\r
0c9ae592 627 len = strlen(names[i]);\r
628 if (len > 10)\r
de24250a 629 offs += (10 - len) * me_mfont_w;\r
f12e492f 630 if (offs < leftname_end)\r
631 offs = leftname_end;\r
62128bad 632 if (i == *(int *)ent->var) {\r
f12e492f 633 text_out16(offs, y, "%s", names[i]);\r
0c9ae592 634 break;\r
635 }\r
636 }\r
637 break;\r
24b24674 638 }\r
639\r
3ffee69c 640 y += me_mfont_h;\r
24b24674 641 }\r
642\r
7b0a2985 643 menu_separation();\r
644\r
0c9ae592 645 /* display help or message if we have one */\r
c66f49e6 646 h = (g_menuscreen_h - h) / 2; // bottom area height\r
3ffee69c 647 if (menu_error_msg[0] != 0) {\r
0c9ae592 648 if (h >= me_mfont_h + 4)\r
cfb49ab9 649 text_out16(5, g_menuscreen_h - me_mfont_h - 4, "%s", menu_error_msg);\r
049a6b3e 650 else\r
651 lprintf("menu msg doesn't fit!\n");\r
652\r
3ffee69c 653 if (plat_get_ticks_ms() - menu_error_time > 2048)\r
654 menu_error_msg[0] = 0;\r
049a6b3e 655 }\r
f6eaae4f 656 else if (ent_sel->help != NULL) {\r
657 const char *tmp = ent_sel->help;\r
0c9ae592 658 int l;\r
659 for (l = 0; tmp != NULL && *tmp != 0; l++)\r
660 tmp = strchr(tmp + 1, '\n');\r
661 if (h >= l * me_sfont_h + 4)\r
f6eaae4f 662 for (tmp = ent_sel->help; l > 0; l--, tmp = strchr(tmp, '\n') + 1)\r
ff8abddd 663 smalltext_out16(5, g_menuscreen_h - (l * me_sfont_h + 4), tmp, PXMAKE(0xff, 0xff, 0xff));\r
0c9ae592 664 }\r
049a6b3e 665\r
675d1d36 666 menu_separation();\r
667\r
053bef76 668 if (draw_more != NULL)\r
669 draw_more();\r
670\r
902972d1 671 menu_draw_end();\r
c7a4ff64 672}\r
673\r
5d34757d 674static int me_process(menu_entry *entry, int is_next, int is_lr)\r
c7a4ff64 675{\r
0c9ae592 676 const char **names;\r
5d34757d 677 int c;\r
c7a4ff64 678 switch (entry->beh)\r
679 {\r
24b24674 680 case MB_OPT_ONOFF:\r
049a6b3e 681 case MB_OPT_CUSTONOFF:\r
92bef70f 682 me_toggle_onoff(entry);\r
c7a4ff64 683 return 1;\r
24b24674 684 case MB_OPT_RANGE:\r
049a6b3e 685 case MB_OPT_CUSTRANGE:\r
5d34757d 686 c = is_lr ? 10 : 1;\r
687 *(int *)entry->var += is_next ? c : -c;\r
049a6b3e 688 if (*(int *)entry->var < (int)entry->min)\r
689 *(int *)entry->var = (int)entry->max;\r
690 if (*(int *)entry->var > (int)entry->max)\r
691 *(int *)entry->var = (int)entry->min;\r
c7a4ff64 692 return 1;\r
0c9ae592 693 case MB_OPT_ENUM:\r
694 names = (const char **)entry->data;\r
695 for (c = 0; names[c] != NULL; c++)\r
696 ;\r
62128bad 697 *(int *)entry->var += is_next ? 1 : -1;\r
698 if (*(int *)entry->var < 0)\r
699 *(int *)entry->var = 0;\r
700 if (*(int *)entry->var >= c)\r
701 *(int *)entry->var = c - 1;\r
0c9ae592 702 return 1;\r
c7a4ff64 703 default:\r
704 return 0;\r
705 }\r
706}\r
707\r
049a6b3e 708static void debug_menu_loop(void);\r
709\r
c7d27148 710static int me_loop_d(menu_entry *menu, int *menu_sel, void (*draw_prep)(void), void (*draw_more)(void))\r
24b24674 711{\r
c7d27148 712 int ret = 0, inp, sel = *menu_sel, menu_sel_max;\r
24b24674 713\r
714 menu_sel_max = me_count(menu) - 1;\r
053bef76 715 if (menu_sel_max < 0) {\r
24b24674 716 lprintf("no enabled menu entries\n");\r
c7d27148 717 return 0;\r
24b24674 718 }\r
719\r
5a31ef07 720 while ((!menu[sel].enabled || !menu[sel].selectable) && sel < menu_sel_max)\r
24b24674 721 sel++;\r
722\r
723 /* make sure action buttons are not pressed on entering menu */\r
053bef76 724 me_draw(menu, sel, NULL);\r
9934732a 725 while (in_menu_wait_any(NULL, 50) & (PBTN_MOK|PBTN_MBACK|PBTN_MENU));\r
24b24674 726\r
727 for (;;)\r
728 {\r
c7d27148 729 if (draw_prep != NULL)\r
730 draw_prep();\r
731\r
053bef76 732 me_draw(menu, sel, draw_more);\r
049a6b3e 733 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|\r
9934732a 734 PBTN_MOK|PBTN_MBACK|PBTN_MENU|PBTN_L|PBTN_R, NULL, 70);\r
049a6b3e 735 if (inp & (PBTN_MENU|PBTN_MBACK))\r
736 break;\r
737\r
24b24674 738 if (inp & PBTN_UP ) {\r
739 do {\r
740 sel--;\r
741 if (sel < 0)\r
742 sel = menu_sel_max;\r
743 }\r
049a6b3e 744 while (!menu[sel].enabled || !menu[sel].selectable);\r
24b24674 745 }\r
746 if (inp & PBTN_DOWN) {\r
747 do {\r
748 sel++;\r
749 if (sel > menu_sel_max)\r
750 sel = 0;\r
751 }\r
049a6b3e 752 while (!menu[sel].enabled || !menu[sel].selectable);\r
753 }\r
754\r
755 /* a bit hacky but oh well */\r
756 if ((inp & (PBTN_L|PBTN_R)) == (PBTN_L|PBTN_R))\r
757 debug_menu_loop();\r
758\r
5d34757d 759 if (inp & (PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R)) { /* multi choice */\r
760 if (me_process(&menu[sel], (inp & (PBTN_RIGHT|PBTN_R)) ? 1 : 0,\r
761 inp & (PBTN_L|PBTN_R)))\r
049a6b3e 762 continue;\r
24b24674 763 }\r
24b24674 764\r
0c9ae592 765 if (inp & (PBTN_MOK|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R))\r
24b24674 766 {\r
0c9ae592 767 /* require PBTN_MOK for MB_NONE */\r
768 if (menu[sel].handler != NULL && (menu[sel].beh != MB_NONE || (inp & PBTN_MOK))) {\r
049a6b3e 769 ret = menu[sel].handler(menu[sel].id, inp);\r
24b24674 770 if (ret) break;\r
0c9ae592 771 menu_sel_max = me_count(menu) - 1; /* might change, so update */\r
24b24674 772 }\r
773 }\r
24b24674 774 }\r
775 *menu_sel = sel;\r
c7d27148 776\r
777 return ret;\r
778}\r
779\r
780static int me_loop(menu_entry *menu, int *menu_sel)\r
781{\r
782 return me_loop_d(menu, menu_sel, NULL, NULL);\r
24b24674 783}\r
784\r
785/* ***************************************** */\r
786\r
ad6fbeba 787static void draw_menu_message(const char *msg, void (*draw_more)(void))\r
049a6b3e 788{\r
049a6b3e 789 int x, y, h, w, wt;\r
ad6fbeba 790 const char *p;\r
24b24674 791\r
ad6fbeba 792 p = msg;\r
049a6b3e 793 for (h = 1, w = 0; *p != 0; h++) {\r
794 for (wt = 0; *p != 0 && *p != '\n'; p++)\r
795 wt++;\r
24b24674 796\r
049a6b3e 797 if (wt > w)\r
798 w = wt;\r
799 if (*p == 0)\r
24b24674 800 break;\r
049a6b3e 801 p++;\r
24b24674 802 }\r
803\r
95a2ec38 804 x = g_menuscreen_w / 2 - w * me_mfont_w / 2;\r
c66f49e6 805 y = g_menuscreen_h / 2 - h * me_mfont_h / 2;\r
049a6b3e 806 if (x < 0) x = 0;\r
807 if (y < 0) y = 0;\r
808\r
675d1d36 809 menu_draw_begin(1, 0);\r
049a6b3e 810\r
ad6fbeba 811 for (p = msg; *p != 0 && y <= g_menuscreen_h - me_mfont_h; y += me_mfont_h) {\r
cfb49ab9 812 text_out16(x, y, "%s", p);\r
049a6b3e 813\r
814 for (; *p != 0 && *p != '\n'; p++)\r
815 ;\r
816 if (*p != 0)\r
817 p++;\r
818 }\r
819\r
675d1d36 820 menu_separation();\r
821\r
95a2ec38 822 if (draw_more != NULL)\r
823 draw_more();\r
824\r
902972d1 825 menu_draw_end();\r
24b24674 826}\r
827\r
82abf46f 828// -------------- del confirm ---------------\r
829\r
830static void do_delete(const char *fpath, const char *fname)\r
831{\r
832 int len, mid, inp;\r
833 const char *nm;\r
834 char tmp[64];\r
835\r
675d1d36 836 menu_draw_begin(1, 0);\r
82abf46f 837\r
82abf46f 838 len = strlen(fname);\r
c66f49e6 839 if (len > g_menuscreen_w / me_sfont_w)\r
840 len = g_menuscreen_w / me_sfont_w;\r
82abf46f 841\r
c66f49e6 842 mid = g_menuscreen_w / 2;\r
82abf46f 843 text_out16(mid - me_mfont_w * 15 / 2, 8 * me_mfont_h, "About to delete");\r
ff8abddd 844 smalltext_out16(mid - len * me_sfont_w / 2, 9 * me_mfont_h + 5, fname, PXMAKE(0xbf, 0xbf, 0xff));\r
82abf46f 845 text_out16(mid - me_mfont_w * 13 / 2, 11 * me_mfont_h, "Are you sure?");\r
846\r
847 nm = in_get_key_name(-1, -PBTN_MA3);\r
848 snprintf(tmp, sizeof(tmp), "(%s - confirm, ", nm);\r
849 len = strlen(tmp);\r
850 nm = in_get_key_name(-1, -PBTN_MBACK);\r
851 snprintf(tmp + len, sizeof(tmp) - len, "%s - cancel)", nm);\r
852 len = strlen(tmp);\r
853\r
cfb49ab9 854 text_out16(mid - me_mfont_w * len / 2, 12 * me_mfont_h, "%s", tmp);\r
902972d1 855 menu_draw_end();\r
82abf46f 856\r
9934732a 857 while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MA2));\r
858 inp = in_menu_wait(PBTN_MA3|PBTN_MBACK, NULL, 100);\r
82abf46f 859 if (inp & PBTN_MA3)\r
860 remove(fpath);\r
861}\r
862\r
049a6b3e 863// -------------- ROM selector --------------\r
725d7f6c 864\r
8a0998fb 865static void draw_dirlist(char *curdir, struct dirent **namelist,\r
866 int n, int sel, int show_help)\r
b8464531 867{\r
f15ca4db 868 int max_cnt, start, i, x, pos;\r
d2f29611 869 void *darken_ptr;\r
8a0998fb 870 char buff[64];\r
b8464531 871\r
c66f49e6 872 max_cnt = g_menuscreen_h / me_sfont_h;\r
049a6b3e 873 start = max_cnt / 2 - sel;\r
b8464531 874\r
675d1d36 875 menu_draw_begin(1, 1);\r
049a6b3e 876\r
877// if (!rom_loaded)\r
878// menu_darken_bg(gp2x_screen, 320*240, 0);\r
879\r
2b27288e 880 darken_ptr = (short *)g_menuscreen_ptr + g_menuscreen_pp * max_cnt/2 * me_sfont_h;\r
881 menu_darken_bg(darken_ptr, darken_ptr, g_menuscreen_pp * me_sfont_h * 8 / 10, 0);\r
049a6b3e 882\r
f15ca4db 883 x = 5 + me_mfont_w + 1;\r
049a6b3e 884 if (start - 2 >= 0)\r
ff8abddd 885 smalltext_out16(14, (start - 2) * me_sfont_h, curdir, PXMAKE(0xff, 0xff, 0xff));\r
049a6b3e 886 for (i = 0; i < n; i++) {\r
887 pos = start + i;\r
888 if (pos < 0) continue;\r
889 if (pos >= max_cnt) break;\r
a23a278d 890 if (namelist[i]->d_type == DT_DIR) {\r
ff8abddd 891 smalltext_out16(x, pos * me_sfont_h, "/", PXMAKE(0xff, 0xff, 0xb0));\r
892 smalltext_out16(x + me_sfont_w, pos * me_sfont_h, namelist[i]->d_name, PXMAKE(0xff, 0xff, 0xb0));\r
049a6b3e 893 } else {\r
a23a278d 894 unsigned short color = fname2color(namelist[i]->d_name);\r
895 smalltext_out16(x, pos * me_sfont_h, namelist[i]->d_name, color);\r
049a6b3e 896 }\r
b8464531 897 }\r
ff8abddd 898 smalltext_out16(5, max_cnt/2 * me_sfont_h, ">", PXMAKE(0xff, 0xff, 0xff));\r
8a0998fb 899\r
900 if (show_help) {\r
901 darken_ptr = (short *)g_menuscreen_ptr\r
2b27288e 902 + g_menuscreen_pp * (g_menuscreen_h - me_sfont_h * 5 / 2);\r
8a0998fb 903 menu_darken_bg(darken_ptr, darken_ptr,\r
2b27288e 904 g_menuscreen_pp * (me_sfont_h * 5 / 2), 1);\r
8a0998fb 905\r
906 snprintf(buff, sizeof(buff), "%s - select, %s - back",\r
907 in_get_key_name(-1, -PBTN_MOK), in_get_key_name(-1, -PBTN_MBACK));\r
ff8abddd 908 smalltext_out16(x, g_menuscreen_h - me_sfont_h * 3 - 2, buff, PXMAKE(0xe0, 0xf0, 0x60));\r
9089665c 909\r
8a0998fb 910 snprintf(buff, sizeof(buff), g_menu_filter_off ?\r
911 "%s - hide unknown files" : "%s - show all files",\r
912 in_get_key_name(-1, -PBTN_MA3));\r
ff8abddd 913 smalltext_out16(x, g_menuscreen_h - me_sfont_h * 2 - 2, buff, PXMAKE(0xe0, 0xf0, 0x60));\r
9089665c 914\r
915 snprintf(buff, sizeof(buff), g_autostateld_opt ?\r
916 "%s - autoload save is ON" : "%s - autoload save is OFF",\r
917 in_get_key_name(-1, -PBTN_MA2));\r
ff8abddd 918 smalltext_out16(x, g_menuscreen_h - me_sfont_h * 1 - 2, buff, PXMAKE(0xe0, 0xf0, 0x60));\r
8a0998fb 919 }\r
920\r
902972d1 921 menu_draw_end();\r
b8464531 922}\r
923\r
049a6b3e 924static int scandir_cmp(const void *p1, const void *p2)\r
b8464531 925{\r
5f7b5155 926 const struct dirent **d1 = (const struct dirent **)p1;\r
927 const struct dirent **d2 = (const struct dirent **)p2;\r
a23a278d 928 const char *p;\r
929 if ((p = (*d1)->d_name)[0] == '.' && p[1] == '.' && p[2] == 0)\r
930 return -1; // ".." first\r
931 if ((p = (*d2)->d_name)[0] == '.' && p[1] == '.' && p[2] == 0)\r
932 return 1;\r
5f7b5155 933 if ((*d1)->d_type == (*d2)->d_type)\r
934 return alphasort(d1, d2);\r
935 if ((*d1)->d_type == DT_DIR)\r
a23a278d 936 return -1; // directories before files/links\r
5f7b5155 937 if ((*d2)->d_type == DT_DIR)\r
938 return 1;\r
939\r
049a6b3e 940 return alphasort(d1, d2);\r
941}\r
b8464531 942\r
4db02226 943static const char **filter_exts_internal;\r
944\r
049a6b3e 945static int scandir_filter(const struct dirent *ent)\r
946{\r
4db02226 947 const char **filter = filter_exts_internal;\r
8a0998fb 948 const char *ext;\r
049a6b3e 949 int i;\r
950\r
f287890d 951 if (ent == NULL)\r
8a0998fb 952 return 0;\r
953\r
515ac0b9 954 switch (ent->d_type) {\r
955 case DT_DIR:\r
a23a278d 956 // leave out useless reference to current directory\r
957 return strcmp(ent->d_name, ".") != 0;\r
515ac0b9 958 case DT_LNK:\r
959 case DT_UNKNOWN:\r
960 // could be a dir, deal with it later..\r
961 return 1;\r
962 }\r
049a6b3e 963\r
8a0998fb 964 ext = strrchr(ent->d_name, '.');\r
965 if (ext == NULL)\r
966 return 0;\r
049a6b3e 967\r
8a0998fb 968 ext++;\r
4db02226 969 for (i = 0; filter[i] != NULL; i++)\r
970 if (strcasecmp(ext, filter[i]) == 0)\r
8a0998fb 971 return 1;\r
049a6b3e 972\r
8a0998fb 973 return 0;\r
b8464531 974}\r
975\r
9934732a 976static int dirent_seek_char(struct dirent **namelist, int len, int sel, char c)\r
977{\r
978 int i;\r
979\r
ec90b021 980 for (i = sel + 1; ; i++) {\r
9934732a 981 if (i >= len)\r
2d02d8d6 982 i = 0;\r
ec90b021 983 if (i == sel)\r
984 break;\r
9934732a 985\r
986 if (tolower_simple(namelist[i]->d_name[0]) == c)\r
987 break;\r
988 }\r
989\r
f5b32cc3 990 return i;\r
9934732a 991}\r
992\r
bf1b3e32 993static const char *menu_loop_romsel_d(char *curr_path, int len,\r
4db02226 994 const char **filter_exts,\r
8a0998fb 995 int (*extra_filter)(struct dirent **namelist, int count,\r
bf1b3e32 996 const char *basedir),\r
997 void (*draw_prep)(void))\r
b8464531 998{\r
515ac0b9 999 static char rom_fname_reload[256]; // used for scratch and return\r
8a0998fb 1000 char sel_fname[256];\r
1001 int (*filter)(const struct dirent *);\r
1002 struct dirent **namelist = NULL;\r
1003 int n = 0, inp = 0, sel = 0, show_help = 0;\r
1004 char *curr_path_restore = NULL;\r
4db02226 1005 const char *ret = NULL;\r
9934732a 1006 char cinp;\r
515ac0b9 1007 int r, i;\r
049a6b3e 1008\r
4db02226 1009 filter_exts_internal = filter_exts;\r
8a0998fb 1010 sel_fname[0] = 0;\r
1011\r
049a6b3e 1012 // is this a dir or a full path?\r
1013 if (!plat_is_dir(curr_path)) {\r
20b14308
GI
1014 char *p = strrchr(curr_path, '/');\r
1015 if (p != NULL) {\r
1016 *p = 0;\r
1017 curr_path_restore = p;\r
1018 snprintf(sel_fname, sizeof(sel_fname), "%s", p + 1);\r
1019 }\r
8a0998fb 1020 }\r
bf1b3e32 1021 show_help = 2;\r
8a0998fb 1022\r
1023rescan:\r
1024 if (namelist != NULL) {\r
bf1b3e32 1025 n += !n;\r
8a0998fb 1026 while (n-- > 0)\r
1027 free(namelist[n]);\r
1028 free(namelist);\r
1029 namelist = NULL;\r
049a6b3e 1030 }\r
b8464531 1031\r
8a0998fb 1032 filter = NULL;\r
1033 if (!g_menu_filter_off)\r
1034 filter = scandir_filter;\r
1035\r
1036 n = scandir(curr_path, &namelist, filter, (void *)scandir_cmp);\r
d5a43fbd 1037 if (n < 0 || !namelist) {\r
049a6b3e 1038 lprintf("menu_loop_romsel failed, dir: %s\n", curr_path);\r
1039\r
a23a278d 1040 // try data root\r
1041 plat_get_data_dir(curr_path, len);\r
8a0998fb 1042 n = scandir(curr_path, &namelist, filter, (void *)scandir_cmp);\r
d5a43fbd 1043 if (n < 0 || !namelist) {\r
049a6b3e 1044 // oops, we failed\r
1045 lprintf("menu_loop_romsel failed, dir: %s\n", curr_path);\r
d5a43fbd 1046 namelist = malloc(sizeof(*namelist));\r
1047 namelist[0] = calloc(1, sizeof(**namelist));\r
049a6b3e 1048 }\r
1049 }\r
1050\r
515ac0b9 1051 // try to resolve DT_UNKNOWN and symlinks\r
515ac0b9 1052 for (i = 0; i < n; i++) {\r
1053 struct stat st;\r
a23a278d 1054 char *slash;\r
515ac0b9 1055\r
1056 if (namelist[i]->d_type == DT_REG || namelist[i]->d_type == DT_DIR)\r
1057 continue;\r
1058\r
a23a278d 1059 r = strlen(curr_path);\r
1060 slash = (r && curr_path[r-1] == '/') ? "" : "/";\r
515ac0b9 1061 snprintf(rom_fname_reload, sizeof(rom_fname_reload),\r
a23a278d 1062 "%s%s%s", curr_path, slash, namelist[i]->d_name);\r
515ac0b9 1063 r = stat(rom_fname_reload, &st);\r
1064 if (r == 0)\r
1065 {\r
a23a278d 1066 if (S_ISREG(st.st_mode))\r
515ac0b9 1067 namelist[i]->d_type = DT_REG;\r
a23a278d 1068 else if (S_ISDIR(st.st_mode))\r
515ac0b9 1069 namelist[i]->d_type = DT_DIR;\r
515ac0b9 1070 }\r
1071 }\r
1072\r
8a0998fb 1073 if (!g_menu_filter_off && extra_filter != NULL)\r
1074 n = extra_filter(namelist, n, curr_path);\r
1075\r
a23a278d 1076 if (n > 1)\r
515ac0b9 1077 qsort(namelist, n, sizeof(namelist[0]), scandir_cmp);\r
1078\r
d23f5773 1079 // add ".." if it's somehow not there\r
1080 if (n == 0 || strcmp(namelist[0]->d_name, "..")) {\r
1081 struct dirent *dotdot = malloc(sizeof(*dotdot));\r
1082 *dotdot = (struct dirent) { .d_name="..", .d_type=DT_DIR };\r
1083 namelist = realloc(namelist, (n+1)*sizeof(*namelist));\r
1084 memmove(namelist+1, namelist, n*sizeof(*namelist));\r
1085 namelist[0] = dotdot;\r
1086 n++;\r
1087 }\r
1088\r
8a0998fb 1089 // try to find selected file\r
8a0998fb 1090 sel = 0;\r
1091 if (sel_fname[0] != 0) {\r
a23a278d 1092 for (i = 0; i < n; i++) {\r
9934732a 1093 char *dname = namelist[i]->d_name;\r
8a0998fb 1094 if (dname[0] == sel_fname[0] && strcmp(dname, sel_fname) == 0) {\r
a23a278d 1095 sel = i;\r
b8464531 1096 break;\r
049a6b3e 1097 }\r
b8464531 1098 }\r
049a6b3e 1099 }\r
b8464531 1100\r
e0e9248c 1101 /* make sure action buttons are not pressed on entering menu */\r
8a0998fb 1102 draw_dirlist(curr_path, namelist, n, sel, show_help);\r
9934732a 1103 while (in_menu_wait_any(NULL, 50) & (PBTN_MOK|PBTN_MBACK|PBTN_MENU))\r
e0e9248c 1104 ;\r
1105\r
049a6b3e 1106 for (;;)\r
1107 {\r
bf1b3e32 1108 if (draw_prep != NULL)\r
1109 draw_prep();\r
8a0998fb 1110 draw_dirlist(curr_path, namelist, n, sel, show_help);\r
1111 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT\r
1112 | PBTN_L|PBTN_R|PBTN_MA2|PBTN_MA3|PBTN_MOK|PBTN_MBACK\r
1113 | PBTN_MENU|PBTN_CHAR, &cinp, 33);\r
8a0998fb 1114 if (inp & PBTN_MA3) {\r
1115 g_menu_filter_off = !g_menu_filter_off;\r
1116 snprintf(sel_fname, sizeof(sel_fname), "%s",\r
a23a278d 1117 namelist[sel]->d_name);\r
bf1b3e32 1118 show_help = 2;\r
8a0998fb 1119 goto rescan;\r
1120 }\r
d5a43fbd 1121 int last = n ? n-1 : 0;\r
1122 if (inp & PBTN_UP ) { sel--; if (sel < 0) sel = last; }\r
9bc19b0f 1123 else if (inp & PBTN_DOWN) { sel++; if (sel > n-1) sel = 0; }\r
1124 else if (inp & PBTN_LEFT) { sel-=10; if (sel < 0) sel = 0; }\r
d5a43fbd 1125 else if (inp & PBTN_RIGHT) { sel+=10; if (sel > n-1) sel = last; }\r
9bc19b0f 1126 else if (inp & PBTN_L) { sel-=24; if (sel < 0) sel = 0; }\r
d5a43fbd 1127 else if (inp & PBTN_R) { sel+=24; if (sel > n-1) sel = last; }\r
9bc19b0f 1128\r
1129 else if ((inp & PBTN_MOK) || (inp & (PBTN_MENU|PBTN_MA2)) == (PBTN_MENU|PBTN_MA2))\r
b8464531 1130 {\r
a23a278d 1131 if (namelist[sel]->d_type == DT_REG)\r
049a6b3e 1132 {\r
a23a278d 1133 int l = strlen(curr_path);\r
1134 char *slash = l && curr_path[l-1] == '/' ? "" : "/";\r
8a0998fb 1135 snprintf(rom_fname_reload, sizeof(rom_fname_reload),\r
a23a278d 1136 "%s%s%s", curr_path, slash, namelist[sel]->d_name);\r
049a6b3e 1137 if (inp & PBTN_MOK) { // return sel\r
1138 ret = rom_fname_reload;\r
1139 break;\r
725d7f6c 1140 }\r
a23a278d 1141 do_delete(rom_fname_reload, namelist[sel]->d_name);\r
049a6b3e 1142 goto rescan;\r
1143 }\r
a23a278d 1144 else if (namelist[sel]->d_type == DT_DIR)\r
049a6b3e 1145 {\r
1146 int newlen;\r
1147 char *p, *newdir;\r
95a2ec38 1148 if (!(inp & PBTN_MOK))\r
1149 continue;\r
a23a278d 1150 newlen = strlen(curr_path) + strlen(namelist[sel]->d_name) + 2;\r
049a6b3e 1151 newdir = malloc(newlen);\r
95a2ec38 1152 if (newdir == NULL)\r
1153 break;\r
a23a278d 1154 if (strcmp(namelist[sel]->d_name, "..") == 0) {\r
049a6b3e 1155 char *start = curr_path;\r
1156 p = start + strlen(start) - 1;\r
1157 while (*p == '/' && p > start) p--;\r
1158 while (*p != '/' && p > start) p--;\r
a23a278d 1159 if (p <= start) plat_get_data_dir(newdir, newlen);\r
049a6b3e 1160 else { strncpy(newdir, start, p-start); newdir[p-start] = 0; }\r
1161 } else {\r
1162 strcpy(newdir, curr_path);\r
1163 p = newdir + strlen(newdir) - 1;\r
9fba90ac 1164 while (p >= newdir && *p == '/') *p-- = 0;\r
049a6b3e 1165 strcat(newdir, "/");\r
a23a278d 1166 strcat(newdir, namelist[sel]->d_name);\r
b8464531 1167 }\r
bf1b3e32 1168 ret = menu_loop_romsel_d(newdir, newlen, filter_exts, extra_filter, draw_prep);\r
049a6b3e 1169 free(newdir);\r
b8464531 1170 break;\r
049a6b3e 1171 }\r
049a6b3e 1172 }\r
9089665c 1173 else if (inp & PBTN_MA2) {\r
1174 g_autostateld_opt = !g_autostateld_opt;\r
1175 show_help = 3;\r
1176 }\r
1177 else if (inp & PBTN_CHAR) {\r
1178 // must be last\r
1179 sel = dirent_seek_char(namelist, n, sel, cinp);\r
1180 }\r
1181\r
049a6b3e 1182 if (inp & PBTN_MBACK)\r
1183 break;\r
8a0998fb 1184\r
1185 if (show_help > 0)\r
1186 show_help--;\r
049a6b3e 1187 }\r
1188\r
1189 if (n > 0) {\r
8a0998fb 1190 while (n-- > 0)\r
1191 free(namelist[n]);\r
049a6b3e 1192 free(namelist);\r
1193 }\r
1194\r
95a2ec38 1195 // restore curr_path\r
8a0998fb 1196 if (curr_path_restore != NULL)\r
1197 *curr_path_restore = '/';\r
95a2ec38 1198\r
049a6b3e 1199 return ret;\r
1200}\r
1201\r
bf1b3e32 1202static const char *menu_loop_romsel(char *curr_path, int len,\r
1203 const char **filter_exts,\r
1204 int (*extra_filter)(struct dirent **namelist, int count,\r
1205 const char *basedir))\r
1206{\r
1207 return menu_loop_romsel_d(curr_path, len, filter_exts, extra_filter, NULL);\r
1208}\r
1209\r
049a6b3e 1210// ------------ savestate loader ------------\r
1211\r
8b8d9463 1212#define STATE_SLOT_COUNT 10\r
1213\r
049a6b3e 1214static int state_slot_flags = 0;\r
8b8d9463 1215static int state_slot_times[STATE_SLOT_COUNT];\r
049a6b3e 1216\r
1217static void state_check_slots(void)\r
1218{\r
1219 int slot;\r
1220\r
1221 state_slot_flags = 0;\r
1222\r
8b8d9463 1223 for (slot = 0; slot < STATE_SLOT_COUNT; slot++) {\r
1224 state_slot_times[slot] = 0;\r
1225 if (emu_check_save_file(slot, &state_slot_times[slot]))\r
049a6b3e 1226 state_slot_flags |= 1 << slot;\r
1227 }\r
1228}\r
1229\r
94a1d22e 1230static void draw_savestate_bg(int slot);\r
049a6b3e 1231\r
1232static void draw_savestate_menu(int menu_sel, int is_loading)\r
1233{\r
1234 int i, x, y, w, h;\r
8b8d9463 1235 char time_buf[32];\r
049a6b3e 1236\r
1237 if (state_slot_flags & (1 << menu_sel))\r
1238 draw_savestate_bg(menu_sel);\r
1239\r
f15ca4db 1240 w = (13 + 2) * me_mfont_w;\r
8b8d9463 1241 h = (1+2+STATE_SLOT_COUNT+1) * me_mfont_h;\r
c66f49e6 1242 x = g_menuscreen_w / 2 - w / 2;\r
049a6b3e 1243 if (x < 0) x = 0;\r
c66f49e6 1244 y = g_menuscreen_h / 2 - h / 2;\r
049a6b3e 1245 if (y < 0) y = 0;\r
95a2ec38 1246#ifdef MENU_ALIGN_LEFT\r
1247 if (x > 12 + me_mfont_w * 2)\r
1248 x = 12 + me_mfont_w * 2;\r
1249#endif\r
049a6b3e 1250\r
675d1d36 1251 menu_draw_begin(1, 1);\r
049a6b3e 1252\r
1253 text_out16(x, y, is_loading ? "Load state" : "Save state");\r
3ffee69c 1254 y += 3 * me_mfont_h;\r
049a6b3e 1255\r
8b8d9463 1256 menu_draw_selection(x - me_mfont_w * 2, y + menu_sel * me_mfont_h, (23 + 2) * me_mfont_w + 4);\r
049a6b3e 1257\r
8b8d9463 1258 /* draw all slots */\r
1259 for (i = 0; i < STATE_SLOT_COUNT; i++, y += me_mfont_h)\r
049a6b3e 1260 {\r
8b8d9463 1261 if (!(state_slot_flags & (1 << i)))\r
1262 strcpy(time_buf, "free");\r
1263 else {\r
1264 strcpy(time_buf, "USED");\r
1265 if (state_slot_times[i] != 0) {\r
1266 time_t time = state_slot_times[i];\r
1267 struct tm *t = localtime(&time);\r
1268 strftime(time_buf, sizeof(time_buf), "%x %R", t);\r
1269 }\r
1270 }\r
1271\r
1272 text_out16(x, y, "SLOT %i (%s)", i, time_buf);\r
049a6b3e 1273 }\r
1274 text_out16(x, y, "back");\r
1275\r
902972d1 1276 menu_draw_end();\r
049a6b3e 1277}\r
1278\r
1279static int menu_loop_savestate(int is_loading)\r
1280{\r
8b8d9463 1281 static int menu_sel = STATE_SLOT_COUNT;\r
1282 int menu_sel_max = STATE_SLOT_COUNT;\r
049a6b3e 1283 unsigned long inp = 0;\r
d2275713 1284 int ret = 0;\r
049a6b3e 1285\r
1286 state_check_slots();\r
1287\r
5354c909 1288 if (!(state_slot_flags & (1 << menu_sel)) && is_loading)\r
1289 menu_sel = menu_sel_max;\r
1290\r
049a6b3e 1291 for (;;)\r
1292 {\r
1293 draw_savestate_menu(menu_sel, is_loading);\r
9934732a 1294 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_MOK|PBTN_MBACK, NULL, 100);\r
049a6b3e 1295 if (inp & PBTN_UP) {\r
1296 do {\r
1297 menu_sel--;\r
1298 if (menu_sel < 0)\r
1299 menu_sel = menu_sel_max;\r
1300 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);\r
1301 }\r
1302 if (inp & PBTN_DOWN) {\r
1303 do {\r
1304 menu_sel++;\r
1305 if (menu_sel > menu_sel_max)\r
1306 menu_sel = 0;\r
1307 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);\r
1308 }\r
1309 if (inp & PBTN_MOK) { // save/load\r
8b8d9463 1310 if (menu_sel < STATE_SLOT_COUNT) {\r
049a6b3e 1311 state_slot = menu_sel;\r
ee0f881e 1312 if (emu_save_load_game(is_loading, 0)) {\r
675d1d36 1313 menu_update_msg(is_loading ? "Load failed" : "Save failed");\r
d2275713 1314 break;\r
049a6b3e 1315 }\r
d2275713 1316 ret = 1;\r
1317 break;\r
049a6b3e 1318 }\r
d2275713 1319 break;\r
049a6b3e 1320 }\r
1321 if (inp & PBTN_MBACK)\r
d2275713 1322 break;\r
049a6b3e 1323 }\r
d2275713 1324\r
1325 return ret;\r
049a6b3e 1326}\r
1327\r
1328// -------------- key config --------------\r
1329\r
1330static char *action_binds(int player_idx, int action_mask, int dev_id)\r
1331{\r
4ec1acc1 1332 int dev = 0, dev_last = IN_MAX_DEVS - 1;\r
1333 int can_combo = 1, type;\r
049a6b3e 1334\r
1335 static_buff[0] = 0;\r
1336\r
8e77275e 1337 type = IN_BINDTYPE_EMU;\r
1338 if (player_idx >= 0) {\r
1339 can_combo = 0;\r
25cfdf0a 1340 type = IN_BINDTYPE_PLAYER12 + (player_idx >> 1);\r
49190405 1341 if (player_idx & 1)\r
1342 action_mask <<= 16;\r
8e77275e 1343 }\r
8e77275e 1344\r
4ec1acc1 1345 if (dev_id >= 0)\r
1346 dev = dev_last = dev_id;\r
1347\r
1348 for (; dev <= dev_last; dev++) {\r
1349 int k, count = 0, combo = 0;\r
1350 const int *binds;\r
049a6b3e 1351\r
4ec1acc1 1352 binds = in_get_dev_binds(dev);\r
1353 if (binds == NULL)\r
049a6b3e 1354 continue;\r
1355\r
4ec1acc1 1356 in_get_config(dev, IN_CFG_BIND_COUNT, &count);\r
1357 in_get_config(dev, IN_CFG_DOES_COMBOS, &combo);\r
1358 combo = combo && can_combo;\r
1359\r
1360 for (k = 0; k < count; k++) {\r
1361 const char *xname;\r
1362 int len;\r
1363\r
1364 if (!(binds[IN_BIND_OFFS(k, type)] & action_mask))\r
1365 continue;\r
1366\r
1367 xname = in_get_key_name(dev, k);\r
1368 len = strlen(static_buff);\r
1369 if (len) {\r
1370 strncat(static_buff, combo ? " + " : ", ",\r
1371 sizeof(static_buff) - len - 1);\r
1372 len += combo ? 3 : 2;\r
1373 }\r
1374 strncat(static_buff, xname, sizeof(static_buff) - len - 1);\r
f15ca4db 1375 }\r
049a6b3e 1376 }\r
1377\r
1378 return static_buff;\r
1379}\r
1380\r
8e77275e 1381static int count_bound_keys(int dev_id, int action_mask, int bindtype)\r
049a6b3e 1382{\r
1383 const int *binds;\r
1384 int k, keys = 0;\r
902972d1 1385 int count = 0;\r
049a6b3e 1386\r
1387 binds = in_get_dev_binds(dev_id);\r
1388 if (binds == NULL)\r
1389 return 0;\r
1390\r
902972d1 1391 in_get_config(dev_id, IN_CFG_BIND_COUNT, &count);\r
049a6b3e 1392 for (k = 0; k < count; k++)\r
1393 {\r
8e77275e 1394 if (binds[IN_BIND_OFFS(k, bindtype)] & action_mask)\r
1395 keys++;\r
049a6b3e 1396 }\r
1397\r
1398 return keys;\r
1399}\r
1400\r
1401static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_idx,\r
1402 int sel, int dev_id, int dev_count, int is_bind)\r
1403{\r
92068389 1404 char buff[64], buff2[32];\r
049a6b3e 1405 const char *dev_name;\r
5a31ef07 1406 int x, y, w, i;\r
049a6b3e 1407\r
5a31ef07 1408 w = ((player_idx >= 0) ? 20 : 30) * me_mfont_w;\r
c66f49e6 1409 x = g_menuscreen_w / 2 - w / 2;\r
1410 y = (g_menuscreen_h - 4 * me_mfont_h) / 2 - (2 + opt_cnt) * me_mfont_h / 2;\r
3ffee69c 1411 if (x < me_mfont_w * 2)\r
1412 x = me_mfont_w * 2;\r
e7f58005
NTKV
1413 if (y < 0)\r
1414 y = 0;\r
675d1d36 1415 menu_draw_begin(1, 0);\r
049a6b3e 1416 if (player_idx >= 0)\r
3ffee69c 1417 text_out16(x, y, "Player %i controls", player_idx + 1);\r
049a6b3e 1418 else\r
3ffee69c 1419 text_out16(x, y, "Emulator controls");\r
049a6b3e 1420\r
3ffee69c 1421 y += 2 * me_mfont_h;\r
5a31ef07 1422 menu_draw_selection(x - me_mfont_w * 2, y + sel * me_mfont_h, w + 2 * me_mfont_w);\r
049a6b3e 1423\r
3ffee69c 1424 for (i = 0; i < opt_cnt; i++, y += me_mfont_h)\r
049a6b3e 1425 text_out16(x, y, "%s : %s", opts[i].name,\r
1426 action_binds(player_idx, opts[i].mask, dev_id));\r
1427\r
675d1d36 1428 menu_separation();\r
1429\r
4ec1acc1 1430 if (dev_id < 0)\r
1431 dev_name = "(all devices)";\r
1432 else\r
a4025790 1433 dev_name = in_get_dev_name(dev_id, 0, 1);\r
3ffee69c 1434 w = strlen(dev_name) * me_mfont_w;\r
1435 if (w < 30 * me_mfont_w)\r
1436 w = 30 * me_mfont_w;\r
c66f49e6 1437 if (w > g_menuscreen_w)\r
1438 w = g_menuscreen_w;\r
049a6b3e 1439\r
c66f49e6 1440 x = g_menuscreen_w / 2 - w / 2;\r
049a6b3e 1441\r
92068389 1442 if (!is_bind) {\r
1443 snprintf(buff2, sizeof(buff2), "%s", in_get_key_name(-1, -PBTN_MOK));\r
1444 snprintf(buff, sizeof(buff), "%s - bind, %s - clear", buff2,\r
1445 in_get_key_name(-1, -PBTN_MA2));\r
cfb49ab9 1446 text_out16(x, g_menuscreen_h - 4 * me_mfont_h, "%s", buff);\r
049a6b3e 1447 }\r
92068389 1448 else\r
c66f49e6 1449 text_out16(x, g_menuscreen_h - 4 * me_mfont_h, "Press a button to bind/unbind");\r
049a6b3e 1450\r
92068389 1451 if (dev_count > 1) {\r
cfb49ab9 1452 text_out16(x, g_menuscreen_h - 3 * me_mfont_h, "%s", dev_name);\r
c66f49e6 1453 text_out16(x, g_menuscreen_h - 2 * me_mfont_h, "Press left/right for other devs");\r
92068389 1454 }\r
049a6b3e 1455\r
902972d1 1456 menu_draw_end();\r
049a6b3e 1457}\r
1458\r
1459static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_idx)\r
1460{\r
902972d1 1461 int i, sel = 0, menu_sel_max = opt_cnt - 1, does_combos = 0;\r
4ec1acc1 1462 int dev_id, bind_dev_id, dev_count, kc, is_down, mkey;\r
92068389 1463 int unbind, bindtype, mask_shift;\r
049a6b3e 1464\r
1465 for (i = 0, dev_id = -1, dev_count = 0; i < IN_MAX_DEVS; i++) {\r
1466 if (in_get_dev_name(i, 1, 0) != NULL) {\r
1467 dev_count++;\r
1468 if (dev_id < 0)\r
1469 dev_id = i;\r
1470 }\r
1471 }\r
1472\r
1473 if (dev_id == -1) {\r
1474 lprintf("no devs, can't do config\n");\r
1475 return;\r
1476 }\r
1477\r
4ec1acc1 1478 dev_id = -1; // show all\r
92068389 1479 mask_shift = 0;\r
49190405 1480 if (player_idx >= 0) {\r
1481 if (player_idx & 1)\r
1482 mask_shift = 16;\r
1483 bindtype = IN_BINDTYPE_PLAYER12 + (player_idx >> 1);\r
1484 } else\r
1485 bindtype = IN_BINDTYPE_EMU;\r
92068389 1486\r
049a6b3e 1487 for (;;)\r
1488 {\r
1489 draw_key_config(opts, opt_cnt, player_idx, sel, dev_id, dev_count, 0);\r
9934732a 1490 mkey = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT\r
1491 |PBTN_MBACK|PBTN_MOK|PBTN_MA2, NULL, 100);\r
049a6b3e 1492 switch (mkey) {\r
1493 case PBTN_UP: sel--; if (sel < 0) sel = menu_sel_max; continue;\r
1494 case PBTN_DOWN: sel++; if (sel > menu_sel_max) sel = 0; continue;\r
1495 case PBTN_LEFT:\r
4ec1acc1 1496 for (i = 0, dev_id--; i < IN_MAX_DEVS + 1; i++, dev_id--) {\r
1497 if (dev_id < -1)\r
049a6b3e 1498 dev_id = IN_MAX_DEVS - 1;\r
a4025790 1499 if (dev_id == -1 || in_get_dev_name(dev_id, 0, 0) != NULL)\r
049a6b3e 1500 break;\r
1501 }\r
1502 continue;\r
1503 case PBTN_RIGHT:\r
1504 for (i = 0, dev_id++; i < IN_MAX_DEVS; i++, dev_id++) {\r
1505 if (dev_id >= IN_MAX_DEVS)\r
4ec1acc1 1506 dev_id = -1;\r
a4025790 1507 if (dev_id == -1 || in_get_dev_name(dev_id, 0, 0) != NULL)\r
049a6b3e 1508 break;\r
1509 }\r
1510 continue;\r
ec54eeef 1511 case PBTN_MBACK:\r
1512 return;\r
049a6b3e 1513 case PBTN_MOK:\r
1514 if (sel >= opt_cnt)\r
1515 return;\r
9934732a 1516 while (in_menu_wait_any(NULL, 30) & PBTN_MOK)\r
ec54eeef 1517 ;\r
049a6b3e 1518 break;\r
92068389 1519 case PBTN_MA2:\r
1520 in_unbind_all(dev_id, opts[sel].mask << mask_shift, bindtype);\r
1521 continue;\r
049a6b3e 1522 default:continue;\r
1523 }\r
1524\r
1525 draw_key_config(opts, opt_cnt, player_idx, sel, dev_id, dev_count, 1);\r
1526\r
1527 /* wait for some up event */\r
1528 for (is_down = 1; is_down; )\r
9934732a 1529 kc = in_update_keycode(&bind_dev_id, &is_down, NULL, -1);\r
049a6b3e 1530\r
4ec1acc1 1531 i = count_bound_keys(bind_dev_id, opts[sel].mask << mask_shift, bindtype);\r
2c600560 1532 unbind = (i > 0);\r
1533\r
1534 /* allow combos if device supports them */\r
4ec1acc1 1535 in_get_config(bind_dev_id, IN_CFG_DOES_COMBOS, &does_combos);\r
902972d1 1536 if (i == 1 && bindtype == IN_BINDTYPE_EMU && does_combos)\r
2c600560 1537 unbind = 0;\r
049a6b3e 1538\r
ec54eeef 1539 if (unbind)\r
4ec1acc1 1540 in_unbind_all(bind_dev_id, opts[sel].mask << mask_shift, bindtype);\r
ec54eeef 1541\r
4ec1acc1 1542 in_bind_key(bind_dev_id, kc, opts[sel].mask << mask_shift, bindtype, 0);\r
9fec8a91 1543\r
1544 // make sure bind change is displayed\r
1545 if (dev_id != -1)\r
1546 dev_id = bind_dev_id;\r
049a6b3e 1547 }\r
1548}\r
1549\r