savestate and other bugfixes
[fceu.git] / drivers / gp2x / main.c
index caea8cc..ac48a2d 100644 (file)
 #include "../common/cheat.h"
 
 #include "../../fce.h"
+#include "../../cart.h"
 
 #include "dface.h"
 
 
-// TODO! broken fs0, sram saves
-
 void CleanSurface(void);
 
 // internals
@@ -93,8 +92,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;
@@ -102,6 +101,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);
@@ -183,7 +184,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;
 
@@ -214,12 +215,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;
@@ -252,9 +250,8 @@ static int DoArgs(int argc, char *argv[])
          {"-input1",0,&inputa[0],0x4001},{"-input2",0,&inputa[1],0x4001},
          {"-fcexp",0,&fcexp,0x4001},
 
-         {"-gg",&docheckie[1],0,0},
-         {"-no8lim",0,&eoptions,0x8001},
-         {"-subase",0,&eoptions,0x8002},
+         {"-gg",0,&eoptions,0x8000|EO_GG},
+         {"-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,10 +275,8 @@ static int DoArgs(int argc, char *argv[])
        }
        if(docheckie[0])
         Settings.region_force=2;
-       if(docheckie[1])
-        FCEUI_SetGameGenie(1);
-        FCEUI_DisableSpriteLimitation(1);
-        FCEUI_SaveExtraDataUnderBase(eoptions&2);
+       FCEUI_SetGameGenie(eoptions&EO_GG);
+        FCEUI_DisableSpriteLimitation(eoptions&EO_NO8LIM);
        FCEUI_SetSnapName(eoptions&EO_SNAPNAME);
 
        for(x=0;x<2;x++)
@@ -290,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();
@@ -364,7 +357,7 @@ int CLImain(int argc, char *argv[])
        LoadLLGN();
        FCEUI_SetNTSCTH(ntsccol, ntsctint, ntschue);
        if(cpalette)
-        LoadCPalette(); // TODO
+        LoadCPalette();
        if(InitSound())
         inited|=1;
 
@@ -393,10 +386,14 @@ int CLImain(int argc, char *argv[])
           if (Settings.region_force)
            FCEUI_SetVidSystem(Settings.region_force - 1);
           ParseGI(fceugi);
-          //RefreshThrottleFPS();
           InitOtherInput();
 
-          GameInterface(GI_INFOSTRING, infostring);
+          if ((eoptions&EO_GG) && geniestage == 0) {
+           strcpy(infostring, "gg.rom is missing, GG disabled");
+           eoptions&=~EO_GG;
+           FCEUI_SetGameGenie(0);
+          } else
+           GameInterface(GI_INFOSTRING, infostring);
           FCEU_DispMessage("%s", infostring);
          }
          else
@@ -421,6 +418,7 @@ int CLImain(int argc, char *argv[])
          }
 
         PrepareOtherInput();
+        RefreshThrottleFPS();
         FCEUI_GetCurrentVidSystem(&srendline,&erendline);
         gp2x_video_changemode(Settings.scaling == 3 ? 15 : 8);
         switch (Settings.scaling & 3) {
@@ -454,7 +452,10 @@ static int DriverInitialize(void)
 static void DriverKill(void)
 {
  // SaveConfig(NULL); // done explicitly in menu now
- SetSignals(SIG_IGN);
+ SetSignals(SIG_DFL);
+
+ if(cpalette) free(cpalette);
+ cpalette=0;
 
  if(inited&4)
   KillVideo();
@@ -465,11 +466,13 @@ static void DriverKill(void)
 
 void FCEUD_Update(uint8 *xbuf, int16 *Buffer, int Count)
 {
- if(!Count && !(eoptions&EO_NOTHROTTLE))
+ if(!(eoptions&EO_NOTHROTTLE))
+ {
+  if(Count)
+   WriteSound(Buffer,Count);
   SpeedThrottle();
+ }
+ FCEUD_UpdateInput();  // must update input before blitting because of save confirmation stuff
  BlitScreen(xbuf);
- if(Count && !(eoptions&EO_NOTHROTTLE))
-  WriteSound(Buffer,Count);
- FCEUD_UpdateInput();
 }