- added FRAMESKIP define by default to SConscript

- commented sdl/main.cpp
This commit is contained in:
gimmedonutnow 2006-08-02 06:05:44 +00:00
parent dee1cf579d
commit af143cdfeb
2 changed files with 389 additions and 313 deletions

View File

@ -4,10 +4,12 @@ import os
opts = Options() opts = Options()
opts.Add('PSS_STYLE', 'Path separator style', 1) opts.Add('PSS_STYLE', 'Path separator style', 1)
opts.Add('LSB_FIRST', 'Least significant byte first?', 1) opts.Add('LSB_FIRST', 'Least significant byte first?', 1)
opts.Add('FRAMESKIP', 'Enable frameskipping', 1)
env = Environment(options = opts, env = Environment(options = opts,
CPPDEFINES={'PSS_STYLE' : '${PSS_STYLE}', CPPDEFINES={'PSS_STYLE' : '${PSS_STYLE}',
'LSB_FIRST' : '${LSB_FIRST}'}) 'LSB_FIRST' : '${LSB_FIRST}',
'FRAMESKIP' : '${FRAMESKIP}'})
if os.environ.has_key('CC'): if os.environ.has_key('CC'):
env.Replace(CC = os.environ['CC']) env.Replace(CC = os.environ['CC'])

View File

