Пример #1
0
int
main (int argc, char *argv[])
{
    struct sigaction sig_callback;

    g_thread_init (NULL);
    gdk_threads_init ();

    gtk_init (&argc, &argv);

    bindtextdomain (GETTEXT_PACKAGE, SNES9XLOCALEDIR);
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
    textdomain (GETTEXT_PACKAGE);

    ZeroMemory (&Settings, sizeof (Settings));

    /* Allow original config file for backend settings */
    S9xLoadConfigFiles (argv, argc);

    /* Perform our config here */
    gui_config = new Snes9xConfig ();

    S9xInitInputDevices ();

    gui_config->load_config_file ();

    char *rom_filename = S9xParseArgs (argv, argc);

    S9xReportControllers ();

    if (!Memory.Init () || !S9xInitAPU ())
        exit (3);

    g_set_application_name ("Snes9x");

    top_level = new Snes9xWindow (gui_config);

    /* If we're going to fullscreen, do it before showing window to avoid flicker. */
    if ((gui_config->full_screen_on_open && rom_filename) || (gui_config->fullscreen))
        gtk_window_fullscreen (top_level->get_window ());

    top_level->show ();

    S9xInitDisplay (argc, argv);

    Memory.PostRomInitFunc = S9xPostRomInit;

    S9xPortSoundInit ();

    gui_config->reconfigure ();
    top_level->update_accels ();

    Settings.Paused = TRUE;
    syncing = 0;
    idle_func_id = g_idle_add_full (IDLE_FUNC_PRIORITY,
                                    S9xIdleFunc,
                                    NULL,
                                    NULL);

    g_timeout_add (10000, S9xScreenSaverCheckFunc, NULL);

    S9xNoROMLoaded ();

    if (rom_filename)
    {
        if (S9xOpenROM (rom_filename) && gui_config->full_screen_on_open)
            gtk_window_unfullscreen (top_level->get_window());
    }

    memset (&sig_callback, 0, sizeof (struct sigaction));
    sig_callback.sa_handler = S9xTerm;

    sigaction (15 /* SIGTERM */, &sig_callback, NULL);
    sigaction (3  /* SIGQUIT */, &sig_callback, NULL);
    sigaction (2  /* SIGINT  */, &sig_callback, NULL);

    if (gui_config->fullscreen)
    {
        gui_config->fullscreen = 0;
        needs_fullscreening = 1;
    }

#ifdef USE_JOYSTICK
    gui_config->flush_joysticks ();
#endif

    gtk_window_present (top_level->get_window ());

    gdk_threads_lock ();

    gtk_main ();

    return 0;
}
Пример #2
0
char* menu_romselector()
{
	char *rom_filename = NULL;
	int romcount = 0;

	bool8_32 exit_loop = false;

	uint8 *keyssnes = 0;


	//Read ROM-Directory
	romcount = FileDir("./roms", "sfc,smc");

	Scale_org = Scale;
	highres_current=Settings.SupportHiRes;

	Scale = false;
	Settings.SupportHiRes=FALSE;
	S9xDeinitDisplay();
	S9xInitDisplay(0, 0);
	
	loadmenu_dispupdate(romcount);
	sys_sleep(100000);

	SDL_Event event;

	do
	{
		loadmenu_dispupdate(romcount);
		sys_sleep(100);

		while(SDL_PollEvent(&event)==1)
		{
			//PANDORA & DINGOO & WIN32 -----------------------------------------------------
			keyssnes = SDL_GetKeyState(NULL);
			switch(event.type)
			{
				case SDL_KEYDOWN:
					keyssnes = SDL_GetKeyState(NULL);

					//UP
					if(keyssnes[sfc_key[UP_1]] == SDL_PRESSED)
						loadcursor--;
					//DOWN
					else if(keyssnes[sfc_key[DOWN_1]] == SDL_PRESSED)
						loadcursor++;
//					//LS
//					else if(keyssnes[sfc_key[L_1]] == SDL_PRESSED)
//						loadcursor=loadcursor-10;
//					//RS
//					else if(keyssnes[sfc_key[R_1]] == SDL_PRESSED)
//						loadcursor=loadcursor+10;
					//QUIT Emulator : press ESCAPE KEY
					else if (keyssnes[sfc_key[SELECT_1]] == SDL_PRESSED)
						S9xExit();
					else if( (keyssnes[sfc_key[B_1]] == SDL_PRESSED) )
					{
						switch(loadcursor)
						{
							default:
								if ((keyssnes[sfc_key[B_1]] == SDL_PRESSED))
								{
									if ((loadcursor>=0) && (loadcursor<(romcount)))
									{
										rom_filename=namelist[loadcursor]->d_name;
										exit_loop = TRUE;
									}
								}
								break;
						}
					}
					break;
			}

			if(loadcursor==-1)
			{
				loadcursor=romcount-1;
			}
			else
			if(loadcursor==romcount)
			{
				loadcursor=0;
			}

			break;
		}
	}
	while( exit_loop!=TRUE && keyssnes[sfc_key[B_1]] != SDL_PRESSED );

	// TODO:
	///free(). 	namelist

	Scale = Scale_org;
	Settings.SupportHiRes=highres_current;
	S9xDeinitDisplay();
	S9xInitDisplay(0, 0);

	return (rom_filename);
}
Пример #3
0
void menu_loop(void)
{
	bool8_32 exit_loop = false;
	char fname[256], ext[8];
	char snapscreen_tmp[17120];

	uint8 *keyssnes = 0;

	SaveSlotNum_old = -1;

	Scale_org = Scale;
	highres_current=Settings.SupportHiRes;

	capt_screenshot();
	memcpy(snapscreen_tmp,snapscreen,17120);

	Scale = false;
	Settings.SupportHiRes=FALSE;
	S9xDeinitDisplay();
	S9xInitDisplay(0, 0);

	menu_dispupdate();
	sys_sleep(100000);

	SDL_Event event;

	do
	{
		while(SDL_PollEvent(&event)==1)
		{

				//PANDORA & DINGOO & WIN32 -----------------------------------------------------
				keyssnes = SDL_GetKeyState(NULL);

				if(keyssnes[sfc_key[UP_1]] == SDL_PRESSED)
					cursor--;
				else if(keyssnes[sfc_key[DOWN_1]] == SDL_PRESSED)
					cursor++;
				else if( (keyssnes[sfc_key[A_1]] == SDL_PRESSED) ||
						 (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED) ||
						 (keyssnes[sfc_key[RIGHT_1]] == SDL_PRESSED) )
				{
					switch(cursor)
					{
						case 2: //exit snes9x
							if (keyssnes[sfc_key[A_1]] == SDL_PRESSED)
								S9xExit();
							break;
						case 3: //reset snes9x
							if ((keyssnes[sfc_key[A_1]] == SDL_PRESSED))
							{
								//make sure the sram is stored before resetting the console
								//it should work without, but better safe than sorry...
								Memory.SaveSRAM (S9xGetFilename (".srm"));
								S9xReset();
								exit_loop = TRUE;
							}
							break;
						case 4:
							if (keyssnes[sfc_key[A_1]] == SDL_PRESSED)
								ShowCredit();
							break;
						case 6: //save state
							if (keyssnes[sfc_key[A_1]] == SDL_PRESSED)
							{
								memcpy(snapscreen,snapscreen_tmp,16050);
								show_screenshot();
								strcpy(fname," Saving...");
								S9xDisplayString (temp, GFX.Screen +320/*280*/, 640,80/*204*/);
								S9xDeinitUpdate (320, 240);
								sprintf(ext, ".s0%d", SaveSlotNum);
								strcpy(fname, S9xGetFilename (ext));
								save_screenshot(fname);
								sprintf(ext, ".00%d", SaveSlotNum);
								strcpy(fname, S9xGetFilename (ext));
								S9xFreezeGame (fname);
								sync();
								exit_loop = TRUE;
							}
							break;
						case 7: //load state
							if (keyssnes[sfc_key[A_1]] == SDL_PRESSED)
							{
								sprintf(ext, ".00%d", SaveSlotNum);
								strcpy(fname, S9xGetFilename (ext));
								S9xLoadSnapshot (fname);
								exit_loop = TRUE;
							}
							break;
						case 8: //select save state slot
							if (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED)
							{
								if ( SaveSlotNum == 0 )
									SaveSlotNum = MAX_SAVE_SLOTS-1; // slots start at 0, so 10 slots means slot 0 to 9
								else
									--SaveSlotNum;
							}
							else
							if (keyssnes[sfc_key[RIGHT_1]] == SDL_PRESSED)
							{
								if ( SaveSlotNum == MAX_SAVE_SLOTS-1 ) // slots start at 0, so 10 slots means slot 0 to 9
									SaveSlotNum = 0;
								else
									++SaveSlotNum;
							}
							break;
						case 10: // rotate through scalers
							if (keyssnes[sfc_key[RIGHT_1]] == SDL_PRESSED)
							{
								do
								{
									g_scale = (blit_scaler_e) ( ( g_scale + 1 ) % bs_max );
								} while ( ( blit_scalers [ g_scale ].valid == bs_invalid )
											|| ( highres_current && !(blit_scalers [ g_scale ].support_hires) ) );
							} else if (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED)
							{
								do
								{
									g_scale = (blit_scaler_e) ( g_scale - 1 );
									if (g_scale < 1) g_scale = (blit_scaler_e)(bs_max-1);
								} while ( ( blit_scalers [ g_scale ].valid == bs_invalid )
											|| ( highres_current && !(blit_scalers [ g_scale ].support_hires) ) );
							}
							// now force update the display, so that the new scaler is directly used (fixes some glitches)
							S9xDeinitDisplay();
							S9xInitDisplay(0, 0);
							break;
						case 11: // set frameskip
							if (Settings.SkipFrames == AUTO_FRAMERATE)
								Settings.SkipFrames = 10;
	
							if (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED)
								Settings.SkipFrames--;
							else
								Settings.SkipFrames++;
	
							if(Settings.SkipFrames<=0 || Settings.SkipFrames==10)
								Settings.SkipFrames = AUTO_FRAMERATE;
							else if (Settings.SkipFrames>=11)
								Settings.SkipFrames = 1;
							break;
						case 12: // set vsync
							if (g_vsync)
								g_vsync = 0;
							else 
								g_vsync = 1;
							break;
						case 13: // set display fps
							Settings.DisplayFrameRate = !Settings.DisplayFrameRate;
							break;
						case 14: // set transparency
							Settings.Transparency = !Settings.Transparency;
							break;
						case 15: // cut lines from top
							if (keyssnes[sfc_key[RIGHT_1]] == SDL_PRESSED)
								cut_top++;
							else if (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED && cut_top>0)
								cut_top--;
							// now force update the display, so that the new scaler is directly used (fixes some glitches)
							S9xDeinitDisplay();
							S9xInitDisplay(0, 0);
							break;
						case 16: // cut lines from bottom
							if (keyssnes[sfc_key[RIGHT_1]] == SDL_PRESSED)
								cut_bottom++;
							else if (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED && cut_bottom>0)
								cut_bottom--;
							S9xDeinitDisplay();
							S9xInitDisplay(0, 0);
							break;
						case 17: // cut from the left
							if (keyssnes[sfc_key[RIGHT_1]] == SDL_PRESSED)
								cut_left++;
							else if (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED && cut_left>0)
								cut_left--;
							S9xDeinitDisplay();
							S9xInitDisplay(0, 0);
							break;
						case 18: // cut from the right
							if (keyssnes[sfc_key[RIGHT_1]] == SDL_PRESSED)
								cut_right++;
							else if (keyssnes[sfc_key[LEFT_1]] == SDL_PRESSED && cut_right>0)
								cut_right--;
							S9xDeinitDisplay();
							S9xInitDisplay(0, 0);
							break;
						case 20:
//offer an option to change to alternative sample decoding
//cf. http://www.gp32x.com/board/index.php?/topic/55378-snes9x4d4p-another-new-build-now-with-hi-res-and-new-rom-picker/page__view__findpost__p__958860
							if (Settings.AltSampleDecode)
								Settings.AltSampleDecode = 0;
							else 
								Settings.AltSampleDecode = 1;
							break;
					}
				}

				if(cursor==1)
					cursor=20;
				else if(cursor==21)	
					cursor=2;
				if(cursor==5 || cursor==9 || cursor==19) {
					if(keyssnes[sfc_key[UP_1]] == SDL_PRESSED)
						cursor--;
					else if(keyssnes[sfc_key[DOWN_1]] == SDL_PRESSED)
						cursor++;
				}

				menu_dispupdate();
				sys_sleep(1000);

				break;
		}
	}
	while( exit_loop!=TRUE && keyssnes[sfc_key[B_1]] != SDL_PRESSED );

	Scale = Scale_org;
	Settings.SupportHiRes=highres_current;
	S9xDeinitDisplay();
	S9xInitDisplay(0, 0);
}
Пример #4
0
int main(int argc, char ** argv) {
	// Initialise SDL
	if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0) 
		DIE("SDL_Init: %s", SDL_GetError());

  GL_Init();

  //Init SDL_TTF to print text to the screen...
  if ( TTF_Init() )
  {
    fprintf( stderr, "Error initializing SDL_ttf!\n" );
    exit ( 1 );
  }

	S9xInitDisplay(argc, argv);

	// Configure snes9x
