usb joys, custom pal
authornotaz <notasas@gmail.com>
Sat, 2 Jun 2007 19:39:18 +0000 (19:39 +0000)
committernotaz <notasas@gmail.com>
Sat, 2 Jun 2007 19:39:18 +0000 (19:39 +0000)
git-svn-id: file:///home/notaz/opt/svn/fceu@146 be3aeb3a-fb24-0410-a615-afba39da0efa

Makefile.gp2x
Makefile.gp2x_test
drivers/gp2x/gp2x.c
drivers/gp2x/input.c
drivers/gp2x/main.c
drivers/gp2x/menu.c
general.c
input.c

index 4af881d..c38f0ea 100644 (file)
@@ -52,9 +52,8 @@ ncpu.o: ncpu.S ncpu.h
 include Makefile.base
 
 ${B}main.o:            ${B}main.c ${B}main.h ${B}usage.h ${B}input.c
-${B}gp2x.o:            ${B}gp2x.c ${B}gp2x.h
+${B}gp2x.o:            ${B}gp2x.c ${B}gp2x.h ${B}rev.h
 ${B}throttle.o:         ${B}throttle.c ${B}main.h ${B}throttle.h
-${B}menu.o:            ${B}rev.h
 ppu.o:                 ppu.c ppu.h
 
 ${B}rev.h: FORCE
index abb9545..bb6721f 100644 (file)
@@ -39,9 +39,8 @@ x6502.o: x6502.c x6502.h ops.h fce.h sound.h dprintf.h
 include Makefile.base
 
 ${B}main.o:            ${B}main.c ${B}main.h ${B}usage.h ${B}input.c
-${B}gp2x.o:            ${B}gp2x.c ${B}gp2x.h
+${B}gp2x.o:            ${B}gp2x.c ${B}gp2x.h ${B}rev.h
 ${B}throttle.o:         ${B}throttle.c ${B}main.h ${B}throttle.h
-${B}menu.o:            ${B}rev.h
 ppu.o:                 ppu.c ppu.h
 
 ${B}rev.h: FORCE
index 58bf931..a4834b3 100644 (file)
@@ -91,6 +91,7 @@ static void SetDefaults(void)
  Settings.sound_rate = 22050;
  Settings.turbo_rate_add = (8*2 << 24) / 60 + 1; // 8Hz turbofire
  Settings.gamma = 100;
+ Settings.sstate_confirm = 1;
  // default controls, RLDU SEBA
  Settings.KeyBinds[ 0] = 0x010; // GP2X_UP
  Settings.KeyBinds[ 4] = 0x020; // GP2X_DOWN
@@ -102,6 +103,9 @@ static void SetDefaults(void)
  Settings.KeyBinds[15] = 0x200; // GP2X_Y
  Settings.KeyBinds[ 8] = 0x008; // GP2X_START
  Settings.KeyBinds[ 9] = 0x004; // GP2X_SELECT
+ Settings.KeyBinds[10] = 0x80000000; // GP2X_L
+ Settings.KeyBinds[11] = 0x40000000; // GP2X_R
+ Settings.KeyBinds[27] = 0xc0000000; // GP2X_PUSH
 }
 
 void DoDriverArgs(void)
index daadc34..7c33a96 100644 (file)
@@ -18,6 +18,9 @@
 #include "../../state.h"
 #include "../../general.h"
 #include "../../input.h"
