/** * Attempts to initialize the graphical video display. Returns 0 on * success, -1 on failure. */ int InitVideo(FCEUGI *gi) { // XXX soules - const? is this necessary? const SDL_VideoInfo *vinf; int error, flags = 0; int doublebuf, xstretch, ystretch, xres, yres, show_fps; FCEUI_printf("Initializing video..."); // load the relevant configuration variables g_config->getOption("SDL.Fullscreen", &s_fullscreen); g_config->getOption("SDL.DoubleBuffering", &doublebuf); #ifdef OPENGL g_config->getOption("SDL.OpenGL", &s_useOpenGL); #endif g_config->getOption("SDL.SpecialFilter", &s_sponge); g_config->getOption("SDL.XStretch", &xstretch); g_config->getOption("SDL.YStretch", &ystretch); g_config->getOption("SDL.LastXRes", &xres); g_config->getOption("SDL.LastYRes", &yres); g_config->getOption("SDL.ClipSides", &s_clipSides); g_config->getOption("SDL.NoFrame", &noframe); g_config->getOption("SDL.ShowFPS", &show_fps); // check the starting, ending, and total scan lines FCEUI_GetCurrentVidSystem(&s_srendline, &s_erendline); s_tlines = s_erendline - s_srendline + 1; // check if we should auto-set x/y resolution // check for OpenGL and set the global flags #if OPENGL if(s_useOpenGL && !s_sponge) { flags = SDL_OPENGL; } #endif // initialize the SDL video subsystem if it is not already active if(!SDL_WasInit(SDL_INIT_VIDEO)) { error = SDL_InitSubSystem(SDL_INIT_VIDEO); if(error) { FCEUD_PrintError(SDL_GetError()); return -1; } } s_inited = 1; // shows the cursor within the display window SDL_ShowCursor(1); // determine if we can allocate the display on the video card vinf = SDL_GetVideoInfo(); if(vinf->hw_available) { flags |= SDL_HWSURFACE; } // get the monitor's current resolution if we do not already have it if(s_nativeWidth < 0) { s_nativeWidth = vinf->current_w; } if(s_nativeHeight < 0) { s_nativeHeight = vinf->current_h; } // check to see if we are showing FPS FCEUI_SetShowFPS(show_fps); // check if we are rendering fullscreen if(s_fullscreen) { int no_cursor; g_config->getOption("SDL.NoFullscreenCursor", &no_cursor); flags |= SDL_FULLSCREEN; SDL_ShowCursor(!no_cursor); } else { SDL_ShowCursor(1); } if(noframe) { flags |= SDL_NOFRAME; } // gives the SDL exclusive palette control... ensures the requested colors // flags |= SDL_HWPALETTE; // enable double buffering if requested and we have hardware support #ifdef OPENGL if(s_useOpenGL) { FCEU_printf("Initializing with OpenGL (Disable with '--opengl 0').\n"); if(doublebuf) { SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); } } else #endif if(doublebuf && (flags & SDL_HWSURFACE)) { flags |= SDL_DOUBLEBUF; } if(s_fullscreen) { int desbpp, autoscale; g_config->getOption("SDL.BitsPerPixel", &desbpp); g_config->getOption("SDL.AutoScale", &autoscale); if (autoscale) { double auto_xscale = GetXScale(xres); double auto_yscale = GetYScale(yres); double native_ratio = ((double)NWIDTH) / s_tlines; double screen_ratio = ((double)xres) / yres; int keep_ratio; g_config->getOption("SDL.KeepRatio", &keep_ratio); // Try to choose resolution if (screen_ratio < native_ratio) { // The screen is narrower than the original. Maximizing width will not clip auto_xscale = auto_yscale = GetXScale(xres); if (keep_ratio) auto_yscale = GetYScale(yres); } else { auto_yscale = auto_xscale = GetYScale(yres); if (keep_ratio) auto_xscale = GetXScale(xres); } s_exs = auto_xscale; s_eys = auto_yscale; } else { g_config->getOption("SDL.XScale", &s_exs); g_config->getOption("SDL.YScale", &s_eys); } g_config->getOption("SDL.SpecialFX", &s_eefx); #ifdef OPENGL if(!s_useOpenGL) { s_exs = (int)s_exs; s_eys = (int)s_eys; } else { desbpp = 0; } // -Video Modes Tag- if(s_sponge) { if(s_sponge == 4 || s_sponge == 5) { s_exs = s_eys = 3; } else { s_exs = s_eys = 2; } s_eefx = 0; if(s_sponge == 1 || s_sponge == 4) { desbpp = 32; } } if((s_useOpenGL && !xstretch) || !s_useOpenGL) #endif if(xres < (NWIDTH * s_exs) || s_exs <= 0.01) { FCEUD_PrintError("xscale out of bounds."); KillVideo(); return -1; } #ifdef OPENGL if((s_useOpenGL && !ystretch) || !s_useOpenGL) #endif if(yres < s_tlines * s_eys || s_eys <= 0.01) { FCEUD_PrintError("yscale out of bounds."); KillVideo(); return -1; } #ifdef OPENGL s_screen = SDL_SetVideoMode(s_useOpenGL ? s_nativeWidth : xres, s_useOpenGL ? s_nativeHeight : yres, desbpp, flags); #else s_screen = SDL_SetVideoMode(xres, yres, desbpp, flags); #endif if(!s_screen) { FCEUD_PrintError(SDL_GetError()); return -1; } } else { int desbpp; g_config->getOption("SDL.BitsPerPixel", &desbpp); g_config->getOption("SDL.XScale", &s_exs); g_config->getOption("SDL.YScale", &s_eys); g_config->getOption("SDL.SpecialFX", &s_eefx); // -Video Modes Tag- if(s_sponge) { if(s_sponge >= 4) { s_exs = s_eys = 3; } else { s_exs = s_eys = 2; } s_eefx = 0; } #ifdef OPENGL if(!s_useOpenGL) { s_exs = (int)s_exs; s_eys = (int)s_eys; } if(s_exs <= 0.01) { FCEUD_PrintError("xscale out of bounds."); KillVideo(); return -1; } if(s_eys <= 0.01) { FCEUD_PrintError("yscale out of bounds."); KillVideo(); return -1; } if(s_sponge && s_useOpenGL) { FCEUD_PrintError("scalers not compatible with openGL mode."); KillVideo(); return -1; } #endif #if defined(_GTK) && defined(SDL_VIDEO_DRIVER_X11) if(noGui == 0) { while (gtk_events_pending()) gtk_main_iteration_do(FALSE); char SDL_windowhack[128]; sprintf(SDL_windowhack, "SDL_WINDOWID=%u", (unsigned int)GDK_WINDOW_XID(gtk_widget_get_window(evbox))); SDL_putenv(SDL_windowhack); // init SDL video if (SDL_WasInit(SDL_INIT_VIDEO)) SDL_QuitSubSystem(SDL_INIT_VIDEO); if ( SDL_InitSubSystem(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't init SDL video: %s\n", SDL_GetError()); gtk_main_quit(); } } #endif s_screen = SDL_SetVideoMode((int)(NWIDTH * s_exs), (int)(s_tlines * s_eys), desbpp, flags); if(!s_screen) { FCEUD_PrintError(SDL_GetError()); return -1; } #ifdef _GTK if(noGui == 0) { GtkRequisition req; gtk_widget_size_request(GTK_WIDGET(MainWindow), &req); gtk_window_resize(GTK_WINDOW(MainWindow), req.width, req.height); } #endif } s_curbpp = s_screen->format->BitsPerPixel; if(!s_screen) { FCEUD_PrintError(SDL_GetError()); KillVideo(); return -1; } #if 0 // XXX soules - this would be creating a surface on the video // card, but was commented out for some reason... s_BlitBuf = SDL_CreateRGBSurface(SDL_HWSURFACE, 256, 240, s_screen->format->BitsPerPixel, s_screen->format->Rmask, s_screen->format->Gmask, s_screen->format->Bmask, 0); #endif FCEU_printf(" Video Mode: %d x %d x %d bpp %s\n", s_screen->w, s_screen->h, s_screen->format->BitsPerPixel, s_fullscreen ? "full screen" : ""); if(s_curbpp != 8 && s_curbpp != 16 && s_curbpp != 24 && s_curbpp != 32) { FCEU_printf(" Sorry, %dbpp modes are not supported by FCE Ultra. Supported bit depths are 8bpp, 16bpp, and 32bpp.\n", s_curbpp); KillVideo(); return -1; } // if the game being run has a name, set it as the window name if(gi) { if(gi->name) { SDL_WM_SetCaption((const char *)gi->name, (const char *)gi->name); } else { SDL_WM_SetCaption(FCEU_NAME_AND_VERSION,"FCE Ultra"); } } // create the surface for displaying graphical messages #ifdef LSB_FIRST s_IconSurface = SDL_CreateRGBSurfaceFrom((void *)fceu_playicon.pixel_data, 32, 32, 24, 32 * 3, 0xFF, 0xFF00, 0xFF0000, 0x00); #else s_IconSurface = SDL_CreateRGBSurfaceFrom((void *)fceu_playicon.pixel_data, 32, 32, 24, 32 * 3, 0xFF0000, 0xFF00, 0xFF, 0x00); #endif SDL_WM_SetIcon(s_IconSurface,0); s_paletterefresh = 1; // XXX soules - can't SDL do this for us? // if using more than 8bpp, initialize the conversion routines if(s_curbpp > 8) { InitBlitToHigh(s_curbpp >> 3, s_screen->format->Rmask, s_screen->format->Gmask, s_screen->format->Bmask, s_eefx, s_sponge, 0); #ifdef OPENGL if(s_useOpenGL) { int openGLip; g_config->getOption("SDL.OpenGLip", &openGLip); if(!InitOpenGL(NOFFSET, 256 - (s_clipSides ? 8 : 0), s_srendline, s_erendline + 1, s_exs, s_eys, s_eefx, openGLip, xstretch, ystretch, s_screen)) { FCEUD_PrintError("Error initializing OpenGL."); KillVideo(); return -1; } } #endif }
int InitVideo(FCEUGI *gi) { // This is a big TODO. Stubbing this off into its own function, // as the SDL surface routines have changed drastically in SDL2 // TODO - SDL2 const char * window_name; int error, flags = 0; int doublebuf, xstretch, ystretch, xres, yres, show_fps; uint32_t Amask, Rmask, Gmask, Bmask; int bpp; FCEUI_printf("Initializing video (SDL2.x) ..."); // load the relevant configuration variables g_config->getOption("SDL.Fullscreen", &s_fullscreen); g_config->getOption("SDL.DoubleBuffering", &doublebuf); #ifdef OPENGL g_config->getOption("SDL.OpenGL", &s_useOpenGL); #endif g_config->getOption("SDL.SpecialFilter", &s_sponge); g_config->getOption("SDL.XStretch", &xstretch); g_config->getOption("SDL.YStretch", &ystretch); g_config->getOption("SDL.LastXRes", &xres); g_config->getOption("SDL.LastYRes", &yres); g_config->getOption("SDL.ClipSides", &s_clipSides); g_config->getOption("SDL.NoFrame", &noframe); g_config->getOption("SDL.ShowFPS", &show_fps); // check the starting, ending, and total scan lines FCEUI_GetCurrentVidSystem(&s_srendline, &s_erendline); s_tlines = s_erendline - s_srendline + 1; #if OPENGL if( !s_useOpenGL || s_sponge ) { FCEUD_PrintError("SDL2 Does not support non-OpenGL rendering or special filters\n"); KillVideo(); return -1; } #endif // initialize the SDL video subsystem if it is not already active if(!SDL_WasInit(SDL_INIT_VIDEO)) { error = SDL_InitSubSystem(SDL_INIT_VIDEO); if(error) { FCEUD_PrintError(SDL_GetError()); return -1; } } s_inited = 1; // For simplicity, hard-code this to 32bpp for now... s_curbpp = 32; // If game is running, set window name accordingly if( gi ) { window_name = (const char *) gi->name; } else { window_name = "FCE Ultra"; } s_exs = 1.0; s_eys = 1.0; if(s_fullscreen) { s_window = SDL_CreateWindow( window_name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 0, 0, // Res not specified in full-screen mode SDL_WINDOW_FULLSCREEN_DESKTOP); } else { #if defined(_GTK) && defined(SDL_VIDEO_DRIVER_X11) if(noGui == 0 && strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) { s_window = SDL_CreateWindowFrom((void*)GDK_WINDOW_XID (gtk_widget_get_window(evbox))); } else #endif s_window = SDL_CreateWindow( window_name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, xres, yres, 0); } // This stuff all applies regardless of full-screen vs windowed mode. s_renderer = SDL_CreateRenderer(s_window, -1, 0); // Set logical rendering size & specify scaling mode. All rendering is // now done to the renderer rather than directly to the screen surface. // The renderer takes care of any scaling necessary. // // NOTE: setting scale quality to "nearest" will result in a blown-up but // pixelated while "linear" will tend to blur everything. SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest"); SDL_RenderSetLogicalSize(s_renderer, xres, yres); // // Create the texture that will ultimately be rendered. // s_screen is used to build up an image, then the texture will be updated // all at once when it's ready s_texture = SDL_CreateTexture(s_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, xres, yres); // // Create a surface to draw pixels onto // SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_ARGB8888, &bpp, &Rmask, &Gmask, &Bmask, &Amask); s_screen = SDL_CreateRGBSurface(0, xres, yres, bpp, Rmask, Gmask, Bmask, Amask); if( !s_screen ) { FCEUD_PrintError(SDL_GetError()); return -1; } // // Setup Icon surface // #ifdef LSB_FIRST s_IconSurface = SDL_CreateRGBSurfaceFrom((void *)fceu_playicon.pixel_data, 32, 32, 24, 32 * 3, 0xFF, 0xFF00, 0xFF0000, 0x00); #else s_IconSurface = SDL_CreateRGBSurfaceFrom((void *)fceu_playicon.pixel_data, 32, 32, 24, 32 * 3, 0xFF0000, 0xFF00, 0xFF, 0x00); #endif SDL_SetWindowIcon(s_window, s_IconSurface); s_paletterefresh = 1; // Force palette refresh // always init blit to high since bpp forced to 32 for now. InitBlitToHigh(s_curbpp >> 3, s_screen->format->Rmask, s_screen->format->Gmask, s_screen->format->Bmask, 0, //s_eefx, Hard-code SFX off 0, //s_sponge, Hard-code special filters off. 0); return 0; }
/** * Initialize the audio subsystem. */ int InitSound() { int sound, soundrate, soundbufsize, soundvolume, soundtrianglevolume, soundsquare1volume, soundsquare2volume, soundnoisevolume, soundpcmvolume, soundq, lowpass, samples; FCEUI_printf("Initializing audio...\n"); g_config->getOption("SDL.Sound", &sound); if (!sound) return 0; memset(&spec, 0, sizeof(spec)); if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { puts(SDL_GetError()); KillSound(); return(0); } char driverName[8]; SDL_AudioDriverName(driverName, 8); fprintf(stderr, "Loading SDL sound with %s driver...\n", driverName); // load configuration variables g_config->getOption("SDL.Sound.Rate", &soundrate); g_config->getOption("SDL.Sound.BufSize", &soundbufsize); g_config->getOption("SDL.Sound.Volume", &soundvolume); g_config->getOption("SDL.Sound.Quality", &soundq); g_config->getOption("SDL.Sound.TriangleVolume", &soundtrianglevolume); g_config->getOption("SDL.Sound.Square1Volume", &soundsquare1volume); g_config->getOption("SDL.Sound.Square2Volume", &soundsquare2volume); g_config->getOption("SDL.Sound.NoiseVolume", &soundnoisevolume); g_config->getOption("SDL.Sound.PCMVolume", &soundpcmvolume); g_config->getOption("SDL.Sound.LowPass", &lowpass); spec.freq = soundrate; spec.format = AUDIO_S16; spec.channels = 2; spec.samples = 512; spec.callback = fillaudio; spec.userdata = 0; while(spec.samples < (soundrate / 60) * 1) spec.samples <<= 1; s_BufferSize = spec.samples * 4; s_Buffer = (int16 *) malloc(sizeof(int16) * s_BufferSize); if (!s_Buffer) return 0; s_BufferRead = s_BufferWrite = s_BufferIn = 0; printf("SDL Size: %d, Internal size: %d\n", spec.samples, s_BufferSize); if(SDL_OpenAudio(&spec, 0) < 0) { puts(SDL_GetError()); KillSound(); return(0); } SDL_PauseAudio(0); FCEUI_SetSoundVolume(soundvolume); FCEUI_SetSoundQuality(soundq); FCEUI_Sound(soundrate); FCEUI_SetTriangleVolume(soundtrianglevolume); FCEUI_SetSquare1Volume(soundsquare1volume); FCEUI_SetSquare2Volume(soundsquare2volume); FCEUI_SetNoiseVolume(soundnoisevolume); FCEUI_SetPCMVolume(soundpcmvolume); FCEUI_SetLowPass(lowpass); return (1); }
/** * The main loop for the SDL. */ int main(int argc, char *argv[]) { // this is a hackish check for the --help arguemnts // these are normally processed by the config parser, but SDL_Init // must be run before the config parser: so if even SDL_Init fails, // these six lines will still print the help output if(argc > 1) { if(!strcmp(argv[1], "--help") || !strcmp(argv[1],"-h")) { ShowUsage(argv[0]); return 0; } } int error, frameskip; FCEUD_Message("Starting " FCEU_NAME_AND_VERSION "...\n"); #ifdef WIN32 /* 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); } #ifdef OPENGL SDL_GL_LoadLibrary(0); #endif // Initialize the configuration system g_config = InitConfig(); if(!g_config) { SDL_Quit(); return -1; } // initialize the infrastructure error = FCEUI_Initialize(); if(error != 1) { ShowUsage(argv[0]); SDL_Quit(); return -1; } // check for --help or -h and display usage; also check for --nogui for(int i=0; i<argc;i++) { if(strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) { ShowUsage(argv[0]); SDL_Quit(); return 0; } #ifdef _GTK else if(strcmp(argv[i], "--nogui") == 0) { noGui = 1; argv[i] = ""; } #endif } int romIndex = g_config->parse(argc, argv); // 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); if(s.size() != 0) { InitVideo(GameInfo); InputCfg(s); } // set the FAMICOM PAD 2 Mic thing { int t; g_config->getOption("SDL.Input.FamicomPad2.EnableMic", &t); if(t) replaceP2StartWithMicrophone = t; } // update the input devices 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); if (result == FCM_CONVERTRESULT_SUCCESS) { okcount++; // *outf = new EMUFILE; EMUFILE_FILE* 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; } // If x/y res set to 0, store current display res in SDL.LastX/YRes int yres, xres; g_config->getOption("SDL.XResolution", &xres); g_config->getOption("SDL.YResolution", &yres); #if SDL_VERSION_ATLEAST(2, 0, 0) // TODO _ SDL 2.0 #else const SDL_VideoInfo* vid_info = SDL_GetVideoInfo(); if(xres == 0) { if(vid_info != NULL) { g_config->setOption("SDL.LastXRes", vid_info->current_w); } else { g_config->setOption("SDL.LastXRes", 512); } } else { g_config->setOption("SDL.LastXRes", xres); } if(yres == 0) { if(vid_info != NULL) { g_config->setOption("SDL.LastYRes", vid_info->current_h); } else { g_config->setOption("SDL.LastYRes", 448); } } else { g_config->setOption("SDL.LastYRes", yres); } #endif int autoResume; g_config->getOption("SDL.AutoResume", &autoResume); if(autoResume) { AutoResumePlay = true; } else { AutoResumePlay = false; } // check to see if recording HUD to AVI is enabled int rh; g_config->getOption("SDL.RecordHUD", &rh); if( rh == 0) FCEUI_SetAviEnableHUDrecording(true); else FCEUI_SetAviEnableHUDrecording(false); // 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&, EMUFILE*, 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<int> subtitleFrames; extern std::vector<std::string> 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; } // if we're not compiling w/ the gui, exit if a rom isn't specified #ifndef _GTK if(romIndex <= 0) { ShowUsage(argv[0]); FCEUD_Message("\nError parsing command line arguments\n"); SDL_Quit(); return -1; } #endif // update the emu core UpdateEMUCore(g_config); #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; // 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(); #ifdef _GTK if(noGui == 0) { gtk_init(&argc, &argv); InitGTKSubsystem(argc, argv); while(gtk_events_pending()) gtk_main_iteration_do(FALSE); } #endif if(romIndex >= 0) { // load the specified game error = LoadGame(argv[romIndex]); if(error != 1) { DriverKill(); SDL_Quit(); return -1; } g_config->setOption("SDL.LastOpenFile", argv[romIndex]); g_config->save(); } // movie playback g_config->getOption("SDL.Movie", &s); g_config->setOption("SDL.Movie", ""); if (s != "") { if(s.find(".fm2") != std::string::npos || s.find(".fm3") != 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, pauseframe ? pauseframe : false); } else { FCEUI_printf("Sorry, I don't know how to play back %s\n", s.c_str()); } } int periodic_saves; int save_state; g_config->getOption("SDL.PeriodicSaves", &periodic_saves); g_config->getOption("SDL.AutoSaveState", &save_state); if(periodic_saves && save_state < 10 && save_state >= 0){ FCEUI_SelectState(save_state, 0); } else { periodic_saves = 0; } #ifdef _S9XLUA_H // load lua script if option passed g_config->getOption("SDL.LuaScript", &s); g_config->setOption("SDL.LuaScript", ""); if (s != "") { FCEU_LoadLuaCode(s.c_str()); } #endif { int id; g_config->getOption("SDL.NewPPU", &id); if (id) newppu = 1; } g_config->getOption("SDL.Frameskip", &frameskip); // loop playing the game #ifdef _GTK if(noGui == 0) { while(1) { if(GameInfo) DoFun(frameskip, periodic_saves); else SDL_Delay(1); while(gtk_events_pending()) gtk_main_iteration_do(FALSE); } } else { while(GameInfo) DoFun(frameskip, periodic_saves); } #else while(GameInfo) { DoFun(frameskip, periodic_saves); } #endif CloseGame(); // exit the infrastructure FCEUI_Kill(); SDL_Quit(); return 0; }