1 // (c) Copyright 2006-2009 notaz, All rights reserved.
\r
2 // Free for non-commercial use.
\r
4 // For commercial use, separate licencing terms must be obtained.
\r
13 #include "readpng.h"
\r
14 #include "lprintf.h"
\r
19 #include <version.h>
\r
20 #include <revision.h>
\r
22 #include <pico/pico_int.h>
\r
23 #include <pico/patch.h>
\r
25 static char static_buff[64];
\r
26 static char menu_error_msg[64] = { 0, };
\r
27 static int menu_error_time = 0;
\r
31 static unsigned char *menu_font_data = NULL;
\r
32 static int menu_text_color = 0xffff; // default to white
\r
33 static int menu_sel_color = -1; // disabled
\r
35 /* note: these might become non-constant in future */
\r
37 static const int me_mfont_w = 16, me_mfont_h = 20;
\r
38 static const int me_sfont_w = 12, me_sfont_h = 20;
\r
40 static const int me_mfont_w = 8, me_mfont_h = 10;
\r
41 static const int me_sfont_w = 6, me_sfont_h = 10;
\r
44 // draws text to current bbp16 screen
\r
45 static void text_out16_(int x, int y, const char *text, int color)
\r
47 int i, l, u, tr, tg, tb, len;
\r
48 unsigned short *dest = (unsigned short *)g_screen_ptr + x + y * g_screen_width;
\r
49 tr = (color & 0xf800) >> 8;
\r
50 tg = (color & 0x07e0) >> 3;
\r
51 tb = (color & 0x001f) << 3;
\r
53 if (text == (void *)1)
\r
62 for (p = text; *p != 0 && *p != '\n'; p++)
\r
67 for (i = 0; i < len; i++)
\r
69 unsigned char *src = menu_font_data + (unsigned int)text[i] * me_mfont_w * me_mfont_h / 2;
\r
70 unsigned short *dst = dest;
\r
71 for (l = 0; l < me_mfont_h; l++, dst += g_screen_width - me_mfont_w)
\r
73 for (u = me_mfont_w / 2; u > 0; u--, src++)
\r
77 r = (*dst & 0xf800) >> 8;
\r
78 g = (*dst & 0x07e0) >> 3;
\r
79 b = (*dst & 0x001f) << 3;
\r
80 r = (c^0xf)*r/15 + c*tr/15;
\r
81 g = (c^0xf)*g/15 + c*tg/15;
\r
82 b = (c^0xf)*b/15 + c*tb/15;
\r
83 *dst++ = ((r<<8)&0xf800) | ((g<<3)&0x07e0) | (b>>3);
\r
85 r = (*dst & 0xf800) >> 8;
\r
86 g = (*dst & 0x07e0) >> 3;
\r
87 b = (*dst & 0x001f) << 3;
\r
88 r = (c^0xf)*r/15 + c*tr/15;
\r
89 g = (c^0xf)*g/15 + c*tg/15;
\r
90 b = (c^0xf)*b/15 + c*tb/15;
\r
91 *dst++ = ((r<<8)&0xf800) | ((g<<3)&0x07e0) | (b>>3);
\r
98 void text_out16(int x, int y, const char *texto, ...)
\r
102 int maxw = (g_screen_width - x) / me_mfont_w;
\r
107 va_start(args, texto);
\r
108 vsnprintf(buffer, sizeof(buffer), texto, args);
\r
111 if (maxw > sizeof(buffer) - 1)
\r
112 maxw = sizeof(buffer) - 1;
\r
115 text_out16_(x,y,buffer,menu_text_color);
\r
118 /* draws in 6x8 font, might multiply size by integer */
\r
119 static void smalltext_out16_(int x, int y, const char *texto, int color)
\r
121 unsigned char *src;
\r
122 unsigned short *dst;
\r
123 int multiplier = me_sfont_w / 6;
\r
126 for (i = 0;; i++, x += me_sfont_w)
\r
128 unsigned char c = (unsigned char) texto[i];
\r
131 if (!c || c == '\n')
\r
134 src = fontdata6x8[c];
\r
135 dst = (unsigned short *)g_screen_ptr + x + y * g_screen_width;
\r
140 for (h2 = multiplier; h2 > 0; h2--)
\r
142 for (m = 0x20; m; m >>= 1) {
\r
144 for (w2 = multiplier; w2 > 0; w2--)
\r
150 dst += g_screen_width - me_sfont_w;
\r
157 static void smalltext_out16(int x, int y, const char *texto, int color)
\r
160 int maxw = (g_screen_width - x) / 6;
\r
165 strncpy(buffer, texto, sizeof(buffer));
\r
166 if (maxw > sizeof(buffer) - 1)
\r
167 maxw = sizeof(buffer) - 1;
\r
170 smalltext_out16_(x, y, buffer, color);
\r
173 static void menu_draw_selection(int x, int y, int w)
\r
176 unsigned short *dst, *dest;
\r
178 text_out16_(x, y, (void *)1, (menu_sel_color < 0) ? menu_text_color : menu_sel_color);
\r
180 if (menu_sel_color < 0) return; // no selection hilight
\r
183 dest = (unsigned short *)g_screen_ptr + x + y * g_screen_width + 14;
\r
184 for (h = me_mfont_h + 1; h > 0; h--)
\r
187 for (i = w - 14; i > 0; i--)
\r
188 *dst++ = menu_sel_color;
\r
189 dest += g_screen_width;
\r
193 static int parse_hex_color(char *buff)
\r
196 int t = (int) strtoul(buff, &endp, 16);
\r
199 return ((t<<8)&0xf800) | ((t>>5)&0x07e0) | ((t>>19)&0x1f);
\r
201 return ((t>>8)&0xf800) | ((t>>5)&0x07e0) | ((t>>3)&0x1f);
\r
206 void menu_init(void)
\r
209 unsigned char *fd, *fds;
\r
213 if (menu_font_data != NULL)
\r
214 free(menu_font_data);
\r
216 menu_font_data = calloc((MENU_X2 ? 256 * 320 : 128 * 160) / 2, 1);
\r
217 if (menu_font_data == NULL)
\r
220 // generate default 8x10 font from fontdata8x8
\r
221 for (c = 0, fd = menu_font_data; c < 256; c++)
\r
223 for (l = 0; l < 8; l++)
\r
225 unsigned char fd8x8 = fontdata8x8[c*8+l];
\r
226 if (fd8x8&0x80) *fd = 0xf0;
\r
227 if (fd8x8&0x40) *fd |= 0x0f; fd++;
\r
228 if (fd8x8&0x20) *fd = 0xf0;
\r
229 if (fd8x8&0x10) *fd |= 0x0f; fd++;
\r
230 if (fd8x8&0x08) *fd = 0xf0;
\r
231 if (fd8x8&0x04) *fd |= 0x0f; fd++;
\r
232 if (fd8x8&0x02) *fd = 0xf0;
\r
233 if (fd8x8&0x01) *fd |= 0x0f; fd++;
\r
235 fd += 8*2/2; // 2 empty lines
\r
239 // expand default font
\r
240 fds = menu_font_data + 128 * 160 / 2 - 4;
\r
241 fd = menu_font_data + 256 * 320 / 2 - 1;
\r
242 for (c = 255; c >= 0; c--)
\r
244 for (l = 9; l >= 0; l--, fds -= 4)
\r
246 for (i = 3; i >= 0; i--) {
\r
247 int px = fds[i] & 0x0f;
\r
248 *fd-- = px | (px << 4);
\r
249 px = (fds[i] >> 4) & 0x0f;
\r
250 *fd-- = px | (px << 4);
\r
252 for (i = 3; i >= 0; i--) {
\r
253 int px = fds[i] & 0x0f;
\r
254 *fd-- = px | (px << 4);
\r
255 px = (fds[i] >> 4) & 0x0f;
\r
256 *fd-- = px | (px << 4);
\r
262 // load custom font and selector (stored as 1st symbol in font table)
\r
263 emu_make_path(buff, "skin/font.png", sizeof(buff));
\r
264 readpng(menu_font_data, buff, READPNG_FONT);
\r
265 // default selector symbol is '>'
\r
266 memcpy(menu_font_data, menu_font_data + ((int)'>') * me_mfont_w * me_mfont_h / 2,
\r
267 me_mfont_w * me_mfont_h / 2);
\r
268 emu_make_path(buff, "skin/selector.png", sizeof(buff));
\r
269 readpng(menu_font_data, buff, READPNG_SELECTOR);
\r
271 // load custom colors
\r
272 emu_make_path(buff, "skin/skin.txt", sizeof(buff));
\r
273 f = fopen(buff, "r");
\r
276 lprintf("found skin.txt\n");
\r
279 fgets(buff, sizeof(buff), f);
\r
280 if (buff[0] == '#' || buff[0] == '/') continue; // comment
\r
281 if (buff[0] == '\r' || buff[0] == '\n') continue; // empty line
\r
282 if (strncmp(buff, "text_color=", 11) == 0)
\r
284 int tmp = parse_hex_color(buff+11);
\r
285 if (tmp >= 0) menu_text_color = tmp;
\r
286 else lprintf("skin.txt: parse error for text_color\n");
\r
288 else if (strncmp(buff, "selection_color=", 16) == 0)
\r
290 int tmp = parse_hex_color(buff+16);
\r
291 if (tmp >= 0) menu_sel_color = tmp;
\r
292 else lprintf("skin.txt: parse error for selection_color\n");
\r
295 lprintf("skin.txt: parse error: %s\n", buff);
\r
302 static int me_id2offset(const menu_entry *ent, menu_id id)
\r
305 for (i = 0; ent->name; ent++, i++)
\r
306 if (ent->id == id) return i;
\r
308 lprintf("%s: id %i not found\n", __FUNCTION__, id);
\r
312 static void me_enable(menu_entry *entries, menu_id id, int enable)
\r
314 int i = me_id2offset(entries, id);
\r
315 entries[i].enabled = enable;
\r
318 static int me_count(const menu_entry *ent)
\r
322 for (ret = 0; ent->name; ent++, ret++)
\r
328 static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void))
\r
330 const menu_entry *ent;
\r
331 int x, y, w = 0, h = 0;
\r
332 int offs, col2_offs = 27 * me_mfont_w;
\r
337 /* calculate size of menu rect */
\r
338 for (ent = entries, i = n = 0; ent->name; ent++, i++)
\r
349 wt = strlen(ent->name) * me_mfont_w;
\r
350 if (wt == 0 && ent->generate_name)
\r
351 name = ent->generate_name(ent->id, &offs);
\r
353 wt = strlen(name) * me_mfont_w;
\r
355 if (ent->beh != MB_NONE)
\r
357 if (wt > col2_offs)
\r
358 col2_offs = wt + me_mfont_w;
\r
361 switch (ent->beh) {
\r
362 case MB_NONE: break;
\r
364 case MB_OPT_RANGE: wt += me_mfont_w * 3; break;
\r
365 case MB_OPT_CUSTOM:
\r
366 case MB_OPT_CUSTONOFF:
\r
367 case MB_OPT_CUSTRANGE:
\r
370 if (ent->generate_name != NULL)
\r
371 name = ent->generate_name(ent->id, &offs);
\r
373 wt += (strlen(name) + offs) * me_mfont_w;
\r
382 h = n * me_mfont_h;
\r
383 w += me_mfont_w * 2; /* selector */
\r
385 if (w > g_screen_width) {
\r
386 lprintf("width %d > %d\n", w, g_screen_width);
\r
387 w = g_screen_width;
\r
389 if (h > g_screen_height) {
\r
390 lprintf("height %d > %d\n", w, g_screen_height);
\r
391 h = g_screen_height;
\r
394 x = g_screen_width / 2 - w / 2;
\r
395 y = g_screen_height / 2 - h / 2;
\r
398 plat_video_menu_begin();
\r
399 menu_draw_selection(x, y + asel * me_mfont_h, w);
\r
400 x += me_mfont_w * 2;
\r
402 for (ent = entries; ent->name; ent++)
\r
408 if (strlen(name) == 0) {
\r
409 if (ent->generate_name)
\r
410 name = ent->generate_name(ent->id, &offs);
\r
413 text_out16(x, y, name);
\r
415 switch (ent->beh) {
\r
419 text_out16(x + col2_offs, y, (*(int *)ent->var & ent->mask) ? "ON" : "OFF");
\r
422 text_out16(x + col2_offs, y, "%i", *(int *)ent->var);
\r
424 case MB_OPT_CUSTOM:
\r
425 case MB_OPT_CUSTONOFF:
\r
426 case MB_OPT_CUSTRANGE:
\r
429 if (ent->generate_name)
\r
430 name = ent->generate_name(ent->id, &offs);
\r
432 text_out16(x + col2_offs + offs * me_mfont_w, y, "%s", name);
\r
439 /* display message if we have one */
\r
440 if (menu_error_msg[0] != 0) {
\r
441 if (g_screen_height - h >= 2 * me_mfont_h)
\r
442 text_out16(5, g_screen_height - me_mfont_h - 4, menu_error_msg);
\r
444 lprintf("menu msg doesn't fit!\n");
\r
446 if (plat_get_ticks_ms() - menu_error_time > 2048)
\r
447 menu_error_msg[0] = 0;
\r
450 if (draw_more != NULL)
\r
453 plat_video_menu_end();
\r
456 static int me_process(menu_entry *entry, int is_next, int is_lr)
\r
459 switch (entry->beh)
\r
462 case MB_OPT_CUSTONOFF:
\r
463 *(int *)entry->var ^= entry->mask;
\r
466 case MB_OPT_CUSTRANGE:
\r
467 c = is_lr ? 10 : 1;
\r
468 *(int *)entry->var += is_next ? c : -c;
\r
469 if (*(int *)entry->var < (int)entry->min)
\r
470 *(int *)entry->var = (int)entry->max;
\r
471 if (*(int *)entry->var > (int)entry->max)
\r
472 *(int *)entry->var = (int)entry->min;
\r
479 static void debug_menu_loop(void);
\r
481 static void me_loop(menu_entry *menu, int *menu_sel, void (*draw_more)(void))
\r
483 int ret, inp, sel = *menu_sel, menu_sel_max;
\r
485 menu_sel_max = me_count(menu) - 1;
\r
486 if (menu_sel_max < 0) {
\r
487 lprintf("no enabled menu entries\n");
\r
491 while ((!menu[sel].enabled || !menu[sel].selectable) && sel < menu_sel_max)
\r
494 /* make sure action buttons are not pressed on entering menu */
\r
495 me_draw(menu, sel, NULL);
\r
496 while (in_menu_wait_any(50) & (PBTN_MOK|PBTN_MBACK|PBTN_MENU));
\r
500 me_draw(menu, sel, draw_more);
\r
501 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|
\r
502 PBTN_MOK|PBTN_MBACK|PBTN_MENU|PBTN_L|PBTN_R, 70);
\r
503 if (inp & (PBTN_MENU|PBTN_MBACK))
\r
506 if (inp & PBTN_UP ) {
\r
510 sel = menu_sel_max;
\r
512 while (!menu[sel].enabled || !menu[sel].selectable);
\r
514 if (inp & PBTN_DOWN) {
\r
517 if (sel > menu_sel_max)
\r
520 while (!menu[sel].enabled || !menu[sel].selectable);
\r
523 /* a bit hacky but oh well */
\r
524 if ((inp & (PBTN_L|PBTN_R)) == (PBTN_L|PBTN_R))
\r
527 if (inp & (PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R)) { /* multi choice */
\r
528 if (me_process(&menu[sel], (inp & (PBTN_RIGHT|PBTN_R)) ? 1 : 0,
\r
529 inp & (PBTN_L|PBTN_R)))
\r
533 if (inp & (PBTN_MOK|PBTN_LEFT|PBTN_RIGHT))
\r
535 if (menu[sel].handler != NULL) {
\r
536 ret = menu[sel].handler(menu[sel].id, inp);
\r
538 menu_sel_max = me_count(menu) - 1; /* might change */
\r
545 /* ***************************************** */
\r
547 /* platform specific options and handlers */
\r
548 #include "../gp2x/menu.c"
\r
550 static void draw_menu_credits(void)
\r
552 const char *creds, *p;
\r
553 int x, y, h, w, wt;
\r
555 p = creds = plat_get_credits();
\r
557 for (h = 1, w = 0; *p != 0; h++) {
\r
558 for (wt = 0; *p != 0 && *p != '\n'; p++)
\r
568 x = g_screen_width / 2 - w * me_mfont_w / 2;
\r
569 y = g_screen_height / 2 - h * me_mfont_h / 2;
\r
573 plat_video_menu_begin();
\r
575 for (p = creds; *p != 0 && y <= g_screen_height - me_mfont_h; y += me_mfont_h) {
\r
576 text_out16(x, y, p);
\r
578 for (; *p != 0 && *p != '\n'; p++)
\r
584 plat_video_menu_end();
\r
587 // --------- loading ROM screen ----------
\r
589 static int cdload_called = 0;
\r
591 static void load_progress_cb(int percent)
\r
593 int ln, len = percent * g_screen_width / 100;
\r
594 unsigned short *dst = (unsigned short *)g_screen_ptr + g_screen_width * 10 * 2;
\r
596 if (len > g_screen_width)
\r
597 len = g_screen_width;
\r
598 for (ln = 10 - 2; ln > 0; ln--, dst += g_screen_width)
\r
599 memset(dst, 0xff, len * 2);
\r
600 plat_video_menu_end();
\r
603 static void cdload_progress_cb(const char *fname, int percent)
\r
605 int ln, len = percent * g_screen_width / 100;
\r
606 unsigned short *dst = (unsigned short *)g_screen_ptr + g_screen_width * 10 * 2;
\r
608 memset(dst, 0xff, g_screen_width * (me_sfont_h - 2) * 2);
\r
610 smalltext_out16(1, 3 * me_sfont_h, "Processing CD image / MP3s", 0xffff);
\r
611 smalltext_out16(1, 4 * me_sfont_h, fname, 0xffff);
\r
612 dst += g_screen_width * me_sfont_h * 3;
\r
614 if (len > g_screen_width)
\r
615 len = g_screen_width;
\r
616 for (ln = (me_sfont_h - 2); ln > 0; ln--, dst += g_screen_width)
\r
617 memset(dst, 0xff, len * 2);
\r
619 plat_video_menu_end();
\r
623 void menu_romload_prepare(const char *rom_name)
\r
625 const char *p = rom_name + strlen(rom_name);
\r
627 while (p > rom_name && *p != '/')
\r
630 /* fill both buffers, callbacks won't update in full */
\r
631 plat_video_menu_begin();
\r
632 smalltext_out16(1, 1, "Loading", 0xffff);
\r
633 smalltext_out16(1, me_sfont_h, p, 0xffff);
\r
634 plat_video_menu_end();
\r
636 plat_video_menu_begin();
\r
637 smalltext_out16(1, 1, "Loading", 0xffff);
\r
638 smalltext_out16(1, me_sfont_h, p, 0xffff);
\r
639 plat_video_menu_end();
\r
641 PicoCartLoadProgressCB = load_progress_cb;
\r
642 PicoCDLoadProgressCB = cdload_progress_cb;
\r
646 void menu_romload_end(void)
\r
648 PicoCartLoadProgressCB = NULL;
\r
649 PicoCDLoadProgressCB = NULL;
\r
650 smalltext_out16(1, (cdload_called ? 6 : 3) * me_sfont_h,
\r
651 "Starting emulation...", 0xffff);
\r
652 plat_video_menu_end();
\r
655 // -------------- del confirm ---------------
\r
657 static void do_delete(const char *fpath, const char *fname)
\r
663 plat_video_menu_begin();
\r
666 menu_darken_bg(g_screen_ptr, g_screen_width * g_screen_height, 0);
\r
668 len = strlen(fname);
\r
669 if (len > g_screen_width/6)
\r
670 len = g_screen_width/6;
\r
672 mid = g_screen_width / 2;
\r
673 text_out16(mid - me_mfont_w * 15 / 2, 8 * me_mfont_h, "About to delete");
\r
674 smalltext_out16(mid - len * me_sfont_w / 2, 9 * me_mfont_h + 5, fname, 0xbdff);
\r
675 text_out16(mid - me_mfont_w * 13 / 2, 11 * me_mfont_h, "Are you sure?");
\r
677 nm = in_get_key_name(-1, -PBTN_MA3);
\r
678 snprintf(tmp, sizeof(tmp), "(%s - confirm, ", nm);
\r
680 nm = in_get_key_name(-1, -PBTN_MBACK);
\r
681 snprintf(tmp + len, sizeof(tmp) - len, "%s - cancel)", nm);
\r
684 text_out16(mid - me_mfont_w * len / 2, 12 * me_mfont_h, tmp);
\r
685 plat_video_menu_end();
\r
687 while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MA2));
\r
688 inp = in_menu_wait(PBTN_MA3|PBTN_MBACK, 100);
\r
689 if (inp & PBTN_MA3)
\r
693 // -------------- ROM selector --------------
\r
695 // rrrr rggg gggb bbbb
\r
696 static unsigned short file2color(const char *fname)
\r
698 const char *ext = fname + strlen(fname) - 3;
\r
699 static const char *rom_exts[] = { "zip", "bin", "smd", "gen", "iso", "cso", "cue" };
\r
700 static const char *other_exts[] = { "gmv", "pat" };
\r
703 if (ext < fname) ext = fname;
\r
704 for (i = 0; i < array_size(rom_exts); i++)
\r
705 if (strcasecmp(ext, rom_exts[i]) == 0) return 0xbdff; // FIXME: mk defines
\r
706 for (i = 0; i < array_size(other_exts); i++)
\r
707 if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5;
\r
711 static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)
\r
713 int max_cnt, start, i, x, pos;
\r
715 max_cnt = g_screen_height / me_sfont_h;
\r
716 start = max_cnt / 2 - sel;
\r
717 n--; // exclude current dir (".")
\r
719 plat_video_menu_begin();
\r
721 // if (!rom_loaded)
\r
722 // menu_darken_bg(gp2x_screen, 320*240, 0);
\r
724 menu_darken_bg((short *)g_screen_ptr + g_screen_width * max_cnt/2 * 10, g_screen_width * 8, 0);
\r
726 x = 5 + me_mfont_w + 1;
\r
727 if (start - 2 >= 0)
\r
728 smalltext_out16(14, (start - 2) * me_sfont_h, curdir, 0xffff);
\r
729 for (i = 0; i < n; i++) {
\r
731 if (pos < 0) continue;
\r
732 if (pos >= max_cnt) break;
\r
733 if (namelist[i+1]->d_type == DT_DIR) {
\r
734 smalltext_out16(x, pos * me_sfont_h, "/", 0xfff6);
\r
735 smalltext_out16(x + me_sfont_w, pos * me_sfont_h, namelist[i+1]->d_name, 0xfff6);
\r
737 unsigned short color = file2color(namelist[i+1]->d_name);
\r
738 smalltext_out16(x, pos * me_sfont_h, namelist[i+1]->d_name, color);
\r
741 smalltext_out16(5, max_cnt/2 * me_sfont_h, ">", 0xffff);
\r
742 plat_video_menu_end();
\r
745 static int scandir_cmp(const void *p1, const void *p2)
\r
747 struct dirent **d1 = (struct dirent **)p1, **d2 = (struct dirent **)p2;
\r
748 if ((*d1)->d_type == (*d2)->d_type) return alphasort(d1, d2);
\r
749 if ((*d1)->d_type == DT_DIR) return -1; // put before
\r
750 if ((*d2)->d_type == DT_DIR) return 1;
\r
751 return alphasort(d1, d2);
\r
754 static const char *filter_exts[] = {
\r
755 ".mp3", ".MP3", ".srm", ".brm", "s.gz", ".mds", "bcfg", ".txt", ".htm", "html",
\r
759 static int scandir_filter(const struct dirent *ent)
\r
764 if (ent == NULL || ent->d_name == NULL) return 0;
\r
765 if (strlen(ent->d_name) < 5) return 1;
\r
767 p = ent->d_name + strlen(ent->d_name) - 4;
\r
769 for (i = 0; i < array_size(filter_exts); i++)
\r
770 if (strcmp(p, filter_exts[i]) == 0)
\r
776 static char *menu_loop_romsel(char *curr_path, int len)
\r
778 struct dirent **namelist;
\r
779 int n, inp, sel = 0;
\r
780 char *ret = NULL, *fname = NULL;
\r
783 // is this a dir or a full path?
\r
784 if (!plat_is_dir(curr_path)) {
\r
785 char *p = curr_path + strlen(curr_path) - 1;
\r
786 for (; p > curr_path && *p != '/'; p--)
\r
792 n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp);
\r
794 lprintf("menu_loop_romsel failed, dir: %s\n", curr_path);
\r
797 getcwd(curr_path, len);
\r
798 n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp);
\r
801 lprintf("menu_loop_romsel failed, dir: %s\n", curr_path);
\r
807 if (fname != NULL) {
\r
809 for (i = 1; i < n; i++) {
\r
810 if (strcmp(namelist[i]->d_name, fname) == 0) {
\r
819 draw_dirlist(curr_path, namelist, n, sel);
\r
820 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|
\r
821 PBTN_L|PBTN_R|PBTN_MA2|PBTN_MOK|PBTN_MBACK|PBTN_MENU, 33);
\r
822 if (inp & PBTN_UP ) { sel--; if (sel < 0) sel = n-2; }
\r
823 if (inp & PBTN_DOWN) { sel++; if (sel > n-2) sel = 0; }
\r
824 if (inp & PBTN_LEFT) { sel-=10; if (sel < 0) sel = 0; }
\r
825 if (inp & PBTN_L) { sel-=24; if (sel < 0) sel = 0; }
\r
826 if (inp & PBTN_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }
\r
827 if (inp & PBTN_R) { sel+=24; if (sel > n-2) sel = n-2; }
\r
828 if ((inp & PBTN_MOK) || (inp & (PBTN_MENU|PBTN_MA2)) == (PBTN_MENU|PBTN_MA2))
\r
831 if (namelist[sel+1]->d_type == DT_REG)
\r
833 strcpy(rom_fname_reload, curr_path);
\r
834 strcat(rom_fname_reload, "/");
\r
835 strcat(rom_fname_reload, namelist[sel+1]->d_name);
\r
836 if (inp & PBTN_MOK) { // return sel
\r
837 ret = rom_fname_reload;
\r
840 do_delete(rom_fname_reload, namelist[sel+1]->d_name);
\r
842 while (n--) free(namelist[n]);
\r
847 else if (namelist[sel+1]->d_type == DT_DIR)
\r
851 if (!(inp & PBTN_MOK)) continue;
\r
852 newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;
\r
853 newdir = malloc(newlen);
\r
854 if (strcmp(namelist[sel+1]->d_name, "..") == 0) {
\r
855 char *start = curr_path;
\r
856 p = start + strlen(start) - 1;
\r
857 while (*p == '/' && p > start) p--;
\r
858 while (*p != '/' && p > start) p--;
\r
859 if (p <= start) strcpy(newdir, "/");
\r
860 else { strncpy(newdir, start, p-start); newdir[p-start] = 0; }
\r
862 strcpy(newdir, curr_path);
\r
863 p = newdir + strlen(newdir) - 1;
\r
864 while (*p == '/' && p >= newdir) *p-- = 0;
\r
865 strcat(newdir, "/");
\r
866 strcat(newdir, namelist[sel+1]->d_name);
\r
868 ret = menu_loop_romsel(newdir, newlen);
\r
874 // unknown file type, happens on NTFS mounts. Try to guess.
\r
875 FILE *tstf; int tmp;
\r
876 strcpy(rom_fname_reload, curr_path);
\r
877 strcat(rom_fname_reload, "/");
\r
878 strcat(rom_fname_reload, namelist[sel+1]->d_name);
\r
879 tstf = fopen(rom_fname_reload, "rb");
\r
882 if (fread(&tmp, 1, 1, tstf) > 0 || ferror(tstf) == 0)
\r
883 namelist[sel+1]->d_type = DT_REG;
\r
884 else namelist[sel+1]->d_type = DT_DIR;
\r
890 if (inp & PBTN_MBACK)
\r
895 while (n--) free(namelist[n]);
\r
902 // ------------ patch/gg menu ------------
\r
904 static void draw_patchlist(int sel)
\r
906 int max_cnt, start, i, pos, active;
\r
908 max_cnt = g_screen_height / 10;
\r
909 start = max_cnt / 2 - sel;
\r
911 plat_video_menu_begin();
\r
913 for (i = 0; i < PicoPatchCount; i++) {
\r
915 if (pos < 0) continue;
\r
916 if (pos >= max_cnt) break;
\r
917 active = PicoPatches[i].active;
\r
918 smalltext_out16(14, pos * me_sfont_h, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff);
\r
919 smalltext_out16(14+6*4, pos * me_sfont_h, PicoPatches[i].name, active ? 0xfff6 : 0xffff);
\r
923 smalltext_out16(14, pos * me_sfont_h, "done", 0xffff);
\r
925 text_out16(5, max_cnt / 2 * me_sfont_h, ">");
\r
926 plat_video_menu_end();
\r
929 static void menu_loop_patches(void)
\r
931 static int menu_sel = 0;
\r
936 draw_patchlist(menu_sel);
\r
937 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R|PBTN_MOK|PBTN_MBACK, 33);
\r
938 if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }
\r
939 if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }
\r
940 if (inp &(PBTN_LEFT|PBTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
\r
941 if (inp &(PBTN_RIGHT|PBTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }
\r
942 if (inp & PBTN_MOK) { // action
\r
943 if (menu_sel < PicoPatchCount)
\r
944 PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;
\r
947 if (inp & PBTN_MBACK)
\r
952 // ------------ savestate loader ------------
\r
954 static int state_slot_flags = 0;
\r
956 static void state_check_slots(void)
\r
960 state_slot_flags = 0;
\r
962 for (slot = 0; slot < 10; slot++) {
\r
963 if (emu_check_save_file(slot))
\r
964 state_slot_flags |= 1 << slot;
\r
968 static void draw_savestate_bg(int slot)
\r
970 struct PicoVideo tmp_pv;
\r
971 unsigned short tmp_cram[0x40];
\r
972 unsigned short tmp_vsram[0x40];
\r
976 fname = emu_get_save_fname(1, 0, slot);
\r
977 if (!fname) return;
\r
979 tmp_vram = malloc(sizeof(Pico.vram));
\r
980 if (tmp_vram == NULL) return;
\r
982 memcpy(tmp_vram, Pico.vram, sizeof(Pico.vram));
\r
983 memcpy(tmp_cram, Pico.cram, sizeof(Pico.cram));
\r
984 memcpy(tmp_vsram, Pico.vsram, sizeof(Pico.vsram));
\r
985 memcpy(&tmp_pv, &Pico.video, sizeof(Pico.video));
\r
987 PicoStateLoadVDP(fname);
\r
989 /* do a frame and fetch menu bg */
\r
990 pemu_forced_frame(POPT_EN_SOFTSCALE);
\r
991 plat_video_menu_enter(1);
\r
993 memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram));
\r
994 memcpy(Pico.cram, tmp_cram, sizeof(Pico.cram));
\r
995 memcpy(Pico.vsram, tmp_vsram, sizeof(Pico.vsram));
\r
996 memcpy(&Pico.video, &tmp_pv, sizeof(Pico.video));
\r
1000 static void draw_savestate_menu(int menu_sel, int is_loading)
\r
1002 int i, x, y, w, h;
\r
1004 if (state_slot_flags & (1 << menu_sel))
\r
1005 draw_savestate_bg(menu_sel);
\r
1007 w = (13 + 2) * me_mfont_w;
\r
1008 h = (1+2+10+1) * me_mfont_h;
\r
1009 x = g_screen_width / 2 - w / 2;
\r
1011 y = g_screen_height / 2 - h / 2;
\r
1014 plat_video_menu_begin();
\r
1016 text_out16(x, y, is_loading ? "Load state" : "Save state");
\r
1017 y += 3 * me_mfont_h;
\r
1019 menu_draw_selection(x - me_mfont_w * 2, y + menu_sel * me_mfont_h, (13 + 2) * me_mfont_w + 4);
\r
1021 /* draw all 10 slots */
\r
1022 for (i = 0; i < 10; i++, y += me_mfont_h)
\r
1024 text_out16(x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free");
\r
1026 text_out16(x, y, "back");
\r
1028 plat_video_menu_end();
\r
1031 static int menu_loop_savestate(int is_loading)
\r
1033 static int menu_sel = 10;
\r
1034 int menu_sel_max = 10;
\r
1035 unsigned long inp = 0;
\r
1037 state_check_slots();
\r
1039 if (!(state_slot_flags & (1 << menu_sel)) && is_loading)
\r
1040 menu_sel = menu_sel_max;
\r
1044 draw_savestate_menu(menu_sel, is_loading);
\r
1045 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_MOK|PBTN_MBACK, 100);
\r
1046 if (inp & PBTN_UP) {
\r
1050 menu_sel = menu_sel_max;
\r
1051 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);
\r
1053 if (inp & PBTN_DOWN) {
\r
1056 if (menu_sel > menu_sel_max)
\r
1058 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);
\r
1060 if (inp & PBTN_MOK) { // save/load
\r
1061 if (menu_sel < 10) {
\r
1062 state_slot = menu_sel;
\r
1063 if (emu_save_load_game(is_loading, 0)) {
\r
1064 me_update_msg(is_loading ? "Load failed" : "Save failed");
\r
1071 if (inp & PBTN_MBACK)
\r
1076 // -------------- key config --------------
\r
1078 static char *action_binds(int player_idx, int action_mask, int dev_id)
\r
1080 int k, count, can_combo, type;
\r
1083 static_buff[0] = 0;
\r
1085 binds = in_get_dev_binds(dev_id);
\r
1086 if (binds == NULL)
\r
1087 return static_buff;
\r
1089 count = in_get_dev_info(dev_id, IN_INFO_BIND_COUNT);
\r
1090 can_combo = in_get_dev_info(dev_id, IN_INFO_DOES_COMBOS);
\r
1092 type = IN_BINDTYPE_EMU;
\r
1093 if (player_idx >= 0) {
\r
1095 type = IN_BINDTYPE_PLAYER12;
\r
1097 if (player_idx == 1)
\r
1098 action_mask <<= 16;
\r
1100 for (k = 0; k < count; k++)
\r
1102 const char *xname;
\r
1105 if (!(binds[IN_BIND_OFFS(k, type)] & action_mask))
\r
1108 xname = in_get_key_name(dev_id, k);
\r
1109 len = strlen(static_buff);
\r
1111 strncat(static_buff, can_combo ? " + " : ", ",
\r
1112 sizeof(static_buff) - len - 1);
\r
1113 len += can_combo ? 3 : 2;
\r
1115 strncat(static_buff, xname, sizeof(static_buff) - len - 1);
\r
1118 return static_buff;
\r
1121 static int count_bound_keys(int dev_id, int action_mask, int bindtype)
\r
1127 binds = in_get_dev_binds(dev_id);
\r
1128 if (binds == NULL)
\r
1131 count = in_get_dev_info(dev_id, IN_INFO_BIND_COUNT);
\r
1132 for (k = 0; k < count; k++)
\r
1134 if (binds[IN_BIND_OFFS(k, bindtype)] & action_mask)
\r
1141 static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_idx,
\r
1142 int sel, int dev_id, int dev_count, int is_bind)
\r
1144 char buff[64], buff2[32];
\r
1145 const char *dev_name;
\r
1148 w = ((player_idx >= 0) ? 20 : 30) * me_mfont_w;
\r
1149 x = g_screen_width / 2 - w / 2;
\r
1150 y = (g_screen_height - 4 * me_mfont_h) / 2 - (2 + opt_cnt) * me_mfont_h / 2;
\r
1151 if (x < me_mfont_w * 2)
\r
1152 x = me_mfont_w * 2;
\r
1154 plat_video_menu_begin();
\r
1155 if (player_idx >= 0)
\r
1156 text_out16(x, y, "Player %i controls", player_idx + 1);
\r
1158 text_out16(x, y, "Emulator controls");
\r
1160 y += 2 * me_mfont_h;
\r
1161 menu_draw_selection(x - me_mfont_w * 2, y + sel * me_mfont_h, w + 2 * me_mfont_w);
\r
1163 for (i = 0; i < opt_cnt; i++, y += me_mfont_h)
\r
1164 text_out16(x, y, "%s : %s", opts[i].name,
\r
1165 action_binds(player_idx, opts[i].mask, dev_id));
\r
1167 dev_name = in_get_dev_name(dev_id, 1, 1);
\r
1168 w = strlen(dev_name) * me_mfont_w;
\r
1169 if (w < 30 * me_mfont_w)
\r
1170 w = 30 * me_mfont_w;
\r
1171 if (w > g_screen_width)
\r
1172 w = g_screen_width;
\r
1174 x = g_screen_width / 2 - w / 2;
\r
1177 snprintf(buff2, sizeof(buff2), "%s", in_get_key_name(-1, -PBTN_MOK));
\r
1178 snprintf(buff, sizeof(buff), "%s - bind, %s - clear", buff2,
\r
1179 in_get_key_name(-1, -PBTN_MA2));
\r
1180 text_out16(x, g_screen_height - 4 * me_mfont_h, buff);
\r
1183 text_out16(x, g_screen_height - 4 * me_mfont_h, "Press a button to bind/unbind");
\r
1185 if (dev_count > 1) {
\r
1186 text_out16(x, g_screen_height - 3 * me_mfont_h, dev_name);
\r
1187 text_out16(x, g_screen_height - 2 * me_mfont_h, "Press left/right for other devs");
\r
1190 plat_video_menu_end();
\r
1193 static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_idx)
\r
1195 int i, sel = 0, menu_sel_max = opt_cnt - 1;
\r
1196 int dev_id, dev_count, kc, is_down, mkey;
\r
1197 int unbind, bindtype, mask_shift;
\r
1199 for (i = 0, dev_id = -1, dev_count = 0; i < IN_MAX_DEVS; i++) {
\r
1200 if (in_get_dev_name(i, 1, 0) != NULL) {
\r
1207 if (dev_id == -1) {
\r
1208 lprintf("no devs, can't do config\n");
\r
1213 if (player_idx == 1)
\r
1215 bindtype = player_idx >= 0 ? IN_BINDTYPE_PLAYER12 : IN_BINDTYPE_EMU;
\r
1219 draw_key_config(opts, opt_cnt, player_idx, sel, dev_id, dev_count, 0);
\r
1220 mkey = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_MBACK|PBTN_MOK|PBTN_MA2, 100);
\r
1222 case PBTN_UP: sel--; if (sel < 0) sel = menu_sel_max; continue;
\r
1223 case PBTN_DOWN: sel++; if (sel > menu_sel_max) sel = 0; continue;
\r
1225 for (i = 0, dev_id--; i < IN_MAX_DEVS; i++, dev_id--) {
\r
1227 dev_id = IN_MAX_DEVS - 1;
\r
1228 if (in_get_dev_name(dev_id, 1, 0) != NULL)
\r
1233 for (i = 0, dev_id++; i < IN_MAX_DEVS; i++, dev_id++) {
\r
1234 if (dev_id >= IN_MAX_DEVS)
\r
1236 if (in_get_dev_name(dev_id, 1, 0) != NULL)
\r
1240 case PBTN_MBACK: return;
\r
1242 if (sel >= opt_cnt)
\r
1244 while (in_menu_wait_any(30) & PBTN_MOK);
\r
1247 in_unbind_all(dev_id, opts[sel].mask << mask_shift, bindtype);
\r
1252 draw_key_config(opts, opt_cnt, player_idx, sel, dev_id, dev_count, 1);
\r
1254 /* wait for some up event */
\r
1255 for (is_down = 1; is_down; )
\r
1256 kc = in_update_keycode(&dev_id, &is_down, -1);
\r
1258 i = count_bound_keys(dev_id, opts[sel].mask << mask_shift, bindtype);
\r
1261 /* allow combos if device supports them */
\r
1262 if (i == 1 && bindtype == IN_BINDTYPE_EMU &&
\r
1263 in_get_dev_info(dev_id, IN_INFO_DOES_COMBOS))
\r
1266 in_bind_key(dev_id, kc, opts[sel].mask << mask_shift, bindtype, unbind);
\r
1270 // PicoPad[] format: MXYZ SACB RLDU
\r
1271 me_bind_action me_ctrl_actions[15] =
\r
1273 { "UP ", 0x0001 },
\r
1274 { "DOWN ", 0x0002 },
\r
1275 { "LEFT ", 0x0004 },
\r
1276 { "RIGHT ", 0x0008 },
\r
1280 { "A turbo", 0x4000 },
\r
1281 { "B turbo", 0x1000 },
\r
1282 { "C turbo", 0x2000 },
\r
1283 { "START ", 0x0080 },
\r
1284 { "MODE ", 0x0800 },
\r
1290 me_bind_action emuctrl_actions[] =
\r
1292 { "Load State ", PEV_STATE_LOAD },
\r
1293 { "Save State ", PEV_STATE_SAVE },
\r
1294 { "Prev Save Slot ", PEV_SSLOT_PREV },
\r
1295 { "Next Save Slot ", PEV_SSLOT_NEXT },
\r
1296 { "Switch Renderer ", PEV_SWITCH_RND },
\r
1297 { "Volume Down ", PEV_VOL_DOWN },
\r
1298 { "Volume Up ", PEV_VOL_UP },
\r
1299 { "Fast forward ", PEV_FF },
\r
1300 { "Enter Menu ", PEV_MENU },
\r
1301 { "Pico Next page ", PEV_PICO_PNEXT },
\r
1302 { "Pico Prev page ", PEV_PICO_PPREV },
\r
1303 { "Pico Switch input", PEV_PICO_SWINP },
\r
1307 static int key_config_loop_wrap(menu_id id, int keys)
\r
1310 case MA_CTRL_PLAYER1:
\r
1311 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions), 0);
\r
1313 case MA_CTRL_PLAYER2:
\r
1314 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions), 1);
\r
1317 key_config_loop(emuctrl_actions, array_size(emuctrl_actions) - 1, -1);
\r
1325 static const char *mgn_dev_name(menu_id id, int *offs)
\r
1327 const char *name = NULL;
\r
1328 static int it = 0;
\r
1330 if (id == MA_CTRL_DEV_FIRST)
\r
1333 for (; it < IN_MAX_DEVS; it++) {
\r
1334 name = in_get_dev_name(it, 1, 1);
\r
1343 static int mh_saveloadcfg(menu_id id, int keys);
\r
1344 static const char *mgn_savecfg(menu_id id, int *offs);
\r
1346 static menu_entry e_menu_keyconfig[] =
\r
1348 mee_handler_id("Player 1", MA_CTRL_PLAYER1, key_config_loop_wrap),
\r
1349 mee_handler_id("Player 2", MA_CTRL_PLAYER2, key_config_loop_wrap),
\r
1350 mee_handler_id("Emulator controls", MA_CTRL_EMU, key_config_loop_wrap),
\r
1351 mee_onoff ("6 button pad", MA_OPT_6BUTTON_PAD, PicoOpt, POPT_6BTN_PAD),
\r
1352 mee_range ("Turbo rate", MA_CTRL_TURBO_RATE, currentConfig.turbo_rate, 1, 30),
\r
1353 mee_handler_mkname_id(MA_OPT_SAVECFG, mh_saveloadcfg, mgn_savecfg),
\r
1354 mee_handler_id("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_saveloadcfg),
\r
1356 mee_label ("Input devices:"),
\r
1357 mee_label_mk (MA_CTRL_DEV_FIRST, mgn_dev_name),
\r
1358 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
\r
1359 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
\r
1360 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
\r
1361 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
\r
1362 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
\r
1363 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
\r
1367 static int menu_loop_keyconfig(menu_id id, int keys)
\r
1369 static int sel = 0;
\r
1371 me_enable(e_menu_keyconfig, MA_OPT_SAVECFG_GAME, rom_loaded);
\r
1372 me_loop(e_menu_keyconfig, &sel, NULL);
\r
1376 // ------------ SCD options menu ------------
\r
1378 static const char *mgn_cdopt_ra(menu_id id, int *offs)
\r
1381 if (PicoCDBuffers <= 0)
\r
1383 sprintf(static_buff, "%5iK", PicoCDBuffers * 2);
\r
1384 return static_buff;
\r
1387 static int mh_cdopt_ra(menu_id id, int keys)
\r
1389 if (keys & PBTN_LEFT) {
\r
1390 PicoCDBuffers >>= 1;
\r
1391 if (PicoCDBuffers < 2)
\r
1392 PicoCDBuffers = 0;
\r
1394 if (PicoCDBuffers <= 0)
\r
1395 PicoCDBuffers = 1;
\r
1396 PicoCDBuffers <<= 1;
\r
1397 if (PicoCDBuffers > 8*1024)
\r
1398 PicoCDBuffers = 8*1024; // 16M
\r
1403 static menu_entry e_menu_cd_options[] =
\r
1405 mee_onoff("CD LEDs", MA_CDOPT_LEDS, currentConfig.EmuOpt, EOPT_EN_CD_LEDS),
\r
1406 mee_onoff("CDDA audio", MA_CDOPT_CDDA, PicoOpt, POPT_EN_MCD_CDDA),
\r
1407 mee_onoff("PCM audio", MA_CDOPT_PCM, PicoOpt, POPT_EN_MCD_PCM),
\r
1408 mee_cust ("ReadAhead buffer", MA_CDOPT_READAHEAD, mh_cdopt_ra, mgn_cdopt_ra),
\r
1409 mee_onoff("SaveRAM cart", MA_CDOPT_SAVERAM, PicoOpt, POPT_EN_MCD_RAMCART),
\r
1410 mee_onoff("Scale/Rot. fx (slow)", MA_CDOPT_SCALEROT_CHIP, PicoOpt, POPT_EN_MCD_GFX),
\r
1411 mee_onoff("Better sync (slow)", MA_CDOPT_BETTER_SYNC, PicoOpt, POPT_EN_MCD_PSYNC),
\r
1415 static int menu_loop_cd_options(menu_id id, int keys)
\r
1417 static int sel = 0;
\r
1418 me_loop(e_menu_cd_options, &sel, NULL);
\r
1422 // ------------ adv options menu ------------
\r
1424 static menu_entry e_menu_adv_options[] =
\r
1426 mee_onoff ("SRAM/BRAM saves", MA_OPT_SRAM_STATES, currentConfig.EmuOpt, EOPT_EN_SRAM),
\r
1427 mee_onoff ("Disable sprite limit", MA_OPT2_NO_SPRITE_LIM, PicoOpt, POPT_DIS_SPRITE_LIM),
\r
1428 mee_onoff ("Emulate Z80", MA_OPT2_ENABLE_Z80, PicoOpt, POPT_EN_Z80),
\r
1429 mee_onoff ("Emulate YM2612 (FM)", MA_OPT2_ENABLE_YM2612, PicoOpt, POPT_EN_FM),
\r
1430 mee_onoff ("Emulate SN76496 (PSG)", MA_OPT2_ENABLE_SN76496,PicoOpt, POPT_EN_PSG),
\r
1431 mee_onoff ("gzip savestates", MA_OPT2_GZIP_STATES, currentConfig.EmuOpt, EOPT_GZIP_SAVES),
\r
1432 mee_onoff ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM, currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG),
\r
1433 mee_onoff ("Disable idle loop patching",MA_OPT2_NO_IDLE_LOOPS,PicoOpt, POPT_DIS_IDLE_DET),
\r
1434 mee_onoff ("Disable frame limiter", MA_OPT2_NO_FRAME_LIMIT,currentConfig.EmuOpt, EOPT_NO_FRMLIMIT),
\r
1435 MENU_GP2X_OPTIONS_ADV
\r
1439 static int menu_loop_adv_options(menu_id id, int keys)
\r
1441 static int sel = 0;
\r
1442 me_loop(e_menu_adv_options, &sel, NULL);
\r
1446 // ------------ gfx options menu ------------
\r
1448 static int mh_opt_render(menu_id id, int keys)
\r
1450 plat_video_toggle_renderer((keys & PBTN_RIGHT) ? 1 : 0, 1);
\r
1454 static menu_entry e_menu_gfx_options[] =
\r
1456 mee_cust ("Renderer", MA_OPT_RENDERER, mh_opt_render, mgn_opt_renderer),
\r
1457 MENU_GP2X_OPTIONS_GFX
\r
1461 static int menu_loop_gfx_options(menu_id id, int keys)
\r
1463 static int sel = 0;
\r
1464 me_loop(e_menu_gfx_options, &sel, NULL);
\r
1468 // ------------ options menu ------------
\r
1470 static menu_entry e_menu_options[];
\r
1472 static int sndrate_prevnext(int rate, int dir)
\r
1474 static const int rates[] = { 8000, 11025, 16000, 22050, 44100 };
\r
1477 for (i = 0; i < 5; i++)
\r
1478 if (rates[i] == rate) break;
\r
1480 i += dir ? 1 : -1;
\r
1482 if (!(PicoOpt & POPT_EN_STEREO)) {
\r
1483 PicoOpt |= POPT_EN_STEREO;
\r
1489 if (PicoOpt & POPT_EN_STEREO) {
\r
1490 PicoOpt &= ~POPT_EN_STEREO;
\r
1498 static void region_prevnext(int right)
\r
1500 // jp_ntsc=1, jp_pal=2, usa=4, eu=8
\r
1501 static const int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };
\r
1505 if (!PicoRegionOverride) {
\r
1506 for (i = 0; i < 6; i++)
\r
1507 if (rgn_orders[i] == PicoAutoRgnOrder) break;
\r
1508 if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];
\r
1509 else PicoRegionOverride=1;
\r
1512 PicoRegionOverride <<= 1;
\r
1513 if (PicoRegionOverride > 8)
\r
1514 PicoRegionOverride = 8;
\r
1516 if (!PicoRegionOverride) {
\r
1517 for (i = 0; i < 6; i++)
\r
1518 if (rgn_orders[i] == PicoAutoRgnOrder) break;
\r
1519 if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];
\r
1522 PicoRegionOverride >>= 1;
\r
1526 static int mh_opt_misc(menu_id id, int keys)
\r
1531 case MA_OPT_SOUND_QUALITY:
\r
1532 PsndRate = sndrate_prevnext(PsndRate, keys & PBTN_RIGHT);
\r
1534 case MA_OPT_REGION:
\r
1535 region_prevnext(keys & PBTN_RIGHT);
\r
1537 case MA_OPT_CONFIRM_STATES:
\r
1538 i = ((currentConfig.EmuOpt>>9)&1) | ((currentConfig.EmuOpt>>10)&2);
\r
1539 i += (keys & PBTN_LEFT) ? -1 : 1;
\r
1540 if (i < 0) i = 0; else if (i > 3) i = 3;
\r
1541 i |= i << 1; i &= ~2;
\r
1542 currentConfig.EmuOpt &= ~0xa00;
\r
1543 currentConfig.EmuOpt |= i << 9;
\r
1551 static int mh_saveloadcfg(menu_id id, int keys)
\r
1555 if (keys & (PBTN_LEFT|PBTN_RIGHT)) { // multi choice
\r
1556 config_slot += (keys & PBTN_LEFT) ? -1 : 1;
\r
1557 if (config_slot < 0) config_slot = 9;
\r
1558 else if (config_slot > 9) config_slot = 0;
\r
1559 me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
\r
1564 case MA_OPT_SAVECFG:
\r
1565 case MA_OPT_SAVECFG_GAME:
\r
1566 if (emu_write_config(id == MA_OPT_SAVECFG_GAME ? 1 : 0))
\r
1567 me_update_msg("config saved");
\r
1569 me_update_msg("failed to write config");
\r
1571 case MA_OPT_LOADCFG:
\r
1572 ret = emu_read_config(1, 1);
\r
1573 if (!ret) ret = emu_read_config(0, 1);
\r
1574 if (ret) me_update_msg("config loaded");
\r
1575 else me_update_msg("failed to load config");
\r
1584 static int mh_restore_defaults(menu_id id, int keys)
\r
1586 emu_set_defconfig();
\r
1587 me_update_msg("defaults restored");
\r
1591 static const char *mgn_opt_fskip(menu_id id, int *offs)
\r
1593 if (currentConfig.Frameskip < 0)
\r
1595 sprintf(static_buff, "%d", currentConfig.Frameskip);
\r
1596 return static_buff;
\r
1599 static const char *mgn_opt_sound(menu_id id, int *offs)
\r
1603 str2 = (PicoOpt & POPT_EN_STEREO) ? "stereo" : "mono";
\r
1604 sprintf(static_buff, "%5iHz %s", PsndRate, str2);
\r
1605 return static_buff;
\r
1608 static const char *mgn_opt_region(menu_id id, int *offs)
\r
1610 static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };
\r
1611 static const char *names_short[] = { "", " JP", " JP", " US", " EU" };
\r
1612 int code = PicoRegionOverride;
\r
1618 while ((code >>= 1)) i++;
\r
1623 strcpy(static_buff, "Auto:");
\r
1624 for (u = 0; u < 3; u++) {
\r
1625 code = (PicoAutoRgnOrder >> u*4) & 0xf;
\r
1626 for (i = 0; code; code >>= 1, i++)
\r
1628 strcat(static_buff, names_short[i]);
\r
1630 return static_buff;
\r
1634 static const char *mgn_opt_c_saves(menu_id id, int *offs)
\r
1636 switch ((currentConfig.EmuOpt >> 9) & 5) {
\r
1637 default: return "OFF";
\r
1638 case 1: return "writes";
\r
1639 case 4: return "loads";
\r
1640 case 5: return "both";
\r
1644 static const char *mgn_savecfg(menu_id id, int *offs)
\r
1646 strcpy(static_buff, "Save global config");
\r
1647 if (config_slot != 0)
\r
1648 sprintf(static_buff + strlen(static_buff), " (profile: %i)", config_slot);
\r
1649 return static_buff;
\r
1652 static const char *mgn_loadcfg(menu_id id, int *offs)
\r
1654 sprintf(static_buff, "Load cfg from profile %i", config_slot);
\r
1655 return static_buff;
\r
1658 static menu_entry e_menu_options[] =
\r
1660 mee_range ("Save slot", MA_OPT_SAVE_SLOT, state_slot, 0, 9),
\r
1661 mee_range_cust("Frameskip", MA_OPT_FRAMESKIP, currentConfig.Frameskip, -1, 16, mgn_opt_fskip),
\r
1662 mee_cust ("Region", MA_OPT_REGION, mh_opt_misc, mgn_opt_region),
\r
1663 mee_onoff ("Show FPS", MA_OPT_SHOW_FPS, currentConfig.EmuOpt, EOPT_SHOW_FPS),
\r
1664 mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, EOPT_EN_SOUND),
\r
1665 mee_cust ("Sound Quality", MA_OPT_SOUND_QUALITY, mh_opt_misc, mgn_opt_sound),
\r
1666 mee_cust ("Confirm savestate", MA_OPT_CONFIRM_STATES,mh_opt_misc, mgn_opt_c_saves),
\r
1667 mee_range (cpu_clk_name, MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 900),
\r
1668 mee_handler ("[Display options]", menu_loop_gfx_options),
\r
1669 mee_handler ("[Sega/Mega CD options]", menu_loop_cd_options),
\r
1670 mee_handler ("[Advanced options]", menu_loop_adv_options),
\r
1671 mee_handler_mkname_id(MA_OPT_SAVECFG, mh_saveloadcfg, mgn_savecfg),
\r
1672 mee_handler_id("Save cfg for current game only", MA_OPT_SAVECFG_GAME, mh_saveloadcfg),
\r
1673 mee_handler_mkname_id(MA_OPT_LOADCFG, mh_saveloadcfg, mgn_loadcfg),
\r
1674 mee_handler ("Restore defaults", mh_restore_defaults),
\r
1678 static int menu_loop_options(menu_id id, int keys)
\r
1680 static int sel = 0;
\r
1682 me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, rom_loaded);
\r
1683 me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
\r
1685 me_loop(e_menu_options, &sel, NULL);
\r
1687 if (PicoRegionOverride)
\r
1688 // force setting possibly changed..
\r
1689 Pico.m.pal = (PicoRegionOverride == 2 || PicoRegionOverride == 8) ? 1 : 0;
\r
1694 // ------------ debug menu ------------
\r
1696 #include <pico/debug.h>
\r
1698 extern void SekStepM68k(void);
\r
1700 static void mplayer_loop(void)
\r
1702 pemu_sound_start();
\r
1707 if (in_menu_wait_any(0) & PBTN_MA3)
\r
1709 pemu_sound_wait();
\r
1712 pemu_sound_stop();
\r
1715 static void draw_text_debug(const char *str, int skip, int from)
\r
1721 while (skip-- > 0)
\r
1723 while (*p && *p != '\n')
\r
1725 if (*p == 0 || p[1] == 0)
\r
1731 for (line = from; line < g_screen_height / me_sfont_h; line++)
\r
1733 smalltext_out16(1, line * me_sfont_h, str, 0xffff);
\r
1734 while (*p && *p != '\n')
\r
1743 #define COMPILER "gcc " __VERSION__
\r
1748 static void draw_frame_debug(void)
\r
1750 char layer_str[48] = "layers: ";
\r
1751 if (PicoDrawMask & PDRAW_LAYERB_ON) memcpy(layer_str + 8, "B", 1);
\r
1752 if (PicoDrawMask & PDRAW_LAYERA_ON) memcpy(layer_str + 10, "A", 1);
\r
1753 if (PicoDrawMask & PDRAW_SPRITES_LOW_ON) memcpy(layer_str + 12, "spr_lo", 6);
\r
1754 if (PicoDrawMask & PDRAW_SPRITES_HI_ON) memcpy(layer_str + 19, "spr_hi", 6);
\r
1756 memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2);
\r
1757 pemu_forced_frame(0);
\r
1758 smalltext_out16(4, 1, "build: r" REVISION " "__DATE__ " " __TIME__ " " COMPILER, 0xffff);
\r
1759 smalltext_out16(4, g_screen_height - me_sfont_h, layer_str, 0xffff);
\r
1762 static void debug_menu_loop(void)
\r
1764 int inp, mode = 0;
\r
1765 int spr_offs = 0, dumped = 0;
\r
1772 case 0: plat_video_menu_begin();
\r
1773 tmp = PDebugMain();
\r
1774 plat_debug_cat(tmp);
\r
1775 draw_text_debug(tmp, 0, 0);
\r
1777 smalltext_out16(g_screen_width - 6 * me_sfont_h,
\r
1778 g_screen_height - me_mfont_h, "dumped", 0xffff);
\r
1782 case 1: draw_frame_debug(); break;
\r
1783 case 2: memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2);
\r
1784 pemu_forced_frame(0);
\r
1785 menu_darken_bg(g_screen_ptr, g_screen_width * g_screen_height, 0);
\r
1786 PDebugShowSpriteStats((unsigned short *)g_screen_ptr + (g_screen_height/2 - 240/2)*g_screen_width +
\r
1787 g_screen_width/2 - 320/2, g_screen_width); break;
\r
1788 case 3: memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2);
\r
1789 PDebugShowPalette(g_screen_ptr, g_screen_width);
\r
1790 PDebugShowSprite((unsigned short *)g_screen_ptr + g_screen_width*120 + g_screen_width/2 + 16,
\r
1791 g_screen_width, spr_offs);
\r
1792 draw_text_debug(PDebugSpriteList(), spr_offs, 6);
\r
1795 plat_video_menu_end();
\r
1797 inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R |
\r
1798 PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, 70);
\r
1799 if (inp & PBTN_MBACK) return;
\r
1800 if (inp & PBTN_L) { mode--; if (mode < 0) mode = 3; }
\r
1801 if (inp & PBTN_R) { mode++; if (mode > 3) mode = 0; }
\r
1805 if (inp & PBTN_MOK)
\r
1807 if (inp & PBTN_MA3) {
\r
1808 while (inp & PBTN_MA3)
\r
1809 inp = in_menu_wait_any(-1);
\r
1812 if ((inp & (PBTN_MA2|PBTN_LEFT)) == (PBTN_MA2|PBTN_LEFT)) {
\r
1813 mkdir("dumps", 0777);
\r
1815 while (inp & PBTN_MA2) inp = in_menu_wait_any(-1);
\r
1820 if (inp & PBTN_LEFT) PicoDrawMask ^= PDRAW_LAYERB_ON;
\r
1821 if (inp & PBTN_RIGHT) PicoDrawMask ^= PDRAW_LAYERA_ON;
\r
1822 if (inp & PBTN_DOWN) PicoDrawMask ^= PDRAW_SPRITES_LOW_ON;
\r
1823 if (inp & PBTN_UP) PicoDrawMask ^= PDRAW_SPRITES_HI_ON;
\r
1824 if (inp & PBTN_MOK) {
\r
1825 PsndOut = NULL; // just in case
\r
1826 PicoSkipFrame = 1;
\r
1828 PicoSkipFrame = 0;
\r
1829 while (inp & PBTN_MOK) inp = in_menu_wait_any(-1);
\r
1833 if (inp & PBTN_DOWN) spr_offs++;
\r
1834 if (inp & PBTN_UP) spr_offs--;
\r
1835 if (spr_offs < 0) spr_offs = 0;
\r
1841 // ------------ main menu ------------
\r
1843 static char *romsel_run(void)
\r
1845 char *ret, *sel_name;
\r
1847 sel_name = malloc(sizeof(rom_fname_loaded));
\r
1848 if (sel_name == NULL)
\r
1850 strcpy(sel_name, rom_fname_loaded);
\r
1852 ret = menu_loop_romsel(sel_name, sizeof(rom_fname_loaded));
\r
1857 static int main_menu_handler(menu_id id, int keys)
\r
1863 case MA_MAIN_RESUME_GAME:
\r
1867 case MA_MAIN_SAVE_STATE:
\r
1869 return menu_loop_savestate(0);
\r
1871 case MA_MAIN_LOAD_STATE:
\r
1873 return menu_loop_savestate(1);
\r
1875 case MA_MAIN_RESET_GAME:
\r
1881 case MA_MAIN_LOAD_ROM:
\r
1882 ret_name = romsel_run();
\r
1883 if (ret_name != NULL) {
\r
1884 lprintf("selected file: %s\n", ret_name);
\r
1885 engineState = PGS_ReloadRom;
\r
1889 case MA_MAIN_CREDITS:
\r
1890 draw_menu_credits();
\r
1891 in_menu_wait(PBTN_MOK|PBTN_MBACK, 70);
\r
1893 case MA_MAIN_EXIT:
\r
1894 engineState = PGS_Quit;
\r
1896 case MA_MAIN_PATCHES:
\r
1897 if (rom_loaded && PicoPatches) {
\r
1898 menu_loop_patches();
\r
1900 me_update_msg("Patches applied");
\r
1904 lprintf("%s: something unknown selected\n", __FUNCTION__);
\r
1911 static menu_entry e_menu_main[] =
\r
1913 mee_label ("PicoDrive " VERSION),
\r
1917 mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler),
\r
1918 mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler),
\r
1919 mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler),
\r
1920 mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler),
\r
1921 mee_handler_id("Load new ROM/ISO", MA_MAIN_LOAD_ROM, main_menu_handler),
\r
1922 mee_handler_id("Change options", MA_MAIN_OPTIONS, menu_loop_options),
\r
1923 mee_handler_id("Configure controls", MA_MAIN_OPTIONS, menu_loop_keyconfig),
\r
1924 mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler),
\r
1925 mee_handler_id("Patches / GameGenie",MA_MAIN_PATCHES, main_menu_handler),
\r
1926 mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler),
\r
1930 void menu_loop(void)
\r
1932 static int sel = 0;
\r
1934 me_enable(e_menu_main, MA_MAIN_RESUME_GAME, rom_loaded);
\r
1935 me_enable(e_menu_main, MA_MAIN_SAVE_STATE, rom_loaded);
\r
1936 me_enable(e_menu_main, MA_MAIN_LOAD_STATE, rom_loaded);
\r
1937 me_enable(e_menu_main, MA_MAIN_RESET_GAME, rom_loaded);
\r
1938 me_enable(e_menu_main, MA_MAIN_PATCHES, PicoPatches != NULL);
\r
1940 plat_video_menu_enter(rom_loaded);
\r
1941 in_set_blocking(1);
\r
1942 me_loop(e_menu_main, &sel, menu_main_plat_draw);
\r
1945 if (engineState == PGS_Menu)
\r
1946 engineState = PGS_Running;
\r
1947 /* wait until menu, ok, back is released */
\r
1948 while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK));
\r
1951 in_set_blocking(0);
\r
1954 // --------- CD tray close menu ----------
\r
1956 static int mh_tray_load_cd(menu_id id, int keys)
\r
1960 ret_name = romsel_run();
\r
1961 if (ret_name == NULL)
\r
1964 engineState = PGS_RestartRun;
\r
1965 return emu_swap_cd(ret_name);
\r
1968 static int mh_tray_nothing(menu_id id, int keys)
\r
1973 static menu_entry e_menu_tray[] =
\r
1975 mee_label ("The CD tray has opened."),
\r
1978 mee_handler("Load CD image", mh_tray_load_cd),
\r
1979 mee_handler("Insert nothing", mh_tray_nothing),
\r
1983 int menu_loop_tray(void)
\r
1985 int ret = 1, sel = 0;
\r
1987 plat_video_menu_enter(rom_loaded);
\r
1989 in_set_blocking(1);
\r
1990 me_loop(e_menu_tray, &sel, NULL);
\r
1992 if (engineState != PGS_RestartRun) {
\r
1993 engineState = PGS_RestartRun;
\r
1994 ret = 0; /* no CD inserted */
\r
1997 while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK));
\r
1998 in_set_blocking(0);
\r
2005 void me_update_msg(const char *msg)
\r
2007 strncpy(menu_error_msg, msg, sizeof(menu_error_msg));
\r
2008 menu_error_msg[sizeof(menu_error_msg) - 1] = 0;
\r
2010 menu_error_time = plat_get_ticks_ms();
\r
2011 lprintf("msg: %s\n", menu_error_msg);
\r
2014 // ------------ util ------------
\r
2016 /* GP2X/wiz for now, probably extend later */
\r
2017 void menu_plat_setup(int is_wiz)
\r
2022 me_enable(e_menu_gfx_options, MA_OPT_TEARING_FIX, 0);
\r
2023 i = me_id2offset(e_menu_gfx_options, MA_OPT_TEARING_FIX);
\r
2024 e_menu_gfx_options[i].need_to_save = 0;
\r
2028 me_enable(e_menu_adv_options, MA_OPT_ARM940_SOUND, 0);
\r
2029 me_enable(e_menu_gfx_options, MA_OPT2_GAMMA, 0);
\r
2030 me_enable(e_menu_gfx_options, MA_OPT2_A_SN_GAMMA, 0);
\r
2032 i = me_id2offset(e_menu_gfx_options, MA_OPT_SCALING);
\r
2033 e_menu_gfx_options[i].max = 1; /* only off and sw */
\r
2034 i = me_id2offset(e_menu_gfx_options, MA_OPT_ARM940_SOUND);
\r
2035 e_menu_gfx_options[i].need_to_save = 0;
\r
2038 /* TODO: rename */
\r
2039 void menu_darken_bg(void *dst, int pixels, int darker)
\r
2041 unsigned int *screen = dst;
\r
2047 unsigned int p = *screen;
\r
2048 *screen++ = ((p&0xf79ef79e)>>1) - ((p&0xc618c618)>>3);
\r
2055 unsigned int p = *screen;
\r
2056 *screen++ = (p&0xf79ef79e)>>1;
\r
2061 /* hidden options for config engine only */
\r
2062 static menu_entry e_menu_hidden[] =
\r
2064 mee_onoff("Accurate sprites", MA_OPT_ACC_SPRITES, PicoOpt, 0x080),
\r
2068 static menu_entry *e_menu_table[] =
\r
2071 e_menu_gfx_options,
\r
2072 e_menu_adv_options,
\r
2073 e_menu_cd_options,
\r
2078 static menu_entry *me_list_table = NULL;
\r
2079 static menu_entry *me_list_i = NULL;
\r
2081 menu_entry *me_list_get_first(void)
\r
2083 me_list_table = me_list_i = e_menu_table[0];
\r
2087 menu_entry *me_list_get_next(void)
\r
2092 if (me_list_i->name != NULL)
\r
2095 for (i = 0; i < array_size(e_menu_table); i++)
\r
2096 if (me_list_table == e_menu_table[i])
\r
2099 if (i + 1 < array_size(e_menu_table))
\r
2100 me_list_table = me_list_i = e_menu_table[i + 1];
\r
2102 me_list_table = me_list_i = NULL;
\r