giz rc1 release
[picodrive.git] / platform / gizmondo / menu.c
index 74bb6e1..bf56c32 100644 (file)
@@ -19,6 +19,7 @@
 #include "menu.h"\r
 #include "../common/arm_utils.h"\r
 #include "../common/menu.h"\r
+#include "../common/emu.h"\r
 #include "../common/readpng.h"\r
 #include "version.h"\r
 #include "kgsdk/Framework.h"\r
 #include <Pico/Patch.h>\r
 #include <zlib/zlib.h>\r
 \r
-extern char romFileName[MAX_PATH];\r
-extern char *rom_data;\r
-extern int  state_slot;\r
-extern int  config_slot, config_slot_current;\r
 \r
 #define gizKeyUnkn "???"\r
 static const char * const gizKeyNames[] = {\r
        "LEFT",          "RIGHT",          "UP",       "DOWN",     "STOP",       "PLAY",   "FORWARD",  "REWIND",\r
-       "LEFT_SHOULDER", "RIGHT_SHOULDER", "HOME",     "VOLUME",   "BRIGHTNESS", "ALARM",  "POWER",    gizKeyUnkn,\r
-       gizKeyUnkn,      gizKeyUnkn,       gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn,\r
+       "L",             "R",              "HOME",     "VOLUME",   "BRIGHTNESS", "ALARM",  "POWER",    gizKeyUnkn,\r
        gizKeyUnkn,      gizKeyUnkn,       gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn,\r
+       gizKeyUnkn,      gizKeyUnkn,       gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn\r
 };\r
 \r
-static unsigned char bg_buffer[321*240*2];\r
-unsigned char menu_screen[321*240*2]; /* draw here and blit later, to avoid flicker */\r
-char menuErrorMsg[40] = {0, };\r
+static unsigned char *bg_buffer = gfx_buffer + 321*240*2;\r
+unsigned char *menu_screen = gfx_buffer; /* draw here and blit later, to avoid flicker */\r
 \r
 static void menu_darken_bg(void *dst, const void *src, int pixels, int darker);\r
 static void menu_prepare_bg(int use_game_bg);\r
@@ -120,7 +116,7 @@ static void load_progress_cb(int percent)
        dst = (unsigned short *)menu_screen + 321*20;\r
 \r
        if (len > 320) len = 320;\r
-       for (ln = 10; ln > 0; ln--, dst += 320)\r
+       for (ln = 10; ln > 0; ln--, dst += 321)\r
                memset(dst, 0xff, len*2);\r
        menu_draw_end();\r
 }\r
@@ -441,6 +437,36 @@ static char *romsel_loop(char *curr_path)
 }\r
 #endif\r
 \r
+// ------------ debug menu ------------\r
+\r
+char *debugString(void);\r
+\r
+static void draw_debug(void)\r
+{\r
+       char *p, *str = debugString();\r
+       int len, line;\r
+\r
+       menu_draw_begin(1);\r
+\r
+       p = str;\r
+       for (line = 0; line < 24; line++)\r
+       {\r
+               while (*p && *p != '\n') p++;\r
+               len = p - str;\r
+               if (len > 55) len = 55;\r
+               smalltext_out16_lim(1, line*10, str, 0xffff, len);\r
+               if (*p == 0) break;\r
+               p++; str = p;\r
+       }\r
+       menu_draw_end();\r
+}\r
+\r
+static void debug_menu_loop(void)\r
+{\r
+       draw_debug();\r
+       wait_for_input(BTN_PLAY|BTN_STOP);\r
+}\r
+\r
 // ------------ patch/gg menu ------------\r
 \r
 static void draw_patchlist(int sel)\r
