diff --git a/src/drivers/sdl/input.cpp b/src/drivers/sdl/input.cpp index bc834573..035b8619 100644 --- a/src/drivers/sdl/input.cpp +++ b/src/drivers/sdl/input.cpp @@ -246,7 +246,9 @@ std::string GetFilename(const char* title, bool save, const char* filter) // TODO: make file filters case insensitive //gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterX); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterAll); - int response = gtk_dialog_run (GTK_DIALOG (fileChooser)); + gtk_dialog_run (GTK_DIALOG (fileChooser)); + + // flush gtk events while(gtk_events_pending()) gtk_main_iteration_do(TRUE); @@ -256,32 +258,6 @@ std::string GetFilename(const char* title, bool save, const char* filter) while(gtk_events_pending()) gtk_main_iteration_do(TRUE); -/* - FILE *fpipe; - std::string command = "zenity --file-selection --title=\""; - command.append(title); - command.append("\" --file-filter=\""); - command.append(filter); - command.append("\""); - if (save) // Do we want to save a file or load one? - { - command.append(" --save --confirm-overwrite --filename=\"."); - command.append(getExtension(filter)); - command.append("\""); - } - if ( !(fpipe = (FILE*)popen(command.c_str(),"r")) ) - { // If fpipe is NULL - FCEUD_PrintError("Pipe error on opening zenity"); - } - - int c; - while( (c = fgetc(fpipe)) ) - { - if (c == EOF || c == '\n') - break; - fname += c; - } - pclose(fpipe);*/ #endif FCEUI_ToggleEmulationPause(); return fname; @@ -305,7 +281,9 @@ std::string GetUserText(const char* title) gtk_widget_show_all(d); - int response = gtk_dialog_run(GTK_DIALOG(d)); + gtk_dialog_run(GTK_DIALOG(d)); + + // flush gtk events while(gtk_events_pending()) gtk_main_iteration_do(TRUE); diff --git a/src/drivers/sdl/sdl.cpp b/src/drivers/sdl/sdl.cpp index 53c8579f..b0db181a 100644 --- a/src/drivers/sdl/sdl.cpp +++ b/src/drivers/sdl/sdl.cpp @@ -40,14 +40,13 @@ #include "unix-netplay.h" #include "../common/configSys.h" +#include "../../oldmovie.h" +#include "../../types.h" #ifdef CREATE_AVI #include "../videolog/nesvideos-piece.h" #endif -#include "../../oldmovie.h" -#include "../../types.h" - #ifdef WIN32 #include #endif @@ -60,8 +59,8 @@ bool turbo = false; int CloseGame(void); -static int inited=0; -static int isloaded=0; // Is game loaded? +static int inited = 0; +static int isloaded = 0; int eoptions=0; @@ -74,68 +73,66 @@ int mutecapture; static int noconfig; char *DriverUsage="\ ---pal {0|1} Uses PAL timing.\n\ ---gamegenie {0|1} Enables emulated Game Genie.\n\ ---newppu {0|1} Enables the new PPU core. (WARNING: May break savestates)\n\ ---frameskip x Sets # of frames to skip per emulated frame.\n\ ---xres x Sets horizontal resolution to x for full screen mode.\n\ ---yres x Sets vertical resolution to x for full screen mode.\n\ ---autoscale {0|1} Enables autoscaling in fullscreen if x in nonzero. \n\ ---keepratio {0|1} Keeps native NES ratio when autoscaling. \n\ ---(x/y)scale x Multiplies width/height by x. \n\ - (Real numbers >0 with OpenGL, otherwise integers >0).\n\ ---(x/y)stretch {0|1} Stretches to fill surface on x/y axis (OpenGL only).\n\ ---bpp {8|16|32} Sets bits per pixel.\n\ ---opengl {0|1} Enables OpenGL support.\n\ ---fullscreen {0|1} Enables full screen mode.\n\ ---noframe {0|1} Hides title bar and window decorations.\n\ ---special {1-4} Use special video scaling filters\n\ - (1 = hq2x 2 = Scale2x 3 = hq3x 4 = Scale3x)\n\ ---palette f Loads a custom global palette from file f.\n\ ---sound {0|1} Enables sound.\n\ ---volume {0-150} Sets volume.\n\ ---soundrecord f Records sound to file f.\n\ ---input(1,2) d Set the input device for input 1 or 2.\n\ - Devices: gamepad zapper powerpad.0 powerpad.1 arkanoid\n\ ---input(3,4) d Set the famicom expansion device for input(3, 4)\n\ - Devices: quizking hypershot mahjong toprider ftrainer\n\ +Option Value Description\n\ +--pal {0|1} Use PAL timing.\n\ +--newppu {0|1} Enable the new PPU core. (WARNING: May break savestates)\n\ +--inputcfg d Configures input device d on startup.\n\ +--gamegenie {0|1} Enable emulated Game Genie.\n\ +--frameskip x Set # of frames to skip per emulated frame.\n\ +--xres x Set horizontal resolution for full screen mode.\n\ +--yres x Set vertical resolution for full screen mode.\n\ +--autoscale {0|1} Enable autoscaling in fullscreen. \n\ +--keepratio {0|1} Keep native NES aspect ratio when autoscaling. \n\ +--(x/y)scale x Multiply width/height by x. \n\ + (Real numbers >0 with OpenGL, otherwise integers >0).\n\ +--(x/y)stretch {0|1} Stretch to fill surface on x/y axis (OpenGL only).\n\ +--bpp {8|16|32} Set bits per pixel.\n\ +--opengl {0|1} Enable OpenGL support.\n\ +--fullscreen {0|1} Enable full screen mode.\n\ +--noframe {0|1} Hide title bar and window decorations.\n\ +--special {1-4} Use special video scaling filters\n\ + (1 = hq2x 2 = Scale2x 3 = hq3x 4 = Scale3x)\n\ +--palette f Load custom global palette from file f.\n\ +--sound {0|1} Enable sound.\n\ +--soundrate x Set sound playback rate to x Hz.\n\ +--soundq {0|1|2} Set sound quality. (0=Low;1=High;2=Very High)\n\ +--soundbufsize x Set sound buffer size to x ms.\n\ +--volume {0-256} Set volume to x.\n\ +--soundrecord f Record sound to file f.\n\ +--input(1,2) d Set the input device for input 1 or 2.\n\ + Devices: gamepad zapper powerpad.0 powerpad.1 arkanoid\n\ +--input(3,4) d Set the famicom expansion device for input(3, 4)\n\ + Devices: quizking hypershot mahjong toprider ftrainer\n\ familykeyboard oekakids arkanoid shadow bworld 4player\n\ ---inputcfg d Configures input device d on startup.\n\ ---inputdisplay{0|1|2|4}Displays game input.\n\ ---playmov f Plays back a recorded movie from filename f.\n\ ---pauseframe x Pauses movie playback at frame x.\n\ ---fcmconvert f Converts fcm movie file f to fm2.\n\ ---ripsubs f Converts movie's subtitles to srt\n\ ---subtitles {0,1} Enables subtitle display\n\ ---fourscore {0,1} Enables fourscore emulation\n\ ---no-config {0,1} Don't change the config file"; +--playmov f Play back a recorded FCM/FM2 movie from filename f.\n\ +--pauseframe x Pause movie playback at frame x.\n\ +--fcmconvert f Convert fcm movie file f to fm2.\n\ +--ripsubs f Convert movie's subtitles to srt\n\ +--subtitles {0,1} Enable subtitle display\n\ +--fourscore {0,1} Enable fourscore emulation\n\ +--no-config {0,1} Use default config file and do not save\n\ +--net s Connect to server 's' for TCP/IP network play.\n\ +--port x Use TCP/IP port x for network play.\n\ +--user x Set the nickname to use in network play.\n\ +--pass x Set password to use for connecting to the server.\n\ +--netkey s Use string 's' to create a unique session for the game loaded.\n\ +--players x Set the number of local players.\n"; -/* Moved network options out while netplay is broken. ---net s, -n s Connects to server 's' for TCP/IP network play.\n\ ---port x, -p x Uses TCP/IP port x for network play.\n\ ---user s, -u s Sets the nickname to use in network play.\n\ ---pass s, -w s Sets password to use for connecting to the server.\n\ ---netkey s, -k s Uses key 's' to create a unique session for the game loaded.\n\ ---players x, -l x Sets the number of local players.\n\ -*/ // these should be moved to the man file -// --nospritelim {0|1} Disables the 8 sprites per scanline limitation.\n\ -//--trianglevol {0-256} Sets Triangle volume.\n\ -//--square1vol {0-256} Sets Square 1 volume.\n\ -//--square2vol {0-256} Sets Square 2 volume.\n\ -//--noisevol {0-256} Sets Noise volume.\n\ -//--pcmvol {0-256} Sets PCM volume.\n\ -//--lowpass {0|1} Enables low-pass filter if x is nonzero.\n\ -//--doublebuf {0|1} Enables SDL double-buffering if x is nonzero.\n\ -//--slend {0-239} Sets the last drawn emulated scanline.\n\ -//--ntsccolor {0|1} Emulates an NTSC TV's colors.\n\ -//--hue x Sets hue for NTSC color emulation.\n\ -//--tint x Sets tint for NTSC color emulation.\n\ -//--soundrate x Sets sound playback rate to x Hz.\n\ -//--soundq {0|1} Enables high sound quality.\n\ -//--soundbufsize x Sets sound buffer size to x ms.\n\ -//--slstart {0-239} Sets the first drawn emulated scanline.\n\ -//--clipsides {0|1} Clips left and rightmost 8 columns of pixels.\n\ +//--nospritelim {0|1} Disables the 8 sprites per scanline limitation.\n +//--trianglevol {0-256} Sets Triangle volume.\n +//--square1vol {0-256} Sets Square 1 volume.\n +//--square2vol {0-256} Sets Square 2 volume.\n +//--noisevol {0-256} Sets Noise volume.\n +//--pcmvol {0-256} Sets PCM volume.\n +//--lowpass {0|1} Enables low-pass filter if x is nonzero.\n +//--doublebuf {0|1} Enables SDL double-buffering if x is nonzero.\n +//--slend {0-239} Sets the last drawn emulated scanline.\n +//--ntsccolor {0|1} Emulates an NTSC TV's colors.\n +//--hue x Sets hue for NTSC color emulation.\n +//--tint x Sets tint for NTSC color emulation.\n +//--slstart {0-239} Sets the first drawn emulated scanline.\n +//--clipsides {0|1} Clips left and rightmost 8 columns of pixels.\n // global configuration object Config *g_config; @@ -146,11 +143,11 @@ static void ShowUsage(char *prog) puts("Options:"); puts(DriverUsage); #ifdef _S9XLUA_H - puts ("--loadlua f Loads lua script from filename f."); + puts ("--loadlua f Loads lua script from filename f."); #endif #ifdef CREATE_AVI - puts ("--videolog c Calls mencoder to grab the video and audio streams to\n encode them. Check the documentation for more on this."); - puts ("--mute {0|1} Mutes FCEUX while still passing the audio stream to\n mencoder."); + puts ("--videolog c Calls mencoder to grab the video and audio streams to\n encode them. Check the documentation for more on this."); + puts ("--mute {0|1} Mutes FCEUX while still passing the audio stream to\n mencoder."); #endif puts(""); printf("Compiled with SDL version %d.%d.%d\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL ); @@ -169,7 +166,7 @@ static void ShowUsage(char *prog) void FCEUD_PrintError(char *s) { - puts(s); + puts(s); } /** @@ -177,7 +174,7 @@ FCEUD_PrintError(char *s) */ void FCEUD_Message(char *s) { - fputs(s, stdout); + fputs(s, stdout); } /** @@ -188,38 +185,36 @@ void FCEUD_Message(char *s) */ int LoadGame(const char *path) { - std::string filename; + CloseGame(); + if(!FCEUI_LoadGame(path, 1)) { + return 0; + } + ParseGIInput(GameInfo); + RefreshThrottleFPS(); - CloseGame(); - if(!FCEUI_LoadGame(path, 1)) { - return 0; - } - ParseGIInput(GameInfo); - RefreshThrottleFPS(); - - if(!DriverInitialize(GameInfo)) { - return(0); - } - - // set pal/ntsc - int buf; - g_config->getOption("SDL.PAL", &buf); - if(buf) + if(!DriverInitialize(GameInfo)) { + return(0); + } + + // set pal/ntsc + int id; + g_config->getOption("SDL.PAL", &id); + if(id) FCEUI_SetVidSystem(1); else FCEUI_SetVidSystem(0); + std::string filename; + g_config->getOption("SDL.SoundRecordFile", &filename); + if(filename.size()) { + if(!FCEUI_BeginWaveRecord(filename.c_str())) { + g_config->setOption("SDL.SoundRecordFile", ""); + } + } + isloaded = 1; - g_config->getOption("SDL.SoundRecordFile", &filename); - if(filename.size()) { - if(!FCEUI_BeginWaveRecord(filename.c_str())) { - g_config->setOption("SDL.SoundRecordFile", ""); - } - } - isloaded = 1; - - FCEUD_NetworkConnect(); - return 1; + FCEUD_NetworkConnect(); + return 1; } /** @@ -228,49 +223,49 @@ int LoadGame(const char *path) int CloseGame() { - std::string filename; + std::string filename; - if(!isloaded) { - return(0); - } - FCEUI_CloseGame(); - DriverKill(); - isloaded = 0; - GameInfo = 0; + if(!isloaded) { + return(0); + } + FCEUI_CloseGame(); + DriverKill(); + isloaded = 0; + GameInfo = 0; - g_config->getOption("SDL.SoundRecordFile", &filename); - if(filename.size()) { - FCEUI_EndWaveRecord(); - } + g_config->getOption("SDL.SoundRecordFile", &filename); + if(filename.size()) { + FCEUI_EndWaveRecord(); + } - InputUserActiveFix(); - return(1); + InputUserActiveFix(); + return(1); } void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count); static void DoFun(int frameskip) { - uint8 *gfx; - int32 *sound; - int32 ssize; - static int fskipc = 0; - static int opause = 0; + uint8 *gfx; + int32 *sound; + int32 ssize; + static int fskipc = 0; + static int opause = 0; #ifdef FRAMESKIP - fskipc = (fskipc + 1) % (frameskip + 1); + fskipc = (fskipc + 1) % (frameskip + 1); #endif - if(NoWaiting) { - gfx = 0; - } - FCEUI_Emulate(&gfx, &sound, &ssize, fskipc); - FCEUD_Update(gfx, sound, ssize); + if(NoWaiting) { + gfx = 0; + } + FCEUI_Emulate(&gfx, &sound, &ssize, fskipc); + FCEUD_Update(gfx, sound, ssize); - if(opause!=FCEUI_EmulationPaused()) { - opause=FCEUI_EmulationPaused(); - SilenceSound(opause); - } + if(opause!=FCEUI_EmulationPaused()) { + opause=FCEUI_EmulationPaused(); + SilenceSound(opause); + } } @@ -280,23 +275,14 @@ static void DoFun(int frameskip) static int DriverInitialize(FCEUGI *gi) { -#ifndef WIN32 - // XXX soules - capturing all these signals seems pointless - //SetSignals(CloseStuff); -#endif + if(InitVideo(gi) < 0) return 0; + inited|=4; - /* Initialize video before all else, due to some wacko dependencies - in the SexyAL code(DirectSound) that need to be fixed. - */ + if(InitSound()) + inited|=1; - if(InitVideo(gi) < 0) return 0; - inited|=4; - - if(InitSound()) - inited|=1; - - if(InitJoysticks()) - inited|=2; + if(InitJoysticks()) + inited|=2; int fourscore=0; g_config->getOption("SDL.FourScore", &fourscore); @@ -304,8 +290,8 @@ DriverInitialize(FCEUGI *gi) if(fourscore) eoptions |= EO_FOURSCORE; - InitInputInterface(); - return 1; + InitInputInterface(); + return 1; } /** @@ -314,21 +300,16 @@ DriverInitialize(FCEUGI *gi) static void DriverKill() { - if (!noconfig) - g_config->save(); + if (!noconfig) + g_config->save(); -#ifndef WIN32 - // XXX soules - capturing all these signals seems pointless - //SetSignals(SIG_IGN); -#endif - - if(inited&2) - KillJoysticks(); - if(inited&4) - KillVideo(); - if(inited&1) - KillSound(); - inited=0; + if(inited&2) + KillJoysticks(); + if(inited&4) + KillVideo(); + if(inited&1) + KillSound(); + inited=0; } /** @@ -337,126 +318,124 @@ DriverKill() */ void FCEUD_Update(uint8 *XBuf, - int32 *Buffer, - int Count) + int32 *Buffer, + int Count) { - extern int FCEUDnetplay; + extern int FCEUDnetplay; - #ifdef CREATE_AVI - if(LoggingEnabled == 2 || (eoptions&EO_NOTHROTTLE)) - { - if(LoggingEnabled == 2) - { - int16* MonoBuf = (int16*)malloc(sizeof(*MonoBuf) * Count); - int n; - for(n=0; n GetWriteSound()) Count = GetWriteSound(); - if (!mutecapture) - if(Count > 0 && Buffer) WriteSound(Buffer,Count); - } - if(inited & 2) - FCEUD_UpdateInput(); - if(XBuf && (inited & 4)) BlitScreen(XBuf); - - //SpeedThrottle(); - return; - } - #endif - - int ocount = Count; - // apply frame scaling to Count - Count = (int)(Count / g_fpsScale); - if(Count) { - int32 can=GetWriteSound(); - static int uflow=0; - int32 tmpcan; + #ifdef CREATE_AVI + if(LoggingEnabled == 2 || (eoptions&EO_NOTHROTTLE)) + { + if(LoggingEnabled == 2) + { + int16* MonoBuf = (int16*)malloc(sizeof(*MonoBuf) * Count); + int n; + for(n=0; n GetWriteSound()) Count = GetWriteSound(); + if (!mutecapture) + if(Count > 0 && Buffer) WriteSound(Buffer,Count); + } + if(inited & 2) + FCEUD_UpdateInput(); + if(XBuf && (inited & 4)) BlitScreen(XBuf); + + //SpeedThrottle(); + return; + } + #endif + + int ocount = Count; + // apply frame scaling to Count + Count = (int)(Count / g_fpsScale); + if(Count) { + int32 can=GetWriteSound(); + static int uflow=0; + int32 tmpcan; - // don't underflow when scaling fps - if(can >= GetMaxSound() && g_fpsScale==1.0) uflow=1; /* Go into massive underflow mode. */ + // don't underflow when scaling fps + if(can >= GetMaxSound() && g_fpsScale==1.0) uflow=1; /* Go into massive underflow mode. */ - if(can > Count) can=Count; - else uflow=0; + if(can > Count) can=Count; + else uflow=0; - #ifdef CREATE_AVI - if (!mutecapture) - #endif - WriteSound(Buffer,can); + #ifdef CREATE_AVI + if (!mutecapture) + #endif + WriteSound(Buffer,can); - //if(uflow) puts("Underflow"); - tmpcan = GetWriteSound(); - // don't underflow when scaling fps - if(g_fpsScale>1.0 || ((tmpcan < Count*0.90) && !uflow)) { - if(XBuf && (inited&4) && !(NoWaiting & 2)) - BlitScreen(XBuf); - Buffer+=can; - Count-=can; - if(Count) { - if(NoWaiting) { - can=GetWriteSound(); - if(Count>can) Count=can; - #ifdef CREATE_AVI - if (!mutecapture) - #endif - WriteSound(Buffer,Count); - } else { - while(Count>0) { - #ifdef CREATE_AVI - if (!mutecapture) - #endif - WriteSound(Buffer,(Count= (Count * 1.8))) { - if(Count > tmpcan) Count=tmpcan; - while(tmpcan > 0) { - // printf("Overwrite: %d\n", (Count <= tmpcan)?Count : tmpcan); - #ifdef CREATE_AVI - if (!mutecapture) - #endif - WriteSound(Buffer, (Count <= tmpcan)?Count : tmpcan); - tmpcan -= Count; - } - } + //if(uflow) puts("Underflow"); + tmpcan = GetWriteSound(); + // don't underflow when scaling fps + if(g_fpsScale>1.0 || ((tmpcan < Count*0.90) && !uflow)) { + if(XBuf && (inited&4) && !(NoWaiting & 2)) + BlitScreen(XBuf); + Buffer+=can; + Count-=can; + if(Count) { + if(NoWaiting) { + can=GetWriteSound(); + if(Count>can) Count=can; + #ifdef CREATE_AVI + if (!mutecapture) + #endif + WriteSound(Buffer,Count); + } else { + while(Count>0) { + #ifdef CREATE_AVI + if (!mutecapture) + #endif + WriteSound(Buffer,(Count= (Count * 1.8))) { + if(Count > tmpcan) Count=tmpcan; + while(tmpcan > 0) { + // printf("Overwrite: %d\n", (Count <= tmpcan)?Count : tmpcan); + #ifdef CREATE_AVI + if (!mutecapture) + #endif + WriteSound(Buffer, (Count <= tmpcan)?Count : tmpcan); + tmpcan -= Count; + } + } - } else { - if(!NoWaiting && (!(eoptions&EO_NOTHROTTLE) || FCEUI_EmulationPaused())) - while (SpeedThrottle()) - { - FCEUD_UpdateInput(); - } - if(XBuf && (inited&4)) { - BlitScreen(XBuf); - } - } - FCEUD_UpdateInput(); - //if(!Count && !NoWaiting && !(eoptions&EO_NOTHROTTLE)) - // SpeedThrottle(); - //if(XBuf && (inited&4)) - //{ - // BlitScreen(XBuf); - //} - //if(Count) - // WriteSound(Buffer,Count,NoWaiting); - //FCEUD_UpdateInput(); + } else { + if(!NoWaiting && (!(eoptions&EO_NOTHROTTLE) || FCEUI_EmulationPaused())) + while (SpeedThrottle()) + { + FCEUD_UpdateInput(); + } + if(XBuf && (inited&4)) { + BlitScreen(XBuf); + } + } + FCEUD_UpdateInput(); + //if(!Count && !NoWaiting && !(eoptions&EO_NOTHROTTLE)) + // SpeedThrottle(); + //if(XBuf && (inited&4)) + //{ + // BlitScreen(XBuf); + //} + //if(Count) + // WriteSound(Buffer,Count,NoWaiting); + //FCEUD_UpdateInput(); } - -/* Maybe ifndef WXWINDOWS would be better? ^_^ */ /** * Opens a file to be read a byte at a time. */ @@ -484,7 +463,7 @@ std::fstream* FCEUD_UTF8_fstream(const char *fn, const char *m) */ FILE *FCEUD_UTF8fopen(const char *fn, const char *mode) { - return(fopen(fn,mode)); + return(fopen(fn,mode)); } static char *s_linuxCompilerString = "g++ " __VERSION__; @@ -492,252 +471,250 @@ static char *s_linuxCompilerString = "g++ " __VERSION__; * Returns the compiler string. */ const char *FCEUD_GetCompilerString() { - return (const char *)s_linuxCompilerString; + return (const char *)s_linuxCompilerString; } /** * Unimplemented. */ void FCEUD_DebugBreakpoint() { - return; + return; } /** * Unimplemented. */ void FCEUD_TraceInstruction() { - return; + return; } /** * The main loop for the SDL. */ -int -main(int argc, - char *argv[]) +int main(int argc, char *argv[]) { - int error, frameskip; + int error, frameskip; - FCEUD_Message("\nStarting "FCEU_NAME_AND_VERSION"...\n"); + FCEUD_Message("\nStarting "FCEU_NAME_AND_VERSION"...\n"); #ifdef WIN32 - /* Taken from win32 sdl_main.c */ - SDL_SetModuleHandle(GetModuleHandle(NULL)); + /* Taken from win32 sdl_main.c */ + SDL_SetModuleHandle(GetModuleHandle(NULL)); #endif - /* SDL_INIT_VIDEO Needed for (joystick config) event processing? */ - if(SDL_Init(SDL_INIT_VIDEO)) { - printf("Could not initialize SDL: %s.\n", SDL_GetError()); - return(-1); - } + /* SDL_INIT_VIDEO Needed for (joystick config) event processing? */ + if(SDL_Init(SDL_INIT_VIDEO)) { + printf("Could not initialize SDL: %s.\n", SDL_GetError()); + return(-1); + } #ifdef OPENGL -SDL_GL_LoadLibrary(0); + SDL_GL_LoadLibrary(0); #endif - // Initialize the configuration system - g_config = InitConfig(); - + // Initialize the configuration system + g_config = InitConfig(); - if(!g_config) { - SDL_Quit(); - return -1; - } + + if(!g_config) { + SDL_Quit(); + return -1; + } - // initialize the infrastructure - error = FCEUI_Initialize(); - if(error != 1) { - ShowUsage(argv[0]); - SDL_Quit(); - return -1; - } - - int romIndex = g_config->parse(argc, argv); + // initialize the infrastructure + error = FCEUI_Initialize(); + if(error != 1) { + ShowUsage(argv[0]); + SDL_Quit(); + return -1; + } + + int romIndex = g_config->parse(argc, argv); - //mbg 8/23/2008 - this is also here so that the inputcfg routines can have a chance to dump the new inputcfg to the fceux.cfg - //in case you didnt specify a rom filename - // This is here so that a default fceux.cfg will be created on first - // run, even without a valid ROM to play. - // Unless, of course, there's actually --no-config given - g_config->getOption("SDL.NoConfig", &noconfig); - if (!noconfig) - g_config->save(); + // This is here so that a default fceux.cfg will be created on first + // run, even without a valid ROM to play. + // Unless, of course, there's actually --no-config given + // mbg 8/23/2008 - this is also here so that the inputcfg routines can have a chance to dump the new inputcfg to the fceux.cfg + // in case you didnt specify a rom filename + g_config->getOption("SDL.NoConfig", &noconfig); + if (!noconfig) + g_config->save(); std::string s; g_config->getOption("SDL.InputCfg", &s); // update the input devices - UpdateInput(g_config); - + UpdateInput(g_config); + + // check for a .fcm file to convert to .fm2 + g_config->getOption ("SDL.FCMConvert", &s); + g_config->setOption ("SDL.FCMConvert", ""); + if (!s.empty()) + { + int okcount = 0; + std::string infname = s.c_str(); + // produce output filename + std::string outname; + size_t dot = infname.find_last_of ("."); + if (dot == std::string::npos) + outname = infname + ".fm2"; + else + outname = infname.substr(0,dot) + ".fm2"; + + MovieData md; + EFCM_CONVERTRESULT result = convert_fcm (md, infname); - - // check for a .fcm file to convert to .fm2 - g_config->getOption ("SDL.FCMConvert", &s); - g_config->setOption ("SDL.FCMConvert", ""); - if (!s.empty()) - { - int okcount = 0; - std::string infname = s.c_str(); - // produce output filename - std::string outname; - size_t dot = infname.find_last_of ("."); - if (dot == std::string::npos) - outname = infname + ".fm2"; - else - outname = infname.substr(0,dot) + ".fm2"; - - MovieData md; - EFCM_CONVERTRESULT result = convert_fcm (md, infname); - - if (result == FCM_CONVERTRESULT_SUCCESS) - { - okcount++; - std::fstream* outf = FCEUD_UTF8_fstream (outname, "wb"); - md.dump (outf,false); - delete outf; - FCEUD_Message ("Your file has been converted to FM2.\n"); - } else { - FCEUD_Message ("Something went wrong while converting your file...\n"); - } - - DriverKill(); - SDL_Quit(); - return 0; - } - - // check to see if movie messages are disabled - int mm; - g_config->getOption("SDL.MovieMsg", &mm); - if( mm == 0) + if (result == FCM_CONVERTRESULT_SUCCESS) { + okcount++; + std::fstream* outf = FCEUD_UTF8_fstream (outname, "wb"); + md.dump (outf,false); + delete outf; + FCEUD_Message ("Your file has been converted to FM2.\n"); + } + else { + FCEUD_Message ("Something went wrong while converting your file...\n"); + } + + DriverKill(); + SDL_Quit(); + return 0; + } + + // check to see if movie messages are disabled + int mm; + g_config->getOption("SDL.MovieMsg", &mm); + if( mm == 0) FCEUI_SetAviDisableMovieMessages(true); else FCEUI_SetAviDisableMovieMessages(false); - // check for a .fm2 file to rip the subtitles - g_config->getOption("SDL.RipSubs", &s); - g_config->setOption("SDL.RipSubs", ""); - if (!s.empty()) - { - MovieData md; - std::string infname; - infname = s.c_str(); - FCEUFILE *fp = FCEU_fopen(s.c_str(), 0, "rb", 0); - - // load the movie and and subtitles - extern bool LoadFM2(MovieData&, std::istream*, int, bool); - LoadFM2(md, fp->stream, INT_MAX, false); - LoadSubtitles(md); // fill subtitleFrames and subtitleMessages - delete fp; - - // produce .srt file's name and open it for writing - std::string outname; - size_t dot = infname.find_last_of ("."); - if (dot == std::string::npos) - outname = infname + ".srt"; - else - outname = infname.substr(0,dot) + ".srt"; - FILE *srtfile; - srtfile = fopen(outname.c_str(), "w"); - - if (srtfile != NULL) - { - extern std::vector subtitleFrames; - extern std::vector subtitleMessages; - float fps = (md.palFlag == 0 ? 60.0988 : 50.0069); // NTSC vs PAL - float subduration = 3; // seconds for the subtitles to be displayed - for (int i = 0; i < subtitleFrames.size(); i++) - { - fprintf(srtfile, "%i\n", i+1); // starts with 1, not 0 - double seconds, ms, endseconds, endms; - seconds = subtitleFrames[i]/fps; - if (i+1 < subtitleFrames.size()) // there's another subtitle coming after this one - { - if (subtitleFrames[i+1]-subtitleFrames[i] < subduration*fps) // avoid two subtitles at the same time - { - endseconds = (subtitleFrames[i+1]-1)/fps; // frame x: subtitle1; frame x+1 subtitle2 - } else { - endseconds = seconds+subduration; - } - } else { - endseconds = seconds+subduration; - } - ms = modf(seconds, &seconds); - endms = modf(endseconds, &endseconds); - // this is just beyond ugly, don't show it to your kids - fprintf(srtfile, - "%02.0f:%02d:%02d,%03d --> %02.0f:%02d:%02d,%03d\n", // hh:mm:ss,ms --> hh:mm:ss,ms - floor(seconds/3600), (int)floor(seconds/60 ) % 60, (int)floor(seconds) % 60, (int)(ms*1000), - floor(endseconds/3600), (int)floor(endseconds/60) % 60, (int)floor(endseconds) % 60, (int)(endms*1000)); - fprintf(srtfile, "%s\n\n", subtitleMessages[i].c_str()); // new line for every subtitle - } - fclose(srtfile); - printf("%d subtitles have been ripped.\n", subtitleFrames.size()); - } else { - FCEUD_Message("Couldn't create output srt file...\n"); - } - - DriverKill(); - SDL_Quit(); - return 0; - } + // check for a .fm2 file to rip the subtitles + g_config->getOption("SDL.RipSubs", &s); + g_config->setOption("SDL.RipSubs", ""); + if (!s.empty()) + { + MovieData md; + std::string infname; + infname = s.c_str(); + FCEUFILE *fp = FCEU_fopen(s.c_str(), 0, "rb", 0); + + // load the movie and and subtitles + extern bool LoadFM2(MovieData&, std::istream*, int, bool); + LoadFM2(md, fp->stream, INT_MAX, false); + LoadSubtitles(md); // fill subtitleFrames and subtitleMessages + delete fp; + + // produce .srt file's name and open it for writing + std::string outname; + size_t dot = infname.find_last_of ("."); + if (dot == std::string::npos) + outname = infname + ".srt"; + else + outname = infname.substr(0,dot) + ".srt"; + FILE *srtfile; + srtfile = fopen(outname.c_str(), "w"); + + if (srtfile != NULL) + { + extern std::vector subtitleFrames; + extern std::vector subtitleMessages; + float fps = (md.palFlag == 0 ? 60.0988 : 50.0069); // NTSC vs PAL + float subduration = 3; // seconds for the subtitles to be displayed + for (int i = 0; i < subtitleFrames.size(); i++) + { + fprintf(srtfile, "%i\n", i+1); // starts with 1, not 0 + double seconds, ms, endseconds, endms; + seconds = subtitleFrames[i]/fps; + if (i+1 < subtitleFrames.size()) // there's another subtitle coming after this one + { + if (subtitleFrames[i+1]-subtitleFrames[i] < subduration*fps) // avoid two subtitles at the same time + { + endseconds = (subtitleFrames[i+1]-1)/fps; // frame x: subtitle1; frame x+1 subtitle2 + } else { + endseconds = seconds+subduration; + } + } else { + endseconds = seconds+subduration; + } + ms = modf(seconds, &seconds); + endms = modf(endseconds, &endseconds); + // this is just beyond ugly, don't show it to your kids + fprintf(srtfile, + "%02.0f:%02d:%02d,%03d --> %02.0f:%02d:%02d,%03d\n", // hh:mm:ss,ms --> hh:mm:ss,ms + floor(seconds/3600), (int)floor(seconds/60 ) % 60, (int)floor(seconds) % 60, (int)(ms*1000), + floor(endseconds/3600), (int)floor(endseconds/60) % 60, (int)floor(endseconds) % 60, (int)(endms*1000)); + fprintf(srtfile, "%s\n\n", subtitleMessages[i].c_str()); // new line for every subtitle + } + fclose(srtfile); + printf("%d subtitles have been ripped.\n", (int)subtitleFrames.size()); + } else { + FCEUD_Message("Couldn't create output srt file...\n"); + } + + DriverKill(); + SDL_Quit(); + return 0; + } - g_config->setOption("SDL.RipSubs", ""); - for(int i=0; igetOption("SDL.VideoLog", &s); + g_config->setOption("SDL.VideoLog", ""); + if(!s.empty()) + { + NESVideoSetVideoCmd(s.c_str()); + LoggingEnabled = 1; + g_config->getOption("SDL.MuteCapture", &mutecapture); + } else { + mutecapture = 0; + } + #endif - // update the emu core - UpdateEMUCore(g_config); - g_config->getOption("SDL.Frameskip", &frameskip); - - #ifdef CREATE_AVI - g_config->getOption("SDL.VideoLog", &s); - g_config->setOption("SDL.VideoLog", ""); - if(!s.empty()) - { - NESVideoSetVideoCmd(s.c_str()); - LoggingEnabled = 1; - g_config->getOption("SDL.MuteCapture", &mutecapture); - } else { - mutecapture = 0; - } - #endif - - { - int id; - g_config->getOption("SDL.InputDisplay", &id); - extern int input_display; - input_display = id; - g_config->getOption("SDL.SubtitleDisplay", &id); // not exactly an id as an true/false switch; still better than creating another int for that - extern int movieSubtitles; - movieSubtitles = id; - } + { + int id; + g_config->getOption("SDL.InputDisplay", &id); + extern int input_display; + input_display = id; + // not exactly an id as an true/false switch; still better than creating another int for that + g_config->getOption("SDL.SubtitleDisplay", &id); + extern int movieSubtitles; + movieSubtitles = id; + } // load the hotkeys from the config life setHotKeys(); + // GTK_LITE: gtk is linked for dialogs + // gtk needs to be started somewhere + // GTK: full gtk GUI. we're starting it here. #ifdef _GTK_LITE gtk_init(&argc, &argv); #endif @@ -745,7 +722,6 @@ SDL_GL_LoadLibrary(0); InitGTKSubsystem(argc, argv); #endif - if(romIndex >= 0) { // load the specified game @@ -756,83 +732,76 @@ SDL_GL_LoadLibrary(0); return -1; } } - - // movie playback - std::string fname; - g_config->getOption("SDL.Movie", &fname); - g_config->setOption("SDL.Movie", ""); - if (fname != "") - { - if(fname.find(".fm2") != std::string::npos) - { - static int pauseframe; - g_config->getOption("SDL.PauseFrame", &pauseframe); - g_config->setOption("SDL.PauseFrame", 0); - FCEUI_printf("Playing back movie located at %s\n", fname.c_str()); - FCEUI_LoadMovie(fname.c_str(), false, false, pauseframe ? pauseframe : false); - } - else - { - FCEUI_printf("Sorry, I don't know how to play back %s\n", fname.c_str()); - } - } - - #ifdef _S9XLUA_H - // load lua script if option passed - g_config->getOption("SDL.LuaScript", &fname); + // movie playback + g_config->getOption("SDL.Movie", &s); + g_config->setOption("SDL.Movie", ""); + if (s != "") + { + if(s.find(".fm2") != std::string::npos) + { + static int pauseframe; + g_config->getOption("SDL.PauseFrame", &pauseframe); + g_config->setOption("SDL.PauseFrame", 0); + FCEUI_printf("Playing back movie located at %s\n", s.c_str()); + FCEUI_LoadMovie(s.c_str(), false, false, pauseframe ? pauseframe : false); + } + else + { + FCEUI_printf("Sorry, I don't know how to play back %s\n", s.c_str()); + } + } + + +#ifdef _S9XLUA_H + // load lua script if option passed + g_config->getOption("SDL.LuaScript", &s); g_config->setOption("SDL.LuaScript", ""); - if (fname != "") - { - FCEU_LoadLuaCode(fname.c_str()); - } - #endif + if (s != "") + { + FCEU_LoadLuaCode(s.c_str()); + } +#endif { - int id; - g_config->getOption("SDL.NewPPU", &id); - if (id) - newppu = 1; + int id; + g_config->getOption("SDL.NewPPU", &id); + if (id) + newppu = 1; } - /*g_config->setOption("SDL.LuaScript", ""); - if (fname != "") - { - FCEU_LoadLuaCode(fname.c_str()); - }*/ - - // loop playing the game -#ifndef _GTK - while(GameInfo) { -#else - while(1) { - if(GameInfo) -#endif - DoFun(frameskip); + g_config->getOption("SDL.Frameskip", &frameskip); + // loop playing the game #ifdef _GTK - else - SDL_Delay(10); - while(gtk_events_pending()) - gtk_main_iteration_do(FALSE); + while(1) + { + if(GameInfo) +#else + while(GameInfo) #endif - } - CloseGame(); + DoFun(frameskip); +#ifdef _GTK + else + SDL_Delay(10); + while(gtk_events_pending()) + gtk_main_iteration_do(FALSE); +#endif + } + CloseGame(); - - // exit the infrastructure - FCEUI_Kill(); - SDL_Quit(); - return 0; + // exit the infrastructure + FCEUI_Kill(); + SDL_Quit(); + return 0; } - /** * Get the time in ticks. */ uint64 FCEUD_GetTime() { - return SDL_GetTicks(); + return SDL_GetTicks(); } /** @@ -841,8 +810,8 @@ FCEUD_GetTime() uint64 FCEUD_GetTimeFreq(void) { - // SDL_GetTicks() is in milliseconds - return 1000; + // SDL_GetTicks() is in milliseconds + return 1000; } /** @@ -886,7 +855,7 @@ bool FCEUI_AviIsRecording(void) {return false;} void FCEUI_UseInputPreset(int preset) { } bool FCEUD_PauseAfterPlayback() { return false; } // These are actually fine, but will be unused and overriden by the current UI code. -void FCEUD_TurboOn (void) { NoWaiting|= 1; } +void FCEUD_TurboOn (void) { NoWaiting|= 1; } void FCEUD_TurboOff (void) { NoWaiting&=~1; } void FCEUD_TurboToggle(void) { NoWaiting^= 1; } FCEUFILE* FCEUD_OpenArchiveIndex(ArchiveScanRecord& asr, std::string &fname, int innerIndex) { return 0; }