perfect vsync, bugfixes
[fceu.git] / drivers / gp2x / main.c
index 05724c6..5926da7 100644 (file)
@@ -39,6 +39,7 @@
 #include "../common/cheat.h"
 
 #include "../../fce.h"
 #include "../common/cheat.h"
 
 #include "../../fce.h"
+#include "../../cart.h"
 
 #include "dface.h"
 
 
 #include "dface.h"
 
@@ -48,6 +49,7 @@ void CleanSurface(void);
 // internals
 extern char lastLoadedGameName[2048];
 extern uint8 Exit; // exit emu loop flag
 // internals
 extern char lastLoadedGameName[2048];
 extern uint8 Exit; // exit emu loop flag
+extern int FSkip;
 void CloseGame(void);
 
 FCEUGI *fceugi = NULL;
 void CloseGame(void);
 
 FCEUGI *fceugi = NULL;
@@ -165,7 +167,7 @@ static void LoadLLGN(void)
 static void SaveLLGN(void)
 {
  // save last loaded game name
 static void SaveLLGN(void)
 {
  // save last loaded game name
- if (lastLoadedGameName[0])
+ if (lastLoadedGameName[0] && !(eoptions&EO_NOAUTOWRITE))
  {
   char tdir[2048];
   FILE *f;
  {
   char tdir[2048];
   FILE *f;
@@ -249,12 +251,13 @@ static int DoArgs(int argc, char *argv[])
          {"-input1",0,&inputa[0],0x4001},{"-input2",0,&inputa[1],0x4001},
          {"-fcexp",0,&fcexp,0x4001},
 
          {"-input1",0,&inputa[0],0x4001},{"-input2",0,&inputa[1],0x4001},
          {"-fcexp",0,&fcexp,0x4001},
 
-         {"-gg",&docheckie[1],0,0},
+         {"-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},
         {"-nothrottle",0,&eoptions,0x8000|EO_NOTHROTTLE},
          {"-no8lim",0,&eoptions,0x8000|EO_NO8LIM},
          {"-snapname",0,&eoptions,0x8000|EO_SNAPNAME},
         {"-nofs",0,&eoptions,0x8000|EO_NOFOURSCORE},
          {"-clipsides",0,&eoptions,0x8000|EO_CLIPSIDES},
         {"-nothrottle",0,&eoptions,0x8000|EO_NOTHROTTLE},
+        {"-noautowrite",0,&eoptions,0x8000|EO_NOAUTOWRITE},
          {"-slstart",0,&srendlinev[0],0},{"-slend",0,&erendlinev[0],0},
          {"-slstartp",0,&srendlinev[1],0},{"-slendp",0,&erendlinev[1],0},
         {0,(void *)DriverArgs,0,0},
          {"-slstart",0,&srendlinev[0],0},{"-slend",0,&erendlinev[0],0},
          {"-slstartp",0,&srendlinev[1],0},{"-slendp",0,&erendlinev[1],0},
         {0,(void *)DriverArgs,0,0},
@@ -274,8 +277,7 @@ static int DoArgs(int argc, char *argv[])
        }
        if(docheckie[0])
         Settings.region_force=2;
        }
        if(docheckie[0])
         Settings.region_force=2;
-       if(docheckie[1])
-        FCEUI_SetGameGenie(1);
+       FCEUI_SetGameGenie(eoptions&EO_GG);
         FCEUI_DisableSpriteLimitation(eoptions&EO_NO8LIM);
        FCEUI_SetSnapName(eoptions&EO_SNAPNAME);
 
         FCEUI_DisableSpriteLimitation(eoptions&EO_NO8LIM);
        FCEUI_SetSnapName(eoptions&EO_SNAPNAME);
 
@@ -286,7 +288,7 @@ static int DoArgs(int argc, char *argv[])
        }
 
         FCEUI_SetRenderedLines(srendlinev[0],erendlinev[0],srendlinev[1],erendlinev[1]);
        }
 
         FCEUI_SetRenderedLines(srendlinev[0],erendlinev[0],srendlinev[1],erendlinev[1]);
-        FCEUI_SetSoundVolume(soundvol);
+        FCEUI_SetSoundVolume(80);
        DoDriverArgs();
 
        if(fcexp)
        DoDriverArgs();
 
        if(fcexp)
@@ -353,7 +355,6 @@ int CLImain(int argc, char *argv[])
         LoadConfig(NULL);
         last_arg_parsed=DoArgs(argc-1,&argv[1]);
        gp2x_opt_setup();
         LoadConfig(NULL);
         last_arg_parsed=DoArgs(argc-1,&argv[1]);
        gp2x_opt_setup();
-       gp2x_cpuclock_gamma_update();
        LoadLLGN();
        FCEUI_SetNTSCTH(ntsccol, ntsctint, ntschue);
        if(cpalette)
        LoadLLGN();
        FCEUI_SetNTSCTH(ntsccol, ntsctint, ntschue);
        if(cpalette)
@@ -388,7 +389,12 @@ int CLImain(int argc, char *argv[])
           ParseGI(fceugi);
           InitOtherInput();
 
           ParseGI(fceugi);
           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
           FCEU_DispMessage("%s", infostring);
          }
          else
