idle loop hack, psp bugfix, plat debug str
[libpicofe.git] / common / menu.c
index bb59510..0f3fb61 100644 (file)
 #include "fonts.h"\r
 #include "readpng.h"\r
 #include "lprintf.h"\r
+#include "common.h"\r
+#include "emu.h"\r
 \r
-#if   defined(__GP2X__)\r
- #include "../gp2x/gp2x.h"\r
- #define SCREEN_WIDTH 320\r
- #define SCREEN_BUFFER gp2x_screen\r
-#elif defined(__GIZ__)\r
- //#include "../gizmondo/giz.h"\r
- #define SCREEN_WIDTH 321\r
- #define SCREEN_BUFFER menu_screen\r
- extern unsigned char *menu_screen;\r
-#elif defined(PSP)\r
- #include "../psp/psp.h"\r
- #define SCREEN_WIDTH 512\r
- #define SCREEN_BUFFER psp_screen\r
-#endif\r
 \r
 char menuErrorMsg[64] = { 0, };\r
 \r
+// PicoPad[] format: MXYZ SACB RLDU\r
+me_bind_action me_ctrl_actions[15] =\r
+{\r
+       { "UP     ", 0x0001 },\r
+       { "DOWN   ", 0x0002 },\r
+       { "LEFT   ", 0x0004 },\r
+       { "RIGHT  ", 0x0008 },\r
+       { "A      ", 0x0040 },\r
+       { "B      ", 0x0010 },\r
+       { "C      ", 0x0020 },\r
+       { "A turbo", 0x4000 },\r
+       { "B turbo", 0x1000 },\r
+       { "C turbo", 0x2000 },\r
+       { "START  ", 0x0080 },\r
+       { "MODE   ", 0x0800 },\r
+       { "X      ", 0x0400 },\r
+       { "Y      ", 0x0200 },\r
+       { "Z      ", 0x0100 }\r
+};\r
+\r
+\r
 static unsigned char menu_font_data[10240];\r
 static int menu_text_color = 0xffff; // default to white\r
 static int menu_sel_color = -1; // disabled\r
@@ -225,7 +234,6 @@ void menu_init(void)
                                int tmp = parse_hex_color(buff+16);\r
                                if (tmp >= 0) menu_sel_color = tmp;\r
                                else lprintf("skin.txt: parse error for selection_color\n");\r
-                               lprintf("sel color: %04x\n", menu_sel_color);\r
                        }\r
                        else\r
                                lprintf("skin.txt: parse error: %s\n", buff);\r
@@ -323,5 +331,145 @@ int me_process(menu_entry *entries, int count, menu_id id, int is_next)
        }\r
 }\r
 \r
+const char *me_region_name(unsigned int code, int auto_order)\r
+{\r
+       static const char *names[] = { "Auto", "      Japan NTSC", "      Japan PAL", "      USA", "      Europe" };\r
+       static const char *names_short[] = { "", " JP", " JP", " US", " EU" };\r
+       int u, i = 0;\r
+       if (code) {\r
+               code <<= 1;\r
+               while((code >>= 1)) i++;\r
+               if (i > 4) return "unknown";\r
+               return names[i];\r
+       } else {\r
+               static char name[24];\r
+               strcpy(name, "Auto:");\r
+               for (u = 0; u < 3; u++) {\r
+                       i = 0; code = ((auto_order >> u*4) & 0xf) << 1;\r
+                       while((code >>= 1)) i++;\r
+                       strcat(name, names_short[i]);\r
+               }\r
+               return name;\r
+       }\r
+}\r
+\r
+// ------------ debug menu ------------\r
+\r
+#include <sys/stat.h>\r
+#include <sys/types.h>\r
+\r
+#include <Pico/Pico.h>\r
+#include <Pico/Debug.h>\r
+\r
+void SekStepM68k(void);\r
+\r
+static void draw_text_debug(const char *str, int skip, int from)\r
+{\r
+       const char *p;\r
+       int len, line;\r
+\r
+       p = str;\r
+       while (skip-- > 0)\r
+       {\r
+               while (*p && *p != '\n') p++;\r
+               if (*p == 0 || p[1] == 0) return;\r
+               p++;\r
+       }\r
+\r
+       str = p;\r
+       for (line = from; line < SCREEN_HEIGHT/10; 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
+}\r
+\r
+static void draw_frame_debug(void)\r
+{\r
+       char layer_str[48] = "layers:             ";\r
+       if (PicoDrawMask & PDRAW_LAYERB_ON)      memcpy(layer_str +  8, "B", 1);\r
+       if (PicoDrawMask & PDRAW_LAYERA_ON)      memcpy(layer_str + 10, "A", 1);\r
+       if (PicoDrawMask & PDRAW_SPRITES_LOW_ON) memcpy(layer_str + 12, "spr_lo", 6);\r
+       if (PicoDrawMask & PDRAW_SPRITES_HI_ON)  memcpy(layer_str + 19, "spr_hi", 6);\r
+\r
+       clear_screen();\r
+       emu_forcedFrame(0);\r
+       smalltext_out16(4, SCREEN_HEIGHT-8, layer_str, 0xffff);\r
+}\r
+\r
+void debug_menu_loop(void)\r
+{\r
+       int inp, mode = 0;\r
+       int spr_offs = 0, dumped = 0;\r
+       char *tmp;\r
+\r
+       while (1)\r
+       {\r
+               switch (mode)\r
+               {\r
+                       case 0: menu_draw_begin();\r
+                               tmp = PDebugMain();\r
+                               emu_platformDebugCat(tmp);\r
+                               draw_text_debug(tmp, 0, 0);\r
+                               if (dumped) {\r
+                                       smalltext_out16(SCREEN_WIDTH-6*10, SCREEN_HEIGHT-8, "dumped", 0xffff);\r
+                                       dumped = 0;\r
+                               }\r
+                               break;\r
+                       case 1: draw_frame_debug(); break;\r
+                       case 2: clear_screen();\r
+                               emu_forcedFrame(0);\r
+                               darken_screen();\r
+                               PDebugShowSpriteStats((unsigned short *)SCREEN_BUFFER + (SCREEN_HEIGHT/2 - 240/2)*SCREEN_WIDTH +\r
+                                       SCREEN_WIDTH/2 - 320/2, SCREEN_WIDTH); break;\r
+                       case 3: clear_screen();\r
+                               PDebugShowPalette(SCREEN_BUFFER, SCREEN_WIDTH);\r
+                               PDebugShowSprite((unsigned short *)SCREEN_BUFFER + SCREEN_WIDTH*120+SCREEN_WIDTH/2+16,\r
+                                       SCREEN_WIDTH, spr_offs);\r
+                               draw_text_debug(PDebugSpriteList(), spr_offs, 6);\r
+                               break;\r
+               }\r
+               menu_draw_end();\r
+\r
+               inp = read_buttons(BTN_EAST|BTN_SOUTH|BTN_WEST|BTN_L|BTN_R|BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT);\r
+               if (inp & BTN_SOUTH) return;\r
+               if (inp & BTN_L) { mode--; if (mode < 0) mode = 3; }\r
+               if (inp & BTN_R) { mode++; if (mode > 3) mode = 0; }\r
+               switch (mode)\r
+               {\r
+                       case 0:\r
+                               if (inp & BTN_EAST) SekStepM68k();\r
+                               if ((inp & (BTN_WEST|BTN_LEFT)) == (BTN_WEST|BTN_LEFT)) {\r
+                                       mkdir("dumps", 0777);\r
+                                       PDebugDumpMem();\r
+                                       while (inp & BTN_WEST) inp = read_buttons_async(BTN_WEST);\r
+                                       dumped = 1;\r
+                               }\r
+                               break;\r
+                       case 1:\r
+                               if (inp & BTN_LEFT)  PicoDrawMask ^= PDRAW_LAYERB_ON;\r
+                               if (inp & BTN_RIGHT) PicoDrawMask ^= PDRAW_LAYERA_ON;\r
+                               if (inp & BTN_DOWN)  PicoDrawMask ^= PDRAW_SPRITES_LOW_ON;\r
+                               if (inp & BTN_UP)    PicoDrawMask ^= PDRAW_SPRITES_HI_ON;\r
+                               if (inp & BTN_EAST) {\r
+                                       PsndOut = NULL; // just in case\r
+                                       PicoSkipFrame = 1;\r
+                                       PicoFrame();\r
+                                       PicoSkipFrame = 0;\r
+                                       while (inp & BTN_EAST) inp = read_buttons_async(BTN_EAST);\r
+                               }\r
+                               break;\r
+                       case 3:\r
+                               if (inp & BTN_DOWN)  spr_offs++;\r
+                               if (inp & BTN_UP)    spr_offs--;\r
+                               if (spr_offs < 0) spr_offs = 0;\r
+                               break;\r
+               }\r
+       }\r
+}\r
 \r
 \r