X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=common%2Fmenu.c;h=4ee5c1977b0ad4bd22c820d95d1b8c3221787a51;hb=b6072c177f57cdcb32cfd5eee53b7c178f89c5d3;hp=5b0474a35be3689522e242fc0bba7c0e93adc382;hpb=d227571356afae37e5ed67b1356b2a5a310bd204;p=libpicofe.git diff --git a/common/menu.c b/common/menu.c index 5b0474a..4ee5c19 100644 --- a/common/menu.c +++ b/common/menu.c @@ -1,4 +1,4 @@ -// (c) Copyright 2006-2009 notaz, All rights reserved. +// (c) Copyright 2006-2010 notaz, All rights reserved. // Free for non-commercial use. // For commercial use, separate licencing terms must be obtained. @@ -25,10 +25,17 @@ static char static_buff[64]; static int menu_error_time = 0; char menu_error_msg[64] = { 0, }; +void *g_menuscreen_ptr; +void *g_menubg_src_ptr; void *g_menubg_ptr; #ifndef UIQ3 +#if !SCREEN_SIZE_FIXED +int g_menuscreen_w = MSCREEN_WIDTH; +int g_menuscreen_h = MSCREEN_HEIGHT; +#endif + static unsigned char *menu_font_data = NULL; static int menu_text_color = 0xffff; // default to white static int menu_sel_color = -1; // disabled @@ -46,7 +53,7 @@ static const int me_sfont_w = 6, me_sfont_h = 10; static void text_out16_(int x, int y, const char *text, int color) { int i, lh, tr, tg, tb, len; - unsigned short *dest = (unsigned short *)g_screen_ptr + x + y * g_screen_width; + unsigned short *dest = (unsigned short *)g_menuscreen_ptr + x + y * g_menuscreen_w; tr = (color & 0xf800) >> 8; tg = (color & 0x07e0) >> 3; tb = (color & 0x001f) << 3; @@ -66,8 +73,8 @@ static void text_out16_(int x, int y, const char *text, int color) } lh = me_mfont_h; - if (y + lh > g_screen_height) - lh = g_screen_height - y; + if (y + lh > g_menuscreen_h) + lh = g_menuscreen_h - y; for (i = 0; i < len; i++) { @@ -75,7 +82,7 @@ static void text_out16_(int x, int y, const char *text, int color) unsigned short *dst = dest; int u, l; - for (l = 0; l < lh; l++, dst += g_screen_width - me_mfont_w) + for (l = 0; l < lh; l++, dst += g_menuscreen_w - me_mfont_w) { for (u = me_mfont_w / 2; u > 0; u--, src++) { @@ -106,7 +113,7 @@ void text_out16(int x, int y, const char *texto, ...) { va_list args; char buffer[256]; - int maxw = (g_screen_width - x) / me_mfont_w; + int maxw = (g_menuscreen_w - x) / me_mfont_w; if (maxw < 0) return; @@ -139,7 +146,7 @@ static void smalltext_out16_(int x, int y, const char *texto, int color) break; src = fontdata6x8[c]; - dst = (unsigned short *)g_screen_ptr + x + y * g_screen_width; + dst = (unsigned short *)g_menuscreen_ptr + x + y * g_menuscreen_w; while (h--) { @@ -154,7 +161,7 @@ static void smalltext_out16_(int x, int y, const char *texto, int color) dst += multiplier; } - dst += g_screen_width - me_sfont_w; + dst += g_menuscreen_w - me_sfont_w; } src++; } @@ -164,7 +171,7 @@ static void smalltext_out16_(int x, int y, const char *texto, int color) static void smalltext_out16(int x, int y, const char *texto, int color) { char buffer[128]; - int maxw = (g_screen_width - x) / 6; + int maxw = (g_menuscreen_w - x) / me_sfont_w; if (maxw < 0) return; @@ -187,13 +194,13 @@ static void menu_draw_selection(int x, int y, int w) if (menu_sel_color < 0) return; // no selection hilight if (y > 0) y--; - dest = (unsigned short *)g_screen_ptr + x + y * g_screen_width + 14; + dest = (unsigned short *)g_menuscreen_ptr + x + y * g_menuscreen_w + me_mfont_w * 2 - 2; for (h = me_mfont_h + 1; h > 0; h--) { dst = dest; - for (i = w - 14; i > 0; i--) + for (i = w - (me_mfont_w * 2 - 2); i > 0; i--) *dst++ = menu_sel_color; - dest += g_screen_width; + dest += g_menuscreen_w; } } @@ -268,12 +275,13 @@ void menu_init(void) // load custom font and selector (stored as 1st symbol in font table) emu_make_path(buff, "skin/font.png", sizeof(buff)); - readpng(menu_font_data, buff, READPNG_FONT); + readpng(menu_font_data, buff, READPNG_FONT, + MENU_X2 ? 256 : 128, MENU_X2 ? 320 : 160); // default selector symbol is '>' memcpy(menu_font_data, menu_font_data + ((int)'>') * me_mfont_w * me_mfont_h / 2, me_mfont_w * me_mfont_h / 2); emu_make_path(buff, "skin/selector.png", sizeof(buff)); - readpng(menu_font_data, buff, READPNG_SELECTOR); + readpng(menu_font_data, buff, READPNG_SELECTOR, me_mfont_w, me_mfont_h); // load custom colors emu_make_path(buff, "skin/skin.txt", sizeof(buff)); @@ -334,8 +342,12 @@ static void menu_enter(int is_rom_loaded) { if (is_rom_loaded) { + void *src = g_menubg_src_ptr; + if (src == NULL) + src = g_menuscreen_ptr; + // darken the active framebuffer - menu_darken_bg(g_menubg_ptr, g_screen_ptr, g_screen_width * g_screen_height, 1); + menu_darken_bg(g_menubg_ptr, src, g_menuscreen_w * g_menuscreen_h, 1); } else { @@ -343,8 +355,8 @@ static void menu_enter(int is_rom_loaded) // should really only happen once, on startup.. emu_make_path(buff, "skin/background.png", sizeof(buff)); - if (readpng(g_menubg_ptr, buff, READPNG_BG) < 0) - memset(g_menubg_ptr, 0, g_screen_width * g_screen_height * 2); + if (readpng(g_menubg_ptr, buff, READPNG_BG, g_menuscreen_w, g_menuscreen_h) < 0) + memset(g_menubg_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2); } plat_video_menu_enter(is_rom_loaded); @@ -378,11 +390,11 @@ static int me_count(const menu_entry *ent) static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void)) { - const menu_entry *ent; + const menu_entry *ent, *ent_sel = entries; int x, y, w = 0, h = 0; int offs, col2_offs = 27 * me_mfont_w; + int vi_sel_ln = 0; const char *name; - int asel = 0; int i, n; /* calculate size of menu rect */ @@ -393,8 +405,10 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void)) if (!ent->enabled) continue; - if (i == sel) - asel = n; + if (i == sel) { + ent_sel = ent; + vi_sel_ln = n; + } name = NULL; wt = strlen(ent->name) * me_mfont_w; @@ -410,9 +424,12 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void)) wt = col2_offs; switch (ent->beh) { - case MB_NONE: break; + case MB_NONE: + break; case MB_OPT_ONOFF: - case MB_OPT_RANGE: wt += me_mfont_w * 3; break; + case MB_OPT_RANGE: + wt += me_mfont_w * 3; + break; case MB_OPT_CUSTOM: case MB_OPT_CUSTONOFF: case MB_OPT_CUSTRANGE: @@ -423,6 +440,9 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void)) if (name != NULL) wt += (strlen(name) + offs) * me_mfont_w; break; + case MB_OPT_ENUM: + wt += 10 * me_mfont_w; + break; } } @@ -433,25 +453,28 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void)) h = n * me_mfont_h; w += me_mfont_w * 2; /* selector */ - if (w > g_screen_width) { - lprintf("width %d > %d\n", w, g_screen_width); - w = g_screen_width; + if (w > g_menuscreen_w) { + lprintf("width %d > %d\n", w, g_menuscreen_w); + w = g_menuscreen_w; } - if (h > g_screen_height) { - lprintf("height %d > %d\n", w, g_screen_height); - h = g_screen_height; + if (h > g_menuscreen_h) { + lprintf("height %d > %d\n", w, g_menuscreen_h); + h = g_menuscreen_h; } - x = g_screen_width / 2 - w / 2; - y = g_screen_height / 2 - h / 2; + x = g_menuscreen_w / 2 - w / 2; + y = g_menuscreen_h / 2 - h / 2; /* draw */ plat_video_menu_begin(); - menu_draw_selection(x, y + asel * me_mfont_h, w); + menu_draw_selection(x, y + vi_sel_ln * me_mfont_h, w); x += me_mfont_w * 2; for (ent = entries; ent->name; ent++) { + const char **names; + int len; + if (!ent->enabled) continue; @@ -482,21 +505,44 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void)) if (name != NULL) text_out16(x + col2_offs + offs * me_mfont_w, y, "%s", name); break; + case MB_OPT_ENUM: + names = (const char **)ent->data; + offs = 0; + for (i = 0; names[i] != NULL; i++) { + len = strlen(names[i]); + if (len > 10) + offs = 10 - len - 2; + if (i == *(int *)ent->var) { + text_out16(x + col2_offs + offs * me_mfont_w, y, "%s", names[i]); + break; + } + } + break; } y += me_mfont_h; } - /* display message if we have one */ + /* display help or message if we have one */ + h = (g_menuscreen_h - h) / 2; // bottom area height if (menu_error_msg[0] != 0) { - if (g_screen_height - h >= 2 * me_mfont_h) - text_out16(5, g_screen_height - me_mfont_h - 4, menu_error_msg); + if (h >= me_mfont_h + 4) + text_out16(5, g_menuscreen_h - me_mfont_h - 4, menu_error_msg); else lprintf("menu msg doesn't fit!\n"); if (plat_get_ticks_ms() - menu_error_time > 2048) menu_error_msg[0] = 0; } + else if (ent_sel->help != NULL) { + const char *tmp = ent_sel->help; + int l; + for (l = 0; tmp != NULL && *tmp != 0; l++) + tmp = strchr(tmp + 1, '\n'); + if (h >= l * me_sfont_h + 4) + for (tmp = ent_sel->help; l > 0; l--, tmp = strchr(tmp, '\n') + 1) + smalltext_out16(5, g_menuscreen_h - (l * me_sfont_h + 4), tmp, 0xffff); + } if (draw_more != NULL) draw_more(); @@ -506,6 +552,7 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void)) static int me_process(menu_entry *entry, int is_next, int is_lr) { + const char **names; int c; switch (entry->beh) { @@ -522,6 +569,16 @@ static int me_process(menu_entry *entry, int is_next, int is_lr) if (*(int *)entry->var > (int)entry->max) *(int *)entry->var = (int)entry->min; return 1; + case MB_OPT_ENUM: + names = (const char **)entry->data; + for (c = 0; names[c] != NULL; c++) + ; + *(int *)entry->var += is_next ? 1 : -1; + if (*(int *)entry->var < 0) + *(int *)entry->var = 0; + if (*(int *)entry->var >= c) + *(int *)entry->var = c - 1; + return 1; default: return 0; } @@ -581,12 +638,13 @@ static void me_loop(menu_entry *menu, int *menu_sel, void (*draw_more)(void)) continue; } - if (inp & (PBTN_MOK|PBTN_LEFT|PBTN_RIGHT)) + if (inp & (PBTN_MOK|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R)) { - if (menu[sel].handler != NULL) { + /* require PBTN_MOK for MB_NONE */ + if (menu[sel].handler != NULL && (menu[sel].beh != MB_NONE || (inp & PBTN_MOK))) { ret = menu[sel].handler(menu[sel].id, inp); if (ret) break; - menu_sel_max = me_count(menu) - 1; /* might change */ + menu_sel_max = me_count(menu) - 1; /* might change, so update */ } } } @@ -624,14 +682,14 @@ static void draw_menu_credits(void) p++; } - x = g_screen_width / 2 - w * me_mfont_w / 2; - y = g_screen_height / 2 - h * me_mfont_h / 2; + x = g_menuscreen_w / 2 - w * me_mfont_w / 2; + y = g_menuscreen_h / 2 - h * me_mfont_h / 2; if (x < 0) x = 0; if (y < 0) y = 0; plat_video_menu_begin(); - for (p = creds; *p != 0 && y <= g_screen_height - me_mfont_h; y += me_mfont_h) { + for (p = creds; *p != 0 && y <= g_menuscreen_h - me_mfont_h; y += me_mfont_h) { text_out16(x, y, p); for (; *p != 0 && *p != '\n'; p++) @@ -649,30 +707,30 @@ static int cdload_called = 0; static void load_progress_cb(int percent) { - int ln, len = percent * g_screen_width / 100; - unsigned short *dst = (unsigned short *)g_screen_ptr + g_screen_width * 10 * 2; + int ln, len = percent * g_menuscreen_w / 100; + unsigned short *dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2; - if (len > g_screen_width) - len = g_screen_width; - for (ln = 10 - 2; ln > 0; ln--, dst += g_screen_width) + if (len > g_menuscreen_w) + len = g_menuscreen_w; + for (ln = me_sfont_h - 2; ln > 0; ln--, dst += g_menuscreen_w) memset(dst, 0xff, len * 2); plat_video_menu_end(); } static void cdload_progress_cb(const char *fname, int percent) { - int ln, len = percent * g_screen_width / 100; - unsigned short *dst = (unsigned short *)g_screen_ptr + g_screen_width * 10 * 2; + int ln, len = percent * g_menuscreen_w / 100; + unsigned short *dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2; - memset(dst, 0xff, g_screen_width * (me_sfont_h - 2) * 2); + memset(dst, 0xff, g_menuscreen_w * (me_sfont_h - 2) * 2); smalltext_out16(1, 3 * me_sfont_h, "Processing CD image / MP3s", 0xffff); smalltext_out16(1, 4 * me_sfont_h, fname, 0xffff); - dst += g_screen_width * me_sfont_h * 3; + dst += g_menuscreen_w * me_sfont_h * 3; - if (len > g_screen_width) - len = g_screen_width; - for (ln = (me_sfont_h - 2); ln > 0; ln--, dst += g_screen_width) + if (len > g_menuscreen_w) + len = g_menuscreen_w; + for (ln = (me_sfont_h - 2); ln > 0; ln--, dst += g_menuscreen_w) memset(dst, 0xff, len * 2); plat_video_menu_end(); @@ -720,13 +778,13 @@ static void do_delete(const char *fpath, const char *fname) plat_video_menu_begin(); if (!rom_loaded) - menu_darken_bg(g_screen_ptr, g_screen_ptr, g_screen_width * g_screen_height, 0); + menu_darken_bg(g_menuscreen_ptr, g_menuscreen_ptr, g_menuscreen_w * g_menuscreen_h, 0); len = strlen(fname); - if (len > g_screen_width/6) - len = g_screen_width/6; + if (len > g_menuscreen_w / me_sfont_w) + len = g_menuscreen_w / me_sfont_w; - mid = g_screen_width / 2; + mid = g_menuscreen_w / 2; text_out16(mid - me_mfont_w * 15 / 2, 8 * me_mfont_h, "About to delete"); smalltext_out16(mid - len * me_sfont_w / 2, 9 * me_mfont_h + 5, fname, 0xbdff); text_out16(mid - me_mfont_w * 13 / 2, 11 * me_mfont_h, "Are you sure?"); @@ -770,7 +828,7 @@ static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel) int max_cnt, start, i, x, pos; void *darken_ptr; - max_cnt = g_screen_height / me_sfont_h; + max_cnt = g_menuscreen_h / me_sfont_h; start = max_cnt / 2 - sel; n--; // exclude current dir (".") @@ -779,8 +837,8 @@ static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel) // if (!rom_loaded) // menu_darken_bg(gp2x_screen, 320*240, 0); - darken_ptr = (short *)g_screen_ptr + g_screen_width * max_cnt/2 * me_sfont_h; - menu_darken_bg(darken_ptr, darken_ptr, g_screen_width * me_sfont_h * 8 / 10, 0); + darken_ptr = (short *)g_menuscreen_ptr + g_menuscreen_w * max_cnt/2 * me_sfont_h; + menu_darken_bg(darken_ptr, darken_ptr, g_menuscreen_w * me_sfont_h * 8 / 10, 0); x = 5 + me_mfont_w + 1; if (start - 2 >= 0) @@ -977,7 +1035,7 @@ static void draw_patchlist(int sel) { int max_cnt, start, i, pos, active; - max_cnt = g_screen_height / 10; + max_cnt = g_menuscreen_h / me_sfont_h; start = max_cnt / 2 - sel; plat_video_menu_begin(); @@ -987,8 +1045,8 @@ static void draw_patchlist(int sel) if (pos < 0) continue; if (pos >= max_cnt) break; active = PicoPatches[i].active; - smalltext_out16(14, pos * me_sfont_h, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff); - smalltext_out16(14+6*4, pos * me_sfont_h, PicoPatches[i].name, active ? 0xfff6 : 0xffff); + smalltext_out16(14, pos * me_sfont_h, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff); + smalltext_out16(14 + me_sfont_w*4, pos * me_sfont_h, PicoPatches[i].name, active ? 0xfff6 : 0xffff); } pos = start + i; if (pos < max_cnt) @@ -1051,7 +1109,7 @@ static void draw_savestate_bg(int slot) PicoStateLoadGfx(fname); /* do a frame and fetch menu bg */ - pemu_forced_frame(POPT_EN_SOFTSCALE); + pemu_forced_frame(POPT_EN_SOFTSCALE, 0); menu_enter(1); PicoTmpStateRestore(tmp_state); @@ -1066,9 +1124,9 @@ static void draw_savestate_menu(int menu_sel, int is_loading) w = (13 + 2) * me_mfont_w; h = (1+2+10+1) * me_mfont_h; - x = g_screen_width / 2 - w / 2; + x = g_menuscreen_w / 2 - w / 2; if (x < 0) x = 0; - y = g_screen_height / 2 - h / 2; + y = g_menuscreen_h / 2 - h / 2; if (y < 0) y = 0; plat_video_menu_begin(); @@ -1210,8 +1268,8 @@ static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_ int x, y, w, i; w = ((player_idx >= 0) ? 20 : 30) * me_mfont_w; - x = g_screen_width / 2 - w / 2; - y = (g_screen_height - 4 * me_mfont_h) / 2 - (2 + opt_cnt) * me_mfont_h / 2; + x = g_menuscreen_w / 2 - w / 2; + y = (g_menuscreen_h - 4 * me_mfont_h) / 2 - (2 + opt_cnt) * me_mfont_h / 2; if (x < me_mfont_w * 2) x = me_mfont_w * 2; @@ -1232,23 +1290,23 @@ static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_ w = strlen(dev_name) * me_mfont_w; if (w < 30 * me_mfont_w) w = 30 * me_mfont_w; - if (w > g_screen_width) - w = g_screen_width; + if (w > g_menuscreen_w) + w = g_menuscreen_w; - x = g_screen_width / 2 - w / 2; + x = g_menuscreen_w / 2 - w / 2; if (!is_bind) { snprintf(buff2, sizeof(buff2), "%s", in_get_key_name(-1, -PBTN_MOK)); snprintf(buff, sizeof(buff), "%s - bind, %s - clear", buff2, in_get_key_name(-1, -PBTN_MA2)); - text_out16(x, g_screen_height - 4 * me_mfont_h, buff); + text_out16(x, g_menuscreen_h - 4 * me_mfont_h, buff); } else - text_out16(x, g_screen_height - 4 * me_mfont_h, "Press a button to bind/unbind"); + text_out16(x, g_menuscreen_h - 4 * me_mfont_h, "Press a button to bind/unbind"); if (dev_count > 1) { - text_out16(x, g_screen_height - 3 * me_mfont_h, dev_name); - text_out16(x, g_screen_height - 2 * me_mfont_h, "Press left/right for other devs"); + text_out16(x, g_menuscreen_h - 3 * me_mfont_h, dev_name); + text_out16(x, g_menuscreen_h - 2 * me_mfont_h, "Press left/right for other devs"); } plat_video_menu_end(); @@ -1301,11 +1359,13 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_ break; } continue; - case PBTN_MBACK: return; + case PBTN_MBACK: + return; case PBTN_MOK: if (sel >= opt_cnt) return; - while (in_menu_wait_any(30) & PBTN_MOK); + while (in_menu_wait_any(30) & PBTN_MOK) + ; break; case PBTN_MA2: in_unbind_all(dev_id, opts[sel].mask << mask_shift, bindtype); @@ -1327,7 +1387,10 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_ in_get_dev_info(dev_id, IN_INFO_DOES_COMBOS)) unbind = 0; - in_bind_key(dev_id, kc, opts[sel].mask << mask_shift, bindtype, unbind); + if (unbind) + in_unbind_all(dev_id, opts[sel].mask << mask_shift, bindtype); + + in_bind_key(dev_id, kc, opts[sel].mask << mask_shift, bindtype, 0); } } @@ -1405,7 +1468,7 @@ static const char *mgn_dev_name(menu_id id, int *offs) } static int mh_saveloadcfg(menu_id id, int keys); -static const char *mgn_savecfg(menu_id id, int *offs); +static const char *mgn_saveloadcfg(menu_id id, int *offs); static menu_entry e_menu_keyconfig[] = { @@ -1414,8 +1477,8 @@ static menu_entry e_menu_keyconfig[] = mee_handler_id("Emulator controls", MA_CTRL_EMU, key_config_loop_wrap), mee_onoff ("6 button pad", MA_OPT_6BUTTON_PAD, PicoOpt, POPT_6BTN_PAD), mee_range ("Turbo rate", MA_CTRL_TURBO_RATE, currentConfig.turbo_rate, 1, 30), - mee_handler_mkname_id(MA_OPT_SAVECFG, mh_saveloadcfg, mgn_savecfg), - mee_handler_id("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_saveloadcfg), + mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg), + mee_cust_nosave("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg), mee_label (""), mee_label ("Input devices:"), mee_label_mk (MA_CTRL_DEV_FIRST, mgn_dev_name), @@ -1464,15 +1527,25 @@ static int mh_cdopt_ra(menu_id id, int keys) return 0; } +static const char h_cdleds[] = "Show power/CD LEDs of emulated console"; +static const char h_cdda[] = "Play audio tracks from mp3s/wavs/bins"; +static const char h_cdpcm[] = "Emulate PCM audio chip for effects/voices/music"; +static const char h_srcart[] = "Emulate the save RAM cartridge accessory\n" + "most games don't need this"; +static const char h_scfx[] = "Emulate scale/rotate ASIC chip for graphics effects\n" + "disable to improve performance"; +static const char h_bsync[] = "More accurate mode for CPUs (needed for some games)\n" + "disable to improve performance"; + static menu_entry e_menu_cd_options[] = { - mee_onoff("CD LEDs", MA_CDOPT_LEDS, currentConfig.EmuOpt, EOPT_EN_CD_LEDS), - mee_onoff("CDDA audio", MA_CDOPT_CDDA, PicoOpt, POPT_EN_MCD_CDDA), - mee_onoff("PCM audio", MA_CDOPT_PCM, PicoOpt, POPT_EN_MCD_PCM), - mee_cust ("ReadAhead buffer", MA_CDOPT_READAHEAD, mh_cdopt_ra, mgn_cdopt_ra), - mee_onoff("SaveRAM cart", MA_CDOPT_SAVERAM, PicoOpt, POPT_EN_MCD_RAMCART), - mee_onoff("Scale/Rot. fx (slow)", MA_CDOPT_SCALEROT_CHIP, PicoOpt, POPT_EN_MCD_GFX), - mee_onoff("Better sync (slow)", MA_CDOPT_BETTER_SYNC, PicoOpt, POPT_EN_MCD_PSYNC), + mee_onoff_h("CD LEDs", MA_CDOPT_LEDS, currentConfig.EmuOpt, EOPT_EN_CD_LEDS, h_cdleds), + mee_onoff_h("CDDA audio", MA_CDOPT_CDDA, PicoOpt, POPT_EN_MCD_CDDA, h_cdda), + mee_onoff_h("PCM audio", MA_CDOPT_PCM, PicoOpt, POPT_EN_MCD_PCM, h_cdpcm), + mee_cust ("ReadAhead buffer", MA_CDOPT_READAHEAD, mh_cdopt_ra, mgn_cdopt_ra), + mee_onoff_h("SaveRAM cart", MA_CDOPT_SAVERAM, PicoOpt, POPT_EN_MCD_RAMCART, h_srcart), + mee_onoff_h("Scale/Rot. fx (slow)", MA_CDOPT_SCALEROT_CHIP, PicoOpt, POPT_EN_MCD_GFX, h_scfx), + mee_onoff_h("Better sync (slow)", MA_CDOPT_BETTER_SYNC, PicoOpt, POPT_EN_MCD_PSYNC, h_bsync), mee_end, }; @@ -1485,51 +1558,62 @@ static int menu_loop_cd_options(menu_id id, int keys) // ------------ 32X options menu ------------ -static const char *get_rname(const char **rn, int val, int *offs) +#ifndef NO_32X + +// convert from multiplier of VClk +static int mh_opt_sh2cycles(menu_id id, int keys) { - int i, len, found = -1, maxlen = 0; + int *mul = (id == MA_32XOPT_MSH2_CYCLES) ? &p32x_msh2_multiplier : &p32x_ssh2_multiplier; - for (i = 0; rn[i] != NULL; i++) { - len = strlen(rn[i]); - if (len > maxlen) - maxlen = len; - if (i == val) - found = i; - } + if (keys & (PBTN_LEFT|PBTN_RIGHT)) + *mul += (keys & PBTN_LEFT) ? -10 : 10; + if (keys & (PBTN_L|PBTN_R)) + *mul += (keys & PBTN_L) ? -100 : 100; - *offs = 3 - maxlen; - if (found >= 0) - return rn[found]; - return "???"; + if (*mul < 1) + *mul = 1; + else if (*mul > (10 << SH2_MULTI_SHIFT)) + *mul = 10 << SH2_MULTI_SHIFT; + + return 0; } -static const char *mgn_opt_renderer32x(menu_id id, int *offs) +static const char *mgn_opt_sh2cycles(menu_id id, int *offs) { - return get_rname(renderer_names32x, currentConfig.renderer32x, offs); + int mul = (id == MA_32XOPT_MSH2_CYCLES) ? p32x_msh2_multiplier : p32x_ssh2_multiplier; + + sprintf(static_buff, "%d", 7670 * mul >> SH2_MULTI_SHIFT); + return static_buff; } +static const char h_32x_enable[] = "Enable emulation of the 32X addon"; +static const char h_pwm[] = "Disabling may improve performance, but break sound"; +static const char h_sh2cycles[] = "Cycles/millisecond (similar to DOSBox)\n" + "lower values speed up emulation but break games\n" + "at least 11000 recommended for compatibility"; + static menu_entry e_menu_32x_options[] = { - mee_onoff ("32X enabled", MA_32XOPT_ENABLE_32X, PicoOpt, POPT_EN_32X), - mee_range_cust("32X renderer", MA_32XOPT_RENDERER, currentConfig.renderer32x, 0, 0, mgn_opt_renderer32x), - mee_onoff ("PWM sound", MA_32XOPT_PWM, PicoOpt, POPT_EN_PWM), + mee_onoff_h ("32X enabled", MA_32XOPT_ENABLE_32X, PicoOpt, POPT_EN_32X, h_32x_enable), + mee_enum ("32X renderer", MA_32XOPT_RENDERER, currentConfig.renderer32x, renderer_names32x), + mee_onoff_h ("PWM sound", MA_32XOPT_PWM, PicoOpt, POPT_EN_PWM, h_pwm), + mee_cust_h ("Master SH2 cycles", MA_32XOPT_MSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles), + mee_cust_h ("Slave SH2 cycles", MA_32XOPT_SSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles), mee_end, }; static int menu_loop_32x_options(menu_id id, int keys) { static int sel = 0; - int i, c; - - for (c = 0; renderer_names32x != NULL && renderer_names32x[c] != NULL; ) - c++; - i = me_id2offset(e_menu_32x_options, MA_32XOPT_RENDERER); - e_menu_32x_options[i].max = c > 0 ? (c - 1) : 0; + me_enable(e_menu_32x_options, MA_32XOPT_RENDERER, renderer_names32x[0] != NULL); me_loop(e_menu_32x_options, &sel, NULL); + return 0; } +#endif + // ------------ adv options menu ------------ static menu_entry e_menu_adv_options[] = @@ -1556,14 +1640,9 @@ static int menu_loop_adv_options(menu_id id, int keys) // ------------ gfx options menu ------------ -static const char *mgn_opt_renderer(menu_id id, int *offs) -{ - return get_rname(renderer_names, currentConfig.renderer, offs); -} - static menu_entry e_menu_gfx_options[] = { - mee_range_cust("Renderer", MA_OPT_RENDERER, currentConfig.renderer, 0, 0, mgn_opt_renderer), + mee_enum("Renderer", MA_OPT_RENDERER, currentConfig.renderer, renderer_names), MENU_OPTIONS_GFX mee_end, }; @@ -1571,15 +1650,10 @@ static menu_entry e_menu_gfx_options[] = static int menu_loop_gfx_options(menu_id id, int keys) { static int sel = 0; - int i, c; - - for (c = 0; renderer_names != NULL && renderer_names[c] != NULL; ) - c++; - i = me_id2offset(e_menu_gfx_options, MA_OPT_RENDERER); - e_menu_gfx_options[i].max = c > 0 ? (c - 1) : 0; - me_enable(e_menu_gfx_options, MA_OPT_RENDERER, renderer_names != NULL); + me_enable(e_menu_gfx_options, MA_OPT_RENDERER, renderer_names[0] != NULL); me_loop(e_menu_gfx_options, &sel, NULL); + return 0; } @@ -1643,8 +1717,6 @@ static void region_prevnext(int right) static int mh_opt_misc(menu_id id, int keys) { - int i; - switch (id) { case MA_OPT_SOUND_QUALITY: PsndRate = sndrate_prevnext(PsndRate, keys & PBTN_RIGHT); @@ -1652,14 +1724,6 @@ static int mh_opt_misc(menu_id id, int keys) case MA_OPT_REGION: region_prevnext(keys & PBTN_RIGHT); break; - case MA_OPT_CONFIRM_STATES: - i = ((currentConfig.EmuOpt>>9)&1) | ((currentConfig.EmuOpt>>10)&2); - i += (keys & PBTN_LEFT) ? -1 : 1; - if (i < 0) i = 0; else if (i > 3) i = 3; - i |= i << 1; i &= ~2; - currentConfig.EmuOpt &= ~0xa00; - currentConfig.EmuOpt |= i << 9; - break; default: break; } @@ -1687,8 +1751,8 @@ static int mh_saveloadcfg(menu_id id, int keys) me_update_msg("failed to write config"); break; case MA_OPT_LOADCFG: - ret = emu_read_config(1, 1); - if (!ret) ret = emu_read_config(0, 1); + ret = emu_read_config(rom_fname_loaded, 1); + if (!ret) ret = emu_read_config(NULL, 1); if (ret) me_update_msg("config loaded"); else me_update_msg("failed to load config"); break; @@ -1749,29 +1813,17 @@ static const char *mgn_opt_region(menu_id id, int *offs) } } -static const char *mgn_opt_c_saves(menu_id id, int *offs) +static const char *mgn_saveloadcfg(menu_id id, int *offs) { - switch ((currentConfig.EmuOpt >> 9) & 5) { - default: return "OFF"; - case 1: return "writes"; - case 4: return "loads"; - case 5: return "both"; - } -} - -static const char *mgn_savecfg(menu_id id, int *offs) -{ - strcpy(static_buff, "Save global config"); + static_buff[0] = 0; if (config_slot != 0) - sprintf(static_buff + strlen(static_buff), " (profile: %i)", config_slot); + sprintf(static_buff, "[%i]", config_slot); return static_buff; } -static const char *mgn_loadcfg(menu_id id, int *offs) -{ - sprintf(static_buff, "Load cfg from profile %i", config_slot); - return static_buff; -} +static const char *men_confirm_save[] = { "OFF", "writes", "loads", "both", NULL }; +static const char h_confirm_save[] = "Ask for confirmation when overwriting save,\n" + "loading state or both"; static menu_entry e_menu_options[] = { @@ -1781,15 +1833,17 @@ static menu_entry e_menu_options[] = mee_onoff ("Show FPS", MA_OPT_SHOW_FPS, currentConfig.EmuOpt, EOPT_SHOW_FPS), mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, EOPT_EN_SOUND), mee_cust ("Sound Quality", MA_OPT_SOUND_QUALITY, mh_opt_misc, mgn_opt_sound), - mee_cust ("Confirm savestate", MA_OPT_CONFIRM_STATES,mh_opt_misc, mgn_opt_c_saves), - mee_range (cpu_clk_name, MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 900), + mee_enum_h ("Confirm savestate", MA_OPT_CONFIRM_STATES,currentConfig.confirm_save, men_confirm_save, h_confirm_save), + mee_range ("", MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 900), mee_handler ("[Display options]", menu_loop_gfx_options), mee_handler ("[Sega/Mega CD options]", menu_loop_cd_options), +#ifndef NO_32X mee_handler ("[32X options]", menu_loop_32x_options), +#endif mee_handler ("[Advanced options]", menu_loop_adv_options), - mee_handler_mkname_id(MA_OPT_SAVECFG, mh_saveloadcfg, mgn_savecfg), - mee_handler_id("Save cfg for current game only", MA_OPT_SAVECFG_GAME, mh_saveloadcfg), - mee_handler_mkname_id(MA_OPT_LOADCFG, mh_saveloadcfg, mgn_loadcfg), + mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg), + mee_cust_nosave("Save cfg for loaded game",MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg), + mee_cust_nosave("Load cfg from profile", MA_OPT_LOADCFG, mh_saveloadcfg, mgn_saveloadcfg), mee_handler ("Restore defaults", mh_restore_defaults), mee_end, }; @@ -1797,7 +1851,10 @@ static menu_entry e_menu_options[] = static int menu_loop_options(menu_id id, int keys) { static int sel = 0; + int i; + i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS); + e_menu_options[i].enabled = e_menu_options[i].name ? 1 : 0; me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, rom_loaded); me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current); @@ -1843,7 +1900,7 @@ static void draw_text_debug(const char *str, int skip, int from) } str = p; - for (line = from; line < g_screen_height / me_sfont_h; line++) + for (line = from; line < g_menuscreen_h / me_sfont_h; line++) { smalltext_out16(1, line * me_sfont_h, str, 0xffff); while (*p && *p != '\n') @@ -1869,10 +1926,10 @@ static void draw_frame_debug(void) if (PicoDrawMask & PDRAW_SPRITES_HI_ON) memcpy(layer_str + 19, "spr_hi", 6); if (PicoDrawMask & PDRAW_32X_ON) memcpy(layer_str + 26, "32x", 4); - memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2); - pemu_forced_frame(0); + memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2); + pemu_forced_frame(0, 0); smalltext_out16(4, 1, "build: r" REVISION " "__DATE__ " " __TIME__ " " COMPILER, 0xffff); - smalltext_out16(4, g_screen_height - me_sfont_h, layer_str, 0xffff); + smalltext_out16(4, g_menuscreen_h - me_sfont_h, layer_str, 0xffff); } static void debug_menu_loop(void) @@ -1890,21 +1947,23 @@ static void debug_menu_loop(void) plat_debug_cat(tmp); draw_text_debug(tmp, 0, 0); if (dumped) { - smalltext_out16(g_screen_width - 6 * me_sfont_h, - g_screen_height - me_mfont_h, "dumped", 0xffff); + smalltext_out16(g_menuscreen_w - 6 * me_sfont_h, + g_menuscreen_h - me_mfont_h, "dumped", 0xffff); dumped = 0; } break; - case 1: draw_frame_debug(); break; - case 2: memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2); - pemu_forced_frame(0); - menu_darken_bg(g_screen_ptr, g_screen_ptr, g_screen_width * g_screen_height, 0); - PDebugShowSpriteStats((unsigned short *)g_screen_ptr + (g_screen_height/2 - 240/2)*g_screen_width + - g_screen_width/2 - 320/2, g_screen_width); break; - case 3: memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2); - PDebugShowPalette(g_screen_ptr, g_screen_width); - PDebugShowSprite((unsigned short *)g_screen_ptr + g_screen_width*120 + g_screen_width/2 + 16, - g_screen_width, spr_offs); + case 1: draw_frame_debug(); + break; + case 2: memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2); + pemu_forced_frame(0, 1); + menu_darken_bg(g_menuscreen_ptr, g_menuscreen_ptr, g_menuscreen_w * g_menuscreen_h, 0); + PDebugShowSpriteStats((unsigned short *)g_menuscreen_ptr + (g_menuscreen_h/2 - 240/2)*g_menuscreen_w + + g_menuscreen_w/2 - 320/2, g_menuscreen_w); + break; + case 3: memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2); + PDebugShowPalette(g_menuscreen_ptr, g_menuscreen_w); + PDebugShowSprite((unsigned short *)g_menuscreen_ptr + g_menuscreen_w*120 + g_menuscreen_w/2 + 16, + g_menuscreen_w, spr_offs); draw_text_debug(PDebugSpriteList(), spr_offs, 6); break; case 4: plat_video_menu_begin(); @@ -2040,8 +2099,8 @@ static menu_entry e_menu_main[] = mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler), mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler), mee_handler_id("Load new ROM/ISO", MA_MAIN_LOAD_ROM, main_menu_handler), - mee_handler_id("Change options", MA_MAIN_OPTIONS, menu_loop_options), - mee_handler_id("Configure controls", MA_MAIN_OPTIONS, menu_loop_keyconfig), + mee_handler ("Change options", menu_loop_options), + mee_handler ("Configure controls", menu_loop_keyconfig), mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler), mee_handler_id("Patches / GameGenie",MA_MAIN_PATCHES, main_menu_handler), mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler), @@ -2135,28 +2194,6 @@ void me_update_msg(const char *msg) // ------------ util ------------ -/* GP2X/wiz for now, probably extend later */ -void menu_plat_setup(int is_wiz) -{ - int i; - - if (!is_wiz) { - me_enable(e_menu_gfx_options, MA_OPT_TEARING_FIX, 0); - i = me_id2offset(e_menu_gfx_options, MA_OPT_TEARING_FIX); - e_menu_gfx_options[i].need_to_save = 0; - return; - } - - me_enable(e_menu_adv_options, MA_OPT_ARM940_SOUND, 0); - me_enable(e_menu_gfx_options, MA_OPT2_GAMMA, 0); - me_enable(e_menu_gfx_options, MA_OPT2_A_SN_GAMMA, 0); - - i = me_id2offset(e_menu_gfx_options, MA_OPT_SCALING); - e_menu_gfx_options[i].max = 1; /* only off and sw */ - i = me_id2offset(e_menu_gfx_options, MA_OPT_ARM940_SOUND); - e_menu_gfx_options[i].need_to_save = 0; -} - /* hidden options for config engine only */ static menu_entry e_menu_hidden[] = { @@ -2170,7 +2207,9 @@ static menu_entry *e_menu_table[] = e_menu_gfx_options, e_menu_adv_options, e_menu_cd_options, +#ifndef NO_32X e_menu_32x_options, +#endif e_menu_keyconfig, e_menu_hidden, };