forked from AppleWin/AppleWin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageConfigTfe.cpp
More file actions
297 lines (238 loc) · 7.72 KB
/
Copy pathPageConfigTfe.cpp
File metadata and controls
297 lines (238 loc) · 7.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/*
AppleWin : An Apple //e emulator for Windows
Copyright (C) 1994-1996, Michael O'Brien
Copyright (C) 1999-2001, Oliver Schmidt
Copyright (C) 2002-2005, Tom Charlesworth
Copyright (C) 2006-2014, Tom Charlesworth, Michael Pohoreski, Nick Westgate
AppleWin is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
AppleWin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with AppleWin; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "StdAfx.h"
#include "../Common.h"
#include "../Registry.h"
#include "../resource/resource.h"
#include "../Tfe/Tfe.h"
#include "../Tfe/Tfesupp.h"
#include "PageConfigTfe.h"
CPageConfigTfe* CPageConfigTfe::ms_this = 0; // reinit'd in ctor
uilib_localize_dialog_param CPageConfigTfe::ms_dialog[] =
{
{0, IDS_TFE_CAPTION, -1},
{IDC_TFE_SETTINGS_ENABLE_T, IDS_TFE_ETHERNET, 0},
{IDC_TFE_SETTINGS_INTERFACE_T, IDS_TFE_INTERFACE, 0},
{IDOK, IDS_OK, 0},
{IDCANCEL, IDS_CANCEL, 0},
{0, 0, 0}
};
uilib_dialog_group CPageConfigTfe::ms_leftgroup[] =
{
{IDC_TFE_SETTINGS_ENABLE_T, 0},
{IDC_TFE_SETTINGS_INTERFACE_T, 0},
{0, 0}
};
uilib_dialog_group CPageConfigTfe::ms_rightgroup[] =
{
{IDC_TFE_SETTINGS_ENABLE, 0},
{IDC_TFE_SETTINGS_INTERFACE, 0},
{0, 0}
};
BOOL CALLBACK CPageConfigTfe::DlgProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
// Switch from static func to our instance
return CPageConfigTfe::ms_this->DlgProcInternal(hwnd, msg, wparam, lparam);
}
BOOL CPageConfigTfe::DlgProcInternal(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch (msg)
{
case WM_COMMAND:
switch (LOWORD(wparam))
{
case IDOK:
DlgOK(hwnd);
/* FALL THROUGH */
case IDCANCEL:
DlgCANCEL(hwnd);
return TRUE;
case IDC_TFE_SETTINGS_INTERFACE:
/* FALL THROUGH */
case IDC_TFE_SETTINGS_ENABLE:
gray_ungray_items(hwnd);
break;
}
return FALSE;
case WM_CLOSE:
EndDialog(hwnd,0);
return TRUE;
case WM_INITDIALOG:
init_tfe_dialog(hwnd);
return TRUE;
}
return FALSE;
}
void CPageConfigTfe::DlgOK(HWND window)
{
save_tfe_dialog(window);
}
void CPageConfigTfe::DlgCANCEL(HWND window)
{
EndDialog(window, 0);
}
BOOL CPageConfigTfe::get_tfename(int number, char **ppname, char **ppdescription)
{
if (tfe_enumadapter_open())
{
char *pname = NULL;
char *pdescription = NULL;
while (number--)
{
if (!tfe_enumadapter(&pname, &pdescription))
break;
lib_free(pname);
lib_free(pdescription);
}
if (tfe_enumadapter(&pname, &pdescription))
{
*ppname = pname;
*ppdescription = pdescription;
tfe_enumadapter_close();
return TRUE;
}
tfe_enumadapter_close();
}
return FALSE;
}
int CPageConfigTfe::gray_ungray_items(HWND hwnd)
{
int enable;
int number;
int disabled = 0;
//resources_get_value("ETHERNET_DISABLED", (void *)&disabled);
REGLOAD(TEXT("Uthernet Disabled") ,(DWORD *)&disabled);
get_disabled_state(&disabled);
if (disabled)
{
EnableWindow(GetDlgItem(hwnd, IDC_TFE_SETTINGS_ENABLE_T), 0);
EnableWindow(GetDlgItem(hwnd, IDC_TFE_SETTINGS_ENABLE), 0);
EnableWindow(GetDlgItem(hwnd, IDOK), 0);
SetWindowText(GetDlgItem(hwnd,IDC_TFE_SETTINGS_INTERFACE_NAME), "");
SetWindowText(GetDlgItem(hwnd,IDC_TFE_SETTINGS_INTERFACE_DESC), "");
enable = 0;
}
else
{
enable = SendMessage(GetDlgItem(hwnd, IDC_TFE_SETTINGS_ENABLE), CB_GETCURSEL, 0, 0) ? 1 : 0;
}
EnableWindow(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_T), enable);
EnableWindow(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE), enable);
if (enable)
{
char *pname = NULL;
char *pdescription = NULL;
number = SendMessage(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE), CB_GETCURSEL, 0, 0);
if (get_tfename(number, &pname, &pdescription))
{
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_NAME), pname);
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_DESC), pdescription);
lib_free(pname);
lib_free(pdescription);
}
}
else
{
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_NAME), "");
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_DESC), "");
}
return disabled ? 1 : 0;
}
void CPageConfigTfe::init_tfe_dialog(HWND hwnd)
{
HWND temp_hwnd;
int active_value;
int tfe_enable;
int xsize, ysize;
char *interface_name = NULL;
uilib_get_group_extent(hwnd, ms_leftgroup, &xsize, &ysize);
uilib_adjust_group_width(hwnd, ms_leftgroup);
uilib_move_group(hwnd, ms_rightgroup, xsize + 30);
//resources_get_value("ETHERNET_ACTIVE", (void *)&tfe_enabled);
get_tfe_enabled(&tfe_enable);
//resources_get_value("ETHERNET_AS_RR", (void *)&tfe_as_rr_net);
active_value = (tfe_enable ? 1 : 0);
temp_hwnd=GetDlgItem(hwnd,IDC_TFE_SETTINGS_ENABLE);
SendMessage(temp_hwnd, CB_ADDSTRING, 0, (LPARAM)"Disabled");
SendMessage(temp_hwnd, CB_ADDSTRING, 0, (LPARAM)"Uthernet");
SendMessage(temp_hwnd, CB_SETCURSEL, (WPARAM)active_value, 0);
//resources_get_value("ETHERNET_INTERFACE", (void *)&interface_name);
interface_name = (char *) get_tfe_interface();
if (tfe_enumadapter_open())
{
int cnt = 0;
char *pname;
char *pdescription;
temp_hwnd=GetDlgItem(hwnd,IDC_TFE_SETTINGS_INTERFACE);
for (cnt = 0; tfe_enumadapter(&pname, &pdescription); cnt++)
{
BOOL this_entry = FALSE;
if (strcmp(pname, interface_name) == 0)
{
this_entry = TRUE;
}
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_NAME), pname);
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_DESC), pdescription);
SendMessage(temp_hwnd, CB_ADDSTRING, 0, (LPARAM)pname);
lib_free(pname);
lib_free(pdescription);
if (this_entry)
{
SendMessage(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE),
CB_SETCURSEL, (WPARAM)cnt, 0);
}
}
tfe_enumadapter_close();
}
if (gray_ungray_items(hwnd))
{
/* we have a problem: TFE is disabled. Give a message to the user */
// TC (18 Dec 2017) this vicekb URL is a broken link now, so I copied it to the AppleWin repo, here:
// . https://github.com/AppleWin/AppleWin/blob/master/docs/VICE%20Knowledge%20Base%20-%20Article%2013-005.htm
MessageBox( hwnd,
"TFE support is not available on your system,\n"
"there is some important part missing. Please have a\n"
"look at the VICE knowledge base support page\n"
"\n http://vicekb.trikaliotis.net/13-005\n\n"
"for possible reasons and to activate networking with VICE.",
"TFE support", MB_ICONINFORMATION|MB_OK);
/* just quit the dialog before it is open */
SendMessage( hwnd, WM_COMMAND, IDCANCEL, 0);
}
}
void CPageConfigTfe::save_tfe_dialog(HWND hwnd)
{
int active_value;
int tfe_enabled;
char buffer[256];
buffer[255] = 0;
GetDlgItemText(hwnd, IDC_TFE_SETTINGS_INTERFACE, buffer, sizeof(buffer)-1);
// RGJ - Added check for NULL interface so we don't set it active without a valid interface selected
if (strlen(buffer) > 0)
{
RegSaveString(TEXT("Configuration"), TEXT("Uthernet Interface"), 1, buffer);
active_value = SendMessage(GetDlgItem(hwnd, IDC_TFE_SETTINGS_ENABLE), CB_GETCURSEL, 0, 0);
tfe_enabled = active_value >= 1 ? 1 : 0;
REGSAVE(TEXT("Uthernet Active") ,tfe_enabled);
}
else
{
REGSAVE(TEXT("Uthernet Active") ,0);
}
}