#if CONF_GUI
	OssoInit();						// Hildon-games-wrapper initialization.
#endif
	S9xLoadConfig(argc, argv);		// Load config files and parse cmd line.
  readOptions();
#if CONF_GUI
	OssoConfig();					// Apply specific hildon-games config.
#endif

  // S9x initialization
  S9xInitDisplay(argc, argv);
  S9xInitAudioOutput();
  S9xInitInputDevices();

  while(1)
  {
    S9xInit();
    S9xReset();

    char * rom = romSelector();
    S9xSetRomFile(rom);
    free(rom);

    // Load rom and related files: state, unfreeze if needed
    loadRom();
    resumeGame();

    // Late initialization
    sprintf(String, "DrNokSnes - %s", Memory.ROMName);
    S9xSetTitle(String);
    S9xHacksLoadFile(Config.hacksFile);
    if (!S9xGraphicsInit())
      DIE("S9xGraphicsInit failed");
    S9xAudioOutputEnable(true);
    SDL_PauseAudio(0);
    S9xVideoReset();

    Config.running = true;
    do {
      frameSync();			// May block, or set frameskip to true.
      S9xMainLoop();			// Does CPU things, renders if needed.
      pollEvents();
      //Ouch that this is going here...
      updateBindingMessage();
    } while (Config.running);

    S9xVideoReset();
    S9xGraphicsDeinit();

    // Save state
    Memory.SaveSRAM(S9xGetFilename(FILE_SRAM));
    pauseGame();
    Memory.Deinit();
    S9xDeinitAPU();
  }

  // Deinitialization
  S9xAudioOutputEnable(false);
  S9xDeinitInputDevices();
  S9xDeinitAudioOutput();
  S9xDeinitDisplay();

	// Late deinitialization
	S9xUnloadConfig();
#if CONF_GUI
	OssoDeinit();
#endif

	SDL_Quit();

	return 0;
}