+#include "../../svga.h"
+#include "../../video.h"
+#include "usbjoy.h"
 
 /* UsrInputType[] is user-specified.  InputType[] is current
        (game loading can override user settings)
@@ -72,14 +75,42 @@ static void do_emu_acts(uint32 acts)
 
        if (acts & (3 << 30))
        {
+               unsigned long keys;
+               int do_it = 1;
                if (acts & (1 << 30))
                {
-                       FCEUI_LoadState();
+                       if (Settings.sstate_confirm & 2)
+                       {
+                               FCEU_DispMessage("LOAD STATE? (Y=yes, X=no)");
+                               FCEU_PutImage();
+                               FCEUD_Update(XBuf+8,NULL,0);
+                               while( !((keys = gp2x_joystick_read(1)) & (GP2X_X|GP2X_Y)) ) usleep(50*1024);
+                               if (keys & GP2X_X) do_it = 0;
+                               FCEU_DispMessage("");
+                       }
+                       if (do_it) FCEUI_LoadState();
                }
                else
                {
-                       FCEUI_SaveState();
+                       if (Settings.sstate_confirm & 1)
+                       {
+                               char *fname = FCEU_MakeFName(FCEUMKF_STATE,CurrentState,0);
+                               FILE *st=fopen(fname,"rb");
+                               free(fname);
+                               if (st)
+                               {
+                                       fclose(st);
+                                       FCEU_DispMessage("OVERWRITE SAVE? (Y=yes, X=no)");
+                                       FCEU_PutImage();
+                                       FCEUD_Update(XBuf+8,NULL,0);
+                                       while( !((keys = gp2x_joystick_read(1)) & (GP2X_X|GP2X_Y)) ) usleep(50*1024);
+                                       if (keys & GP2X_X) do_it = 0;
+                                       FCEU_DispMessage("");
+                               }
+                       }
+                       if (do_it) FCEUI_SaveState();
                }
+               RefreshThrottleFPS();
        }
        else if (acts & (3 << 28)) // state slot next/prev
        {
@@ -156,9 +187,9 @@ static void do_fake_mouse(unsigned long keys)
 void FCEUD_UpdateInput(void)
 {
        static int volpushed_frames = 0;
-       static int turbo_rate_cnt_a = 0, turbo_rate_cnt_b = 0;
+       static int turbo_rate_cnt_a[2] = {0,0}, turbo_rate_cnt_b[2] = {0,0};
        unsigned long keys = gp2x_joystick_read(0);
-       uint32 all_acts = 0;
+       uint32 all_acts[2] = {0,0};
        int i;
 
        if ((down(VOL_DOWN) && down(VOL_UP)) || (keys & (GP2X_L|GP2X_L|GP2X_START)) == (GP2X_L|GP2X_L|GP2X_START))
@@ -219,21 +250,49 @@ void FCEUD_UpdateInput(void)
                        }
                        if (u != 32) acts &=  combo_acts; // other combo key pressed
                        else         acts &= ~combo_acts;
-                       all_acts |= acts;
+                       all_acts[(acts>>16)&1] |= acts;
+               }
+       }
+
+       // add joy inputs
+       if (num_of_joys > 0)
+       {
+               int joy;
+               gp2x_usbjoy_update();
+               for (joy = 0; joy < num_of_joys; joy++) {
+                       int keys = gp2x_usbjoy_check2(joy);
+                       for (i = 0; i < 32; i++) {
+                               if (keys & (1 << i)) {
+                                       int acts = Settings.JoyBinds[joy][i];
+                                       all_acts[(acts>>16)&1] |= acts;
+                               }
+                       }
                }
        }
 
-       JSreturn |= all_acts & 0xff;
-       if (all_acts & 0x100) {         // A turbo
-               turbo_rate_cnt_a += Settings.turbo_rate_add;
-               JSreturn |= (turbo_rate_cnt_a >> 24) & 1;
+       // player 1
+       JSreturn |= all_acts[0] & 0xff;
+       if (all_acts[0] & 0x100) {              // A turbo
+               turbo_rate_cnt_a[0] += Settings.turbo_rate_add;
+               JSreturn |= (turbo_rate_cnt_a[0] >> 24) & 1;
        }
-       if (all_acts & 0x200) {         // B turbo
-               turbo_rate_cnt_b += Settings.turbo_rate_add;
-               JSreturn |= (turbo_rate_cnt_b >> 23) & 2;
+       if (all_acts[0] & 0x200) {              // B turbo
+               turbo_rate_cnt_b[0] += Settings.turbo_rate_add;
+               JSreturn |= (turbo_rate_cnt_b[0] >> 23) & 2;
        }
 
-       do_emu_acts(all_acts);
+       // player 2
+       JSreturn |= (all_acts[1] & 0xff) << 16;
+       if (all_acts[1] & 0x100) {              // A turbo
+               turbo_rate_cnt_a[1] += Settings.turbo_rate_add;
+               JSreturn |= (turbo_rate_cnt_a[1] >> 8) & 0x10000;
+       }
+       if (all_acts[1] & 0x200) {              // B turbo
+               turbo_rate_cnt_b[1] += Settings.turbo_rate_add;
+               JSreturn |= (turbo_rate_cnt_b[1] >> 7) & 0x20000;
+       }
+
+       do_emu_acts(all_acts[0]|all_acts[1]);
 }
 
 
@@ -301,6 +360,8 @@ static void PrepareOtherInput(void)
                }
        }
 
+       combo_acts &= ~0x00030000; // don't take player_id bits
+
        // find combo_keys
        for (act = 1; act; act <<= 1)
        {
index 3f4dff9..05724c6 100644 (file)
@@ -91,8 +91,8 @@ void FCEUD_PrintError(char *s)
  puts(s);
 }
 
-static char *cpalette=0;
-static void LoadCPalette(void)
+char *cpalette=0;
+void LoadCPalette(void)
 {
  char tmpp[192];
  FILE *fp;
@@ -100,6 +100,8 @@ static void LoadCPalette(void)
  if(!(fp=fopen(cpalette,"rb")))
  {
   printf(" Error loading custom palette from file: %s\n",cpalette);
+  free(cpalette);
+  cpalette=0;
   return;
  }
  fread(tmpp,1,192,fp);
@@ -181,7 +183,7 @@ static void SaveLLGN(void)
 
 static void CreateDirs(void)
 {
- char *subs[]={"fcs","snaps","gameinfo","sav","cheats","cfg"};
+ char *subs[]={"fcs","snaps","gameinfo","sav","cheats","cfg","pal"};
  char tdir[2048];
  int x;
 
@@ -212,12 +214,9 @@ static void CloseStuff(int signum)
          case SIGHUP:printf("Reach out and hang-up on someone.\n");break;
          case SIGPIPE:printf("The pipe has broken!  Better watch out for floods...\n");break;
          case SIGSEGV:printf("Iyeeeeeeeee!!!  A segmentation fault has occurred.  Have a fluffy day.\n");break;
-        /* So much SIGBUS evil. */
-        #ifdef SIGBUS
         #if(SIGBUS!=SIGSEGV)
          case SIGBUS:printf("I told you to be nice to the driver.\n");break;
         #endif
