X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=common%2Fmenu.c;h=39a71b156ec77fbc56d0c7bf3d9250019e438b8d;hb=209a7eff8b4d8e347bb580c2bd3fe6402f074f9b;hp=412dbc2cdabdeaad2e036ce46133be978ccd883a;hpb=93c18cb44bf9794c7c9bc93411c68880723320d1;p=libpicofe.git diff --git a/common/menu.c b/common/menu.c index 412dbc2..39a71b1 100644 --- a/common/menu.c +++ b/common/menu.c @@ -17,16 +17,15 @@ #include "plat.h" #include "posix.h" #include +#include -#include +#include #include -#include - -#define array_size(x) (sizeof(x) / sizeof(x[0])) static char static_buff[64]; -static char menu_error_msg[64] = { 0, }; static int menu_error_time = 0; +char menu_error_msg[64] = { 0, }; +void *g_menubg_ptr; #ifndef UIQ3 @@ -46,7 +45,7 @@ static const int me_sfont_w = 6, me_sfont_h = 10; // draws text to current bbp16 screen static void text_out16_(int x, int y, const char *text, int color) { - int i, l, u, tr, tg, tb, len; + int i, lh, tr, tg, tb, len; unsigned short *dest = (unsigned short *)g_screen_ptr + x + y * g_screen_width; tr = (color & 0xf800) >> 8; tg = (color & 0x07e0) >> 3; @@ -66,11 +65,17 @@ static void text_out16_(int x, int y, const char *text, int color) len = p - text; } + lh = me_mfont_h; + if (y + lh > g_screen_height) + lh = g_screen_height - y; + for (i = 0; i < len; i++) { unsigned char *src = menu_font_data + (unsigned int)text[i] * me_mfont_w * me_mfont_h / 2; unsigned short *dst = dest; - for (l = 0; l < me_mfont_h; l++, dst += g_screen_width - me_mfont_w) + int u, l; + + for (l = 0; l < lh; l++, dst += g_screen_width - me_mfont_w) { for (u = me_mfont_w / 2; u > 0; u--, src++) { @@ -159,7 +164,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_screen_width - x) / me_sfont_w; if (maxw < 0) return; @@ -182,11 +187,11 @@ 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_screen_ptr + x + y * g_screen_width + 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; } @@ -262,20 +267,25 @@ void menu_init(void) } // load custom font and selector (stored as 1st symbol in font table) - readpng(menu_font_data, "skin/font.png", READPNG_FONT); + emu_make_path(buff, "skin/font.png", sizeof(buff)); + 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); - readpng(menu_font_data, "skin/selector.png", READPNG_SELECTOR); + emu_make_path(buff, "skin/selector.png", sizeof(buff)); + readpng(menu_font_data, buff, READPNG_SELECTOR, me_mfont_w, me_mfont_h); // load custom colors - f = fopen("skin/skin.txt", "r"); + emu_make_path(buff, "skin/skin.txt", sizeof(buff)); + f = fopen(buff, "r"); if (f != NULL) { lprintf("found skin.txt\n"); while (!feof(f)) { - fgets(buff, sizeof(buff), f); + if (fgets(buff, sizeof(buff), f) == NULL) + break; if (buff[0] == '#' || buff[0] == '/') continue; // comment if (buff[0] == '\r' || buff[0] == '\n') continue; // empty line if (strncmp(buff, "text_color=", 11) == 0) @@ -298,6 +308,49 @@ void menu_init(void) } +static void menu_darken_bg(void *dst, void *src, int pixels, int darker) +{ + unsigned int *dest = dst; + unsigned int *sorc = src; + pixels /= 2; + if (darker) + { + while (pixels--) + { + unsigned int p = *sorc++; + *dest++ = ((p&0xf79ef79e)>>1) - ((p&0xc618c618)>>3); + } + } + else + { + while (pixels--) + { + unsigned int p = *sorc++; + *dest++ = (p&0xf79ef79e)>>1; + } + } +} + +static void menu_enter(int is_rom_loaded) +{ + if (is_rom_loaded) + { + // darken the active framebuffer + menu_darken_bg(g_menubg_ptr, g_screen_ptr, g_screen_width * g_screen_height, 1); + } + else + { + char buff[256]; + + // should really only happen once, on startup.. + emu_make_path(buff, "skin/background.png", sizeof(buff)); + if (readpng(g_menubg_ptr, buff, READPNG_BG, g_screen_width, g_screen_height) < 0) + memset(g_menubg_ptr, 0, g_screen_width * g_screen_height * 2); + } + + plat_video_menu_enter(is_rom_loaded); +} + static int me_id2offset(const menu_entry *ent, menu_id id) { int i; @@ -324,13 +377,13 @@ static int me_count(const menu_entry *ent) return ret; } -static void me_draw(const menu_entry *entries, int sel) +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, opt_offs = 27 * me_mfont_w; + 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 */ @@ -341,8 +394,10 @@ static void me_draw(const menu_entry *entries, int sel) 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; @@ -353,14 +408,17 @@ static void me_draw(const menu_entry *entries, int sel) if (ent->beh != MB_NONE) { - if (wt > opt_offs) - opt_offs = wt + me_mfont_w; - wt = opt_offs; + if (wt > col2_offs) + col2_offs = wt + me_mfont_w; + 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: @@ -371,6 +429,9 @@ static void me_draw(const menu_entry *entries, int sel) if (name != NULL) wt += (strlen(name) + offs) * me_mfont_w; break; + case MB_OPT_ENUM: + wt += 10 * me_mfont_w; + break; } } @@ -395,11 +456,14 @@ static void me_draw(const menu_entry *entries, int sel) /* 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; @@ -415,10 +479,10 @@ static void me_draw(const menu_entry *entries, int sel) case MB_NONE: break; case MB_OPT_ONOFF: - text_out16(x + opt_offs, y, (*(int *)ent->var & ent->mask) ? "ON" : "OFF"); + text_out16(x + col2_offs, y, (*(int *)ent->var & ent->mask) ? "ON" : "OFF"); break; case MB_OPT_RANGE: - text_out16(x + opt_offs, y, "%i", *(int *)ent->var); + text_out16(x + col2_offs, y, "%i", *(int *)ent->var); break; case MB_OPT_CUSTOM: case MB_OPT_CUSTONOFF: @@ -428,16 +492,30 @@ static void me_draw(const menu_entry *entries, int sel) if (ent->generate_name) name = ent->generate_name(ent->id, &offs); if (name != NULL) - text_out16(x + opt_offs + offs * me_mfont_w, y, "%s", name); + 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_screen_height - h) / 2; // bottom area height if (menu_error_msg[0] != 0) { - if (g_screen_height - h >= 2 * me_mfont_h) + if (h >= me_mfont_h + 4) text_out16(5, g_screen_height - me_mfont_h - 4, menu_error_msg); else lprintf("menu msg doesn't fit!\n"); @@ -445,12 +523,26 @@ static void me_draw(const menu_entry *entries, int sel) 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_screen_height - (l * me_sfont_h + 4), tmp, 0xffff); + } + + if (draw_more != NULL) + draw_more(); plat_video_menu_end(); } -static int me_process(menu_entry *entry, int is_next) +static int me_process(menu_entry *entry, int is_next, int is_lr) { + const char **names; + int c; switch (entry->beh) { case MB_OPT_ONOFF: @@ -459,12 +551,23 @@ static int me_process(menu_entry *entry, int is_next) return 1; case MB_OPT_RANGE: case MB_OPT_CUSTRANGE: - *(int *)entry->var += is_next ? 1 : -1; + c = is_lr ? 10 : 1; + *(int *)entry->var += is_next ? c : -c; if (*(int *)entry->var < (int)entry->min) *(int *)entry->var = (int)entry->max; 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; } @@ -472,12 +575,12 @@ static int me_process(menu_entry *entry, int is_next) static void debug_menu_loop(void); -static void me_loop(menu_entry *menu, int *menu_sel) +static void me_loop(menu_entry *menu, int *menu_sel, void (*draw_more)(void)) { int ret, inp, sel = *menu_sel, menu_sel_max; menu_sel_max = me_count(menu) - 1; - if (menu_sel_max < 1) { + if (menu_sel_max < 0) { lprintf("no enabled menu entries\n"); return; } @@ -486,12 +589,12 @@ static void me_loop(menu_entry *menu, int *menu_sel) sel++; /* make sure action buttons are not pressed on entering menu */ - me_draw(menu, sel); + me_draw(menu, sel, NULL); while (in_menu_wait_any(50) & (PBTN_MOK|PBTN_MBACK|PBTN_MENU)); for (;;) { - me_draw(menu, sel); + me_draw(menu, sel, draw_more); inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT| PBTN_MOK|PBTN_MBACK|PBTN_MENU|PBTN_L|PBTN_R, 70); if (inp & (PBTN_MENU|PBTN_MBACK)) @@ -518,17 +621,19 @@ static void me_loop(menu_entry *menu, int *menu_sel) if ((inp & (PBTN_L|PBTN_R)) == (PBTN_L|PBTN_R)) debug_menu_loop(); - if (inp & (PBTN_LEFT|PBTN_RIGHT)) { /* multi choice */ - if (me_process(&menu[sel], (inp & PBTN_RIGHT) ? 1 : 0)) + if (inp & (PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R)) { /* multi choice */ + if (me_process(&menu[sel], (inp & (PBTN_RIGHT|PBTN_R)) ? 1 : 0, + inp & (PBTN_L|PBTN_R))) 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 */ } } } @@ -537,6 +642,17 @@ static void me_loop(menu_entry *menu, int *menu_sel) /* ***************************************** */ +/* platform specific options and handlers */ +#if defined(__GP2X__) +#include "../gp2x/menu.c" +#elif defined(PANDORA) +#include "../pandora/menu.c" +#else +#define MENU_OPTIONS_GFX +#define MENU_OPTIONS_ADV +#define menu_main_plat_draw NULL +#endif + static void draw_menu_credits(void) { const char *creds, *p; @@ -581,24 +697,24 @@ 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; + unsigned short *dst = (unsigned short *)g_screen_ptr + g_screen_width * me_sfont_h * 2; if (len > g_screen_width) len = g_screen_width; - for (ln = 10 - 2; ln > 0; ln--, dst += g_screen_width) + for (ln = me_sfont_h - 2; ln > 0; ln--, dst += g_screen_width) memset(dst, 0xff, len * 2); plat_video_menu_end(); } -static void cdload_progress_cb(int percent) +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; + unsigned short *dst = (unsigned short *)g_screen_ptr + g_screen_width * me_sfont_h * 2; memset(dst, 0xff, g_screen_width * (me_sfont_h - 2) * 2); smalltext_out16(1, 3 * me_sfont_h, "Processing CD image / MP3s", 0xffff); - smalltext_out16(1, 4 * me_sfont_h, rom_fname_loaded, 0xffff); + smalltext_out16(1, 4 * me_sfont_h, fname, 0xffff); dst += g_screen_width * me_sfont_h * 3; if (len > g_screen_width) @@ -613,20 +729,18 @@ static void cdload_progress_cb(int percent) void menu_romload_prepare(const char *rom_name) { const char *p = rom_name + strlen(rom_name); + int i; while (p > rom_name && *p != '/') p--; - /* fill both buffers, callbacks won't update in full */ - plat_video_menu_begin(); - smalltext_out16(1, 1, "Loading", 0xffff); - smalltext_out16(1, me_sfont_h, p, 0xffff); - plat_video_menu_end(); - - plat_video_menu_begin(); - smalltext_out16(1, 1, "Loading", 0xffff); - smalltext_out16(1, me_sfont_h, p, 0xffff); - plat_video_menu_end(); + /* fill all buffers, callbacks won't update in full */ + for (i = 0; i < 3; i++) { + plat_video_menu_begin(); + smalltext_out16(1, 1, "Loading", 0xffff); + smalltext_out16(1, me_sfont_h, p, 0xffff); + plat_video_menu_end(); + } PicoCartLoadProgressCB = load_progress_cb; PicoCDLoadProgressCB = cdload_progress_cb; @@ -635,7 +749,8 @@ void menu_romload_prepare(const char *rom_name) void menu_romload_end(void) { - PicoCartLoadProgressCB = PicoCDLoadProgressCB = NULL; + PicoCartLoadProgressCB = NULL; + PicoCDLoadProgressCB = NULL; smalltext_out16(1, (cdload_called ? 6 : 3) * me_sfont_h, "Starting emulation...", 0xffff); plat_video_menu_end(); @@ -652,11 +767,11 @@ 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_width * g_screen_height, 0); + menu_darken_bg(g_screen_ptr, g_screen_ptr, g_screen_width * g_screen_height, 0); len = strlen(fname); - if (len > g_screen_width/6) - len = g_screen_width/6; + if (len > g_screen_width / me_sfont_w) + len = g_screen_width / me_sfont_w; mid = g_screen_width / 2; text_out16(mid - me_mfont_w * 15 / 2, 8 * me_mfont_h, "About to delete"); @@ -700,6 +815,7 @@ static unsigned short file2color(const char *fname) 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; start = max_cnt / 2 - sel; @@ -710,7 +826,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); - menu_darken_bg((short *)g_screen_ptr + g_screen_width * max_cnt/2 * 10, g_screen_width * 8, 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); x = 5 + me_mfont_w + 1; if (start - 2 >= 0) @@ -733,10 +850,15 @@ static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel) static int scandir_cmp(const void *p1, const void *p2) { - struct dirent **d1 = (struct dirent **)p1, **d2 = (struct dirent **)p2; - if ((*d1)->d_type == (*d2)->d_type) return alphasort(d1, d2); - if ((*d1)->d_type == DT_DIR) return -1; // put before - if ((*d2)->d_type == DT_DIR) return 1; + const struct dirent **d1 = (const struct dirent **)p1; + const struct dirent **d2 = (const struct dirent **)p2; + if ((*d1)->d_type == (*d2)->d_type) + return alphasort(d1, d2); + if ((*d1)->d_type == DT_DIR) + return -1; // put before + if ((*d2)->d_type == DT_DIR) + return 1; + return alphasort(d1, d2); } @@ -778,13 +900,16 @@ rescan: fname = p+1; } - n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp); + n = scandir(curr_path, &namelist, scandir_filter, (void *)scandir_cmp); if (n < 0) { + char *t; lprintf("menu_loop_romsel failed, dir: %s\n", curr_path); // try root - getcwd(curr_path, len); - n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp); + t = getcwd(curr_path, len); + if (t == NULL) + plat_get_root_dir(curr_path, len); + n = scandir(curr_path, &namelist, scandir_filter, (void *)scandir_cmp); if (n < 0) { // oops, we failed lprintf("menu_loop_romsel failed, dir: %s\n", curr_path); @@ -803,6 +928,11 @@ rescan: } } + /* make sure action buttons are not pressed on entering menu */ + draw_dirlist(curr_path, namelist, n, sel); + while (in_menu_wait_any(50) & (PBTN_MOK|PBTN_MBACK|PBTN_MENU)) + ; + for (;;) { draw_dirlist(curr_path, namelist, n, sel); @@ -894,7 +1024,7 @@ static void draw_patchlist(int sel) { int max_cnt, start, i, pos, active; - max_cnt = g_screen_height / 10; + max_cnt = g_screen_height / me_sfont_h; start = max_cnt / 2 - sel; plat_video_menu_begin(); @@ -904,8 +1034,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) @@ -949,62 +1079,29 @@ static void state_check_slots(void) state_slot_flags = 0; for (slot = 0; slot < 10; slot++) { - if (emu_checkSaveFile(slot)) + if (emu_check_save_file(slot)) state_slot_flags |= 1 << slot; } } static void draw_savestate_bg(int slot) { - struct PicoVideo tmp_pv; - unsigned short tmp_cram[0x40]; - unsigned short tmp_vsram[0x40]; - void *tmp_vram, *file; - char *fname; + const char *fname; + void *tmp_state; - fname = emu_GetSaveFName(1, 0, slot); - if (!fname) return; - - tmp_vram = malloc(sizeof(Pico.vram)); - if (tmp_vram == NULL) return; - - memcpy(tmp_vram, Pico.vram, sizeof(Pico.vram)); - memcpy(tmp_cram, Pico.cram, sizeof(Pico.cram)); - memcpy(tmp_vsram, Pico.vsram, sizeof(Pico.vsram)); - memcpy(&tmp_pv, &Pico.video, sizeof(Pico.video)); + fname = emu_get_save_fname(1, 0, slot); + if (!fname) + return; - if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) { - file = gzopen(fname, "rb"); - emu_setSaveStateCbs(1); - } else { - file = fopen(fname, "rb"); - emu_setSaveStateCbs(0); - } + tmp_state = PicoTmpStateSave(); - if (file) { - if (PicoAHW & PAHW_MCD) { - PicoCdLoadStateGfx(file); - } else { - areaSeek(file, 0x10020, SEEK_SET); // skip header and RAM in state file - areaRead(Pico.vram, 1, sizeof(Pico.vram), file); - areaSeek(file, 0x2000, SEEK_CUR); - areaRead(Pico.cram, 1, sizeof(Pico.cram), file); - areaRead(Pico.vsram, 1, sizeof(Pico.vsram), file); - areaSeek(file, 0x221a0, SEEK_SET); - areaRead(&Pico.video, 1, sizeof(Pico.video), file); - } - areaClose(file); - } + PicoStateLoadGfx(fname); /* do a frame and fetch menu bg */ - pemu_forced_frame(POPT_EN_SOFTSCALE); - plat_video_menu_enter(1); + pemu_forced_frame(POPT_EN_SOFTSCALE, 0); + menu_enter(1); - memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram)); - memcpy(Pico.cram, tmp_cram, sizeof(Pico.cram)); - memcpy(Pico.vsram, tmp_vsram, sizeof(Pico.vsram)); - memcpy(&Pico.video, &tmp_pv, sizeof(Pico.video)); - free(tmp_vram); + PicoTmpStateRestore(tmp_state); } static void draw_savestate_menu(int menu_sel, int is_loading) @@ -1043,9 +1140,13 @@ static int menu_loop_savestate(int is_loading) static int menu_sel = 10; int menu_sel_max = 10; unsigned long inp = 0; + int ret = 0; state_check_slots(); + if (!(state_slot_flags & (1 << menu_sel)) && is_loading) + menu_sel = menu_sel_max; + for (;;) { draw_savestate_menu(menu_sel, is_loading); @@ -1067,25 +1168,28 @@ static int menu_loop_savestate(int is_loading) if (inp & PBTN_MOK) { // save/load if (menu_sel < 10) { state_slot = menu_sel; - if (emu_SaveLoadGame(is_loading, 0)) { + if (emu_save_load_game(is_loading, 0)) { me_update_msg(is_loading ? "Load failed" : "Save failed"); - return 0; + break; } - return 1; + ret = 1; + break; } - return 0; + break; } if (inp & PBTN_MBACK) - return 0; + break; } + + return ret; } // -------------- key config -------------- static char *action_binds(int player_idx, int action_mask, int dev_id) { + int k, count, can_combo, type; const int *binds; - int k, count; static_buff[0] = 0; @@ -1094,21 +1198,30 @@ static char *action_binds(int player_idx, int action_mask, int dev_id) return static_buff; count = in_get_dev_info(dev_id, IN_INFO_BIND_COUNT); + can_combo = in_get_dev_info(dev_id, IN_INFO_DOES_COMBOS); + + type = IN_BINDTYPE_EMU; + if (player_idx >= 0) { + can_combo = 0; + type = IN_BINDTYPE_PLAYER12; + } + if (player_idx == 1) + action_mask <<= 16; + for (k = 0; k < count; k++) { const char *xname; int len; - if (!(binds[k] & action_mask)) - continue; - if (player_idx >= 0 && ((binds[k] >> 16) & 3) != player_idx) + if (!(binds[IN_BIND_OFFS(k, type)] & action_mask)) continue; xname = in_get_key_name(dev_id, k); len = strlen(static_buff); if (len) { - strncat(static_buff, " + ", sizeof(static_buff) - len - 1); - len += 3; + strncat(static_buff, can_combo ? " + " : ", ", + sizeof(static_buff) - len - 1); + len += can_combo ? 3 : 2; } strncat(static_buff, xname, sizeof(static_buff) - len - 1); } @@ -1116,7 +1229,7 @@ static char *action_binds(int player_idx, int action_mask, int dev_id) return static_buff; } -static int count_bound_keys(int dev_id, int action_mask, int player_idx) +static int count_bound_keys(int dev_id, int action_mask, int bindtype) { const int *binds; int k, keys = 0; @@ -1129,13 +1242,8 @@ static int count_bound_keys(int dev_id, int action_mask, int player_idx) count = in_get_dev_info(dev_id, IN_INFO_BIND_COUNT); for (k = 0; k < count; k++) { - if (!(binds[k] & action_mask)) - continue; - - if (player_idx >= 0 && ((binds[k] >> 16) & 3) != player_idx) - continue; - - keys++; + if (binds[IN_BIND_OFFS(k, bindtype)] & action_mask) + keys++; } return keys; @@ -1144,6 +1252,7 @@ static int count_bound_keys(int dev_id, int action_mask, int player_idx) static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_idx, int sel, int dev_id, int dev_count, int is_bind) { + char buff[64], buff2[32]; const char *dev_name; int x, y, w, i; @@ -1175,15 +1284,19 @@ static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_ x = g_screen_width / 2 - w / 2; - if (dev_count > 1) { - text_out16(x, g_screen_height - 4 * me_mfont_h, "Viewing binds for:"); - text_out16(x, g_screen_height - 3 * me_mfont_h, dev_name); + 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); } + else + text_out16(x, g_screen_height - 4 * me_mfont_h, "Press a button to bind/unbind"); - if (is_bind) - text_out16(x, g_screen_height - 2 * me_mfont_h, "Press a button to bind/unbind"); - else if (dev_count > 1) + 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"); + } plat_video_menu_end(); } @@ -1191,7 +1304,8 @@ static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_idx) { int i, sel = 0, menu_sel_max = opt_cnt - 1; - int dev_id, dev_count, kc, is_down, mkey, unbind; + int dev_id, dev_count, kc, is_down, mkey; + int unbind, bindtype, mask_shift; for (i = 0, dev_id = -1, dev_count = 0; i < IN_MAX_DEVS; i++) { if (in_get_dev_name(i, 1, 0) != NULL) { @@ -1206,10 +1320,15 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_ return; } + mask_shift = 0; + if (player_idx == 1) + mask_shift = 16; + bindtype = player_idx >= 0 ? IN_BINDTYPE_PLAYER12 : IN_BINDTYPE_EMU; + for (;;) { draw_key_config(opts, opt_cnt, player_idx, sel, dev_id, dev_count, 0); - mkey = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_MBACK|PBTN_MOK, 100); + mkey = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_MBACK|PBTN_MOK|PBTN_MA2, 100); switch (mkey) { case PBTN_UP: sel--; if (sel < 0) sel = menu_sel_max; continue; case PBTN_DOWN: sel++; if (sel > menu_sel_max) sel = 0; continue; @@ -1235,6 +1354,9 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_ return; while (in_menu_wait_any(30) & PBTN_MOK); break; + case PBTN_MA2: + in_unbind_all(dev_id, opts[sel].mask << mask_shift, bindtype); + continue; default:continue; } @@ -1244,19 +1366,15 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_ for (is_down = 1; is_down; ) kc = in_update_keycode(&dev_id, &is_down, -1); - i = count_bound_keys(dev_id, opts[sel].mask, player_idx); + i = count_bound_keys(dev_id, opts[sel].mask << mask_shift, bindtype); unbind = (i > 0); /* allow combos if device supports them */ - if (i == 1 && in_get_dev_info(dev_id, IN_INFO_DOES_COMBOS)) + if (i == 1 && bindtype == IN_BINDTYPE_EMU && + in_get_dev_info(dev_id, IN_INFO_DOES_COMBOS)) unbind = 0; - in_bind_key(dev_id, kc, opts[sel].mask, unbind); - if (player_idx >= 0) { - /* FIXME */ - in_bind_key(dev_id, kc, 3 << 16, 1); - in_bind_key(dev_id, kc, player_idx << 16, 0); - } + in_bind_key(dev_id, kc, opts[sel].mask << mask_shift, bindtype, unbind); } } @@ -1280,10 +1398,6 @@ me_bind_action me_ctrl_actions[15] = { "Z ", 0x0100 } }; -// player2_flag, reserved, ?, ?, -// ?, ?, fast forward, menu -// "NEXT SAVE SLOT", "PREV SAVE SLOT", "SWITCH RENDERER", "SAVE STATE", -// "LOAD STATE", "VOLUME UP", "VOLUME DOWN", "DONE" me_bind_action emuctrl_actions[] = { { "Load State ", PEV_STATE_LOAD }, @@ -1338,7 +1452,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[] = { @@ -1347,8 +1461,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), @@ -1364,7 +1478,9 @@ static menu_entry e_menu_keyconfig[] = static int menu_loop_keyconfig(menu_id id, int keys) { static int sel = 0; - me_loop(e_menu_keyconfig, &sel); + + me_enable(e_menu_keyconfig, MA_OPT_SAVECFG_GAME, rom_loaded); + me_loop(e_menu_keyconfig, &sel, NULL); return 0; } @@ -1395,83 +1511,133 @@ 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, 0x0400), - 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, }; static int menu_loop_cd_options(menu_id id, int keys) { static int sel = 0; - me_loop(e_menu_cd_options, &sel); + me_loop(e_menu_cd_options, &sel, NULL); + return 0; +} + +// ------------ 32X options menu ------------ + +#ifndef NO_32X + +// convert from multiplier of VClk +static int mh_opt_sh2cycles(menu_id id, int keys) +{ + int *mul = (id == MA_32XOPT_MSH2_CYCLES) ? &p32x_msh2_multiplier : &p32x_ssh2_multiplier; + + if (keys & (PBTN_LEFT|PBTN_RIGHT)) + *mul += (keys & PBTN_LEFT) ? -10 : 10; + if (keys & (PBTN_L|PBTN_R)) + *mul += (keys & PBTN_L) ? -100 : 100; + + if (*mul < 1) + *mul = 1; + else if (*mul > (10 << SH2_MULTI_SHIFT)) + *mul = 10 << SH2_MULTI_SHIFT; + + return 0; +} + +static const char *mgn_opt_sh2cycles(menu_id id, int *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_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; + + me_enable(e_menu_32x_options, MA_32XOPT_RENDERER, renderer_names32x != NULL); + me_loop(e_menu_32x_options, &sel, NULL); + return 0; } +#endif + // ------------ adv options menu ------------ static menu_entry e_menu_adv_options[] = { - mee_onoff ("SRAM/BRAM saves", MA_OPT_SRAM_STATES, currentConfig.EmuOpt, EOPT_USE_SRAM), + mee_onoff ("SRAM/BRAM saves", MA_OPT_SRAM_STATES, currentConfig.EmuOpt, EOPT_EN_SRAM), mee_onoff ("Disable sprite limit", MA_OPT2_NO_SPRITE_LIM, PicoOpt, POPT_DIS_SPRITE_LIM), - mee_onoff ("Use second CPU for sound", MA_OPT_ARM940_SOUND, PicoOpt, POPT_EXT_FM), mee_onoff ("Emulate Z80", MA_OPT2_ENABLE_Z80, PicoOpt, POPT_EN_Z80), mee_onoff ("Emulate YM2612 (FM)", MA_OPT2_ENABLE_YM2612, PicoOpt, POPT_EN_FM), mee_onoff ("Emulate SN76496 (PSG)", MA_OPT2_ENABLE_SN76496,PicoOpt, POPT_EN_PSG), mee_onoff ("gzip savestates", MA_OPT2_GZIP_STATES, currentConfig.EmuOpt, EOPT_GZIP_SAVES), mee_onoff ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM, currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG), - mee_onoff ("RAM overclock", MA_OPT2_RAMTIMINGS, currentConfig.EmuOpt, EOPT_RAM_TIMINGS), - mee_onoff ("MMU hack", MA_OPT2_SQUIDGEHACK, currentConfig.EmuOpt, EOPT_MMUHACK), - mee_onoff ("SVP dynarec", MA_OPT2_SVP_DYNAREC, PicoOpt, POPT_EN_SVP_DRC), mee_onoff ("Disable idle loop patching",MA_OPT2_NO_IDLE_LOOPS,PicoOpt, POPT_DIS_IDLE_DET), + mee_onoff ("Disable frame limiter", MA_OPT2_NO_FRAME_LIMIT,currentConfig.EmuOpt, EOPT_NO_FRMLIMIT), + MENU_OPTIONS_ADV mee_end, }; static int menu_loop_adv_options(menu_id id, int keys) { static int sel = 0; - me_loop(e_menu_adv_options, &sel); + me_loop(e_menu_adv_options, &sel, NULL); return 0; } // ------------ gfx options menu ------------ -static const char *mgn_opt_scaling(menu_id id, int *offs) -{ - *offs = -13; - switch (currentConfig.scaling) { - default: return " OFF"; - case EOPT_SCALE_HW_H: return " hw horizontal"; - case EOPT_SCALE_HW_HV: return "hw horiz. + vert"; - case EOPT_SCALE_SW_H: return " sw horizontal"; - } -} - -static const char *mgn_aopt_gamma(menu_id id, int *offs) -{ - sprintf(static_buff, "%i.%02i", currentConfig.gamma / 100, currentConfig.gamma%100); - return static_buff; -} - static menu_entry e_menu_gfx_options[] = { - mee_range_cust("Scaling", MA_OPT_SCALING, currentConfig.scaling, 0, 3, mgn_opt_scaling), - mee_range_cust("Gamma correction", MA_OPT2_GAMMA, currentConfig.gamma, 1, 300, mgn_aopt_gamma), - mee_onoff ("A_SN's gamma curve", MA_OPT2_A_SN_GAMMA, currentConfig.EmuOpt, EOPT_A_SN_GAMMA), - mee_onoff ("Perfect vsync", MA_OPT2_VSYNC, currentConfig.EmuOpt, EOPT_PSYNC), + mee_enum("Renderer", MA_OPT_RENDERER, currentConfig.renderer, renderer_names), + MENU_OPTIONS_GFX mee_end, }; static int menu_loop_gfx_options(menu_id id, int keys) { static int sel = 0; - me_loop(e_menu_gfx_options, &sel); + + me_enable(e_menu_gfx_options, MA_OPT_RENDERER, renderer_names[0] != NULL); + me_loop(e_menu_gfx_options, &sel, NULL); + return 0; } @@ -1479,20 +1645,6 @@ static int menu_loop_gfx_options(menu_id id, int keys) static menu_entry e_menu_options[]; -/* TODO: move to plat */ -static int mh_opt_render(menu_id id, int keys) -{ - if (keys & PBTN_LEFT) { - if (PicoOpt&0x10) PicoOpt&= ~0x10; - else if (!(currentConfig.EmuOpt &0x80))currentConfig.EmuOpt |= 0x80; - } else { - if (PicoOpt&0x10) return 0; - else if (!(currentConfig.EmuOpt &0x80))PicoOpt|= 0x10; - else if ( currentConfig.EmuOpt &0x80) currentConfig.EmuOpt &= ~0x80; - } - return 0; -} - static int sndrate_prevnext(int rate, int dir) { static const int rates[] = { 8000, 11025, 16000, 22050, 44100 }; @@ -1549,8 +1701,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); @@ -1558,14 +1708,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; } @@ -1587,14 +1729,14 @@ static int mh_saveloadcfg(menu_id id, int keys) switch (id) { case MA_OPT_SAVECFG: case MA_OPT_SAVECFG_GAME: - if (emu_WriteConfig(id == MA_OPT_SAVECFG_GAME ? 1 : 0)) + if (emu_write_config(id == MA_OPT_SAVECFG_GAME ? 1 : 0)) me_update_msg("config saved"); else me_update_msg("failed to write config"); break; case MA_OPT_LOADCFG: - ret = emu_ReadConfig(1, 1); - if (!ret) ret = emu_ReadConfig(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; @@ -1605,15 +1747,11 @@ static int mh_saveloadcfg(menu_id id, int keys) return 1; } -static const char *mgn_opt_renderer(menu_id id, int *offs) +static int mh_restore_defaults(menu_id id, int keys) { - *offs = -6; - if (PicoOpt & POPT_ALT_RENDERER) - return " 8bit fast"; - else if (currentConfig.EmuOpt & 0x80) - return "16bit accurate"; - else - return " 8bit accurate"; + emu_set_defconfig(); + me_update_msg("defaults restored"); + return 1; } static const char *mgn_opt_fskip(menu_id id, int *offs) @@ -1659,47 +1797,38 @@ static const char *mgn_opt_region(menu_id id, int *offs) } } -static const char *mgn_opt_c_saves(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) +static const char *mgn_saveloadcfg(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[] = { mee_range ("Save slot", MA_OPT_SAVE_SLOT, state_slot, 0, 9), mee_range_cust("Frameskip", MA_OPT_FRAMESKIP, currentConfig.Frameskip, -1, 16, mgn_opt_fskip), mee_cust ("Region", MA_OPT_REGION, mh_opt_misc, mgn_opt_region), - mee_cust ("Renderer", MA_OPT_RENDERER, mh_opt_render, mgn_opt_renderer), - mee_onoff ("Show FPS", MA_OPT_SHOW_FPS, currentConfig.EmuOpt, 0x002), - mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, 0x004), + 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_enum_h ("Confirm savestate", MA_OPT_CONFIRM_STATES,currentConfig.confirm_save, men_confirm_save, h_confirm_save), mee_range (cpu_clk_name, MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 900), mee_handler ("[Display options]", menu_loop_gfx_options), - mee_handler ("[Advanced options]", menu_loop_adv_options), mee_handler ("[Sega/Mega CD options]", menu_loop_cd_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), +#ifndef NO_32X + mee_handler ("[32X options]", menu_loop_32x_options), +#endif + mee_handler ("[Advanced options]", menu_loop_adv_options), + 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, }; @@ -1710,11 +1839,7 @@ static int menu_loop_options(menu_id id, int keys) me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, rom_loaded); me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current); - me_loop(e_menu_options, &sel); - - if (PicoRegionOverride) - // force setting possibly changed.. - Pico.m.pal = (PicoRegionOverride == 2 || PicoRegionOverride == 8) ? 1 : 0; + me_loop(e_menu_options, &sel, NULL); return 0; } @@ -1767,17 +1892,24 @@ static void draw_text_debug(const char *str, int skip, int from) } } +#ifdef __GNUC__ +#define COMPILER "gcc " __VERSION__ +#else +#define COMPILER +#endif + static void draw_frame_debug(void) { - char layer_str[48] = "layers: "; + char layer_str[48] = "layers: "; if (PicoDrawMask & PDRAW_LAYERB_ON) memcpy(layer_str + 8, "B", 1); if (PicoDrawMask & PDRAW_LAYERA_ON) memcpy(layer_str + 10, "A", 1); if (PicoDrawMask & PDRAW_SPRITES_LOW_ON) memcpy(layer_str + 12, "spr_lo", 6); 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); - smalltext_out16(4, 1, "build: " __DATE__ " " __TIME__, 0xffff); + 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); } @@ -1801,31 +1933,37 @@ static void debug_menu_loop(void) dumped = 0; } break; - case 1: draw_frame_debug(); 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_width * g_screen_height, 0); + pemu_forced_frame(0, 1); + 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; + 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); draw_text_debug(PDebugSpriteList(), spr_offs, 6); break; + case 4: plat_video_menu_begin(); + tmp = PDebug32x(); + draw_text_debug(tmp, 0, 0); + break; } plat_video_menu_end(); inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R | PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, 70); if (inp & PBTN_MBACK) return; - if (inp & PBTN_L) { mode--; if (mode < 0) mode = 3; } - if (inp & PBTN_R) { mode++; if (mode > 3) mode = 0; } + if (inp & PBTN_L) { mode--; if (mode < 0) mode = 4; } + if (inp & PBTN_R) { mode++; if (mode > 4) mode = 0; } switch (mode) { case 0: if (inp & PBTN_MOK) - SekStepM68k(); + PDebugCPUStep(); if (inp & PBTN_MA3) { while (inp & PBTN_MA3) inp = in_menu_wait_any(-1); @@ -1843,6 +1981,7 @@ static void debug_menu_loop(void) if (inp & PBTN_RIGHT) PicoDrawMask ^= PDRAW_LAYERA_ON; if (inp & PBTN_DOWN) PicoDrawMask ^= PDRAW_SPRITES_LOW_ON; if (inp & PBTN_UP) PicoDrawMask ^= PDRAW_SPRITES_HI_ON; + if (inp & PBTN_MA2) PicoDrawMask ^= PDRAW_32X_ON; if (inp & PBTN_MOK) { PsndOut = NULL; // just in case PicoSkipFrame = 1; @@ -1941,8 +2080,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), @@ -1959,15 +2098,16 @@ void menu_loop(void) me_enable(e_menu_main, MA_MAIN_RESET_GAME, rom_loaded); me_enable(e_menu_main, MA_MAIN_PATCHES, PicoPatches != NULL); - plat_video_menu_enter(rom_loaded); + menu_enter(rom_loaded); in_set_blocking(1); - me_loop(e_menu_main, &sel); + me_loop(e_menu_main, &sel, menu_main_plat_draw); if (rom_loaded) { if (engineState == PGS_Menu) engineState = PGS_Running; /* wait until menu, ok, back is released */ - while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK)); + while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK)) + ; } in_set_blocking(0); @@ -1977,24 +2117,14 @@ void menu_loop(void) static int mh_tray_load_cd(menu_id id, int keys) { - cd_img_type cd_type; char *ret_name; - int ret = -1; ret_name = romsel_run(); if (ret_name == NULL) return 0; - cd_type = emu_cdCheck(NULL, ret_name); - if (cd_type != CIT_NOT_CD) - ret = Insert_CD(ret_name, cd_type); - if (ret != 0) { - me_update_msg("Load failed, invalid CD image?"); - return 0; - } - engineState = PGS_RestartRun; - return 1; + return emu_swap_cd(ret_name); } static int mh_tray_nothing(menu_id id, int keys) @@ -2004,22 +2134,22 @@ static int mh_tray_nothing(menu_id id, int keys) static menu_entry e_menu_tray[] = { - mee_label ("The unit is about to"), - mee_label ("close the CD tray."), + mee_label ("The CD tray has opened."), mee_label (""), mee_label (""), mee_handler("Load CD image", mh_tray_load_cd), mee_handler("Insert nothing", mh_tray_nothing), + mee_end, }; int menu_loop_tray(void) { int ret = 1, sel = 0; - plat_video_menu_enter(rom_loaded); + menu_enter(rom_loaded); in_set_blocking(1); - me_loop(e_menu_tray, &sel); + me_loop(e_menu_tray, &sel, NULL); if (engineState != PGS_RestartRun) { engineState = PGS_RestartRun; @@ -2045,13 +2175,17 @@ void me_update_msg(const char *msg) // ------------ util ------------ -/* wiz for now, probably extend later */ +/* GP2X/wiz for now, probably extend later */ void menu_plat_setup(int is_wiz) { int i; - if (!is_wiz) + 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); @@ -2059,29 +2193,8 @@ void menu_plat_setup(int is_wiz) i = me_id2offset(e_menu_gfx_options, MA_OPT_SCALING); e_menu_gfx_options[i].max = 1; /* only off and sw */ -} - -/* TODO: rename */ -void menu_darken_bg(void *dst, int pixels, int darker) -{ - unsigned int *screen = dst; - pixels /= 2; - if (darker) - { - while (pixels--) - { - unsigned int p = *screen; - *screen++ = ((p&0xf79ef79e)>>1) - ((p&0xc618c618)>>3); - } - } - else - { - while (pixels--) - { - unsigned int p = *screen; - *screen++ = (p&0xf79ef79e)>>1; - } - } + 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 */ @@ -2097,6 +2210,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, };