X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=common%2Fmenu.c;h=ded7bbcf734691ed263ae50a08d49c5bf80b9264;hb=b188c2b6d0448a9c328a9dcae5ba5c8c8b5273f3;hp=5fc2a5768defa9f9951d952ad5a7f334f4d0479e;hpb=22b2271a09c970cf2d4c9ba28460f7a5aa2a6127;p=libpicofe.git diff --git a/common/menu.c b/common/menu.c index 5fc2a57..ded7bbc 100644 --- a/common/menu.c +++ b/common/menu.c @@ -17,16 +17,15 @@ #include "plat.h" #include "posix.h" #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 @@ -278,7 +277,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) @@ -301,6 +301,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; @@ -547,7 +590,16 @@ 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 mgn_opt_renderer NULL /* TODO */ +#define menu_main_plat_draw NULL +#endif static void draw_menu_credits(void) { @@ -602,7 +654,7 @@ static void load_progress_cb(int percent) 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; @@ -610,7 +662,7 @@ static void cdload_progress_cb(int percent) 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) @@ -625,20 +677,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; @@ -647,7 +697,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(); @@ -664,7 +715,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) @@ -712,6 +763,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; @@ -722,7 +774,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) @@ -745,10 +798,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); } @@ -790,13 +848,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); @@ -815,6 +876,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); @@ -971,8 +1037,8 @@ 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; + void *tmp_vram; + const char *fname; fname = emu_get_save_fname(1, 0, slot); if (!fname) return; @@ -985,32 +1051,11 @@ static void draw_savestate_bg(int slot) memcpy(tmp_vsram, Pico.vsram, sizeof(Pico.vsram)); memcpy(&tmp_pv, &Pico.video, sizeof(Pico.video)); - if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) { - file = gzopen(fname, "rb"); - emu_setSaveStateCbs(1); - } else { - file = fopen(fname, "rb"); - emu_setSaveStateCbs(0); - } - - 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); - } + PicoStateLoadVDP(fname); /* 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)); @@ -1058,6 +1103,9 @@ static int menu_loop_savestate(int is_loading) 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); @@ -1438,6 +1486,22 @@ static int menu_loop_cd_options(menu_id id, int keys) return 0; } +// ------------ 32X options menu ------------ + +static menu_entry e_menu_32x_options[] = +{ + mee_onoff("32X enabled", MA_32XOPT_ENABLE_32X, PicoOpt, POPT_EN_32X), + 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; + me_loop(e_menu_32x_options, &sel, NULL); + return 0; +} + // ------------ adv options menu ------------ static menu_entry e_menu_adv_options[] = @@ -1451,7 +1515,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, }; @@ -1466,14 +1530,14 @@ static int menu_loop_adv_options(menu_id id, int keys) static int mh_opt_render(menu_id id, int keys) { - plat_video_toggle_renderer((keys & PBTN_RIGHT) ? 1 : 0, 1); + plat_video_toggle_renderer((keys & PBTN_RIGHT) ? 1 : 0, 0, 1); return 0; } static menu_entry e_menu_gfx_options[] = { mee_cust ("Renderer", MA_OPT_RENDERER, mh_opt_render, mgn_opt_renderer), - MENU_GP2X_OPTIONS_GFX + MENU_OPTIONS_GFX mee_end, }; @@ -1685,8 +1749,9 @@ static menu_entry e_menu_options[] = 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_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 ("[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), mee_handler_mkname_id(MA_OPT_LOADCFG, mh_saveloadcfg, mgn_loadcfg), @@ -1703,10 +1768,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; } @@ -1758,17 +1819,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); + smalltext_out16(4, 1, "build: r" REVISION " "__DATE__ " " __TIME__ " " COMPILER, 0xffff); smalltext_out16(4, g_screen_height - me_sfont_h, layer_str, 0xffff); } @@ -1795,7 +1863,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); @@ -1804,19 +1872,23 @@ static void debug_menu_loop(void) 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); @@ -1834,6 +1906,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; @@ -1950,7 +2023,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); @@ -1958,7 +2031,8 @@ void menu_loop(void) 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); @@ -1968,24 +2042,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_cd_check(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) @@ -1995,19 +2059,19 @@ 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, NULL); @@ -2058,29 +2122,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[] = { @@ -2094,6 +2135,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, };