tweak and refactor frontends, menu and config
[libpicofe.git] / common / menu.c
index 4ee5c19..8b69d20 100644 (file)
@@ -314,6 +314,17 @@ void menu_init(void)
        }\r
 }\r
 \r
+static void menu_draw_begin(int need_bg)\r
+{\r
+       plat_video_menu_begin();\r
+       if (need_bg)\r
+               memcpy(g_menuscreen_ptr, g_menubg_ptr, g_menuscreen_w * g_menuscreen_h * 2);\r
+}\r
+\r
+static void menu_draw_end(void)\r
+{\r
+       plat_video_menu_end();\r
+}\r
 \r
 static void menu_darken_bg(void *dst, void *src, int pixels, int darker)\r
 {\r
@@ -342,12 +353,8 @@ static void menu_enter(int is_rom_loaded)
 {\r
        if (is_rom_loaded)\r
        {\r
-               void *src = g_menubg_src_ptr;\r
-               if (src == NULL)\r
-                       src = g_menuscreen_ptr;\r
-\r
                // darken the active framebuffer\r
-               menu_darken_bg(g_menubg_ptr, src, g_menuscreen_w * g_menuscreen_h, 1);\r
+               menu_darken_bg(g_menubg_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h, 1);\r
        }\r
        else\r
        {\r
@@ -466,7 +473,7 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void))
        y = g_menuscreen_h / 2 - h / 2;\r
 \r
        /* draw */\r
-       plat_video_menu_begin();\r
+       menu_draw_begin(1);\r
        menu_draw_selection(x, y + vi_sel_ln * me_mfont_h, w);\r
        x += me_mfont_w * 2;\r
 \r
@@ -547,7 +554,7 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void))
        if (draw_more != NULL)\r
                draw_more();\r
 \r
-       plat_video_menu_end();\r
+       menu_draw_end();\r
 }\r
 \r
 static int me_process(menu_entry *entry, int is_next, int is_lr)\r
@@ -687,7 +694,7 @@ static void draw_menu_credits(void)
        if (x < 0) x = 0;\r
        if (y < 0) y = 0;\r
 \r
-       plat_video_menu_begin();\r
+       menu_draw_begin(1);\r
 \r
        for (p = creds; *p != 0 && y <= g_menuscreen_h - me_mfont_h; y += me_mfont_h) {\r
                text_out16(x, y, p);\r
@@ -698,7 +705,7 @@ static void draw_menu_credits(void)
                        p++;\r
        }\r
 \r
-       plat_video_menu_end();\r
+       menu_draw_end();\r
 }\r
 \r
 // --------- loading ROM screen ----------\r
@@ -708,20 +715,25 @@ static int cdload_called = 0;
 static void load_progress_cb(int percent)\r
 {\r
        int ln, len = percent * g_menuscreen_w / 100;\r
-       unsigned short *dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2;\r
+       unsigned short *dst;\r
 \r
        if (len > g_menuscreen_w)\r
                len = g_menuscreen_w;\r
+\r
+       menu_draw_begin(0);\r
+       dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2;\r
        for (ln = me_sfont_h - 2; ln > 0; ln--, dst += g_menuscreen_w)\r
                memset(dst, 0xff, len * 2);\r
-       plat_video_menu_end();\r
+       menu_draw_end();\r
 }\r
 \r
 static void cdload_progress_cb(const char *fname, int percent)\r
 {\r
        int ln, len = percent * g_menuscreen_w / 100;\r
-       unsigned short *dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2;\r
+       unsigned short *dst;\r
 \r
+       menu_draw_begin(0);\r
+       dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2;\r
        memset(dst, 0xff, g_menuscreen_w * (me_sfont_h - 2) * 2);\r
 \r
        smalltext_out16(1, 3 * me_sfont_h, "Processing CD image / MP3s", 0xffff);\r
@@ -730,10 +742,11 @@ static void cdload_progress_cb(const char *fname, int percent)
 \r
        if (len > g_menuscreen_w)\r
                len = g_menuscreen_w;\r
+\r
        for (ln = (me_sfont_h - 2); ln > 0; ln--, dst += g_menuscreen_w)\r
                memset(dst, 0xff, len * 2);\r
+       menu_draw_end();\r
 \r
-       plat_video_menu_end();\r
        cdload_called = 1;\r
 }\r
 \r
@@ -747,10 +760,10 @@ void menu_romload_prepare(const char *rom_name)
 \r
        /* fill all buffers, callbacks won't update in full */\r
        for (i = 0; i < 3; i++) {\r
-               plat_video_menu_begin();\r
+               menu_draw_begin(1);\r
                smalltext_out16(1, 1, "Loading", 0xffff);\r
                smalltext_out16(1, me_sfont_h, p, 0xffff);\r
-               plat_video_menu_end();\r
+               menu_draw_end();\r
        }\r
 \r
        PicoCartLoadProgressCB = load_progress_cb;\r
