PCem

view src/pc.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 c5989dbbc2ce
children d08a822e6603
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdarg.h>
4 #include "ibm.h"
5 #include "device.h"
7 #include "ali1429.h"
8 #include "amstrad.h"
9 #include "cdrom-ioctl.h"
10 #include "config.h"
11 #include "cpu.h"
12 #include "dma.h"
13 #include "fdc.h"
14 #include "sound_gus.h"
15 #include "ide.h"
16 #include "keyboard.h"
17 #include "mem.h"
18 #include "model.h"
19 #include "mouse.h"
20 #include "nvr.h"
21 #include "pic.h"
22 #include "pit.h"
23 #include "plat-joystick.h"
24 #include "plat-mouse.h"
25 #include "serial.h"
26 #include "sound.h"
27 #include "sound_cms.h"
28 #include "sound_opl.h"
29 #include "sound_sb.h"
30 #include "sound_ssi2001.h"
31 #include "timer.h"
32 #include "vid_voodoo.h"
33 #include "video.h"
35 int frame = 0;
37 int cdrom_enabled;
38 int CPUID;
39 int vid_resize, vid_api;
41 int cycles_lost = 0;
43 int clockrate;
44 int insc=0;
45 float mips,flops;
46 extern int mmuflush;
47 extern int readlnum,writelnum;
48 void fullspeed();
50 int framecount,fps;
51 int intcount;
53 int output;
54 int atfullspeed;
55 void loadconfig();
56 void saveconfig();
57 int infocus;
58 int mousecapture;
59 FILE *pclogf;
60 void pclog(const char *format, ...)
61 {
62 #ifndef RELEASE_BUILD
63 char buf[1024];
64 //return;
65 if (!pclogf)
66 pclogf=fopen("pclog.txt","wt");
67 //return;
68 va_list ap;
69 va_start(ap, format);
70 vsprintf(buf, format, ap);
71 va_end(ap);
72 fputs(buf,pclogf);
73 fflush(pclogf);
74 #endif
75 }
77 void fatal(const char *format, ...)
78 {
79 char buf[256];
80 // return;
81 if (!pclogf)
82 pclogf=fopen("pclog.txt","wt");
83 //return;
84 va_list ap;
85 va_start(ap, format);
86 vsprintf(buf, format, ap);
87 va_end(ap);
88 fputs(buf,pclogf);
89 fflush(pclogf);
90 dumppic();
91 dumpregs();
92 exit(-1);
93 }
95 uint8_t cgastat;
97 int pollmouse_delay = 2;
98 void pollmouse()
99 {
100 int x,y;
101 // return;
102 pollmouse_delay--;
103 if (pollmouse_delay) return;
104 pollmouse_delay = 2;
105 poll_mouse();
106 get_mouse_mickeys(&x,&y);
107 if (mouse_poll)
108 mouse_poll(x, y, mouse_b);
109 if (mousecapture) position_mouse(64,64);
110 }
112 /*PC1512 languages -
113 7=English
114 6=German
115 5=French
116 4=Spanish
117 3=Danish
118 2=Swedish
119 1=Italian
120 3,2,1 all cause the self test to fail for some reason
121 */
123 int cpuspeed2;
125 int clocks[3][12][4]=
126 {
127 {
128 {4772728,13920,59660,5965}, /*4.77MHz*/
129 {8000000,23333,110000,0}, /*8MHz*/
130 {10000000,29166,137500,0}, /*10MHz*/
131 {12000000,35000,165000,0}, /*12MHz*/
132 {16000000,46666,220000,0}, /*16MHz*/
133 },
134 {
135 {8000000,23333,110000,0}, /*8MHz*/
136 {12000000,35000,165000,0}, /*12MHz*/
137 {16000000,46666,220000,0}, /*16MHz*/
138 {20000000,58333,275000,0}, /*20MHz*/
139 {25000000,72916,343751,0}, /*25MHz*/
140 },
141 {
142 {16000000, 46666,220000,0}, /*16MHz*/
143 {20000000, 58333,275000,0}, /*20MHz*/
144 {25000000, 72916,343751,0}, /*25MHz*/
145 {33000000, 96000,454000,0}, /*33MHz*/
146 {40000000,116666,550000,0}, /*40MHz*/
147 {50000000, 72916*2,343751*2,0}, /*50MHz*/
148 {33000000*2, 96000*2,454000*2,0}, /*66MHz*/
149 {75000000, 72916*3,343751*3,0}, /*75MHz*/
150 {80000000,116666*2,550000*2,0}, /*80MHz*/
151 {100000000, 72916*4,343751*4,0}, /*100MHz*/
152 {120000000,116666*3,550000*3,0}, /*120MHz*/
153 {133000000, 96000*4,454000*4,0}, /*133MHz*/
154 }
155 };
157 int updatestatus;
158 int win_title_update=0;
161 void onesec()
162 {
163 fps=framecount;
164 framecount=0;
165 win_title_update=1;
166 }
168 void pc_reset()
169 {
170 resetx86();
171 cpu_set();
172 //timer_reset();
173 dma_reset();
174 fdc_reset();
175 pic_reset();
176 pit_reset();
177 serial_reset();
179 setpitclock(models[model].cpu[cpu_manufacturer].cpus[cpu].rspeed);
181 // sb_reset();
183 ali1429_reset();
184 // video_init();
185 }
187 void initpc()
188 {
189 char *p;
190 // allegro_init();
191 get_executable_name(pcempath,511);
192 pclog("executable_name = %s\n", pcempath);
193 p=get_filename(pcempath);
194 *p=0;
195 pclog("path = %s\n", pcempath);
197 keyboard_init();
198 mouse_init();
199 joystick_init();
201 loadconfig();
202 pclog("Config loaded\n");
204 cpuspeed2=(AT)?2:1;
205 // cpuspeed2=cpuspeed;
206 atfullspeed=0;
208 device_init();
210 initvideo();
211 mem_init();
212 loadbios();
213 mem_add_bios();
215 loaddisc(0,discfns[0]);
216 loaddisc(1,discfns[1]);
218 timer_reset();
219 sound_reset();
220 fdc_init();
222 //loadfont();
223 loadnvr();
224 sound_init();
225 resetide();
226 ioctl_open(cdrom_drive);
227 model_init();
228 video_init();
229 speaker_init();
230 sound_card_init(sound_card_current);
231 if (GUS)
232 device_add(&gus_device);
233 if (GAMEBLASTER)
234 device_add(&cms_device);
235 if (SSI2001)
236 device_add(&ssi2001_device);
238 pc_reset();
240 pit_reset();
241 /* if (romset==ROM_AMI386 || romset==ROM_AMI486) */fullspeed();
242 mem_updatecache();
243 ali1429_reset();
244 // CPUID=(is486 && (cpuspeed==7 || cpuspeed>=9));
245 // pclog("Init - CPUID %i %i\n",CPUID,cpuspeed);
246 shadowbios=0;
247 voodoo_init();
248 }
250 void resetpc()
251 {
252 pc_reset();
253 // cpuspeed2=(AT)?2:1;
254 // atfullspeed=0;
255 ///* if (romset==ROM_AMI386 || romset==ROM_AMI486) */fullspeed();
256 shadowbios=0;
257 }
259 void resetpchard()
260 {
261 device_close_all();
262 device_init();
264 timer_reset();
265 sound_reset();
266 mem_resize();
267 fdc_init();
268 model_init();
269 video_init();
270 speaker_init();
271 sound_card_init(sound_card_current);
272 if (GUS)
273 device_add(&gus_device);
274 if (GAMEBLASTER)
275 device_add(&cms_device);
276 if (SSI2001)
277 device_add(&ssi2001_device);
279 pc_reset();
281 resetide();
283 loadnvr();
285 // cpuspeed2 = (AT)?2:1;
286 // atfullspeed = 0;
287 // setpitclock(models[model].cpu[cpu_manufacturer].cpus[cpu].rspeed);
289 shadowbios = 0;
290 ali1429_reset();
292 keyboard_at_reset();
294 // output=3;
295 }
297 char romsets[17][40]={"IBM PC","IBM XT","Generic Turbo XT","Euro PC","Tandy 1000","Amstrad PC1512","Sinclair PC200","Amstrad PC1640","IBM AT","AMI 286 clone","Dell System 200","Misc 286","IBM AT 386","Misc 386","386 clone","486 clone","486 clone 2"};
298 char clockspeeds[3][12][16]=
299 {
300 {"4.77MHz","8MHz","10MHz","12MHz","16MHz"},
301 {"8MHz","12MHz","16MHz","20MHz","25MHz"},
302 {"16MHz","20MHz","25MHz","33MHz","40MHz","50MHz","66MHz","75MHz","80MHz","100MHz","120MHz","133MHz"},
303 };
304 int framecountx=0;
305 int sndcount=0;
306 int oldat70hz;
308 int sreadlnum,swritelnum,segareads,segawrites, scycles_lost;
310 int serial_fifo_read, serial_fifo_write;
312 int emu_fps = 0;
314 void runpc()
315 {
316 char s[200];
317 int done=0;
319 startblit();
320 clockrate = models[model].cpu[cpu_manufacturer].cpus[cpu].rspeed;
321 if (is386) exec386(models[model].cpu[cpu_manufacturer].cpus[cpu].rspeed / 100);
322 else if (AT) exec386(models[model].cpu[cpu_manufacturer].cpus[cpu].rspeed / 100);
323 else execx86(models[model].cpu[cpu_manufacturer].cpus[cpu].rspeed / 100);
324 keyboard_poll_host();
325 keyboard_process();
326 // checkkeys();
327 pollmouse();
328 poll_joystick();
329 endblit();
331 framecountx++;
332 framecount++;
333 if (framecountx>=100)
334 {
335 pclog("onesec\n");
336 framecountx=0;
337 mips=(float)insc/1000000.0f;
338 insc=0;
339 flops=(float)fpucount/1000000.0f;
340 fpucount=0;
341 sreadlnum=readlnum;
342 swritelnum=writelnum;
343 segareads=egareads;
344 segawrites=egawrites;
345 scycles_lost = cycles_lost;
346 updatestatus=1;
347 readlnum=writelnum=0;
348 egareads=egawrites=0;
349 cycles_lost = 0;
350 mmuflush=0;
351 intcount=0;
352 intcount=pitcount=0;
353 emu_fps = frames;
354 frames = 0;
355 }
356 if (win_title_update)
357 {
358 win_title_update=0;
359 sprintf(s, "PCem v8.1 - %s - %s - %s - %i%%", model_getname(), models[model].cpu[cpu_manufacturer].cpus[cpu].name, (!mousecapture) ? "Click to capture mouse" : "Press CTRL-END or middle button to release mouse", fps);
360 set_window_title(s);
361 }
362 done++;
363 frame++;
364 }
366 void fullspeed()
367 {
368 cpuspeed2=cpuspeed;
369 if (!atfullspeed)
370 {
371 printf("Set fullspeed - %i %i %i\n",is386,AT,cpuspeed2);
372 setpitclock(models[model].cpu[cpu_manufacturer].cpus[cpu].rspeed);
373 // if (is386) setpitclock(clocks[2][cpuspeed2][0]);
374 // else setpitclock(clocks[AT?1:0][cpuspeed2][0]);
375 }
376 atfullspeed=1;
377 nvr_recalc();
378 }
380 void speedchanged()
381 {
382 if (atfullspeed)
383 {
384 cpuspeed2=cpuspeed;
385 setpitclock(models[model].cpu[cpu_manufacturer].cpus[cpu].rspeed);
386 // if (is386) setpitclock(clocks[2][cpuspeed2][0]);
387 // else setpitclock(clocks[AT?1:0][cpuspeed2][0]);
388 }
389 mem_updatecache();
390 nvr_recalc();
391 }
393 void closepc()
394 {
395 atapi->exit();
396 // ioctl_close();
397 dumppic();
398 // output=7;
399 // setpitclock(clocks[0][0][0]);
400 // while (1) runpc();
401 savedisc(0);
402 savedisc(1);
403 dumpregs();
404 closevideo();
405 device_close_all();
406 }
408 /*int main()
409 {
410 initpc();
411 while (!key[KEY_F11])
412 {
413 runpc();
414 }
415 closepc();
416 return 0;
417 }
419 END_OF_MAIN();*/
421 int cga_comp=0;
423 void loadconfig()
424 {
425 char s[512];
426 char *p;
427 append_filename(s, pcempath, "pcem.cfg", 511);
428 set_config_file(s);
430 config_load();
432 GAMEBLASTER = get_config_int(NULL, "gameblaster", 0);
433 GUS = get_config_int(NULL, "gus", 0);
434 SSI2001 = get_config_int(NULL, "ssi2001", 0);
436 model = get_config_int(NULL, "model", 14);
438 if (model >= model_count())
439 model = model_count() - 1;
441 romset = model_getromset();
442 cpu_manufacturer = get_config_int(NULL, "cpu_manufacturer", 0);
443 cpu = get_config_int(NULL, "cpu", 0);
445 gfxcard = get_config_int(NULL, "gfxcard", 0);
446 video_speed = get_config_int(NULL, "video_speed", 3);
447 sound_card_current = get_config_int(NULL, "sndcard", SB2);
449 p = (char *)get_config_string(NULL, "disc_a", "");
450 if (p) strcpy(discfns[0], p);
451 else strcpy(discfns[0], "");
453 p = (char *)get_config_string(NULL, "disc_b", "");
454 if (p) strcpy(discfns[1], p);
455 else strcpy(discfns[1], "");
457 mem_size = get_config_int(NULL, "mem_size", 4);
458 cdrom_drive = get_config_int(NULL, "cdrom_drive", 0);
459 cdrom_enabled = get_config_int(NULL, "cdrom_enabled", 0);
461 slowega = get_config_int(NULL, "slow_video", 1);
462 cache = get_config_int(NULL, "cache", 3);
463 cga_comp = get_config_int(NULL, "cga_composite", 0);
465 vid_resize = get_config_int(NULL, "vid_resize", 0);
466 vid_api = get_config_int(NULL, "vid_api", 0);
467 video_fullscreen_scale = get_config_int(NULL, "video_fullscreen_scale", 0);
468 video_fullscreen_first = get_config_int(NULL, "video_fullscreen_first", 1);
470 hdc[0].spt = get_config_int(NULL, "hdc_sectors", 0);
471 hdc[0].hpc = get_config_int(NULL, "hdc_heads", 0);
472 hdc[0].tracks = get_config_int(NULL, "hdc_cylinders", 0);
473 p = (char *)get_config_string(NULL, "hdc_fn", "");
474 if (p) strcpy(ide_fn[0], p);
475 else strcpy(ide_fn[0], "");
476 hdc[1].spt = get_config_int(NULL, "hdd_sectors", 0);
477 hdc[1].hpc = get_config_int(NULL, "hdd_heads", 0);
478 hdc[1].tracks = get_config_int(NULL, "hdd_cylinders", 0);
479 p = (char *)get_config_string(NULL, "hdd_fn", "");
480 if (p) strcpy(ide_fn[1], p);
481 else strcpy(ide_fn[1], "");
482 }
484 void saveconfig()
485 {
486 set_config_int(NULL, "gameblaster", GAMEBLASTER);
487 set_config_int(NULL, "gus", GUS);
488 set_config_int(NULL, "ssi2001", SSI2001);
490 set_config_int(NULL, "model", model);
491 set_config_int(NULL, "cpu_manufacturer", cpu_manufacturer);
492 set_config_int(NULL, "cpu", cpu);
494 set_config_int(NULL, "gfxcard", gfxcard);
495 set_config_int(NULL, "video_speed", video_speed);
496 set_config_int(NULL, "sndcard", sound_card_current);
497 set_config_int(NULL, "cpu_speed", cpuspeed);
498 set_config_int(NULL, "has_fpu", hasfpu);
499 set_config_int(NULL, "slow_video", slowega);
500 set_config_int(NULL, "cache", cache);
501 set_config_int(NULL, "cga_composite", cga_comp);
502 set_config_string(NULL, "disc_a", discfns[0]);
503 set_config_string(NULL, "disc_b", discfns[1]);
504 set_config_int(NULL, "mem_size", mem_size);
505 set_config_int(NULL, "cdrom_drive", cdrom_drive);
506 set_config_int(NULL, "cdrom_enabled", cdrom_enabled);
507 set_config_int(NULL, "vid_resize", vid_resize);
508 set_config_int(NULL, "vid_api", vid_api);
509 set_config_int(NULL, "video_fullscreen_scale", video_fullscreen_scale);
510 set_config_int(NULL, "video_fullscreen_first", video_fullscreen_first);
512 set_config_int(NULL, "hdc_sectors", hdc[0].spt);
513 set_config_int(NULL, "hdc_heads", hdc[0].hpc);
514 set_config_int(NULL, "hdc_cylinders", hdc[0].tracks);
515 set_config_string(NULL, "hdc_fn", ide_fn[0]);
516 set_config_int(NULL, "hdd_sectors", hdc[1].spt);
517 set_config_int(NULL, "hdd_heads", hdc[1].hpc);
518 set_config_int(NULL, "hdd_cylinders", hdc[1].tracks);
519 set_config_string(NULL, "hdd_fn", ide_fn[1]);
521 config_save();
522 }