Create Xref-Html Frames Remove All Frames
file:/home/jivera/wd/pcsx/Linux/GtkGui.c (Tue Nov 25 22:46:14 2003
)
1: /* Pcsx - Pc Psx Emulator
2: * Copyright (C) 1999-2002 Pcsx Team
3: *
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.
8: *
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.
13: *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: #include <stdio.h>
20: #include <stdlib.h>
21: #include <unistd.h>
22: #include <string.h>
23: #include <dirent.h>
24: #include <dlfcn.h>
25: #include <sys/stat.h>
26: #include <gdk/gdkkeysyms.h>
27: #include <gtk/gtk.h>
28: #include <signal.h>
29: #include <sys/time.h>
30:
31: #include "Linux.h"
32: #include "plugins.h"
33: #include "Sio.h"
34: #include "GladeGui.h"
35: #include "GladeFuncs.h"
36:
37: extern int UseGui;
38: long LoadCdBios;
39: static int needreset = 1;
40:
41: PSEgetLibType PSE_getLibType = NULL;
42: PSEgetLibVersion PSE_getLibVersion = NULL;
43: PSEgetLibName PSE_getLibName = NULL;
44:
45: // Helper Functions
46: void FindPlugins();
47: void FindNetPlugin();
48:
49: // Functions Callbacks
50: void OnFile_RunExe();
51: void OnFile_RunCd();
52: void OnFile_RunCdBios();
53: void OnFile_Exit();
54: void OnEmu_Run();
55: void OnEmu_Reset();
56: void OnConf_Gpu();
57: void OnConf_Spu();
58: void OnConf_Cdr();
59: void OnConf_Pads();
60: void OnConf_Mcds();
61: void OnConf_Cpu();
62: void OnConf_Conf();
63: void OnLanguage(GtkMenuItem *menuitem, gpointer user_data);
64: void OnHelp_Help();
65: void OnHelp_About();
66:
67:
68: GtkWidget *Window = NULL;
69: GtkWidget *ConfDlg;
70: GtkWidget *AboutDlg;
71: GtkWidget *FileSel;
72:
73: GtkAccelGroup *AccelGroup;
74:
75: typedef struct {
76: GtkWidget *Combo;
77: GList *glist;
78: char plist[255][255];
79: int plugins;
80: } PluginConf;
81:
82: PluginConf GpuConfS;
83: PluginConf SpuConfS;
84: PluginConf CdrConfS;
85: PluginConf Pad1ConfS;
86: PluginConf Pad2ConfS;
87: PluginConf NetConfS;
88: PluginConf BiosConfS;
89:
90: #define FindComboText(combo,list,conf) \
91: if (strlen(conf) > 0) { \
92: int i; \
93: for (i=2;i<255;i+=2) { \
94: if (!strcmp(conf, list[i-2])) { \
95: gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), list[i-1]); \
96: break; \
97: } \
98: } \
99: }
100:
101: #define GetComboText(combo,list,conf) \
102: { \
103: int i; \
104: char *tmp = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry)); \
105: for (i=2;i<255;i+=2) { \
106: if (!strcmp(tmp, list[i-1])) { \
107: strcpy(conf, list[i-2]); \
108: break; \
109: } \
110: } \
111: }
112:
113: int Slots[5] = { -1, -1, -1, -1, -1 };
114:
115: void ResetMenuSlots() {
116: GtkWidget *Item;
117: char str[256];
118: int i;
119:
120: for (i=0; i<5; i++) {
121: sprintf(str, "GtkMenuItem_LoadSlot%d", i+1);
122: Item = lookup_widget(Window, str);
123: if (Slots[i] == -1)
124: gtk_widget_set_sensitive(Item, FALSE);
125: else
126: gtk_widget_set_sensitive(Item, TRUE);
127: }
128: }
129:
130: void UpdateMenuSlots() {
131: char str[256];
132: int i;
133:
134: for (i=0; i<5; i++) {
135: sprintf(str, "sstates/%10.10s.%3.3d", CdromLabel, i);
136: Slots[i] = CheckState(str);
137: }
138: }
139:
140: void StartGui() {
141: #ifdef ENABLE_NLS
142: GtkWidget *Menu;
143: GtkWidget *Item;
144: int i;
145: #endif
146:
147: Window = create_MainWindow();
148: gtk_window_set_title(GTK_WINDOW(Window), "PCSX");
149:
150: ResetMenuSlots();
151:
152: #ifdef ENABLE_NLS
153: Item = lookup_widget(Window, "GtkMenuItem_Language");
154: Menu = gtk_menu_new();
155: gtk_menu_item_set_submenu(GTK_MENU_ITEM(Item), Menu);
156:
157: for (i=0; i<langsMax; i++) {
158: Item = gtk_check_menu_item_new_with_label(ParseLang(langs[i].lang));
159: gtk_widget_show(Item);
160: gtk_container_add(GTK_CONTAINER(Menu), Item);
161: gtk_check_menu_item_set_show_toggle(GTK_CHECK_MENU_ITEM(Item), TRUE);
162: if (!strcmp(Config.Lang, langs[i].lang))
163: gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(Item), TRUE);
164:
165: gtk_signal_connect(GTK_OBJECT(Item), "activate",
166: GTK_SIGNAL_FUNC(OnLanguage),
167: (gpointer)i);
168: }
169: #endif
170:
171: gtk_widget_show_all(Window);
172: gtk_main();
173: }
174:
175: void RunGui() {
176: StartGui();
177: }
178:
179: int destroy=0;
180:
181: void OnDestroy() {
182: if (!destroy) OnFile_Exit();
183: }
184:
185: void OnLanguage(GtkMenuItem *menuitem, gpointer user_data) {
186: ChangeLanguage(langs[(int)user_data].lang);
187: destroy=1;
188: gtk_widget_destroy(Window);
189: destroy=0;
190: gtk_main_quit();
191: while (gtk_events_pending()) gtk_main_iteration();
192: StartGui();
193: }
194:
195: void ConfigurePlugins() {
196: if (!UseGui) return;
197: OnConf_Conf();
198: }
199:
200: void ConfigureMemcards() {
201: OnConf_Mcds();
202: }
203:
204: void OnRunExe_Ok() {
205: gchar *File;
206: char exe[256];
207:
208: File = gtk_file_selection_get_filename(GTK_FILE_SELECTION(FileSel));
209: strcpy(exe, File);
210: gtk_widget_destroy(FileSel);
211: destroy=1;
212: gtk_widget_destroy(Window);
213: destroy=0;
214: gtk_main_quit();
215: while (gtk_events_pending()) gtk_main_iteration();
216: if (OpenPlugins() == -1) { SysRunGui(); return; }
217: SysReset();
218: needreset = 0;
219: Load(exe);
220: psxCpu->Execute();
221: }
222:
223: void OnRunExe_Cancel() {
224: gtk_widget_destroy(FileSel);
225: }
226:
227: void OnFile_RunExe() {
228: GtkWidget *Ok,*Cancel;
229:
230: FileSel = gtk_file_selection_new(_("Select Psx Exe File"));
231:
232: Ok = GTK_FILE_SELECTION(FileSel)->ok_button;
233: gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnRunExe_Ok), NULL);
234: gtk_widget_show(Ok);
235:
236: Cancel = GTK_FILE_SELECTION(FileSel)->cancel_button;
237: gtk_signal_connect (GTK_OBJECT(Cancel), "clicked", GTK_SIGNAL_FUNC(OnRunExe_Cancel), NULL);
238: gtk_widget_show(Cancel);
239:
240: gtk_widget_show(FileSel);
241: gdk_window_raise(FileSel->window);
242: }
243:
244: void OnFile_RunCd() {
245: LoadCdBios = 0;
246: destroy=1;
247: gtk_widget_destroy(Window);
248: destroy=0;
249: gtk_main_quit();
250: while (gtk_events_pending()) gtk_main_iteration();
251: if (OpenPlugins() == -1) { SysRunGui(); return; }
252: SysReset();
253: needreset = 0;
254: CheckCdrom();
255: if (LoadCdrom() == -1) {
256: ClosePlugins();
257: SysMessage(_("Could not load Cdrom\n"));
258: return;
259: }
260: psxCpu->Execute();
261: }
262:
263: void OnFile_RunCdBios() {
264: LoadCdBios = 1;
265: destroy=1;
266: gtk_widget_destroy(Window);
267: destroy=0;
268: gtk_main_quit();
269: while (gtk_events_pending()) gtk_main_iteration();
270: if (OpenPlugins() == -1) { SysRunGui(); return; }
271: SysReset();
272: needreset = 0;
273: CheckCdrom();
274: psxCpu->Execute();
275: }
276:
277: void OnFile_Exit() {
278: DIR *dir;
279: struct dirent *ent;
280: void *Handle;
281: char plugin[256];
282:
283: // with this the problem with plugins that are linked with the pthread
284: // library is solved
285:
286: dir = opendir(Config.PluginsDir);
287: if (dir != NULL) {
288: while ((ent = readdir(dir)) != NULL) {
289: sprintf (plugin, "%s%s", Config.PluginsDir, ent->d_name);
290:
291: if (strstr(plugin, ".so") == NULL) continue;
292: Handle = dlopen(plugin, RTLD_NOW);
293: if (Handle == NULL) continue;
294: }
295: }
296:
297: printf (_("PCSX Quitting\n"));
298: if (UseGui) gtk_main_quit();
299: SysClose();
300: if (UseGui) gtk_exit(0);
301: else exit(0);
302: }
303:
304: void States_Load(int num) {
305: char Text[256];
306: int ret;
307:
308: destroy=1;
309: gtk_widget_destroy(Window);
310: destroy=0;
311: gtk_main_quit();
312: while (gtk_events_pending()) gtk_main_iteration();
313: if (OpenPlugins() == -1) { SysRunGui(); return; }
314: SysReset();
315: needreset = 0;
316:
317: sprintf (Text, "sstates/%10.10s.%3.3d", CdromLabel, num);
318: ret = LoadState(Text);
319: if (ret == 0)
320: sprintf (Text, _("*PCSX*: Loaded State %d"), num+1);
321: else sprintf (Text, _("*PCSX*: Error Loading State %d"), num+1);
322: GPU_displayText(Text);
323:
324: psxCpu->Execute();
325: }
326:
327: void States_Save(int num) {
328: char Text[256];
329: int ret;
330:
331: destroy=1;
332: gtk_widget_destroy(Window);
333: destroy=0;
334: gtk_main_quit();
335: while (gtk_events_pending()) gtk_main_iteration();
336: if (OpenPlugins() == -1) { SysRunGui(); return; }
337: if (needreset) {
338: SysReset();
339: needreset = 0;
340: }
341: GPU_updateLace();
342:
343: sprintf (Text, "sstates/%10.10s.%3.3d", CdromLabel, num);
344: GPU_freeze(2, (GPUFreeze_t *)&num);
345: ret = SaveState(Text);
346: if (ret == 0)
347: sprintf (Text, _("*PCSX*: Saved State %d"), num+1);
348: else sprintf (Text, _("*PCSX*: Error Saving State %d"), num+1);
349: GPU_displayText(Text);
350:
351: psxCpu->Execute();
352: }
353:
354: void OnStates_Load1() { States_Load(0); }
355: void OnStates_Load2() { States_Load(1); }
356: void OnStates_Load3() { States_Load(2); }
357: void OnStates_Load4() { States_Load(3); }
358: void OnStates_Load5() { States_Load(4); }
359:
360: void OnLoadOther_Ok() {
361: gchar *File;
362: char str[256];
363: char Text[256];
364: int ret;
365:
366: File = gtk_file_selection_get_filename(GTK_FILE_SELECTION(FileSel));
367: strcpy(str, File);
368: gtk_widget_destroy(FileSel);
369: destroy=1;
370: gtk_widget_destroy(Window);
371: destroy=0;
372: gtk_main_quit();
373: while (gtk_events_pending()) gtk_main_iteration();
374: if (OpenPlugins() == -1) { SysRunGui(); return; }
375: SysReset();
376: needreset = 0;
377:
378: ret = LoadState(str);
379: if (ret == 0)
380: sprintf (Text, _("*PCSX*: Loaded State %s"), str);
381: else sprintf (Text, _("*PCSX*: Error Loading State %s"), str);
382: GPU_displayText(Text);
383:
384: psxCpu->Execute();
385: }
386:
387: void OnLoadOther_Cancel() {
388: gtk_widget_destroy(FileSel);
389: }
390:
391: void OnStates_LoadOther() {
392: GtkWidget *Ok,*Cancel;
393:
394: FileSel = gtk_file_selection_new(_("Select State File"));
395: gtk_file_selection_set_filename(GTK_FILE_SELECTION(FileSel), "sstates/");
396:
397: Ok = GTK_FILE_SELECTION(FileSel)->ok_button;
398: gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnLoadOther_Ok), NULL);
399: gtk_widget_show(Ok);
400:
401: Cancel = GTK_FILE_SELECTION(FileSel)->cancel_button;
402: gtk_signal_connect (GTK_OBJECT(Cancel), "clicked", GTK_SIGNAL_FUNC(OnLoadOther_Cancel), NULL);
403: gtk_widget_show(Cancel);
404:
405: gtk_widget_show(FileSel);
406: gdk_window_raise(FileSel->window);
407: }
408:
409: void OnStates_Save1() { States_Save(0); }
410: void OnStates_Save2() { States_Save(1); }
411: void OnStates_Save3() { States_Save(2); }
412: void OnStates_Save4() { States_Save(3); }
413: void OnStates_Save5() { States_Save(4); }
414:
415: void OnSaveOther_Ok() {
416: gchar *File;
417: char str[256];
418: char Text[256];
419: int ret;
420:
421: File = gtk_file_selection_get_filename(GTK_FILE_SELECTION(FileSel));
422: strcpy(str, File);
423: gtk_widget_destroy(FileSel);
424: destroy=1;
425: gtk_widget_destroy(Window);
426: destroy=0;
427: gtk_main_quit();
428: while (gtk_events_pending()) gtk_main_iteration();
429: if (OpenPlugins() == -1) { SysRunGui(); return; }
430: if (needreset) {
431: SysReset();
432: needreset = 0;
433: }
434: GPU_updateLace();
435:
436: ret = SaveState(str);
437: if (ret == 0)
438: sprintf (Text, _("*PCSX*: Saved State %s"), str);
439: else sprintf (Text, _("*PCSX*: Error Saving State %s"), str);
440: GPU_displayText(Text);
441:
442: psxCpu->Execute();
443: }
444:
445: void OnSaveOther_Cancel() {
446: gtk_widget_destroy(FileSel);
447: }
448:
449: void OnStates_SaveOther() {
450: GtkWidget *Ok,*Cancel;
451:
452: FileSel = gtk_file_selection_new(_("Select State File"));
453: gtk_file_selection_set_filename(GTK_FILE_SELECTION(FileSel), "sstates/");
454:
455: Ok = GTK_FILE_SELECTION(FileSel)->ok_button;
456: gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnSaveOther_Ok), NULL);
457: gtk_widget_show(Ok);
458:
459: Cancel = GTK_FILE_SELECTION(FileSel)->cancel_button;
460: gtk_signal_connect (GTK_OBJECT(Cancel), "clicked", GTK_SIGNAL_FUNC(OnSaveOther_Cancel), NULL);
461: gtk_widget_show(Cancel);
462:
463: gtk_widget_show(FileSel);
464: gdk_window_raise(FileSel->window);
465: }
466:
467: void OnEmu_Run() {
468: destroy=1;
469: gtk_widget_destroy(Window);
470: destroy=0;
471: gtk_main_quit();
472: while (gtk_events_pending()) gtk_main_iteration();
473: if (OpenPlugins() == -1) { SysRunGui(); return; }
474: if (needreset) { SysReset(); needreset = 0; }
475: psxCpu->Execute();
476: }
477:
478: void OnEmu_Reset() {
479: needreset = 1;
480: }
481:
482: void OnConf_Gpu() {
483: gtk_widget_set_sensitive(Window, FALSE);
484: while (gtk_events_pending()) gtk_main_iteration();
485: if (GPU_configure) GPU_configure();
486: gtk_widget_set_sensitive(Window, TRUE);
487: }
488:
489: void OnConf_Spu() {
490: gtk_widget_set_sensitive(Window, FALSE);
491: while (gtk_events_pending()) gtk_main_iteration();
492: if (SPU_configure) SPU_configure();
493: gtk_widget_set_sensitive(Window, TRUE);
494: }
495:
496: void OnConf_Cdr() {
497: gtk_widget_set_sensitive(Window, FALSE);
498: while (gtk_events_pending()) gtk_main_iteration();
499: if (CDR_configure) CDR_configure();
500: gtk_widget_set_sensitive(Window, TRUE);
501: }
502:
503: void OnConf_Pads() {
504: gtk_widget_set_sensitive(Window, FALSE);
505: while (gtk_events_pending()) gtk_main_iteration();
506: if (PAD1_configure) PAD1_configure();
507: if (strcmp(Config.Pad1, Config.Pad2)) if (PAD2_configure) PAD2_configure();
508: gtk_widget_set_sensitive(Window, TRUE);
509: }
510:
511: GtkWidget *NetDlg;
512:
513: void OnNet_Ok() {
514: GetComboText(NetConfS.Combo, NetConfS.plist, Config.Net);
515:
516: SaveConfig();
517:
518: ReleasePlugins();
519: LoadPlugins();
520: needreset = 1;
521:
522: gtk_widget_destroy(NetDlg);
523: gtk_widget_set_sensitive(Window, TRUE);
524: gtk_main_quit();
525: }
526:
527: void OnNet_Cancel() {
528: gtk_widget_destroy(NetDlg);
529: gtk_widget_set_sensitive(Window, TRUE);
530: gtk_main_quit();
531: }
532:
533: void OnConf_Net() {
534: NetDlg = create_NetDlg();
535:
536: FindNetPlugin();
537:
538: gtk_widget_show_all(NetDlg);
539: gtk_widget_set_sensitive(Window, FALSE);
540: gtk_main();
541: }
542:
543: GtkWidget *McdDlg;
544: GtkWidget *Entry1,*Entry2;
545: GtkWidget *List1,*List2;
546: GtkWidget *BtnPaste;
547: GTimer *Gtimer;
548: int timer;
549: McdBlock Blocks[2][15];
550: int IconC[2][15];
551:
552: void SetIcon(short *icon, GtkWidget *List, int i) {
553: GdkPixmap *pixmap;
554: GdkImage *image;
555: GdkVisual *visual;
556: GdkGC *gc;
557: int x, y, c;
558:
559: visual = gdk_window_get_visual(McdDlg->window);
560:
561: if (visual->depth == 8) return;
562:
563: image = gdk_image_new(GDK_IMAGE_NORMAL, visual, 16, 16);
564:
565: for (y=0; y<16; y++) {
566: for (x=0; x<16; x++) {
567: c = icon[y*16+x];
568: c = ((c&0x001f) << 10) | ((c&0x7c00) >> 10) | (c&0x03e0);
569: if (visual->depth == 16)
570: c = (c&0x001f) | ((c&0x7c00) << 1) | ((c&0x03e0) << 1);
571: else if (visual->depth == 24 || visual->depth == 32)
572: c = ((c&0x001f) << 3) | ((c&0x03e0) << 6) | ((c&0x7c00) << 9);
573:
574: gdk_image_put_pixel(image, x, y, c);
575: }
576: }
577:
578: pixmap = gdk_pixmap_new(McdDlg->window, 16, 16, visual->depth);
579:
580: gc = gdk_gc_new(pixmap);
581: gdk_draw_image(pixmap, gc, image, 0, 0, 0, 0, 16, 16);
582: gdk_gc_destroy(gc);
583: gdk_image_destroy(image);
584:
585: gtk_clist_set_pixmap(GTK_CLIST(List), i-1, 0, pixmap, NULL);
586: }
587:
588: void LoadListItems(int mcd, GtkWidget *List) {
589: int i;
590:
591: gtk_clist_clear(GTK_CLIST(List));
592:
593: for (i=1; i<16; i++) {
594: McdBlock *Info;
595: gchar *text[5];
596:
597: Info = &Blocks[mcd-1][i-1];
598: IconC[mcd-1][i-1] = 0;
599:
600: if ((Info->Flags & 0xF0) == 0xA0) {
601: if ((Info->Flags & 0xF) >= 1 &&
602: (Info->Flags & 0xF) <= 3) {
603: text[2] = _("Deleted");
604: } else text[2] = _("Free");
605: } else if ((Info->Flags & 0xF0) == 0x50)
606: text[2] = _("Used");
607: else { text[2] = _("Free"); }
608:
609: text[0] = "";
610: text[1] = Info->Title;
611: text[3] = Info->ID;
612: text[4] = Info->Name;
613:
614: gtk_clist_insert(GTK_CLIST(List), i-1, text);
615:
616: if (Info->IconCount == 0) continue;
617:
618: SetIcon(Info->Icon, List, i);
619: }
620: }
621:
622: void UpdateListItems(int mcd, GtkWidget *List) {
623: int i,j;
624:
625: for (i=1; i<16; i++) {
626: McdBlock *Info;
627: gchar *text[5];
628:
629: Info = &Blocks[mcd-1][i-1];
630: IconC[mcd-1][i-1] = 0;
631:
632: if ((Info->Flags & 0xF0) == 0xA0) {
633: if ((Info->Flags & 0xF) >= 1 &&
634: (Info->Flags & 0xF) <= 3) {
635: text[2] = _("Deleted");
636: } else text[2] = _("Free");
637: } else if ((Info->Flags & 0xF0) == 0x50)
638: text[2] = _("Used");
639: else { text[2] = _("Free"); }
640:
641: text[0] = "";
642: text[1] = Info->Title;
643: text[3] = Info->ID;
644: text[4] = Info->Name;
645:
646: for (j=0; j<5; j++)
647: gtk_clist_set_text(GTK_CLIST(List), i-1, j, text[j]);
648:
649: if (Info->IconCount == 0) continue;
650:
651: SetIcon(Info->Icon, List, i);
652: }
653: }
654:
655: void LoadMcdDlg() {
656: int i;
657:
658: for (i=1; i<16; i++) GetMcdBlockInfo(1, i, &Blocks[0][i-1]);
659: for (i=1; i<16; i++) GetMcdBlockInfo(2, i, &Blocks[1][i-1]);
660: LoadListItems(1, List1);
661: LoadListItems(2, List2);
662: }
663:
664: void UpdateMcdDlg() {
665: int i;
666:
667: for (i=1; i<16; i++) GetMcdBlockInfo(1, i, &Blocks[0][i-1]);
668: for (i=1; i<16; i++) GetMcdBlockInfo(2, i, &Blocks[1][i-1]);
669: UpdateListItems(1, List1);
670: UpdateListItems(2, List2);
671: }
672:
673: void StopTimer() {
674: g_timer_stop(Gtimer); timer = 0;
675: }
676:
677: void OnMcd_Ok() {
678: char *tmp;
679:
680: StopTimer();
681:
682: tmp = gtk_entry_get_text(GTK_ENTRY(Entry1));
683: strcpy(Config.Mcd1, tmp);
684: tmp = gtk_entry_get_text(GTK_ENTRY(Entry2));
685: strcpy(Config.Mcd2, tmp);
686:
687: SaveConfig();
688: LoadMcds(Config.Mcd1, Config.Mcd2);
689:
690: gtk_widget_destroy(McdDlg);
691: if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE);
692: // gtk_main_quit();
693: }
694:
695: void OnMcd_Cancel() {
696: StopTimer();
697:
698: LoadMcds(Config.Mcd1, Config.Mcd2);
699:
700: gtk_widget_destroy(McdDlg);
701: if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE);
702: // gtk_main_quit();
703: }
704:
705: void OnMcdFS1_Ok() {
706: gchar *File;
707:
708: File = gtk_file_selection_get_filename(GTK_FILE_SELECTION(FileSel));
709: gtk_entry_set_text(GTK_ENTRY(Entry1), File);
710:
711: LoadMcd(1, File);
712: UpdateMcdDlg();
713:
714: gtk_widget_destroy(FileSel);
715: }
716:
717: void OnMcdFS2_Ok() {
718: gchar *File;
719:
720: File = gtk_file_selection_get_filename(GTK_FILE_SELECTION(FileSel));
721: gtk_entry_set_text(GTK_ENTRY(Entry2), File);
722:
723: LoadMcd(2, File);
724: UpdateMcdDlg();
725:
726: gtk_widget_destroy(FileSel);
727: }
728:
729: void OnMcdFS_Cancel() {
730: gtk_widget_destroy(FileSel);
731: }
732:
733: void OnMcd_FS1() {
734: GtkWidget *Ok,*Cancel;
735:
736: FileSel = gtk_file_selection_new(_("Select Psx Mcd File"));
737: gtk_file_selection_set_filename(GTK_FILE_SELECTION(FileSel), gtk_entry_get_text(GTK_ENTRY(Entry1)));
738:
739: Ok = GTK_FILE_SELECTION(FileSel)->ok_button;
740: gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnMcdFS1_Ok), NULL);
741: gtk_widget_show(Ok);
742:
743: Cancel = GTK_FILE_SELECTION(FileSel)->cancel_button;
744: gtk_signal_connect (GTK_OBJECT(Cancel), "clicked", GTK_SIGNAL_FUNC(OnMcdFS_Cancel), NULL);
745: gtk_widget_show(Cancel);
746:
747: gtk_widget_show(FileSel);
748: gdk_window_raise(FileSel->window);
749: }
750:
751: void OnMcd_FS2() {
752: GtkWidget *Ok,*Cancel;
753:
754: FileSel = gtk_file_selection_new(_("Select Psx Mcd File"));
755: gtk_file_selection_set_filename(GTK_FILE_SELECTION(FileSel), gtk_entry_get_text(GTK_ENTRY(Entry2)));
756:
757: Ok = GTK_FILE_SELECTION(FileSel)->ok_button;
758: gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnMcdFS2_Ok), NULL);
759: gtk_widget_show(Ok);
760:
761: Cancel = GTK_FILE_SELECTION(FileSel)->cancel_button;
762: gtk_signal_connect (GTK_OBJECT(Cancel), "clicked", GTK_SIGNAL_FUNC(OnMcdFS_Cancel), NULL);
763: gtk_widget_show(Cancel);
764:
765: gtk_widget_show(FileSel);
766: gdk_window_raise(FileSel->window);
767: }
768:
769: GtkWidget *MsgBoxDlg;
770: int yes;
771:
772: void OnMsgBox_Yes() {
773: yes = 1;
774: gtk_widget_destroy(MsgBoxDlg);
775: gtk_main_quit();
776: }
777:
778: void OnMsgBox_No() {
779: yes = 0;
780: gtk_widget_destroy(MsgBoxDlg);
781: gtk_main_quit();
782: }
783:
784: int MessageBox(char *msg, char *title) {
785: GtkWidget *Ok,*Txt;
786: GtkWidget *Box,*Box1;
787: int w;
788:
789: if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0;
790:
791: w = strlen(msg) * 6 + 20;
792:
793: MsgBoxDlg = gtk_window_new (GTK_WINDOW_DIALOG);
794: gtk_widget_set_usize(MsgBoxDlg, w, 70);
795: gtk_window_set_position(GTK_WINDOW(MsgBoxDlg), GTK_WIN_POS_CENTER);
796: gtk_window_set_title(GTK_WINDOW(MsgBoxDlg), title);
797: gtk_container_set_border_width(GTK_CONTAINER(MsgBoxDlg), 0);
798:
799: Box = gtk_vbox_new(0, 0);
800: gtk_container_add(GTK_CONTAINER(MsgBoxDlg), Box);
801: gtk_widget_show(Box);
802:
803: Txt = gtk_label_new(msg);
804:
805: gtk_box_pack_start(GTK_BOX(Box), Txt, FALSE, FALSE, 5);
806: gtk_widget_show(Txt);
807:
808: Box1 = gtk_hbutton_box_new();
809: gtk_box_pack_start(GTK_BOX(Box), Box1, FALSE, FALSE, 0);
810: gtk_widget_show(Box1);
811:
812: Ok = gtk_button_new_with_label(_("Yes"));
813: gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnMsgBox_Yes), NULL);
814: gtk_container_add(GTK_CONTAINER(Box1), Ok);
815: GTK_WIDGET_SET_FLAGS(Ok, GTK_CAN_DEFAULT);
816: gtk_widget_show(Ok);
817:
818: Ok = gtk_button_new_with_label(_("No"));
819: gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnMsgBox_No), NULL);
820: gtk_container_add(GTK_CONTAINER(Box1), Ok);
821: GTK_WIDGET_SET_FLAGS(Ok, GTK_CAN_DEFAULT);
822: gtk_widget_show(Ok);
823:
824: gtk_widget_show(MsgBoxDlg);
825:
826: gtk_main();
827:
828: return yes;
829: }
830:
831: void OnMcd_Format1() {
832: char *str;
833:
834: if (MessageBox(_("Are you sure you want to format this Memory Card?"), _("Confirmation")) == 0) return;
835: str = gtk_entry_get_text(GTK_ENTRY(Entry1));
836: CreateMcd(str);
837: LoadMcd(1, str);
838: UpdateMcdDlg();
839: }
840:
841: void OnMcd_Format2() {
842: char *str;
843:
844: if (MessageBox(_("Are you sure you want to format this Memory Card?"), _("Confirmation")) == 0) return;
845: str = gtk_entry_get_text(GTK_ENTRY(Entry2));
846: CreateMcd(str);
847: LoadMcd(2, str);
848: UpdateMcdDlg();
849: }
850:
851: void OnMcd_Reload1() {
852: char *str;
853:
854: str = gtk_entry_get_text(GTK_ENTRY(Entry1));
855: LoadMcd(1, str);
856: UpdateMcdDlg();
857: }
858:
859: void OnMcd_Reload2() {
860: char *str;
861:
862: str = gtk_entry_get_text(GTK_ENTRY(Entry2));
863: LoadMcd(2, str);
864: UpdateMcdDlg();
865: }
866:
867: static int copy = 0, copymcd = 0;
868:
869: void OnMcd_CopyTo1() {
870: int i = GTK_CLIST(List2)->focus_row;
871:
872: copy = i;
873: copymcd = 1;
874:
875: gtk_widget_set_sensitive(BtnPaste, TRUE);
876: }
877:
878: void OnMcd_CopyTo2() {
879: int i = GTK_CLIST(List1)->focus_row;
880:
881: copy = i;
882: copymcd = 2;
883:
884: gtk_widget_set_sensitive(BtnPaste, TRUE);
885: }
886:
887: void OnMcd_Paste() {
888: int i;
889: char *str;
890:
891: if (MessageBox(_("Are you sure you want to paste this selection?"), _("Confirmation")) == 0) return;
892:
893: if (copymcd == 1) {
894: str = gtk_entry_get_text(GTK_ENTRY(Entry1));
895: i = GTK_CLIST(List1)->focus_row;
896:
897: // save dir data + save data
898: memcpy(Mcd1Data + (i+1) * 128, Mcd2Data + (copy+1) * 128, 128);
899: SaveMcd(str, Mcd1Data, (i+1) * 128, 128);
900: memcpy(Mcd1Data + (i+1) * 1024 * 8, Mcd2Data + (copy+1) * 1024 * 8, 1024 * 8);
901: SaveMcd(str, Mcd1Data, (i+1) * 1024 * 8, 1024 * 8);
902: } else { // 2
903: str = gtk_entry_get_text(GTK_ENTRY(Entry2));
904: i = GTK_CLIST(List2)->focus_row;
905:
906: // save dir data + save data
907: memcpy(Mcd2Data + (i+1) * 128, Mcd1Data + (copy+1) * 128, 128);
908: SaveMcd(str, Mcd2Data, (i+1) * 128, 128);
909: memcpy(Mcd2Data + (i+1) * 1024 * 8, Mcd1Data + (copy+1) * 1024 * 8, 1024 * 8);
910: SaveMcd(str, Mcd2Data, (i+1) * 1024 * 8, 1024 * 8);
911: }
912:
913: UpdateMcdDlg();
914: }
915:
916: void OnMcd_Delete1() {
917: McdBlock *Info;
918: int mcd = 1;
919: int i, xor = 0, j;
920: unsigned char *data, *ptr;
921: char *str;
922:
923: str = gtk_entry_get_text(GTK_ENTRY(Entry1));
924: i = GTK_CLIST(List1)->focus_row;
925: data = Mcd1Data;
926:
927: i++;
928:
929: ptr = data + i * 128;
930:
931: Info = &Blocks[mcd-1][i-1];
932:
933: if ((Info->Flags & 0xF0) == 0xA0) {
934: if ((Info->Flags & 0xF) >= 1 &&
935: (Info->Flags & 0xF) <= 3) { // deleted
936: *ptr = 0x50 | (Info->Flags & 0xF);
937: } else return;
938: } else if ((Info->Flags & 0xF0) == 0x50) { // used
939: *ptr = 0xA0 | (Info->Flags & 0xF);
940: } else { return; }
941:
942: for (j=0; j<127; j++) xor^=*ptr++;
943: *ptr = xor;
944:
945: SaveMcd(str, data, i * 128, 128);
946: UpdateMcdDlg();
947: }
948:
949: void OnMcd_Delete2() {
950: McdBlock *Info;
951: int mcd = 2;
952: int i, xor = 0, j;
953: unsigned char *data, *ptr;
954: char *str;
955:
956: str = gtk_entry_get_text(GTK_ENTRY(Entry2));
957: i = GTK_CLIST(List2)->focus_row;
958: data = Mcd2Data;
959:
960: i++;
961:
962: ptr = data + i * 128;
963:
964: Info = &Blocks[mcd-1][i-1];
965:
966: if ((Info->Flags & 0xF0) == 0xA0) {
967: if ((Info->Flags & 0xF) >= 1 &&
968: (Info->Flags & 0xF) <= 3) { // deleted
969: *ptr = 0x50 | (Info->Flags & 0xF);
970: } else return;
971: } else if ((Info->Flags & 0xF0) == 0x50) { // used
972: *ptr = 0xA0 | (Info->Flags & 0xF);
973: } else { return; }
974:
975: for (j=0; j<127; j++) xor^=*ptr++;
976: *ptr = xor;
977:
978: SaveMcd(str, data, i * 128, 128);
979: UpdateMcdDlg();
980: }
981:
982: void UpdateMcdIcon(int mcd, GtkWidget *List) {
983: int i;
984:
985: for (i=1; i<16; i++) {
986: McdBlock *Info;
987: int *count;
988:
989: Info = &Blocks[mcd-1][i-1];
990: count = &IconC[mcd-1][i-1];
991:
992: if (Info->IconCount <= 1) continue;
993:
994: (*count)++;
995: if (*count == Info->IconCount) *count = 0;
996:
997: SetIcon(&Info->Icon[*count*16*16], List, i);
998: }
999: }
1000:
1001: void OnConf_Mcds() {
1002: McdDlg = create_McdsDlg();
1003: gtk_window_set_title(GTK_WINDOW(McdDlg), _("PCSX Memcard Manager"));
1004:
1005: Entry1 = lookup_widget(McdDlg, "GtkEntry_Mcd1");
1006: if (!strlen(Config.Mcd1)) strcpy(Config.Mcd1, "memcards/Mcd001.mcr");
1007: gtk_entry_set_text(GTK_ENTRY(Entry1), Config.Mcd1);
1008:
1009: Entry2 = lookup_widget(McdDlg, "GtkEntry_Mcd2");
1010: if (!strlen(Config.Mcd2)) strcpy(Config.Mcd2, "memcards/Mcd002.mcr");
1011: gtk_entry_set_text(GTK_ENTRY(Entry2), Config.Mcd2);
1012:
1013: List1 = lookup_widget(McdDlg, "GtkCList_McdList1");
1014: List2 = lookup_widget(McdDlg, "GtkCList_McdList2");
1015:
1016: BtnPaste = lookup_widget(McdDlg, "GtkButton_McdPaste");
1017: gtk_widget_set_sensitive(BtnPaste, FALSE);
1018:
1019: gtk_clist_set_column_justification(GTK_CLIST(List1), 0, GTK_JUSTIFY_CENTER);
1020: gtk_clist_set_column_justification(GTK_CLIST(List2), 0, GTK_JUSTIFY_CENTER);
1021: gtk_clist_set_column_justification(GTK_CLIST(List1), 2, GTK_JUSTIFY_CENTER);
1022: gtk_clist_set_column_justification(GTK_CLIST(List2), 2, GTK_JUSTIFY_CENTER);
1023:
1024: gtk_widget_show_all(McdDlg);
1025:
1026: LoadMcdDlg();
1027:
1028: if (Window != NULL) gtk_widget_set_sensitive(Window, FALSE);
1029:
1030: Gtimer = g_timer_new(); timer = 1;
1031:
1032: while (gtk_events_pending()) gtk_main_iteration();
1033:
1034: while (timer) {
1035: unsigned long usecs;
1036:
1037: g_timer_elapsed(Gtimer, &usecs);
1038: if (usecs > 250000) {
1039: UpdateMcdIcon(1, List1);
1040: UpdateMcdIcon(2, List2);
1041: g_timer_reset(Gtimer);
1042: }
1043:
1044: while (gtk_events_pending()) gtk_main_iteration();
1045: usleep(10000);
1046: }
1047: }
1048:
1049: GtkWidget *CpuDlg;
1050: GtkWidget *PsxCombo;
1051: GList *psxglist;
1052: char *psxtypes[] = {
1053: "NTSC",
1054: "PAL"
1055: };
1056:
1057: void OnCpu_Ok() {
1058: GtkWidget *Btn;
1059: char *tmp;
1060: long t;
1061:
1062: tmp = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(PsxCombo)->entry));
1063:
1064: if (!strcmp("NTSC",tmp)) Config.PsxType = 0;
1065: else Config.PsxType = 1; // pal
1066:
1067: Btn = lookup_widget(CpuDlg, "GtkCheckButton_Xa");
1068: Config.Xa = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn));
1069:
1070: Btn = lookup_widget(CpuDlg, "GtkCheckButton_Sio");
1071: Config.Sio = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn));
1072:
1073: Btn = lookup_widget(CpuDlg, "GtkCheckButton_Mdec");
1074: Config.Mdec = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn));
1075:
1076: Btn = lookup_widget(CpuDlg, "GtkCheckButton_Cdda");
1077: Config.Cdda = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn));
1078:
1079: Btn = lookup_widget(CpuDlg, "GtkCheckButton_PsxAuto");
1080: Config.PsxAuto = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn));
1081:
1082: t = Config.Cpu;
1083: Btn = lookup_widget(CpuDlg, "GtkCheckButton_Cpu");
1084: Config.Cpu = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn));
1085: if (t != Config.Cpu) {
1086: psxCpu->Shutdown();
1087: if (Config.Cpu)
1088: psxCpu = &psxInt;
1089: else psxCpu = &psxRec;
1090: if (psxCpu->Init() == -1) {
1091: SysClose();
1092: exit(1);
1093: }
1094: psxCpu->Reset();
1095: }
1096:
1097: Btn = lookup_widget(CpuDlg, "GtkCheckButton_PsxOut");
1098: Config.PsxOut = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn));
1099:
1100: Btn = lookup_widget(CpuDlg, "GtkCheckButton_SpuIrq");
1101: Config.SpuIrq = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn));
1102:
1103: Btn = lookup_widget(CpuDlg, "GtkCheckButton_RCntFix");
1104: Config.RCntFix = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn));
1105:
1106: Btn = lookup_widget(CpuDlg, "GtkCheckButton_VSyncWA");
1107: Config.VSyncWA = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn));
1108:
1109: gtk_widget_destroy(CpuDlg);
1110:
1111: SaveConfig();
1112: if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE);
1113: gtk_main_quit();
1114: }
1115:
1116: void OnCpu_Cancel() {
1117: gtk_widget_destroy(CpuDlg);
1118: if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE);
1119: gtk_main_quit();
1120: }
1121:
1122:
1123: void OnConf_Cpu() {
1124: GtkWidget *Btn;
1125: int i;
1126:
1127: CpuDlg = create_CpuDlg();
1128: gtk_window_set_title(GTK_WINDOW(CpuDlg), _("PCSX Configuration"));
1129:
1130: psxglist = NULL;
1131: for (i=0;i<2;i++)
1132: psxglist = g_list_append(psxglist, psxtypes[i]);
1133: PsxCombo = lookup_widget(CpuDlg, "GtkCombo_PsxType");
1134: gtk_combo_set_popdown_strings(GTK_COMBO(PsxCombo), psxglist);
1135: gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(PsxCombo)->entry), psxtypes[Config.PsxType]);
1136:
1137: Btn = lookup_widget(CpuDlg, "GtkCheckButton_Xa");
1138: gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.Xa);
1139:
1140: Btn = lookup_widget(CpuDlg, "GtkCheckButton_Sio");
1141: gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.Sio);
1142:
1143: Btn = lookup_widget(CpuDlg, "GtkCheckButton_Mdec");
1144: gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.Mdec);
1145:
1146: Btn = lookup_widget(CpuDlg, "GtkCheckButton_Cdda");
1147: gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.Cdda);
1148:
1149: Btn = lookup_widget(CpuDlg, "GtkCheckButton_PsxAuto");
1150: gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.PsxAuto);
1151:
1152: Btn = lookup_widget(CpuDlg, "GtkCheckButton_Cpu");
1153: gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.Cpu);
1154:
1155: Btn = lookup_widget(CpuDlg, "GtkCheckButton_PsxOut");
1156: gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.PsxOut);
1157:
1158: Btn = lookup_widget(CpuDlg, "GtkCheckButton_SpuIrq");
1159: gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.SpuIrq);
1160:
1161: Btn = lookup_widget(CpuDlg, "GtkCheckButton_RCntFix");
1162: gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.RCntFix);
1163:
1164: Btn = lookup_widget(CpuDlg, "GtkCheckButton_VSyncWA");
1165: gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.VSyncWA);
1166:
1167: gtk_widget_show_all(CpuDlg);
1168: if (Window != NULL) gtk_widget_set_sensitive(Window, FALSE);
1169: gtk_main();
1170: }
1171:
1172: void OnConfConf_Ok() {
1173: GetComboText(GpuConfS.Combo, GpuConfS.plist, Config.Gpu);
1174: GetComboText(SpuConfS.Combo, SpuConfS.plist, Config.Spu);
1175: GetComboText(CdrConfS.Combo, CdrConfS.plist, Config.Cdr);
1176: GetComboText(Pad1ConfS.Combo, Pad1ConfS.plist, Config.Pad1);
1177: GetComboText(Pad2ConfS.Combo, Pad2ConfS.plist, Config.Pad2);
1178: GetComboText(BiosConfS.Combo, BiosConfS.plist, Config.Bios);
1179:
1180: SaveConfig();
1181:
1182: ReleasePlugins();
1183: LoadPlugins();
1184:
1185: needreset = 1;
1186: gtk_widget_destroy(ConfDlg);
1187: if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE);
1188: gtk_main_quit();
1189: }
1190:
1191: void OnConfConf_Cancel() {
1192: gtk_widget_destroy(ConfDlg);
1193: if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE);
1194: gtk_main_quit();
1195: if (CancelQuit == 1)
1196: OnFile_Exit();
1197: }
1198:
1199: #define ConfPlugin(src, confs, plugin, name) \
1200: void *drv; \
1201: src conf; \
1202: char file[256]; \
1203: \
1204: GetComboText(confs.Combo, confs.plist, plugin); \
1205: strcpy(file, Config.PluginsDir); \
1206: strcat(file, plugin); \
1207: drv = SysLoadLibrary(file); \
1208: if (drv == NULL) return; \
1209: \
1210: gtk_widget_set_sensitive(ConfDlg, FALSE); \
1211: while (gtk_events_pending()) gtk_main_iteration(); \
1212: conf = (src) SysLoadSym(drv, name); \
1213: if (conf) { \
1214: conf(); \
1215: } else SysMessage(_("Plugin doesn't needs to be configured")); \
1216: SysCloseLibrary(drv); \
1217: gtk_widget_set_sensitive(ConfDlg, TRUE);
1218:
1219: #define TestPlugin(src, confs, plugin, name) \
1220: void *drv; \
1221: src conf; \
1222: int ret = 0; \
1223: char file[256]; \
1224: \
1225: GetComboText(confs.Combo, confs.plist, plugin); \
1226: strcpy(file, Config.PluginsDir); \
1227: strcat(file, plugin); \
1228: drv = SysLoadLibrary(file); \
1229: if (drv == NULL) return; \
1230: \
1231: gtk_widget_set_sensitive(ConfDlg, FALSE); \
1232: while (gtk_events_pending()) gtk_main_iteration(); \
1233: conf = (src) SysLoadSym(drv, name); \
1234: if (SysLibError() == NULL) ret = conf(); \
1235: SysCloseLibrary(drv); \
1236: if (ret == 0) \
1237: SysMessage("This plugin reports that should work correctly"); \
1238: else SysMessage("This plugin reports that should not work correctly"); \
1239: gtk_widget_set_sensitive(ConfDlg, TRUE);
1240:
1241: void OnConfConf_GpuConf() {
1242: ConfPlugin(GPUconfigure, GpuConfS, Config.Gpu, "GPUconfigure");
1243: }
1244:
1245: void OnConfConf_GpuTest() {
1246: TestPlugin(GPUtest, GpuConfS, Config.Gpu, "GPUtest");
1247: }
1248:
1249: void OnConfConf_GpuAbout() {
1250: ConfPlugin(GPUabout, GpuConfS, Config.Gpu, "GPUabout");
1251: }
1252:
1253: void OnConfConf_SpuConf() {
1254: ConfPlugin(SPUconfigure, SpuConfS, Config.Spu, "SPUconfigure");
1255: }
1256:
1257: void OnConfConf_SpuTest() {
1258: TestPlugin(SPUtest, SpuConfS, Config.Spu, "SPUtest");
1259: }
1260:
1261: void OnConfConf_SpuAbout() {
1262: ConfPlugin(SPUabout, SpuConfS, Config.Spu, "SPUabout");
1263: }
1264:
1265: void OnConfConf_CdrConf() {
1266: ConfPlugin(CDRconfigure, CdrConfS, Config.Cdr, "CDRconfigure");
1267: }
1268:
1269: void OnConfConf_CdrTest() {
1270: TestPlugin(CDRtest, CdrConfS, Config.Cdr, "CDRtest");
1271: }
1272:
1273: void OnConfConf_CdrAbout() {
1274: ConfPlugin(CDRabout, CdrConfS, Config.Cdr, "CDRabout");
1275: }
1276:
1277: void OnConfConf_Pad1Conf() {
1278: ConfPlugin(PADconfigure, Pad1ConfS, Config.Pad1, "PADconfigure");
1279: }
1280:
1281: void OnConfConf_Pad1Test() {
1282: TestPlugin(PADtest, Pad1ConfS, Config.Pad1, "PADtest");
1283: }
1284:
1285: void OnConfConf_Pad1About() {
1286: ConfPlugin(PADabout, Pad1ConfS, Config.Pad1, "PADabout");
1287: }
1288:
1289: void OnConfConf_Pad2Conf() {
1290: ConfPlugin(PADconfigure, Pad2ConfS, Config.Pad2, "PADconfigure");
1291: }
1292:
1293: void OnConfConf_Pad2Test() {
1294: TestPlugin(PADtest, Pad2ConfS, Config.Pad2, "PADtest");
1295: }
1296:
1297: void OnConfConf_Pad2About() {
1298: ConfPlugin(PADabout, Pad2ConfS, Config.Pad2, "PADabout");
1299: }
1300:
1301: void OnNet_Conf() {
1302: ConfPlugin(NETconfigure, NetConfS, Config.Net, "NETconfigure");
1303: }
1304:
1305: void OnNet_Test() {
1306: TestPlugin(NETtest, NetConfS, Config.Net, "NETtest");
1307: }
1308:
1309: void OnNet_About() {
1310: ConfPlugin(NETabout, NetConfS, Config.Net, "NETabout");
1311: }
1312:
1313:
1314:
1315: void OnPluginsPath_Ok() {
1316: gchar *File;
1317:
1318: File = gtk_file_selection_get_filename(GTK_FILE_SELECTION(FileSel));
1319: strcpy(Config.PluginsDir, File);
1320: if (Config.PluginsDir[strlen(Config.PluginsDir)-1] != '/')
1321: strcat(Config.PluginsDir, "/");
1322:
1323: FindPlugins();
1324:
1325: gtk_widget_destroy(FileSel);
1326: }
1327:
1328: void OnPluginsPath_Cancel() {
1329: gtk_widget_destroy(FileSel);
1330: }
1331:
1332: void OnConfConf_PluginsPath() {
1333: GtkWidget *Ok,*Cancel;
1334:
1335: FileSel = gtk_file_selection_new(_("Select Plugins Directory"));
1336:
1337: Ok = GTK_FILE_SELECTION(FileSel)->ok_button;
1338: gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnPluginsPath_Ok), NULL);
1339: gtk_widget_show(Ok);
1340:
1341: Cancel = GTK_FILE_SELECTION(FileSel)->cancel_button;
1342: gtk_signal_connect (GTK_OBJECT(Cancel), "clicked", GTK_SIGNAL_FUNC(OnPluginsPath_Cancel), NULL);
1343: gtk_widget_show(Cancel);
1344:
1345: gtk_widget_show(FileSel);
1346: gdk_window_raise(FileSel->window);
1347: }
1348:
1349: void OnBiosPath_Ok() {
1350: gchar *File;
1351:
1352: File = gtk_file_selection_get_filename(GTK_FILE_SELECTION(FileSel));
1353: strcpy(Config.BiosDir, File);
1354: if (Config.BiosDir[strlen(Config.BiosDir)-1] != '/')
1355: strcat(Config.BiosDir, "/");
1356:
1357: FindPlugins();
1358:
1359: gtk_widget_destroy(FileSel);
1360: }
1361:
1362: void OnBiosPath_Cancel() {
1363: gtk_widget_destroy(FileSel);
1364: }
1365:
1366: void OnConfConf_BiosPath() {
1367: GtkWidget *Ok,*Cancel;
1368:
1369: FileSel = gtk_file_selection_new(_("Select Bios Directory"));
1370:
1371: Ok = GTK_FILE_SELECTION(FileSel)->ok_button;
1372: gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnBiosPath_Ok), NULL);
1373: gtk_widget_show(Ok);
1374:
1375: Cancel = GTK_FILE_SELECTION(FileSel)->cancel_button;
1376: gtk_signal_connect (GTK_OBJECT(Cancel), "clicked", GTK_SIGNAL_FUNC(OnBiosPath_Cancel), NULL);
1377: gtk_widget_show(Cancel);
1378:
1379: gtk_widget_show(FileSel);
1380: gdk_window_raise(FileSel->window);
1381: }
1382:
1383: void OnConf_Conf() {
1384: ConfDlg = create_ConfDlg();
1385: gtk_window_set_title(GTK_WINDOW(ConfDlg), _("PCSX Configuration"));
1386:
1387: FindPlugins();
1388:
1389: gtk_widget_show_all(ConfDlg);
1390: if (Window != NULL) gtk_widget_set_sensitive(Window, FALSE);
1391: gtk_main();
1392: }
1393:
1394: void OnHelp_Help() {
1395: }
1396:
1397: void OnHelpAbout_Ok() {
1398: gtk_widget_destroy(AboutDlg);
1399: if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE);
1400: gtk_main_quit();
1401: }
1402:
1403: void OnHelp_About() {
1404: GtkWidget *Label;
1405: char text[256];
1406:
1407: AboutDlg = create_AboutDlg();
1408: gtk_window_set_title(GTK_WINDOW(AboutDlg), _("About PCSX"));
1409:
1410: Label = lookup_widget(AboutDlg, "GtkAbout_LabelVersion");
1411: sprintf(text, "PCSX For Linux\nVersion %s", PCSX_VERSION);
1412: gtk_label_set_text(GTK_LABEL(Label), text);
1413:
1414: Label = lookup_widget(AboutDlg, "GtkAbout_LabelAuthors");
1415: gtk_label_set_text(GTK_LABEL(Label), _(LabelAuthors));
1416:
1417: Label = lookup_widget(AboutDlg, "GtkAbout_LabelGreets");
1418: gtk_label_set_text(GTK_LABEL(Label), _(LabelGreets));
1419:
1420: gtk_widget_show_all(AboutDlg);
1421: if (Window != NULL) gtk_widget_set_sensitive(Window, FALSE);
1422: gtk_main();
1423: }
1424:
1425: #define ComboAddPlugin(type) { \
1426: type##ConfS.plugins+=2; \
1427: strcpy(type##ConfS.plist[type##ConfS.plugins-1], name); \
1428: strcpy(type##ConfS.plist[type##ConfS.plugins-2], ent->d_name); \
1429: type##ConfS.glist = g_list_append(type##ConfS.glist, type##ConfS.plist[type##ConfS.plugins-1]); \
1430: }
1431:
1432: #define ConfCreatePConf(name, type) \
1433: type##ConfS.Combo = lookup_widget(ConfDlg, "GtkCombo_" name); \
1434: if (type##ConfS.glist != NULL) { \
1435: gtk_combo_set_popdown_strings(GTK_COMBO(type##ConfS.Combo), type##ConfS.glist); \
1436: FindComboText(type##ConfS.Combo, type##ConfS.plist, Config.type); \
1437: }
1438:
1439: void FindPlugins() {
1440: DIR *dir;
1441: struct dirent *ent;
1442: void *Handle;
1443: char plugin[256],name[256];
1444:
1445: GpuConfS.plugins = 0; SpuConfS.plugins = 0; CdrConfS.plugins = 0;
1446: Pad1ConfS.plugins = 0; Pad2ConfS.plugins = 0; BiosConfS.plugins = 0;
1447: GpuConfS.glist = NULL; SpuConfS.glist = NULL; CdrConfS.glist = NULL;
1448: Pad1ConfS.glist = NULL; Pad2ConfS.glist = NULL; BiosConfS.glist = NULL;
1449:
1450: dir = opendir(Config.PluginsDir);
1451: if (dir == NULL) {
1452: SysMessage(_("Could not open '%s' directory\n"), Config.PluginsDir);
1453: return;
1454: }
1455: while ((ent = readdir(dir)) != NULL) {
1456: long type,v;
1457:
1458: sprintf(plugin, "%s%s", Config.PluginsDir, ent->d_name);
1459:
1460: if (strstr(plugin, ".so") == NULL) continue;
1461: Handle = dlopen(plugin, RTLD_NOW);
1462: if (Handle == NULL) { fprintf(stderr, "%s: %s\n", plugin, dlerror()); continue; }
1463:
1464: PSE_getLibType = (PSEgetLibType) dlsym(Handle, "PSEgetLibType");
1465: if (dlerror() != NULL) {
1466: if (strstr(plugin, "gpu") != NULL) type = PSE_LT_GPU;
1467: else if (strstr(plugin, "cdr") != NULL) type = PSE_LT_CDR;
1468: else if (strstr(plugin, "spu") != NULL) type = PSE_LT_SPU;
1469: else if (strstr(plugin, "pad") != NULL) type = PSE_LT_PAD;
1470: else continue;
1471: }
1472: else type = PSE_getLibType();
1473:
1474: PSE_getLibName = (PSEgetLibName) dlsym(Handle, "PSEgetLibName");
1475: if (dlerror() == NULL) {
1476: sprintf(name, "%s", PSE_getLibName());
1477: PSE_getLibVersion = (PSEgetLibVersion) dlsym(Handle, "PSEgetLibVersion");
1478: if (dlerror() == NULL) {
1479: char ver[32];
1480:
1481: v = PSE_getLibVersion();
1482: sprintf(ver, " %ld.%ld.%ld",v>>16,(v>>8)&0xff,v&0xff);
1483: strcat(name, ver);
1484: }
1485: }
1486: else strcpy(name, ent->d_name);
1487:
1488: if (type & PSE_LT_CDR) {
1489: ComboAddPlugin(Cdr);
1490: }
1491: if (type & PSE_LT_GPU) {
1492: ComboAddPlugin(Gpu);
1493: }
1494: if (type & PSE_LT_SPU) {
1495: ComboAddPlugin(Spu);
1496: }
1497: if (type & PSE_LT_PAD) {
1498: PADquery query = (PADquery)dlsym(Handle, "PADquery");
1499: if (query() & 0x1) {
1500: ComboAddPlugin(Pad1);
1501: }
1502: if (query() & 0x2) {
1503: ComboAddPlugin(Pad2);
1504: }
1505: }
1506: }
1507: closedir(dir);
1508:
1509: ConfCreatePConf("Gpu", Gpu);
1510: ConfCreatePConf("Spu", Spu);
1511: ConfCreatePConf("Pad1", Pad1);
1512: ConfCreatePConf("Pad2", Pad2);
1513: ConfCreatePConf("Cdr", Cdr);
1514:
1515: BiosConfS.plugins+=2;
1516: strcpy(BiosConfS.plist[BiosConfS.plugins-1], _("Internal HLE Bios"));
1517: strcpy(BiosConfS.plist[BiosConfS.plugins-2], "HLE");
1518: BiosConfS.glist = g_list_append(BiosConfS.glist, BiosConfS.plist[BiosConfS.plugins-1]);
1519:
1520: dir = opendir(Config.BiosDir);
1521: if (dir == NULL) {
1522: SysMessage(_("Could not open '%s' directory\n"), Config.BiosDir);
1523: return;
1524: }
1525:
1526: while ((ent = readdir(dir)) != NULL) {
1527: struct stat buf;
1528:
1529: sprintf (plugin, "%s%s", Config.BiosDir, ent->d_name);
1530: if (stat(plugin, &buf) == -1) continue;
1531: if (buf.st_size != (1024*512)) continue;
1532:
1533: BiosConfS.plugins+=2;
1534: strcpy(BiosConfS.plist[BiosConfS.plugins-1], ent->d_name);
1535: strcpy(BiosConfS.plist[BiosConfS.plugins-2], ent->d_name);
1536: BiosConfS.glist = g_list_append(BiosConfS.glist, BiosConfS.plist[BiosConfS.plugins-1]);
1537: }
1538: closedir(dir);
1539:
1540: ConfCreatePConf("Bios", Bios);
1541: }
1542:
1543: #define ConfCreatePNet(name, type) \
1544: if (type##ConfS.glist != NULL) { \
1545: type##ConfS.Combo = lookup_widget(NetDlg, "GtkCombo_" name); \
1546: gtk_combo_set_popdown_strings(GTK_COMBO(type##ConfS.Combo), type##ConfS.glist); \
1547: FindComboText(type##ConfS.Combo, type##ConfS.plist, Config.type); \
1548: }
1549:
1550: void FindNetPlugin() {
1551: DIR *dir;
1552: struct dirent *ent;
1553: void *Handle;
1554: char plugin[256],name[256];
1555:
1556: NetConfS.plugins = 0;
1557: NetConfS.glist = NULL;
1558:
1559: NetConfS.plugins+=2;
1560: strcpy(NetConfS.plist[NetConfS.plugins-1], "Disabled");
1561: strcpy(NetConfS.plist[NetConfS.plugins-2], "Disabled");
1562: NetConfS.glist = g_list_append(NetConfS.glist, NetConfS.plist[NetConfS.plugins-1]);
1563:
1564: dir = opendir(Config.PluginsDir);
1565: if (dir == NULL) {
1566: SysMessage(_("Could not open '%s' directory\n"), Config.PluginsDir);
1567: return;
1568: }
1569: while ((ent = readdir(dir)) != NULL) {
1570: long type,v;
1571:
1572: sprintf(plugin, "%s%s", Config.PluginsDir, ent->d_name);
1573:
1574: if (strstr(plugin, ".so") == NULL) continue;
1575: Handle = dlopen(plugin, RTLD_NOW);
1576: if (Handle == NULL) continue;
1577:
1578: PSE_getLibType = (PSEgetLibType) dlsym(Handle, "PSEgetLibType");
1579: if (dlerror() != NULL) {
1580: if (strstr(plugin, "net") != NULL) type = PSE_LT_NET;
1581: else continue;
1582: }
1583: else type = PSE_getLibType();
1584:
1585: PSE_getLibName = (PSEgetLibName) dlsym(Handle, "PSEgetLibName");
1586: if (dlerror() == NULL) {
1587: sprintf(name, "%s", PSE_getLibName());
1588: PSE_getLibVersion = (PSEgetLibVersion) dlsym(Handle, "PSEgetLibVersion");
1589: if (dlerror() == NULL) {
1590: char ver[32];
1591:
1592: v = PSE_getLibVersion();
1593: sprintf(ver, " %ld.%ld.%ld",v>>16,(v>>8)&0xff,v&0xff);
1594: strcat(name, ver);
1595: }
1596: }
1597: else strcpy(name, ent->d_name);
1598:
1599: if (type & PSE_LT_NET) {
1600: ComboAddPlugin(Net);
1601: }
1602: }
1603: closedir(dir);
1604:
1605: ConfCreatePNet("Net", Net);
1606: }
1607:
1608: GtkWidget *MsgDlg;
1609:
1610: void OnMsg_Ok() {
1611: gtk_widget_destroy(MsgDlg);
1612: gtk_main_quit();
1613: }
1614:
1615: void SysMessage(char *fmt, ...) {
1616: GtkWidget *Ok,*Txt;
1617: GtkWidget *Box,*Box1;
1618: va_list list;
1619: char msg[512];
1620:
1621: va_start(list, fmt);
1622: vsprintf(msg, fmt, list);
1623: va_end(list);
1624:
1625: if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0;
1626:
1627: if (!UseGui) { printf ("%s\n",msg); return; }
1628:
1629: MsgDlg = gtk_window_new (GTK_WINDOW_DIALOG);
1630: gtk_window_set_position(GTK_WINDOW(MsgDlg), GTK_WIN_POS_CENTER);
1631: gtk_window_set_title(GTK_WINDOW(MsgDlg), _("Pcsx Msg"));
1632: gtk_container_set_border_width(GTK_CONTAINER(MsgDlg), 5);
1633:
1634: Box = gtk_vbox_new(5, 0);
1635: gtk_container_add(GTK_CONTAINER(MsgDlg), Box);
1636: gtk_widget_show(Box);
1637:
1638: Txt = gtk_label_new(msg);
1639:
1640: gtk_box_pack_start(GTK_BOX(Box), Txt, FALSE, FALSE, 5);
1641: gtk_widget_show(Txt);
1642:
1643: Box1 = gtk_hbutton_box_new();
1644: gtk_box_pack_start(GTK_BOX(Box), Box1, FALSE, FALSE, 0);
1645: gtk_widget_show(Box1);
1646:
1647: Ok = gtk_button_new_with_label(_("Ok"));
1648: gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnMsg_Ok), NULL);
1649: gtk_container_add(GTK_CONTAINER(Box1), Ok);
1650: GTK_WIDGET_SET_FLAGS(Ok, GTK_CAN_DEFAULT);
1651: gtk_widget_show(Ok);
1652:
1653: gtk_widget_show(MsgDlg);
1654:
1655: gtk_main();
1656: }
1657:
1658: /* arch-tag: Matthew Dempsky Wed Oct 15 10:34:36 CST 2003 (Linux/GtkGui.c)
1659: */
1660:
Html form generated by Xrefactory version 1.6.4 on Fri Dec 12 20:52:56 2003
Trial version.