39 |
|
#include "prefs.h" |
40 |
|
#include "prefs_editor.h" |
41 |
|
|
42 |
+ |
#define DEBUG 0 |
43 |
+ |
#include "debug.h" |
44 |
+ |
|
45 |
|
|
46 |
|
// Global variables |
47 |
|
static GtkWidget *win; // Preferences window |
48 |
< |
static bool start_clicked = true; // Return value of PrefsEditor() function |
48 |
> |
static bool start_clicked = false; // Return value of PrefsEditor() function |
49 |
|
|
50 |
|
|
51 |
|
// Prototypes |
63 |
|
* Utility functions |
64 |
|
*/ |
65 |
|
|
66 |
+ |
#if ! GLIB_CHECK_VERSION(2,0,0) |
67 |
+ |
#define G_OBJECT(obj) GTK_OBJECT(obj) |
68 |
+ |
#define g_object_get_data(obj, key) gtk_object_get_data((obj), (key)) |
69 |
+ |
#define g_object_set_data(obj, key, data) gtk_object_set_data((obj), (key), (data)) |
70 |
+ |
#endif |
71 |
+ |
|
72 |
|
struct opt_desc { |
73 |
|
int label_id; |
74 |
|
GtkSignalFunc func; |
78 |
|
int label_id; |
79 |
|
}; |
80 |
|
|
81 |
+ |
struct file_req_assoc { |
82 |
+ |
file_req_assoc(GtkWidget *r, GtkWidget *e) : req(r), entry(e) {} |
83 |
+ |
GtkWidget *req; |
84 |
+ |
GtkWidget *entry; |
85 |
+ |
}; |
86 |
+ |
|
87 |
+ |
static void cb_browse_ok(GtkWidget *button, file_req_assoc *assoc) |
88 |
+ |
{ |
89 |
+ |
gchar *file = (char *)gtk_file_selection_get_filename(GTK_FILE_SELECTION(assoc->req)); |
90 |
+ |
gtk_entry_set_text(GTK_ENTRY(assoc->entry), file); |
91 |
+ |
gtk_widget_destroy(assoc->req); |
92 |
+ |
delete assoc; |
93 |
+ |
} |
94 |
+ |
|
95 |
+ |
static void cb_browse(GtkWidget *widget, void *user_data) |
96 |
+ |
{ |
97 |
+ |
GtkWidget *req = gtk_file_selection_new(GetString(STR_BROWSE_TITLE)); |
98 |
+ |
gtk_signal_connect_object(GTK_OBJECT(req), "delete_event", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(req)); |
99 |
+ |
gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(req)->ok_button), "clicked", GTK_SIGNAL_FUNC(cb_browse_ok), new file_req_assoc(req, (GtkWidget *)user_data)); |
100 |
+ |
gtk_signal_connect_object(GTK_OBJECT(GTK_FILE_SELECTION(req)->cancel_button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(req)); |
101 |
+ |
gtk_widget_show(req); |
102 |
+ |
} |
103 |
+ |
|
104 |
+ |
static GtkWidget *make_browse_button(GtkWidget *entry) |
105 |
+ |
{ |
106 |
+ |
GtkWidget *button; |
107 |
+ |
|
108 |
+ |
button = gtk_button_new_with_label(GetString(STR_BROWSE_CTRL)); |
109 |
+ |
gtk_widget_show(button); |
110 |
+ |
gtk_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc)cb_browse, (void *)entry); |
111 |
+ |
return button; |
112 |
+ |
} |
113 |
+ |
|
114 |
|
static void add_menu_item(GtkWidget *menu, int label_id, GtkSignalFunc func) |
115 |
|
{ |
116 |
|
GtkWidget *item = gtk_menu_item_new_with_label(GetString(label_id)); |
124 |
|
GtkWidget *frame, *label, *box; |
125 |
|
|
126 |
|
frame = gtk_frame_new(NULL); |
127 |
< |
gtk_widget_show(frame); |
86 |
< |
gtk_container_border_width(GTK_CONTAINER(frame), 4); |
87 |
< |
|
88 |
< |
label = gtk_label_new(GetString(title_id)); |
89 |
< |
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame, label); |
127 |
> |
gtk_container_set_border_width(GTK_CONTAINER(frame), 4); |
128 |
|
|
129 |
|
box = gtk_vbox_new(FALSE, 4); |
92 |
– |
gtk_widget_show(box); |
130 |
|
gtk_container_set_border_width(GTK_CONTAINER(box), 4); |
131 |
|
gtk_container_add(GTK_CONTAINER(frame), box); |
132 |
+ |
|
133 |
+ |
gtk_widget_show_all(frame); |
134 |
+ |
|
135 |
+ |
label = gtk_label_new(GetString(title_id)); |
136 |
+ |
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame, label); |
137 |
|
return box; |
138 |
|
} |
139 |
|
|
174 |
|
return table; |
175 |
|
} |
176 |
|
|
177 |
+ |
static GtkWidget *table_make_option_menu(GtkWidget *table, int row, int label_id, const opt_desc *options, int active) |
178 |
+ |
{ |
179 |
+ |
GtkWidget *label, *opt, *menu; |
180 |
+ |
|
181 |
+ |
label = gtk_label_new(GetString(label_id)); |
182 |
+ |
gtk_widget_show(label); |
183 |
+ |
gtk_table_attach(GTK_TABLE(table), label, 0, 1, row, row + 1, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4); |
184 |
+ |
|
185 |
+ |
opt = gtk_option_menu_new(); |
186 |
+ |
gtk_widget_show(opt); |
187 |
+ |
menu = gtk_menu_new(); |
188 |
+ |
|
189 |
+ |
while (options->label_id) { |
190 |
+ |
add_menu_item(menu, options->label_id, options->func); |
191 |
+ |
options++; |
192 |
+ |
} |
193 |
+ |
gtk_menu_set_active(GTK_MENU(menu), active); |
194 |
+ |
|
195 |
+ |
gtk_option_menu_set_menu(GTK_OPTION_MENU(opt), menu); |
196 |
+ |
gtk_table_attach(GTK_TABLE(table), opt, 1, 2, row, row + 1, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4); |
197 |
+ |
return menu; |
198 |
+ |
} |
199 |
+ |
|
200 |
+ |
static GtkWidget *table_make_combobox(GtkWidget *table, int row, int label_id, const char *default_value, GList *glist) |
201 |
+ |
{ |
202 |
+ |
GtkWidget *label, *combo; |
203 |
+ |
char str[32]; |
204 |
+ |
|
205 |
+ |
label = gtk_label_new(GetString(label_id)); |
206 |
+ |
gtk_widget_show(label); |
207 |
+ |
gtk_table_attach(GTK_TABLE(table), label, 0, 1, row, row + 1, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4); |
208 |
+ |
|
209 |
+ |
combo = gtk_combo_new(); |
210 |
+ |
gtk_widget_show(combo); |
211 |
+ |
gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist); |
212 |
+ |
|
213 |
+ |
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), default_value); |
214 |
+ |
gtk_table_attach(GTK_TABLE(table), combo, 1, 2, row, row + 1, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4); |
215 |
+ |
|
216 |
+ |
return combo; |
217 |
+ |
} |
218 |
+ |
|
219 |
+ |
static GtkWidget *table_make_combobox(GtkWidget *table, int row, int label_id, const char *default_value, const combo_desc *options) |
220 |
+ |
{ |
221 |
+ |
GList *glist = NULL; |
222 |
+ |
while (options->label_id) { |
223 |
+ |
glist = g_list_append(glist, (void *)GetString(options->label_id)); |
224 |
+ |
options++; |
225 |
+ |
} |
226 |
+ |
|
227 |
+ |
return table_make_combobox(table, row, label_id, default_value, glist); |
228 |
+ |
} |
229 |
+ |
|
230 |
+ |
static GtkWidget *table_make_file_entry(GtkWidget *table, int row, int label_id, const char *prefs_item, bool only_dirs = false) |
231 |
+ |
{ |
232 |
+ |
GtkWidget *box, *label, *entry, *button; |
233 |
+ |
|
234 |
+ |
label = gtk_label_new(GetString(label_id)); |
235 |
+ |
gtk_widget_show(label); |
236 |
+ |
gtk_table_attach(GTK_TABLE(table), label, 0, 1, row, row + 1, (GtkAttachOptions)0, (GtkAttachOptions)0, 4, 4); |
237 |
+ |
|
238 |
+ |
const char *str = PrefsFindString(prefs_item); |
239 |
+ |
if (str == NULL) |
240 |
+ |
str = ""; |
241 |
+ |
|
242 |
+ |
box = gtk_hbox_new(FALSE, 4); |
243 |
+ |
gtk_widget_show(box); |
244 |
+ |
gtk_table_attach(GTK_TABLE(table), box, 1, 2, row, row + 1, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 4, 4); |
245 |
+ |
|
246 |
+ |
entry = gtk_entry_new(); |
247 |
+ |
gtk_entry_set_text(GTK_ENTRY(entry), str); |
248 |
+ |
gtk_widget_show(entry); |
249 |
+ |
gtk_box_pack_start(GTK_BOX(box), entry, TRUE, TRUE, 0); |
250 |
+ |
|
251 |
+ |
button = make_browse_button(entry); |
252 |
+ |
gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0); |
253 |
+ |
g_object_set_data(G_OBJECT(entry), "chooser_button", button); |
254 |
+ |
return entry; |
255 |
+ |
} |
256 |
+ |
|
257 |
|
static GtkWidget *make_option_menu(GtkWidget *top, int label_id, const opt_desc *options, int active) |
258 |
|
{ |
259 |
|
GtkWidget *box, *label, *opt, *menu; |
428 |
|
dialog = gnome_about_new( |
429 |
|
"Basilisk II", |
430 |
|
version, |
431 |
< |
"Copyright (C) 1997-2004 Christian Bauer", |
431 |
> |
"Copyright (C) 1997-2005 Christian Bauer", |
432 |
|
authors, |
433 |
|
"Basilisk II comes with ABSOLUTELY NO WARRANTY." |
434 |
|
"This is free software, and you are welcome to redistribute it" |
444 |
|
char str[512]; |
445 |
|
sprintf(str, |
446 |
|
"Basilisk II\nVersion %d.%d\n\n" |
447 |
< |
"Copyright (C) 1997-2004 Christian Bauer et al.\n" |
447 |
> |
"Copyright (C) 1997-2005 Christian Bauer et al.\n" |
448 |
|
"E-mail: Christian.Bauer@uni-mainz.de\n" |
449 |
|
"http://www.uni-mainz.de/~bauec002/B2Main.html\n\n" |
450 |
|
"Basilisk II comes with ABSOLUTELY NO\n" |
485 |
|
// Menu item descriptions |
486 |
|
static GtkItemFactoryEntry menu_items[] = { |
487 |
|
{(gchar *)GetString(STR_PREFS_MENU_FILE_GTK), NULL, NULL, 0, "<Branch>"}, |
488 |
< |
{(gchar *)GetString(STR_PREFS_ITEM_START_GTK), NULL, GTK_SIGNAL_FUNC(cb_start), 0, NULL}, |
488 |
> |
{(gchar *)GetString(STR_PREFS_ITEM_START_GTK), "<control>S", GTK_SIGNAL_FUNC(cb_start), 0, NULL}, |
489 |
|
{(gchar *)GetString(STR_PREFS_ITEM_ZAP_PRAM_GTK), NULL, GTK_SIGNAL_FUNC(mn_zap_pram), 0, NULL}, |
490 |
|
{(gchar *)GetString(STR_PREFS_ITEM_SEPL_GTK), NULL, NULL, 0, "<Separator>"}, |
491 |
|
{(gchar *)GetString(STR_PREFS_ITEM_QUIT_GTK), "<control>Q", GTK_SIGNAL_FUNC(cb_quit), 0, NULL}, |
519 |
|
gtk_box_pack_start(GTK_BOX(box), menu_bar, FALSE, TRUE, 0); |
520 |
|
|
521 |
|
GtkWidget *notebook = gtk_notebook_new(); |
400 |
– |
gtk_widget_show(notebook); |
522 |
|
gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_TOP); |
523 |
|
gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), FALSE); |
524 |
|
gtk_box_pack_start(GTK_BOX(box), notebook, TRUE, TRUE, 0); |
525 |
+ |
gtk_widget_realize(notebook); |
526 |
|
|
527 |
|
create_volumes_pane(notebook); |
528 |
|
create_scsi_pane(notebook); |
531 |
|
create_serial_pane(notebook); |
532 |
|
create_memory_pane(notebook); |
533 |
|
create_jit_pane(notebook); |
534 |
+ |
gtk_widget_show(notebook); |
535 |
|
|
536 |
|
static const opt_desc buttons[] = { |
537 |
|
{STR_START_BUTTON, GTK_SIGNAL_FUNC(cb_start)}, |
560 |
|
selected_volume = row; |
561 |
|
} |
562 |
|
|
440 |
– |
struct file_req_assoc { |
441 |
– |
file_req_assoc(GtkWidget *r, GtkWidget *e) : req(r), entry(e) {} |
442 |
– |
GtkWidget *req; |
443 |
– |
GtkWidget *entry; |
444 |
– |
}; |
445 |
– |
|
563 |
|
// Volume selected for addition |
564 |
|
static void add_volume_ok(GtkWidget *button, file_req_assoc *assoc) |
565 |
|
{ |
712 |
|
static GtkWidget *w_jit_lazy_flush; |
713 |
|
static GtkWidget *w_jit_follow_const_jumps; |
714 |
|
|
715 |
+ |
// Are we running a JIT capable CPU? |
716 |
+ |
static bool is_jit_capable(void) |
717 |
+ |
{ |
718 |
+ |
#if USE_JIT && (defined __i386__ || defined __x86_64__) |
719 |
+ |
return true; |
720 |
+ |
#elif defined __APPLE__ && defined __MACH__ |
721 |
+ |
// XXX run-time detect so that we can use a PPC GUI prefs editor |
722 |
+ |
static char cpu[10]; |
723 |
+ |
if (cpu[0] == 0) { |
724 |
+ |
FILE *fp = popen("uname -p", "r"); |
725 |
+ |
if (fp == NULL) |
726 |
+ |
return false; |
727 |
+ |
fgets(cpu, sizeof(cpu) - 1, fp); |
728 |
+ |
fclose(fp); |
729 |
+ |
} |
730 |
+ |
if (cpu[0] == 'i' && cpu[2] == '8' && cpu[3] == '6') // XXX assuming i?86 |
731 |
+ |
return true; |
732 |
+ |
#endif |
733 |
+ |
return false; |
734 |
+ |
} |
735 |
+ |
|
736 |
|
// Set sensitivity of widgets |
737 |
|
static void set_jit_sensitive(void) |
738 |
|
{ |
771 |
|
// Read settings from widgets and set preferences |
772 |
|
static void read_jit_settings(void) |
773 |
|
{ |
774 |
< |
#if USE_JIT |
637 |
< |
bool jit_enabled = PrefsFindBool("jit"); |
774 |
> |
bool jit_enabled = is_jit_capable() && PrefsFindBool("jit"); |
775 |
|
if (jit_enabled) { |
776 |
|
const char *str = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(w_jit_cache_size)->entry)); |
777 |
|
PrefsReplaceInt32("jitcachesize", atoi(str)); |
778 |
|
} |
642 |
– |
#endif |
779 |
|
} |
780 |
|
|
781 |
|
// Create "JIT Compiler" pane |
782 |
|
static void create_jit_pane(GtkWidget *top) |
783 |
|
{ |
784 |
< |
#if USE_JIT |
784 |
> |
if (!is_jit_capable()) |
785 |
> |
return; |
786 |
> |
|
787 |
|
GtkWidget *box, *table, *label, *menu; |
788 |
|
char str[32]; |
789 |
|
|
809 |
|
w_jit_follow_const_jumps = make_checkbox(box, STR_JIT_FOLLOW_CONST_JUMPS, "jitinline", GTK_SIGNAL_FUNC(tb_jit_follow_const_jumps)); |
810 |
|
|
811 |
|
set_jit_sensitive(); |
674 |
– |
#endif |
812 |
|
} |
813 |
|
|
814 |
|
/* |
1131 |
|
// Set sensitivity of widgets |
1132 |
|
static void set_input_sensitive(void) |
1133 |
|
{ |
1134 |
< |
gtk_widget_set_sensitive(w_keycode_file, PrefsFindBool("keycodes")); |
1134 |
> |
const bool use_keycodes = PrefsFindBool("keycodes"); |
1135 |
> |
gtk_widget_set_sensitive(w_keycode_file, use_keycodes); |
1136 |
> |
gtk_widget_set_sensitive(GTK_WIDGET(g_object_get_data(G_OBJECT(w_keycode_file), "chooser_button")), use_keycodes); |
1137 |
|
gtk_widget_set_sensitive(w_mouse_wheel_lines, PrefsFindInt32("mousewheelmode") == 1); |
1138 |
|
} |
1139 |
|
|
1163 |
|
// Create "Input" pane |
1164 |
|
static void create_input_pane(GtkWidget *top) |
1165 |
|
{ |
1166 |
< |
GtkWidget *box, *hbox, *menu, *label; |
1166 |
> |
GtkWidget *box, *hbox, *menu, *label, *button; |
1167 |
|
GtkObject *adj; |
1168 |
|
|
1169 |
|
box = make_pane(top, STR_INPUT_PANE_TITLE); |
1170 |
|
|
1171 |
|
make_checkbox(box, STR_KEYCODES_CTRL, "keycodes", GTK_SIGNAL_FUNC(tb_keycodes)); |
1172 |
< |
w_keycode_file = make_file_entry(box, STR_KEYCODE_FILE_CTRL, "keycodefile"); |
1172 |
> |
|
1173 |
> |
hbox = gtk_hbox_new(FALSE, 4); |
1174 |
> |
gtk_widget_show(hbox); |
1175 |
> |
gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0); |
1176 |
> |
|
1177 |
> |
label = gtk_label_new(GetString(STR_KEYCODES_CTRL)); |
1178 |
> |
gtk_widget_show(label); |
1179 |
> |
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); |
1180 |
> |
|
1181 |
> |
const char *str = PrefsFindString("keycodefile"); |
1182 |
> |
if (str == NULL) |
1183 |
> |
str = ""; |
1184 |
> |
|
1185 |
> |
w_keycode_file = gtk_entry_new(); |
1186 |
> |
gtk_entry_set_text(GTK_ENTRY(w_keycode_file), str); |
1187 |
> |
gtk_widget_show(w_keycode_file); |
1188 |
> |
gtk_box_pack_start(GTK_BOX(hbox), w_keycode_file, TRUE, TRUE, 0); |
1189 |
> |
|
1190 |
> |
button = make_browse_button(w_keycode_file); |
1191 |
> |
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); |
1192 |
> |
g_object_set_data(G_OBJECT(w_keycode_file), "chooser_button", button); |
1193 |
|
|
1194 |
|
make_separator(box); |
1195 |
|
|
1430 |
|
* "Memory/Misc" pane |
1431 |
|
*/ |
1432 |
|
|
1433 |
< |
static GtkObject *w_ramsize_adj; |
1433 |
> |
static GtkWidget *w_ramsize; |
1434 |
|
static GtkWidget *w_rom_file; |
1435 |
|
|
1436 |
|
// "Ignore SEGV" button toggled |
1455 |
|
// Read settings from widgets and set preferences |
1456 |
|
static void read_memory_settings(void) |
1457 |
|
{ |
1458 |
< |
PrefsReplaceInt32("ramsize", int(GTK_ADJUSTMENT(w_ramsize_adj)->value) << 20); |
1458 |
> |
const char *str = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(w_ramsize)->entry)); |
1459 |
> |
PrefsReplaceInt32("ramsize", atoi(str) << 20); |
1460 |
|
|
1461 |
< |
const char *str = get_file_entry_path(w_rom_file); |
1461 |
> |
str = get_file_entry_path(w_rom_file); |
1462 |
|
if (str && strlen(str)) |
1463 |
|
PrefsReplaceString("rom", str); |
1464 |
|
else |
1469 |
|
// Create "Memory/Misc" pane |
1470 |
|
static void create_memory_pane(GtkWidget *top) |
1471 |
|
{ |
1472 |
< |
GtkWidget *box, *hbox, *vbox, *hbox2, *label, *scale; |
1472 |
> |
GtkWidget *box, *hbox, *table, *label, *menu; |
1473 |
|
|
1474 |
|
box = make_pane(top, STR_MEMORY_MISC_PANE_TITLE); |
1475 |
+ |
table = make_table(box, 2, 5); |
1476 |
|
|
1477 |
< |
hbox = gtk_hbox_new(FALSE, 4); |
1478 |
< |
gtk_widget_show(hbox); |
1479 |
< |
|
1480 |
< |
label = gtk_label_new(GetString(STR_RAMSIZE_SLIDER)); |
1481 |
< |
gtk_widget_show(label); |
1482 |
< |
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); |
1483 |
< |
|
1484 |
< |
vbox = gtk_vbox_new(FALSE, 4); |
1485 |
< |
gtk_widget_show(vbox); |
1486 |
< |
|
1487 |
< |
gfloat min, max; |
1488 |
< |
min = 1; |
1489 |
< |
max = 1024; |
1490 |
< |
w_ramsize_adj = gtk_adjustment_new(min, min, max, 1, 16, 0); |
1491 |
< |
gtk_adjustment_set_value(GTK_ADJUSTMENT(w_ramsize_adj), PrefsFindInt32("ramsize") >> 20); |
1492 |
< |
|
1332 |
< |
scale = gtk_hscale_new(GTK_ADJUSTMENT(w_ramsize_adj)); |
1333 |
< |
gtk_widget_show(scale); |
1334 |
< |
gtk_scale_set_digits(GTK_SCALE(scale), 0); |
1335 |
< |
gtk_box_pack_start(GTK_BOX(vbox), scale, TRUE, TRUE, 0); |
1336 |
< |
|
1337 |
< |
hbox2 = gtk_hbox_new(FALSE, 4); |
1338 |
< |
gtk_widget_show(hbox2); |
1339 |
< |
|
1340 |
< |
char val[32]; |
1341 |
< |
sprintf(val, GetString(STR_RAMSIZE_FMT), int(min)); |
1342 |
< |
label = gtk_label_new(val); |
1343 |
< |
gtk_widget_show(label); |
1344 |
< |
gtk_box_pack_start(GTK_BOX(hbox2), label, FALSE, FALSE, 0); |
1345 |
< |
|
1346 |
< |
sprintf(val, GetString(STR_RAMSIZE_FMT), int(max)); |
1347 |
< |
label = gtk_label_new(val); |
1348 |
< |
gtk_widget_show(label); |
1349 |
< |
gtk_box_pack_end(GTK_BOX(hbox2), label, FALSE, FALSE, 0); |
1350 |
< |
gtk_box_pack_start(GTK_BOX(vbox), hbox2, TRUE, TRUE, 0); |
1351 |
< |
gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0); |
1352 |
< |
gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0); |
1477 |
> |
static const combo_desc options[] = { |
1478 |
> |
STR_RAMSIZE_2MB_LAB, |
1479 |
> |
STR_RAMSIZE_4MB_LAB, |
1480 |
> |
STR_RAMSIZE_8MB_LAB, |
1481 |
> |
STR_RAMSIZE_16MB_LAB, |
1482 |
> |
STR_RAMSIZE_32MB_LAB, |
1483 |
> |
STR_RAMSIZE_64MB_LAB, |
1484 |
> |
STR_RAMSIZE_128MB_LAB, |
1485 |
> |
STR_RAMSIZE_256MB_LAB, |
1486 |
> |
STR_RAMSIZE_512MB_LAB, |
1487 |
> |
STR_RAMSIZE_1024MB_LAB, |
1488 |
> |
0 |
1489 |
> |
}; |
1490 |
> |
char default_ramsize[10]; |
1491 |
> |
sprintf(default_ramsize, "%d", PrefsFindInt32("ramsize") >> 20); |
1492 |
> |
w_ramsize = table_make_combobox(table, 0, STR_RAMSIZE_CTRL, default_ramsize, options); |
1493 |
|
|
1494 |
|
static const opt_desc model_options[] = { |
1495 |
|
{STR_MODELID_5_LAB, GTK_SIGNAL_FUNC(mn_modelid_5)}, |
1501 |
|
case 5: active = 0; break; |
1502 |
|
case 14: active = 1; break; |
1503 |
|
} |
1504 |
< |
make_option_menu(box, STR_MODELID_CTRL, model_options, active); |
1504 |
> |
table_make_option_menu(table, 2, STR_MODELID_CTRL, model_options, active); |
1505 |
|
|
1506 |
|
#if EMULATED_68K |
1507 |
|
static const opt_desc cpu_options[] = { |
1520 |
|
case 3: active = fpu ? 3 : 2; break; |
1521 |
|
case 4: active = 4; |
1522 |
|
} |
1523 |
< |
make_option_menu(box, STR_CPU_CTRL, cpu_options, active); |
1523 |
> |
table_make_option_menu(table, 3, STR_CPU_CTRL, cpu_options, active); |
1524 |
|
#endif |
1525 |
|
|
1526 |
< |
w_rom_file = make_file_entry(box, STR_ROM_FILE_CTRL, "rom"); |
1526 |
> |
w_rom_file = table_make_file_entry(table, 4, STR_ROM_FILE_CTRL, "rom"); |
1527 |
|
|
1528 |
|
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION |
1529 |
|
make_checkbox(box, STR_IGNORESEGV_CTRL, "ignoresegv", GTK_SIGNAL_FUNC(tb_ignoresegv)); |
1545 |
|
read_memory_settings(); |
1546 |
|
read_jit_settings(); |
1547 |
|
} |
1548 |
+ |
|
1549 |
+ |
|
1550 |
+ |
#ifdef STANDALONE_GUI |
1551 |
+ |
#include <errno.h> |
1552 |
+ |
#include <sys/wait.h> |
1553 |
+ |
#include "rpc.h" |
1554 |
+ |
|
1555 |
+ |
/* |
1556 |
+ |
* Fake unused data and functions |
1557 |
+ |
*/ |
1558 |
+ |
|
1559 |
+ |
uint8 XPRAM[XPRAM_SIZE]; |
1560 |
+ |
void MountVolume(void *fh) { } |
1561 |
+ |
void FileDiskLayout(loff_t size, uint8 *data, loff_t &start_byte, loff_t &real_size) { } |
1562 |
+ |
|
1563 |
+ |
#if defined __APPLE__ && defined __MACH__ |
1564 |
+ |
void DarwinAddCDROMPrefs(void) { } |
1565 |
+ |
void DarwinAddFloppyPrefs(void) { } |
1566 |
+ |
void DarwinAddSerialPrefs(void) { } |
1567 |
+ |
bool DarwinCDReadTOC(char *, uint8 *) { } |
1568 |
+ |
#endif |
1569 |
+ |
|
1570 |
+ |
|
1571 |
+ |
/* |
1572 |
+ |
* Display alert |
1573 |
+ |
*/ |
1574 |
+ |
|
1575 |
+ |
static void dl_destroyed(void) |
1576 |
+ |
{ |
1577 |
+ |
gtk_main_quit(); |
1578 |
+ |
} |
1579 |
+ |
|
1580 |
+ |
static void display_alert(int title_id, int prefix_id, int button_id, const char *text) |
1581 |
+ |
{ |
1582 |
+ |
char str[256]; |
1583 |
+ |
sprintf(str, GetString(prefix_id), text); |
1584 |
+ |
|
1585 |
+ |
GtkWidget *dialog = gtk_dialog_new(); |
1586 |
+ |
gtk_window_set_title(GTK_WINDOW(dialog), GetString(title_id)); |
1587 |
+ |
gtk_container_border_width(GTK_CONTAINER(dialog), 5); |
1588 |
+ |
gtk_widget_set_uposition(GTK_WIDGET(dialog), 100, 150); |
1589 |
+ |
gtk_signal_connect(GTK_OBJECT(dialog), "destroy", GTK_SIGNAL_FUNC(dl_destroyed), NULL); |
1590 |
+ |
|
1591 |
+ |
GtkWidget *label = gtk_label_new(str); |
1592 |
+ |
gtk_widget_show(label); |
1593 |
+ |
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), label, TRUE, TRUE, 0); |
1594 |
+ |
|
1595 |
+ |
GtkWidget *button = gtk_button_new_with_label(GetString(button_id)); |
1596 |
+ |
gtk_widget_show(button); |
1597 |
+ |
gtk_signal_connect_object(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(dl_quit), GTK_OBJECT(dialog)); |
1598 |
+ |
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), button, FALSE, FALSE, 0); |
1599 |
+ |
GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); |
1600 |
+ |
gtk_widget_grab_default(button); |
1601 |
+ |
gtk_widget_show(dialog); |
1602 |
+ |
|
1603 |
+ |
gtk_main(); |
1604 |
+ |
} |
1605 |
+ |
|
1606 |
+ |
|
1607 |
+ |
/* |
1608 |
+ |
* Display error alert |
1609 |
+ |
*/ |
1610 |
+ |
|
1611 |
+ |
void ErrorAlert(const char *text) |
1612 |
+ |
{ |
1613 |
+ |
display_alert(STR_ERROR_ALERT_TITLE, STR_GUI_ERROR_PREFIX, STR_QUIT_BUTTON, text); |
1614 |
+ |
} |
1615 |
+ |
|
1616 |
+ |
|
1617 |
+ |
/* |
1618 |
+ |
* Display warning alert |
1619 |
+ |
*/ |
1620 |
+ |
|
1621 |
+ |
void WarningAlert(const char *text) |
1622 |
+ |
{ |
1623 |
+ |
display_alert(STR_WARNING_ALERT_TITLE, STR_GUI_WARNING_PREFIX, STR_OK_BUTTON, text); |
1624 |
+ |
} |
1625 |
+ |
|
1626 |
+ |
|
1627 |
+ |
/* |
1628 |
+ |
* RPC handlers |
1629 |
+ |
*/ |
1630 |
+ |
|
1631 |
+ |
static int handle_ErrorAlert(rpc_connection_t *connection) |
1632 |
+ |
{ |
1633 |
+ |
D(bug("handle_ErrorAlert\n")); |
1634 |
+ |
|
1635 |
+ |
int error; |
1636 |
+ |
char *str; |
1637 |
+ |
if ((error = rpc_method_get_args(connection, RPC_TYPE_STRING, &str, RPC_TYPE_INVALID)) < 0) |
1638 |
+ |
return error; |
1639 |
+ |
|
1640 |
+ |
ErrorAlert(str); |
1641 |
+ |
free(str); |
1642 |
+ |
return RPC_ERROR_NO_ERROR; |
1643 |
+ |
} |
1644 |
+ |
|
1645 |
+ |
static int handle_WarningAlert(rpc_connection_t *connection) |
1646 |
+ |
{ |
1647 |
+ |
D(bug("handle_WarningAlert\n")); |
1648 |
+ |
|
1649 |
+ |
int error; |
1650 |
+ |
char *str; |
1651 |
+ |
if ((error = rpc_method_get_args(connection, RPC_TYPE_STRING, &str, RPC_TYPE_INVALID)) < 0) |
1652 |
+ |
return error; |
1653 |
+ |
|
1654 |
+ |
WarningAlert(str); |
1655 |
+ |
free(str); |
1656 |
+ |
return RPC_ERROR_NO_ERROR; |
1657 |
+ |
} |
1658 |
+ |
|
1659 |
+ |
static int handle_Exit(rpc_connection_t *connection) |
1660 |
+ |
{ |
1661 |
+ |
D(bug("handle_Exit\n")); |
1662 |
+ |
|
1663 |
+ |
return RPC_ERROR_NO_ERROR; |
1664 |
+ |
} |
1665 |
+ |
|
1666 |
+ |
|
1667 |
+ |
/* |
1668 |
+ |
* Start standalone GUI |
1669 |
+ |
*/ |
1670 |
+ |
|
1671 |
+ |
int main(int argc, char *argv[]) |
1672 |
+ |
{ |
1673 |
+ |
#ifdef HAVE_GNOMEUI |
1674 |
+ |
// Init GNOME/GTK |
1675 |
+ |
char version[16]; |
1676 |
+ |
sprintf(version, "%d.%d", VERSION_MAJOR, VERSION_MINOR); |
1677 |
+ |
gnome_init("Basilisk II", version, argc, argv); |
1678 |
+ |
#else |
1679 |
+ |
// Init GTK |
1680 |
+ |
gtk_set_locale(); |
1681 |
+ |
gtk_init(&argc, &argv); |
1682 |
+ |
#endif |
1683 |
+ |
|
1684 |
+ |
// Read preferences |
1685 |
+ |
PrefsInit(argc, argv); |
1686 |
+ |
|
1687 |
+ |
// Show preferences editor |
1688 |
+ |
bool start = PrefsEditor(); |
1689 |
+ |
|
1690 |
+ |
// Exit preferences |
1691 |
+ |
PrefsExit(); |
1692 |
+ |
|
1693 |
+ |
// Transfer control to the executable |
1694 |
+ |
if (start) { |
1695 |
+ |
char gui_connection_path[64]; |
1696 |
+ |
sprintf(gui_connection_path, "/org/BasiliskII/GUI/%d", getpid()); |
1697 |
+ |
|
1698 |
+ |
// Search and run the BasiliskII executable |
1699 |
+ |
// XXX it can be in a bundle on MacOS X |
1700 |
+ |
char b2_path[PATH_MAX]; |
1701 |
+ |
strcpy(b2_path, argv[0]); |
1702 |
+ |
char *p = strrchr(b2_path, '/'); |
1703 |
+ |
p = p ? p + 1 : b2_path; |
1704 |
+ |
*p = '\0'; |
1705 |
+ |
strcat(b2_path, "BasiliskII"); |
1706 |
+ |
|
1707 |
+ |
int pid = fork(); |
1708 |
+ |
if (pid == 0) { |
1709 |
+ |
execl(b2_path, b2_path, "--gui-connection", gui_connection_path, (char *)NULL); |
1710 |
+ |
return -errno; |
1711 |
+ |
} |
1712 |
+ |
|
1713 |
+ |
// Establish a connection to Basilisk II |
1714 |
+ |
rpc_connection_t *connection; |
1715 |
+ |
if ((connection = rpc_init_server(gui_connection_path)) == NULL) { |
1716 |
+ |
printf("ERROR: failed to initialize GUI-side RPC server connection\n"); |
1717 |
+ |
return 1; |
1718 |
+ |
} |
1719 |
+ |
static const rpc_method_descriptor_t vtable[] = { |
1720 |
+ |
{ RPC_METHOD_ERROR_ALERT, handle_ErrorAlert }, |
1721 |
+ |
{ RPC_METHOD_WARNING_ALERT, handle_WarningAlert }, |
1722 |
+ |
{ RPC_METHOD_EXIT, handle_Exit } |
1723 |
+ |
}; |
1724 |
+ |
if (rpc_method_add_callbacks(connection, vtable, sizeof(vtable) / sizeof(vtable[0])) < 0) { |
1725 |
+ |
printf("ERROR: failed to setup GUI method callbacks\n"); |
1726 |
+ |
return 1; |
1727 |
+ |
} |
1728 |
+ |
int socket; |
1729 |
+ |
if ((socket = rpc_listen_socket(connection)) < 0) { |
1730 |
+ |
printf("ERROR: failed to initialize RPC server thread\n"); |
1731 |
+ |
return 1; |
1732 |
+ |
} |
1733 |
+ |
|
1734 |
+ |
int child_status = 1; |
1735 |
+ |
GMainLoop *loop = g_main_new(TRUE); |
1736 |
+ |
while (g_main_is_running(loop)) { |
1737 |
+ |
|
1738 |
+ |
// Process a few events pending |
1739 |
+ |
const int N_EVENTS_DISPATCH = 10; |
1740 |
+ |
for (int i = 0; i < N_EVENTS_DISPATCH; i++) { |
1741 |
+ |
if (!g_main_iteration(FALSE)) |
1742 |
+ |
break; |
1743 |
+ |
} |
1744 |
+ |
|
1745 |
+ |
// Check if the child has terminated |
1746 |
+ |
int status = 1; |
1747 |
+ |
int ret = waitpid(pid, &status, WNOHANG); |
1748 |
+ |
if (ret == pid || (ret < 0 && errno == ECHILD)) { |
1749 |
+ |
if (WIFEXITED(status)) { |
1750 |
+ |
child_status = WEXITSTATUS(status); |
1751 |
+ |
if (child_status & 0x80) |
1752 |
+ |
child_status |= -1 ^0xff; |
1753 |
+ |
} |
1754 |
+ |
break; |
1755 |
+ |
} |
1756 |
+ |
|
1757 |
+ |
// Check for RPC events |
1758 |
+ |
// XXX implement an rpc_try_dispatch(connection, timeout) |
1759 |
+ |
fd_set rfds; |
1760 |
+ |
FD_ZERO(&rfds); |
1761 |
+ |
FD_SET(socket, &rfds); |
1762 |
+ |
struct timeval tv; |
1763 |
+ |
tv.tv_sec = 1; |
1764 |
+ |
tv.tv_usec = 0; |
1765 |
+ |
ret = select(socket + 1, &rfds, NULL, NULL, &tv); |
1766 |
+ |
if (ret < 0) |
1767 |
+ |
break; |
1768 |
+ |
if (ret == 0) |
1769 |
+ |
continue; |
1770 |
+ |
rpc_dispatch(connection); |
1771 |
+ |
} |
1772 |
+ |
|
1773 |
+ |
rpc_exit(connection); |
1774 |
+ |
|
1775 |
+ |
// Report failure to execute the BasiliskII binary |
1776 |
+ |
if (child_status < 0) { |
1777 |
+ |
char str[256]; |
1778 |
+ |
sprintf(str, GetString(STR_NO_B2_EXE_FOUND), b2_path, strerror(-child_status)); |
1779 |
+ |
ErrorAlert(str); |
1780 |
+ |
return 1; |
1781 |
+ |
} |
1782 |
+ |
|
1783 |
+ |
return child_status; |
1784 |
+ |
} |
1785 |
+ |
|
1786 |
+ |
return 0; |
1787 |
+ |
} |
1788 |
+ |
#endif |