@@ -762,9 +775,11 @@ void menu_romload_end(void)
 {\r
        PicoCartLoadProgressCB = NULL;\r
        PicoCDLoadProgressCB = NULL;\r
+\r
+       menu_draw_begin(0);\r
        smalltext_out16(1, (cdload_called ? 6 : 3) * me_sfont_h,\r
                "Starting emulation...", 0xffff);\r
-       plat_video_menu_end();\r
+       menu_draw_end();\r
 }\r
 \r
 // -------------- del confirm ---------------\r
@@ -775,7 +790,7 @@ static void do_delete(const char *fpath, const char *fname)
        const char *nm;\r
        char tmp[64];\r
 \r
-       plat_video_menu_begin();\r
+       menu_draw_begin(1);\r
 \r
        if (!rom_loaded)\r
                menu_darken_bg(g_menuscreen_ptr, g_menuscreen_ptr, g_menuscreen_w * g_menuscreen_h, 0);\r
@@ -797,7 +812,7 @@ static void do_delete(const char *fpath, const char *fname)
        len = strlen(tmp);\r
 \r
        text_out16(mid - me_mfont_w * len / 2, 12 * me_mfont_h, tmp);\r
-       plat_video_menu_end();\r
+       menu_draw_end();\r
 \r
        while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MA2));\r
        inp = in_menu_wait(PBTN_MA3|PBTN_MBACK, 100);\r
@@ -832,7 +847,7 @@ static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)
        start = max_cnt / 2 - sel;\r
        n--; // exclude current dir (".")\r
 \r
-       plat_video_menu_begin();\r
+       menu_draw_begin(1);\r
 \r
 //     if (!rom_loaded)\r
 //             menu_darken_bg(gp2x_screen, 320*240, 0);\r
@@ -856,7 +871,7 @@ static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)
                }\r
        }\r
        smalltext_out16(5, max_cnt/2 * me_sfont_h, ">", 0xffff);\r
-       plat_video_menu_end();\r
+       menu_draw_end();\r
 }\r
 \r
 static int scandir_cmp(const void *p1, const void *p2)\r
@@ -1038,7 +1053,7 @@ static void draw_patchlist(int sel)
        max_cnt = g_menuscreen_h / me_sfont_h;\r
        start = max_cnt / 2 - sel;\r
 \r
-       plat_video_menu_begin();\r
+       menu_draw_begin(1);\r
 \r
        for (i = 0; i < PicoPatchCount; i++) {\r
                pos = start + i;\r
@@ -1053,7 +1068,7 @@ static void draw_patchlist(int sel)
                smalltext_out16(14, pos * me_sfont_h, "done", 0xffff);\r
 \r
        text_out16(5, max_cnt / 2 * me_sfont_h, ">");\r
-       plat_video_menu_end();\r
+       menu_draw_end();\r
 }\r
 \r
 static void menu_loop_patches(void)\r
@@ -1109,8 +1124,9 @@ static void draw_savestate_bg(int slot)
        PicoStateLoadGfx(fname);\r
 \r
        /* do a frame and fetch menu bg */\r
-       pemu_forced_frame(POPT_EN_SOFTSCALE, 0);\r
-       menu_enter(1);\r
+       pemu_forced_frame(0, 0);\r
+\r
+       menu_darken_bg(g_menubg_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h, 1);\r
 \r
        PicoTmpStateRestore(tmp_state);\r
 }\r
@@ -1129,7 +1145,7 @@ static void draw_savestate_menu(int menu_sel, int is_loading)
        y = g_menuscreen_h / 2 - h / 2;\r
        if (y < 0) y = 0;\r
 \r
-       plat_video_menu_begin();\r
+       menu_draw_begin(1);\r
 \r
        text_out16(x, y, is_loading ? "Load state" : "Save state");\r
        y += 3 * me_mfont_h;\r
@@ -1143,7 +1159,7 @@ static void draw_savestate_menu(int menu_sel, int is_loading)
        }\r
        text_out16(x, y, "back");\r
 \r
-       plat_video_menu_end();\r
+       menu_draw_end();\r
 }\r
 \r
 static int menu_loop_savestate(int is_loading)\r
