#include <stdlib.h>
#include <string.h>
-#include "gp2x.h"
+#include "../../driver.h"
+#include "../common/config.h"
+#include "../common/args.h"
+#include "../common/platform.h"
+#include "../common/settings.h"
+#include "../common/revision.h"
#include "gp2x-video.h"
#ifdef NETWORK
#include "unix-netplay.h"
#endif
-#include "minimal.h"
-int CLImain(int argc, char *argv[]);
-extern void SetVideoScaling(int, int, int);
-
-//#define SOUND_RATE 44100
-#define SOUND_RATE 22050
-
-DSETTINGS Settings;
-CFGSTRUCT DriverConfig[]={
- AC(_xscale),
- AC(_yscale),
- AC(_xscalefs),
- AC(_yscalefs),
- AC(_efx),
- AC(_efxfs),
- AC(_sound),
- #ifdef DSPSOUND
- AC(_f8bit),
- #else
- AC(_ebufsize),
- AC(_lbufsize),
- #endif
- AC(_fullscreen),
- AC(_xres),
- AC(_yres),
- ACA(joyBMap),
- ACA(joyAMap),
- ACA(joy),
- //ACS(_fshack),
- ENDCFGSTRUCT
-};
+#include "minimal.h"
+#include "cpuctrl.h"
+#include "squidgehack.h"
-//-fshack x Set the environment variable SDL_VIDEODRIVER to \"x\" when
-// entering full screen mode and x is not \"0\".
+extern uint8 PAL;
char *DriverUsage=
-"-xres x Set horizontal resolution to x for full screen mode.\n\
--yres x Set vertical resolution to x for full screen mode.\n\
--xscale(fs) x Multiply width by x.\n\
--yscale(fs) x Multiply height by x.\n\
--efx(fs) x Enable scanlines effect if x is non zero. yscale must be >=2\n\
- and preferably a multiple of 2.\n\
--fs x Select full screen mode if x is non zero.\n\
--joyx y Use joystick y as virtual joystick x.\n\
--sound x Sound.\n\
- 0 = Disabled.\n\
- Otherwise, x = playback rate.\n\
-"
-#ifdef DSPSOUND
-"-f8bit x Force 8-bit sound.\n\
- 0 = Disabled.\n\
- 1 = Enabled.\n\
-"
-#else
-"-lbufsize x Internal FCE Ultra sound buffer size. Size = 2^x samples.\n\
--ebufsize x External SDL sound buffer size. Size = 2^x samples.\n\
-"
-#endif
-"-connect s Connect to server 's' for TCP/IP network play.\n\
--server Be a host/server for TCP/IP network play.\n\
--netport x Use TCP/IP port x for network play.";
+"-mmuhack x Enable squidge's MMU hack if x is nonzero (GP2X).\n\
+-ramtimings x Enable RAM overclocking if x is nonzero (GP2X).\n\
+";
-#ifdef NETWORK
-static int docheckie[2]={0,0};
-#endif
ARGPSTRUCT DriverArgs[]={
- {"-joy1",0,&joy[0],0},{"-joy2",0,&joy[1],0},
- {"-joy3",0,&joy[2],0},{"-joy4",0,&joy[3],0},
- {"-xscale",0,&_xscale,0},
- {"-yscale",0,&_yscale,0},
- {"-efx",0,&_efx,0},
- {"-xscalefs",0,&_xscalefs,0},
- {"-yscalefs",0,&_yscalefs,0},
- {"-efxfs",0,&_efxfs,0},
- {"-xres",0,&_xres,0},
- {"-yres",0,&_yres,0},
- {"-fs",0,&_fullscreen,0},
- //{"-fshack",0,&_fshack,0x4001},
- {"-sound",0,&_sound,0},
- #ifdef DSPSOUND
- {"-f8bit",0,&_f8bit,0},
- #else
- {"-lbufsize",0,&_lbufsize,0},
- {"-ebufsize",0,&_ebufsize,0},
- #endif
- #ifdef NETWORK
- {"-connect",&docheckie[0],&netplayhost,0x4001},
- {"-server",&docheckie[1],0,0},
- {"-netport",0,&Port,0},
- #endif
+ {"-mmuhack",0,&Settings.mmuhack,0},
+ {"-ramtimings",0,&Settings.ramtimings,0},
+ {"-menu",0,&ext_menu,0x4001},
+ {"-menustate",0,&ext_state,0x4001},
{0,0,0,0}
};
-
-
-
-
void GetBaseDirectory(char *BaseDirectory)
{
- char *ol;
-
- ol="/mnt/sd/roms/nes";
- BaseDirectory[0]=0;
- if(ol)
- {
- strncpy(BaseDirectory,ol,2047);
- BaseDirectory[2047]=0;
- strcat(BaseDirectory,"/fceultra");
- }
+ strcpy(BaseDirectory, "fceultra");
}
static void SetDefaults(void)
{
- _xres=320;
- _yres=240;
- _fullscreen=0;
- _sound=SOUND_RATE; // 48000 wrong
- #ifdef DSPSOUND
- _f8bit=0;
- #else
- _lbufsize=10;
- _ebufsize=8;
- #endif
- _xscale=_yscale=_xscalefs=_yscalefs=1;
- _efx=_efxfs=0;
- //_fshack=_fshacksave=0;
- memset(joy,0,sizeof(joy));
+ memset(&Settings,0,sizeof(Settings));
+ Settings.cpuclock = 150;
+ Settings.frameskip = -1; // auto
+ Settings.mmuhack = 1;
+ 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 BROKEN
- if(_fshack)
- {
- if(_fshack[0]=='0')
- if(_fshack[1]==0)
- {
- free(_fshack);
- _fshack=0;
- }
- }
- #endif
-
- #ifdef NETWORK
- if(docheckie[0])
- netplay=2;
- else if(docheckie[1])
- netplay=1;
-
- if(netplay)
- FCEUI_SetNetworkPlay(netplay);
- #endif
-
- for(x=0;x<4;x++)
- if(!joy[x])
- {
- memset(joyBMap[x],0,sizeof(joyBMap[0]));
- memset(joyAMap[x],0,sizeof(joyAMap[0]));
- }
-}
-int InitMouse(void)
-{
- return(0);
-}
-void KillMouse(void){}
-void GetMouseData(uint32 *d)
{
}
-int InitKeyboard(void)
-{
- return(1);
-}
-int UpdateKeyboard(void)
-{
- return(1);
-}
+int mmuhack_status = 0;
-void KillKeyboard(void)
+
+void platform_init(void)
{
+ printf("Starting GPFCE " REV " (" __DATE__ ")\n");
+ 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();
-char *GetKeyboard(void)
-{
- return NULL;
+ SetDefaults();
}
-#include "unix-basedir.h"
-extern int showfps;
-extern int swapbuttons;
-
-int main(int argc, char *argv[])
+void platform_finish(void)
{
+ // unscale the screen, in case it is bad.
+ gp2x_video_RGB_setscaling(320, 240);
- puts("Starting GPFCE - Port version 0.2 05-29-2006");
- puts("Based on FCE Ultra "VERSION_STRING"...");
- puts("Ported by Zheng Zhu\n");
+ if (mmuhack_status > 0)
+ mmuunhack();
- // stereo
- //gp2x_init (1000, 8, SOUND_RATE, 16, 1, 60);
+ set_gamma(100);
+ cpuctrl_deinit();
+ gp2x_deinit();
- // mono 44khz
- //gp2x_init (1000, 8, SOUND_RATE<<1, 16, 0, 60);
- // mono 22khz
- gp2x_init (1000, 8, SOUND_RATE, 16, 0, 60);
+ return(ret?0:-1);
+}
- SetDefaults();
- int ret=CLImain(argc,argv);
+void platform_set_volume(int val) // 0-100
+{
+ platform_set_volume(val, val);
+}
- // unscale the screen, in case this is bad.
- SetVideoScaling(320, 320, 240);
+/* optional GP2X stuff to be done after config is loaded */
+void platform_late_init(void)
+{
+ if (Settings.mmuhack) {
+ int ret = mmuhack();
+ printf("squidge hack code finished and returned %s\n", ret > 0 ? "ok" : "fail");
+ fflush(stdout);
+ mmuhack_status = ret;
+ }
+ if (Settings.ramtimings) {
+ printf("setting RAM timings.. "); fflush(stdout);
+ // craigix: --trc 6 --tras 4 --twr 1 --tmrd 1 --trfc 1 --trp 2 --trcd 2
+ set_RAM_Timings(6, 4, 1, 1, 1, 2, 2);
+ printf("done.\n"); fflush(stdout);
+ }
+}
- gp2x_deinit();
- // make sure sound thread has exited cleanly
- printf("Exiting main(). terminated");
- if (showfps && swapbuttons)
- {
- execl("./selector","./selector","./gpfce_showfps_swapbuttons_config",NULL);
- }
- else if (showfps)
- {
- execl("./selector","./selector","./gpfce_showfps_config",NULL);
- }
- else if (swapbuttons)
- {
- execl("./selector","./selector","./gpfce_swapbuttons_config",NULL);
- }
- else
- {
- execl("./selector","./selector","./gpfce_config",NULL);
- }
- return(ret?0:-1);
+void platform_apply_config(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;
+ }
+
+ gp2x_video_changemode(Settings.scaling == 3 ? 15 : 8);
+ switch (Settings.scaling & 3) {
+ 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;
+ }
}
+