frontend: reuse menu logic for config changing plugins
authornotaz <notasas@gmail.com>
Fri, 22 Aug 2025 21:12:31 +0000 (00:12 +0300)
committernotaz <notasas@gmail.com>
Fri, 22 Aug 2025 21:24:54 +0000 (00:24 +0300)
notaz/pcsx_rearmed#388

frontend/main.c
frontend/menu.c
frontend/menu.h

index 4337316..debfb11 100644 (file)
@@ -636,7 +636,8 @@ int main(int argc, char *argv[])
                                                        "\t-cdfile FILE\tRuns a CD image file\n"
                                                        "\t-cfg FILE\tLoads desired configuration file (default: ~/.pcsx/pcsx.cfg)\n"
                                                        "\t-psxout\t\tEnable PSX output\n"
-                                                       "\t-load STATENUM\tLoads savestate STATENUM (1-5)\n"
+                                                       "\t-load STATENUM\tLoads savestate STATENUM (1-9)\n"
+                                                       "\t-loadf FILE\tLoads savestate from FILE\n"
                                                        "\t-h -help\tDisplay this message\n"
                                                        "\tfile\t\tLoads a PSX EXE file\n"));
                         return 0;
@@ -695,15 +696,8 @@ int main(int argc, char *argv[])
                if (Load(file) != -1)
                        ready_to_go = 1;
        } else {
-               if (cdfile) {
-                       if (LoadCdrom() == -1) {
-                               ClosePlugins();
-                               SysPrintf(_("Could not load CD-ROM!\n"));
-                               return -1;
-                       }
-                       emu_on_new_cd(!loadst);
-                       ready_to_go = 1;
-               }
+               if (cdfile)
+                       ready_to_go = menu_load_cd_image(cdfile) == 0;
        }
 
        if (loadst_f) {
@@ -714,14 +708,12 @@ int main(int argc, char *argv[])
        }
 
        if (ready_to_go) {
-               if (menu_load_config(1) != 0)
-                       menu_load_config(0);
                menu_prepare_emu();
 
-               // If a state has been specified, then load that
-               if (loadst) {
+               // If a state slot has been specified, then load that
+               if (cdfile && loadst) {
                        int ret = emu_load_state(loadst - 1);
-                       SysPrintf("%s state %d\n",
+                       SysPrintf("%s state slot %d\n",
                                ret ? "failed to load" : "loaded", loadst);
                }
        }
index 1b6ed58..2de3831 100644 (file)
@@ -2166,7 +2166,6 @@ static int run_exe(void)
        SysReset();
        if (Load(fname) != 0) {
                menu_update_msg("exe load failed, bad file?");
-               printf("meh\n");
                return -1;
        }
 
@@ -2242,20 +2241,9 @@ static int run_cd_image(const char *fname)
        return 0;
 }
 
-static int romsel_run(void)
+int menu_load_cd_image(const char *fname)
 {
        int prev_gpu, prev_spu;
-       const char *fname;
-
-       fname = menu_loop_romsel(last_selected_fname,
-                       sizeof(last_selected_fname), filter_exts,
-                       optional_cdimg_filter);
-       if (fname == NULL)
-               return -1;
-
-       printf("selected file: %s\n", fname);
-
-       ndrc_clear_full();
 
        if (run_cd_image(fname) != 0)
                return -1;
@@ -2268,7 +2256,7 @@ static int romsel_run(void)
        // check for plugin changes, have to repeat
        // loading if game config changed plugins to reload them
        if (prev_gpu != gpu_plugsel || prev_spu != spu_plugsel) {
-               printf("plugin change detected, reloading plugins..\n");
+               printf("plugin change detected, reloading plugins...\n");
                if (run_cd_image(fname) != 0)
                        return -1;
        }
@@ -2278,6 +2266,23 @@ static int romsel_run(void)
        return 0;
 }
 
+static int romsel_run(void)
+{
+       const char *fname;
+
+       fname = menu_loop_romsel(last_selected_fname,
+                       sizeof(last_selected_fname), filter_exts,
+                       optional_cdimg_filter);
+       if (fname == NULL)
+               return -1;
+
+       printf("selected file: %s\n", fname);
+
+       ndrc_clear_full();
+
+       return menu_load_cd_image(fname);
+}
+
 static int swap_cd_image(void)
 {
        const char *fname;
index 26643af..5988556 100644 (file)
@@ -7,6 +7,7 @@ void menu_loop(void);
 void menu_finish(void);
 
 void menu_notify_mode_change(int w, int h, int bpp);
+int  menu_load_cd_image(const char *fname);
 int  menu_load_config(int is_game);
 
 enum g_opts_opts {