diff --git a/gtk/src/gtk_file.cpp b/gtk/src/gtk_file.cpp index e0215e3e..e5ff062a 100644 --- a/gtk/src/gtk_file.cpp +++ b/gtk/src/gtk_file.cpp @@ -102,7 +102,7 @@ const char *S9xGetDirectory(enum s9x_getdirtype dirtype) } /* Anything else, use ROM filename path */ - if (dirname == "") + if (dirname == "" && gui_config && !gui_config->rom_loaded) { fs::path path(Memory.ROMFilename); diff --git a/gtk/src/gtk_s9x.cpp b/gtk/src/gtk_s9x.cpp index 60979c44..847f0a4c 100644 --- a/gtk/src/gtk_s9x.cpp +++ b/gtk/src/gtk_s9x.cpp @@ -34,8 +34,8 @@ static bool S9xIdleFunc(); static bool S9xPauseFunc(); static bool S9xScreenSaverCheckFunc(); -Snes9xWindow *top_level; -Snes9xConfig *gui_config; +Snes9xWindow *top_level = nullptr; +Snes9xConfig *gui_config = nullptr; StateManager state_manager; gint64 frame_clock = -1; gint64 pointer_timestamp = -1; @@ -49,7 +49,6 @@ static void S9xTerm(int signal) int main(int argc, char *argv[]) { - struct sigaction sig_callback; auto app = Gtk::Application::create("com.snes9x.gtk", Gio::APPLICATION_NON_UNIQUE); setlocale(LC_ALL, ""); @@ -57,7 +56,13 @@ int main(int argc, char *argv[]) bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); - memset(&Settings, 0, sizeof(Settings)); + struct sigaction sig_callback{}; + sig_callback.sa_handler = S9xTerm; + sigaction(15, &sig_callback, NULL); // SIGTERM + sigaction(3, &sig_callback, NULL); // SIGQUIT + sigaction(2, &sig_callback, NULL); // SIGINT + + Settings = {}; // Original config fills out values this port doesn't. S9xLoadConfigFiles(argv, argc); @@ -75,8 +80,6 @@ int main(int argc, char *argv[]) settings->set_property("gtk-menu-images", gui_config->enable_icons); settings->set_property("gtk-button-images", gui_config->enable_icons); - S9xReportControllers(); - if (!Memory.Init() || !S9xInitAPU()) exit(3); @@ -85,13 +88,13 @@ int main(int argc, char *argv[]) // Setting fullscreen before showing the window avoids some flicker. if ((gui_config->full_screen_on_open && rom_filename) || (gui_config->fullscreen)) top_level->window->fullscreen(); - top_level->show(); S9xInitDisplay(argc, argv); S9xPortSoundInit(); + S9xReportControllers(); for (int port = 0; port < 2; port++) { enum controllers type; @@ -125,10 +128,6 @@ int main(int argc, char *argv[]) top_level->update_accelerators(); Settings.Paused = true; - - Glib::signal_timeout().connect(sigc::ptr_fun(S9xPauseFunc), 100); - Glib::signal_timeout().connect(sigc::ptr_fun(S9xScreenSaverCheckFunc), 10000); - S9xNoROMLoaded(); if (rom_filename) @@ -137,23 +136,18 @@ int main(int argc, char *argv[]) top_level->window->unfullscreen(); } - memset(&sig_callback, 0, sizeof(struct sigaction)); - sig_callback.sa_handler = S9xTerm; - - sigaction(15, &sig_callback, NULL); // SIGTERM - sigaction(3, &sig_callback, NULL); // SIGQUIT - sigaction(2, &sig_callback, NULL); // SIGINT - // Perform the complete fullscreen process, including mode sets, which // didn't happen in the earlier Gtk call. if (gui_config->fullscreen) top_level->enter_fullscreen_mode(); - gui_config->joysticks.flush_events(); - if (rom_filename && *Settings.InitialSnapshotFilename) S9xUnfreezeGame(Settings.InitialSnapshotFilename); + gui_config->joysticks.flush_events(); + + Glib::signal_timeout().connect(sigc::ptr_fun(S9xPauseFunc), 100); + Glib::signal_timeout().connect(sigc::ptr_fun(S9xScreenSaverCheckFunc), 10000); app->run(*top_level->window.get()); return 0; } @@ -181,40 +175,6 @@ int S9xOpenROM(const char *rom_filename) Settings.StopEmulation = !loaded; - if (!loaded && rom_filename) - { - char dir[_MAX_DIR + 1]; - char drive[_MAX_DRIVE + 1]; - char name[_MAX_FNAME + 1]; - char ext[_MAX_EXT + 1]; - char fname[_MAX_PATH + 1]; - - _splitpath(rom_filename, drive, dir, name, ext); - _makepath(fname, drive, dir, name, ext); - - strcpy(fname, S9xGetDirectory(ROM_DIR)); - strcat(fname, SLASH_STR); - strcat(fname, name); - - if (ext[0]) - { - strcat(fname, "."); - strcat(fname, ext); - } - - _splitpath(fname, drive, dir, name, ext); - _makepath(fname, drive, dir, name, ext); - - if ((Settings.StopEmulation = !Memory.LoadROM(fname))) - { - fprintf(stderr, _("Error opening: %s\n"), rom_filename); - - loaded = false; - } - else - loaded = true; - } - if (loaded) { Memory.LoadSRAM(S9xGetFilename(".srm", SRAM_DIR)); @@ -334,14 +294,14 @@ static bool S9xIdleFunc() S9xProcessEvents(true); + S9xThrottle(Settings.SkipFrames); + if (!S9xDisplayDriverIsReady()) { usleep(100); return true; } - S9xThrottle(Settings.SkipFrames); - if (!S9xNetplayPush()) { if (Settings.Rewinding) @@ -360,7 +320,7 @@ static bool S9xIdleFunc() if ((Settings.TurboMode || Settings.Rewinding) && gui_config->mute_sound_turbo) Settings.Mute |= 0x80; - else + else Settings.Mute &= ~0x80; S9xMainLoop(); @@ -400,64 +360,32 @@ void S9xParseArg(char **argv, int &i, int argc) { if (!strcasecmp(argv[i], "-filter")) { + std::string filter_names[] = + { + "none", + "supereagle", + "2xsai", + "super2xsai", + "epx", + "epx_smooth", + "ntsc", + "scanlines", + "simple2x", + "simple3x", + "simple4x", + "hq2x", + "hq3x", + "hq4x", + "2xbrz", + "3xbrz", + "4xbrz" + }; + if ((++i) < argc) { - if (!strcasecmp(argv[i], "none")) - { - gui_config->scale_method = FILTER_NONE; - } - else if (!strcasecmp(argv[i], "supereagle")) - { - gui_config->scale_method = FILTER_SUPEREAGLE; - } - else if (!strcasecmp(argv[i], "2xsai")) - { - gui_config->scale_method = FILTER_2XSAI; - } - else if (!strcasecmp(argv[i], "super2xsai")) - { - gui_config->scale_method = FILTER_SUPER2XSAI; - } -#ifdef USE_HQ2X - else if (!strcasecmp(argv[i], "hq2x")) - { - gui_config->scale_method = FILTER_HQ2X; - } - else if (!strcasecmp(argv[i], "hq3x")) - { - gui_config->scale_method = FILTER_HQ3X; - } - else if (!strcasecmp(argv[i], "hq4x")) - { - gui_config->scale_method = FILTER_HQ4X; - } -#endif /* USE_HQ2X */ -#ifdef USE_XBRZ - else if (!strcasecmp(argv[i], "2xbrz")) - { - gui_config->scale_method = FILTER_2XBRZ; - } - else if (!strcasecmp(argv[i], "3xbrz")) - { - gui_config->scale_method = FILTER_3XBRZ; - } - else if (!strcasecmp(argv[i], "4xbrz")) - { - gui_config->scale_method = FILTER_4XBRZ; - } -#endif /* USE_XBRZ */ - else if (!strcasecmp(argv[i], "epx")) - { - gui_config->scale_method = FILTER_EPX; - } - else if (!strcasecmp(argv[i], "ntsc")) - { - gui_config->scale_method = FILTER_NTSC; - } - else - { - gui_config->scale_method = FILTER_NONE; - } + for (int f = 0; f < NUM_FILTERS; f++) + if (filter_names[f] == argv[i]) + gui_config->scale_method = f; } } else if (!strcasecmp(argv[i], "-mutesound"))