bugfix/improvement
[libpicofe.git] / psp / menu.c
index 356597f..cdcf1e6 100644 (file)
@@ -43,7 +43,7 @@ static unsigned short bg_buffer[480*272] __attribute__((aligned(16)));
 #define menu_screen psp_screen
 
 static void menu_darken_bg(void *dst, const void *src, int pixels, int darker);
-static void menu_prepare_bg(int use_game_bg);
+static void menu_prepare_bg(int use_game_bg, int use_fg);
 
 
 static unsigned int inp_prev = 0;
@@ -190,10 +190,10 @@ static void draw_dirlist(char *curdir, struct my_dirent **namelist, int n, int s
                if (pos > 26) break;
                if (namelist[i+1]->d_type & DT_DIR) {
                        smalltext_out16_lim(14,   pos*10, "/", 0xd7ff, 1);
-                       smalltext_out16_lim(14+6, pos*10, namelist[i+1]->d_name, 0xd7ff, 53-3);
+                       smalltext_out16_lim(14+6, pos*10, namelist[i+1]->d_name, 0xd7ff, 80-3);
                } else {
                        unsigned short color = file2color(namelist[i+1]->d_name);
-                       smalltext_out16_lim(14,   pos*10, namelist[i+1]->d_name, color, 53-2);
+                       smalltext_out16_lim(14,   pos*10, namelist[i+1]->d_name, color, 80-2);
                }
        }
        text_out16(5, 130, ">");
@@ -552,7 +552,7 @@ static void draw_savestate_bg(int slot)
        }
 
        emu_forcedFrame();
-       menu_prepare_bg(1);
+       menu_prepare_bg(1, 0);
 
        restore_oldstate(oldstate);
 }
@@ -962,6 +962,7 @@ menu_entry opt3_entries[] =
        { NULL,                        MB_NONE,  MA_OPT3_HSCALE32,      NULL, 0, 0, 0, 1 },
        { NULL,                        MB_NONE,  MA_OPT3_HSCALE40,      NULL, 0, 0, 0, 1 },
        { NULL,                        MB_ONOFF, MA_OPT3_FILTERING,     &currentConfig.scaling, 1, 0, 0, 1 },
+       { NULL,                        MB_NONE,  MA_OPT3_VSYNC,         NULL, 0, 0, 0, 1 },
        { "Set to unscaled centered",  MB_NONE,  MA_OPT3_PRES_NOSCALE,  NULL, 0, 0, 0, 1 },
        { "Set to fullscreen",         MB_NONE,  MA_OPT3_PRES_FULLSCR,  NULL, 0, 0, 0, 1 },
        { "done",                      MB_NONE,  MA_OPT3_DONE,          NULL, 0, 0, 0, 1 },
@@ -986,6 +987,13 @@ static void menu_opt3_cust_draw(const menu_entry *entry, int x, int y, void *par
                case MA_OPT3_FILTERING:
                        text_out16(x, y, "Bilinear filtering                 %s", currentConfig.scaling?"ON":"OFF");
                        break;
+               case MA_OPT3_VSYNC: {
+                       char *val = "    never";
+                       if (currentConfig.EmuOpt & 0x2000)
+                               val = (currentConfig.EmuOpt & 0x10000) ? "sometimes" : "   always";
+                       text_out16(x, y, "Wait for vsync (slow)         %s", val);
+                       break;
+               }
                default: break;
        }
 }
@@ -1016,18 +1024,18 @@ static void menu_opt3_preview(int is_32col)
 
        memset32(psp_screen, 0, 512*272*2/4);
        emu_forcedFrame();
-       menu_prepare_bg(1);
+       menu_prepare_bg(1, 0);
 
        if (oldstate) restore_oldstate(oldstate);
 }
 
 static void draw_dispmenu_options(int menu_sel)
 {
-       int tl_x = 80+25, tl_y = 16+50;
+       int tl_x = 80, tl_y = 16+50;
 
        menu_draw_begin();
 
-       menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 252);
+       menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 316);
 
        me_draw(opt3_entries, OPT3_ENTRY_COUNT, tl_x, tl_y, menu_opt3_cust_draw, NULL);
 
