X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=common%2Fmenu.c;h=34d5b4996980e3dfb3b2890316d66c2913fa16bf;hb=662e622b59369f975691a70756f80188d8d27ea0;hp=867378490d8157ce65689968250c74131562353f;hpb=762ab456021d48de4b2601ac8721061e6cca809e;p=libpicofe.git diff --git a/common/menu.c b/common/menu.c index 8673784..34d5b49 100644 --- a/common/menu.c +++ b/common/menu.c @@ -23,8 +23,9 @@ #include 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 @@ -44,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; @@ -64,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++) { @@ -276,7 +283,8 @@ void menu_init(void) 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) @@ -299,6 +307,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) < 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; @@ -545,7 +596,15 @@ static void me_loop(menu_entry *menu, int *menu_sel, void (*draw_more)(void)) /* ***************************************** */ /* 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) { @@ -623,20 +682,18 @@ static void cdload_progress_cb(const char *fname, 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; @@ -663,7 +720,7 @@ 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) @@ -711,6 +768,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; @@ -721,7 +779,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) @@ -744,10 +803,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); } @@ -789,13 +853,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); @@ -993,7 +1060,7 @@ static void draw_savestate_bg(int slot) /* do a frame and fetch menu bg */ pemu_forced_frame(POPT_EN_SOFTSCALE); - plat_video_menu_enter(1); + menu_enter(1); memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram)); memcpy(Pico.cram, tmp_cram, sizeof(Pico.cram)); @@ -1424,6 +1491,53 @@ static int menu_loop_cd_options(menu_id id, int keys) return 0; } +// ------------ 32X options menu ------------ + +static const char *get_rname(const char **rn, int val, int *offs) +{ + int i, len, found = -1, maxlen = 0; + + for (i = 0; rn[i] != NULL; i++) { + len = strlen(rn[i]); + if (len > maxlen) + maxlen = len; + if (i == val) + found = i; + } + + *offs = 3 - maxlen; + if (found >= 0) + return rn[found]; + return "???"; +} + +static const char *mgn_opt_renderer32x(menu_id id, int *offs) +{ + return get_rname(renderer_names32x, currentConfig.renderer32x, offs); +} + +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_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_loop(e_menu_32x_options, &sel, NULL); + return 0; +} + // ------------ adv options menu ------------ static menu_entry e_menu_adv_options[] = @@ -1437,7 +1551,7 @@ static menu_entry e_menu_adv_options[] = mee_onoff ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM, currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG), 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_GP2X_OPTIONS_ADV + MENU_OPTIONS_ADV mee_end, }; @@ -1450,22 +1564,29 @@ static int menu_loop_adv_options(menu_id id, int keys) // ------------ gfx options menu ------------ -static int mh_opt_render(menu_id id, int keys) +static const char *mgn_opt_renderer(menu_id id, int *offs) { - plat_video_toggle_renderer((keys & PBTN_RIGHT) ? 1 : 0, 0, 1); - return 0; + return get_rname(renderer_names, currentConfig.renderer, offs); } static menu_entry e_menu_gfx_options[] = { - mee_cust ("Renderer", MA_OPT_RENDERER, mh_opt_render, mgn_opt_renderer), - MENU_GP2X_OPTIONS_GFX + mee_range_cust("Renderer", MA_OPT_RENDERER, currentConfig.renderer, 0, 0, mgn_opt_renderer), + MENU_OPTIONS_GFX mee_end, }; 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_loop(e_menu_gfx_options, &sel, NULL); return 0; } @@ -1672,6 +1793,7 @@ static menu_entry e_menu_options[] = mee_range (cpu_clk_name, 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), + mee_handler ("[32X options]", menu_loop_32x_options), 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), @@ -1689,10 +1811,6 @@ static int menu_loop_options(menu_id id, int keys) me_loop(e_menu_options, &sel, NULL); - if (PicoRegionOverride) - // force setting possibly changed.. - Pico.m.pal = (PicoRegionOverride == 2 || PicoRegionOverride == 8) ? 1 : 0; - return 0; } @@ -1788,7 +1906,7 @@ static void debug_menu_loop(void) 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); + 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); @@ -1948,7 +2066,7 @@ 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, menu_main_plat_draw); @@ -1996,7 +2114,7 @@ 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, NULL); @@ -2047,29 +2165,6 @@ void menu_plat_setup(int is_wiz) e_menu_gfx_options[i].need_to_save = 0; } -/* 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; - } - } -} - /* hidden options for config engine only */ static menu_entry e_menu_hidden[] = { @@ -2083,6 +2178,7 @@ static menu_entry *e_menu_table[] = e_menu_gfx_options, e_menu_adv_options, e_menu_cd_options, + e_menu_32x_options, e_menu_keyconfig, e_menu_hidden, };