@@ -502,7 +528,7 @@ static void state_check_slots(void)
 \r
        for (slot = 0; slot < 10; slot++)\r
        {\r
-               if (emu_check_save_file(slot))\r
+               if (emu_checkSaveFile(slot))\r
                {\r
                        state_slot_flags |= 1 << slot;\r
                }\r
@@ -530,10 +556,10 @@ static void draw_savestate_bg(int slot)
 \r
        if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) {\r
                file = gzopen(fname, "rb");\r
-               emu_set_save_cbs(1);\r
+               emu_setSaveStateCbs(1);\r
        } else {\r
                file = fopen(fname, "rb");\r
-               emu_set_save_cbs(0);\r
+               emu_setSaveStateCbs(0);\r
        }\r
 \r
        if (file) {\r
@@ -551,7 +577,7 @@ static void draw_savestate_bg(int slot)
                areaClose(file);\r
        }\r
 \r
-       emu_forced_frame();\r
+       emu_forcedFrame();\r
        menu_prepare_bg(1);\r
 \r
        memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram));\r
@@ -687,13 +713,13 @@ static void draw_key_config(const bind_action_t *opts, int opt_cnt, int player_i
 \r
        if (sel < opt_cnt) {\r
                text_out16(30, 180, "Press a button to bind/unbind");\r
-               text_out16(30, 190, "Use SELECT to clear");\r
-               text_out16(30, 200, "To bind UP/DOWN, hold SELECT");\r
+               text_out16(30, 190, "Use HOME to clear");\r
+               text_out16(30, 200, "To bind UP/DOWN, hold HOME");\r
                text_out16(30, 210, "Select \"Done\" to exit");\r
        } else {\r
                text_out16(30, 190, "Use Options -> Save cfg");\r
                text_out16(30, 200, "to save controls");\r
-               text_out16(30, 210, "Press B or X to exit");\r
+               text_out16(30, 210, "Press PLAY or STOP to exit");\r
        }\r
        menu_draw_end();\r
 }\r
@@ -706,7 +732,7 @@ static void key_config_loop(const bind_action_t *opts, int opt_cnt, int player_i
        for (;;)\r
        {\r
                draw_key_config(opts, opt_cnt, player_idx, sel);\r
-               inp = wait_for_input(CONFIGURABLE_KEYS);\r
+               inp = wait_for_input(CONFIGURABLE_KEYS|BTN_HOME);\r
                if (!(inp & BTN_HOME)) {\r
                        prev_select = 0;\r
                        if(inp & BTN_UP  ) { sel--; if (sel < 0) sel = menu_sel_max; continue; }\r
@@ -781,7 +807,6 @@ static bind_action_t emuctrl_actions[] =
        { "Switch Renderer", 1<<26 },\r
        { "Volume Down    ", 1<<30 },\r
        { "Volume Up      ", 1<<29 },\r
-       { "Enter Menu     ", 1<<23 },\r
 };\r
 \r
 static void kc_sel_loop(void)\r
@@ -888,17 +913,17 @@ static void cd_menu_loop_options(void)
        menu_id selected_id;\r
        char *bios, *p;\r
 \r
-       if (find_bios(4, &bios)) { // US\r
+       if (emu_findBios(4, &bios)) { // US\r
                for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r
                strncpy(bios_names.us, p, sizeof(bios_names.us)); bios_names.us[sizeof(bios_names.us)-1] = 0;\r
        } else  strcpy(bios_names.us, "NOT FOUND");\r
 \r
-       if (find_bios(8, &bios)) { // EU\r
+       if (emu_findBios(8, &bios)) { // EU\r
                for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r
                strncpy(bios_names.eu, p, sizeof(bios_names.eu)); bios_names.eu[sizeof(bios_names.eu)-1] = 0;\r
        } else  strcpy(bios_names.eu, "NOT FOUND");\r
 \r
-       if (find_bios(1, &bios)) { // JP\r
+       if (emu_findBios(1, &bios)) { // JP\r
                for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r
                strncpy(bios_names.jp, p, sizeof(bios_names.jp)); bios_names.jp[sizeof(bios_names.jp)-1] = 0;\r
        } else  strcpy(bios_names.jp, "NOT FOUND");\r
@@ -930,21 +955,21 @@ static void cd_menu_loop_options(void)
                        }\r
                        switch (selected_id) { // BIOS testers\r
                                case MA_CDOPT_TESTBIOS_USA:\r
-                                       if (find_bios(4, &bios)) { // test US\r
+                                       if (emu_findBios(4, &bios)) { // test US\r
                                                strcpy(romFileName, bios);\r
                                                engineState = PGS_ReloadRom;\r
                                                return;\r
                                        }\r
                                        break;\r
                                case MA_CDOPT_TESTBIOS_EUR:\r
-                                       if (find_bios(8, &bios)) { // test EU\r
+                                       if (emu_findBios(8, &bios)) { // test EU\r
                                                strcpy(romFileName, bios);\r
                                                engineState = PGS_ReloadRom;\r
                                                return;\r
                                        }\r
                                        break;\r
                                case MA_CDOPT_TESTBIOS_JAP:\r
-                                       if (find_bios(1, &bios)) { // test JP\r
+                                       if (emu_findBios(1, &bios)) { // test JP\r
                                                strcpy(romFileName, bios);\r
                                                engineState = PGS_ReloadRom;\r
                                                return;\r
@@ -966,6 +991,7 @@ menu_entry opt2_entries[] =
        { "Emulate Z80",               MB_ONOFF, MA_OPT2_ENABLE_Z80,    &currentConfig.PicoOpt,0x0004, 0, 0, 1 },\r
        { "Emulate YM2612 (FM)",       MB_ONOFF, MA_OPT2_ENABLE_YM2612, &currentConfig.PicoOpt,0x0001, 0, 0, 1 },\r
        { "Emulate SN76496 (PSG)",     MB_ONOFF, MA_OPT2_ENABLE_SN76496,&currentConfig.PicoOpt,0x0002, 0, 0, 1 },\r
+       { "Wait for V-sync (slow)",    MB_ONOFF, MA_OPT2_VSYNC,         &currentConfig.EmuOpt, 0x2000, 0, 0, 1 },\r
        { "gzip savestates",           MB_ONOFF, MA_OPT2_GZIP_STATES,   &currentConfig.EmuOpt, 0x0008, 0, 0, 1 },\r
        { "Don't save last used ROM",  MB_ONOFF, MA_OPT2_NO_LAST_ROM,   &currentConfig.EmuOpt, 0x0020, 0, 0, 1 },\r
        { "done",                      MB_NONE,  MA_OPT2_DONE,          NULL, 0, 0, 0, 1 },\r
@@ -1006,7 +1032,7 @@ static void amenu_loop_options(void)
                if (inp & (BTN_LEFT|BTN_RIGHT)) { // multi choise\r
                        if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0) &&\r
                            selected_id == MA_OPT2_GAMMA) {\r
-                               while ((inp = Framework_PollGetButtons(1)) & (BTN_LEFT|BTN_RIGHT)) {\r
+                               while ((inp = Framework_PollGetButtons()) & (BTN_LEFT|BTN_RIGHT)) {\r
                                        currentConfig.gamma += (inp & BTN_LEFT) ? -1 : 1;\r
                                        if (currentConfig.gamma <   1) currentConfig.gamma =   1;\r
                                        if (currentConfig.gamma > 300) currentConfig.gamma = 300;\r
@@ -1031,16 +1057,17 @@ static void amenu_loop_options(void)
 menu_entry opt_entries[] =\r
 {\r
        { NULL,                        MB_NONE,  MA_OPT_RENDERER,      NULL, 0, 0, 0, 1 },\r
-       { "Scale low res mode",        MB_ONOFF, MA_OPT_SCALING,       &currentConfig.scaling, 0x001, 0, 3, 1 },\r
-       { "Accurate timing (slower)",  MB_ONOFF, MA_OPT_ACC_TIMING,    &currentConfig.PicoOpt, 0x040, 0, 0, 1 },\r
-       { "Accurate sprites (slower)", MB_ONOFF, MA_OPT_ACC_SPRITES,   &currentConfig.PicoOpt, 0x080, 0, 0, 1 },\r
-       { "Show FPS",                  MB_ONOFF, MA_OPT_SHOW_FPS,      &currentConfig.EmuOpt,  0x002, 0, 0, 1 },\r
+       { "Interlaced rend. (faster)", MB_ONOFF, MA_OPT_INTERLACED,    &currentConfig.EmuOpt,  0x4000, 0, 0, 1 },\r
+       { "Scale low res mode",        MB_ONOFF, MA_OPT_SCALING,       &currentConfig.scaling, 0x0001, 0, 3, 1 },\r
+       { "Accurate timing (slower)",  MB_ONOFF, MA_OPT_ACC_TIMING,    &currentConfig.PicoOpt, 0x0040, 0, 0, 1 },\r
+       { "Accurate sprites (slower)", MB_ONOFF, MA_OPT_ACC_SPRITES,   &currentConfig.PicoOpt, 0x0080, 0, 0, 1 },\r
+       { "Show FPS",                  MB_ONOFF, MA_OPT_SHOW_FPS,      &currentConfig.EmuOpt,  0x0002, 0, 0, 1 },\r
        { NULL,                        MB_RANGE, MA_OPT_FRAMESKIP,     &currentConfig.Frameskip, 0, -1, 16, 1 },\r
-       { "Enable sound",              MB_ONOFF, MA_OPT_ENABLE_SOUND,  &currentConfig.EmuOpt,  0x004, 0, 0, 1 },\r
+       { "Enable sound",              MB_ONOFF, MA_OPT_ENABLE_SOUND,  &currentConfig.EmuOpt,  0x0004, 0, 0, 1 },\r
        { NULL,                        MB_NONE,  MA_OPT_SOUND_QUALITY, NULL, 0, 0, 0, 1 },\r
-       { "6 button pad",              MB_ONOFF, MA_OPT_6BUTTON_PAD,   &currentConfig.PicoOpt, 0x020, 0, 0, 1 },\r
+       { "6 button pad",              MB_ONOFF, MA_OPT_6BUTTON_PAD,   &currentConfig.PicoOpt, 0x0020, 0, 0, 1 },\r
        { NULL,                        MB_NONE,  MA_OPT_REGION,        NULL, 0, 0, 0, 1 },\r
-       { "Use SRAM/BRAM savestates",  MB_ONOFF, MA_OPT_SRAM_STATES,   &currentConfig.EmuOpt,  0x001, 0, 0, 1 },\r
+       { "Use SRAM/BRAM savestates",  MB_ONOFF, MA_OPT_SRAM_STATES,   &currentConfig.EmuOpt,  0x0001, 0, 0, 1 },\r
        { NULL,                        MB_NONE,  MA_OPT_CONFIRM_STATES,NULL, 0, 0, 0, 1 },\r
        { "Save slot",                 MB_RANGE, MA_OPT_SAVE_SLOT,     &state_slot, 0, 0, 9, 1 },\r
        { "[Sega/Mega CD options]",    MB_NONE,  MA_OPT_SCD_OPTS,      NULL, 0, 0, 0, 1 },\r
@@ -1144,14 +1171,14 @@ static void draw_menu_options(int menu_sel)
 \r
 static int sndrate_prevnext(int rate, int dir)\r
 {\r
-       int i, rates[] = { 8000, 11025, 16000, 22050, 44100 };\r
+       int i, rates[] = { 11025, 22050, 44100 };\r
 \r
        for (i = 0; i < 5; i++)\r
                if (rates[i] == rate) break;\r
 \r
        i += dir ? 1 : -1;\r
-       if (i > 4) return dir ? 44100 : 22050;\r
-       if (i < 0) return dir ? 11025 : 8000;\r
+       if (i > 2) return dir ? 44100 : 22050;\r
+       if (i < 0) return dir ? 22050 : 11025;\r
        return rates[i];\r
 }\r
 \r
@@ -1188,7 +1215,6 @@ static void menu_options_save(void)
                // unbind XYZ MODE, just in case\r
                unbind_action(0xf00);\r
        }\r
-       scaling_update();\r
 }\r
 \r
 static int menu_loop_options(void)\r
@@ -1219,21 +1245,30 @@ static int menu_loop_options(void)
                                switch (selected_id) {\r
                                        case MA_OPT_RENDERER:\r
                                                if (inp & BTN_LEFT) {\r
-                                                       if      (  currentConfig.PicoOpt&0x10) currentConfig.PicoOpt&= ~0x10;\r
-                                                       else if (!(currentConfig.EmuOpt &0x80))currentConfig.EmuOpt |=  0x80;\r
-                                                       else if (  currentConfig.EmuOpt &0x80) break;\r
+                                                       if ((currentConfig.PicoOpt&0x10) || !(currentConfig.EmuOpt &0x80)) {\r
+                                                               currentConfig.PicoOpt&= ~0x10;\r
+                                                               currentConfig.EmuOpt |=  0x80;\r
+                                                       }\r
                                                } else {\r
-                                                       if      (  currentConfig.PicoOpt&0x10) break;\r
-                                                       else if (!(currentConfig.EmuOpt &0x80))currentConfig.PicoOpt|=  0x10;\r
-                                                       else if (  currentConfig.EmuOpt &0x80) currentConfig.EmuOpt &= ~0x80;\r
+                                                       if (!(currentConfig.PicoOpt&0x10) || (currentConfig.EmuOpt &0x80)) {\r
+                                                               currentConfig.PicoOpt|=  0x10;\r
+                                                               currentConfig.EmuOpt &= ~0x80;\r
+                                                       }\r
                                                }\r
                                                break;\r
                                        case MA_OPT_SOUND_QUALITY:\r
-                                               if ((inp & BTN_RIGHT) && currentConfig.PsndRate == 44100 && !(currentConfig.PicoOpt&0x08)) {\r
-                                                       currentConfig.PsndRate = 8000;  currentConfig.PicoOpt|= 0x08;\r
-                                               } else if ((inp & BTN_LEFT) && currentConfig.PsndRate == 8000 && (currentConfig.PicoOpt&0x08)) {\r
-                                                       currentConfig.PsndRate = 44100; currentConfig.PicoOpt&=~0x08;\r
-                                               } else currentConfig.PsndRate = sndrate_prevnext(currentConfig.PsndRate, inp & BTN_RIGHT);\r
+                                               if ((inp & BTN_RIGHT) && currentConfig.PsndRate == 44100 &&\r
+                                                               !(currentConfig.PicoOpt&0x08))\r
+                                               {\r
+                                                       currentConfig.PsndRate =  11025;\r
+                                                       currentConfig.PicoOpt |=  8;\r
+                                               } else if ((inp & BTN_LEFT) && currentConfig.PsndRate == 11025 &&\r
+                                                               (currentConfig.PicoOpt&0x08) && !(PicoMCD&1))\r
+                                               {\r
+                                                       currentConfig.PsndRate =  44100;\r
+                                                       currentConfig.PicoOpt &= ~8;\r
+                                               } else\r
+                                                       currentConfig.PsndRate = sndrate_prevnext(currentConfig.PsndRate, inp & BTN_RIGHT);\r
                                                break;\r
                                        case MA_OPT_REGION:\r
                                                region_prevnext(inp & BTN_RIGHT);\r
@@ -1319,6 +1354,7 @@ static void draw_menu_credits(void)
        menu_draw_begin(1);\r
 \r
        text_out16(tl_x, 20, "PicoDrive v" VERSION " (c) notaz, 2006,2007");\r
+text_out16(tl_x, 30, "rc1");\r
        y = tl_y;\r
        text_out16(tl_x, y, "Credits:");\r
        text_out16(tl_x, (y+=10), "Dave: Cyclone 68000 core,");\r
@@ -1329,8 +1365,8 @@ static void draw_menu_credits(void)
        text_out16(tl_x, (y+=10), "Stephane Dallongeville:");\r
        text_out16(tl_x, (y+=10), "      opensource Gens");\r
        text_out16(tl_x, (y+=10), "Haze: Genesis hw info");\r
-       text_out16(tl_x, (y+=10), "Reesy: TODO");\r
-       text_out16(tl_x, (y+=10), "TODO: gizmondo hardware");\r
+       text_out16(tl_x, (y+=10), "Reesy: kgsdk wrapper, sound code");\r
+       text_out16(tl_x, (y+=10), "jens.l: gizmondo hardware");\r
        text_out16(tl_x, (y+=10), "ketchupgun: skin design");\r
 \r
        menu_draw_end();\r
@@ -1394,7 +1430,7 @@ static void menu_loop_root(void)
        /* make sure action buttons are not pressed on entering menu */\r
        draw_menu_root(menu_sel);\r
 \r
-       while (Framework_PollGetButtons(1) & (BTN_PLAY|BTN_STOP|BTN_HOME)) Sleep(50);\r
+       while (Framework_PollGetButtons() & (BTN_PLAY|BTN_STOP|BTN_HOME)) Sleep(50);\r
 \r
        for (;;)\r
        {\r
@@ -1402,9 +1438,10 @@ static void menu_loop_root(void)
                inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY|BTN_STOP|BTN_HOME|BTN_L|BTN_R);\r
                if(inp & BTN_UP  )  { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
                if(inp & BTN_DOWN)  { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
-               if(inp &(BTN_HOME|BTN_STOP)){\r
+               if((inp & (BTN_L|BTN_R)) == (BTN_L|BTN_R)) debug_menu_loop();\r
+               if( inp & (BTN_HOME|BTN_STOP)) {\r
                        if (rom_data) {\r
-                               while (Framework_PollGetButtons(1) & (BTN_HOME|BTN_STOP)) Sleep(50); // wait until select is released\r
+                               while (Framework_PollGetButtons() & (BTN_HOME|BTN_STOP)) Sleep(50); // wait until released\r
                                engineState = PGS_Running;\r
                                break;\r
                        }\r
@@ -1414,7 +1451,7 @@ static void menu_loop_root(void)
                        {\r
                                case MA_MAIN_RESUME_GAME:\r
                                        if (rom_data) {\r
-                                               while (Framework_PollGetButtons(1) & BTN_PLAY) Sleep(50);\r
+                                               while (Framework_PollGetButtons() & BTN_PLAY) Sleep(50);\r
                                                engineState = PGS_Running;\r
                                                return;\r
                                        }\r
@@ -1524,10 +1561,13 @@ static void menu_prepare_bg(int use_game_bg)
        if (use_game_bg)\r
        {\r
                // darken the active framebuffer\r
-               // TODO: take from somewhere else, not giz_screen\r
+               if (giz_screen == NULL)\r
+                       giz_screen = Framework2D_LockBuffer();\r
                memset(bg_buffer, 0, 321*8*2);\r
                menu_darken_bg(bg_buffer + 321*8*2, (char *)giz_screen + 321*8*2, 321*224, 1);\r
                memset(bg_buffer + 321*232*2, 0, 321*8*2);\r
+               Framework2D_UnlockBuffer();\r
+               giz_screen = NULL;\r
        }\r
        else\r
        {\r
@@ -1603,7 +1643,7 @@ int menu_loop_tray(void)
 \r
        /* make sure action buttons are not pressed on entering menu */\r
        draw_menu_tray(menu_sel);\r
-       while (Framework_PollGetButtons(1) & BTN_PLAY) Sleep(50);\r
+       while (Framework_PollGetButtons() & BTN_PLAY) Sleep(50);\r
 \r
        for (;;)\r
        {\r
@@ -1617,7 +1657,7 @@ int menu_loop_tray(void)
                                        selfname = romsel_loop(curr_path);\r
                                        if (selfname) {\r
                                                int ret = -1, cd_type;\r
-                                               cd_type = emu_cd_check(NULL);\r
+                                               cd_type = emu_cdCheck(NULL);\r
                                                if (cd_type > 0)\r
                                                        ret = Insert_CD(romFileName, cd_type == 2);\r
                                                if (ret != 0) {\r