PCem

view src/allegro-gui-configure.c @ 154:d0d530adce12

Initial port to Linux (using Allegro). 64-bit fixes. Some changes to aid portability. A few other tweaks.
author TomW
date Thu Sep 04 21:07:24 2014 +0100
parents
children
line source
1 #include "ibm.h"
2 #include "allegro-main.h"
3 #include "allegro-gui.h"
4 #include "cpu.h"
5 #include "model.h"
6 #include "sound.h"
7 #include "video.h"
9 static int romstolist[ROM_MAX], listtomodel[ROM_MAX], romstomodel[ROM_MAX], modeltolist[ROM_MAX];
10 static int settings_sound_to_list[20], settings_list_to_sound[20];
12 #if 0
13 DEFPUSHBUTTON "OK",IDOK,64,232,50,14, WS_TABSTOP
14 PUSHBUTTON "Cancel",IDCANCEL,128,232,50,14, WS_TABSTOP
15 COMBOBOX IDC_COMBO1,62,16,157,120,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
16 COMBOBOX IDC_COMBOVID,62,36,157,120,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
17 PUSHBUTTON "Configure", IDC_CONFIGUREVID, 224, 36, 40, 14, WS_TABSTOP
18 COMBOBOX IDC_COMBOCPUM,62,56,157,120,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
19 COMBOBOX IDC_COMBO3,62,76,157,120,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
20 COMBOBOX IDC_COMBOCHC,62,96,157,120,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
21 COMBOBOX IDC_COMBOSPD,62,116,157,120,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
22 COMBOBOX IDC_COMBOSND,62,136,157,120,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
23 PUSHBUTTON "Configure", IDC_CONFIGURESND, 224, 136, 40, 14, WS_TABSTOP
24 EDITTEXT IDC_MEMTEXT, 62, 152, 36, 14, ES_AUTOHSCROLL | ES_NUMBER
25 CONTROL "", IDC_MEMSPIN, UPDOWN_CLASS, UDS_ALIGNRIGHT | UDS_ARROWKEYS | UDS_NOTHOUSANDS | UDS_SETBUDDYINT, 98, 152, 12, 14
26 LTEXT "MB", IDC_STATIC, 98, 152, 40, 10
27 CONTROL "CMS / Game Blaster",IDC_CHECK3,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,172,118,10
28 CONTROL "Gravis Ultrasound",IDC_CHECKGUS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,188,118,10
29 CONTROL "Innovation SSI-2001",IDC_CHECKSSI,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,204,118,10
30 CONTROL "Composite CGA",IDC_CHECK4,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,220,118,10
31 LTEXT "Machine :",IDC_STATIC,15,16,40,10
32 LTEXT "Video :",IDC_STATIC,15,36,34,10
33 LTEXT "CPU type :",IDC_STATIC,15,56,34,10
34 LTEXT "CPU :",IDC_STATIC,15,76,34,10
35 LTEXT "Cache :",IDC_STATIC,15,96,40,10
36 LTEXT "Video speed :",IDC_STATIC,15,116,40,10
37 LTEXT "Soundcard :",IDC_STATIC,15,136,40,10
38 LTEXT "Memory :",IDC_STATIC,15,156,40,10
39 #endif
41 typedef struct allegro_list_t
42 {
43 char name[256];
44 int num;
45 } allegro_list_t;
47 static allegro_list_t model_list[ROM_MAX+1];
48 static allegro_list_t video_list[GFX_MAX+1];
49 static allegro_list_t sound_list[GFX_MAX+1];
50 static allegro_list_t cpumanu_list[4];
51 static allegro_list_t cpu_list[32];
53 static char mem_size_str[10];
55 static allegro_list_t cache_list[] =
56 {
57 {"A little", 0},
58 {"A bit", 1},
59 {"Some", 2},
60 {"A lot", 3},
61 {"Infinite", 4},
62 {"", -1}
63 };
65 static allegro_list_t vidspeed_list[] =
66 {
67 {"8-bit", 0},
68 {"Slow 16-bit", 1},
69 {"Fast 16-bit", 2},
70 {"Slow VLB/PCI", 3},
71 {"Mid VLB/PCI", 4},
72 {"Fast VLB/PCI", 5},
73 {"", -1}
74 };
76 static void reset_list();
78 static char *list_proc_model(int index, int *list_size)
79 {
80 if (index < 0)
81 {
82 int c = 0;
84 while (model_list[c].name[0])
85 c++;
87 *list_size = c;
88 return NULL;
89 }
91 return model_list[index].name;
92 }
94 static char *list_proc_video(int index, int *list_size)
95 {
96 if (index < 0)
97 {
98 int c = 0;
100 while (video_list[c].name[0])
101 c++;
103 *list_size = c;
104 return NULL;
105 }
107 return video_list[index].name;
108 }
110 static char *list_proc_cache(int index, int *list_size)
111 {
112 if (index < 0)
113 {
114 int c = 0;
116 while (cache_list[c].name[0])
117 c++;
119 *list_size = c;
120 return NULL;
121 }
123 return cache_list[index].name;
124 }
126 static char *list_proc_vidspeed(int index, int *list_size)
127 {
128 if (index < 0)
129 {
130 int c = 0;
132 while (vidspeed_list[c].name[0])
133 c++;
135 *list_size = c;
136 return NULL;
137 }
139 return vidspeed_list[index].name;
140 }
142 static char *list_proc_sound(int index, int *list_size)
143 {
144 if (index < 0)
145 {
146 int c = 0;
148 while (sound_list[c].name[0])
149 c++;
151 *list_size = c;
152 return NULL;
153 }
155 return sound_list[index].name;
156 }
158 static char *list_proc_cpumanu(int index, int *list_size)
159 {
160 if (index < 0)
161 {
162 int c = 0;
164 while (cpumanu_list[c].name[0])
165 c++;
167 *list_size = c;
168 return NULL;
169 }
171 return cpumanu_list[index].name;
172 }
174 static char *list_proc_cpu(int index, int *list_size)
175 {
176 if (index < 0)
177 {
178 int c = 0;
180 while (cpu_list[c].name[0])
181 c++;
183 *list_size = c;
184 return NULL;
185 }
187 return cpu_list[index].name;
188 }
190 static int list_proc(int msg, DIALOG *d, int c);
192 static DIALOG configure_dialog[] =
193 {
194 {d_shadow_box_proc, 0, 0, 236*2,256,0,0xffffff,0,0, 0,0,0,0,0}, // 0
196 {d_button_proc, 176, 232, 50, 14, 0, 0xffffff, 0, D_EXIT, 0, 0, "OK", 0, 0}, // 1
197 {d_button_proc, 246, 232, 50, 16, 0, 0xffffff, 0, D_EXIT, 0, 0, "Cancel", 0, 0}, // 2
199 {list_proc, 70*2, 12, 152*2, 20, 0, 0xffffff, 0, 0, 0, 0, list_proc_model, 0, 0},
201 {list_proc, 70*2, 32, 152*2, 20, 0, 0xffffff, 0, 0, 0, 0, list_proc_video, 0, 0},
203 {list_proc, 70*2, 52, 152*2, 20, 0, 0xffffff, 0, 0, 0, 0, list_proc_cpumanu, 0, 0}, //5
204 {d_list_proc, 70*2, 72, 152*2, 20, 0, 0xffffff, 0, 0, 0, 0, list_proc_cpu, 0, 0},
205 {d_list_proc, 70*2, 92, 152*2, 20, 0, 0xffffff, 0, 0, 0, 0, list_proc_cache, 0, 0},
206 {d_list_proc, 70*2, 112, 152*2, 20, 0, 0xffffff, 0, 0, 0, 0, list_proc_vidspeed, 0, 0},
207 {list_proc, 70*2, 132, 152*2, 20, 0, 0xffffff, 0, 0, 0, 0, list_proc_sound, 0, 0}, //9
209 {d_edit_proc, 70*2, 156, 32, 14, 0, 0xffffff, 0, 0, 3, 0, mem_size_str, 0, 0},
211 {d_text_proc, 98*2, 156, 40, 10, 0, 0xffffff, 0, 0, 0, 0, "MB", 0, 0},
213 {d_check_proc, 14*2, 172, 118*2, 10, 0, 0xffffff, 0, 0, 0, 0, "CMS / Game Blaster", 0, 0},
214 {d_check_proc, 14*2, 188, 118*2, 10, 0, 0xffffff, 0, 0, 0, 0, "Gravis Ultrasound", 0, 0},
215 {d_check_proc, 14*2, 204, 118*2, 10, 0, 0xffffff, 0, 0, 0, 0, "Innovation SSI-2001", 0, 0},
216 {d_check_proc, 14*2, 220, 118*2, 10, 0, 0xffffff, 0, 0, 0, 0, "Composite CGA", 0, 0},
218 {d_text_proc, 16*2, 16, 40, 10, 0, 0xffffff, 0, 0, 0, 0, "Machine :", 0, 0},
219 {d_text_proc, 16*2, 36, 40, 10, 0, 0xffffff, 0, 0, 0, 0, "Video :", 0, 0},
220 {d_text_proc, 16*2, 56, 40, 10, 0, 0xffffff, 0, 0, 0, 0, "CPU type :", 0, 0},
221 {d_text_proc, 16*2, 76, 40, 10, 0, 0xffffff, 0, 0, 0, 0, "CPU :", 0, 0},
222 {d_text_proc, 16*2, 96, 40, 10, 0, 0xffffff, 0, 0, 0, 0, "Cache :", 0, 0},
223 {d_text_proc, 16*2, 116, 40, 10, 0, 0xffffff, 0, 0, 0, 0, "Video speed :", 0, 0},
224 {d_text_proc, 16*2, 136, 40, 10, 0, 0xffffff, 0, 0, 0, 0, "Soundcard :", 0, 0},
225 {d_text_proc, 16*2, 156, 40, 10, 0, 0xffffff, 0, 0, 0, 0, "Memory :", 0, 0},
227 {0,0,0,0,0,0,0,0,0,0,0,NULL,NULL,NULL}
228 };
230 static int list_proc(int msg, DIALOG *d, int c)
231 {
232 int old = d->d1;
233 int ret = d_list_proc(msg, d, c);
235 if (d->d1 != old)
236 {
237 int new_model = model_list[configure_dialog[3].d1].num;
239 reset_list();
241 if (models[new_model].fixed_gfxcard)
242 configure_dialog[4].flags |= D_DISABLED;
243 else
244 configure_dialog[4].flags &= ~D_DISABLED;
246 return D_REDRAW;
247 }
249 return ret;
250 }
252 static void reset_list()
253 {
254 int model = model_list[configure_dialog[3].d1].num;
255 int cpumanu = configure_dialog[5].d1;
256 int cpu = configure_dialog[6].d1;
257 int c;
259 memset(cpumanu_list, 0, sizeof(cpumanu_list));
260 memset(cpu_list, 0, sizeof(cpu_list));
262 c = 0;
263 while (models[model].cpu[c].cpus != NULL && c < 3)
264 {
265 strcpy(cpumanu_list[c].name, models[model].cpu[c].name);
266 cpumanu_list[c].num = c;
267 c++;
268 }
270 if (cpumanu >= c)
271 cpumanu = configure_dialog[6].d1 = c-1;
273 c = 0;
274 while (models[model].cpu[cpumanu].cpus[c].cpu_type != -1)
275 {
276 strcpy(cpu_list[c].name, models[model].cpu[cpumanu].cpus[c].name);
277 cpu_list[c].num = c;
278 c++;
279 }
281 if (cpu >= c)
282 cpu = configure_dialog[7].d1 = c-1;
283 }
285 int settings_configure()
286 {
287 int c, d;
289 memset(model_list, 0, sizeof(model_list));
290 memset(video_list, 0, sizeof(video_list));
291 memset(sound_list, 0, sizeof(sound_list));
293 for (c = 0; c < ROM_MAX; c++)
294 romstolist[c] = 0;
295 c = d = 0;
296 while (models[c].id != -1)
297 {
298 pclog("INITDIALOG : %i %i %i\n",c,models[c].id,romspresent[models[c].id]);
299 if (romspresent[models[c].id])
300 {
301 strcpy(model_list[d].name, models[c].name);
302 model_list[d].num = c;
303 if (c == model)
304 configure_dialog[3].d1 = d;
305 d++;
306 }
307 c++;
308 }
310 if (models[model].fixed_gfxcard)
311 configure_dialog[4].flags |= D_DISABLED;
312 else
313 configure_dialog[4].flags &= ~D_DISABLED;
315 c = d = 0;
316 while (1)
317 {
318 char *s = video_card_getname(c);
320 if (!s[0])
321 break;
322 pclog("video_card_available : %i\n", c);
323 if (video_card_available(c))
324 {
325 strcpy(video_list[d].name, video_card_getname(c));
326 video_list[d].num = video_new_to_old(c);
327 if (video_new_to_old(c) == gfxcard)
328 configure_dialog[4].d1 = d;
329 d++;
330 }
332 c++;
333 }
335 c = d = 0;
336 while (1)
337 {
338 char *s = sound_card_getname(c);
340 if (!s[0])
341 break;
343 if (sound_card_available(c))
344 {
345 strcpy(sound_list[d].name, sound_card_getname(c));
346 sound_list[d].num = c;
347 if (c == sound_card_current)
348 configure_dialog[9].d1 = d;
349 d++;
350 }
352 c++;
353 }
355 configure_dialog[5].d1 = cpu_manufacturer;
356 configure_dialog[6].d1 = cpu;
357 configure_dialog[7].d1 = cache;
358 configure_dialog[8].d1 = video_speed;
359 reset_list();
360 // strcpy(cpumanu_str, models[romstomodel[romset]].cpu[cpu_manufacturer].name);
361 // strcpy(cpu_str, models[romstomodel[romset]].cpu[cpu_manufacturer].cpus[cpu].name);
362 // strcpy(cache_str, cache_str_list[cache]);
363 // strcpy(vidspeed_str, vidspeed_str_list[video_speed]);
365 // strcpy(soundcard_str, sound_card_getname(sound_card_current));
367 if (GAMEBLASTER)
368 configure_dialog[12].flags |= D_SELECTED;
369 else
370 configure_dialog[12].flags &= ~D_SELECTED;
372 if (GUS)
373 configure_dialog[13].flags |= D_SELECTED;
374 else
375 configure_dialog[13].flags &= ~D_SELECTED;
377 if (SSI2001)
378 configure_dialog[14].flags |= D_SELECTED;
379 else
380 configure_dialog[14].flags &= ~D_SELECTED;
382 if (cga_comp)
383 configure_dialog[15].flags |= D_SELECTED;
384 else
385 configure_dialog[15].flags &= ~D_SELECTED;
387 sprintf(mem_size_str, "%i", mem_size);
389 while (1)
390 {
391 position_dialog(configure_dialog, SCREEN_W/2 - 272, SCREEN_H/2 - 256/2);
393 c = popup_dialog(configure_dialog, 1);
395 position_dialog(configure_dialog, -(SCREEN_W/2 - 272), -(SCREEN_H/2 - 256/2));
397 if (c == 1)
398 {
399 int new_model = model_list[configure_dialog[3].d1].num;
400 int new_gfxcard = video_list[configure_dialog[4].d1].num;
401 int new_sndcard = sound_list[configure_dialog[9].d1].num;
402 int new_cpu_m = configure_dialog[5].d1;
403 int new_cpu = configure_dialog[6].d1;
404 int new_mem_size;
405 int new_has_fpu = (models[new_model].cpu[new_cpu_m].cpus[new_cpu].cpu_type >= CPU_i486DX) ? 1 : 0;
406 int new_GAMEBLASTER = (configure_dialog[12].flags & D_SELECTED) ? 1 : 0;
407 int new_GUS = (configure_dialog[13].flags & D_SELECTED) ? 1 : 0;
408 int new_SSI2001 = (configure_dialog[14].flags & D_SELECTED) ? 1 : 0;
410 sscanf(mem_size_str, "%i", &new_mem_size);
411 if (new_mem_size < 1 || new_mem_size > 256)
412 {
413 alert("Invalid memory size", "Memory must be between 1 and 256 MB", NULL, "OK", NULL, 0, 0);
414 continue;
415 }
417 if (new_model != model || new_gfxcard != gfxcard || new_mem_size != mem_size ||
418 new_has_fpu != hasfpu || new_GAMEBLASTER != GAMEBLASTER || new_GUS != GUS ||
419 new_SSI2001 != SSI2001 || new_sndcard != sound_card_current)
420 {
421 if (alert("This will reset PCem!", "Okay to continue?", NULL, "OK", "Cancel", 0, 0) != 1)
422 continue;
424 model = new_model;
425 romset = model_getromset();
426 gfxcard = new_gfxcard;
427 mem_size = new_mem_size;
428 cpu_manufacturer = new_cpu_m;
429 cpu = new_cpu;
430 GAMEBLASTER = new_GAMEBLASTER;
431 GUS = new_GUS;
432 SSI2001 = new_SSI2001;
433 sound_card_current = new_sndcard;
435 mem_resize();
436 loadbios();
437 resetpchard();
438 }
440 video_speed = configure_dialog[8].d1;
442 cga_comp = (configure_dialog[15].flags & D_SELECTED) ? 1 : 0;
444 cpu_manufacturer = new_cpu_m;
445 cpu = new_cpu;
446 cpu_set();
448 cache = configure_dialog[9].d1;
449 mem_updatecache();
451 saveconfig();
453 speedchanged();
455 return D_O_K;
456 }
458 if (c == 2)
459 return D_O_K;
460 }
462 return D_O_K;
463 }