release r2, update credits
[fceu.git] / drivers / gp2x / menu.c
index d3eb71e..e0fb738 100644 (file)
 \r
 #include "minimal.h"\r
 #include "usbjoy.h"\r
-#include "asmutils.h"\r
+#include "../arm/asmutils.h"\r
 #include "menu.h"\r
-#include "main.h"\r
-#include "fonts.h"\r
+#include "../common/main.h"\r
+#include "../libpicofe/fonts.h"\r
 #include "gp2x.h"\r
 \r
 #include "../../input.h"\r
 #include "../../state.h"\r
 #include "../../palette.h"\r
-#include "readpng.h"\r
+#include "../libpicofe/readpng.h"\r
 \r
 #ifndef _DIRENT_HAVE_D_TYPE\r
-#error "need d_type for file browser\r
+#error need d_type for file browser\r
 #endif\r
 \r
 extern int GP2X_PORT_REV;\r
@@ -166,7 +166,7 @@ void gp2x_text_out15_lim(int x, int y, const char *texto, int max)
        gp2x_text_out15(x,y,buffer);\r
 }\r
 \r
-static void gp2x_smalltext16(int x, int y, const char *texto)\r
+static void gp2x_smalltext16(int x, int y, const char *texto, unsigned short color)\r
 {\r
        int i;\r
        unsigned char  *src;\r
@@ -187,7 +187,7 @@ static void gp2x_smalltext16(int x, int y, const char *texto)
                        int w = 0x20;\r
                        while (w)\r
                        {\r
-                               if( *src & w ) *dst = 0xffff;\r
+                               if( *src & w ) *dst = color;\r
                                dst++;\r
                                w>>=1;\r
                        }\r
@@ -198,7 +198,7 @@ static void gp2x_smalltext16(int x, int y, const char *texto)
        }\r
 }\r
 \r
-static void gp2x_smalltext16_lim(int x, int y, const char *texto, int max)\r
+static void gp2x_smalltext16_lim(int x, int y, const char *texto, unsigned short color, int max)\r
 {\r
        char    buffer[320/6+1];\r
 \r
@@ -207,7 +207,7 @@ static void gp2x_smalltext16_lim(int x, int y, const char *texto, int max)
        if (max < 0) max = 0;\r
        buffer[max] = 0;\r
 \r
-       gp2x_smalltext16(x, y, buffer);\r
+       gp2x_smalltext16(x, y, buffer, color);\r
 }\r
 \r
 \r
@@ -299,6 +299,22 @@ static unsigned long wait_for_input_usbjoy(unsigned long interesting, int *joy)
 \r
 // -------------- ROM selector --------------\r
 \r
+// rrrr rggg gggb bbbb\r
+static unsigned short file2color(const char *fname)\r
+{\r
+       const char *ext = fname + strlen(fname) - 3;\r
+       static const char *rom_exts[]   = { "zip", "nes", "fds", "unf", "nez", "nif" }; // nif is for unif\r
+       static const char *other_exts[] = { "nsf", "ips", "fcm" };\r
+       int i;\r
+\r
+       if (ext < fname) ext = fname;\r
+       for (i = 0; i < sizeof(rom_exts)/sizeof(rom_exts[0]); i++)\r
+               if (strcasecmp(ext, rom_exts[i]) == 0) return 0xbdff;\r
+       for (i = 0; i < sizeof(other_exts)/sizeof(other_exts[0]); i++)\r
+               if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5;\r
+       return 0xffff;\r
+}\r
+\r
 static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)\r
 {\r
        int start, i, pos;\r
@@ -310,16 +326,17 @@ static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)
        gp2x_fceu_darken_all();\r
 \r
        if(start - 2 >= 0)\r
-               gp2x_smalltext16_lim(14, (start - 2)*10, curdir, 53-2);\r
+               gp2x_smalltext16_lim(14, (start - 2)*10, curdir, 0xffff, 53-2);\r
        for (i = 0; i < n; i++) {\r
                pos = start + i;\r
                if (pos < 0)  continue;\r
                if (pos > 23) break;\r
                if (namelist[i+1]->d_type == DT_DIR) {\r
-                       gp2x_smalltext16_lim(14,   pos*10, "/", 1);\r
-                       gp2x_smalltext16_lim(14+6, pos*10, namelist[i+1]->d_name, 53-3);\r
+                       gp2x_smalltext16_lim(14,   pos*10, "/", 0xfff6, 1);\r
+                       gp2x_smalltext16_lim(14+6, pos*10, namelist[i+1]->d_name, 0xfff6, 53-3);\r
                } else {\r
-                       gp2x_smalltext16_lim(14,   pos*10, namelist[i+1]->d_name, 53-2);\r
+                       unsigned short color = file2color(namelist[i+1]->d_name);\r
+                       gp2x_smalltext16_lim(14,   pos*10, namelist[i+1]->d_name, color, 53-2);\r
                }\r
        }\r
        gp2x_text_out15(5, 120, ">");\r
