ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Unix/prefs_editor_gtk.cpp
Revision: 1.8
Committed: 2004-04-13T22:22:21Z (20 years, 2 months ago) by gbeauche
Branch: MAIN
Changes since 1.7: +9 -0 lines
Log Message:
Fix DGA mode for emulated PPC targets. It currently doesn't work in native
mode as the stack is corrupted and we are jumping to garbage when moving
the mouse. Also add 1152x768 resolution from PBG4, but make timing match
the 1152x870 version.

Cleanups, further merges from Basilisk II tree.

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * prefs_editor_linux.cpp - Preferences editor, Linux implementation using GTK+
3     *
4 cebix 1.6 * SheepShaver (C) 1997-2004 Christian Bauer and Marc Hellwig
5 cebix 1.1 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19     */
20    
21     #include "sysdeps.h"
22    
23     #include <gtk/gtk.h>
24     #include <stdlib.h>
25     #include <dirent.h>
26     #include <sys/socket.h>
27     #include <sys/ioctl.h>
28     #include <net/if.h>
29     #include <net/if_arp.h>
30    
31     #include "user_strings.h"
32     #include "version.h"
33     #include "cdrom.h"
34     #include "xpram.h"
35     #include "prefs.h"
36     #include "prefs_editor.h"
37    
38    
39     // Global variables
40     static GtkWidget *win; // Preferences window
41     static bool start_clicked = true; // Return value of PrefsEditor() function
42    
43    
44     // Prototypes
45     static void create_volumes_pane(GtkWidget *top);
46     static void create_graphics_pane(GtkWidget *top);
47 gbeauche 1.2 static void create_input_pane(GtkWidget *top);
48 cebix 1.1 static void create_serial_pane(GtkWidget *top);
49     static void create_memory_pane(GtkWidget *top);
50 gbeauche 1.3 static void create_jit_pane(GtkWidget *top);
51 cebix 1.1 static void read_settings(void);
52    
53    
54     /*
55     * Utility functions
56     */
57    
58     struct opt_desc {
59     int label_id;
60     GtkSignalFunc func;
61     };
62    
63     static void add_menu_item(GtkWidget *menu, int label_id, GtkSignalFunc func)
64     {
65     GtkWidget *item = gtk_menu_item_new_with_label(GetString(label_id));
66     gtk_widget_show(item);
67     gtk_signal_connect(GTK_OBJECT(item), "activate", func, NULL);
68     gtk_menu_append(GTK_MENU(menu), item);
69     }
70    
71     static GtkWidget *make_pane(GtkWidget *notebook, int title_id)
72     {
73     GtkWidget *frame, *label, *box;
74    
75     frame = gtk_frame_new(NULL);
76     gtk_widget_show(frame);
77     gtk_container_border_width(GTK_CONTAINER(frame), 4);
78    
79     label = gtk_label_new(GetString(title_id));
80     gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame, label);
81    
82     box = gtk_vbox_new(FALSE, 4);
83     gtk_widget_show(box);
84     gtk_container_set_border_width(GTK_CONTAINER(box), 4);
85     gtk_container_add(GTK_CONTAINER(frame), box);
86     return box;
87     }
88    
89     static GtkWidget *make_button_box(GtkWidget *top, int border, const opt_desc *buttons)
90     {
91     GtkWidget *bb, *button;
92    
93     bb = gtk_hbutton_box_new();
94     gtk_widget_show(bb);
95     gtk_container_set_border_width(GTK_CONTAINER(bb), border);
96     gtk_button_box_set_layout(GTK_BUTTON_BOX(bb), GTK_BUTTONBOX_DEFAULT_STYLE);
97     gtk_button_box_set_spacing(GTK_BUTTON_BOX(bb), 4);
98     gtk_box_pack_start(GTK_BOX(top), bb, FALSE, FALSE, 0);
99    
100     while (buttons->label_id) {
101     button = gtk_button_new_with_label(GetString(buttons->label_id));
102     gtk_widget_show(button);
103     gtk_signal_connect_object(GTK_OBJECT(button), "clicked", buttons->func, NULL);
104     gtk_box_pack_start(GTK_BOX(bb), button, TRUE, TRUE, 0);
105     buttons++;
106     }
107     return bb;
108     }
109    
110     static GtkWidget *make_separator(GtkWidget *top)
111     {
112     GtkWidget *sep = gtk_hseparator_new();
113     gtk_box_pack_start(GTK_BOX(top), sep, FALSE, FALSE, 0);
114     gtk_widget_show(sep);
115     return sep;
116     }
117    
118     static GtkWidget *make_table(GtkWidget *top, int x, int y)
119     {
120     GtkWidget *table = gtk_table_new(x, y, FALSE);
121     gtk_widget_show(table);
122     gtk_box_pack_start(GTK_BOX(top), table, FALSE, FALSE, 0);
123     return table;
124     }
125    
126     static GtkWidget *make_option_menu(GtkWidget *top, int label_id, const opt_desc *options, int active)
127     {
128     GtkWidget *box, *label, *opt, *menu;
129    
130     box = gtk_hbox_new(FALSE, 4);
131     gtk_widget_show(box);
132     gtk_box_pack_start(GTK_BOX(top), box, FALSE, FALSE, 0);
133    
134     label = gtk_label_new(GetString(label_id));
135     gtk_widget_show(label);
136     gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);
137    
138     opt = gtk_option_menu_new();
139     gtk_widget_show(opt);
140     menu = gtk_menu_new();
141    
142     while (options->label_id) {
143     add_menu_item(menu, options->label_id, options->func);
144     options++;
145     }
146     gtk_menu_set_active(GTK_MENU(menu), active);
147    
148     gtk_option_menu_set_menu(GTK_OPTION_MENU(opt), menu);
149     gtk_box_pack_start(GTK_BOX(box), opt, FALSE, FALSE, 0);
150     return menu;
151     }
152    
153     static GtkWidget *make_entry(GtkWidget *top, int label_id, const char *prefs_item)
154     {
155     GtkWidget *box, *label, *entry;
156    
157     box = gtk_hbox_new(FALSE, 4);
158     gtk_widget_show(box);
159     gtk_box_pack_start(GTK_BOX(top), box, FALSE, FALSE, 0);
160    
161     label = gtk_label_new(GetString(label_id));
162     gtk_widget_show(label);
163     gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);
164    
165     entry = gtk_entry_new();
166     gtk_widget_show(entry);
167     const char *str = PrefsFindString(prefs_item);
168     if (str == NULL)
169     str = "";
170     gtk_entry_set_text(GTK_ENTRY(entry), str);
171     gtk_box_pack_start(GTK_BOX(box), entry, TRUE, TRUE, 0);
172     return entry;
173     }
174    
175 gbeauche 1.2 static char *get_file_entry_path(GtkWidget *entry)
176     {
177     return gtk_entry_get_text(GTK_ENTRY(entry));
178     }
179    
180 cebix 1.1 static GtkWidget *make_checkbox(GtkWidget *top, int label_id, const char *prefs_item, GtkSignalFunc func)
181     {
182     GtkWidget *button = gtk_check_button_new_with_label(GetString(label_id));
183     gtk_widget_show(button);
184     gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), PrefsFindBool(prefs_item));
185     gtk_signal_connect(GTK_OBJECT(button), "toggled", func, button);
186     gtk_box_pack_start(GTK_BOX(top), button, FALSE, FALSE, 0);
187     return button;
188     }
189    
190     static GtkWidget *make_checkbox(GtkWidget *top, int label_id, bool active, GtkSignalFunc func)
191     {
192     GtkWidget *button = gtk_check_button_new_with_label(GetString(label_id));
193     gtk_widget_show(button);
194     gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), active);
195     gtk_signal_connect(GTK_OBJECT(button), "toggled", func, button);
196     gtk_box_pack_start(GTK_BOX(top), button, FALSE, FALSE, 0);
197     return button;
198     }
199    
200    
201     /*
202     * Show preferences editor
203     * Returns true when user clicked on "Start", false otherwise
204     */
205    
206     // Window closed
207     static gint window_closed(void)
208     {
209     return FALSE;
210     }
211    
212     // Window destroyed
213     static void window_destroyed(void)
214     {
215     gtk_main_quit();
216     }
217    
218     // "Start" button clicked
219     static void cb_start(...)
220     {
221     start_clicked = true;
222     read_settings();
223     SavePrefs();
224     gtk_widget_destroy(win);
225     }
226    
227     // "Quit" button clicked
228     static void cb_quit(...)
229     {
230     start_clicked = false;
231     gtk_widget_destroy(win);
232     }
233    
234     // "OK" button of "About" dialog clicked
235     static void dl_quit(GtkWidget *dialog)
236     {
237     gtk_widget_destroy(dialog);
238     }
239    
240     // "About" selected
241     static void mn_about(...)
242     {
243     GtkWidget *dialog, *label, *button;
244    
245     char str[512];
246     sprintf(str,
247     "SheepShaver\nVersion %d.%d\n\n"
248 cebix 1.6 "Copyright (C) 1997-2004 Christian Bauer and Marc Hellwig\n"
249 cebix 1.1 "E-mail: Christian.Bauer@uni-mainz.de\n"
250     "http://www.uni-mainz.de/~bauec002/\n\n"
251     "SheepShaver comes with ABSOLUTELY NO\n"
252     "WARRANTY. This is free software, and\n"
253     "you are welcome to redistribute it\n"
254     "under the terms of the GNU General\n"
255     "Public License.\n",
256     VERSION_MAJOR, VERSION_MINOR
257     );
258    
259     dialog = gtk_dialog_new();
260     gtk_window_set_title(GTK_WINDOW(dialog), GetString(STR_ABOUT_TITLE));
261     gtk_container_border_width(GTK_CONTAINER(dialog), 5);
262     gtk_widget_set_uposition(GTK_WIDGET(dialog), 100, 150);
263    
264     label = gtk_label_new(str);
265     gtk_widget_show(label);
266     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), label, TRUE, TRUE, 0);
267    
268     button = gtk_button_new_with_label(GetString(STR_OK_BUTTON));
269     gtk_widget_show(button);
270     gtk_signal_connect_object(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(dl_quit), GTK_OBJECT(dialog));
271     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), button, FALSE, FALSE, 0);
272     GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
273     gtk_widget_grab_default(button);
274     gtk_widget_show(dialog);
275     }
276    
277     // "Zap NVRAM" selected
278     static void mn_zap_pram(...)
279     {
280     ZapPRAM();
281     }
282    
283     // Menu item descriptions
284     static GtkItemFactoryEntry menu_items[] = {
285     {(gchar *)GetString(STR_PREFS_MENU_FILE_GTK), NULL, NULL, 0, "<Branch>"},
286     {(gchar *)GetString(STR_PREFS_ITEM_START_GTK), NULL, GTK_SIGNAL_FUNC(cb_start), 0, NULL},
287     {(gchar *)GetString(STR_PREFS_ITEM_ZAP_PRAM_GTK), NULL, GTK_SIGNAL_FUNC(mn_zap_pram), 0, NULL},
288     {(gchar *)GetString(STR_PREFS_ITEM_SEPL_GTK), NULL, NULL, 0, "<Separator>"},
289     {(gchar *)GetString(STR_PREFS_ITEM_QUIT_GTK), "<control>Q", GTK_SIGNAL_FUNC(cb_quit), 0, NULL},
290     {(gchar *)GetString(STR_HELP_MENU_GTK), NULL, NULL, 0, "<LastBranch>"},
291     {(gchar *)GetString(STR_HELP_ITEM_ABOUT_GTK), NULL, GTK_SIGNAL_FUNC(mn_about), 0, NULL}
292     };
293    
294     bool PrefsEditor(void)
295     {
296     // Create window
297     win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
298     gtk_window_set_title(GTK_WINDOW(win), GetString(STR_PREFS_TITLE));
299     gtk_signal_connect(GTK_OBJECT(win), "delete_event", GTK_SIGNAL_FUNC(window_closed), NULL);
300     gtk_signal_connect(GTK_OBJECT(win), "destroy", GTK_SIGNAL_FUNC(window_destroyed), NULL);
301    
302     // Create window contents
303     GtkWidget *box = gtk_vbox_new(FALSE, 4);
304     gtk_widget_show(box);
305     gtk_container_add(GTK_CONTAINER(win), box);
306    
307     GtkAccelGroup *accel_group = gtk_accel_group_new();
308     GtkItemFactory *item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", accel_group);
309     gtk_item_factory_create_items(item_factory, sizeof(menu_items) / sizeof(menu_items[0]), menu_items, NULL);
310     gtk_accel_group_attach(accel_group, GTK_OBJECT(win));
311     GtkWidget *menu_bar = gtk_item_factory_get_widget(item_factory, "<main>");
312     gtk_widget_show(menu_bar);
313     gtk_box_pack_start(GTK_BOX(box), menu_bar, FALSE, TRUE, 0);
314    
315     GtkWidget *notebook = gtk_notebook_new();
316     gtk_widget_show(notebook);
317     gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_TOP);
318     gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), FALSE);
319     gtk_box_pack_start(GTK_BOX(box), notebook, TRUE, TRUE, 0);
320    
321     create_volumes_pane(notebook);
322     create_graphics_pane(notebook);
323 gbeauche 1.2 create_input_pane(notebook);
324 cebix 1.1 create_serial_pane(notebook);
325     create_memory_pane(notebook);
326 gbeauche 1.3 create_jit_pane(notebook);
327 cebix 1.1
328     static const opt_desc buttons[] = {
329     {STR_START_BUTTON, GTK_SIGNAL_FUNC(cb_start)},
330     {STR_QUIT_BUTTON, GTK_SIGNAL_FUNC(cb_quit)},
331     {0, NULL}
332     };
333     make_button_box(box, 4, buttons);
334    
335     // Show window and enter main loop
336     gtk_widget_show(win);
337     gtk_main();
338     return start_clicked;
339     }
340    
341    
342     /*
343     * "Volumes" pane
344     */
345    
346     static GtkWidget *volume_list, *w_extfs;
347     static int selected_volume;
348    
349     // Volume in list selected
350     static void cl_selected(GtkWidget *list, int row, int column)
351     {
352     selected_volume = row;
353     }
354    
355     struct file_req_assoc {
356     file_req_assoc(GtkWidget *r, GtkWidget *e) : req(r), entry(e) {}
357     GtkWidget *req;
358     GtkWidget *entry;
359     };
360    
361     // Volume selected for addition
362     static void add_volume_ok(GtkWidget *button, file_req_assoc *assoc)
363     {
364     char *file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(assoc->req));
365     gtk_clist_append(GTK_CLIST(volume_list), &file);
366     gtk_widget_destroy(assoc->req);
367     delete assoc;
368     }
369    
370     // Volume selected for creation
371     static void create_volume_ok(GtkWidget *button, file_req_assoc *assoc)
372     {
373     char *file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(assoc->req));
374    
375     char *str = gtk_entry_get_text(GTK_ENTRY(assoc->entry));
376     int size = atoi(str);
377    
378     char cmd[1024];
379     sprintf(cmd, "dd if=/dev/zero \"of=%s\" bs=1024k count=%d", file, size);
380     int ret = system(cmd);
381     if (ret == 0)
382     gtk_clist_append(GTK_CLIST(volume_list), &file);
383     gtk_widget_destroy(GTK_WIDGET(assoc->req));
384     delete assoc;
385     }
386    
387     // "Add Volume" button clicked
388     static void cb_add_volume(...)
389     {
390     GtkWidget *req = gtk_file_selection_new(GetString(STR_ADD_VOLUME_TITLE));
391     gtk_signal_connect_object(GTK_OBJECT(req), "delete_event", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(req));
392     gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(req)->ok_button), "clicked", GTK_SIGNAL_FUNC(add_volume_ok), new file_req_assoc(req, NULL));
393     gtk_signal_connect_object(GTK_OBJECT(GTK_FILE_SELECTION(req)->cancel_button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(req));
394     gtk_widget_show(req);
395     }
396    
397     // "Create Hardfile" button clicked
398     static void cb_create_volume(...)
399     {
400     GtkWidget *req = gtk_file_selection_new(GetString(STR_CREATE_VOLUME_TITLE));
401    
402     GtkWidget *box = gtk_hbox_new(FALSE, 4);
403     gtk_widget_show(box);
404     GtkWidget *label = gtk_label_new(GetString(STR_HARDFILE_SIZE_CTRL));
405     gtk_widget_show(label);
406     GtkWidget *entry = gtk_entry_new();
407     gtk_widget_show(entry);
408     char str[32];
409     sprintf(str, "%d", 40);
410     gtk_entry_set_text(GTK_ENTRY(entry), str);
411     gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);
412     gtk_box_pack_start(GTK_BOX(box), entry, FALSE, FALSE, 0);
413     gtk_box_pack_start(GTK_BOX(GTK_FILE_SELECTION(req)->main_vbox), box, FALSE, FALSE, 0);
414    
415     gtk_signal_connect_object(GTK_OBJECT(req), "delete_event", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(req));
416     gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(req)->ok_button), "clicked", GTK_SIGNAL_FUNC(create_volume_ok), new file_req_assoc(req, entry));
417     gtk_signal_connect_object(GTK_OBJECT(GTK_FILE_SELECTION(req)->cancel_button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(req));
418     gtk_widget_show(req);
419     }
420    
421     // "Remove Volume" button clicked
422     static void cb_remove_volume(...)
423     {
424     gtk_clist_remove(GTK_CLIST(volume_list), selected_volume);
425     }
426    
427     // "Boot From" selected
428     static void mn_boot_any(...) {PrefsReplaceInt32("bootdriver", 0);}
429     static void mn_boot_cdrom(...) {PrefsReplaceInt32("bootdriver", CDROMRefNum);}
430    
431     // "No CD-ROM Driver" button toggled
432     static void tb_nocdrom(GtkWidget *widget)
433     {
434     PrefsReplaceBool("nocdrom", GTK_TOGGLE_BUTTON(widget)->active);
435     }
436    
437     // Read settings from widgets and set preferences
438     static void read_volumes_settings(void)
439     {
440     while (PrefsFindString("disk"))
441     PrefsRemoveItem("disk");
442    
443     for (int i=0; i<GTK_CLIST(volume_list)->rows; i++) {
444     char *str;
445     gtk_clist_get_text(GTK_CLIST(volume_list), i, 0, &str);
446     PrefsAddString("disk", str);
447     }
448    
449     PrefsReplaceString("extfs", gtk_entry_get_text(GTK_ENTRY(w_extfs)));
450     }
451    
452     // Create "Volumes" pane
453     static void create_volumes_pane(GtkWidget *top)
454     {
455     GtkWidget *box, *scroll, *menu;
456    
457     box = make_pane(top, STR_VOLUMES_PANE_TITLE);
458    
459     scroll = gtk_scrolled_window_new(NULL, NULL);
460     gtk_widget_show(scroll);
461     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
462     volume_list = gtk_clist_new(1);
463     gtk_widget_show(volume_list);
464     gtk_clist_set_selection_mode(GTK_CLIST(volume_list), GTK_SELECTION_SINGLE);
465     gtk_clist_set_shadow_type(GTK_CLIST(volume_list), GTK_SHADOW_NONE);
466     gtk_clist_set_reorderable(GTK_CLIST(volume_list), true);
467     gtk_signal_connect(GTK_OBJECT(volume_list), "select_row", GTK_SIGNAL_FUNC(cl_selected), NULL);
468     char *str;
469     int32 index = 0;
470     while ((str = (char *)PrefsFindString("disk", index++)) != NULL)
471     gtk_clist_append(GTK_CLIST(volume_list), &str);
472     gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), volume_list);
473     gtk_box_pack_start(GTK_BOX(box), scroll, TRUE, TRUE, 0);
474     selected_volume = 0;
475    
476     static const opt_desc buttons[] = {
477     {STR_ADD_VOLUME_BUTTON, GTK_SIGNAL_FUNC(cb_add_volume)},
478     {STR_CREATE_VOLUME_BUTTON, GTK_SIGNAL_FUNC(cb_create_volume)},
479     {STR_REMOVE_VOLUME_BUTTON, GTK_SIGNAL_FUNC(cb_remove_volume)},
480     {0, NULL},
481     };
482     make_button_box(box, 0, buttons);
483     make_separator(box);
484    
485     w_extfs = make_entry(box, STR_EXTFS_CTRL, "extfs");
486    
487     static const opt_desc options[] = {
488     {STR_BOOT_ANY_LAB, GTK_SIGNAL_FUNC(mn_boot_any)},
489     {STR_BOOT_CDROM_LAB, GTK_SIGNAL_FUNC(mn_boot_cdrom)},
490     {0, NULL}
491     };
492     int bootdriver = PrefsFindInt32("bootdriver"), active = 0;
493     switch (bootdriver) {
494     case 0: active = 0; break;
495     case CDROMRefNum: active = 1; break;
496     }
497     menu = make_option_menu(box, STR_BOOTDRIVER_CTRL, options, active);
498    
499     make_checkbox(box, STR_NOCDROM_CTRL, "nocdrom", GTK_SIGNAL_FUNC(tb_nocdrom));
500     }
501    
502    
503     /*
504 gbeauche 1.3 * "JIT Compiler" pane
505     */
506    
507     // Set sensitivity of widgets
508     static void set_jit_sensitive(void)
509     {
510     const bool jit_enabled = PrefsFindBool("jit");
511     }
512    
513     // "Use JIT Compiler" button toggled
514     static void tb_jit(GtkWidget *widget)
515     {
516     PrefsReplaceBool("jit", GTK_TOGGLE_BUTTON(widget)->active);
517     set_jit_sensitive();
518     }
519    
520     // Read settings from widgets and set preferences
521     static void read_jit_settings(void)
522     {
523     #if USE_JIT
524     bool jit_enabled = PrefsFindBool("jit");
525     #endif
526     }
527    
528     // Create "JIT Compiler" pane
529     static void create_jit_pane(GtkWidget *top)
530     {
531     #if USE_JIT
532     GtkWidget *box, *table, *label, *menu;
533     char str[32];
534    
535     box = make_pane(top, STR_JIT_PANE_TITLE);
536     make_checkbox(box, STR_JIT_CTRL, "jit", GTK_SIGNAL_FUNC(tb_jit));
537    
538     set_jit_sensitive();
539     #endif
540     }
541    
542    
543     /*
544 cebix 1.1 * "Graphics/Sound" pane
545     */
546    
547     static GtkWidget *w_frameskip;
548    
549 gbeauche 1.4 static GtkWidget *w_dspdevice_file, *w_mixerdevice_file;
550    
551 cebix 1.1 // "5 Hz".."60Hz" selected
552     static void mn_5hz(...) {PrefsReplaceInt32("frameskip", 12);}
553     static void mn_7hz(...) {PrefsReplaceInt32("frameskip", 8);}
554     static void mn_10hz(...) {PrefsReplaceInt32("frameskip", 6);}
555     static void mn_15hz(...) {PrefsReplaceInt32("frameskip", 4);}
556     static void mn_30hz(...) {PrefsReplaceInt32("frameskip", 2);}
557     static void mn_60hz(...) {PrefsReplaceInt32("frameskip", 1);}
558    
559     // Video modes
560     static void tb_w640x480(GtkWidget *widget)
561     {
562     if (GTK_TOGGLE_BUTTON(widget)->active)
563     PrefsReplaceInt32("windowmodes", PrefsFindInt32("windowmodes") | 1);
564     else
565     PrefsReplaceInt32("windowmodes", PrefsFindInt32("windowmodes") & ~1);
566     }
567    
568     static void tb_w800x600(GtkWidget *widget)
569     {
570     if (GTK_TOGGLE_BUTTON(widget)->active)
571     PrefsReplaceInt32("windowmodes", PrefsFindInt32("windowmodes") | 2);
572     else
573     PrefsReplaceInt32("windowmodes", PrefsFindInt32("windowmodes") & ~2);
574     }
575    
576     static void tb_fs640x480(GtkWidget *widget)
577     {
578     if (GTK_TOGGLE_BUTTON(widget)->active)
579     PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") | 1);
580     else
581     PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") & ~1);
582     }
583    
584     static void tb_fs800x600(GtkWidget *widget)
585     {
586     if (GTK_TOGGLE_BUTTON(widget)->active)
587     PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") | 2);
588     else
589     PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") & ~2);
590     }
591    
592     static void tb_fs1024x768(GtkWidget *widget)
593     {
594     if (GTK_TOGGLE_BUTTON(widget)->active)
595     PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") | 4);
596     else
597     PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") & ~4);
598     }
599    
600 gbeauche 1.8 static void tb_fs1152x768(GtkWidget *widget)
601     {
602     if (GTK_TOGGLE_BUTTON(widget)->active)
603     PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") | 64);
604     else
605     PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") & ~64);
606     }
607    
608 cebix 1.1 static void tb_fs1152x900(GtkWidget *widget)
609     {
610     if (GTK_TOGGLE_BUTTON(widget)->active)
611     PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") | 8);
612     else
613     PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") & ~8);
614     }
615    
616     static void tb_fs1280x1024(GtkWidget *widget)
617     {
618     if (GTK_TOGGLE_BUTTON(widget)->active)
619     PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") | 16);
620     else
621     PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") & ~16);
622     }
623    
624     static void tb_fs1600x1200(GtkWidget *widget)
625     {
626     if (GTK_TOGGLE_BUTTON(widget)->active)
627     PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") | 32);
628     else
629     PrefsReplaceInt32("screenmodes", PrefsFindInt32("screenmodes") & ~32);
630     }
631    
632 gbeauche 1.4 // Set sensitivity of widgets
633     static void set_graphics_sensitive(void)
634     {
635     const bool sound_enabled = !PrefsFindBool("nosound");
636     gtk_widget_set_sensitive(w_dspdevice_file, sound_enabled);
637     gtk_widget_set_sensitive(w_mixerdevice_file, sound_enabled);
638     }
639    
640 cebix 1.1 // "Disable Sound Output" button toggled
641     static void tb_nosound(GtkWidget *widget)
642     {
643     PrefsReplaceBool("nosound", GTK_TOGGLE_BUTTON(widget)->active);
644 gbeauche 1.4 set_graphics_sensitive();
645 cebix 1.1 }
646    
647     // Read settings from widgets and set preferences
648     static void read_graphics_settings(void)
649     {
650 gbeauche 1.4 PrefsReplaceString("dsp", get_file_entry_path(w_dspdevice_file));
651     PrefsReplaceString("mixer", get_file_entry_path(w_mixerdevice_file));
652 cebix 1.1 }
653    
654     // Create "Graphics/Sound" pane
655     static void create_graphics_pane(GtkWidget *top)
656     {
657     GtkWidget *box, *vbox, *frame;
658    
659     box = make_pane(top, STR_GRAPHICS_SOUND_PANE_TITLE);
660    
661     static const opt_desc options[] = {
662     {STR_REF_5HZ_LAB, GTK_SIGNAL_FUNC(mn_5hz)},
663     {STR_REF_7_5HZ_LAB, GTK_SIGNAL_FUNC(mn_7hz)},
664     {STR_REF_10HZ_LAB, GTK_SIGNAL_FUNC(mn_10hz)},
665     {STR_REF_15HZ_LAB, GTK_SIGNAL_FUNC(mn_15hz)},
666     {STR_REF_30HZ_LAB, GTK_SIGNAL_FUNC(mn_30hz)},
667     {STR_REF_60HZ_LAB, GTK_SIGNAL_FUNC(mn_60hz)},
668     {0, NULL}
669     };
670     int frameskip = PrefsFindInt32("frameskip"), active = 0;
671     switch (frameskip) {
672     case 12: active = 0; break;
673     case 8: active = 1; break;
674     case 6: active = 2; break;
675     case 4: active = 3; break;
676     case 2: active = 4; break;
677     case 1: active = 5; break;
678     }
679     w_frameskip = make_option_menu(box, STR_FRAMESKIP_CTRL, options, active);
680    
681     frame = gtk_frame_new (GetString(STR_VIDEO_MODE_CTRL));
682     gtk_widget_show(frame);
683     gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 0);
684    
685     vbox = gtk_vbox_new(FALSE, 4);
686     gtk_widget_show(vbox);
687     gtk_container_set_border_width(GTK_CONTAINER(vbox), 4);
688     gtk_container_add(GTK_CONTAINER(frame), vbox);
689    
690     make_checkbox(vbox, STR_W_640x480_CTRL, PrefsFindInt32("windowmodes") & 1, GTK_SIGNAL_FUNC(tb_w640x480));
691     make_checkbox(vbox, STR_W_800x600_CTRL, PrefsFindInt32("windowmodes") & 2, GTK_SIGNAL_FUNC(tb_w800x600));
692     make_checkbox(vbox, STR_640x480_CTRL, PrefsFindInt32("screenmodes") & 1, GTK_SIGNAL_FUNC(tb_fs640x480));
693     make_checkbox(vbox, STR_800x600_CTRL, PrefsFindInt32("screenmodes") & 2, GTK_SIGNAL_FUNC(tb_fs800x600));
694     make_checkbox(vbox, STR_1024x768_CTRL, PrefsFindInt32("screenmodes") & 4, GTK_SIGNAL_FUNC(tb_fs1024x768));
695 gbeauche 1.8 make_checkbox(vbox, STR_1152x768_CTRL, PrefsFindInt32("screenmodes") & 64, GTK_SIGNAL_FUNC(tb_fs1152x768));
696 cebix 1.1 make_checkbox(vbox, STR_1152x900_CTRL, PrefsFindInt32("screenmodes") & 8, GTK_SIGNAL_FUNC(tb_fs1152x900));
697     make_checkbox(vbox, STR_1280x1024_CTRL, PrefsFindInt32("screenmodes") & 16, GTK_SIGNAL_FUNC(tb_fs1280x1024));
698     make_checkbox(vbox, STR_1600x1200_CTRL, PrefsFindInt32("screenmodes") & 32, GTK_SIGNAL_FUNC(tb_fs1600x1200));
699    
700 gbeauche 1.4 make_separator(box);
701 cebix 1.1 make_checkbox(box, STR_NOSOUND_CTRL, "nosound", GTK_SIGNAL_FUNC(tb_nosound));
702 gbeauche 1.4 w_dspdevice_file = make_entry(box, STR_DSPDEVICE_FILE_CTRL, "dsp");
703     w_mixerdevice_file = make_entry(box, STR_MIXERDEVICE_FILE_CTRL, "mixer");
704    
705     set_graphics_sensitive();
706 gbeauche 1.2 }
707    
708    
709     /*
710     * "Input" pane
711     */
712    
713     static GtkWidget *w_keycode_file;
714 gbeauche 1.5 static GtkWidget *w_mouse_wheel_lines;
715 gbeauche 1.2
716     // Set sensitivity of widgets
717     static void set_input_sensitive(void)
718     {
719     gtk_widget_set_sensitive(w_keycode_file, PrefsFindBool("keycodes"));
720 gbeauche 1.5 gtk_widget_set_sensitive(w_mouse_wheel_lines, PrefsFindInt32("mousewheelmode") == 1);
721 gbeauche 1.2 }
722    
723     // "Use Raw Keycodes" button toggled
724     static void tb_keycodes(GtkWidget *widget)
725     {
726     PrefsReplaceBool("keycodes", GTK_TOGGLE_BUTTON(widget)->active);
727     set_input_sensitive();
728     }
729    
730 gbeauche 1.5 // "Mouse Wheel Mode" selected
731     static void mn_wheel_page(...) {PrefsReplaceInt32("mousewheelmode", 0); set_input_sensitive();}
732     static void mn_wheel_cursor(...) {PrefsReplaceInt32("mousewheelmode", 1); set_input_sensitive();}
733    
734 gbeauche 1.2 // Read settings from widgets and set preferences
735     static void read_input_settings(void)
736     {
737     const char *str = get_file_entry_path(w_keycode_file);
738     if (str && strlen(str))
739     PrefsReplaceString("keycodefile", str);
740     else
741     PrefsRemoveItem("keycodefile");
742 gbeauche 1.5
743     PrefsReplaceInt32("mousewheellines", gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(w_mouse_wheel_lines)));
744 gbeauche 1.2 }
745    
746     // Create "Input" pane
747     static void create_input_pane(GtkWidget *top)
748     {
749     GtkWidget *box, *hbox, *menu, *label;
750     GtkObject *adj;
751    
752     box = make_pane(top, STR_INPUT_PANE_TITLE);
753    
754     make_checkbox(box, STR_KEYCODES_CTRL, "keycodes", GTK_SIGNAL_FUNC(tb_keycodes));
755     w_keycode_file = make_entry(box, STR_KEYCODE_FILE_CTRL, "keycodefile");
756 gbeauche 1.5
757     make_separator(box);
758    
759     static const opt_desc options[] = {
760     {STR_MOUSEWHEELMODE_PAGE_LAB, GTK_SIGNAL_FUNC(mn_wheel_page)},
761     {STR_MOUSEWHEELMODE_CURSOR_LAB, GTK_SIGNAL_FUNC(mn_wheel_cursor)},
762     {0, NULL}
763     };
764     int wheelmode = PrefsFindInt32("mousewheelmode"), active = 0;
765     switch (wheelmode) {
766     case 0: active = 0; break;
767     case 1: active = 1; break;
768     }
769     menu = make_option_menu(box, STR_MOUSEWHEELMODE_CTRL, options, active);
770    
771     hbox = gtk_hbox_new(FALSE, 4);
772     gtk_widget_show(hbox);
773     gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
774    
775     label = gtk_label_new(GetString(STR_MOUSEWHEELLINES_CTRL));
776     gtk_widget_show(label);
777     gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
778    
779     adj = gtk_adjustment_new(PrefsFindInt32("mousewheellines"), 1, 1000, 1, 5, 0);
780     w_mouse_wheel_lines = gtk_spin_button_new(GTK_ADJUSTMENT(adj), 0.0, 0);
781     gtk_widget_show(w_mouse_wheel_lines);
782     gtk_box_pack_start(GTK_BOX(hbox), w_mouse_wheel_lines, FALSE, FALSE, 0);
783 gbeauche 1.2
784     set_input_sensitive();
785 cebix 1.1 }
786    
787    
788     /*
789     * "Serial/Network" pane
790     */
791    
792     static GtkWidget *w_seriala, *w_serialb, *w_ether;
793    
794     // Read settings from widgets and set preferences
795     static void read_serial_settings(void)
796     {
797     const char *str;
798    
799     str = gtk_entry_get_text(GTK_ENTRY(w_seriala));
800     PrefsReplaceString("seriala", str);
801    
802     str = gtk_entry_get_text(GTK_ENTRY(w_serialb));
803     PrefsReplaceString("serialb", str);
804    
805     str = gtk_entry_get_text(GTK_ENTRY(w_ether));
806     if (str && strlen(str))
807     PrefsReplaceString("ether", str);
808     else
809     PrefsRemoveItem("ether");
810     }
811    
812     // Add names of serial devices
813     static gint gl_str_cmp(gconstpointer a, gconstpointer b)
814     {
815     return strcmp((char *)a, (char *)b);
816     }
817    
818     static GList *add_serial_names(void)
819     {
820     GList *glist = NULL;
821    
822     // Search /dev for ttyS* and lp*
823     DIR *d = opendir("/dev");
824     if (d) {
825     struct dirent *de;
826     while ((de = readdir(d)) != NULL) {
827 gbeauche 1.7 #if defined(__linux__)
828 cebix 1.1 if (strncmp(de->d_name, "ttyS", 4) == 0 || strncmp(de->d_name, "lp", 2) == 0) {
829 gbeauche 1.7 #elif defined(__FreeBSD__)
830     if (strncmp(de->d_name, "cuaa", 4) == 0 || strncmp(de->d_name, "lpt", 3) == 0) {
831     #elif defined(__NetBSD__)
832     if (strncmp(de->d_name, "tty0", 4) == 0 || strncmp(de->d_name, "lpt", 3) == 0) {
833     #elif defined(sgi)
834     if (strncmp(de->d_name, "ttyf", 4) == 0 || strncmp(de->d_name, "plp", 3) == 0) {
835     #else
836     if (false) {
837     #endif
838 cebix 1.1 char *str = new char[64];
839     sprintf(str, "/dev/%s", de->d_name);
840     glist = g_list_append(glist, str);
841     }
842     }
843     closedir(d);
844     }
845     if (glist)
846     g_list_sort(glist, gl_str_cmp);
847     else
848     glist = g_list_append(glist, (void *)"<none>");
849     return glist;
850     }
851    
852     // Add names of ethernet interfaces
853     static GList *add_ether_names(void)
854     {
855     GList *glist = NULL;
856    
857     // Get list of all Ethernet interfaces
858     int s = socket(PF_INET, SOCK_DGRAM, 0);
859     if (s >= 0) {
860     char inbuf[8192];
861     struct ifconf ifc;
862     ifc.ifc_len = sizeof(inbuf);
863     ifc.ifc_buf = inbuf;
864     if (ioctl(s, SIOCGIFCONF, &ifc) == 0) {
865     struct ifreq req, *ifr = ifc.ifc_req;
866     for (int i=0; i<ifc.ifc_len; i+=sizeof(ifreq), ifr++) {
867     req = *ifr;
868 gbeauche 1.7 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(sgi)
869     if (ioctl(s, SIOCGIFADDR, &req) == 0 && (req.ifr_addr.sa_family == ARPHRD_ETHER || req.ifr_addr.sa_family == ARPHRD_ETHER+1)) {
870     #elif defined(__linux__)
871 cebix 1.1 if (ioctl(s, SIOCGIFHWADDR, &req) == 0 && req.ifr_hwaddr.sa_family == ARPHRD_ETHER) {
872 gbeauche 1.7 #else
873     if (false) {
874     #endif
875 cebix 1.1 char *str = new char[64];
876     strncpy(str, ifr->ifr_name, 63);
877     glist = g_list_append(glist, str);
878     }
879     }
880     }
881     close(s);
882     }
883     if (glist)
884     g_list_sort(glist, gl_str_cmp);
885     else
886     glist = g_list_append(glist, (void *)"<none>");
887     return glist;
888     }
889    
890     // Create "Serial/Network" pane
891     static void create_serial_pane(GtkWidget *top)
892     {
893     GtkWidget *box, *table, *label, *combo;
894     GList *glist = add_serial_names();
895    
896     box = make_pane(top, STR_SERIAL_NETWORK_PANE_TITLE);
897     table = make_table(box, 2, 3);
898    
899     label = gtk_label_new(GetString(STR_SERPORTA_CTRL));
900     gtk_widget_show(label);
901     gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
902    
903     combo = gtk_combo_new();
904     gtk_widget_show(combo);
905     gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
906     const char *str = PrefsFindString("seriala");
907     if (str == NULL)
908     str = "";
909     gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), str);
910     gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 0, 1, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
911     w_seriala = GTK_COMBO(combo)->entry;
912    
913     label = gtk_label_new(GetString(STR_SERPORTB_CTRL));
914     gtk_widget_show(label);
915     gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
916    
917     combo = gtk_combo_new();
918     gtk_widget_show(combo);
919     gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
920     str = PrefsFindString("serialb");
921     if (str == NULL)
922     str = "";
923     gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), str);
924     gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 1, 2, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
925     w_serialb = GTK_COMBO(combo)->entry;
926    
927     label = gtk_label_new(GetString(STR_ETHERNET_IF_CTRL));
928     gtk_widget_show(label);
929     gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4);
930    
931     glist = add_ether_names();
932     combo = gtk_combo_new();
933     gtk_widget_show(combo);
934     gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
935     str = PrefsFindString("ether");
936     if (str == NULL)
937     str = "";
938     gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), str);
939     gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 2, 3, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4);
940     w_ether = GTK_COMBO(combo)->entry;
941     }
942    
943    
944     /*
945     * "Memory/Misc" pane
946     */
947    
948     static GtkObject *w_ramsize_adj;
949     static GtkWidget *w_rom_file;
950    
951     // "Ignore SEGV" button toggled
952     static void tb_ignoresegv(GtkWidget *widget)
953     {
954     PrefsReplaceBool("ignoresegv", GTK_TOGGLE_BUTTON(widget)->active);
955     }
956    
957     // Read settings from widgets and set preferences
958     static void read_memory_settings(void)
959     {
960     PrefsReplaceInt32("ramsize", int(GTK_ADJUSTMENT(w_ramsize_adj)->value) << 20);
961    
962     const char *str = gtk_entry_get_text(GTK_ENTRY(w_rom_file));
963     if (str && strlen(str))
964     PrefsReplaceString("rom", str);
965     else
966     PrefsRemoveItem("rom");
967     }
968    
969     // Create "Memory/Misc" pane
970     static void create_memory_pane(GtkWidget *top)
971     {
972     GtkWidget *box, *vbox, *hbox, *hbox2, *label, *scale;
973    
974     box = make_pane(top, STR_MEMORY_MISC_PANE_TITLE);
975    
976     hbox = gtk_hbox_new(FALSE, 4);
977     gtk_widget_show(hbox);
978    
979     label = gtk_label_new(GetString(STR_RAMSIZE_SLIDER));
980     gtk_widget_show(label);
981     gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
982    
983     vbox = gtk_vbox_new(FALSE, 4);
984     gtk_widget_show(vbox);
985    
986     gfloat min, max;
987     min = 1;
988     max = 256;
989     w_ramsize_adj = gtk_adjustment_new(min, min, max, 1, 16, 0);
990     gtk_adjustment_set_value(GTK_ADJUSTMENT(w_ramsize_adj), PrefsFindInt32("ramsize") >> 20);
991    
992     scale = gtk_hscale_new(GTK_ADJUSTMENT(w_ramsize_adj));
993     gtk_widget_show(scale);
994     gtk_scale_set_digits(GTK_SCALE(scale), 0);
995     gtk_box_pack_start(GTK_BOX(vbox), scale, TRUE, TRUE, 0);
996    
997     hbox2 = gtk_hbox_new(FALSE, 4);
998     gtk_widget_show(hbox2);
999    
1000     char val[32];
1001     sprintf(val, GetString(STR_RAMSIZE_FMT), int(min));
1002     label = gtk_label_new(val);
1003     gtk_widget_show(label);
1004     gtk_box_pack_start(GTK_BOX(hbox2), label, FALSE, FALSE, 0);
1005    
1006     sprintf(val, GetString(STR_RAMSIZE_FMT), int(max));
1007     label = gtk_label_new(val);
1008     gtk_widget_show(label);
1009     gtk_box_pack_end(GTK_BOX(hbox2), label, FALSE, FALSE, 0);
1010     gtk_box_pack_start(GTK_BOX(vbox), hbox2, TRUE, TRUE, 0);
1011     gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0);
1012     gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
1013    
1014     w_rom_file = make_entry(box, STR_ROM_FILE_CTRL, "rom");
1015    
1016     make_checkbox(box, STR_IGNORESEGV_CTRL, "ignoresegv", GTK_SIGNAL_FUNC(tb_ignoresegv));
1017     }
1018    
1019    
1020     /*
1021     * Read settings from widgets and set preferences
1022     */
1023    
1024     static void read_settings(void)
1025     {
1026     read_volumes_settings();
1027     read_graphics_settings();
1028     read_serial_settings();
1029     read_memory_settings();
1030 gbeauche 1.3 read_jit_settings();
1031 cebix 1.1 }