@@ -412,18 +418,19 @@ int CLImain(int argc, char *argv[])
          }
          }
 
          }
          }
 
+        gp2x_opt_update();
         PrepareOtherInput();
         PrepareOtherInput();
-        RefreshThrottleFPS();
         FCEUI_GetCurrentVidSystem(&srendline,&erendline);
         gp2x_video_changemode(Settings.scaling == 3 ? 15 : 8);
         switch (Settings.scaling & 3) {
         FCEUI_GetCurrentVidSystem(&srendline,&erendline);
         gp2x_video_changemode(Settings.scaling == 3 ? 15 : 8);
         switch (Settings.scaling & 3) {
-                case 0: gp2x_video_set_offs(0);  gp2x_video_RGB_setscaling(0, 320, 240); break;
-                case 1: gp2x_video_set_offs(32); gp2x_video_RGB_setscaling(0, 256, 240); break;
-                case 2: gp2x_video_set_offs(32); gp2x_video_RGB_setscaling(srendline, 256, erendline-srendline); break;
-                case 3: gp2x_video_set_offs(32); gp2x_video_RGB_setscaling(0, 320, 240); break;
+                case 0: gp2x_video_set_offs(0);  gp2x_video_RGB_setscaling(320, 240); break;
+                case 1: gp2x_video_set_offs(32); gp2x_video_RGB_setscaling(256, 240); break;
+                case 2: gp2x_video_set_offs(32+srendline*320); gp2x_video_RGB_setscaling(256, erendline-srendline); break;
+                case 3: gp2x_video_set_offs(32); gp2x_video_RGB_setscaling(320, 240); break;
         }
         CleanSurface();
         gp2x_start_sound(Settings.sound_rate, 16, 0);
         }
         CleanSurface();
         gp2x_start_sound(Settings.sound_rate, 16, 0);
+        RefreshThrottleFPS();
         FCEUI_Emulate();
        }
 
         FCEUI_Emulate();
        }
 
@@ -447,7 +454,7 @@ static int DriverInitialize(void)
 static void DriverKill(void)
 {
  // SaveConfig(NULL); // done explicitly in menu now
 static void DriverKill(void)
 {
  // SaveConfig(NULL); // done explicitly in menu now
- SetSignals(SIG_IGN);
+ SetSignals(SIG_DFL);
 
  if(cpalette) free(cpalette);
  cpalette=0;
 
  if(cpalette) free(cpalette);
  cpalette=0;
@@ -461,11 +468,16 @@ static void DriverKill(void)
 
 void FCEUD_Update(uint8 *xbuf, int16 *Buffer, int Count)
 {
 
 void FCEUD_Update(uint8 *xbuf, int16 *Buffer, int Count)
 {
- if(!Count && !(eoptions&EO_NOTHROTTLE))
+ FCEUD_UpdateInput();  // must update input before blitting because of save confirmation stuff
+ BlitPrepare(xbuf == NULL);
+ if(!(eoptions&EO_NOTHROTTLE))
+ {
+  if(Count)
+   WriteSound(Buffer,Count);
   SpeedThrottle();
   SpeedThrottle();
- BlitScreen(xbuf);
- if(Count && !(eoptions&EO_NOTHROTTLE))
-  WriteSound(Buffer,Count);
FCEUD_UpdateInput();
+ }
+ BlitScreen(xbuf == NULL);
+ // make sure last frame won't get skipped, because we need it for menu bg
if (Exit) FSkip=0;
 }
 
 }