@@ -328,7 +345,8 @@ static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)
 \r
 static int scandir_cmp(const void *p1, const void *p2)\r
 {\r
-       struct dirent **d1 = (struct dirent **)p1, **d2 = (struct dirent **)p2;\r
+       const struct dirent **d1 = (const struct dirent **)p1;\r
+       const struct dirent **d2 = (const struct dirent **)p2;\r
        if ((*d1)->d_type == (*d2)->d_type) return alphasort(d1, d2);\r
        if ((*d1)->d_type == DT_DIR) return -1; // put before\r
        if ((*d2)->d_type == DT_DIR) return  1;\r
@@ -336,7 +354,7 @@ static int scandir_cmp(const void *p1, const void *p2)
 }\r
 \r
 static char *filter_exts[] = {\r
-       ".gpe", ".png", "ck.o", ".txt"\r
+       ".gpe", ".png", "ck.o", ".txt", ".srm"\r
 };\r
 \r
 static int scandir_filter(const struct dirent *ent)\r
@@ -375,10 +393,10 @@ static char *filesel_loop(char *curr_path, char *final_dest)
                fname = p+1;\r
        }\r
 \r
-       n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp);\r
+       n = scandir(curr_path, &namelist, scandir_filter, (void *)scandir_cmp);\r
        if (n < 0) {\r
                // try root\r
-               n = scandir("/", &namelist, scandir_filter, scandir_cmp);\r
+               n = scandir("/", &namelist, scandir_filter, (void *)scandir_cmp);\r
                if (n < 0) {\r
                        // oops, we failed\r
                        printf("dir: %s\n", curr_path);\r
@@ -490,9 +508,9 @@ static int clistcallb(char *name, uint32 a, uint8 v, int compare, int s, int typ
        if (pos < 0)  return 1;\r
        if (pos > 23) return 0;\r
 \r
-       gp2x_smalltext16_lim(14,     pos*10, s ? "ON " : "OFF", 3);\r
-       gp2x_smalltext16_lim(14+6*4, pos*10, type ? "S" : "R", 1);\r
-       gp2x_smalltext16_lim(14+6*6, pos*10, name, 53-8);\r
+       gp2x_smalltext16_lim(14,     pos*10, s ? "ON " : "OFF", 0xffff, 3);\r
+       gp2x_smalltext16_lim(14+6*4, pos*10, type ? "S" : "R", 0xffff, 1);\r
+       gp2x_smalltext16_lim(14+6*6, pos*10, name, 0xffff, 53-8);\r
 \r
        return 1;\r
 }\r
@@ -509,7 +527,7 @@ static void draw_patchlist(int sel)
        FCEUI_ListCheats(clistcallb,0);\r
 \r
        pos = cheat_start + cheat_pos;\r
-       if (pos < 24) gp2x_smalltext16_lim(14, pos*10, "done", 4);\r
+       if (pos < 24) gp2x_smalltext16_lim(14, pos*10, "done", 0xffff, 4);\r
 \r
        gp2x_text_out15(5, 120, ">");\r
        menu_flip();\r
@@ -911,7 +929,7 @@ static void kc_sel_loop(void)
                if(inp & GP2X_B) {\r
                        switch (menu_sel) {\r
                                case 0: key_config_loop(ctrl_actions, 10, 0); return;\r
-                               case 1: key_config_loop(ctrl_actions,  8, 1); return;\r
+                               case 1: key_config_loop(ctrl_actions, 10, 1); return;\r
                                case 2: key_config_loop(emuctrl_actions,\r
                                                sizeof(emuctrl_actions)/sizeof(emuctrl_actions[0]), -1); return;\r
                                case 3: if (!fceugi) SaveConfig(NULL); return;\r
@@ -1139,7 +1157,7 @@ static void config_commit(void)
 static int menu_loop_options(void)\r
 {\r
        static int menu_sel = 0;\r
-       int menu_sel_max = 16;\r
+       int ret, menu_sel_max = 16;\r
        unsigned long inp = 0;\r
 \r
        if (fceugi) menu_sel_max++;\r
@@ -1161,12 +1179,16 @@ static int menu_loop_options(void)
                                case 15: fcemenu_loop_options(); break;\r
                                case 16: // done (update and write)\r
                                        config_commit();\r
-                                       SaveConfig(NULL);\r
+                                       ret = SaveConfig(NULL);\r
+                                       strcpy(menuErrorMsg, ret == 0 ? "default config saved" : "config save failed");\r
                                        return 1;\r
                                case 17: // done (update and write for current game)\r
-                                       config_commit();\r
                                        if (lastLoadedGameName[0])\r
-                                               SaveConfig(lastLoadedGameName);\r
+                                       {\r
+                                               config_commit();\r
+                                               ret = SaveConfig(lastLoadedGameName);\r
+                                               strcpy(menuErrorMsg, ret == 0 ? "game config saved" : "config save failed");\r
+                                       }\r
                                        return 1;\r
                        }\r
                }\r
@@ -1415,7 +1437,7 @@ static void menu_prepare_bg(void)
        else\r
        {\r
                memset32((int *)menu_bg, 0, 320*240*2/4);\r
-               readpng(menu_bg, "background.png");\r
+               readpng(menu_bg, "background.png", READPNG_BG, 320, 240);\r
        }\r
 }\r
 \r