ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Windows/prefs_editor_gtk.cpp
(Generate patch)

Comparing BasiliskII/src/Windows/prefs_editor_gtk.cpp (file contents):
Revision 1.3 by gbeauche, 2005-11-20T17:26:16Z vs.
Revision 1.12 by gbeauche, 2006-04-29T14:15:01Z

# Line 20 | Line 20
20  
21   #include "sysdeps.h"
22  
23 #include <gtk/gtk.h>
23   #include <stdlib.h>
24 + #include <string.h>
25 + #include <fcntl.h>
26 + #include <sys/stat.h>
27 + #include <gtk/gtk.h>
28  
29   #include "user_strings.h"
30   #include "version.h"
# Line 29 | Line 32
32   #include "xpram.h"
33   #include "prefs.h"
34   #include "prefs_editor.h"
35 + #include "util_windows.h"
36 + #include "b2ether/inc/b2ether_hl.h"
37  
38  
39   // Global variables
# Line 49 | Line 54 | static void read_settings(void);
54  
55  
56   /*
57 + *  SheepShaver glue
58 + */
59 +
60 + #ifdef SHEEPSHAVER
61 + #define DISABLE_SCSI 1
62 + #define PROGRAM_NAME "SheepShaver"
63 + enum {
64 +        STR_WINDOW_LAB = STR_WINDOW_CTRL,
65 +        STR_FULLSCREEN_LAB = STR_FULLSCREEN_CTRL,
66 +        STR_SERIALA_CTRL = STR_SERPORTA_CTRL,
67 +        STR_SERIALB_CTRL = STR_SERPORTB_CTRL,
68 + };
69 + #else
70 + #define DISABLE_SCSI 1 /* XXX merge code from original Basilisk II for Windows */
71 + #define PROGRAM_NAME "BasiliskII"
72 + #endif
73 +
74 +
75 + /*
76   *  Utility functions
77   */
78  
# Line 94 | Line 118 | static GtkWidget *make_browse_button(Gtk
118          return button;
119   }
120  
121 < static void add_menu_item(GtkWidget *menu, int label_id, GtkSignalFunc func)
121 > static void add_menu_item(GtkWidget *menu, const char *label, GtkSignalFunc func, gpointer data = NULL)
122   {
123 <        GtkWidget *item = gtk_menu_item_new_with_label(GetString(label_id));
123 >        GtkWidget *item = gtk_menu_item_new_with_label(label);
124          gtk_widget_show(item);
125 <        gtk_signal_connect(GTK_OBJECT(item), "activate", func, NULL);
125 >        gtk_signal_connect(GTK_OBJECT(item), "activate", func, data);
126          gtk_menu_append(GTK_MENU(menu), item);
127   }
128  
129 + static void add_menu_item(GtkWidget *menu, int label_id, GtkSignalFunc func)
130 + {
131 +        add_menu_item(menu, GetString(label_id), func, NULL);
132 + }
133 +
134   static GtkWidget *make_pane(GtkWidget *notebook, int title_id)
135   {
136          GtkWidget *frame, *label, *box;
# Line 302 | Line 331 | static GtkWidget *make_checkbox(GtkWidge
331          return button;
332   }
333  
334 < static GtkWidget *make_combobox(GtkWidget *top, int label_id, const char *prefs_item, const combo_desc *options)
334 > static GtkWidget *make_combobox(GtkWidget *top, int label_id, const char *default_value, GList *glist)
335   {
336          GtkWidget *box, *label, *combo;
308        char str[32];
337  
338          box = gtk_hbox_new(FALSE, 4);
339          gtk_widget_show(box);
# Line 314 | Line 342 | static GtkWidget *make_combobox(GtkWidge
342          label = gtk_label_new(GetString(label_id));
343          gtk_widget_show(label);
344          gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);
317
318        GList *glist = NULL;
319        while (options->label_id) {
320                glist = g_list_append(glist, (void *)GetString(options->label_id));
321                options++;
322        }
345          
346          combo = gtk_combo_new();
347          gtk_widget_show(combo);
348          gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
349          
350 <        sprintf(str, "%d", PrefsFindInt32(prefs_item));
329 <        gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), str);
350 >        gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), default_value);
351          gtk_box_pack_start(GTK_BOX(box), combo, TRUE, TRUE, 0);
352          
353          return combo;
354   }
355  
356 + static GtkWidget *make_combobox(GtkWidget *top, int label_id, const char *default_value, const combo_desc *options)
357 + {
358 +        GList *glist = NULL;
359 +        while (options->label_id) {
360 +                glist = g_list_append(glist, (void *)GetString(options->label_id));
361 +                options++;
362 +        }
363 +
364 +        return make_combobox(top, label_id, default_value, glist);
365 + }
366 +
367  
368   /*
369   *  Show preferences editor
# Line 387 | Line 419 | static void cb_about(...)
419  
420          char str[512];
421          sprintf(str,
422 <                "Basilisk II\nVersion %d.%d\n\n"
422 >                PROGRAM_NAME "\nVersion %d.%d\n\n"
423                  "Copyright (C) 1997-2005 Christian Bauer et al.\n"
424 <                "E-mail: Christian.Bauer@uni-mainz.de\n"
425 <                "http://www.uni-mainz.de/~bauec002/B2Main.html\n\n"
426 <                "Basilisk II comes with ABSOLUTELY NO\n"
424 >                "E-mail: cb@cebix.net\n"
425 > #ifdef SHEEPSHAVER
426 >                "http://sheepshaver.cebix.net/\n\n"
427 > #else
428 >                "http://basilisk.cebix.net/\n\n"
429 > #endif
430 >                PROGRAM_NAME " comes with ABSOLUTELY NO\n"
431                  "WARRANTY. This is free software, and\n"
432                  "you are welcome to redistribute it\n"
433                  "under the terms of the GNU General\n"
# Line 421 | Line 457 | static void cb_about(...)
457   // Menu item descriptions
458   static GtkItemFactoryEntry menu_items[] = {
459          {(gchar *)GetString(STR_PREFS_MENU_FILE_GTK),           NULL,                   NULL,                                                   0, "<Branch>"},
460 <        {(gchar *)GetString(STR_PREFS_ITEM_START_GTK),          NULL,                   GTK_SIGNAL_FUNC(cb_start),              0, NULL},
460 >        {(gchar *)GetString(STR_PREFS_ITEM_START_GTK),          "<control>S",   GTK_SIGNAL_FUNC(cb_start),              0, NULL},
461          {(gchar *)GetString(STR_PREFS_ITEM_ZAP_PRAM_GTK),       NULL,                   GTK_SIGNAL_FUNC(cb_zap_pram),   0, NULL},
462          {(gchar *)GetString(STR_PREFS_ITEM_SEPL_GTK),           NULL,                   NULL,                                                   0, "<Separator>"},
463          {(gchar *)GetString(STR_PREFS_ITEM_QUIT_GTK),           "<control>Q",   GTK_SIGNAL_FUNC(cb_quit),               0, NULL},
464          {(gchar *)GetString(STR_HELP_MENU_GTK),                         NULL,                   NULL,                                                   0, "<LastBranch>"},
465 <        {(gchar *)GetString(STR_HELP_ITEM_ABOUT_GTK),           NULL,                   GTK_SIGNAL_FUNC(cb_about),              0, NULL}
465 >        {(gchar *)GetString(STR_HELP_ITEM_ABOUT_GTK),           "<control>H",   GTK_SIGNAL_FUNC(cb_about),              0, NULL}
466   };
467  
468 + void PrefsMigrate(void)
469 + {
470 +        // Ethernet
471 +        const char *ether = PrefsFindString("ether");
472 +        if (ether && ether[0] == '{') {
473 +                PrefsReplaceString("etherguid", ether);
474 +                PrefsReplaceString("ether", "b2ether");
475 +        }
476 +        if (PrefsFindBool("routerenabled")) {
477 +                PrefsRemoveItem("etherguid");
478 +                PrefsReplaceString("ether", "router");
479 +        }
480 + }
481 +
482   bool PrefsEditor(void)
483   {
484          // Create window
# Line 461 | Line 511 | bool PrefsEditor(void)
511          gtk_box_pack_start(GTK_BOX(box), notebook, TRUE, TRUE, 0);
512  
513          create_volumes_pane(notebook);
514 + #ifndef DISABLE_SCSI
515          create_scsi_pane(notebook);
516 + #endif
517          create_graphics_pane(notebook);
518          create_input_pane(notebook);
519          create_serial_pane(notebook);
# Line 471 | Line 523 | bool PrefsEditor(void)
523  
524          static const opt_desc buttons[] = {
525                  {STR_START_BUTTON, GTK_SIGNAL_FUNC(cb_start)},
474                {STR_PREFS_ITEM_ZAP_PRAM, GTK_SIGNAL_FUNC(cb_zap_pram)},
475                {STR_ABOUT_BUTTON, GTK_SIGNAL_FUNC(cb_about)},
526                  {STR_QUIT_BUTTON, GTK_SIGNAL_FUNC(cb_quit)},
527                  {0, NULL}
528          };
# Line 489 | Line 539 | bool PrefsEditor(void)
539   *  "Volumes" pane
540   */
541  
542 + static GtkWidget *w_enableextfs, *w_extdrives, *w_cdrom_drive;
543   static GtkWidget *volume_list;
544   static int selected_volume;
545  
546 + // Set sensitivity of widgets
547 + static void set_volumes_sensitive(void)
548 + {
549 +        const bool enable_extfs = PrefsFindBool("enableextfs");
550 +        gtk_widget_set_sensitive(w_extdrives, enable_extfs);
551 +        const bool no_cdrom = PrefsFindBool("nocdrom");
552 +        gtk_widget_set_sensitive(w_cdrom_drive, !no_cdrom);
553 + }
554 +
555   // Volume in list selected
556   static void cl_selected(GtkWidget *list, int row, int column)
557   {
# Line 513 | Line 573 | static void create_volume_ok(GtkWidget *
573          gchar *file = (gchar *)gtk_file_selection_get_filename(GTK_FILE_SELECTION(assoc->req));
574  
575          const gchar *str = gtk_entry_get_text(GTK_ENTRY(assoc->entry));
576 <        int size = atoi(str);
576 >        size_t size = atoi(str) << 20;
577  
578 <        char cmd[1024];
579 <        sprintf(cmd, "dd if=/dev/zero \"of=%s\" bs=1024k count=%d", file, size);
580 <        int ret = system(cmd);
521 <        if (ret == 0)
578 >        int fd = _open(file, _O_WRONLY | _O_CREAT | _O_BINARY | _O_TRUNC, _S_IREAD | _S_IWRITE);
579 >        if (fd >= 0) {
580 >          if (_chsize(fd, size) == 0)
581                  gtk_clist_append(GTK_CLIST(volume_list), &file);
582 +          _close(fd);
583 +        }
584          gtk_widget_destroy(GTK_WIDGET(assoc->req));
585          delete assoc;
586   }
# Line 568 | Line 629 | static void cb_remove_volume(...)
629   static void mn_boot_any(...) {PrefsReplaceInt32("bootdriver", 0);}
630   static void mn_boot_cdrom(...) {PrefsReplaceInt32("bootdriver", CDROMRefNum);}
631  
632 + // "Enable external file system" button toggled
633 + static void tb_enableextfs(GtkWidget *widget)
634 + {
635 +        PrefsReplaceBool("enableextfs", GTK_TOGGLE_BUTTON(widget)->active);
636 +        set_volumes_sensitive();
637 + }
638 +
639   // "No CD-ROM Driver" button toggled
640   static void tb_nocdrom(GtkWidget *widget)
641   {
642          PrefsReplaceBool("nocdrom", GTK_TOGGLE_BUTTON(widget)->active);
643 +        set_volumes_sensitive();
644 + }
645 +
646 + // Add names of CD-ROM devices
647 + static GList *add_cdrom_names(void)
648 + {
649 +        GList *glist = NULL;
650 +
651 +        char rootdir[4] = "X:\\";
652 +        for (char letter = 'C'; letter <= 'Z'; letter++) {
653 +                rootdir[0] = letter;
654 +                if (GetDriveType(rootdir) == DRIVE_CDROM)
655 +                        glist = g_list_append(glist, strdup(rootdir));
656 +        }
657 +
658 +        return glist;
659 + }
660 +
661 + // "Enable polling" button toggled
662 + static void tb_pollmedia(GtkWidget *widget)
663 + {
664 +        PrefsReplaceBool("pollmedia", GTK_TOGGLE_BUTTON(widget)->active);
665   }
666  
667   // Read settings from widgets and set preferences
# Line 585 | Line 675 | static void read_volumes_settings(void)
675                  gtk_clist_get_text(GTK_CLIST(volume_list), i, 0, &str);
676                  PrefsAddString("disk", str);
677          }
678 +
679 +        const char *str = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(w_cdrom_drive)->entry));
680 +        if (str && strlen(str))
681 +                PrefsReplaceString("cdrom", str);
682 +        else
683 +                PrefsRemoveItem("cdrom");
684 +
685 +        PrefsReplaceString("extdrives", get_file_entry_path(w_extdrives));
686   }
687  
688   // Create "Volumes" pane
# Line 633 | Line 731 | static void create_volumes_pane(GtkWidge
731          menu = make_option_menu(box, STR_BOOTDRIVER_CTRL, options, active);
732  
733          make_checkbox(box, STR_NOCDROM_CTRL, "nocdrom", GTK_SIGNAL_FUNC(tb_nocdrom));
734 +
735 +        GList *glist = add_cdrom_names();
736 +        str = const_cast<char *>(PrefsFindString("cdrom"));
737 +        if (str == NULL)
738 +                str = "";
739 +        w_cdrom_drive = make_combobox(box, STR_CDROM_DRIVE_CTRL, str, glist);
740 +
741 +        make_checkbox(box, STR_POLLMEDIA_CTRL, "pollmedia", GTK_SIGNAL_FUNC(tb_pollmedia));
742 +
743 +        make_separator(box);
744 +        w_enableextfs = make_checkbox(box, STR_EXTFS_ENABLE_CTRL, "enableextfs", GTK_SIGNAL_FUNC(tb_enableextfs));
745 +        w_extdrives = make_file_entry(box, STR_EXTFS_DRIVES_CTRL, "extdrives", true);
746 +
747 +        set_volumes_sensitive();
748   }
749  
750  
# Line 640 | Line 752 | static void create_volumes_pane(GtkWidge
752   *  "JIT Compiler" pane
753   */
754  
755 + #ifndef SHEEPSHAVER
756   static GtkWidget *w_jit_fpu;
757   static GtkWidget *w_jit_atraps;
758   static GtkWidget *w_jit_cache_size;
759   static GtkWidget *w_jit_lazy_flush;
760   static GtkWidget *w_jit_follow_const_jumps;
761 + #endif
762  
763   // Set sensitivity of widgets
764   static void set_jit_sensitive(void)
765   {
766 + #ifndef SHEEPSHAVER
767          const bool jit_enabled = PrefsFindBool("jit");
768          gtk_widget_set_sensitive(w_jit_fpu, jit_enabled);
769          gtk_widget_set_sensitive(w_jit_cache_size, jit_enabled);
770          gtk_widget_set_sensitive(w_jit_lazy_flush, jit_enabled);
771          gtk_widget_set_sensitive(w_jit_follow_const_jumps, jit_enabled);
772 + #endif
773   }
774  
775   // "Use JIT Compiler" button toggled
# Line 664 | Line 780 | static void tb_jit(GtkWidget *widget)
780   }
781  
782   // "Compile FPU Instructions" button toggled
783 + #ifndef SHEEPSHAVER
784   static void tb_jit_fpu(GtkWidget *widget)
785   {
786          PrefsReplaceBool("jitfpu", GTK_TOGGLE_BUTTON(widget)->active);
787   }
788 + #endif
789  
790   // "Lazy translation cache invalidation" button toggled
791 + #ifndef SHEEPSHAVER
792   static void tb_jit_lazy_flush(GtkWidget *widget)
793   {
794          PrefsReplaceBool("jitlazyflush", GTK_TOGGLE_BUTTON(widget)->active);
795   }
796 + #endif
797  
798   // "Translate through constant jumps (inline blocks)" button toggled
799 + #ifndef SHEEPSHAVER
800   static void tb_jit_follow_const_jumps(GtkWidget *widget)
801   {
802          PrefsReplaceBool("jitinline", GTK_TOGGLE_BUTTON(widget)->active);
803   }
804 + #endif
805  
806   // Read settings from widgets and set preferences
807   static void read_jit_settings(void)
# Line 687 | Line 809 | static void read_jit_settings(void)
809   #if USE_JIT
810          bool jit_enabled = PrefsFindBool("jit");
811          if (jit_enabled) {
812 + #ifndef SHEEPSHAVER
813                  const char *str = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(w_jit_cache_size)->entry));
814                  PrefsReplaceInt32("jitcachesize", atoi(str));
815 + #endif
816          }
817   #endif
818   }
819  
820 + // "Use built-in 68k DR emulator" button toggled
821 + #ifdef SHEEPSHAVER
822 + static void tb_jit_68k(GtkWidget *widget)
823 + {
824 +        PrefsReplaceBool("jit68k", GTK_TOGGLE_BUTTON(widget)->active);
825 + }
826 + #endif
827 +
828   // Create "JIT Compiler" pane
829   static void create_jit_pane(GtkWidget *top)
830   {
# Line 703 | Line 835 | static void create_jit_pane(GtkWidget *t
835          box = make_pane(top, STR_JIT_PANE_TITLE);
836          make_checkbox(box, STR_JIT_CTRL, "jit", GTK_SIGNAL_FUNC(tb_jit));
837          
838 + #ifndef SHEEPSHAVER
839          w_jit_fpu = make_checkbox(box, STR_JIT_FPU_CTRL, "jitfpu", GTK_SIGNAL_FUNC(tb_jit_fpu));
840          
841          // Translation cache size
# Line 713 | Line 846 | static void create_jit_pane(GtkWidget *t
846                  STR_JIT_CACHE_SIZE_16MB_LAB,
847                  0
848          };
849 <        w_jit_cache_size = make_combobox(box, STR_JIT_CACHE_SIZE_CTRL, "jitcachesize", options);
849 >        sprintf(str, "%d", PrefsFindInt32("jitcachesize"));
850 >        w_jit_cache_size = make_combobox(box, STR_JIT_CACHE_SIZE_CTRL, str, options);
851          
852          // Lazy translation cache invalidation
853          w_jit_lazy_flush = make_checkbox(box, STR_JIT_LAZY_CINV_CTRL, "jitlazyflush", GTK_SIGNAL_FUNC(tb_jit_lazy_flush));
854  
855          // Follow constant jumps (inline basic blocks)
856          w_jit_follow_const_jumps = make_checkbox(box, STR_JIT_FOLLOW_CONST_JUMPS, "jitinline", GTK_SIGNAL_FUNC(tb_jit_follow_const_jumps));
857 + #endif
858  
859          set_jit_sensitive();
860   #endif
861 +
862 + #ifdef SHEEPSHAVER
863 +        make_checkbox(box, STR_JIT_68K_CTRL, "jit68k", GTK_SIGNAL_FUNC(tb_jit_68k));
864 + #endif
865   }
866  
867   /*
# Line 734 | Line 873 | static GtkWidget *w_scsi[7];
873   // Read settings from widgets and set preferences
874   static void read_scsi_settings(void)
875   {
876 + #ifndef DISABLE_SCSI
877          for (int id=0; id<7; id++) {
878                  char prefs_name[32];
879                  sprintf(prefs_name, "scsi%d", id);
# Line 743 | Line 883 | static void read_scsi_settings(void)
883                  else
884                          PrefsRemoveItem(prefs_name);
885          }
886 + #endif
887   }
888  
889   // Create "SCSI" pane
890   static void create_scsi_pane(GtkWidget *top)
891   {
892 + #ifndef DISABLE_SCSI
893          GtkWidget *box;
894  
895          box = make_pane(top, STR_SCSI_PANE_TITLE);
# Line 757 | Line 899 | static void create_scsi_pane(GtkWidget *
899                  sprintf(prefs_name, "scsi%d", id);
900                  w_scsi[id] = make_file_entry(box, STR_SCSI_ID_0 + id, prefs_name);
901          }
902 + #endif
903   }
904  
905  
# Line 800 | Line 943 | static void mn_fullscreen(...)
943   {
944          display_type = DISPLAY_SCREEN;
945          hide_show_graphics_widgets();
946 +        PrefsReplaceInt32("frameskip", 1);
947   }
948  
949   // "5 Hz".."60Hz" selected
# Line 811 | Line 955 | static void mn_30hz(...) {PrefsReplaceIn
955   static void mn_60hz(...) {PrefsReplaceInt32("frameskip", 1);}
956   static void mn_dynamic(...) {PrefsReplaceInt32("frameskip", 0);}
957  
958 + // QuickDraw acceleration
959 + #ifdef SHEEPSHAVER
960 + static void tb_gfxaccel(GtkWidget *widget)
961 + {
962 +        PrefsReplaceBool("gfxaccel", GTK_TOGGLE_BUTTON(widget)->active);
963 + }
964 + #endif
965 +
966   // Set sensitivity of widgets
967   static void set_graphics_sensitive(void)
968   {
# Line 828 | Line 980 | static void tb_nosound(GtkWidget *widget
980   static void parse_graphics_prefs(void)
981   {
982          display_type = DISPLAY_WINDOW;
983 + #ifdef SHEEPSHAVER
984 +        dis_width = 640;
985 +        dis_height = 480;
986 + #else
987          dis_width = 512;
988          dis_height = 384;
989 + #endif
990  
991          const char *str = PrefsFindString("screen");
992          if (str) {
# Line 969 | Line 1126 | static void create_graphics_pane(GtkWidg
1126          gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 3, 4, (GtkAttachOptions)GTK_FILL, (GtkAttachOptions)0, 4, 4);
1127          w_display_y = GTK_COMBO(combo)->entry;
1128  
1129 + #ifdef SHEEPSHAVER
1130 +        make_checkbox(box, STR_GFXACCEL_CTRL, "gfxaccel", GTK_SIGNAL_FUNC(tb_gfxaccel));
1131 + #endif
1132 +
1133          make_separator(box);
1134          make_checkbox(box, STR_NOSOUND_CTRL, "nosound", GTK_SIGNAL_FUNC(tb_nosound));
1135  
# Line 988 | Line 1149 | static GtkWidget *w_mouse_wheel_lines;
1149   // Set sensitivity of widgets
1150   static void set_input_sensitive(void)
1151   {
1152 <        gtk_widget_set_sensitive(w_keycode_file, PrefsFindBool("keycodes"));
1152 >        const bool use_keycodes = PrefsFindBool("keycodes");
1153 >        gtk_widget_set_sensitive(w_keycode_file, use_keycodes);
1154 >        gtk_widget_set_sensitive(GTK_WIDGET(g_object_get_data(G_OBJECT(w_keycode_file), "chooser_button")), use_keycodes);
1155          gtk_widget_set_sensitive(w_mouse_wheel_lines, PrefsFindInt32("mousewheelmode") == 1);
1156   }
1157  
# Line 1018 | Line 1181 | static void read_input_settings(void)
1181   // Create "Input" pane
1182   static void create_input_pane(GtkWidget *top)
1183   {
1184 <        GtkWidget *box, *hbox, *menu, *label;
1184 >        GtkWidget *box, *hbox, *menu, *label, *button;
1185          GtkObject *adj;
1186  
1187          box = make_pane(top, STR_INPUT_PANE_TITLE);
1188  
1189          make_checkbox(box, STR_KEYCODES_CTRL, "keycodes", GTK_SIGNAL_FUNC(tb_keycodes));
1190 <        w_keycode_file = make_file_entry(box, STR_KEYCODE_FILE_CTRL, "keycodefile");
1190 >
1191 >        hbox = gtk_hbox_new(FALSE, 4);
1192 >        gtk_widget_show(hbox);
1193 >        gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
1194 >
1195 >        label = gtk_label_new(GetString(STR_KEYCODES_CTRL));
1196 >        gtk_widget_show(label);
1197 >        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1198 >
1199 >        const char *str = PrefsFindString("keycodefile");
1200 >        if (str == NULL)
1201 >                str = "";
1202 >
1203 >        w_keycode_file = gtk_entry_new();
1204 >        gtk_entry_set_text(GTK_ENTRY(w_keycode_file), str);
1205 >        gtk_widget_show(w_keycode_file);
1206 >        gtk_box_pack_start(GTK_BOX(hbox), w_keycode_file, TRUE, TRUE, 0);
1207 >
1208 >        button = make_browse_button(w_keycode_file);
1209 >        gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1210 >        g_object_set_data(G_OBJECT(w_keycode_file), "chooser_button", button);
1211  
1212          make_separator(box);
1213  
# Line 1102 | Line 1285 | static void read_serial_settings(void)
1285   // Port changed in combo
1286   static void cb_serial_port_changed(...)
1287   {
1105        printf("serial port changed\n");
1288          set_serial_sensitive();
1289   }
1290  
# Line 1160 | Line 1342 | static void create_serial_pane(GtkWidget
1342   *  "Ethernet" pane
1343   */
1344  
1345 < static GtkWidget *w_ether, *w_udp_port;
1345 > static GtkWidget *w_ftp_port_list, *w_tcp_port_list;
1346  
1347   // Set sensitivity of widgets
1348   static void set_ethernet_sensitive(void)
1349   {
1350 +        const char *str = PrefsFindString("ether");
1351 +
1352 +        bool is_router = str && strcmp(str, "router") == 0;
1353 +        gtk_widget_set_sensitive(w_ftp_port_list, is_router);
1354 +        gtk_widget_set_sensitive(w_tcp_port_list, is_router);
1355   }
1356  
1357   // Read settings from widgets and set preferences
1358   static void read_ethernet_settings(void)
1359   {
1360 <        const char *str = gtk_entry_get_text(GTK_ENTRY(w_ether));
1361 <        if (str && strlen(str))
1362 <                PrefsReplaceString("ether", str);
1363 <        else
1364 <                PrefsRemoveItem("ether");
1360 >        const char *str = PrefsFindString("ether");
1361 >
1362 >        bool is_router = str && strcmp(str, "router") == 0;
1363 >        if (is_router) {
1364 >                str = gtk_entry_get_text(GTK_ENTRY(w_ftp_port_list));
1365 >                PrefsReplaceString("ftp_port_list", str);
1366 >                str = gtk_entry_get_text(GTK_ENTRY(w_tcp_port_list));
1367 >                PrefsReplaceString("tcp_port", str);
1368 >        }
1369   }
1370  
1371 < // Add names of ethernet interfaces
1372 < static GList *add_ether_names(void)
1371 > // Ethernet emulation type changed in menulist
1372 > static void cb_ether_changed(...)
1373   {
1374 <        GList *glist = NULL;
1374 >        set_ethernet_sensitive();
1375 > }
1376  
1377 <        // TODO: Get list of all Ethernet interfaces
1378 < #ifdef HAVE_SLIRP
1379 <        static char s_slirp[] = "slirp";
1380 <        glist = g_list_append(glist, s_slirp);
1381 < #endif
1190 < #if 0
1191 <        if (glist)
1192 <                g_list_sort(glist, gl_str_cmp);
1193 <        else
1194 < #endif
1195 <                glist = g_list_append(glist, (void *)GetString(STR_NONE_LAB));
1196 <        return glist;
1377 > // Ethernet option "None" selected
1378 > static void mn_ether_none(void)
1379 > {
1380 >        PrefsRemoveItem("ether");
1381 >        PrefsRemoveItem("etherguid");
1382   }
1383  
1384 + // Ethernet option "Basilisk II Router" selected
1385 + static void mn_ether_router(void)
1386 + {
1387 +        PrefsReplaceString("ether", "router");
1388 +        PrefsRemoveItem("etherguid");
1389 + }
1390 +
1391 + // Ethernet option "Basilisk II Slirp" selected
1392 + static void mn_ether_slirp(void)
1393 + {
1394 +        PrefsReplaceString("ether", "slirp");
1395 +        PrefsRemoveItem("etherguid");
1396 + }
1397 +
1398 + // Ethernet option for Basilisk II driver selected
1399 + static void mn_ether_b2ether(GtkWidget *, const char *guid)
1400 + {
1401 +        PrefsReplaceString("ether", "b2ether");
1402 +        PrefsReplaceString("etherguid", guid);
1403 + }
1404 +
1405 + // Create ethernet interfaces menu
1406 + static int create_ether_menu(GtkWidget *menu)
1407 + {
1408 +        int active = -1;
1409 +        int n_items = 0;
1410 +        const char *ether = PrefsFindString("ether");
1411 +        const char *etherguid = PrefsFindString("etherguid");
1412 +
1413 +        add_menu_item(menu, STR_NONE_LAB, (GtkSignalFunc)mn_ether_none);
1414 +        if (ether == NULL)
1415 +                active = n_items;
1416 +        n_items++;
1417 +
1418 +        add_menu_item(menu, "Basilisk II Router", (GtkSignalFunc)mn_ether_router);
1419 +        if (ether && strcmp(ether, "router") == 0)
1420 +                active = n_items;
1421 +        n_items++;
1422 +
1423 +        add_menu_item(menu, "Basilisk II Slirp", (GtkSignalFunc)mn_ether_router);
1424 +        if (ether && strcmp(ether, "slirp") == 0)
1425 +                active = n_items;
1426 +        n_items++;
1427 +
1428 +        PacketOpenAdapter("", 0);
1429 +        {
1430 +                ULONG sz;
1431 +                char names[1024];
1432 +                sz = sizeof(names);
1433 +                if (PacketGetAdapterNames(NULL, names, &sz) == ERROR_SUCCESS) {
1434 +                        char *p = names;
1435 +                        while (*p) {
1436 +                                const char DEVICE_HEADER[] = "\\Device\\B2ether_";
1437 +                                if (strnicmp(p, DEVICE_HEADER, sizeof(DEVICE_HEADER) - 1) == 0) {
1438 +                                        LPADAPTER fd = PacketOpenAdapter(p + sizeof(DEVICE_HEADER) - 1, 0);
1439 +                                        if (fd) {
1440 +                                                char guid[256];
1441 +                                                sprintf(guid, "%s", p + sizeof(DEVICE_HEADER) - 1);
1442 +                                                const char *name = ether_guid_to_name(guid);
1443 +                                                if (name && (name = g_locale_to_utf8(name, -1, NULL, NULL, NULL))) {
1444 +                                                        add_menu_item(menu, name, (GtkSignalFunc)mn_ether_b2ether, strdup(guid));
1445 +                                                        if (etherguid && strcmp(guid, etherguid) == 0 &&
1446 +                                                                ether && strcmp(ether, "b2ether") == 0)
1447 +                                                                active = n_items;
1448 +                                                        n_items++;
1449 +                                                }
1450 +                                                PacketCloseAdapter(fd);
1451 +                                        }
1452 +                                }
1453 +                                p += strlen(p) + 1;
1454 +                        }
1455 +                }
1456 +        }
1457 +        PacketCloseAdapter(NULL);
1458 +
1459 +        return active;
1460 + }
1461  
1462   // Create "Ethernet" pane
1463   static void create_ethernet_pane(GtkWidget *top)
1464   {
1465 <        GtkWidget *box, *hbox, *table, *label, *combo, *sep, *entry;
1465 >        GtkWidget *box, *hbox, *table, *label, *sep, *entry, *opt, *menu, *item;
1466  
1467          box = make_pane(top, STR_NETWORK_PANE_TITLE);
1468          table = make_table(box, 2, 5);
# Line 1209 | Line 1471 | static void create_ethernet_pane(GtkWidg
1471          gtk_widget_show(label);
1472          gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
1473  
1474 <        GList *glist = add_ether_names();
1475 <        combo = gtk_combo_new();
1476 <        gtk_widget_show(combo);
1477 <        gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
1478 <        const char *str = PrefsFindString("ether");
1474 >        opt = gtk_option_menu_new();
1475 >        gtk_widget_show(opt);
1476 >        menu = gtk_menu_new();
1477 >        int active = create_ether_menu(menu);
1478 >        if (active >= 0)
1479 >                gtk_menu_set_active(GTK_MENU(menu), active);
1480 >        gtk_option_menu_set_menu(GTK_OPTION_MENU(opt), menu);
1481 >        gtk_table_attach(GTK_TABLE(table), opt, 1, 2, 0, 1, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
1482 >        gtk_signal_connect(GTK_OBJECT(opt), "changed", GTK_SIGNAL_FUNC(cb_ether_changed), NULL);
1483 >
1484 >        sep = gtk_hseparator_new();
1485 >        gtk_widget_show(sep);
1486 >        gtk_table_attach(GTK_TABLE(table), sep, 0, 2, 1, 2, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
1487 >
1488 >        label = gtk_label_new(GetString(STR_ETHER_FTP_PORT_LIST_CTRL));
1489 >        gtk_widget_show(label);
1490 >        gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
1491 >
1492 >        entry = gtk_entry_new();
1493 >        const char *str = PrefsFindString("ftp_port_list");
1494          if (str == NULL)
1495                  str = "";
1496 <        gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), str);
1497 <        gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 0, 1, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
1498 <        w_ether = GTK_COMBO(combo)->entry;
1496 >        gtk_entry_set_text(GTK_ENTRY(entry), str);
1497 >        gtk_widget_show(entry);
1498 >        gtk_table_attach(GTK_TABLE(table), entry, 1, 2, 2, 3, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
1499 >        w_ftp_port_list = entry;
1500 >
1501 >        label = gtk_label_new(GetString(STR_ETHER_TCP_PORT_LIST_CTRL));
1502 >        gtk_widget_show(label);
1503 >        gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
1504 >
1505 >        entry = gtk_entry_new();
1506 >        str = PrefsFindString("tcp_port");
1507 >        if (str == NULL)
1508 >                str = "";
1509 >        gtk_entry_set_text(GTK_ENTRY(entry), str);
1510 >        gtk_widget_show(entry);
1511 >        gtk_table_attach(GTK_TABLE(table), entry, 1, 2, 3, 4, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
1512 >        w_tcp_port_list = entry;
1513  
1514          set_ethernet_sensitive();
1515   }
# Line 1231 | Line 1522 | static void create_ethernet_pane(GtkWidg
1522   static GtkWidget *w_ramsize;
1523   static GtkWidget *w_rom_file;
1524  
1525 + // Don't use CPU when idle?
1526 + #ifdef SHEEPSHAVER
1527 + static void tb_idlewait(GtkWidget *widget)
1528 + {
1529 +        PrefsReplaceBool("idlewait", GTK_TOGGLE_BUTTON(widget)->active);
1530 + }
1531 + #endif
1532 +
1533   // "Ignore SEGV" button toggled
1534   #ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
1535   static void tb_ignoresegv(GtkWidget *widget)
# Line 1273 | Line 1572 | static void create_memory_pane(GtkWidget
1572          table = make_table(box, 2, 5);
1573  
1574          static const combo_desc options[] = {
1575 + #ifndef SHEEPSHAVER
1576                  STR_RAMSIZE_2MB_LAB,
1577 + #endif
1578                  STR_RAMSIZE_4MB_LAB,
1579                  STR_RAMSIZE_8MB_LAB,
1580                  STR_RAMSIZE_16MB_LAB,
# Line 1282 | Line 1583 | static void create_memory_pane(GtkWidget
1583                  STR_RAMSIZE_128MB_LAB,
1584                  STR_RAMSIZE_256MB_LAB,
1585                  STR_RAMSIZE_512MB_LAB,
1586 + #ifndef SHEEPSHAVER
1587                  STR_RAMSIZE_1024MB_LAB,
1588 + #endif
1589                  0
1590          };
1591          char default_ramsize[10];
1592          sprintf(default_ramsize, "%d", PrefsFindInt32("ramsize") >> 20);
1593          w_ramsize = table_make_combobox(table, 0, STR_RAMSIZE_CTRL, default_ramsize, options);
1594  
1595 + #ifndef SHEEPSHAVER
1596          static const opt_desc model_options[] = {
1597                  {STR_MODELID_5_LAB, GTK_SIGNAL_FUNC(mn_modelid_5)},
1598                  {STR_MODELID_14_LAB, GTK_SIGNAL_FUNC(mn_modelid_14)},
# Line 1300 | Line 1604 | static void create_memory_pane(GtkWidget
1604                  case 14: active = 1; break;
1605          }
1606          table_make_option_menu(table, 2, STR_MODELID_CTRL, model_options, active);
1607 + #endif
1608  
1609   #if EMULATED_68K
1610          static const opt_desc cpu_options[] = {
# Line 1326 | Line 1631 | static void create_memory_pane(GtkWidget
1631   #ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
1632          make_checkbox(box, STR_IGNORESEGV_CTRL, "ignoresegv", GTK_SIGNAL_FUNC(tb_ignoresegv));
1633   #endif
1634 +
1635 + #ifdef SHEEPSHAVER
1636 +        make_checkbox(box, STR_IDLEWAIT_CTRL, "idlewait", GTK_SIGNAL_FUNC(tb_idlewait));
1637 + #endif
1638   }
1639  
1640  
# Line 1353 | Line 1662 | static void read_settings(void)
1662   uint8 XPRAM[XPRAM_SIZE];
1663   void MountVolume(void *fh) { }
1664   void FileDiskLayout(loff_t size, uint8 *data, loff_t &start_byte, loff_t &real_size) { }
1665 < void WarningAlert(const char *text) { }
1665 > void recycle_write_packet(LPPACKET) { }
1666 > VOID CALLBACK packet_read_completion(DWORD, DWORD, LPOVERLAPPED) { }
1667  
1668  
1669   /*
# Line 1368 | Line 1678 | void SysAddSerialPrefs(void)
1678  
1679  
1680   /*
1681 + *  Display alerts
1682 + */
1683 +
1684 + static void display_alert(int title_id, const char *text, int flags)
1685 + {
1686 +        MessageBox(NULL, text, GetString(title_id), MB_OK | flags);
1687 + }
1688 +
1689 + void ErrorAlert(const char *text)
1690 + {
1691 +        display_alert(STR_ERROR_ALERT_TITLE, text, MB_ICONSTOP);
1692 + }
1693 +
1694 + void WarningAlert(const char *text)
1695 + {
1696 +        display_alert(STR_WARNING_ALERT_TITLE, text, MB_ICONSTOP);
1697 + }
1698 +
1699 +
1700 + /*
1701   *  Start standalone GUI
1702   */
1703  
# Line 1380 | Line 1710 | int main(int argc, char *argv[])
1710          // Read preferences
1711          PrefsInit(argc, argv);
1712  
1713 +        // Migrate preferences
1714 +        PrefsMigrate();
1715 +
1716          // Show preferences editor
1717          bool start = PrefsEditor();
1718  
1719          // Exit preferences
1720          PrefsExit();
1721  
1722 <        // Transfer control to the Basilisk II executable
1722 >        // Transfer control to the executable
1723          if (start) {
1724 <                printf("Start Basilisk II\n");
1724 >                char path[_MAX_PATH];
1725 >                bool ok = GetModuleFileName(NULL, path, sizeof(path)) != 0;
1726 >                if (ok) {
1727 >                        char b2_path[_MAX_PATH];
1728 >                        char *p = strrchr(path, '\\');
1729 >                        *++p = '\0';
1730 >                        SetCurrentDirectory(path);
1731 >                        strcpy(b2_path, path);
1732 >                        strcat(b2_path, PROGRAM_NAME);
1733 >                        strcat(b2_path, ".exe");
1734 >                        HINSTANCE h = ShellExecute(GetDesktopWindow(), "open",
1735 >                                                                           b2_path, "", path, SW_SHOWNORMAL);
1736 >                        if ((int)h <= 32)
1737 >                                ok = false;
1738 >                }
1739 >                if (!ok) {
1740 >                        ErrorAlert("Coult not start " PROGRAM_NAME " executable");
1741 >                        return 1;
1742 >                }
1743          }
1744  
1745          return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines