1.30 release
[picodrive.git] / platform / gp2x / menu.c
index 236b693..47b91b1 100644 (file)
@@ -17,8 +17,9 @@
 #include "usbjoy.h"\r
 #include "version.h"\r
 \r
-#include "Pico/PicoInt.h"\r
-#include "zlib/zlib.h"\r
+#include <Pico/PicoInt.h>\r
+#include <Pico/Patch.h>\r
+#include <zlib/zlib.h>\r
 \r
 #ifndef _DIRENT_HAVE_D_TYPE\r
 #error "need d_type for file browser\r
@@ -391,6 +392,54 @@ static char *romsel_loop(char *curr_path)
        return ret;\r
 }\r
 \r
+// ------------ patch/gg menu ------------\r
+\r
+static void draw_patchlist(int sel)\r
+{\r
+       int start, i, pos;\r
+\r
+       start = 12 - sel;\r
+\r
+       gp2x_pd_clone_buffer2();\r
+\r
+       for (i = 0; i < PicoPatchCount; i++) {\r
+               pos = start + i;\r
+               if (pos < 0)  continue;\r
+               if (pos > 23) break;\r
+               gp2x_smalltext8_lim(14,     pos*10, PicoPatches[i].active ? "ON " : "OFF", 3);\r
+               gp2x_smalltext8_lim(14+6*4, pos*10, PicoPatches[i].name, 53-6);\r
+       }\r
+       pos = start + i;\r
+       if (pos < 24) gp2x_smalltext8_lim(14, pos*10, "done", 4);\r
+\r
+       gp2x_text_out8(5, 120, ">");\r
+       gp2x_video_flip2();\r
+}\r
+\r
+\r
+void patches_menu_loop(void)\r
+{\r
+       int menu_sel = 0;\r
+       unsigned long inp = 0;\r
+\r
+       for(;;)\r
+       {\r
+               draw_patchlist(menu_sel);\r
+               inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_B|GP2X_X);\r
+               if(inp & GP2X_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }\r
+               if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }\r
+               if(inp &(GP2X_LEFT|GP2X_L))  { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }\r
+               if(inp &(GP2X_RIGHT|GP2X_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }\r
+               if(inp & GP2X_B) { // action\r
+                       if (menu_sel < PicoPatchCount)\r
+                               PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;\r
+                       else    return;\r
+               }\r
+               if(inp & GP2X_X) return;\r
+       }\r
+\r
+}\r
+\r
 // ------------ savestate loader ------------\r
 \r
 static void menu_prepare_bg(void);\r
@@ -680,6 +729,10 @@ static void kc_sel_loop(void)
 static void draw_cd_menu_options(int menu_sel, char *b_us, char *b_eu, char *b_jp)\r
 {\r
        int tl_x = 25, tl_y = 60, y;\r
+       char ra_buff[16];\r
+\r
+       if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2);\r
+       else strcpy(ra_buff, "     OFF");\r
 \r
        y = tl_y;\r
        //memset(gp2x_screen, 0, 320*240);\r
@@ -691,7 +744,9 @@ static void draw_cd_menu_options(int menu_sel, char *b_us, char *b_eu, char *b_j
        gp2x_text_out8(tl_x, (y+=10), "CD LEDs                    %s", (currentConfig.EmuOpt &0x0400)?"ON":"OFF"); // 3\r
        gp2x_text_out8(tl_x, (y+=10), "CDDA audio (using mp3s)    %s", (currentConfig.PicoOpt&0x0800)?"ON":"OFF"); // 4\r
        gp2x_text_out8(tl_x, (y+=10), "PCM audio                  %s", (currentConfig.PicoOpt&0x0400)?"ON":"OFF"); // 5\r
-       gp2x_text_out8(tl_x, (y+=10), "Better sync (very slow)    %s", (currentConfig.PicoOpt&0x2000)?"ON":"OFF"); // 6\r
+       gp2x_text_out8(tl_x, (y+=10), "ReadAhead buffer      %s", ra_buff); // 6\r
+       gp2x_text_out8(tl_x, (y+=10), "Scale/Rot. fx (buggy,slow) %s", (currentConfig.PicoOpt&0x1000)?"ON":"OFF"); // 7\r
+       gp2x_text_out8(tl_x, (y+=10), "Better sync (slow)         %s", (currentConfig.PicoOpt&0x2000)?"ON":"OFF"); // 8\r
        gp2x_text_out8(tl_x, (y+=10), "Done");\r
 \r
        // draw cursor\r
@@ -707,7 +762,7 @@ static void draw_cd_menu_options(int menu_sel, char *b_us, char *b_eu, char *b_j
 \r
 static void cd_menu_loop_options(void)\r
 {\r
-       int menu_sel = 0, menu_sel_max = 7;\r
+       int menu_sel = 0, menu_sel_max = 9;\r
        unsigned long inp = 0;\r
        char bios_us[32], bios_eu[32], bios_jp[32], *bios, *p;\r
 \r
@@ -737,8 +792,19 @@ static void cd_menu_loop_options(void)
                                case  3: currentConfig.EmuOpt ^=0x0400; break;\r
                                case  4: currentConfig.PicoOpt^=0x0800; break;\r
                                case  5: currentConfig.PicoOpt^=0x0400; break;\r
-                               case  6: currentConfig.PicoOpt^=0x2000; break;\r
-                               case  7: return;\r
+                               case  6:\r
+                                       if (inp & GP2X_LEFT) {\r
+                                               PicoCDBuffers >>= 1;\r
+                                               if (PicoCDBuffers < 64) PicoCDBuffers = 0;\r
+                                       } else {\r
+                                               if (PicoCDBuffers < 64) PicoCDBuffers = 64;\r
+                                               else PicoCDBuffers <<= 1;\r
+                                               if (PicoCDBuffers > 8*1024) PicoCDBuffers = 8*1024; // 16M\r
+                                       }\r
+                                       break;\r
+                               case  7: currentConfig.PicoOpt^=0x1000; break;\r
+                               case  8: currentConfig.PicoOpt^=0x2000; break;\r
+                               case  9: return;\r
                        }\r
                }\r
                if(inp & (GP2X_X|GP2X_A)) return;\r
@@ -1106,6 +1172,8 @@ static void draw_menu_root(int menu_sel)
        gp2x_text_out8(tl_x, (y+=10), "Configure controls");\r
        gp2x_text_out8(tl_x, (y+=10), "Credits");\r
        gp2x_text_out8(tl_x, (y+=10), "Exit");\r
+       if (PicoPatches)\r
+               gp2x_text_out8(tl_x, (y+=10), "Patches / GameGenie");\r
 \r
        // draw cursor\r
        gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
@@ -1133,6 +1201,7 @@ static void menu_loop_root(void)
        }\r
 \r
        if (rom_data) menu_sel = menu_sel_min = 0;\r
+       if (PicoPatches) menu_sel_max = 9;\r
 \r
        for(;;)\r
        {\r
@@ -1199,6 +1268,14 @@ static void menu_loop_root(void)
                                case 8: // exit\r
                                        engineState = PGS_Quit;\r
                                        return;\r
+                               case 9: // patches/gg\r
+                                       if (rom_data && PicoPatches) {\r
+                                               patches_menu_loop();\r
+                                               PicoPatchApply();\r
+                                               strcpy(menuErrorMsg, "Patches applied");\r
+                                               continue;\r
+                                       }\r
+                                       break;\r
                        }\r
                }\r
                menuErrorMsg[0] = 0; // clear error msg\r