Esempio n. 1
0
/**
 * Closes a game.  Frees memory, and deinitializes the drivers.
 */
int
CloseGame()
{
	std::string filename;

	if(!isloaded) {
		return(0);
	}

    int state_to_save;
    g_config->getOption("SDL.AutoSaveState", &state_to_save);
    if (state_to_save < 10 && state_to_save >= 0){
        FCEUI_SelectState(state_to_save, 0);
        FCEUI_SaveState(NULL, false);
    }
	FCEUI_CloseGame();

	DriverKill();
	isloaded = 0;
	GameInfo = 0;

	g_config->getOption("SDL.Sound.RecordFile", &filename);
	if(filename.size()) {
		FCEUI_EndWaveRecord();
	}

	InputUserActiveFix();
	return(1);
}
Esempio n. 2
0
/**
 * Loads a game, given a full path/filename.  The driver code must be
 * initialized after the game is loaded, because the emulator code
 * provides data necessary for the driver code(number of scanlines to
 * render, what virtual input devices to use, etc.).
 */
int LoadGame(const char *path)
{
    if (isloaded){
        CloseGame();
    }
	if(!FCEUI_LoadGame(path, 1)) {
		return 0;
	}

    int state_to_load;
    g_config->getOption("SDL.AutoLoadState", &state_to_load);
    if (state_to_load >= 0 && state_to_load < 10){
        FCEUI_SelectState(state_to_load, 0);
        FCEUI_LoadState(NULL, false);
    }

	ParseGIInput(GameInfo);
	RefreshThrottleFPS();

	if(!DriverInitialize(GameInfo)) {
		return(0);
	}
	
	// set pal/ntsc
	int id;
	g_config->getOption("SDL.PAL", &id);
	switch(id)
	{
		case 0:
			FCEUI_SetVidSystem(0);
			pal_emulation = 0;
			dendy = 0;
			break;
		case 1:
			FCEUI_SetVidSystem(1);
			pal_emulation = 1;
			dendy = 0;
			break;
		case 2:
			FCEUI_SetVidSystem(0);
			pal_emulation = 0;
			dendy = 1;
	}
	
	std::string filename;
	g_config->getOption("SDL.Sound.RecordFile", &filename);
	if(filename.size()) {
		if(!FCEUI_BeginWaveRecord(filename.c_str())) {
			g_config->setOption("SDL.Sound.RecordFile", "");
		}
	}
	isloaded = 1;

	FCEUD_NetworkConnect();
	return 1;
}
Esempio n. 3
0
void Ingame_Menu(void)
{
    char *temp;
    int i,selection = 0;
    oldselect = -1;
    char stateoption[16];
    strcpy(stateoption,"State number: ");

    int option_changed = 0;

    int menu_x1 = gsGlobal->Width*0.25;
    int menu_y1 = gsGlobal->Height*0.15;
    int menu_x2 = gsGlobal->Width*0.75;
    int menu_y2 = gsGlobal->Height*0.85+FONT_HEIGHT;

    int text_line = menu_y1 + 4;

    char options[14][23] = {
        { "State number: " },
        { "Save State" },
        { "Load State" },
        { "Filtering: "},
        { "LowPass: "******"Configure Input" },
        { "Rapidfire Switch: "},
        { "RapidFire P1: " },
        { "RapidFire P2: " },
        { "Reset Game" },
        { "Exit Game" },
        { "Exit Menu" },
        { "Palette:" },
        { "" }
    };

    for(i=0;i<14;i++) {
        switch(i) {
            case 0:
                sprintf(options[i],"%s%d",options[i],statenum);
                break;
            case 3:
                if(!Settings.filter)
                    sprintf(options[i],"%s%s",options[i],"Off");
                else
                    sprintf(options[i],"%s%s",options[i],"On");
                break;
            case 4:
                if(!Settings.lowpass)
                    sprintf(options[i],"%s%s",options[i],"Off");
                else
                    sprintf(options[i],"%s%s",options[i],"On");
                break;
            case 6:
                if(!Settings.turbo) {
                    sprintf(options[i],"%s%s",options[i],"Off");
                }
                else {
                    sprintf(options[i],"%s%s",options[i],"On");
                }
                break;
            case 7:
                switch(aorborab[0]) {
                    case 0:
                        sprintf(options[i],"%s%s",options[i],"Off");
                        break;
                    case 1:
                        sprintf(options[i],"%s%s",options[i],"A");
                        break;
                    case 2:
                        sprintf(options[i],"%s%s",options[i],"B");
                        break;
                    case 3:
                        sprintf(options[i],"%s%s",options[i],"AB");
                        break;
                }
                break;
            case 8:
                switch(aorborab[1]) {
                    case 0:
                        sprintf(options[i],"%s%s",options[i],"Off");
                        break;
                    case 1:
                        sprintf(options[i],"%s%s",options[i],"A");
                        break;
                    case 2:
                        sprintf(options[i],"%s%s",options[i],"B");
                        break;
                    case 3:
                        sprintf(options[i],"%s%s",options[i],"AB");
                        break;
                }
				break;
            case 13:
				sprintf(options[i],"%s%s",options[i],palette_names[Settings.current_palette - 1].name);
                break;
        }
    }

#ifdef SOUND_ON
    audsrv_stop_audio();
#endif
    gsKit_mode_switch(gsGlobal, GS_ONESHOT);
    gsGlobal->DrawOrder = GS_PER_OS;

    while(1) {
        selected = 0; //clear selected flag
        selection += menu_input(0,0);

		if(selection == 12 && oldselect == 11) { selection++; } //12 is palette
        if(selection == 12 && oldselect == 13) { selection--; }
        if(selection > 13) { selection = 0; }
        if(selection < 0) { selection = 13; }

        if(oldselect != selection || option_changed) {
            i = 0x10000;
            while(i--) asm("nop\nnop\nnop\nnop");
            gsKit_queue_reset(gsGlobal->Os_Queue);

            option_changed = 0;

            menu_primitive("Options", &MENU_TEX, menu_x1, menu_y1, menu_x2, menu_y2);

            for(i=0;i<14;i++) {
                if(selection == i) {
                    //font_print(gsGlobal, menu_x1+10.0f, text_line + i*FONT_HEIGHT, 2, DarkYellowFont, options[i]);
                    printXY(options[i],menu_x1+10,text_line + i*FONT_HEIGHT, 4, FCEUSkin.highlight, 1, 0);
                }
                else {
                    //font_print(gsGlobal, menu_x1+10.0f, text_line + i*FONT_HEIGHT, 2, WhiteFont, options[i]);
                    printXY(options[i],menu_x1+10,text_line + i*FONT_HEIGHT, 4, FCEUSkin.textcolor, 1, 0);
                }
            }

            DrawScreen(gsGlobal);
        }

        oldselect = selection;

        if(selected) {
            if(selected == 2) { //menu combo pressed again
                selection = 11;
            }
            i = selection;
            switch(i) {
                case 0: //State Number
                    statenum++;
                    if(statenum > 9) {statenum = 0;}
                    sprintf(options[i],"%s%d",stateoption,statenum);
                    FCEUI_SelectState(statenum);
                    option_changed = 1;
                    break;
                case 1:
                    FCEUI_SaveState(NULL);
                    SetupNESGS();
                    return;
                case 2:
                    FCEUI_LoadState(NULL);
                    SetupNESGS();
                    return;
                case 3:
                    Settings.filter ^= 1;
                    if(Settings.filter) {
                        temp = strstr(options[i],"Off");
                        *temp = 0;
                        strcat(options[i],"On");
                    }
                    else {
                        temp = strstr(options[i],"On");
                        *temp = 0;
                        strcat(options[i],"Off");
                    }
                    option_changed = 1;
                    break;
                case 4:
                    Settings.lowpass ^= 1;
                    if(Settings.lowpass) {
                        FCEUI_SetLowPass(Settings.lowpass);
                        temp = strstr(options[i],"Off");
                        *temp = 0;
                        strcat(options[i],"On");
                    }
                    else {
                        FCEUI_SetLowPass(Settings.lowpass);
                        temp = strstr(options[i],"On");
                        *temp = 0;
                        strcat(options[i],"Off");
                    }
                    option_changed = 1;
                    break;
                case 6:
                    Settings.turbo ^= 1;
                    if(Settings.turbo) {
                        temp = strstr(options[i],"Off");
                        *temp = 0;
                        strcat(options[i],"On");
                    }
                    else {
                        temp = strstr(options[i],"On");
                        *temp = 0;
                        strcat(options[i],"Off");
                    }
                    option_changed = 1;
                    break;
                case 7:
                    aorborab[0]++;
                    if(aorborab[0] > 3)
                        aorborab[0] = 0;
                    switch(aorborab[0]) {
                        case 0: //Off
                            rapidfire_a[0] = 0;
                            rapidfire_b[0] = 0;
                            temp = strstr(options[i],"AB");
                            *temp = 0;
                            strcat(options[i],"Off");
                            break;
                        case 1: //A
                            rapidfire_a[0] = 1;
                            rapidfire_b[0] = 0;
                            temp = strstr(options[i],"Off");
                            *temp = 0;
                            strcat(options[i],"A");
                            break;
                        case 2: //B
                            rapidfire_a[0] = 0;
                            rapidfire_b[0] = 1;
                            temp = strstr(options[i]," A");
                            *temp = 0;
                            strcat(options[i]," B");
                            break;
                        case 3: //AB
                            rapidfire_a[0] = 1;
                            rapidfire_b[0] = 1;
                            temp = strstr(options[i]," B");
                            *temp = 0;
                            strcat(options[i]," AB");
                            break;
                    }
                    option_changed = 1;
                    break;
                case 8:
                    aorborab[1]++;
                    if(aorborab[1] > 3)
                        aorborab[1] = 0;
                    switch(aorborab[1]) {
                        case 0: //Off
                            rapidfire_a[1] = 0;
                            rapidfire_b[1] = 0;
                            temp = strstr(options[i],"AB");
                            *temp = 0;
                            strcat(options[i],"Off");
                            break;
                        case 1: //A
                            rapidfire_a[1] = 1;
                            rapidfire_b[1] = 0;
                            temp = strstr(options[i],"Off");
                            *temp = 0;
                            strcat(options[i],"A");
                            break;
                        case 2: //B
                            rapidfire_a[1] = 0;
                            rapidfire_b[1] = 1;
                            temp = strstr(options[i]," A");
                            *temp = 0;
                            strcat(options[i]," B");
                            break;
                        case 3: //AB
                            rapidfire_a[1] = 1;
                            rapidfire_b[1] = 1;
                            temp = strstr(options[i]," B");
                            *temp = 0;
                            strcat(options[i]," AB");
                            break;
                    }
                    option_changed = 1;
                    break;
                case 9:
                    FCEUI_ResetNES();
                    SetupNESGS();
                    return;
                case 10:
                    fdsswap = 0;
                    statenum = 0;
                    exitgame = 1;
                    selected = 0;
                    return;
                case 11:
                    SetupNESGS();
                    return;
                case 13:
                    Settings.current_palette++;
                    if(Settings.current_palette > MAXPAL) {Settings.current_palette = 1;}
					sprintf(options[i],"%s",palette_names[Settings.current_palette - 1].name);
					SetupNESTexture();
					option_changed = 1;
                    break;
            }
        }
    }
}
void Emulator_IncrementCurrentSaveStateSlot()
{
	current_state_save = (current_state_save+1) % 9;
	FCEUI_SelectState(current_state_save, true);
}
void Emulator_DecrementCurrentSaveStateSlot()
{
	current_state_save = (current_state_save-1);
	if (current_state_save < 0) current_state_save = 9;
	FCEUI_SelectState(current_state_save, true);
}
Esempio n. 6
0
void FCEUGUI_Run() {
	static int index = 0;
	static int spy = 72;
	int done = 0, y, i;

	load_preview();

	g_dirty = 1;
	while (!done) {

		// Parse input
		readkey();
		if (parsekey(DINGOO_B))
			done = 1;

		if (parsekey(DINGOO_UP, 1)) {
			if (index > 0) {
				index--;
				spy -= 16;
			} else {
				index = 7;
				spy = 72 + 16*index;
			}
		}

		if (parsekey(DINGOO_DOWN, 1)) {
			if (index < 7) {
				index++;
				spy += 16;
			} else {
				index = 0;
				spy = 72;
			}
		}

		if (parsekey(DINGOO_A)) {
			done = main_menu[index].command();
			if(index == 3) load_preview();
		}

		if (index == 3 || index == 4) {
			if (parsekey(DINGOO_RIGHT, 1)) {
				if (g_slot < 9) {
					g_slot++;
					FCEUI_SelectState(g_slot, 0);
					load_preview();
				}
			}

			if (parsekey(DINGOO_LEFT, 1)) {
				if (g_slot > 0) {
					g_slot--;
					FCEUI_SelectState(g_slot, 0);
					load_preview();
				}
			}
		}

		// Must draw bg only when needed
		// Draw stuff
		if (g_dirty) {
			draw_bg(g_bg);
			
			//Draw Top and Bottom Bars
			DrawChar(gui_screen, SP_SELECTOR, 0, 37);
			DrawChar(gui_screen, SP_SELECTOR, 81, 37);
			DrawChar(gui_screen, SP_SELECTOR, 0, 225);
			DrawChar(gui_screen, SP_SELECTOR, 81, 225);
			DrawText(gui_screen, "B - Go Back", 235, 225);
			DrawChar(gui_screen, SP_LOGO, 12, 9);
			
			// Draw selector
			DrawChar(gui_screen, SP_SELECTOR, 56, spy);
			DrawChar(gui_screen, SP_SELECTOR, 77, spy);

			if (index == 3 || index == 4) {
				// Draw state preview
				DrawChar(gui_screen, SP_PREVIEWBLOCK, 184, 73);
				draw_preview((unsigned short *)gui_screen->pixels, 185, 100);
				if (!g_ispreview)
					DrawChar(gui_screen, SP_NOPREVIEW, 207, 135);
			}

			if (index == 5) {
				DrawChar(gui_screen, SP_PREVIEWBLOCK, 184, 73);
				draw_shot_preview((unsigned short *)gui_screen->pixels, 185, 100);
			}

			DrawText(gui_screen, "Now Playing:", 8, 37);
			DrawText(gui_screen, g_romname, 96, 37);

			// Draw menu
			for (i = 0, y = 72; i < 8; i++, y += 16) {
				DrawText(gui_screen, main_menu[i].name, 60, y);
			}

			// Draw info
			DrawText(gui_screen, main_menu[index].info, 8, 225);

			// If save/load state render slot preview and number
			if (index == 3 || index == 4) {
				char tmp[32];
				sprintf(tmp, "Slot %d", g_slot);
				DrawText(gui_screen, tmp, 212, 80);

				if (g_slot > 0)
					DrawChar(gui_screen, SP_LEFTARROW, 197, 83);
				if (g_slot < 9)
					DrawChar(gui_screen, SP_RIGHTARROW, 259, 83);
			}

			// If screenshot render current frame preview
			if (index == 5) {
				DrawText(gui_screen, "Preview", 207, 80);
			}

			g_dirty = 0;
		}

		SDL_Delay(16);

		// Update real screen
		FCEUGUI_Flip();
	}

	g_psdl = FCEUD_GetPaletteArray16();

	// Clear screen
	dingoo_clear_video();
}
Esempio n. 7
0
/**
 * 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;
}