1 /* Hey EMACS -*- linux-c -*- */
2 /* $Id: device.c 1364 2005-07-13 12:08:10Z roms $ */
3
4 /* TiEmu - Tiemu Is an EMUlator
5 * Copyright (C) 1999-2005 Romain Lievin
6 * Copyright (C) 2007 Kevin Kofler
7 *
8 * This program is free software you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
26
27 #include <gtk/gtk.h>
28 #include <glade/glade.h>
29 #include <string.h>
30
31 #include "intl.h"
32 #include "support.h"
33 #include "paths.h"
34 #include "device.h"
35 #include "refresh.h"
36 #include "tilibs.h"
37 #include "dboxes.h"
38 #include "tie_error.h"
39 #include "ti68k_int.h"
40
41 extern DeviceOptions linkp;
42 static DeviceOptions tmp;
43 static DeviceOptions old;
44
45 static GtkWidget* lbl;
46 static GtkWidget* comm_cable;
47 static GtkWidget* comm_port;
48
display_device_dbox()49 gint display_device_dbox()
50 {
51 GladeXML *xml;
52 GtkWidget *dbox;
53 GtkWidget *data;
54 gint result;
55 int err;
56
57 xml = glade_xml_new(tilp_paths_build_glade("device-2.glade"), "device_dbox", PACKAGE);
58 if (!xml)
59 g_error(_("comm.c: GUI loading failed !\n"));
60 glade_xml_signal_autoconnect(xml);
61
62 dbox = glade_xml_get_widget(xml, "device_dbox");
63 gtk_dialog_set_alternative_button_order(GTK_DIALOG(dbox), GTK_RESPONSE_OK,
64 GTK_RESPONSE_CANCEL,-1);
65
66 lbl = glade_xml_get_widget(xml, "label7");
67
68 // Cable
69 data = comm_cable = glade_xml_get_widget(xml, "combobox1");
70 switch (linkp.cable_model)
71 {
72 case CABLE_NUL:
73 gtk_combo_box_set_active(GTK_COMBO_BOX(data), 0);
74 break;
75
76 case CABLE_GRY:
77 gtk_combo_box_set_active(GTK_COMBO_BOX(data), 1);
78 break;
79
80 case CABLE_BLK:
81 gtk_combo_box_set_active(GTK_COMBO_BOX(data), 2);
82 break;
83
84 case CABLE_PAR:
85 gtk_combo_box_set_active(GTK_COMBO_BOX(data), 3);
86 break;
87
88 case CABLE_SLV:
89 gtk_combo_box_set_active(GTK_COMBO_BOX(data), 4);
90 break;
91
92 case CABLE_USB:
93 gtk_combo_box_set_active(GTK_COMBO_BOX(data), 5);
94 break;
95
96 case CABLE_VTI:
97 gtk_combo_box_set_active(GTK_COMBO_BOX(data), 6);
98 break;
99
100 case CABLE_TIE:
101 gtk_combo_box_set_active(GTK_COMBO_BOX(data), 7);
102 break;
103
104 case CABLE_ILP:
105 gtk_combo_box_set_active(GTK_COMBO_BOX(data), 8);
106 break;
107
108 default:
109 gtk_combo_box_set_active(GTK_COMBO_BOX(data), 0);
110 break;
111 }
112
113 // Port
114 data = comm_port = glade_xml_get_widget(xml, "combobox2");
115 switch (linkp.cable_port)
116 {
117 case PORT_0:
118 gtk_combo_box_set_active(GTK_COMBO_BOX(data), 0);
119 break;
120 case PORT_1:
121 gtk_combo_box_set_active(GTK_COMBO_BOX(data), 1);
122 break;
123 case PORT_2:
124 gtk_combo_box_set_active(GTK_COMBO_BOX(data), 2);
125 break;
126 case PORT_3:
127 gtk_combo_box_set_active(GTK_COMBO_BOX(data), 3);
128 break;
129 case PORT_4:
130 gtk_combo_box_set_active(GTK_COMBO_BOX(data), 4);
131 break;
132 }
133
134 // Timeout
135 data = glade_xml_get_widget(xml, "spinbutton_comm_timeout");
136 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data), linkp.cable_timeout);
137
138 // Delay
139 data = glade_xml_get_widget(xml, "spinbutton_comm_delay");
140 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data), linkp.cable_delay);
141
142 // Data exchange
143 memcpy(&tmp, &linkp, sizeof(DeviceOptions));
144 memcpy(&old, &linkp, sizeof(DeviceOptions));
145
146 // Loop
147 result = gtk_dialog_run(GTK_DIALOG(dbox));
148 switch (result)
149 {
150 case GTK_RESPONSE_CANCEL:
151 break;
152 case GTK_RESPONSE_OK:
153 ti68k_linkport_unconfigure();
154
155 data = glade_xml_get_widget(xml, "spinbutton_comm_delay");
156 tmp.cable_delay = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(data));
157
158 data = glade_xml_get_widget(xml, "spinbutton_comm_timeout");
159 tmp.cable_timeout = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(data));
160
161 memcpy(&linkp, &tmp, sizeof(DeviceOptions));
162 tmp.calc_model = ti68k_calc_to_libti_calc();
163
164 err = ti68k_linkport_reconfigure();
165 if(err)
166 {
167 // if reconfiguring fails, fallback to null cable & port
168 ti68k_linkport_unconfigure();
169
170 memcpy(&linkp, &old, sizeof(DeviceOptions));
171 tmp.calc_model = ti68k_calc_to_libti_calc();
172
173 ti68k_linkport_reconfigure();
174 }
175 break;
176 case GTK_RESPONSE_HELP:
177 break;
178 default:
179 break;
180 }
181 gtk_widget_destroy(dbox);
182 return 0;
183 }
184
185
186 GLADE_CB void
on_device_combobox1_changed(GtkComboBox * combobox,gpointer user_data)187 on_device_combobox1_changed (GtkComboBox *combobox,
188 gpointer user_data)
189 {
190 gint nitem = gtk_combo_box_get_active(combobox);
191
192 switch(nitem)
193 {
194 case 0: tmp.cable_model = CABLE_NUL; break;
195 case 1: tmp.cable_model = CABLE_GRY; break;
196 case 2: tmp.cable_model = CABLE_BLK; break;
197 case 3: tmp.cable_model = CABLE_PAR; break;
198 case 4: tmp.cable_model = CABLE_SLV; break;
199 case 5: tmp.cable_model = CABLE_USB; break;
200 case 6: tmp.cable_model = CABLE_VTI; break;
201 case 7: tmp.cable_model = CABLE_TIE; break;
202 case 8: tmp.cable_model = CABLE_ILP; break;
203 }
204 }
205
206
207 GLADE_CB void
on_device_combobox2_changed(GtkComboBox * combobox,gpointer user_data)208 on_device_combobox2_changed (GtkComboBox *combobox,
209 gpointer user_data)
210 {
211 gint nitem = gtk_combo_box_get_active(combobox);
212
213 switch(nitem)
214 {
215 case 0: tmp.cable_port = PORT_0; break;
216 case 1: tmp.cable_port = PORT_1; break;
217 case 2: tmp.cable_port = PORT_2; break;
218 case 3: tmp.cable_port = PORT_3; break;
219 case 4: tmp.cable_port = PORT_4; break;
220 }
221 }
222
223
224 GLADE_CB void
comm_spinbutton_delay_changed(GtkEditable * editable,gpointer user_data)225 comm_spinbutton_delay_changed (GtkEditable *editable,
226 gpointer user_data)
227 {
228 tmp.cable_delay =
229 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(user_data));
230 }
231
232
233 GLADE_CB void
comm_spinbutton_timeout_changed(GtkEditable * editable,gpointer user_data)234 comm_spinbutton_timeout_changed (GtkEditable *editable,
235 gpointer user_data)
236 {
237 tmp.cable_timeout =
238 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(user_data));
239 }
240