@ -74,30 +74,44 @@ int gametype = 0;
FCEUGI *CurGame=NULL; FCEUGI *CurGame=NULL;
static void ParseGI(FCEUGI *gi) /**
* Wrapper for ParseGIInput().
*/
static void
ParseGI(FCEUGI *gi)
{ {
ParseGIInput(gi); ParseGIInput(gi);
gametype = gi->type; gametype = gi->type;
} }
void FCEUD_PrintError(char *s) /**
* Prints an error string to STDOUT.
*/
void
FCEUD_PrintError(char *s)
{ {
puts(s); puts(s);
} }
/**
* Prints the given string to STDOUT.
*/
void FCEUD_Message(char *s) void FCEUD_Message(char *s)
{ {
fputs(s, stdout); fputs(s, stdout);
} }
static char *cpalette=0; static char *cpalette=0;
static void LoadCPalette(void) /**
* Read a custom pallete from a file and load it into the core.
*/
static void
LoadCPalette()
{ {
uint8 tmpp[192]; uint8 tmpp[192];
FILE *fp; FILE *fp;
if(!(fp=FCEUD_UTF8fopen(cpalette,"rb"))) if(!(fp = FCEUD_UTF8fopen(cpalette, "rb"))) {
{
printf(" Error loading custom palette from file: %s\n", cpalette); printf(" Error loading custom palette from file: %s\n", cpalette);
return; return;
} }
@ -105,6 +119,8 @@ static void LoadCPalette(void)
FCEUI_SetPaletteArray(tmpp); FCEUI_SetPaletteArray(tmpp);
fclose(fp); fclose(fp);
} }
static CFGSTRUCT fceuconfig[]={ static CFGSTRUCT fceuconfig[]={
AC(soundrate), AC(soundrate),
AC(soundq), AC(soundq),
@ -123,7 +139,12 @@ static CFGSTRUCT fceuconfig[]={
ENDCFGSTRUCT ENDCFGSTRUCT
}; };
static void SaveConfig(void) /**
* Wrapper for SaveFCEUConfig() that sets the path. Hopefully
* obsolete with new configuration system.
*/
static void
SaveConfig()
{ {
char tdir[2048]; char tdir[2048];
sprintf(tdir,"%s"PSS"fceu98.cfg", DrBaseDirectory); sprintf(tdir,"%s"PSS"fceu98.cfg", DrBaseDirectory);
@ -131,17 +152,28 @@ static void SaveConfig(void)
SaveFCEUConfig(tdir, fceuconfig); SaveFCEUConfig(tdir, fceuconfig);
} }
static void LoadConfig(void) /**
* Wrapper for LoadFCEUConfig() that sets the path. Hopefully
* obsolete with the new configuration system.
*/
static void
LoadConfig()
{ {
char tdir[2048]; char tdir[2048];
sprintf(tdir,"%s"PSS"fceu98.cfg",DrBaseDirectory); sprintf(tdir,"%s"PSS"fceu98.cfg",DrBaseDirectory);
FCEUI_GetNTSCTH(&ntsctint, &ntschue); /* Get default settings for if
no config file exists. */ /* Get default settings for if no config file exists. */
FCEUI_GetNTSCTH(&ntsctint, &ntschue);
LoadFCEUConfig(tdir,fceuconfig); LoadFCEUConfig(tdir,fceuconfig);
InputUserActiveFix(); InputUserActiveFix();
} }
static void CreateDirs(void) /**
* Creates the subdirectories used for saving snapshots, movies, game
* saves, etc. Hopefully obsolete with new configuration system.
*/
static void
CreateDirs(void)
{ {
char *subs[7]={"fcs","fcm","snaps","gameinfo","sav","cheats","movie"}; char *subs[7]={"fcs","fcm","snaps","gameinfo","sav","cheats","movie"};
char tdir[2048]; char tdir[2048];
@ -149,15 +181,13 @@ static void CreateDirs(void)
#ifdef WIN32 #ifdef WIN32
mkdir((char *)DrBaseDirectory); mkdir((char *)DrBaseDirectory);
for(x=0;x<6;x++) for(x = 0; x < 6; x++) {
{
sprintf(tdir,"%s"PSS"%s",DrBaseDirectory,subs[x]); sprintf(tdir,"%s"PSS"%s",DrBaseDirectory,subs[x]);
mkdir(tdir); mkdir(tdir);
} }
#else #else
mkdir((char *)DrBaseDirectory,S_IRWXU); mkdir((char *)DrBaseDirectory,S_IRWXU);
for(x=0;x<6;x++) for(x = 0; x < 6; x++) {
{
sprintf(tdir,"%s"PSS"%s",DrBaseDirectory,subs[x]); sprintf(tdir,"%s"PSS"%s",DrBaseDirectory,subs[x]);
mkdir(tdir,S_IRWXU); mkdir(tdir,S_IRWXU);
} }
@ -165,20 +195,27 @@ static void CreateDirs(void)
} }
#ifndef WIN32 #ifndef WIN32
static void SetSignals(void (*t)(int)) /**
* Capture and handle signals sent to FCEU.
*/
static void
SetSignals(void (*t)(int))
{ {
// XXX soules - why do we capture these? Seems unnecessary.
int sigs[11]={SIGINT,SIGTERM,SIGHUP,SIGPIPE,SIGSEGV,SIGFPE,SIGKILL,SIGALRM,SIGABRT,SIGUSR1,SIGUSR2}; int sigs[11]={SIGINT,SIGTERM,SIGHUP,SIGPIPE,SIGSEGV,SIGFPE,SIGKILL,SIGALRM,SIGABRT,SIGUSR1,SIGUSR2};
int x; int x;
for(x=0;x<11;x++) for(x = 0; x < 11; x++) {
signal(sigs[x], t); signal(sigs[x], t);
} }
}
static void CloseStuff(int signum) static void
CloseStuff(int signum)
{ {
// XXX soules - again, not clear why this is necessary
DriverKill(); DriverKill();
printf("\nSignal %d has been caught and dealt with...\n",signum); printf("\nSignal %d has been caught and dealt with...\n",signum);
switch(signum) switch(signum) {
{
case SIGINT:printf("How DARE you interrupt me!\n");break; case SIGINT:printf("How DARE you interrupt me!\n");break;
case SIGTERM:printf("MUST TERMINATE ALL HUMANS\n");break; case SIGTERM:printf("MUST TERMINATE ALL HUMANS\n");break;
case SIGHUP:printf("Reach out and hang-up on someone.\n");break; case SIGHUP:printf("Reach out and hang-up on someone.\n");break;
@ -200,7 +237,13 @@ static void CloseStuff(int signum)
} }
#endif #endif
static void DoArgs(int argc, char *argv[]) /**
* Handles arguments passed to FCEU. Hopefully obsolete with new
* configuration system.
*/
static void
DoArgs(int argc,
char *argv[])
{ {
int x; int x;
@ -234,15 +277,15 @@ static void DoArgs(int argc, char *argv[])
}; };
ParseArguments(argc, argv, FCEUArgs); ParseArguments(argc, argv, FCEUArgs);
if(cpalette) if(cpalette) {
{ if(cpalette[0] == '0') {
if(cpalette[0]=='0') if(cpalette[1] == 0) {
if(cpalette[1]==0)
{
free(cpalette); free(cpalette);
cpalette=0; cpalette=0;
} }
} }
}
FCEUI_SetVidSystem((eoptions&EO_PAL)?1:0); FCEUI_SetVidSystem((eoptions&EO_PAL)?1:0);
FCEUI_SetGameGenie((eoptions&EO_GAMEGENIE)?1:0); FCEUI_SetGameGenie((eoptions&EO_GAMEGENIE)?1:0);
FCEUI_SetLowPass((eoptions&EO_LOWPASS)?1:0); FCEUI_SetLowPass((eoptions&EO_LOWPASS)?1:0);
@ -250,8 +293,7 @@ static void DoArgs(int argc, char *argv[])
FCEUI_DisableSpriteLimitation(eoptions&1); FCEUI_DisableSpriteLimitation(eoptions&1);
FCEUI_SetSnapName(eoptions&EO_SNAPNAME); FCEUI_SetSnapName(eoptions&EO_SNAPNAME);
for(x=0;x<2;x++) for(x = 0; x < 2; x++) {
{
if(srendlinev[x]<0 || srendlinev[x]>239) srendlinev[x]=0; if(srendlinev[x]<0 || srendlinev[x]>239) srendlinev[x]=0;
if(erendlinev[x]<srendlinev[x] || erendlinev[x]>239) erendlinev[x]=239; if(erendlinev[x]<srendlinev[x] || erendlinev[x]>239) erendlinev[x]=239;
} }
@ -262,28 +304,29 @@ static void DoArgs(int argc, char *argv[])
#include "usage.h" #include "usage.h"
/* Loads a game, given a full path/filename. The driver code must be /**
initialized after the game is loaded, because the emulator code * Loads a game, given a full path/filename. The driver code must be
provides data necessary for the driver code(number of scanlines to * initialized after the game is loaded, because the emulator code
render, what virtual input devices to use, etc.). * provides data necessary for the driver code(number of scanlines to
* render, what virtual input devices to use, etc.).
*/ */
int LoadGame(const char *path) int LoadGame(const char *path)
{ {
FCEUGI *tmp; FCEUGI *tmp;
CloseGame(); CloseGame();
if(!(tmp=FCEUI_LoadGame(path,1))) if(!(tmp = FCEUI_LoadGame(path, 1))) {
return 0; return 0;
}
CurGame=tmp; CurGame=tmp;
ParseGI(tmp); ParseGI(tmp);
RefreshThrottleFPS(); RefreshThrottleFPS();
if(!DriverInitialize(tmp)) if(!DriverInitialize(tmp)) {
return(0); return(0);
if(soundrecfn) }
{ if(soundrecfn) {
if(!FCEUI_BeginWaveRecord(soundrecfn)) if(!FCEUI_BeginWaveRecord(soundrecfn)) {
{
free(soundrecfn); free(soundrecfn);
soundrecfn=0; soundrecfn=0;
} }
@ -294,17 +337,23 @@ int LoadGame(const char *path)
return 1; return 1;
} }
/* Closes a game. Frees memory, and deinitializes the drivers. */ /**
int CloseGame(void) * Closes a game. Frees memory, and deinitializes the drivers.
*/
int
CloseGame()
{ {
if(!isloaded) return(0); if(!isloaded) {
return(0);
}
FCEUI_CloseGame(); FCEUI_CloseGame();
DriverKill(); DriverKill();
isloaded=0; isloaded=0;
CurGame=0; CurGame=0;
if(soundrecfn) if(soundrecfn) {
FCEUI_EndWaveRecord(); FCEUI_EndWaveRecord();
}
InputUserActiveFix(); InputUserActiveFix();
return(1); return(1);
@ -324,31 +373,38 @@ void DoFun(void)
fskipc=(fskipc+1)%(frameskip+1); fskipc=(fskipc+1)%(frameskip+1);
#endif #endif
if(NoWaiting) {gfx=0;} if(NoWaiting) {
gfx = 0;
}
FCEUI_Emulate(&gfx, &sound, &ssize, fskipc); FCEUI_Emulate(&gfx, &sound, &ssize, fskipc);
FCEUD_Update(gfx, sound, ssize); FCEUD_Update(gfx, sound, ssize);
if(opause!=FCEUI_EmulationPaused()) if(opause!=FCEUI_EmulationPaused()) {
{
opause=FCEUI_EmulationPaused(); opause=FCEUI_EmulationPaused();
SilenceSound(opause); SilenceSound(opause);
} }
} }
int CLImain(int argc, char *argv[]) /**
* Common Layer Interface main() loop. This should get merged into
* the SDL main() loop since we're only supporting SDL now.
*/
int
CLImain(int argc,
char *argv[])
{ {
int ret; int ret;
if(!(ret=FCEUI_Initialize())) if(!(ret=FCEUI_Initialize())) {
return(0); return(0);
}
DrBaseDirectory=GetBaseDirectory(); DrBaseDirectory=GetBaseDirectory();
FCEUI_SetBaseDirectory((char *)DrBaseDirectory); FCEUI_SetBaseDirectory((char *)DrBaseDirectory);
CreateDirs(); CreateDirs();
if(argc<=1) if(argc<=1) {
{
ShowUsage(argv[0]); ShowUsage(argv[0]);
return(0); return(0);
} }
@ -356,19 +412,19 @@ int CLImain(int argc, char *argv[])
LoadConfig(); LoadConfig();
DoArgs(argc-2,&argv[1]); DoArgs(argc-2,&argv[1]);
FCEUI_SetNTSCTH(ntsccol, ntsctint, ntschue); FCEUI_SetNTSCTH(ntsccol, ntsctint, ntschue);
if(cpalette) if(cpalette) {
LoadCPalette(); LoadCPalette();
}
/* All the config files and arguments are parsed now. */ /* All the config files and arguments are parsed now. */
if(!LoadGame(argv[argc-1])) if(!LoadGame(argv[argc-1])) {
{
DriverKill(); DriverKill();
return(0); return(0);
} }
while(CurGame) while(CurGame) {
DoFun(); DoFun();
}
CloseGame(); CloseGame();
@ -379,7 +435,12 @@ int CLImain(int argc, char *argv[])
return(1); return(1);
} }
static int DriverInitialize(FCEUGI *gi) /**
* Initialize all of the subsystem drivers: video, audio, joystick,
* keyboard, mouse.
*/
static int
DriverInitialize(FCEUGI *gi)
{ {
#ifndef WIN32 #ifndef WIN32
SetSignals(CloseStuff); SetSignals(CloseStuff);
@ -405,7 +466,12 @@ static int DriverInitialize(FCEUGI *gi)
return 1; return 1;
} }
static void DriverKill(void) /**
* Shut down all of the subsystem drivers: video, audio, joystick,
* keyboard.
*/
static void
DriverKill()
{ {
SaveConfig(); SaveConfig();
@ -426,15 +492,21 @@ static void DriverKill(void)
inited=0; inited=0;
} }
void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count) /**
* Update the video, audio, and input subsystems with the provided
* video (XBuf) and audio (Buffer) information.
*/
void
FCEUD_Update(uint8 *XBuf,
int32 *Buffer,
int Count)
{ {
extern int FCEUDnetplay; extern int FCEUDnetplay;
int ocount = Count; int ocount = Count;
// apply frame scaling to Count // apply frame scaling to Count
Count = (Count<<8)/fps_scale; Count = (Count<<8)/fps_scale;
if(Count) if(Count) {
{
int32 can=GetWriteSound(); int32 can=GetWriteSound();
static int uflow=0; static int uflow=0;
int32 tmpcan; int32 tmpcan;
@ -450,48 +522,37 @@ void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count)
//if(uflow) puts("Underflow"); //if(uflow) puts("Underflow");
tmpcan = GetWriteSound(); tmpcan = GetWriteSound();
// don't underflow when scaling fps // don't underflow when scaling fps
if(fps_scale>256 || ((tmpcan < Count*0.90) && !uflow)) if(fps_scale>256 || ((tmpcan < Count*0.90) && !uflow)) {
{
if(XBuf && (inited&4) && !(NoWaiting & 2)) if(XBuf && (inited&4) && !(NoWaiting & 2))
BlitScreen(XBuf); BlitScreen(XBuf);
Buffer+=can; Buffer+=can;
Count-=can; Count-=can;
if(Count) if(Count) {
{ if(NoWaiting) {
if(NoWaiting)
{
can=GetWriteSound(); can=GetWriteSound();
if(Count>can) Count=can; if(Count>can) Count=can;
WriteSound(Buffer,Count); WriteSound(Buffer,Count);
} } else {
else while(Count>0) {
{
while(Count>0)
{
WriteSound(Buffer,(Count<ocount) ? Count : ocount); WriteSound(Buffer,(Count<ocount) ? Count : ocount);
Count -= ocount; Count -= ocount;
} }
} }
} }
} //else puts("Skipped"); } //else puts("Skipped");
else if(!NoWaiting && FCEUDnetplay && (uflow || tmpcan >= (Count * 1.8))) else if(!NoWaiting && FCEUDnetplay && (uflow || tmpcan >= (Count * 1.8))) {
{
if(Count > tmpcan) Count=tmpcan; if(Count > tmpcan) Count=tmpcan;
while(tmpcan > 0) while(tmpcan > 0) {
{
// printf("Overwrite: %d\n", (Count <= tmpcan)?Count : tmpcan); // printf("Overwrite: %d\n", (Count <= tmpcan)?Count : tmpcan);
WriteSound(Buffer, (Count <= tmpcan)?Count : tmpcan); WriteSound(Buffer, (Count <= tmpcan)?Count : tmpcan);
tmpcan -= Count; tmpcan -= Count;
} }
} }
} } else {
else
{
if(!NoWaiting && (!(eoptions&EO_NOTHROTTLE) || FCEUI_EmulationPaused())) if(!NoWaiting && (!(eoptions&EO_NOTHROTTLE) || FCEUI_EmulationPaused()))
SpeedThrottle(); SpeedThrottle();
if(XBuf && (inited&4)) if(XBuf && (inited&4)) {
{
BlitScreen(XBuf); BlitScreen(XBuf);
} }
} }
@ -509,19 +570,32 @@ void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count)
/* Maybe ifndef WXWINDOWS would be better? ^_^ */ /* Maybe ifndef WXWINDOWS would be better? ^_^ */
/**
* Opens a file to be read a byte at a time.
*/
FILE *FCEUD_UTF8fopen(const char *fn, const char *mode) FILE *FCEUD_UTF8fopen(const char *fn, const char *mode)
{ {
return(fopen(fn,mode)); return(fopen(fn,mode));
} }
static char *s_linuxCompilerString = "g++ " __VERSION__; static char *s_linuxCompilerString = "g++ " __VERSION__;
/**
* Returns the compiler string.
*/
char *FCEUD_GetCompilerString() { char *FCEUD_GetCompilerString() {
return (char *)s_linuxCompilerString; return (char *)s_linuxCompilerString;
} }
/**
* Unimplemented.
*/
void FCEUD_DebugBreakpoint() { void FCEUD_DebugBreakpoint() {
return; return;
} }
/**
* Unimplemented.
*/
void FCEUD_TraceInstruction() { void FCEUD_TraceInstruction() {
return; return;
} }