perfect vsync, bugfixes
[fceu.git] / drivers / gp2x / gp2x.c
index e7c3a0e..92103c0 100644 (file)
 #include "cpuctrl.h"
 #include "squidgehack.h"
 
-int CLImain(int argc, char *argv[]);
+int GP2X_PORT_REV =
+#include "rev.h"
+;
 
-//#define SOUND_RATE 44100
-#define SOUND_RATE 22050
-#define GP2X_PORT_VERSION "0.4"
+extern uint8 PAL;
+
+int CLImain(int argc, char *argv[]);
 
 DSETTINGS Settings;
 CFGSTRUCT DriverConfig[]={
-        AC(Settings.sound),
-        ACA(Settings.joyBMap),
-       ACA(Settings.joyAMap),
-        ACA(Settings.joy),
+        ACA(Settings.KeyBinds),
+       ACA(Settings.JoyBinds),
+        AC(Settings.turbo_rate_add),
+        AC(Settings.sound_rate),
        AC(Settings.showfps),
        AC(Settings.scaling),
        AC(Settings.frameskip),
@@ -35,6 +37,7 @@ CFGSTRUCT DriverConfig[]={
        AC(Settings.cpuclock),
        AC(Settings.mmuhack),
        AC(Settings.ramtimings),
+       AC(Settings.gamma),
        // TODO
         ENDCFGSTRUCT
 };
@@ -60,9 +63,7 @@ char *DriverUsage=
 static int docheckie[2]={0,0};
 #endif
 ARGPSTRUCT DriverArgs[]={
-         {"-joy1",0,&Settings.joy[0],0},{"-joy2",0,&Settings.joy[1],0},
-         {"-joy3",0,&Settings.joy[2],0},{"-joy4",0,&Settings.joy[3],0},
-         {"-sound",0,&Settings.sound,0},
+         {"-sound",0,&Settings.sound_rate,0},
          {"-showfps",0,&Settings.showfps,0},
          {"-mmuhack",0,&Settings.mmuhack,0},
          {"-ramtimings",0,&Settings.ramtimings,0},
@@ -89,13 +90,28 @@ static void SetDefaults(void)
  Settings.cpuclock = 150;
  Settings.frameskip = -1; // auto
  Settings.mmuhack = 1;
- Settings.sound=SOUND_RATE;
+ 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
+ Settings.KeyBinds[ 2] = 0x040; // GP2X_LEFT
+ Settings.KeyBinds[ 6] = 0x080; // GP2X_RIGHT
+ Settings.KeyBinds[13] = 0x001; // GP2X_B
+ Settings.KeyBinds[14] = 0x002; // GP2X_X
+ Settings.KeyBinds[12] = 0x100; // GP2X_A
+ 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)
 {
-        int x;
-
        #ifdef NETWORK
         if(docheckie[0])
          netplay=2;
@@ -105,48 +121,11 @@ void DoDriverArgs(void)
         if(netplay)
          FCEUI_SetNetworkPlay(netplay);
        #endif
-
-        for(x=0;x<4;x++)
-         if(!Settings.joy[x])
-        {
-         memset(Settings.joyBMap[x],0,sizeof(Settings.joyBMap[0]));
-         memset(Settings.joyAMap[x],0,sizeof(Settings.joyAMap[0]));
-        }
-}
-
-int InitMouse(void)
-{
- return(0);
-}
-
-void KillMouse(void){}
-
-void GetMouseData(uint32 *d)
-{
-}
-
-int InitKeyboard(void)
-{
- return(1);
 }
 
-int UpdateKeyboard(void)
-{
- return(1);
-}
-
-void KillKeyboard(void)
-{
 
-}
-
-char *GetKeyboard(void)
-{
- return NULL;
-}
-
-extern int swapbuttons; // TODO: rm
 char **g_argv;
+int mmuhack_status = 0;
 
 
 // TODO: cleanup
@@ -155,25 +134,25 @@ int main(int argc, char *argv[])
        int ret;
        g_argv = argv;
 
-        puts("Starting GPFCE - Port version " GP2X_PORT_VERSION " (" __DATE__ ")");
-        puts("Based on FCE Ultra "VERSION_STRING"...");
-        puts("Ported by Zheng Zhu");
-        puts("Additional optimization/misc work by notaz\n");
+        printf("Starting GPFCE - Port version " GP2X_PORT_VERSION " r%i (" __DATE__ ")\n", GP2X_PORT_REV);
+        puts("Based on FCE Ultra "VERSION_STRING" and 0.98.1x versions");
+        puts("Original port by Zheng Zhu");
+        puts("Menu/optimization/misc work by notaz\n");
 
        gp2x_init();
        cpuctrl_init();
 
-        // unscale the screen, in case this is bad.
-       gp2x_video_changemode(8);
-        gp2x_video_RGB_setscaling(0, 320, 240);
-
         SetDefaults();
 
         ret = CLImain(argc,argv);
 
-        // unscale the screen, in case this is bad.
-        gp2x_video_RGB_setscaling(0, 320, 240);
+        // unscale the screen, in case it is bad.
+        gp2x_video_RGB_setscaling(320, 240);
+
+       if (mmuhack_status > 0)
+               mmuunhack();
 
+       set_gamma(100);
        cpuctrl_deinit();
         gp2x_deinit();
 
@@ -181,14 +160,13 @@ int main(int argc, char *argv[])
 }
 
 
-int mmuhack_status = 0;
-
 /* optional GP2X stuff to be done after config is loaded */
 void gp2x_opt_setup(void)
 {
        if (Settings.mmuhack) {
                int ret = mmuhack();
-               printf("squidge hack code finished and returned %i\n", ret); fflush(stdout);
+               printf("squidge hack code finished and returned %s\n", ret > 0 ? "ok" : "fail");
+               fflush(stdout);
                mmuhack_status = ret;
        }
        if (Settings.ramtimings) {
@@ -199,3 +177,34 @@ void gp2x_opt_setup(void)
        }
 }
 
+void gp2x_opt_update(void)
+{
+       static int prev_cpuclock = 200, prev_gamma = 100, prev_vsync = 0, prev_pal = 0;
+       if (Settings.cpuclock != 0 && Settings.cpuclock != prev_cpuclock)
+       {
+               set_FCLK(Settings.cpuclock);
+               prev_cpuclock = Settings.cpuclock;
+       }
+
+       if (Settings.gamma != 0 && Settings.gamma != prev_gamma)
+       {
+               set_gamma(Settings.gamma);
+               prev_gamma = Settings.gamma;
+       }
+
+       if (Settings.perfect_vsync != prev_vsync || (Settings.perfect_vsync && prev_pal != PAL))
+       {
+               if (Settings.perfect_vsync)
+               {
+                       set_LCD_custom_rate(PAL ? LCDR_100_02 : LCDR_120_20);
+                       prev_pal = PAL;
+               }
+               else
+               {
+                       unset_LCD_custom_rate();
+               }
+               prev_vsync = Settings.perfect_vsync;
+       }
+}
+
+