1 /* Pcsx - Pc Psx Emulator
2 * Copyright (C) 1999-2002 Pcsx Team
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA
26 #include <gdk/gdkkeysyms.h>
28 #include <glade/glade.h>
35 #include "../libpcsxcore/plugins.h"
36 #include "../libpcsxcore/cheat.h"
38 #include "MemcardDlg.h"
40 #include "DebugMemory.h"
43 // Functions Callbacks
45 void OnFile_RunBios();
47 void OnFile_RunImage();
50 void OnEmu_SwitchImage();
56 void on_states_load(GtkWidget *widget, gpointer user_data);
57 void on_states_load_other();
58 void on_states_save(GtkWidget *widget, gpointer user_data);
59 void on_states_save_other();
61 GtkWidget *Window = NULL;
67 /* TODO - If MAX_SLOTS changes, need to find a way to automatically set all positions */
68 int Slots[MAX_SLOTS] = { -1, -1, -1, -1, -1 };
70 void ResetMenuSlots(GladeXML *xml) {
75 if (CdromId[0] == '\0') {
76 // disable state saving/loading if no CD is loaded
77 for (i = 0; i < MAX_SLOTS; i++) {
78 str = g_strdup_printf("GtkMenuItem_SaveSlot%d", i+1);
79 widget = glade_xml_get_widget(xml, str);
82 gtk_widget_set_sensitive(widget, FALSE);
84 str = g_strdup_printf("GtkMenuItem_LoadSlot%d", i+1);
85 widget = glade_xml_get_widget(xml, str);
88 gtk_widget_set_sensitive(widget, FALSE);
91 // also disable certain menu/toolbar items
92 widget = glade_xml_get_widget(xml, "other1");
93 gtk_widget_set_sensitive(widget, FALSE);
94 widget = glade_xml_get_widget(xml, "other2");
95 gtk_widget_set_sensitive(widget, FALSE);
96 widget = glade_xml_get_widget(xml, "run1");
97 gtk_widget_set_sensitive(widget, FALSE);
98 widget = glade_xml_get_widget(xml, "reset1");
99 gtk_widget_set_sensitive(widget, FALSE);
100 widget = glade_xml_get_widget(xml, "search1");
101 gtk_widget_set_sensitive(widget, FALSE);
102 widget = glade_xml_get_widget(xml, "SwitchImage");
103 gtk_widget_set_sensitive(widget, FALSE);
104 widget = glade_xml_get_widget(xml, "memorydump1");
105 gtk_widget_set_sensitive(widget, FALSE);
106 widget = glade_xml_get_widget(xml, "toolbutton_run");
107 gtk_widget_set_sensitive(widget, FALSE);
108 widget = glade_xml_get_widget(xml, "toolbutton_switchimage");
109 gtk_widget_set_sensitive(widget, FALSE);
111 widget = glade_xml_get_widget(xml, "statusbar");
112 gtk_statusbar_pop(GTK_STATUSBAR(widget), 1);
113 gtk_statusbar_push(GTK_STATUSBAR(widget), 1, _("Ready"));
116 for (i = 0; i < MAX_SLOTS; i++) {
117 str = g_strdup_printf("GtkMenuItem_LoadSlot%d", i+1);
118 widget = glade_xml_get_widget (xml, str);
122 gtk_widget_set_sensitive(widget, FALSE);
124 gtk_widget_set_sensitive(widget, TRUE);
127 widget = glade_xml_get_widget(xml, "plugins_bios");
128 gtk_widget_set_sensitive(widget, FALSE);
129 widget = glade_xml_get_widget(xml, "graphics1");
130 gtk_widget_set_sensitive(widget, FALSE);
131 widget = glade_xml_get_widget(xml, "sound1");
132 gtk_widget_set_sensitive(widget, FALSE);
133 widget = glade_xml_get_widget(xml, "cdrom1");
134 gtk_widget_set_sensitive(widget, FALSE);
135 widget = glade_xml_get_widget(xml, "pad1");
136 gtk_widget_set_sensitive(widget, FALSE);
137 widget = glade_xml_get_widget(xml, "net1");
138 gtk_widget_set_sensitive(widget, FALSE);
139 widget = glade_xml_get_widget(xml, "SwitchImage");
140 gtk_widget_set_sensitive(widget, UsingIso());
141 widget = glade_xml_get_widget(xml, "toolbutton_switchimage");
142 gtk_widget_set_sensitive(widget, UsingIso());
143 widget = glade_xml_get_widget(xml, "toolbutton_graphics");
144 gtk_widget_set_sensitive(widget, FALSE);
145 widget = glade_xml_get_widget(xml, "toolbutton_sound");
146 gtk_widget_set_sensitive(widget, FALSE);
147 widget = glade_xml_get_widget(xml, "toolbutton_cdrom");
148 gtk_widget_set_sensitive(widget, FALSE);
149 widget = glade_xml_get_widget(xml, "toolbutton_controllers");
150 gtk_widget_set_sensitive(widget, FALSE);
152 widget = glade_xml_get_widget(xml, "statusbar");
153 gtk_statusbar_pop(GTK_STATUSBAR(widget), 1);
154 gtk_statusbar_push(GTK_STATUSBAR(widget), 1, _("Emulation Paused."));
158 int match(const char *string, char *pattern) {
162 if (regcomp(&re, pattern, REG_EXTENDED | REG_NOSUB) != 0) {
165 status = regexec(&re, string, (size_t) 0, NULL, 0);
174 gchar* get_state_filename(int i) {
175 gchar *state_filename;
180 strncpy(trimlabel, CdromLabel, 32);
182 for (j = 31; j >= 0; j--)
183 if (trimlabel[j] == ' ')
188 sprintf(SStateFile, "%.32s-%.9s.%3.3d", trimlabel, CdromId, i);
189 state_filename = g_build_filename (getenv("HOME"), STATES_DIR, SStateFile, NULL);
191 return state_filename;
194 void UpdateMenuSlots() {
198 for (i = 0; i < MAX_SLOTS; i++) {
199 str = get_state_filename (i);
200 Slots[i] = CheckState(str);
209 /* If a plugin fails, the Window is not NULL, but is not initialised,
210 so the following causes a segfault
211 if (Window != NULL) {
212 gtk_window_present (GTK_WINDOW (Window));
216 xml = glade_xml_new(PACKAGE_DATA_DIR "pcsx.glade2", "MainWindow", NULL);
219 g_warning("We could not load the interface!");
223 Window = glade_xml_get_widget(xml, "MainWindow");
224 gtk_window_set_title(GTK_WINDOW(Window), "PCSX");
225 gtk_window_set_icon_from_file(GTK_WINDOW(Window), PIXMAPDIR "pcsx-icon.png", NULL);
226 gtk_window_set_default_icon_from_file(PIXMAPDIR "pcsx-icon.png", NULL);
230 g_signal_connect_data(GTK_OBJECT(Window), "delete-event",
231 GTK_SIGNAL_FUNC(OnDestroy), xml, (GClosureNotify)g_object_unref, G_CONNECT_AFTER);
234 widget = glade_xml_get_widget(xml, "RunCd");
235 g_signal_connect_data(GTK_OBJECT(widget), "activate",
236 GTK_SIGNAL_FUNC(OnFile_RunCd), NULL, NULL, G_CONNECT_AFTER);
238 widget = glade_xml_get_widget(xml, "RunBios");
239 g_signal_connect_data(GTK_OBJECT(widget), "activate",
240 GTK_SIGNAL_FUNC(OnFile_RunBios), NULL, NULL, G_CONNECT_AFTER);
242 widget = glade_xml_get_widget(xml, "RunExe");
243 g_signal_connect_data(GTK_OBJECT(widget), "activate",
244 GTK_SIGNAL_FUNC(OnFile_RunExe), NULL, NULL, G_CONNECT_AFTER);
246 widget = glade_xml_get_widget(xml, "RunImage");
247 g_signal_connect_data(GTK_OBJECT(widget), "activate",
248 GTK_SIGNAL_FUNC(OnFile_RunImage), NULL, NULL, G_CONNECT_AFTER);
250 widget = glade_xml_get_widget(xml, "exit2");
251 g_signal_connect_data(GTK_OBJECT(widget), "activate",
252 GTK_SIGNAL_FUNC(OnFile_Exit), NULL, NULL, G_CONNECT_AFTER);
255 widget = glade_xml_get_widget(xml, "GtkMenuItem_LoadSlot1");
256 g_signal_connect_data(GTK_OBJECT(widget), "activate",
257 GTK_SIGNAL_FUNC(on_states_load), (gpointer) 0, NULL, G_CONNECT_AFTER);
258 widget = glade_xml_get_widget(xml, "GtkMenuItem_LoadSlot2");
259 g_signal_connect_data(GTK_OBJECT(widget), "activate",
260 GTK_SIGNAL_FUNC(on_states_load), (gpointer) 1, NULL, G_CONNECT_AFTER);
261 widget = glade_xml_get_widget(xml, "GtkMenuItem_LoadSlot3");
262 g_signal_connect_data(GTK_OBJECT(widget), "activate",
263 GTK_SIGNAL_FUNC(on_states_load), (gpointer) 2, NULL, G_CONNECT_AFTER);
264 widget = glade_xml_get_widget(xml, "GtkMenuItem_LoadSlot4");
265 g_signal_connect_data(GTK_OBJECT(widget), "activate",
266 GTK_SIGNAL_FUNC(on_states_load), (gpointer) 3, NULL, G_CONNECT_AFTER);
267 widget = glade_xml_get_widget(xml, "GtkMenuItem_LoadSlot5");
268 g_signal_connect_data(GTK_OBJECT(widget), "activate",
269 GTK_SIGNAL_FUNC(on_states_load), (gpointer) 4, NULL, G_CONNECT_AFTER);
270 widget = glade_xml_get_widget(xml, "other1");
271 g_signal_connect_data(GTK_OBJECT(widget), "activate",
272 GTK_SIGNAL_FUNC(on_states_load_other), NULL, NULL, G_CONNECT_AFTER);
274 widget = glade_xml_get_widget(xml, "GtkMenuItem_SaveSlot1");
275 g_signal_connect_data(GTK_OBJECT(widget), "activate",
276 GTK_SIGNAL_FUNC(on_states_save), (gpointer) 0, NULL, G_CONNECT_AFTER);
277 widget = glade_xml_get_widget(xml, "GtkMenuItem_SaveSlot2");
278 g_signal_connect_data(GTK_OBJECT(widget), "activate",
279 GTK_SIGNAL_FUNC(on_states_save), (gpointer) 1, NULL, G_CONNECT_AFTER);
280 widget = glade_xml_get_widget(xml, "GtkMenuItem_SaveSlot3");
281 g_signal_connect_data(GTK_OBJECT(widget), "activate",
282 GTK_SIGNAL_FUNC(on_states_save), (gpointer) 2, NULL, G_CONNECT_AFTER);
283 widget = glade_xml_get_widget(xml, "GtkMenuItem_SaveSlot4");
284 g_signal_connect_data(GTK_OBJECT(widget), "activate",
285 GTK_SIGNAL_FUNC(on_states_save), (gpointer) 3, NULL, G_CONNECT_AFTER);
286 widget = glade_xml_get_widget(xml, "GtkMenuItem_SaveSlot5");
287 g_signal_connect_data(GTK_OBJECT(widget), "activate",
288 GTK_SIGNAL_FUNC(on_states_save), (gpointer) 4, NULL, G_CONNECT_AFTER);
289 widget = glade_xml_get_widget(xml, "other2");
290 g_signal_connect_data(GTK_OBJECT(widget), "activate",
291 GTK_SIGNAL_FUNC(on_states_save_other), NULL, NULL, G_CONNECT_AFTER);
294 widget = glade_xml_get_widget(xml, "run1");
295 g_signal_connect_data(GTK_OBJECT(widget), "activate",
296 GTK_SIGNAL_FUNC(OnEmu_Run), NULL, NULL, G_CONNECT_AFTER);
297 widget = glade_xml_get_widget(xml, "reset1");
298 g_signal_connect_data(GTK_OBJECT(widget), "activate",
299 GTK_SIGNAL_FUNC(OnEmu_Reset), NULL, NULL, G_CONNECT_AFTER);
300 widget = glade_xml_get_widget(xml, "SwitchImage");
301 g_signal_connect_data(GTK_OBJECT(widget), "activate",
302 GTK_SIGNAL_FUNC(OnEmu_SwitchImage), NULL, NULL, G_CONNECT_AFTER);
304 // Configuration menu
305 widget = glade_xml_get_widget(xml, "plugins_bios");
306 g_signal_connect_data(GTK_OBJECT(widget), "activate",
307 GTK_SIGNAL_FUNC(ConfigurePlugins), NULL, NULL, G_CONNECT_AFTER);
308 widget = glade_xml_get_widget(xml, "graphics1");
309 g_signal_connect_data(GTK_OBJECT(widget), "activate",
310 GTK_SIGNAL_FUNC(OnConf_Graphics), NULL, NULL, G_CONNECT_AFTER);
311 widget = glade_xml_get_widget(xml, "sound1");
312 g_signal_connect_data(GTK_OBJECT(widget), "activate",
313 GTK_SIGNAL_FUNC(OnConf_Sound), NULL, NULL, G_CONNECT_AFTER);
314 widget = glade_xml_get_widget(xml, "cdrom1");
315 g_signal_connect_data(GTK_OBJECT(widget), "activate",
316 GTK_SIGNAL_FUNC(OnConf_CdRom), NULL, NULL, G_CONNECT_AFTER);
317 widget = glade_xml_get_widget(xml, "pad1");
318 g_signal_connect_data(GTK_OBJECT(widget), "activate",
319 GTK_SIGNAL_FUNC(OnConf_Pad), NULL, NULL, G_CONNECT_AFTER);
320 widget = glade_xml_get_widget(xml, "cpu1");
321 g_signal_connect_data(GTK_OBJECT(widget), "activate",
322 GTK_SIGNAL_FUNC(OnConf_Cpu), NULL, NULL, G_CONNECT_AFTER);
323 widget = glade_xml_get_widget(xml, "memory_cards1");
324 g_signal_connect_data(GTK_OBJECT(widget), "activate",
325 GTK_SIGNAL_FUNC(OnConf_Mcds), NULL, NULL, G_CONNECT_AFTER);
326 widget = glade_xml_get_widget(xml, "net1");
327 g_signal_connect_data(GTK_OBJECT(widget), "activate",
328 GTK_SIGNAL_FUNC(OnConf_Net), NULL, NULL, G_CONNECT_AFTER);
329 widget = glade_xml_get_widget(xml, "memorydump1");
330 g_signal_connect_data(GTK_OBJECT(widget), "activate",
331 GTK_SIGNAL_FUNC(RunDebugMemoryDialog), NULL, NULL, G_CONNECT_AFTER);
334 widget = glade_xml_get_widget(xml, "browse1");
335 g_signal_connect_data(GTK_OBJECT(widget), "activate",
336 GTK_SIGNAL_FUNC(RunCheatListDialog), NULL, NULL, G_CONNECT_AFTER);
337 widget = glade_xml_get_widget(xml, "search1");
338 g_signal_connect_data(GTK_OBJECT(widget), "activate",
339 GTK_SIGNAL_FUNC(RunCheatSearchDialog), NULL, NULL, G_CONNECT_AFTER);
342 widget = glade_xml_get_widget(xml, "about_pcsx1");
343 g_signal_connect_data(GTK_OBJECT(widget), "activate",
344 GTK_SIGNAL_FUNC(OnHelp_About), NULL, NULL, G_CONNECT_AFTER);
347 widget = glade_xml_get_widget(xml, "toolbutton_runcd");
348 g_signal_connect_data(GTK_OBJECT(widget), "clicked",
349 GTK_SIGNAL_FUNC(OnFile_RunCd), NULL, NULL, G_CONNECT_AFTER);
351 widget = glade_xml_get_widget(xml, "toolbutton_runimage");
352 g_signal_connect_data(GTK_OBJECT(widget), "clicked",
353 GTK_SIGNAL_FUNC(OnFile_RunImage), NULL, NULL, G_CONNECT_AFTER);
355 widget = glade_xml_get_widget(xml, "toolbutton_run");
356 g_signal_connect_data(GTK_OBJECT(widget), "clicked",
357 GTK_SIGNAL_FUNC(OnEmu_Run), NULL, NULL, G_CONNECT_AFTER);
359 widget = glade_xml_get_widget(xml, "toolbutton_switchimage");
360 g_signal_connect_data(GTK_OBJECT(widget), "clicked",
361 GTK_SIGNAL_FUNC(OnEmu_SwitchImage), NULL, NULL, G_CONNECT_AFTER);
363 widget = glade_xml_get_widget(xml, "toolbutton_memcards");
364 g_signal_connect_data(GTK_OBJECT(widget), "clicked",
365 GTK_SIGNAL_FUNC(OnConf_Mcds), NULL, NULL, G_CONNECT_AFTER);
367 widget = glade_xml_get_widget(xml, "toolbutton_graphics");
368 g_signal_connect_data(GTK_OBJECT(widget), "clicked",
369 GTK_SIGNAL_FUNC(OnConf_Graphics), NULL, NULL, G_CONNECT_AFTER);
371 widget = glade_xml_get_widget(xml, "toolbutton_sound");
372 g_signal_connect_data(GTK_OBJECT(widget), "clicked",
373 GTK_SIGNAL_FUNC(OnConf_Sound), NULL, NULL, G_CONNECT_AFTER);
375 widget = glade_xml_get_widget(xml, "toolbutton_cdrom");
376 g_signal_connect_data(GTK_OBJECT(widget), "clicked",
377 GTK_SIGNAL_FUNC(OnConf_CdRom), NULL, NULL, G_CONNECT_AFTER);
379 widget = glade_xml_get_widget(xml, "toolbutton_controllers");
380 g_signal_connect_data(GTK_OBJECT(widget), "clicked",
381 GTK_SIGNAL_FUNC(OnConf_Pad), NULL, NULL, G_CONNECT_AFTER);
387 if (!destroy) OnFile_Exit();
390 void destroy_main_window () {
392 gtk_widget_destroy(Window);
396 while (gtk_events_pending()) gtk_main_iteration();
399 void OnFile_RunExe() {
400 GtkWidget *file_chooser;
402 if (plugins_configured() == FALSE) {
405 file_chooser = gtk_file_chooser_dialog_new(_("Select PSX EXE File"),
406 NULL, GTK_FILE_CHOOSER_ACTION_OPEN,
407 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
408 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
411 GtkFileFilter *exefilter = gtk_file_filter_new ();
412 gtk_file_filter_add_pattern (exefilter, "*.exe");
413 gtk_file_filter_add_pattern (exefilter, "*.psx");
414 gtk_file_filter_add_pattern (exefilter, "*.cpe");
415 gtk_file_filter_add_pattern (exefilter, "*.EXE");
416 gtk_file_filter_add_pattern (exefilter, "*.PSX");
417 gtk_file_filter_add_pattern (exefilter, "*.CPE");
418 gtk_file_filter_set_name (exefilter, _("PlayStation Executable Files"));
419 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (file_chooser), exefilter);
420 GtkFileFilter *allfilter = gtk_file_filter_new ();
421 gtk_file_filter_add_pattern (allfilter, "*");
422 gtk_file_filter_set_name (allfilter, _("All Files"));
423 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (file_chooser), allfilter);
425 // Set this to the config object and retain it - maybe LastUsedDir
426 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_chooser), getenv("HOME"));
428 if (gtk_dialog_run(GTK_DIALOG(file_chooser)) == GTK_RESPONSE_ACCEPT) {
431 /* TODO Need to validate the file */
433 file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(file_chooser));
435 gtk_widget_destroy (file_chooser);
436 destroy_main_window();
442 if (OpenPlugins() == -1) {
448 if (Load(file) == 0) {
454 SysErrorMessage(_("Not a valid PSX file"), _("The file does not appear to be a valid Playstation executable"));
459 gtk_widget_destroy(file_chooser);
463 void OnFile_RunCd() {
464 if (plugins_configured() == FALSE) {
469 destroy_main_window();
475 if (OpenPlugins() == -1) {
482 if (CheckCdrom() == -1) {
483 /* Only check the CD if we are starting the console with a CD */
485 SysErrorMessage (_("CD ROM failed"), _("The CD does not appear to be a valid Playstation CD"));
490 // Read main executable directly from CDRom and start it
491 if (LoadCdrom() == -1) {
493 SysErrorMessage(_("Could not load CD-ROM!"), _("The CD-ROM could not be loaded"));
500 void OnFile_RunBios() {
501 if (plugins_configured() == FALSE) {
506 if (strcmp(Config.Bios, "HLE") == 0) {
507 SysErrorMessage (_("Could not run BIOS"), _("Running BIOS is not supported with Internal HLE BIOS."));
511 destroy_main_window();
517 if (OpenPlugins() == -1) {
525 CdromLabel[0] = '\0';
530 static gchar *Open_Iso_Proc() {
533 GtkFileFilter *psxfilter, *allfilter;
534 static char current_folder[MAXPATHLEN] = "";
536 chooser = gtk_file_chooser_dialog_new (_("Open PSX Disc Image File"),
537 NULL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
538 GTK_STOCK_OK, GTK_RESPONSE_OK,
541 if (current_folder[0] == '\0') {
542 strcpy(current_folder, getenv("HOME"));
545 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (chooser), current_folder);
547 psxfilter = gtk_file_filter_new();
548 gtk_file_filter_add_pattern(psxfilter, "*.bin");
549 gtk_file_filter_add_pattern(psxfilter, "*.img");
550 gtk_file_filter_add_pattern(psxfilter, "*.mdf");
551 gtk_file_filter_add_pattern(psxfilter, "*.iso");
552 gtk_file_filter_add_pattern(psxfilter, "*.BIN");
553 gtk_file_filter_add_pattern(psxfilter, "*.IMG");
554 gtk_file_filter_add_pattern(psxfilter, "*.MDF");
555 gtk_file_filter_add_pattern(psxfilter, "*.ISO");
556 gtk_file_filter_set_name(psxfilter, _("PSX Image Files (*.bin, *.img, *.mdf, *.iso)"));
557 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (chooser), psxfilter);
559 allfilter = gtk_file_filter_new();
560 gtk_file_filter_add_pattern(allfilter, "*");
561 gtk_file_filter_set_name(allfilter, _("All Files"));
562 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (chooser), allfilter);
564 if (gtk_dialog_run(GTK_DIALOG(chooser)) == GTK_RESPONSE_OK) {
565 gchar *path = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(chooser));
566 strcpy(current_folder, path);
568 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (chooser));
569 gtk_widget_destroy(GTK_WIDGET(chooser));
570 while (gtk_events_pending()) gtk_main_iteration();
573 gtk_widget_destroy (GTK_WIDGET(chooser));
574 while (gtk_events_pending()) gtk_main_iteration();
579 void OnFile_RunImage() {
582 if (plugins_configured() == FALSE) {
587 filename = Open_Iso_Proc();
588 if (filename == NULL) {
592 destroy_main_window();
594 SetIsoFile(filename);
600 if (OpenPlugins() == -1) {
607 if (CheckCdrom() == -1) {
608 // Only check the CD if we are starting the console with a CD
610 SysErrorMessage (_("CD ROM failed"), _("The CD does not appear to be a valid Playstation CD"));
615 // Read main executable directly from CDRom and start it
616 if (LoadCdrom() == -1) {
618 SysErrorMessage(_("Could not load CD-ROM!"), _("The CD-ROM could not be loaded"));
626 if (plugins_configured() == FALSE) {
631 destroy_main_window();
633 if (OpenPlugins() == -1) {
638 CheatSearchBackupMemory();
643 if (plugins_configured() == FALSE) {
648 destroy_main_window();
650 if (OpenPlugins() == -1) {
657 if (CheckCdrom() != -1) {
664 void OnEmu_SwitchImage() {
667 if (plugins_configured() == FALSE) {
672 filename = Open_Iso_Proc();
673 if (filename == NULL) {
677 destroy_main_window();
679 SetIsoFile(filename);
682 if (OpenPlugins() == -1) {
687 SetCdOpenCaseTime(time(NULL) + 2);
689 CheatSearchBackupMemory();
697 gchar *plugin = NULL;
700 dotdir = g_build_filename(getenv("HOME"), PLUGINS_DIR, NULL);
702 // with this the problem with plugins that are linked with the pthread
705 dir = opendir(dotdir);
707 while ((ent = readdir(dir)) != NULL) {
708 plugin = g_build_filename(dotdir, ent->d_name, NULL);
710 if (strstr(plugin, ".so") == NULL && strstr(plugin, ".dylib") == NULL)
712 Handle = dlopen(plugin, RTLD_NOW);
721 bind_textdomain_codeset(PACKAGE_NAME, "");
731 void state_load(gchar *state_filename) {
733 char Text[MAXPATHLEN + 20];
736 // check if the state file actually exists
737 fp = fopen(state_filename, "rb");
739 // file does not exist
745 // If the window exists, then we are loading the state from within
746 // within the PCSX GUI. We need to initialise the plugins first
748 destroy_main_window();
750 if (OpenPlugins() == -1) {
756 ret = CheckState(state_filename);
760 ret = LoadState(state_filename);
764 // Check the CD-ROM is valid
765 if (CheckCdrom() == -1) {
771 sprintf(Text, _("Loaded state %s."), state_filename);
772 GPU_displayText(Text);
774 sprintf(Text, _("Error loading state %s!"), state_filename);
775 GPU_displayText(Text);
779 void state_save(gchar *state_filename) {
780 char Text[MAXPATHLEN + 20];
784 if (SaveState(state_filename) == 0)
785 sprintf(Text, _("Saved state %s."), state_filename);
787 sprintf(Text, _("Error saving state %s!"), state_filename);
789 GPU_displayText(Text);
792 void on_states_load (GtkWidget *widget, gpointer user_data) {
793 gchar *state_filename;
794 gint state = (int)user_data;
796 state_filename = get_state_filename(state);
798 state_load(state_filename);
800 g_free(state_filename);
805 void on_states_save (GtkWidget *widget, gpointer user_data) {
806 gchar *state_filename;
807 gint state = (int)user_data;
809 state_filename = get_state_filename(state);
811 state_save(state_filename);
813 g_free(state_filename);
816 void on_states_load_other() {
817 GtkWidget *file_chooser;
820 SStateFile = g_strconcat(getenv("HOME"), STATES_DIR, NULL);
822 file_chooser = gtk_file_chooser_dialog_new(_("Select State File"), NULL, GTK_FILE_CHOOSER_ACTION_OPEN,
823 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
824 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
826 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (file_chooser), SStateFile);
829 if (gtk_dialog_run(GTK_DIALOG(file_chooser)) == GTK_RESPONSE_ACCEPT) {
832 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(file_chooser));
833 gtk_widget_destroy(file_chooser);
835 state_load(filename);
841 gtk_widget_destroy(file_chooser);
844 void on_states_save_other() {
845 GtkWidget *file_chooser;
848 SStateFile = g_strconcat (getenv("HOME"), STATES_DIR, NULL);
850 file_chooser = gtk_file_chooser_dialog_new(_("Select State File"),
851 NULL, GTK_FILE_CHOOSER_ACTION_SAVE,
852 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
853 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
855 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_chooser), SStateFile);
858 if (gtk_dialog_run (GTK_DIALOG(file_chooser)) == GTK_RESPONSE_OK) {
861 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (file_chooser));
862 gtk_widget_destroy(file_chooser);
864 state_save(filename);
869 gtk_widget_destroy(file_chooser);
872 void OnHelp_About(GtkWidget *widget, gpointer user_data) {
876 void SysMessage(const char *fmt, ...) {
877 GtkWidget *Txt, *MsgDlg;
882 vsprintf(msg, fmt, list);
885 if (msg[strlen(msg) - 1] == '\n')
886 msg[strlen(msg) - 1] = 0;
889 fprintf(stderr, "%s\n", msg);
893 MsgDlg = gtk_dialog_new_with_buttons(_("Notice"), NULL,
894 GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, GTK_RESPONSE_NONE, NULL);
896 gtk_window_set_position (GTK_WINDOW(MsgDlg), GTK_WIN_POS_CENTER);
898 Txt = gtk_label_new (msg);
899 gtk_label_set_line_wrap(GTK_LABEL(Txt), TRUE);
900 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(MsgDlg)->vbox), Txt);
902 gtk_widget_show (Txt);
903 gtk_widget_show_all (MsgDlg);
904 gtk_dialog_run (GTK_DIALOG(MsgDlg));
905 gtk_widget_destroy (MsgDlg);
908 void SysErrorMessage(gchar *primary, gchar *secondary) {
909 GtkWidget *message_dialog;
911 printf ("%s - %s\n", primary, secondary);
913 message_dialog = gtk_message_dialog_new(NULL,
919 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(message_dialog),
922 gtk_dialog_run(GTK_DIALOG(message_dialog));
923 gtk_widget_destroy(message_dialog);
927 void SysInfoMessage(gchar *primary, gchar *secondary) {
928 GtkWidget *message_dialog;
930 printf ("%s - %s\n", primary, secondary);
932 message_dialog = gtk_message_dialog_new(NULL,
938 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(message_dialog),
941 gtk_dialog_run(GTK_DIALOG(message_dialog));
942 gtk_widget_destroy(message_dialog);