@@ -1199,7 +1215,7 @@ static int menu_loop_savestate(int is_loading)
 \r
 static char *action_binds(int player_idx, int action_mask, int dev_id)\r
 {\r
-       int k, count, can_combo, type;\r
+       int k, count = 0, can_combo = 0, type;\r
        const int *binds;\r
 \r
        static_buff[0] = 0;\r
@@ -1208,8 +1224,8 @@ static char *action_binds(int player_idx, int action_mask, int dev_id)
        if (binds == NULL)\r
                return static_buff;\r
 \r
-       count = in_get_dev_info(dev_id, IN_INFO_BIND_COUNT);\r
-       can_combo = in_get_dev_info(dev_id, IN_INFO_DOES_COMBOS);\r
+       in_get_config(dev_id, IN_CFG_BIND_COUNT, &count);\r
+       in_get_config(dev_id, IN_CFG_DOES_COMBOS, &can_combo);\r
 \r
        type = IN_BINDTYPE_EMU;\r
        if (player_idx >= 0) {\r
@@ -1244,13 +1260,13 @@ static int count_bound_keys(int dev_id, int action_mask, int bindtype)
 {\r
        const int *binds;\r
        int k, keys = 0;\r
-       int count;\r
+       int count = 0;\r
 \r
        binds = in_get_dev_binds(dev_id);\r
        if (binds == NULL)\r
                return 0;\r
 \r
-       count = in_get_dev_info(dev_id, IN_INFO_BIND_COUNT);\r
+       in_get_config(dev_id, IN_CFG_BIND_COUNT, &count);\r
        for (k = 0; k < count; k++)\r
        {\r
                if (binds[IN_BIND_OFFS(k, bindtype)] & action_mask)\r
@@ -1273,7 +1289,7 @@ static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_
        if (x < me_mfont_w * 2)\r
                x = me_mfont_w * 2;\r
 \r
-       plat_video_menu_begin();\r
+       menu_draw_begin(1);\r
        if (player_idx >= 0)\r
                text_out16(x, y, "Player %i controls", player_idx + 1);\r
        else\r
@@ -1309,12 +1325,12 @@ static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_
                text_out16(x, g_menuscreen_h - 2 * me_mfont_h, "Press left/right for other devs");\r
        }\r
 \r
-       plat_video_menu_end();\r
+       menu_draw_end();\r
 }\r
 \r
 static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_idx)\r
 {\r
-       int i, sel = 0, menu_sel_max = opt_cnt - 1;\r
+       int i, sel = 0, menu_sel_max = opt_cnt - 1, does_combos = 0;\r
        int dev_id, dev_count, kc, is_down, mkey;\r
        int unbind, bindtype, mask_shift;\r
 \r
@@ -1383,8 +1399,8 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_
                unbind = (i > 0);\r
 \r
                /* allow combos if device supports them */\r
-               if (i == 1 && bindtype == IN_BINDTYPE_EMU &&\r
-                               in_get_dev_info(dev_id, IN_INFO_DOES_COMBOS))\r
+               in_get_config(dev_id, IN_CFG_DOES_COMBOS, &does_combos);\r
+               if (i == 1 && bindtype == IN_BINDTYPE_EMU && does_combos)\r
                        unbind = 0;\r
 \r
                if (unbind)\r
@@ -1477,6 +1493,7 @@ static menu_entry e_menu_keyconfig[] =
        mee_handler_id("Emulator controls", MA_CTRL_EMU,        key_config_loop_wrap),\r
        mee_onoff     ("6 button pad",      MA_OPT_6BUTTON_PAD, PicoOpt, POPT_6BTN_PAD),\r
        mee_range     ("Turbo rate",        MA_CTRL_TURBO_RATE, currentConfig.turbo_rate, 1, 30),\r
+       mee_range     ("Analog deadzone",   MA_CTRL_DEADZONE,   currentConfig.analog_deadzone, 1, 99),\r
        mee_cust_nosave("Save global config",       MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),\r
        mee_cust_nosave("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),\r
        mee_label     (""),\r
@@ -1834,7 +1851,7 @@ static menu_entry e_menu_options[] =
        mee_onoff     ("Enable sound",             MA_OPT_ENABLE_SOUND,  currentConfig.EmuOpt, EOPT_EN_SOUND),\r
        mee_cust      ("Sound Quality",            MA_OPT_SOUND_QUALITY, mh_opt_misc, mgn_opt_sound),\r
        mee_enum_h    ("Confirm savestate",        MA_OPT_CONFIRM_STATES,currentConfig.confirm_save, men_confirm_save, h_confirm_save),\r
-       mee_range     ("",                         MA_OPT_CPU_CLOCKS,    currentConfig.CPUclock, 20, 900),\r
+       mee_range     ("",                         MA_OPT_CPU_CLOCKS,    currentConfig.CPUclock, 20, 1200),\r
        mee_handler   ("[Display options]",        menu_loop_gfx_options),\r
        mee_handler   ("[Sega/Mega CD options]",   menu_loop_cd_options),\r
 #ifndef NO_32X\r
@@ -1854,7 +1871,7 @@ static int menu_loop_options(menu_id id, int keys)
        int i;\r
 \r
        i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);\r
-       e_menu_options[i].enabled = e_menu_options[i].name ? 1 : 0;\r
+       e_menu_options[i].enabled = e_menu_options[i].name[0] ? 1 : 0;\r
        me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, rom_loaded);\r
        me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);\r
 \r