-        #endif
          case SIGFPE:printf("Those darn floating points.  Ne'er know when they'll bite!\n");break;
          case SIGALRM:printf("Don't throw your clock at the meowing cats!\n");break;
          case SIGABRT:printf("Abort, Retry, Ignore, Fail?\n");break;
@@ -251,8 +250,7 @@ static int DoArgs(int argc, char *argv[])
          {"-fcexp",0,&fcexp,0x4001},
 
          {"-gg",&docheckie[1],0,0},
-         {"-no8lim",0,&eoptions,0x8001},
-         {"-subase",0,&eoptions,0x8002},
+         {"-no8lim",0,&eoptions,0x8000|EO_NO8LIM},
          {"-snapname",0,&eoptions,0x8000|EO_SNAPNAME},
         {"-nofs",0,&eoptions,0x8000|EO_NOFOURSCORE},
          {"-clipsides",0,&eoptions,0x8000|EO_CLIPSIDES},
@@ -278,8 +276,7 @@ static int DoArgs(int argc, char *argv[])
         Settings.region_force=2;
        if(docheckie[1])
         FCEUI_SetGameGenie(1);
-        FCEUI_DisableSpriteLimitation(1);
-        FCEUI_SaveExtraDataUnderBase(eoptions&2);
+        FCEUI_DisableSpriteLimitation(eoptions&EO_NO8LIM);
        FCEUI_SetSnapName(eoptions&EO_SNAPNAME);
 
        for(x=0;x<2;x++)
@@ -288,8 +285,6 @@ static int DoArgs(int argc, char *argv[])
          if(erendlinev[x]<srendlinev[x] || erendlinev[x]>239) erendlinev[x]=239;
        }
 
-       printf("FCEUI_SetRenderedLines: %d, %d, %d, %d\n",srendlinev[0],erendlinev[0],srendlinev[1],erendlinev[1]);
-        printf("clip sides: %d\n", eoptions&EO_CLIPSIDES);
         FCEUI_SetRenderedLines(srendlinev[0],erendlinev[0],srendlinev[1],erendlinev[1]);
         FCEUI_SetSoundVolume(soundvol);
        DoDriverArgs();
@@ -362,7 +357,7 @@ int CLImain(int argc, char *argv[])
        LoadLLGN();
        FCEUI_SetNTSCTH(ntsccol, ntsctint, ntschue);
        if(cpalette)
-        LoadCPalette(); // TODO
+        LoadCPalette();
        if(InitSound())
         inited|=1;
 
@@ -454,6 +449,9 @@ static void DriverKill(void)
  // SaveConfig(NULL); // done explicitly in menu now
  SetSignals(SIG_IGN);
 
