patch/gg support, 1.201 release
[picodrive.git] / platform / gp2x / menu.c
index 236b693..032616a 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-5);\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
@@ -1106,6 +1155,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 +1184,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 +1251,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