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
21 #include <pico/pico_int.h>
\r
22 #include <pico/patch.h>
\r
23 #include <zlib/zlib.h>
\r
25 #define array_size(x) (sizeof(x) / sizeof(x[0]))
\r
27 static char static_buff[64];
\r
28 static char menu_error_msg[64] = { 0, };
\r
29 static int menu_error_time = 0;
\r
33 static unsigned char *menu_font_data = NULL;
\r
34 static int menu_text_color = 0xffff; // default to white
\r
35 static int menu_sel_color = -1; // disabled
\r
37 static const int me_mfont_w = 16, me_mfont_h = 20;
\r
39 static const int me_mfont_w = 8, me_mfont_h = 10;
\r
42 // draws text to current bbp16 screen
\r
43 static void text_out16_(int x, int y, const char *text, int color)
\r
45 int i, l, u, tr, tg, tb, len;
\r
46 unsigned short *dest = (unsigned short *)g_screen_ptr + x + y * g_screen_width;
\r
47 tr = (color & 0xf800) >> 8;
\r
48 tg = (color & 0x07e0) >> 3;
\r
49 tb = (color & 0x001f) << 3;
\r
51 if (text == (void *)1)
\r
60 for (p = text; *p != 0 && *p != '\n'; p++)
\r
65 for (i = 0; i < len; i++)
\r
67 unsigned char *src = menu_font_data + (unsigned int)text[i] * me_mfont_w * me_mfont_h / 2;
\r
68 unsigned short *dst = dest;
\r
69 for (l = 0; l < me_mfont_h; l++, dst += g_screen_width - me_mfont_w)
\r
71 for (u = me_mfont_w / 2; u > 0; u--, src++)
\r
75 r = (*dst & 0xf800) >> 8;
\r
76 g = (*dst & 0x07e0) >> 3;
\r
77 b = (*dst & 0x001f) << 3;
\r
78 r = (c^0xf)*r/15 + c*tr/15;
\r
79 g = (c^0xf)*g/15 + c*tg/15;
\r
80 b = (c^0xf)*b/15 + c*tb/15;
\r
81 *dst++ = ((r<<8)&0xf800) | ((g<<3)&0x07e0) | (b>>3);
\r
83 r = (*dst & 0xf800) >> 8;
\r
84 g = (*dst & 0x07e0) >> 3;
\r
85 b = (*dst & 0x001f) << 3;
\r
86 r = (c^0xf)*r/15 + c*tr/15;
\r
87 g = (c^0xf)*g/15 + c*tg/15;
\r
88 b = (c^0xf)*b/15 + c*tb/15;
\r
89 *dst++ = ((r<<8)&0xf800) | ((g<<3)&0x07e0) | (b>>3);
\r
96 void text_out16(int x, int y, const char *texto, ...)
\r
100 int maxw = (g_screen_width - x) / me_mfont_w;
\r
105 va_start(args, texto);
\r
106 vsnprintf(buffer, sizeof(buffer), texto, args);
\r
109 if (maxw > sizeof(buffer) - 1)
\r
110 maxw = sizeof(buffer) - 1;
\r
113 text_out16_(x,y,buffer,menu_text_color);
\r
117 static void smalltext_out16_(int x, int y, const char *texto, int color)
\r
120 unsigned char *src;
\r
121 unsigned short *dst;
\r
123 for (i = 0;; i++, x += 6)
\r
125 unsigned char c = (unsigned char) texto[i];
\r
130 src = fontdata6x8[c];
\r
131 dst = (unsigned short *)g_screen_ptr + x + y * g_screen_width;
\r
138 if( *src & w ) *dst = color;
\r
144 dst += g_screen_width - 6;
\r
149 static void smalltext_out16(int x, int y, const char *texto, int color)
\r
152 int maxw = (g_screen_width - x) / 6;
\r
157 strncpy(buffer, texto, sizeof(buffer));
\r
158 if (maxw > sizeof(buffer) - 1)
\r
159 maxw = sizeof(buffer) - 1;
\r
162 smalltext_out16_(x, y, buffer, color);
\r
165 static void menu_draw_selection(int x, int y, int w)
\r
168 unsigned short *dst, *dest;
\r
170 text_out16_(x, y, (void *)1, (menu_sel_color < 0) ? menu_text_color : menu_sel_color);
\r
172 if (menu_sel_color < 0) return; // no selection hilight
\r
175 dest = (unsigned short *)g_screen_ptr + x + y * g_screen_width + 14;
\r
176 for (h = me_mfont_h + 1; h > 0; h--)
\r
179 for (i = w; i > 0; i--)
\r
180 *dst++ = menu_sel_color;
\r
181 dest += g_screen_width;
\r
185 static int parse_hex_color(char *buff)
\r
188 int t = (int) strtoul(buff, &endp, 16);
\r
191 return ((t<<8)&0xf800) | ((t>>5)&0x07e0) | ((t>>19)&0x1f);
\r
193 return ((t>>8)&0xf800) | ((t>>5)&0x07e0) | ((t>>3)&0x1f);
\r
198 void menu_init(void)
\r
201 unsigned char *fd, *fds;
\r
205 if (menu_font_data != NULL)
\r
206 free(menu_font_data);
\r
208 menu_font_data = calloc((MENU_X2 ? 256 * 320 : 128 * 160) / 2, 1);
\r
209 if (menu_font_data == NULL)
\r
212 // generate default 8x10 font from fontdata8x8
\r
213 for (c = 0, fd = menu_font_data; c < 256; c++)
\r
215 for (l = 0; l < 8; l++)
\r
217 unsigned char fd8x8 = fontdata8x8[c*8+l];
\r
218 if (fd8x8&0x80) *fd = 0xf0;
\r
219 if (fd8x8&0x40) *fd |= 0x0f; fd++;
\r
220 if (fd8x8&0x20) *fd = 0xf0;
\r
221 if (fd8x8&0x10) *fd |= 0x0f; fd++;
\r
222 if (fd8x8&0x08) *fd = 0xf0;
\r
223 if (fd8x8&0x04) *fd |= 0x0f; fd++;
\r
224 if (fd8x8&0x02) *fd = 0xf0;
\r
225 if (fd8x8&0x01) *fd |= 0x0f; fd++;
\r
227 fd += 8*2/2; // 2 empty lines
\r
231 // expand default font
\r
232 fds = menu_font_data + 128 * 160 / 2 - 4;
\r
233 fd = menu_font_data + 256 * 320 / 2 - 1;
\r
234 for (c = 255; c >= 0; c--)
\r
236 for (l = 9; l >= 0; l--, fds -= 4)
\r
238 for (i = 3; i >= 0; i--) {
\r
239 int px = fds[i] & 0x0f;
\r
240 *fd-- = px | (px << 4);
\r
241 px = (fds[i] >> 4) & 0x0f;
\r
242 *fd-- = px | (px << 4);
\r
244 for (i = 3; i >= 0; i--) {
\r
245 int px = fds[i] & 0x0f;
\r
246 *fd-- = px | (px << 4);
\r
247 px = (fds[i] >> 4) & 0x0f;
\r
248 *fd-- = px | (px << 4);
\r
254 // load custom font and selector (stored as 1st symbol in font table)
\r
255 readpng(menu_font_data, "skin/font.png", READPNG_FONT);
\r
256 // default selector symbol is '>'
\r
257 memcpy(menu_font_data, menu_font_data + ((int)'>') * me_mfont_w * me_mfont_h / 2,
\r
258 me_mfont_w * me_mfont_h / 2);
\r
259 readpng(menu_font_data, "skin/selector.png", READPNG_SELECTOR);
\r
261 // load custom colors
\r
262 f = fopen("skin/skin.txt", "r");
\r
265 lprintf("found skin.txt\n");
\r
268 fgets(buff, sizeof(buff), f);
\r
269 if (buff[0] == '#' || buff[0] == '/') continue; // comment
\r
270 if (buff[0] == '\r' || buff[0] == '\n') continue; // empty line
\r
271 if (strncmp(buff, "text_color=", 11) == 0)
\r
273 int tmp = parse_hex_color(buff+11);
\r
274 if (tmp >= 0) menu_text_color = tmp;
\r
275 else lprintf("skin.txt: parse error for text_color\n");
\r
277 else if (strncmp(buff, "selection_color=", 16) == 0)
\r
279 int tmp = parse_hex_color(buff+16);
\r
280 if (tmp >= 0) menu_sel_color = tmp;
\r
281 else lprintf("skin.txt: parse error for selection_color\n");
\r
284 lprintf("skin.txt: parse error: %s\n", buff);
\r
291 static int me_id2offset(const menu_entry *ent, menu_id id)
\r
294 for (i = 0; ent->name; ent++, i++)
\r
295 if (ent->id == id) return i;
\r
297 lprintf("%s: id %i not found\n", __FUNCTION__, id);
\r
301 static void me_enable(menu_entry *entries, menu_id id, int enable)
\r
303 int i = me_id2offset(entries, id);
\r
304 entries[i].enabled = enable;
\r
307 static int me_count(const menu_entry *ent)
\r
311 for (ret = 0; ent->name; ent++, ret++)
\r
317 static void me_draw(const menu_entry *entries, int sel)
\r
319 const menu_entry *ent;
\r
320 int x, y, w = 0, h = 0;
\r
321 int offs, opt_offs = 27 * me_mfont_w;
\r
326 /* calculate size of menu rect */
\r
327 for (ent = entries, i = n = 0; ent->name; ent++, i++)
\r
338 wt = strlen(ent->name) * me_mfont_w;
\r
339 if (wt == 0 && ent->generate_name)
\r
340 name = ent->generate_name(ent->id, &offs);
\r
342 wt = strlen(name) * me_mfont_w;
\r
344 if (ent->beh != MB_NONE)
\r
347 opt_offs = wt + me_mfont_w;
\r
350 switch (ent->beh) {
\r
351 case MB_NONE: break;
\r
353 case MB_OPT_RANGE: wt += me_mfont_w * 3; break;
\r
354 case MB_OPT_CUSTOM:
\r
355 case MB_OPT_CUSTONOFF:
\r
356 case MB_OPT_CUSTRANGE:
\r
359 if (ent->generate_name != NULL)
\r
360 name = ent->generate_name(ent->id, &offs);
\r
362 wt += (strlen(name) + offs) * me_mfont_w;
\r
371 h = n * me_mfont_h;
\r
372 w += me_mfont_w * 2; /* selector */
\r
374 if (w > g_screen_width) {
\r
375 lprintf("width %d > %d\n", w, g_screen_width);
\r
376 w = g_screen_width;
\r
378 if (h > g_screen_height) {
\r
379 lprintf("height %d > %d\n", w, g_screen_height);
\r
380 h = g_screen_height;
\r
383 x = g_screen_width / 2 - w / 2;
\r
384 y = g_screen_height / 2 - h / 2;
\r
387 plat_video_menu_begin();
\r
388 menu_draw_selection(x, y + asel * me_mfont_h, w);
\r
389 x += me_mfont_w * 2;
\r
391 for (ent = entries; ent->name; ent++)
\r
397 if (strlen(name) == 0) {
\r
398 if (ent->generate_name)
\r
399 name = ent->generate_name(ent->id, &offs);
\r
402 text_out16(x, y, name);
\r
404 switch (ent->beh) {
\r
408 text_out16(x + opt_offs, y, (*(int *)ent->var & ent->mask) ? "ON" : "OFF");
\r
411 text_out16(x + opt_offs, y, "%i", *(int *)ent->var);
\r
413 case MB_OPT_CUSTOM:
\r
414 case MB_OPT_CUSTONOFF:
\r
415 case MB_OPT_CUSTRANGE:
\r
418 if (ent->generate_name)
\r
419 name = ent->generate_name(ent->id, &offs);
\r
421 text_out16(x + opt_offs + offs * me_mfont_w, y, "%s", name);
\r
428 /* display message if we have one */
\r
429 if (menu_error_msg[0] != 0) {
\r
430 if (g_screen_height - h >= 2 * me_mfont_h)
\r
431 text_out16(5, g_screen_height - me_mfont_h - 4, menu_error_msg);
\r
433 lprintf("menu msg doesn't fit!\n");
\r
435 if (plat_get_ticks_ms() - menu_error_time > 2048)
\r
436 menu_error_msg[0] = 0;
\r
439 plat_video_menu_end();
\r
442 static int me_process(menu_entry *entry, int is_next)
\r
444 switch (entry->beh)
\r
447 case MB_OPT_CUSTONOFF:
\r
448 *(int *)entry->var ^= entry->mask;
\r
451 case MB_OPT_CUSTRANGE:
\r
452 *(int *)entry->var += is_next ? 1 : -1;
\r
453 if (*(int *)entry->var < (int)entry->min)
\r
454 *(int *)entry->var = (int)entry->max;
\r
455 if (*(int *)entry->var > (int)entry->max)
\r
456 *(int *)entry->var = (int)entry->min;
\r
463 static void debug_menu_loop(void);
\r
465 static void me_loop(menu_entry *menu, int *menu_sel)
\r
467 int ret, inp, sel = *menu_sel, menu_sel_max;
\r
469 menu_sel_max = me_count(menu) - 1;
\r
470 if (menu_sel_max < 1) {
\r
471 lprintf("no enabled menu entries\n");
\r
475 while (!menu[sel].enabled && sel < menu_sel_max)
\r
478 /* make sure action buttons are not pressed on entering menu */
\r
479 me_draw(menu, sel);
\r
480 while (in_menu_wait_any(50) & (PBTN_MOK|PBTN_MBACK|PBTN_MENU));
\r
484 me_draw(menu, sel);
\r
485 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|
\r
486 PBTN_MOK|PBTN_MBACK|PBTN_MENU|PBTN_L|PBTN_R, 70);
\r
487 if (inp & (PBTN_MENU|PBTN_MBACK))
\r
490 if (inp & PBTN_UP ) {
\r
494 sel = menu_sel_max;
\r
496 while (!menu[sel].enabled || !menu[sel].selectable);
\r
498 if (inp & PBTN_DOWN) {
\r
501 if (sel > menu_sel_max)
\r
504 while (!menu[sel].enabled || !menu[sel].selectable);
\r
507 /* a bit hacky but oh well */
\r
508 if ((inp & (PBTN_L|PBTN_R)) == (PBTN_L|PBTN_R))
\r
511 if (inp & (PBTN_LEFT|PBTN_RIGHT)) { /* multi choice */
\r
512 if (me_process(&menu[sel], (inp & PBTN_RIGHT) ? 1 : 0))
\r
516 if (inp & (PBTN_MOK|PBTN_LEFT|PBTN_RIGHT))
\r
518 if (menu[sel].handler != NULL) {
\r
519 ret = menu[sel].handler(menu[sel].id, inp);
\r
521 menu_sel_max = me_count(menu) - 1; /* might change */
\r
528 /* ***************************************** */
\r
530 static void draw_menu_credits(void)
\r
532 const char *creds, *p;
\r
533 int x, y, h, w, wt;
\r
535 p = creds = plat_get_credits();
\r
537 for (h = 1, w = 0; *p != 0; h++) {
\r
538 for (wt = 0; *p != 0 && *p != '\n'; p++)
\r
548 x = g_screen_width / 2 - w * me_mfont_w / 2;
\r
549 y = g_screen_height / 2 - h * me_mfont_h / 2;
\r
553 plat_video_menu_begin();
\r
555 for (p = creds; *p != 0 && y <= g_screen_height - me_mfont_h; y += me_mfont_h) {
\r
556 text_out16(x, y, p);
\r
558 for (; *p != 0 && *p != '\n'; p++)
\r
564 plat_video_menu_end();
\r
567 // --------- loading ROM screen ----------
\r
569 static int cdload_called = 0;
\r
571 static void load_progress_cb(int percent)
\r
573 int ln, len = percent * g_screen_width / 100;
\r
574 unsigned short *dst = (unsigned short *)g_screen_ptr + g_screen_width * 10 * 2;
\r
576 if (len > g_screen_width)
\r
577 len = g_screen_width;
\r
578 for (ln = 10 - 2; ln > 0; ln--, dst += g_screen_width)
\r
579 memset(dst, 0xff, len * 2);
\r
580 plat_video_menu_end();
\r
583 static void cdload_progress_cb(int percent)
\r
585 int ln, len = percent * g_screen_width / 100;
\r
586 unsigned short *dst = (unsigned short *)g_screen_ptr + g_screen_width * 10 * 2;
\r
588 memset(dst, 0xff, g_screen_width * (10 - 2) * 2);
\r
590 smalltext_out16(1, 3 * 10, "Processing CD image / MP3s", 0xffff);
\r
591 smalltext_out16(1, 4 * 10, rom_fname_loaded, 0xffff);
\r
592 dst += g_screen_width * 30;
\r
594 if (len > g_screen_width)
\r
595 len = g_screen_width;
\r
596 for (ln = (10 - 2); ln > 0; ln--, dst += g_screen_width)
\r
597 memset(dst, 0xff, len * 2);
\r
599 plat_video_menu_end();
\r
603 void menu_romload_prepare(const char *rom_name)
\r
605 const char *p = rom_name + strlen(rom_name);
\r
607 plat_video_menu_begin();
\r
609 while (p > rom_name && *p != '/')
\r
612 /* fill both buffers, callbacks won't update in full */
\r
613 smalltext_out16(1, 1, "Loading", 0xffff);
\r
614 smalltext_out16(1, 10, p, 0xffff);
\r
615 plat_video_menu_end();
\r
617 smalltext_out16(1, 1, "Loading", 0xffff);
\r
618 smalltext_out16(1, 10, p, 0xffff);
\r
619 plat_video_menu_end();
\r
621 PicoCartLoadProgressCB = load_progress_cb;
\r
622 PicoCDLoadProgressCB = cdload_progress_cb;
\r
626 void menu_romload_end(void)
\r
628 PicoCartLoadProgressCB = PicoCDLoadProgressCB = NULL;
\r
629 smalltext_out16(1, (cdload_called ? 6 : 3) * 10,
\r
630 "Starting emulation...", 0xffff);
\r
631 plat_video_menu_end();
\r
634 // -------------- ROM selector --------------
\r
636 // rrrr rggg gggb bbbb
\r
637 static unsigned short file2color(const char *fname)
\r
639 const char *ext = fname + strlen(fname) - 3;
\r
640 static const char *rom_exts[] = { "zip", "bin", "smd", "gen", "iso", "cso", "cue" };
\r
641 static const char *other_exts[] = { "gmv", "pat" };
\r
644 if (ext < fname) ext = fname;
\r
645 for (i = 0; i < array_size(rom_exts); i++)
\r
646 if (strcasecmp(ext, rom_exts[i]) == 0) return 0xbdff; // FIXME: mk defines
\r
647 for (i = 0; i < array_size(other_exts); i++)
\r
648 if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5;
\r
652 static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)
\r
654 int max_cnt, start, i, pos;
\r
656 max_cnt = g_screen_height / 10;
\r
657 start = max_cnt / 2 - sel;
\r
658 n--; // exclude current dir (".")
\r
660 plat_video_menu_begin();
\r
662 // if (!rom_loaded)
\r
663 // menu_darken_bg(gp2x_screen, 320*240, 0);
\r
665 menu_darken_bg((short *)g_screen_ptr + g_screen_width * max_cnt/2 * 10, g_screen_width * 8, 0);
\r
667 if (start - 2 >= 0)
\r
668 smalltext_out16(14, (start - 2)*10, curdir, 0xffff);
\r
669 for (i = 0; i < n; i++) {
\r
671 if (pos < 0) continue;
\r
672 if (pos >= max_cnt) break;
\r
673 if (namelist[i+1]->d_type == DT_DIR) {
\r
674 smalltext_out16(14, pos*10, "/", 0xfff6);
\r
675 smalltext_out16(14+6, pos*10, namelist[i+1]->d_name, 0xfff6);
\r
677 unsigned short color = file2color(namelist[i+1]->d_name);
\r
678 smalltext_out16(14, pos*10, namelist[i+1]->d_name, color);
\r
681 smalltext_out16(5, max_cnt/2 * 10, ">", 0xffff);
\r
682 plat_video_menu_end();
\r
685 static int scandir_cmp(const void *p1, const void *p2)
\r
687 struct dirent **d1 = (struct dirent **)p1, **d2 = (struct dirent **)p2;
\r
688 if ((*d1)->d_type == (*d2)->d_type) return alphasort(d1, d2);
\r
689 if ((*d1)->d_type == DT_DIR) return -1; // put before
\r
690 if ((*d2)->d_type == DT_DIR) return 1;
\r
691 return alphasort(d1, d2);
\r
694 static const char *filter_exts[] = {
\r
695 ".mp3", ".MP3", ".srm", ".brm", "s.gz", ".mds", "bcfg", ".txt", ".htm", "html",
\r
699 static int scandir_filter(const struct dirent *ent)
\r
704 if (ent == NULL || ent->d_name == NULL) return 0;
\r
705 if (strlen(ent->d_name) < 5) return 1;
\r
707 p = ent->d_name + strlen(ent->d_name) - 4;
\r
709 for (i = 0; i < array_size(filter_exts); i++)
\r
710 if (strcmp(p, filter_exts[i]) == 0)
\r
716 static char *menu_loop_romsel(char *curr_path, int len)
\r
718 struct dirent **namelist;
\r
719 int n, inp, sel = 0;
\r
720 char *ret = NULL, *fname = NULL;
\r
723 // is this a dir or a full path?
\r
724 if (!plat_is_dir(curr_path)) {
\r
725 char *p = curr_path + strlen(curr_path) - 1;
\r
726 for (; p > curr_path && *p != '/'; p--)
\r
732 n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp);
\r
734 lprintf("menu_loop_romsel failed, dir: %s\n", curr_path);
\r
737 getcwd(curr_path, len);
\r
738 n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp);
\r
741 lprintf("menu_loop_romsel failed, dir: %s\n", curr_path);
\r
747 if (fname != NULL) {
\r
749 for (i = 1; i < n; i++) {
\r
750 if (strcmp(namelist[i]->d_name, fname) == 0) {
\r
759 draw_dirlist(curr_path, namelist, n, sel);
\r
760 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|
\r
761 PBTN_L|PBTN_R|PBTN_MA2|PBTN_MOK|PBTN_MBACK|PBTN_MENU, 33);
\r
762 if (inp & PBTN_UP ) { sel--; if (sel < 0) sel = n-2; }
\r
763 if (inp & PBTN_DOWN) { sel++; if (sel > n-2) sel = 0; }
\r
764 if (inp & PBTN_LEFT) { sel-=10; if (sel < 0) sel = 0; }
\r
765 if (inp & PBTN_L) { sel-=24; if (sel < 0) sel = 0; }
\r
766 if (inp & PBTN_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }
\r
767 if (inp & PBTN_R) { sel+=24; if (sel > n-2) sel = n-2; }
\r
768 if ((inp & PBTN_MOK) || (inp & (PBTN_MENU|PBTN_MA2)) == (PBTN_MENU|PBTN_MA2))
\r
771 if (namelist[sel+1]->d_type == DT_REG)
\r
773 strcpy(rom_fname_reload, curr_path);
\r
774 strcat(rom_fname_reload, "/");
\r
775 strcat(rom_fname_reload, namelist[sel+1]->d_name);
\r
776 if (inp & PBTN_MOK) { // return sel
\r
777 ret = rom_fname_reload;
\r
780 // do_delete(rom_fname_reload, namelist[sel+1]->d_name); // TODO
\r
782 while (n--) free(namelist[n]);
\r
787 else if (namelist[sel+1]->d_type == DT_DIR)
\r
791 if (!(inp & PBTN_MOK)) continue;
\r
792 newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;
\r
793 newdir = malloc(newlen);
\r
794 if (strcmp(namelist[sel+1]->d_name, "..") == 0) {
\r
795 char *start = curr_path;
\r
796 p = start + strlen(start) - 1;
\r
797 while (*p == '/' && p > start) p--;
\r
798 while (*p != '/' && p > start) p--;
\r
799 if (p <= start) strcpy(newdir, "/");
\r
800 else { strncpy(newdir, start, p-start); newdir[p-start] = 0; }
\r
802 strcpy(newdir, curr_path);
\r
803 p = newdir + strlen(newdir) - 1;
\r
804 while (*p == '/' && p >= newdir) *p-- = 0;
\r
805 strcat(newdir, "/");
\r
806 strcat(newdir, namelist[sel+1]->d_name);
\r
808 ret = menu_loop_romsel(newdir, newlen);
\r
814 // unknown file type, happens on NTFS mounts. Try to guess.
\r
815 FILE *tstf; int tmp;
\r
816 strcpy(rom_fname_reload, curr_path);
\r
817 strcat(rom_fname_reload, "/");
\r
818 strcat(rom_fname_reload, namelist[sel+1]->d_name);
\r
819 tstf = fopen(rom_fname_reload, "rb");
\r
822 if (fread(&tmp, 1, 1, tstf) > 0 || ferror(tstf) == 0)
\r
823 namelist[sel+1]->d_type = DT_REG;
\r
824 else namelist[sel+1]->d_type = DT_DIR;
\r
830 if (inp & PBTN_MBACK)
\r
835 while (n--) free(namelist[n]);
\r
842 // ------------ patch/gg menu ------------
\r
844 static void draw_patchlist(int sel)
\r
846 int max_cnt, start, i, pos, active;
\r
848 max_cnt = g_screen_height / 10;
\r
849 start = max_cnt / 2 - sel;
\r
851 plat_video_menu_begin();
\r
853 for (i = 0; i < PicoPatchCount; i++) {
\r
855 if (pos < 0) continue;
\r
856 if (pos >= max_cnt) break;
\r
857 active = PicoPatches[i].active;
\r
858 smalltext_out16(14, pos*10, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff);
\r
859 smalltext_out16(14+6*4, pos*10, PicoPatches[i].name, active ? 0xfff6 : 0xffff);
\r
863 smalltext_out16(14, pos * 10, "done", 0xffff);
\r
865 text_out16(5, max_cnt / 2 * 10, ">");
\r
866 plat_video_menu_end();
\r
869 static void menu_loop_patches(void)
\r
871 static int menu_sel = 0;
\r
876 draw_patchlist(menu_sel);
\r
877 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R|PBTN_MOK|PBTN_MBACK, 33);
\r
878 if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }
\r
879 if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }
\r
880 if (inp &(PBTN_LEFT|PBTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
\r
881 if (inp &(PBTN_RIGHT|PBTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }
\r
882 if (inp & PBTN_MOK) { // action
\r
883 if (menu_sel < PicoPatchCount)
\r
884 PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;
\r
887 if (inp & PBTN_MBACK)
\r
892 // ------------ savestate loader ------------
\r
894 static int state_slot_flags = 0;
\r
896 static void state_check_slots(void)
\r
900 state_slot_flags = 0;
\r
902 for (slot = 0; slot < 10; slot++) {
\r
903 if (emu_checkSaveFile(slot))
\r
904 state_slot_flags |= 1 << slot;
\r
908 static void draw_savestate_bg(int slot)
\r
910 struct PicoVideo tmp_pv;
\r
911 unsigned short tmp_cram[0x40];
\r
912 unsigned short tmp_vsram[0x40];
\r
913 void *tmp_vram, *file;
\r
916 fname = emu_GetSaveFName(1, 0, slot);
\r
917 if (!fname) return;
\r
919 tmp_vram = malloc(sizeof(Pico.vram));
\r
920 if (tmp_vram == NULL) return;
\r
922 memcpy(tmp_vram, Pico.vram, sizeof(Pico.vram));
\r
923 memcpy(tmp_cram, Pico.cram, sizeof(Pico.cram));
\r
924 memcpy(tmp_vsram, Pico.vsram, sizeof(Pico.vsram));
\r
925 memcpy(&tmp_pv, &Pico.video, sizeof(Pico.video));
\r
927 if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) {
\r
928 file = gzopen(fname, "rb");
\r
929 emu_setSaveStateCbs(1);
\r
931 file = fopen(fname, "rb");
\r
932 emu_setSaveStateCbs(0);
\r
936 if (PicoAHW & PAHW_MCD) {
\r
937 PicoCdLoadStateGfx(file);
\r
939 areaSeek(file, 0x10020, SEEK_SET); // skip header and RAM in state file
\r
940 areaRead(Pico.vram, 1, sizeof(Pico.vram), file);
\r
941 areaSeek(file, 0x2000, SEEK_CUR);
\r
942 areaRead(Pico.cram, 1, sizeof(Pico.cram), file);
\r
943 areaRead(Pico.vsram, 1, sizeof(Pico.vsram), file);
\r
944 areaSeek(file, 0x221a0, SEEK_SET);
\r
945 areaRead(&Pico.video, 1, sizeof(Pico.video), file);
\r
950 /* do a frame and fetch menu bg */
\r
951 emu_forcedFrame(POPT_EN_SOFTSCALE);
\r
952 plat_video_menu_enter(1);
\r
954 memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram));
\r
955 memcpy(Pico.cram, tmp_cram, sizeof(Pico.cram));
\r
956 memcpy(Pico.vsram, tmp_vsram, sizeof(Pico.vsram));
\r
957 memcpy(&Pico.video, &tmp_pv, sizeof(Pico.video));
\r
961 static void draw_savestate_menu(int menu_sel, int is_loading)
\r
965 if (state_slot_flags & (1 << menu_sel))
\r
966 draw_savestate_bg(menu_sel);
\r
968 w = 13 * me_mfont_w + me_mfont_w * 2;
\r
969 h = (1+2+10+1) * me_mfont_h;
\r
970 x = g_screen_width / 2 - w / 2;
\r
972 y = g_screen_height / 2 - h / 2;
\r
975 plat_video_menu_begin();
\r
977 text_out16(x, y, is_loading ? "Load state" : "Save state");
\r
978 y += 3 * me_mfont_h;
\r
980 menu_draw_selection(x - me_mfont_w * 2, y + menu_sel * me_mfont_h, 13 * me_mfont_w + 4);
\r
982 /* draw all 10 slots */
\r
983 for (i = 0; i < 10; i++, y += me_mfont_h)
\r
985 text_out16(x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free");
\r
987 text_out16(x, y, "back");
\r
989 plat_video_menu_end();
\r
992 static int menu_loop_savestate(int is_loading)
\r
994 static int menu_sel = 10;
\r
995 int menu_sel_max = 10;
\r
996 unsigned long inp = 0;
\r
998 state_check_slots();
\r
1002 draw_savestate_menu(menu_sel, is_loading);
\r
1003 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_MOK|PBTN_MBACK, 100);
\r
1004 if (inp & PBTN_UP) {
\r
1008 menu_sel = menu_sel_max;
\r
1009 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);
\r
1011 if (inp & PBTN_DOWN) {
\r
1014 if (menu_sel > menu_sel_max)
\r
1016 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);
\r
1018 if (inp & PBTN_MOK) { // save/load
\r
1019 if (menu_sel < 10) {
\r
1020 state_slot = menu_sel;
\r
1021 if (emu_SaveLoadGame(is_loading, 0)) {
\r
1022 me_update_msg(is_loading ? "Load failed" : "Save failed");
\r
1029 if (inp & PBTN_MBACK)
\r
1034 // -------------- key config --------------
\r
1036 static char *action_binds(int player_idx, int action_mask, int dev_id)
\r
1041 static_buff[0] = 0;
\r
1043 binds = in_get_dev_binds(dev_id);
\r
1044 if (binds == NULL)
\r
1045 return static_buff;
\r
1047 count = in_get_dev_bind_count(dev_id);
\r
1048 for (k = 0; k < count; k++)
\r
1050 const char *xname;
\r
1051 if (!(binds[k] & action_mask))
\r
1054 if (player_idx >= 0 && ((binds[k] >> 16) & 3) != player_idx)
\r
1057 xname = in_get_key_name(dev_id, k);
\r
1058 if (static_buff[0])
\r
1059 strncat(static_buff, " + ", sizeof(static_buff));
\r
1060 strncat(static_buff, xname, sizeof(static_buff));
\r
1063 return static_buff;
\r
1066 static int count_bound_keys(int dev_id, int action_mask, int player_idx)
\r
1072 binds = in_get_dev_binds(dev_id);
\r
1073 if (binds == NULL)
\r
1076 count = in_get_dev_bind_count(dev_id);
\r
1077 for (k = 0; k < count; k++)
\r
1079 if (!(binds[k] & action_mask))
\r
1082 if (player_idx >= 0 && ((binds[k] >> 16) & 3) != player_idx)
\r
1091 static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_idx,
\r
1092 int sel, int dev_id, int dev_count, int is_bind)
\r
1095 const char *dev_name;
\r
1097 x = g_screen_width / 2 - 20 * me_mfont_w / 2;
\r
1098 y = (g_screen_height - 4 * me_mfont_h) / 2 - (2 + opt_cnt) * me_mfont_h / 2;
\r
1099 if (x < me_mfont_w * 2)
\r
1100 x = me_mfont_w * 2;
\r
1102 plat_video_menu_begin();
\r
1103 if (player_idx >= 0)
\r
1104 text_out16(x, y, "Player %i controls", player_idx + 1);
\r
1106 text_out16(x, y, "Emulator controls");
\r
1108 y += 2 * me_mfont_h;
\r
1109 menu_draw_selection(x - me_mfont_w * 2, y + sel * me_mfont_h, me_mfont_w); // FIXME last arg
\r
1111 for (i = 0; i < opt_cnt; i++, y += me_mfont_h)
\r
1112 text_out16(x, y, "%s : %s", opts[i].name,
\r
1113 action_binds(player_idx, opts[i].mask, dev_id));
\r
1115 dev_name = in_get_dev_name(dev_id, 1, 1);
\r
1116 w = strlen(dev_name) * me_mfont_w;
\r
1117 if (w < 30 * me_mfont_w)
\r
1118 w = 30 * me_mfont_w;
\r
1119 if (w > g_screen_width)
\r
1120 w = g_screen_width;
\r
1122 x = g_screen_width / 2 - w / 2;
\r
1124 if (dev_count > 1) {
\r
1125 text_out16(x, g_screen_height - 4 * me_mfont_h, "Viewing binds for:");
\r
1126 text_out16(x, g_screen_height - 3 * me_mfont_h, dev_name);
\r
1130 text_out16(x, g_screen_height - 2 * me_mfont_h, "Press a button to bind/unbind");
\r
1131 else if (dev_count > 1)
\r
1132 text_out16(x, g_screen_height - 2 * me_mfont_h, "Press left/right for other devs");
\r
1134 plat_video_menu_end();
\r
1137 static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_idx)
\r
1139 int i, sel = 0, menu_sel_max = opt_cnt - 1;
\r
1140 int dev_id, dev_count, kc, is_down, mkey, unbind;
\r
1142 for (i = 0, dev_id = -1, dev_count = 0; i < IN_MAX_DEVS; i++) {
\r
1143 if (in_get_dev_name(i, 1, 0) != NULL) {
\r
1150 if (dev_id == -1) {
\r
1151 lprintf("no devs, can't do config\n");
\r
1157 draw_key_config(opts, opt_cnt, player_idx, sel, dev_id, dev_count, 0);
\r
1158 mkey = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_MBACK|PBTN_MOK, 100);
\r
1160 case PBTN_UP: sel--; if (sel < 0) sel = menu_sel_max; continue;
\r
1161 case PBTN_DOWN: sel++; if (sel > menu_sel_max) sel = 0; continue;
\r
1163 for (i = 0, dev_id--; i < IN_MAX_DEVS; i++, dev_id--) {
\r
1165 dev_id = IN_MAX_DEVS - 1;
\r
1166 if (in_get_dev_name(dev_id, 1, 0) != NULL)
\r
1171 for (i = 0, dev_id++; i < IN_MAX_DEVS; i++, dev_id++) {
\r
1172 if (dev_id >= IN_MAX_DEVS)
\r
1174 if (in_get_dev_name(dev_id, 1, 0) != NULL)
\r
1178 case PBTN_MBACK: return;
\r
1180 if (sel >= opt_cnt)
\r
1182 while (in_menu_wait_any(30) & PBTN_MOK);
\r
1187 draw_key_config(opts, opt_cnt, player_idx, sel, dev_id, dev_count, 1);
\r
1189 /* wait for some up event */
\r
1190 for (is_down = 1; is_down; )
\r
1191 kc = in_update_keycode(&dev_id, &is_down, -1);
\r
1193 unbind = count_bound_keys(dev_id, opts[sel].mask, player_idx) >= 2;
\r
1195 in_bind_key(dev_id, kc, opts[sel].mask, unbind);
\r
1196 if (player_idx >= 0) {
\r
1198 in_bind_key(dev_id, kc, 3 << 16, 1);
\r
1199 in_bind_key(dev_id, kc, player_idx << 16, 0);
\r
1204 // PicoPad[] format: MXYZ SACB RLDU
\r
1205 me_bind_action me_ctrl_actions[15] =
\r
1207 { "UP ", 0x0001 },
\r
1208 { "DOWN ", 0x0002 },
\r
1209 { "LEFT ", 0x0004 },
\r
1210 { "RIGHT ", 0x0008 },
\r
1214 { "A turbo", 0x4000 },
\r
1215 { "B turbo", 0x1000 },
\r
1216 { "C turbo", 0x2000 },
\r
1217 { "START ", 0x0080 },
\r
1218 { "MODE ", 0x0800 },
\r
1224 // player2_flag, reserved, ?, ?,
\r
1225 // ?, ?, fast forward, menu
\r
1226 // "NEXT SAVE SLOT", "PREV SAVE SLOT", "SWITCH RENDERER", "SAVE STATE",
\r
1227 // "LOAD STATE", "VOLUME UP", "VOLUME DOWN", "DONE"
\r
1228 me_bind_action emuctrl_actions[] =
\r
1230 { "Load State ", 1<<28 },
\r
1231 { "Save State ", 1<<27 },
\r
1232 { "Prev Save Slot ", 1<<25 },
\r
1233 { "Next Save Slot ", 1<<24 },
\r
1234 { "Switch Renderer ", 1<<26 },
\r
1235 { "Volume Down ", 1<<30 },
\r
1236 { "Volume Up ", 1<<29 },
\r
1237 { "Fast forward ", 1<<22 },
\r
1238 { "Enter Menu ", 1<<23 },
\r
1239 { "Pico Next page ", 1<<21 },
\r
1240 { "Pico Prev page ", 1<<20 },
\r
1241 { "Pico Switch input", 1<<19 },
\r
1245 static int key_config_loop_wrap(menu_id id, int keys)
\r
1248 case MA_CTRL_PLAYER1:
\r
1249 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions), 0);
\r
1251 case MA_CTRL_PLAYER2:
\r
1252 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions), 1);
\r
1255 key_config_loop(emuctrl_actions, array_size(emuctrl_actions) - 1, -1);
\r
1263 static const char *mgn_dev_name(menu_id id, int *offs)
\r
1265 const char *name = NULL;
\r
1266 static int it = 0;
\r
1268 if (id == MA_CTRL_DEV_FIRST)
\r
1271 for (; it < IN_MAX_DEVS; it++) {
\r
1272 name = in_get_dev_name(it, 1, 1);
\r
1281 static int mh_saveloadcfg(menu_id id, int keys);
\r
1282 static const char *mgn_savecfg(menu_id id, int *offs);
\r
1284 static menu_entry e_menu_keyconfig[] =
\r
1286 mee_handler_id("Player 1", MA_CTRL_PLAYER1, key_config_loop_wrap),
\r
1287 mee_handler_id("Player 2", MA_CTRL_PLAYER2, key_config_loop_wrap),
\r
1288 mee_handler_id("Emulator controls", MA_CTRL_EMU, key_config_loop_wrap),
\r
1289 mee_onoff ("6 button pad", MA_OPT_6BUTTON_PAD, PicoOpt, POPT_6BTN_PAD),
\r
1290 mee_range ("Turbo rate", MA_CTRL_TURBO_RATE, currentConfig.turbo_rate, 1, 30),
\r
1291 mee_handler_mkname_id(MA_OPT_SAVECFG, mh_saveloadcfg, mgn_savecfg),
\r
1292 mee_handler_id("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_saveloadcfg),
\r
1294 mee_label ("Input devices:"),
\r
1295 mee_label_mk (MA_CTRL_DEV_FIRST, mgn_dev_name),
\r
1296 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
\r
1297 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
\r
1298 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
\r
1299 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
\r
1300 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
\r
1301 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
\r
1305 static int menu_loop_keyconfig(menu_id id, int keys)
\r
1307 static int sel = 0;
\r
1308 me_loop(e_menu_keyconfig, &sel);
\r
1312 // ------------ SCD options menu ------------
\r
1314 static const char *mgn_cdopt_ra(menu_id id, int *offs)
\r
1317 if (PicoCDBuffers <= 0)
\r
1319 sprintf(static_buff, "%5iK", PicoCDBuffers * 2);
\r
1320 return static_buff;
\r
1323 static int mh_cdopt_ra(menu_id id, int keys)
\r
1325 if (keys & PBTN_LEFT) {
\r
1326 PicoCDBuffers >>= 1;
\r
1327 if (PicoCDBuffers < 2)
\r
1328 PicoCDBuffers = 0;
\r
1330 if (PicoCDBuffers <= 0)
\r
1331 PicoCDBuffers = 1;
\r
1332 PicoCDBuffers <<= 1;
\r
1333 if (PicoCDBuffers > 8*1024)
\r
1334 PicoCDBuffers = 8*1024; // 16M
\r
1339 static menu_entry e_menu_cd_options[] =
\r
1341 mee_onoff("CD LEDs", MA_CDOPT_LEDS, currentConfig.EmuOpt, 0x0400),
\r
1342 mee_onoff("CDDA audio", MA_CDOPT_CDDA, PicoOpt, POPT_EN_MCD_CDDA),
\r
1343 mee_onoff("PCM audio", MA_CDOPT_PCM, PicoOpt, POPT_EN_MCD_PCM),
\r
1344 mee_cust ("ReadAhead buffer", MA_CDOPT_READAHEAD, mh_cdopt_ra, mgn_cdopt_ra),
\r
1345 mee_onoff("SaveRAM cart", MA_CDOPT_SAVERAM, PicoOpt, POPT_EN_MCD_RAMCART),
\r
1346 mee_onoff("Scale/Rot. fx (slow)", MA_CDOPT_SCALEROT_CHIP, PicoOpt, POPT_EN_MCD_GFX),
\r
1347 mee_onoff("Better sync (slow)", MA_CDOPT_BETTER_SYNC, PicoOpt, POPT_EN_MCD_PSYNC),
\r
1351 static int menu_loop_cd_options(menu_id id, int keys)
\r
1353 static int sel = 0;
\r
1354 me_loop(e_menu_cd_options, &sel);
\r
1358 // ------------ adv options menu ------------
\r
1360 // TODO FIXME fix if and mv
\r
1361 static const char *mgn_aopt_sqhack(menu_id id, int *offs)
\r
1364 sprintf(static_buff, "%s, %s", 111 ? " active" : "inactive",
\r
1365 (currentConfig.EmuOpt & 0x10) ? "ON" : "OFF");
\r
1366 return static_buff;
\r
1369 static menu_entry e_menu_adv_options[] =
\r
1371 mee_onoff ("SRAM/BRAM saves", MA_OPT_SRAM_STATES, currentConfig.EmuOpt, EOPT_USE_SRAM),
\r
1372 mee_onoff ("Disable sprite limit", MA_OPT2_NO_SPRITE_LIM, PicoOpt, POPT_DIS_SPRITE_LIM),
\r
1373 mee_onoff ("Use second CPU for sound", MA_OPT_ARM940_SOUND, PicoOpt, POPT_EXT_FM),
\r
1374 mee_onoff ("Emulate Z80", MA_OPT2_ENABLE_Z80, PicoOpt, POPT_EN_Z80),
\r
1375 mee_onoff ("Emulate YM2612 (FM)", MA_OPT2_ENABLE_YM2612, PicoOpt, POPT_EN_FM),
\r
1376 mee_onoff ("Emulate SN76496 (PSG)", MA_OPT2_ENABLE_SN76496,PicoOpt, POPT_EN_PSG),
\r
1377 mee_onoff ("gzip savestates", MA_OPT2_GZIP_STATES, currentConfig.EmuOpt, EOPT_GZIP_SAVES),
\r
1378 mee_onoff ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM, currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG),
\r
1379 mee_label ("- needs restart -"),
\r
1380 mee_onoff ("craigix's RAM timings", MA_OPT2_RAMTIMINGS, currentConfig.EmuOpt, 0x0100),
\r
1381 mee_onoff_cust("Squidgehack", MA_OPT2_SQUIDGEHACK, currentConfig.EmuOpt, 0x0010, mgn_aopt_sqhack),
\r
1382 mee_onoff ("SVP dynarec", MA_OPT2_SVP_DYNAREC, PicoOpt, POPT_EN_SVP_DRC),
\r
1383 mee_onoff ("Disable idle loop patching",MA_OPT2_NO_IDLE_LOOPS,PicoOpt, POPT_DIS_IDLE_DET),
\r
1387 static int menu_loop_adv_options(menu_id id, int keys)
\r
1389 static int sel = 0;
\r
1390 me_loop(e_menu_adv_options, &sel);
\r
1394 // ------------ gfx options menu ------------
\r
1396 static const char *mgn_opt_scaling(menu_id id, int *offs)
\r
1399 switch (currentConfig.scaling) {
\r
1400 default: return " OFF";
\r
1401 case 1: return "hw horizontal";
\r
1402 case 2: return "hw horiz. + vert.";
\r
1403 case 3: return "sw horizontal";
\r
1407 static const char *mgn_aopt_gamma(menu_id id, int *offs)
\r
1409 sprintf(static_buff, "%i.%02i", currentConfig.gamma / 100, currentConfig.gamma%100);
\r
1410 return static_buff;
\r
1413 static menu_entry e_menu_gfx_options[] =
\r
1415 mee_range_cust("Scaling", MA_OPT_SCALING, currentConfig.scaling, 0, 3, mgn_opt_scaling),
\r
1416 mee_range_cust("Gamma correction", MA_OPT2_GAMMA, currentConfig.gamma, 1, 300, mgn_aopt_gamma),
\r
1417 mee_onoff ("A_SN's gamma curve", MA_OPT2_A_SN_GAMMA, currentConfig.EmuOpt, 0x1000),
\r
1418 mee_onoff ("Perfect vsync", MA_OPT2_VSYNC, currentConfig.EmuOpt, 0x2000),
\r
1422 static int menu_loop_gfx_options(menu_id id, int keys)
\r
1424 static int sel = 0;
\r
1425 me_loop(e_menu_gfx_options, &sel);
\r
1429 // ------------ options menu ------------
\r
1431 static menu_entry e_menu_options[];
\r
1433 /* TODO: move to plat */
\r
1434 static int mh_opt_render(menu_id id, int keys)
\r
1436 if (keys & PBTN_LEFT) {
\r
1437 if (PicoOpt&0x10) PicoOpt&= ~0x10;
\r
1438 else if (!(currentConfig.EmuOpt &0x80))currentConfig.EmuOpt |= 0x80;
\r
1440 if (PicoOpt&0x10) return 0;
\r
1441 else if (!(currentConfig.EmuOpt &0x80))PicoOpt|= 0x10;
\r
1442 else if ( currentConfig.EmuOpt &0x80) currentConfig.EmuOpt &= ~0x80;
\r
1447 static int sndrate_prevnext(int rate, int dir)
\r
1449 static const int rates[] = { 8000, 11025, 16000, 22050, 44100 };
\r
1452 for (i = 0; i < 5; i++)
\r
1453 if (rates[i] == rate) break;
\r
1455 i += dir ? 1 : -1;
\r
1457 if (!(PicoOpt & POPT_EN_STEREO)) {
\r
1458 PicoOpt |= POPT_EN_STEREO;
\r
1464 if (PicoOpt & POPT_EN_STEREO) {
\r
1465 PicoOpt &= ~POPT_EN_STEREO;
\r
1473 static void region_prevnext(int right)
\r
1475 // jp_ntsc=1, jp_pal=2, usa=4, eu=8
\r
1476 static const int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };
\r
1480 if (!PicoRegionOverride) {
\r
1481 for (i = 0; i < 6; i++)
\r
1482 if (rgn_orders[i] == PicoAutoRgnOrder) break;
\r
1483 if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];
\r
1484 else PicoRegionOverride=1;
\r
1487 PicoRegionOverride <<= 1;
\r
1488 if (PicoRegionOverride > 8)
\r
1489 PicoRegionOverride = 8;
\r
1491 if (!PicoRegionOverride) {
\r
1492 for (i = 0; i < 6; i++)
\r
1493 if (rgn_orders[i] == PicoAutoRgnOrder) break;
\r
1494 if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];
\r
1497 PicoRegionOverride >>= 1;
\r
1501 static int mh_opt_misc(menu_id id, int keys)
\r
1506 case MA_OPT_SOUND_QUALITY:
\r
1507 PsndRate = sndrate_prevnext(PsndRate, keys & PBTN_RIGHT);
\r
1509 case MA_OPT_REGION:
\r
1510 region_prevnext(keys & PBTN_RIGHT);
\r
1512 case MA_OPT_CONFIRM_STATES:
\r
1513 i = ((currentConfig.EmuOpt>>9)&1) | ((currentConfig.EmuOpt>>10)&2);
\r
1514 i += (keys & PBTN_LEFT) ? -1 : 1;
\r
1515 if (i < 0) i = 0; else if (i > 3) i = 3;
\r
1516 i |= i << 1; i &= ~2;
\r
1517 currentConfig.EmuOpt &= ~0xa00;
\r
1518 currentConfig.EmuOpt |= i << 9;
\r
1526 static int mh_saveloadcfg(menu_id id, int keys)
\r
1530 if (keys & (PBTN_LEFT|PBTN_RIGHT)) { // multi choice
\r
1531 config_slot += (keys & PBTN_LEFT) ? -1 : 1;
\r
1532 if (config_slot < 0) config_slot = 9;
\r
1533 else if (config_slot > 9) config_slot = 0;
\r
1534 me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
\r
1539 case MA_OPT_SAVECFG:
\r
1540 case MA_OPT_SAVECFG_GAME:
\r
1541 if (emu_WriteConfig(id == MA_OPT_SAVECFG_GAME ? 1 : 0))
\r
1542 me_update_msg("config saved");
\r
1544 me_update_msg("failed to write config");
\r
1546 case MA_OPT_LOADCFG:
\r
1547 ret = emu_ReadConfig(1, 1);
\r
1548 if (!ret) ret = emu_ReadConfig(0, 1);
\r
1549 if (ret) me_update_msg("config loaded");
\r
1550 else me_update_msg("failed to load config");
\r
1559 static const char *mgn_opt_renderer(menu_id id, int *offs)
\r
1562 if (PicoOpt & POPT_ALT_RENDERER)
\r
1563 return " 8bit fast";
\r
1564 else if (currentConfig.EmuOpt & 0x80)
\r
1565 return "16bit accurate";
\r
1567 return " 8bit accurate";
\r
1570 static const char *mgn_opt_fskip(menu_id id, int *offs)
\r
1572 if (currentConfig.Frameskip < 0)
\r
1574 sprintf(static_buff, "%d", currentConfig.Frameskip);
\r
1575 return static_buff;
\r
1578 static const char *mgn_opt_sound(menu_id id, int *offs)
\r
1582 str2 = (PicoOpt & POPT_EN_STEREO) ? "stereo" : "mono";
\r
1583 sprintf(static_buff, "%5iHz %s", PsndRate, str2);
\r
1584 return static_buff;
\r
1587 static const char *mgn_opt_region(menu_id id, int *offs)
\r
1589 static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };
\r
1590 static const char *names_short[] = { "", " JP", " JP", " US", " EU" };
\r
1591 int code = PicoRegionOverride;
\r
1597 while ((code >>= 1)) i++;
\r
1602 strcpy(static_buff, "Auto:");
\r
1603 for (u = 0; u < 3; u++) {
\r
1604 code = (PicoAutoRgnOrder >> u*4) & 0xf;
\r
1605 for (i = 0; code; code >>= 1, i++)
\r
1607 strcat(static_buff, names_short[i]);
\r
1609 return static_buff;
\r
1613 static const char *mgn_opt_c_saves(menu_id id, int *offs)
\r
1615 switch ((currentConfig.EmuOpt >> 9) & 5) {
\r
1616 default: return "OFF";
\r
1617 case 1: return "writes";
\r
1618 case 4: return "loads";
\r
1619 case 5: return "both";
\r
1623 static const char *mgn_savecfg(menu_id id, int *offs)
\r
1625 strcpy(static_buff, "Save global config");
\r
1626 if (config_slot != 0)
\r
1627 sprintf(static_buff + strlen(static_buff), " (profile: %i)", config_slot);
\r
1628 return static_buff;
\r
1631 static const char *mgn_loadcfg(menu_id id, int *offs)
\r
1633 sprintf(static_buff, "Load cfg from profile %i", config_slot);
\r
1634 return static_buff;
\r
1637 static menu_entry e_menu_options[] =
\r
1639 mee_range ("Save slot", MA_OPT_SAVE_SLOT, state_slot, 0, 9),
\r
1640 mee_range_cust("Frameskip", MA_OPT_FRAMESKIP, currentConfig.Frameskip, -1, 16, mgn_opt_fskip),
\r
1641 mee_cust ("Region", MA_OPT_REGION, mh_opt_misc, mgn_opt_region),
\r
1642 mee_cust ("Renderer", MA_OPT_RENDERER, mh_opt_render, mgn_opt_renderer),
\r
1643 mee_onoff ("Show FPS", MA_OPT_SHOW_FPS, currentConfig.EmuOpt, 0x002),
\r
1644 mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, 0x004),
\r
1645 mee_cust ("Sound Quality", MA_OPT_SOUND_QUALITY, mh_opt_misc, mgn_opt_sound),
\r
1646 mee_cust ("Confirm savestate", MA_OPT_CONFIRM_STATES,mh_opt_misc, mgn_opt_c_saves),
\r
1647 #if defined(__GP2X__)
\r
1648 mee_range ("GP2X CPU clocks", MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 400),
\r
1649 #elif defined(PSP)
\r
1650 mee_range ("PSP CPU clock", MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, )
\r
1652 mee_handler ("[Display options]", menu_loop_gfx_options),
\r
1653 mee_handler ("[Advanced options]", menu_loop_adv_options),
\r
1654 mee_handler ("[Sega/Mega CD options]", menu_loop_cd_options),
\r
1655 mee_handler_mkname_id(MA_OPT_SAVECFG, mh_saveloadcfg, mgn_savecfg),
\r
1656 mee_handler_id("Save cfg for current game only", MA_OPT_SAVECFG_GAME, mh_saveloadcfg),
\r
1657 mee_handler_mkname_id(MA_OPT_LOADCFG, mh_saveloadcfg, mgn_loadcfg),
\r
1661 static int menu_loop_options(menu_id id, int keys)
\r
1663 static int sel = 0;
\r
1665 me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, rom_loaded);
\r
1666 me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
\r
1668 me_loop(e_menu_options, &sel);
\r
1670 if (PicoRegionOverride)
\r
1671 // force setting possibly changed..
\r
1672 Pico.m.pal = (PicoRegionOverride == 2 || PicoRegionOverride == 8) ? 1 : 0;
\r
1677 // ------------ debug menu ------------
\r
1679 #include <sys/stat.h>
\r
1680 #include <sys/types.h>
\r
1682 #include <pico/debug.h>
\r
1684 extern void SekStepM68k(void);
\r
1686 static void mplayer_loop(void)
\r
1693 if (in_menu_wait_any(0) & PBTN_MA3)
\r
1701 static void draw_text_debug(const char *str, int skip, int from)
\r
1707 while (skip-- > 0)
\r
1709 while (*p && *p != '\n') p++;
\r
1710 if (*p == 0 || p[1] == 0) return;
\r
1715 for (line = from; line < g_screen_height / 10; line++)
\r
1717 while (*p && *p != '\n') p++;
\r
1718 smalltext_out16(1, line*10, str, 0xffff);
\r
1719 if (*p == 0) break;
\r
1724 static void draw_frame_debug(void)
\r
1726 char layer_str[48] = "layers: ";
\r
1727 if (PicoDrawMask & PDRAW_LAYERB_ON) memcpy(layer_str + 8, "B", 1);
\r
1728 if (PicoDrawMask & PDRAW_LAYERA_ON) memcpy(layer_str + 10, "A", 1);
\r
1729 if (PicoDrawMask & PDRAW_SPRITES_LOW_ON) memcpy(layer_str + 12, "spr_lo", 6);
\r
1730 if (PicoDrawMask & PDRAW_SPRITES_HI_ON) memcpy(layer_str + 19, "spr_hi", 6);
\r
1732 memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2);
\r
1733 emu_forcedFrame(0);
\r
1734 smalltext_out16(4, g_screen_height - 8, layer_str, 0xffff);
\r
1737 static void debug_menu_loop(void)
\r
1739 int inp, mode = 0;
\r
1740 int spr_offs = 0, dumped = 0;
\r
1747 case 0: plat_video_menu_begin();
\r
1748 tmp = PDebugMain();
\r
1749 emu_platformDebugCat(tmp);
\r
1750 draw_text_debug(tmp, 0, 0);
\r
1752 smalltext_out16(g_screen_width - 6 * me_mfont_h,
\r
1753 g_screen_height - me_mfont_h, "dumped", 0xffff);
\r
1757 case 1: draw_frame_debug(); break;
\r
1758 case 2: memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2);
\r
1759 emu_forcedFrame(0);
\r
1760 menu_darken_bg(g_screen_ptr, g_screen_width * g_screen_height, 0);
\r
1761 PDebugShowSpriteStats((unsigned short *)g_screen_ptr + (g_screen_height/2 - 240/2)*g_screen_width +
\r
1762 g_screen_width/2 - 320/2, g_screen_width); break;
\r
1763 case 3: memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2);
\r
1764 PDebugShowPalette(g_screen_ptr, g_screen_width);
\r
1765 PDebugShowSprite((unsigned short *)g_screen_ptr + g_screen_width*120 + g_screen_width/2 + 16,
\r
1766 g_screen_width, spr_offs);
\r
1767 draw_text_debug(PDebugSpriteList(), spr_offs, 6);
\r
1770 plat_video_menu_end();
\r
1772 inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R |
\r
1773 PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, 70);
\r
1774 if (inp & PBTN_MBACK) return;
\r
1775 if (inp & PBTN_L) { mode--; if (mode < 0) mode = 3; }
\r
1776 if (inp & PBTN_R) { mode++; if (mode > 3) mode = 0; }
\r
1780 if (inp & PBTN_MOK)
\r
1782 if (inp & PBTN_MA3) {
\r
1783 while (inp & PBTN_MA3)
\r
1784 inp = in_menu_wait_any(-1);
\r
1787 if ((inp & (PBTN_MA2|PBTN_LEFT)) == (PBTN_MA2|PBTN_LEFT)) {
\r
1788 mkdir("dumps", 0777);
\r
1790 while (inp & PBTN_MA2) inp = in_menu_wait_any(-1);
\r
1795 if (inp & PBTN_LEFT) PicoDrawMask ^= PDRAW_LAYERB_ON;
\r
1796 if (inp & PBTN_RIGHT) PicoDrawMask ^= PDRAW_LAYERA_ON;
\r
1797 if (inp & PBTN_DOWN) PicoDrawMask ^= PDRAW_SPRITES_LOW_ON;
\r
1798 if (inp & PBTN_UP) PicoDrawMask ^= PDRAW_SPRITES_HI_ON;
\r
1799 if (inp & PBTN_MOK) {
\r
1800 PsndOut = NULL; // just in case
\r
1801 PicoSkipFrame = 1;
\r
1803 PicoSkipFrame = 0;
\r
1804 while (inp & PBTN_MOK) inp = in_menu_wait_any(-1);
\r
1808 if (inp & PBTN_DOWN) spr_offs++;
\r
1809 if (inp & PBTN_UP) spr_offs--;
\r
1810 if (spr_offs < 0) spr_offs = 0;
\r
1816 // ------------ main menu ------------
\r
1818 static char *romsel_run(void)
\r
1820 char *ret, *sel_name;
\r
1822 sel_name = malloc(sizeof(rom_fname_loaded));
\r
1823 if (sel_name == NULL)
\r
1825 strcpy(sel_name, rom_fname_loaded);
\r
1827 ret = menu_loop_romsel(sel_name, sizeof(rom_fname_loaded));
\r
1832 static int main_menu_handler(menu_id id, int keys)
\r
1838 case MA_MAIN_RESUME_GAME:
\r
1842 case MA_MAIN_SAVE_STATE:
\r
1844 return menu_loop_savestate(0);
\r
1846 case MA_MAIN_LOAD_STATE:
\r
1848 return menu_loop_savestate(1);
\r
1850 case MA_MAIN_RESET_GAME:
\r
1856 case MA_MAIN_LOAD_ROM:
\r
1857 ret_name = romsel_run();
\r
1858 if (ret_name != NULL) {
\r
1859 lprintf("selected file: %s\n", ret_name);
\r
1860 engineState = PGS_ReloadRom;
\r
1864 case MA_MAIN_CREDITS:
\r
1865 draw_menu_credits();
\r
1866 in_menu_wait(PBTN_MOK|PBTN_MBACK, 70);
\r
1868 case MA_MAIN_EXIT:
\r
1869 engineState = PGS_Quit;
\r
1871 case MA_MAIN_PATCHES:
\r
1872 if (rom_loaded && PicoPatches) {
\r
1873 menu_loop_patches();
\r
1875 me_update_msg("Patches applied");
\r
1879 lprintf("%s: something unknown selected\n", __FUNCTION__);
\r
1886 static menu_entry e_menu_main[] =
\r
1888 mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler),
\r
1889 mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler),
\r
1890 mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler),
\r
1891 mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler),
\r
1892 mee_handler_id("Load new ROM/ISO", MA_MAIN_LOAD_ROM, main_menu_handler),
\r
1893 mee_handler_id("Change options", MA_MAIN_OPTIONS, menu_loop_options),
\r
1894 mee_handler_id("Configure controls", MA_MAIN_OPTIONS, menu_loop_keyconfig),
\r
1895 mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler),
\r
1896 mee_handler_id("Patches / GameGenie",MA_MAIN_PATCHES, main_menu_handler),
\r
1897 mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler),
\r
1901 void menu_loop(void)
\r
1903 static int sel = 0;
\r
1905 me_enable(e_menu_main, MA_MAIN_RESUME_GAME, rom_loaded);
\r
1906 me_enable(e_menu_main, MA_MAIN_SAVE_STATE, rom_loaded);
\r
1907 me_enable(e_menu_main, MA_MAIN_LOAD_STATE, rom_loaded);
\r
1908 me_enable(e_menu_main, MA_MAIN_RESET_GAME, rom_loaded);
\r
1909 me_enable(e_menu_main, MA_MAIN_PATCHES, PicoPatches != NULL);
\r
1911 plat_video_menu_enter(rom_loaded);
\r
1912 in_set_blocking(1);
\r
1913 me_loop(e_menu_main, &sel);
\r
1914 in_set_blocking(0);
\r
1916 if (rom_loaded && engineState == PGS_Menu) {
\r
1917 /* wait until menu, ok, back is released */
\r
1918 while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK));
\r
1919 engineState = PGS_Running;
\r
1923 // --------- CD tray close menu ----------
\r
1925 static int mh_tray_load_cd(menu_id id, int keys)
\r
1927 cd_img_type cd_type;
\r
1931 ret_name = romsel_run();
\r
1932 if (ret_name == NULL)
\r
1935 cd_type = emu_cdCheck(NULL, ret_name);
\r
1936 if (cd_type != CIT_NOT_CD)
\r
1937 ret = Insert_CD(ret_name, cd_type);
\r
1939 me_update_msg("Load failed, invalid CD image?");
\r
1943 engineState = PGS_RestartRun;
\r
1947 static int mh_tray_nothing(menu_id id, int keys)
\r
1952 static menu_entry e_menu_tray[] =
\r
1954 mee_label ("The unit is about to"),
\r
1955 mee_label ("close the CD tray."),
\r
1958 mee_handler("Load CD image", mh_tray_load_cd),
\r
1959 mee_handler("Insert nothing", mh_tray_nothing),
\r
1962 int menu_loop_tray(void)
\r
1964 int ret = 1, sel = 0;
\r
1966 plat_video_menu_enter(rom_loaded);
\r
1968 in_set_blocking(1);
\r
1969 me_loop(e_menu_tray, &sel);
\r
1970 in_set_blocking(0);
\r
1972 if (engineState != PGS_RestartRun) {
\r
1973 engineState = PGS_RestartRun;
\r
1974 ret = 0; /* no CD inserted */
\r
1977 while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK));
\r
1984 void me_update_msg(const char *msg)
\r
1986 strncpy(menu_error_msg, msg, sizeof(menu_error_msg));
\r
1987 menu_error_msg[sizeof(menu_error_msg) - 1] = 0;
\r
1989 menu_error_time = plat_get_ticks_ms();
\r
1990 lprintf("msg: %s\n", menu_error_msg);
\r
1993 // ------------ util ------------
\r
1995 /* TODO: rename */
\r
1996 void menu_darken_bg(void *dst, int pixels, int darker)
\r
1998 unsigned int *screen = dst;
\r
2004 unsigned int p = *screen;
\r
2005 *screen++ = ((p&0xf79ef79e)>>1) - ((p&0xc618c618)>>3);
\r
2012 unsigned int p = *screen;
\r
2013 *screen++ = (p&0xf79ef79e)>>1;
\r
2018 /* hidden options for config engine only */
\r
2019 static menu_entry e_menu_hidden[] =
\r
2021 mee_onoff("Accurate sprites", MA_OPT_ACC_SPRITES, PicoOpt, 0x080),
\r
2025 static menu_entry *e_menu_table[] =
\r
2028 e_menu_gfx_options,
\r
2029 e_menu_adv_options,
\r
2030 e_menu_cd_options,
\r
2035 static menu_entry *me_list_table = NULL;
\r
2036 static menu_entry *me_list_i = NULL;
\r
2038 menu_entry *me_list_get_first(void)
\r
2040 me_list_table = me_list_i = e_menu_table[0];
\r
2044 menu_entry *me_list_get_next(void)
\r
2049 if (me_list_i->name != NULL)
\r
2052 for (i = 0; i < array_size(e_menu_table); i++)
\r
2053 if (me_list_table == e_menu_table[i])
\r
2056 if (i + 1 < array_size(e_menu_table))
\r
2057 me_list_table = me_list_i = e_menu_table[i + 1];
\r
2059 me_list_table = me_list_i = NULL;
\r