@@ -1926,8 +1943,8 @@ static void draw_frame_debug(void)
        if (PicoDrawMask & PDRAW_SPRITES_HI_ON)  memcpy(layer_str + 19, "spr_hi", 6);\r
        if (PicoDrawMask & PDRAW_32X_ON)         memcpy(layer_str + 26, "32x", 4);\r
 \r
-       memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);\r
-       pemu_forced_frame(0, 0);\r
+       pemu_forced_frame(1, 0);\r
+       memcpy(g_menuscreen_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h * 2);\r
        smalltext_out16(4, 1, "build: r" REVISION "  "__DATE__ " " __TIME__ " " COMPILER, 0xffff);\r
        smalltext_out16(4, g_menuscreen_h - me_sfont_h, layer_str, 0xffff);\r
 }\r
@@ -1940,10 +1957,10 @@ static void debug_menu_loop(void)
 \r
        while (1)\r
        {\r
+               menu_draw_begin(1);\r
                switch (mode)\r
                {\r
-                       case 0: plat_video_menu_begin();\r
-                               tmp = PDebugMain();\r
+                       case 0: tmp = PDebugMain();\r
                                plat_debug_cat(tmp);\r
                                draw_text_debug(tmp, 0, 0);\r
                                if (dumped) {\r
@@ -1954,9 +1971,8 @@ static void debug_menu_loop(void)
                                break;\r
                        case 1: draw_frame_debug();\r
                                break;\r
-                       case 2: memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);\r
-                               pemu_forced_frame(0, 1);\r
-                               menu_darken_bg(g_menuscreen_ptr, g_menuscreen_ptr, g_menuscreen_w * g_menuscreen_h, 0);\r
+                       case 2: pemu_forced_frame(1, 0);\r
+                               menu_darken_bg(g_menuscreen_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h, 0);\r
                                PDebugShowSpriteStats((unsigned short *)g_menuscreen_ptr + (g_menuscreen_h/2 - 240/2)*g_menuscreen_w +\r
                                        g_menuscreen_w/2 - 320/2, g_menuscreen_w);\r
                                break;\r
@@ -1966,12 +1982,11 @@ static void debug_menu_loop(void)
                                        g_menuscreen_w, spr_offs);\r
                                draw_text_debug(PDebugSpriteList(), spr_offs, 6);\r
                                break;\r
-                       case 4: plat_video_menu_begin();\r
-                               tmp = PDebug32x();\r
+                       case 4: tmp = PDebug32x();\r
                                draw_text_debug(tmp, 0, 0);\r
                                break;\r
                }\r
-               plat_video_menu_end();\r
+               menu_draw_end();\r
 \r
                inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R |\r
                                        PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, 70);\r
@@ -2118,7 +2133,7 @@ void menu_loop(void)
        me_enable(e_menu_main, MA_MAIN_PATCHES, PicoPatches != NULL);\r
 \r
        menu_enter(rom_loaded);\r
-       in_set_blocking(1);\r
+       in_set_config_int(0, IN_CFG_BLOCKING, 1);\r
        me_loop(e_menu_main, &sel, menu_main_plat_draw);\r
 \r
        if (rom_loaded) {\r
@@ -2129,7 +2144,7 @@ void menu_loop(void)
                        ;\r
        }\r
 \r
-       in_set_blocking(0);\r
+       in_set_config_int(0, IN_CFG_BLOCKING, 0);\r
 }\r
 \r
 // --------- CD tray close menu ----------\r
@@ -2167,7 +2182,7 @@ int menu_loop_tray(void)
 \r
        menu_enter(rom_loaded);\r
 \r
-       in_set_blocking(1);\r
+       in_set_config_int(0, IN_CFG_BLOCKING, 1);\r
        me_loop(e_menu_tray, &sel, NULL);\r
 \r
        if (engineState != PGS_RestartRun) {\r
@@ -2176,7 +2191,7 @@ int menu_loop_tray(void)
        }\r
 \r
        while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK));\r
-       in_set_blocking(0);\r
+       in_set_config_int(0, IN_CFG_BLOCKING, 0);\r
 \r
        return ret;\r
 }\r