+ if(cpalette) free(cpalette);
+ cpalette=0;
+
  if(inited&4)
   KillVideo();
  if(inited&1)
index cdd06b2..b23837a 100644 (file)
@@ -20,6 +20,7 @@
 \r
 #include "../../input.h"\r
 #include "../../state.h"\r
+#include "../../palette.h"\r
 \r
 #ifndef _DIRENT_HAVE_D_TYPE\r
 #error "need d_type for file browser\r
@@ -41,6 +42,9 @@ static char *gp2xKeyNames[] = {
        "18???", "19???",  "1a???","PUSH",  "1c???","1d???", "1e???",    "1f???"\r
 };\r
 \r
+\r
+static char path_buffer[PATH_MAX];\r
+\r
 char menuErrorMsg[40] = {0, };\r
 \r
 // TODO\r
@@ -290,11 +294,11 @@ static int scandir_filter(const struct dirent *ent)
        return 1;\r
 }\r
 \r
-static char *romsel_loop(char *curr_path)\r
+static char *filesel_loop(char *curr_path, char *final_dest)\r
 {\r
        struct dirent **namelist;\r
        DIR *dir;\r
-       int n, sel = 0;\r
+       int n, newlen, sel = 0;\r
        unsigned long inp = 0;\r
        char *ret = NULL, *fname = NULL;\r
 \r
@@ -343,15 +347,18 @@ static char *romsel_loop(char *curr_path)
                if(inp & GP2X_R)     { sel+=24; if (sel > n-2) sel = n-2; }\r
                if(inp & GP2X_B)     { // enter dir/select\r
                        again:\r
-                       if (namelist[sel+1]->d_type == DT_REG) {\r
-                               strcpy(lastLoadedGameName, curr_path);\r
-                               strcat(lastLoadedGameName, "/");\r
-                               strcat(lastLoadedGameName, namelist[sel+1]->d_name);\r
-                               ret = lastLoadedGameName;\r
+                       newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;\r
+                       if (namelist[sel+1]->d_type == DT_REG) { // file selected\r
+                               if (final_dest == NULL) final_dest = malloc(newlen);\r
+                               if (final_dest == NULL) break;\r
+                               strcpy(final_dest, curr_path);\r
+                               strcat(final_dest, "/");\r
+                               strcat(final_dest, namelist[sel+1]->d_name);\r
+                               ret = final_dest;\r
                                break;\r
                        } else if (namelist[sel+1]->d_type == DT_DIR) {\r
-                               int newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;\r
                                char *p, *newdir = malloc(newlen);\r
+                               if (newdir == NULL) break;\r
                                if (strcmp(namelist[sel+1]->d_name, "..") == 0) {\r
                                        char *start = curr_path;\r
                                        p = start + strlen(start) - 1;\r
@@ -366,16 +373,19 @@ static char *romsel_loop(char *curr_path)
                                        strcat(newdir, "/");\r
                                        strcat(newdir, namelist[sel+1]->d_name);\r
                                }\r
-                               ret = romsel_loop(newdir);\r
+                               ret = filesel_loop(newdir, final_dest);\r
                                free(newdir);\r
                                break;\r
                        } else {\r
                                // unknown file type, happens on NTFS mounts. Try to guess.\r
-                               FILE *tstf; int tmp;\r
-                               strcpy(lastLoadedGameName, curr_path);\r
-                               strcat(lastLoadedGameName, "/");\r
-                               strcat(lastLoadedGameName, namelist[sel+1]->d_name);\r
-                               tstf = fopen(lastLoadedGameName, "rb");\r
+                               char *tstfn; FILE *tstf; int tmp;\r
+                               tstfn = malloc(newlen);\r
+                               if (tstfn == NULL) break;\r
+                               strcpy(tstfn, curr_path);\r
+                               strcat(tstfn, "/");\r
+                               strcat(tstfn, namelist[sel+1]->d_name);\r
+                               tstf = fopen(tstfn, "rb");\r
+                               free(tstfn);\r
                                if (tstf != NULL)\r
                                {\r
                                        if (fread(&tmp, 1, 1, tstf) > 0 || ferror(tstf) == 0)\r
@@ -617,7 +627,7 @@ static char *action_binds(int player_idx, int action_mask)
                {\r
                        if (Settings.JoyBinds[joy][i] & action_mask)\r
                        {\r
-                               if (player_idx >= 0 && ((Settings.KeyBinds[i] >> 16) & 3) != player_idx) continue;\r
+                               if (player_idx >= 0 && ((Settings.JoyBinds[joy][i] >> 16) & 3) != player_idx) continue;\r
                                if (strkeys[0]) {\r
                                        strcat(strkeys, ", "); strcat(strkeys, usb_joy_key_name(joy + 1, i));\r
                                        break;\r
@@ -685,6 +695,8 @@ static void draw_key_config(const bind_action_t *opts, int opt_cnt, int player_i
                gp2x_text_out15(30, 210, "To bind UP/DOWN, hold VOL-");\r
                gp2x_text_out15(30, 220, "Select \"Done\" to exit");\r
        } else {\r
+               gp2x_text_out15(30, 200, "Use Options -> Save cfg");\r
+               gp2x_text_out15(30, 210, "to save controls");\r
                gp2x_text_out15(30, 220, "Press B or X to exit");\r
        }\r
        gp2x_video_flip();\r
@@ -723,7 +735,9 @@ static void key_config_loop(const bind_action_t *opts, int opt_cnt, int player_i
                                                Settings.KeyBinds[i] |= player_idx << 16;\r
                                        }\r
                                }\r
-               } else if (sel < opt_cnt) {\r
+               }\r
+               else if (sel < opt_cnt)\r
+               {\r
                        for (i = 0; i < 32; i++)\r
                                if (inp & (1 << i)) {\r
                                        if (count_bound_keys(opts[sel].mask, 1) >= 1) // disallow combos for usbjoy\r
@@ -810,6 +824,7 @@ static void kc_sel_loop(void)
                                case 1: key_config_loop(ctrl_actions,  8, 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
                                default: return;\r
                        }\r
                }\r
@@ -824,6 +839,8 @@ extern int ntsccol,ntschue,ntsctint;
 extern int srendlinev[2];\r
 extern int erendlinev[2];\r
 extern int eoptions;\r
+extern char *cpalette;\r
+extern void LoadCPalette(void);\r
 \r
 \r
 static void int_incdec(int *p, int inc, int min, int max)\r
@@ -836,20 +853,37 @@ static void int_incdec(int *p, int inc, int min, int max)
 static void draw_fcemenu_options(int menu_sel)\r
 {\r
        int tl_x = 25, tl_y = 60, y;\r
+       char cpal[32];\r
+\r
+       if (cpalette != NULL)\r
+       {\r
+               char *p = cpalette + strlen(cpalette) - 1;\r
+               while (*p != '/' && p > cpalette) p--;\r
+               if (*p == '/') p++;\r
+               strncpy(cpal, p, 16);\r
+               cpal[16] = 0;\r
+       }\r
+       else strcpy(cpal, "           OFF");\r
 \r
        y = tl_y;\r
        gp2x_fceu_copy_bg();\r
 \r
-       gp2x_text_out15(tl_x,  y,      "NTSC Color Emulation       %s", ntsccol?"ON":"OFF");    // 0\r
+       gp2x_text_out15(tl_x,  y,      "Custom palette: %s", cpal);                             // 0\r
+       gp2x_text_out15(tl_x, (y+=10), "NTSC Color Emulation       %s", ntsccol?"ON":"OFF");\r
        gp2x_text_out15(tl_x, (y+=10), "  Tint (default: 56)       %i", ntsctint);\r
        gp2x_text_out15(tl_x, (y+=10), "  Hue  (default: 72)       %i", ntschue);\r
        gp2x_text_out15(tl_x, (y+=10), "First visible line (NTSC)  %i", srendlinev[0]);\r
-       gp2x_text_out15(tl_x, (y+=10), "Last visible line (NTSC)   %i", erendlinev[0]);\r
-       gp2x_text_out15(tl_x, (y+=10), "First visible line (PAL)   %i", srendlinev[1]);         // 5\r
+       gp2x_text_out15(tl_x, (y+=10), "Last visible line (NTSC)   %i", erendlinev[0]);         // 5\r
+       gp2x_text_out15(tl_x, (y+=10), "First visible line (PAL)   %i", srendlinev[1]);\r
        gp2x_text_out15(tl_x, (y+=10), "Last visible line (PAL)    %i", erendlinev[1]);\r
        gp2x_text_out15(tl_x, (y+=10), "Clip 8 left/right columns  %s", (eoptions&EO_CLIPSIDES)?"ON":"OFF");\r
-       gp2x_text_out15(tl_x, (y+=10), "Disable 8 sprite limit     %s", "TODO");\r
-       gp2x_text_out15(tl_x, (y+=10), "Done");                                                 // 9\r
+       gp2x_text_out15(tl_x, (y+=10), "Disable 8 sprite limit     %s", (eoptions&EO_NO8LIM)?"ON":"OFF");\r
+       gp2x_text_out15(tl_x, (y+=10), "Done");                                                 // 10\r
+\r
+       if (menu_sel == 0) {\r
+               gp2x_text_out15(30, 210, "Press B to browse,");\r
+               gp2x_text_out15(30, 220, "START to use default");\r
+       }\r
 \r
        // draw cursor\r
        gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">");\r
@@ -859,7 +893,7 @@ static void draw_fcemenu_options(int menu_sel)
 \r
 static void fcemenu_loop_options(void)\r
 {\r
-       int menu_sel = 0, menu_sel_max = 9, i;\r
+       int menu_sel = 0, menu_sel_max = 10, i;\r
        unsigned long inp = 0;\r
 \r
        FCEUI_GetNTSCTH(&ntsctint, &ntschue);\r
@@ -867,14 +901,15 @@ static void fcemenu_loop_options(void)
        for(;;)\r
        {\r
                draw_fcemenu_options(menu_sel);\r
-               inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);\r
+               inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A|GP2X_START);\r
                if(inp & GP2X_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
                if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
                if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options\r
                        switch (menu_sel) {\r
-                               case  0: ntsccol = !ntsccol; break;\r
-                               case  7: eoptions^=EO_CLIPSIDES; break;\r
-                               case  9: return;\r
+                               case  1: ntsccol = !ntsccol; break;\r
+                               case  8: eoptions^=EO_CLIPSIDES; break;\r
+                               case  9: eoptions^=EO_NO8LIM; break;\r
+                               case 10: return;\r
                        }\r
                }\r
                if(inp & (GP2X_X|GP2X_A)) {\r
@@ -885,16 +920,38 @@ static void fcemenu_loop_options(void)
                        }\r
                        FCEUI_SetNTSCTH(ntsccol, ntsctint, ntschue);\r
                        FCEUI_SetRenderedLines(srendlinev[0],erendlinev[0],srendlinev[1],erendlinev[1]);\r
+                       FCEUI_DisableSpriteLimitation(eoptions&EO_NO8LIM);\r
+                       if (cpalette) LoadCPalette();\r
+                       else FCEUI_SetPaletteArray(0); // set to default\r
+                       FCEU_ResetPalette();\r
                        return;\r
                }\r
                if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise\r
                        switch (menu_sel) {\r
-                               case  1: int_incdec(&ntsctint,      (inp & GP2X_LEFT) ? -1 : 1, 0, 128); break;\r
-                               case  2: int_incdec(&ntschue,       (inp & GP2X_LEFT) ? -1 : 1, 0, 128); break;\r
-                               case  3: int_incdec(&srendlinev[0], (inp & GP2X_LEFT) ? -1 : 1, 0, 239); break;\r
-                               case  4: int_incdec(&erendlinev[0], (inp & GP2X_LEFT) ? -1 : 1, 0, 239); break;\r
-                               case  5: int_incdec(&srendlinev[1], (inp & GP2X_LEFT) ? -1 : 1, 0, 239); break;\r
-                               case  6: int_incdec(&erendlinev[1], (inp & GP2X_LEFT) ? -1 : 1, 0, 239); break;\r
+                               case  2: int_incdec(&ntsctint,      (inp & GP2X_LEFT) ? -1 : 1, 0, 128); break;\r
+                               case  3: int_incdec(&ntschue,       (inp & GP2X_LEFT) ? -1 : 1, 0, 128); break;\r
+                               case  4: int_incdec(&srendlinev[0], (inp & GP2X_LEFT) ? -1 : 1, 0, 239); break;\r
+                               case  5: int_incdec(&erendlinev[0], (inp & GP2X_LEFT) ? -1 : 1, 0, 239); break;\r
+                               case  6: int_incdec(&srendlinev[1], (inp & GP2X_LEFT) ? -1 : 1, 0, 239); break;\r
+                               case  7: int_incdec(&erendlinev[1], (inp & GP2X_LEFT) ? -1 : 1, 0, 239); break;\r
+                       }\r
+               }\r
+               if(menu_sel == 0 && (inp & (GP2X_START|GP2X_B))) { // custom palette\r
+                       if ((inp & GP2X_START) && cpalette) {\r
+                               free(cpalette);\r
+                               cpalette=NULL;\r
+                       }\r
+                       else if (inp & GP2X_B) {\r
+                               char *selfname;\r
+                               if (cpalette) strncpy(path_buffer, cpalette, sizeof(path_buffer));\r
+                               else getcwd(path_buffer, PATH_MAX);\r
+                               path_buffer[sizeof(path_buffer)-1] = 0;\r
+\r
+                               selfname = filesel_loop(path_buffer, NULL);\r
+                               if (selfname) {\r
+                                       if (cpalette) free(cpalette);\r
+                                       cpalette = selfname;\r
+                               }\r
                        }\r
                }\r
        }\r
@@ -934,14 +991,13 @@ static void draw_menu_options(int menu_sel)
        gp2x_text_out15(tl_x, (y+=10), "Sound Rate:           %5iHz", Settings.sound_rate);             // 4\r
        gp2x_text_out15(tl_x, (y+=10), "Force Region:              %s",\r
                Settings.region_force == 2 ? "PAL" : Settings.region_force == 1 ? "NTSC" : "OFF");      // 5\r
-       gp2x_text_out15(tl_x, (y+=10), "Use SRAM savestates        %s", "OFF");\r
        gp2x_text_out15(tl_x, (y+=10), "Turbo rate                 %iHz", (Settings.turbo_rate_add*60/2) >> 24);\r
-       gp2x_text_out15(tl_x, (y+=10), "Confirm savestate          %s", strssconfirm);                  // 8\r
+       gp2x_text_out15(tl_x, (y+=10), "Confirm savestate          %s", strssconfirm);                  // 7\r
        gp2x_text_out15(tl_x, (y+=10), "Save slot                  %i", CurrentState);\r
        gp2x_text_out15(tl_x, (y+=10), "Faster RAM timings         %s", Settings.ramtimings?"ON":"OFF");\r
-       gp2x_text_out15(tl_x, (y+=10), "squidgehack (now %s %s",   mms, Settings.mmuhack?"ON":"OFF");   // 11\r
+       gp2x_text_out15(tl_x, (y+=10), "squidgehack (now %s %s",   mms, Settings.mmuhack?"ON":"OFF");   // 10\r
        gp2x_text_out15(tl_x, (y+=10), "Gamma correction           %i.%02i", Settings.gamma / 100, Settings.gamma%100);\r
-       gp2x_text_out15(tl_x, (y+=10), "GP2X CPU clock             %iMhz", Settings.cpuclock);          // 13\r
+       gp2x_text_out15(tl_x, (y+=10), "GP2X CPU clock             %iMhz", Settings.cpuclock);          // 12\r
        gp2x_text_out15(tl_x, (y+=10), "[FCE Ultra options]");\r
        gp2x_text_out15(tl_x, (y+=10), "Save cfg as default");\r
        if (fceugi)\r
@@ -991,14 +1047,14 @@ static int menu_loop_options(void)
                        switch (menu_sel) {\r
                                case  1: Settings.showfps    = !Settings.showfps; break;\r
                                case  3: soundvol = soundvol ? 0 : 100; break;\r
-                               case 10: Settings.ramtimings = !Settings.ramtimings; break;\r
-                               case 11: Settings.mmuhack    = !Settings.mmuhack; break;\r
-                               case 14: fcemenu_loop_options(); break;\r
-                               case 15: // done (update and write)\r
+                               case  9: Settings.ramtimings = !Settings.ramtimings; break;\r
+                               case 10: Settings.mmuhack    = !Settings.mmuhack; break;\r
+                               case 13: fcemenu_loop_options(); break;\r
+                               case 14: // done (update and write)\r
                                        config_commit();\r
                                        SaveConfig(NULL);\r
                                        return 1;\r
-                               case 16: // done (update and write for current game)\r
+                               case 15: // done (update and write for current game)\r
                                        config_commit();\r
                                        if (lastLoadedGameName[0])\r
                                                SaveConfig(lastLoadedGameName);\r
@@ -1018,16 +1074,16 @@ static int menu_loop_options(void)
                                        InitSound();\r
                                        break;\r
                                case  5: int_incdec(&Settings.region_force,   (inp & GP2X_LEFT) ? -1 : 1, 0, 2); break;\r
-                               case  7: {\r
+                               case  6: {\r
                                        int hz = Settings.turbo_rate_add*60/2 >> 24;\r
                                        int_incdec(&hz, (inp & GP2X_LEFT) ? -1 : 1, 1, 30);\r
                                        Settings.turbo_rate_add = (hz*2 << 24) / 60 + 1;\r
                                        break;\r
                                }\r
-                               case  8: int_incdec(&Settings.sstate_confirm, (inp & GP2X_LEFT) ? -1 : 1, 0, 3); break;\r
-                               case  9: int_incdec(&CurrentState,            (inp & GP2X_LEFT) ? -1 : 1, 0, 9); break;\r
-                               case 12: int_incdec(&Settings.gamma,          (inp & GP2X_LEFT) ? -1 : 1, 0, 300); break;\r
-                               case 13:\r
+                               case  7: int_incdec(&Settings.sstate_confirm, (inp & GP2X_LEFT) ? -1 : 1, 0, 3); break;\r
+                               case  8: int_incdec(&CurrentState,            (inp & GP2X_LEFT) ? -1 : 1, 0, 9); break;\r
+                               case 11: int_incdec(&Settings.gamma,          (inp & GP2X_LEFT) ? -1 : 1, 0, 300); break;\r
+                               case 12:\r
                                        while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {\r
                                                Settings.cpuclock += (inp & GP2X_LEFT) ? -1 : 1;\r
                                                if (Settings.cpuclock < 0) Settings.cpuclock = 0; // 0 ~ do not change\r
@@ -1112,19 +1168,6 @@ static int menu_loop_root(void)
        int ret, menu_sel_max = 8, menu_sel_min = 4;\r
        static int menu_sel = 4;\r
        unsigned long inp = 0;\r
-       char curr_path[PATH_MAX], *selfname;\r
-       FILE *tstf;\r
-\r
-       if ( (tstf = fopen(lastLoadedGameName, "rb")) )\r
-       {\r
-               fclose(tstf);\r
-               strncpy(curr_path, lastLoadedGameName, sizeof(curr_path));\r
-               curr_path[sizeof(curr_path)-1] = 0;\r
-       }\r
-       else\r
-       {\r
-               getcwd(curr_path, PATH_MAX);\r
-       }\r
 \r
        if (fceugi) menu_sel_min = 0;\r
 // TODO        if (PicoPatches) menu_sel_max = 9;\r
@@ -1185,13 +1228,29 @@ static int menu_loop_root(void)
                                        }\r
                                        break;\r
                                case 4: // select rom\r
-                                       selfname = romsel_loop(curr_path);\r
+                               {\r
+                                       FILE *tstf;\r
+                                       char *selfname;\r
+\r
+                                       if ( (tstf = fopen(lastLoadedGameName, "rb")) )\r
+                                       {\r
+                                               fclose(tstf);\r
+                                               strncpy(path_buffer, lastLoadedGameName, sizeof(path_buffer));\r
+                                               path_buffer[sizeof(path_buffer)-1] = 0;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               getcwd(path_buffer, PATH_MAX);\r
+                                       }\r
+\r
+                                       selfname = filesel_loop(path_buffer, lastLoadedGameName);\r
                                        if (selfname) {\r
                                                printf("selected file: %s\n", selfname);\r
                                                while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000);\r
                                                return 2;\r
                                        }\r
                                        break;\r
+                               }\r
                                case 5: // options\r
                                        ret = menu_loop_options();\r
                                        if (ret == 1) continue; // status update\r
index 46383c2..ab1af60 100644 (file)
--- a/general.c
+++ b/general.c
@@ -217,7 +217,7 @@ char *FCEU_MakeFName(int type, int id1, char *cd1)
                        if(odirs[FCEUIOD_MISC])
                         asprintf(&ret,"%s"PSS"%s.pal",odirs[FCEUIOD_MISC],FileBase);
                        else
-                        asprintf(&ret,"%s"PSS"%s.pal",BaseDirectory,FileBase);
+                        asprintf(&ret,"%s"PSS"pal"PSS"%s.pal",BaseDirectory,FileBase);
                        break;
   case FCEUMKF_MOVIEGLOB:
                      if(odirs[FCEUIOD_MISC])
diff --git a/input.c b/input.c
index 0d4a9af..b625583 100644 (file)
--- a/input.c
+++ b/input.c
@@ -117,7 +117,7 @@ static DECLFR(JPRead)
          ret=FCExp->Read(A&1,ret);
 
        ret|=X.DB&0xC0;
-       dprintf("JPRead %02x", ret);
+       dprintf("JPRead %i %02x", A&1, ret);
        return(ret);
 }