PCem
view src/win-deviceconfig.c @ 113:f749363ad763
Added per-device configuration.
Reworked configuration parser a bit.
Added configuration for S3 ViRGE and 8-bit Sound Blasters.
IRQ 2 routed to IRQ 9 on AT machines.
| author | TomW |
|---|---|
| date | Mon Jun 30 21:31:28 2014 +0100 |
| parents | |
| children | d0d530adce12 |
line source
1 #define BITMAP WINDOWS_BITMAP
2 #include <windows.h>
3 #include <windowsx.h>
4 #undef BITMAP
6 #include "ibm.h"
7 #include "config.h"
8 #include "device.h"
9 #include "resources.h"
10 #include "win.h"
12 static device_t *config_device;
14 static BOOL CALLBACK deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
15 {
16 switch (message)
17 {
18 case WM_INITDIALOG:
19 {
20 int id = IDC_CONFIG_BASE;
21 device_config_t *config = config_device->config;
22 int c;
24 while (config->type != -1)
25 {
26 device_config_selection_t *selection = config->selection;
27 HWND h = GetDlgItem(hdlg, id);
28 int val_int;
29 char *val_string;
31 switch (config->type)
32 {
33 case CONFIG_BINARY:
34 val_int = get_config_int(config_device->name, config->name, config->default_int);
36 SendMessage(h, BM_SETCHECK, val_int, 0);
38 id++;
39 break;
41 case CONFIG_SELECTION:
42 val_int = get_config_int(config_device->name, config->name, config->default_int);
44 c = 0;
45 while (selection->description[0])
46 {
47 SendMessage(h, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)selection->description);
48 if (val_int == selection->value)
49 SendMessage(h, CB_SETCURSEL, c, 0);
50 selection++;
51 c++;
52 }
54 id += 2;
55 break;
56 }
57 config++;
58 }
59 }
60 return TRUE;
62 case WM_COMMAND:
63 switch (LOWORD(wParam))
64 {
65 case IDOK:
66 {
67 int id = IDC_CONFIG_BASE;
68 device_config_t *config = config_device->config;
69 int c;
70 int changed = 0;
72 while (config->type != -1)
73 {
74 device_config_selection_t *selection = config->selection;
75 HWND h = GetDlgItem(hdlg, id);
76 int val_int;
77 char *val_string;
79 switch (config->type)
80 {
81 case CONFIG_BINARY:
82 val_int = get_config_int(config_device->name, config->name, config->default_int);
84 if (val_int != SendMessage(h, BM_GETCHECK, 0, 0))
85 changed = 1;
87 id++;
88 break;
90 case CONFIG_SELECTION:
91 val_int = get_config_int(config_device->name, config->name, config->default_int);
93 c = SendMessage(h, CB_GETCURSEL, 0, 0);
95 for (; c > 0; c--)
96 selection++;
98 if (val_int != selection->value)
99 changed = 1;
101 id += 2;
102 break;
103 }
104 config++;
105 }
107 if (!changed)
108 {
109 EndDialog(hdlg, 0);
110 return TRUE;
111 }
113 if (MessageBox(NULL, "This will reset PCem!\nOkay to continue?", "PCem", MB_OKCANCEL) != IDOK)
114 {
115 EndDialog(hdlg, 0);
116 return TRUE;
117 }
119 id = IDC_CONFIG_BASE;
120 config = config_device->config;
122 while (config->type != -1)
123 {
124 device_config_selection_t *selection = config->selection;
125 HWND h = GetDlgItem(hdlg, id);
126 int val_int;
127 char *val_string;
129 switch (config->type)
130 {
131 case CONFIG_BINARY:
132 set_config_int(config_device->name, config->name, SendMessage(h, BM_GETCHECK, 0, 0));
134 id++;
135 break;
137 case CONFIG_SELECTION:
138 c = SendMessage(h, CB_GETCURSEL, 0, 0);
139 for (; c > 0; c--)
140 selection++;
141 set_config_int(config_device->name, config->name, selection->value);
143 id += 2;
144 break;
145 }
146 config++;
147 }
149 saveconfig();
151 resetpchard();
153 EndDialog(hdlg, 0);
154 return TRUE;
155 }
156 case IDCANCEL:
157 EndDialog(hdlg, 0);
158 return TRUE;
159 }
160 break;
161 }
162 return FALSE;
163 }
165 void deviceconfig_open(HWND hwnd, device_t *device)
166 {
167 device_config_t *config = device->config;
168 uint16_t *data = malloc(16384);
169 DLGTEMPLATE *dlg = (DLGTEMPLATE *)data;
170 DLGITEMTEMPLATE *item;
171 int y = 10;
172 int id = IDC_CONFIG_BASE;
174 memset(data, 0, 4096);
176 dlg->style = DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU;
177 dlg->x = 10;
178 dlg->y = 10;
179 dlg->cx = 150;
180 dlg->cy = 70;
182 data = (uint16_t *)(dlg + 1);
184 *data++ = 0; /*no menu*/
185 *data++ = 0; /*predefined dialog box class*/
186 data += MultiByteToWideChar(CP_ACP, 0, "Device Configuration", -1, data, 50);
188 *data++ = 8; /*Point*/
189 data += MultiByteToWideChar(CP_ACP, 0, "MS Sans Serif", -1, data, 50);
191 if (((unsigned long)data) & 2)
192 data++;
194 while (config->type != -1)
195 {
196 switch (config->type)
197 {
198 case CONFIG_BINARY:
199 item = (DLGITEMTEMPLATE *)data;
200 item->x = 10;
201 item->y = y;
202 item->id = id++;
204 item->cx = 80;
205 item->cy = 15;
207 item->style = WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX;
209 data = (uint16_t *)(item + 1);
210 *data++ = 0xFFFF;
211 *data++ = 0x0080; // button class
213 data += MultiByteToWideChar(CP_ACP, 0, config->description, -1, data, 256);
214 *data++ = 0; // no creation data
216 y += 20;
217 break;
219 case CONFIG_SELECTION:
220 /*Combo box*/
221 item = (DLGITEMTEMPLATE *)data;
222 item->x = 70;
223 item->y = y;
224 item->id = id++;
226 item->cx = 70;
227 item->cy = 150;
229 item->style = WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | WS_VSCROLL;
231 data = (uint16_t *)(item + 1);
232 *data++ = 0xFFFF;
233 *data++ = 0x0085; // combo box class
235 data += MultiByteToWideChar(CP_ACP, 0, config->description, -1, data, 256);
236 *data++ = 0; // no creation data
238 if (((unsigned long)data) & 2)
239 data++;
241 /*Static text*/
242 item = (DLGITEMTEMPLATE *)data;
243 item->x = 10;
244 item->y = y;
245 item->id = id++;
247 item->cx = 60;
248 item->cy = 15;
250 item->style = WS_CHILD | WS_VISIBLE;
252 data = (uint16_t *)(item + 1);
253 *data++ = 0xFFFF;
254 *data++ = 0x0082; // static class
256 data += MultiByteToWideChar(CP_ACP, 0, config->description, -1, data, 256);
257 *data++ = 0; // no creation data
259 if (((unsigned long)data) & 2)
260 data++;
262 y += 20;
263 break;
264 }
266 if (((unsigned long)data) & 2)
267 data++;
269 config++;
270 }
272 dlg->cdit = (id - IDC_CONFIG_BASE) + 2;
274 // DEFPUSHBUTTON "OK",IDOK,64,232,50,14, WS_TABSTOP
275 // PUSHBUTTON "Cancel",IDCANCEL,128,232,50,14, WS_TABSTOP
277 item = (DLGITEMTEMPLATE *)data;
278 item->x = 20;
279 item->y = y;
280 item->cx = 50;
281 item->cy = 14;
282 item->id = IDOK; // OK button identifier
283 item->style = WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON;
285 data = (uint16_t *)(item + 1);
286 *data++ = 0xFFFF;
287 *data++ = 0x0080; // button class
289 data += MultiByteToWideChar(CP_ACP, 0, "OK", -1, data, 50);
290 *data++ = 0; // no creation data
292 if (((unsigned long)data) & 2)
293 data++;
295 item = (DLGITEMTEMPLATE *)data;
296 item->x = 80;
297 item->y = y;
298 item->cx = 50;
299 item->cy = 14;
300 item->id = IDCANCEL; // OK button identifier
301 item->style = WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON;
303 data = (uint16_t *)(item + 1);
304 *data++ = 0xFFFF;
305 *data++ = 0x0080; // button class
307 data += MultiByteToWideChar(CP_ACP, 0, "Cancel", -1, data, 50);
308 *data++ = 0; // no creation data
310 dlg->cy = y + 20;
312 config_device = device;
314 DialogBoxIndirect(hinstance, dlg, hwnd, deviceconfig_dlgproc);
316 free(data);
317 }
