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








































Html form generated by Xrefactory version 1.6.4 on Fri Dec 12 20:52:56 2003
Trial version.