@@ -1037,13 +1045,13 @@ static void draw_dispmenu_options(int menu_sel)
 static void dispmenu_loop_options(void)
 {
        static int menu_sel = 0;
-       int menu_sel_max, is_32col = 0;
+       int menu_sel_max, is_32col = (Pico.video.reg[12]&1)^1;
        unsigned long inp = 0;
        menu_id selected_id;
 
        menu_sel_max = me_count_enabled(opt3_entries, OPT3_ENTRY_COUNT) - 1;
 
-       for(;;)
+       for (;;)
        {
                draw_dispmenu_options(menu_sel);
                inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_X|BTN_CIRCLE);
@@ -1056,12 +1064,19 @@ static void dispmenu_loop_options(void)
                if (inp & (BTN_LEFT|BTN_RIGHT)) // multi choise
                {
                        float *setting = NULL;
+                       int tmp;
                        me_process(opt3_entries, OPT3_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0);
                        switch (selected_id) {
                                case MA_OPT3_SCALE:    setting = &currentConfig.scale; break;
                                case MA_OPT3_HSCALE40: setting = &currentConfig.hscale40; is_32col = 0; break;
                                case MA_OPT3_HSCALE32: setting = &currentConfig.hscale32; is_32col = 1; break;
                                case MA_OPT3_FILTERING:menu_opt3_preview(is_32col); break;
+                               case MA_OPT3_VSYNC:    tmp = ((currentConfig.EmuOpt>>13)&1) | ((currentConfig.EmuOpt>>15)&2);
+                                       tmp = (inp & BTN_LEFT) ? (tmp>>1) : ((tmp<<1)|1);
+                                       if (tmp > 3) tmp = 3;
+                                       currentConfig.EmuOpt &= ~0x12000;
+                                       currentConfig.EmuOpt |= ((tmp&2)<<15) | ((tmp&1)<<13);
+                                       break;
                                default: break;
                        }
                        if (setting != NULL) {
@@ -1218,12 +1233,12 @@ static void menu_opt_cust_draw(const menu_entry *entry, int x, int y, void *para
        {
                case MA_OPT_RENDERER:
                        if (currentConfig.PicoOpt&0x10)
-                               str = " 8bit fast";
+                               str = "fast";
                        else if (currentConfig.EmuOpt&0x80)
-                               str = "16bit accurate";
+                               str = "accurate";
                        else
-                               str = " 8bit accurate";
-                       text_out16(x, y, "Renderer:            %s", str);
+                               str = " 8bit accurate"; // n/a
+                       text_out16(x, y, "Renderer:                  %s", str);
                        break;
                case MA_OPT_FRAMESKIP:
                        if (currentConfig.Frameskip < 0)
@@ -1353,31 +1368,16 @@ static int menu_loop_options(void)
                        if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0)) {
                                switch (selected_id) {
                                        case MA_OPT_RENDERER:
-                                               if (inp & BTN_LEFT) {
-                                                       if ((currentConfig.PicoOpt&0x10) || !(currentConfig.EmuOpt &0x80)) {
-                                                               currentConfig.PicoOpt&= ~0x10;
-                                                               currentConfig.EmuOpt |=  0x80;
-                                                       }
+                                               if ((currentConfig.PicoOpt&0x10) || !(currentConfig.EmuOpt &0x80)) {
+                                                       currentConfig.PicoOpt&= ~0x10;
+                                                       currentConfig.EmuOpt |=  0x80;
                                                } else {
-                                                       if (!(currentConfig.PicoOpt&0x10) || (currentConfig.EmuOpt &0x80)) {
-                                                               currentConfig.PicoOpt|=  0x10;
-                                                               currentConfig.EmuOpt &= ~0x80;
-                                                       }
+                                                       currentConfig.PicoOpt|=  0x10;
+                                                       currentConfig.EmuOpt &= ~0x80;
                                                }
                                                break;
                                        case MA_OPT_SOUND_QUALITY:
-                                               if ((inp & BTN_RIGHT) && currentConfig.PsndRate == 44100 &&
-                                                               !(currentConfig.PicoOpt&0x08))
-                                               {
-                                                       currentConfig.PsndRate =  11025;
-                                                       currentConfig.PicoOpt |=  8;
-                                               } else if ((inp & BTN_LEFT) && currentConfig.PsndRate == 11025 &&
-                                                               (currentConfig.PicoOpt&0x08) && !(PicoMCD&1))
-                                               {
-                                                       currentConfig.PsndRate =  44100;
-                                                       currentConfig.PicoOpt &= ~8;
-                                               } else
-                                                       currentConfig.PsndRate = sndrate_prevnext(currentConfig.PsndRate, inp & BTN_RIGHT);
+                                               currentConfig.PsndRate = sndrate_prevnext(currentConfig.PsndRate, inp & BTN_RIGHT);
                                                break;
                                        case MA_OPT_REGION:
                                                region_prevnext(inp & BTN_RIGHT);
@@ -1477,12 +1477,15 @@ static void draw_menu_credits(void)
 
        y = tl_y;
        text_out16(tl_x, y, "Credits:");
-       text_out16(tl_x, (y+=10), "Dave: base code of PicoDrive");
+       text_out16(tl_x, (y+=10), "fDave: base code of PicoDrive");
+       text_out16(tl_x, (y+=10), "Chui: Fame/C");
+       text_out16(tl_x, (y+=10), "NJ: CZ80");
        text_out16(tl_x, (y+=10), "MAME devs: YM2612 and SN76496 cores");
-       text_out16(tl_x, (y+=10), "Charles MacDonald: Genesis hw docs");
        text_out16(tl_x, (y+=10), "Stephane Dallongeville:");
-       text_out16(tl_x, (y+=10), "      opensource Gens");
+       text_out16(tl_x, (y+=10), "    Gens code, base of Fame/C, CZ80");
+       text_out16(tl_x, (y+=10), "Charles MacDonald: Genesis hw docs");
        text_out16(tl_x, (y+=10), "Haze: Genesis hw info");
+       text_out16(tl_x, (y+=10), "ps2dev.org people: PSP SDK/code");
        text_out16(tl_x, (y+=10), "ketchupgun: skin design");
 
        menu_draw_end();
@@ -1670,13 +1673,13 @@ static void menu_darken_bg(void *dst, const void *src, int pixels, int darker)
        }
 }
 
-static void menu_prepare_bg(int use_game_bg)
+static void menu_prepare_bg(int use_game_bg, int use_fg)
 {
        if (use_game_bg)
        {
                // darken the active framebuffer
                unsigned short *dst = bg_buffer;
-               unsigned short *src = psp_screen;
+               unsigned short *src = use_fg ? psp_video_get_active_fb() : psp_screen;
                int i;
                for (i = 272; i > 0; i--, dst += 480, src += 512)
                        menu_darken_bg(dst, src, 480, 1);
@@ -1693,7 +1696,7 @@ static void menu_prepare_bg(int use_game_bg)
 
 static void menu_gfx_prepare(void)
 {
-       menu_prepare_bg(rom_data != NULL);
+       menu_prepare_bg(rom_data != NULL, 1);
 
        menu_draw_begin();
        menu_draw_end();