PCem
view src/pc.c @ 169:b184d3ebfd41
Updated version number to v9.
Updated documentation for next release.
| author | TomW |
|---|---|
| date | Sat Oct 04 19:39:09 2014 +0100 |
| parents | d0d530adce12 |
| children |
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 "cdrom-null.h"
11 #include "config.h"
12 #include "cpu.h"
13 #include "dma.h"
14 #include "fdc.h"
15 #include "sound_gus.h"
16 #include "ide.h"
17 #include "keyboard.h"
18 #include "mem.h"
19 #include "model.h"
20 #include "mouse.h"
21 #include "nvr.h"
22 #include "pic.h"
23 #include "pit.h"
24 #include "plat-joystick.h"
25 #include "plat-mouse.h"
26 #include "serial.h"
27 #include "sound.h"
28 #include "sound_cms.h"
29 #include "sound_opl.h"
30 #include "sound_sb.h"
31 #include "sound_ssi2001.h"
32 #include "timer.h"
33 #include "vid_voodoo.h"
34 #include "video.h"
36 int frame = 0;
38 int cdrom_enabled;
39 int CPUID;
40 int vid_resize, vid_api;
42 int cycles_lost = 0;
44 int clockrate;
45 int insc=0;
46 float mips,flops;
47 extern int mmuflush;
48 extern int readlnum,writelnum;
49 void fullspeed();
51 int framecount,fps;
52 int intcount;
54 int output;
55 int atfullspeed;
57 void saveconfig();
58 int infocus;
59 int mousecapture;
60 FILE *pclogf;
61 void pclog(const char *format, ...)
62 {
63 #ifndef RELEASE_BUILD
64 char buf[1024];
65 //return;
66 if (!pclogf)
67 pclogf=fopen("pclog.txt","wt");
68 //return;
69 va_list ap;
70 va_start(ap, format);
71 vsprintf(buf, format, ap);
72 va_end(ap);
73 fputs(buf,pclogf);
74 //fflush(pclogf);
75 #endif
76 }
78 void fatal(const char *format, ...)
79 {
80 char buf[256];
81 // return;
82 if (!pclogf)
83 pclogf=fopen("pclog.txt","wt");
84 //return;
85 va_list ap;
86 va_start(ap, format);
87 vsprintf(buf, format, ap);
88 va_end(ap);
89 fputs(buf,pclogf);
90 fflush(pclogf);
91 dumppic();
92 dumpregs();
93 exit(-1);
94 }
96 uint8_t cgastat;
98 int pollmouse_delay = 2;
99 void pollmouse()
100 {
101 int x,y;
102 // return;
103 pollmouse_delay--;
104 if (pollmouse_delay) return;
105 pollmouse_delay = 2;
106 mouse_poll_host();
107 mouse_get_mickeys(&x,&y);
108 if (mouse_poll)
109 mouse_poll(x, y, mouse_buttons);
110 // if (mousecapture) position_mouse(64,64);
111 }
113 /*PC1512 languages -
114 7=English
115 6=German
116 5=French
117 4=Spanish
118 3=Danish
119 2=Swedish
120 1=Italian
121 3,2,1 all cause the self test to fail for some reason
122 */
124 int cpuspeed2;
126 int clocks[3][12][4]=
127 {
128 {
129 {4772728,13920,59660,5965}, /*4.77MHz*/
130 {8000000,23333,110000,0}, /*8MHz*/
131 {10000000,29166,137500,0}, /*10MHz*/
132 {12000000,35000,165000,0}, /*12MHz*/
133 {16000000,46666,220000,0}, /*16MHz*/
134 },
135 {
136 {8000000,23333,110000,0}, /*8MHz*/
137 {12000000,35000,165000,0}, /*12MHz*/
138 {16000000,46666,220000,0}, /*16MHz*/
139 {20000000,58333,275000,0}, /*20MHz*/
140 {25000000,72916,343751,0}, /*25MHz*/
141 },
142 {
143 {16000000, 46666,220000,0}, /*16MHz*/
144 {20000000, 58333,275000,0}, /*20MHz*/
145 {25000000, 72916,343751,0}, /*25MHz*/
146 {33000000, 96000,454000,0}, /*33MHz*/
147 {40000000,116666,550000,0}, /*40MHz*/
148 {50000000, 72916*2,343751*2,0}, /*50MHz*/
149 {33000000*2, 96000*2,454000*2,0}, /*66MHz*/
150 {75000000, 72916*3,343751*3,0}, /*75MHz*/
151 {80000000,116666*2,550000*2,0}, /*80MHz*/
152 {100000000, 72916*4,343751*4,0}, /*100MHz*/
153 {120000000,116666*3,550000*3,0}, /*120MHz*/
154 {133000000, 96000*4,454000*4,0}, /*133MHz*/
155 }
156 };
158 int updatestatus;
159 int win_title_update=0;
162 void onesec()
163 {
164 fps=framecount;
165 framecount=0;
166 win_title_update=1;
167 }
169 void pc_reset()
170 {
171 resetx86();
172 cpu_set();
173 //timer_reset();
174 dma_reset();
175 fdc_reset();
176 pic_reset();
177 pit_reset();
178 serial_reset();
180 setpitclock(models[model].cpu[cpu_manufacturer].cpus[cpu].rspeed);
182 // sb_reset();
184 ali1429_reset();
185 // video_init();
186 }
188 void initpc()
189 {
190 char *p;
191 // allegro_init();
192 get_executable_name(pcempath,511);
193 pclog("executable_name = %s\n", pcempath);
194 p=get_filename(pcempath);
195 *p=0;
196 pclog("path = %s\n", pcempath);
198 keyboard_init();
199 mouse_init();
200 joystick_init();
202 loadconfig(NULL);
203 pclog("Config loaded\n");
205 cpuspeed2=(AT)?2:1;
206 // cpuspeed2=cpuspeed;
207 atfullspeed=0;
209 device_init();
211 initvideo();
212 mem_init();
213 loadbios();
214 mem_add_bios();
216 loaddisc(0,discfns[0]);
217 loaddisc(1,discfns[1]);
219 timer_reset();
220 sound_reset();
221 fdc_init();
223 //loadfont();
224 loadnvr();
225 sound_init();
226 resetide();
227 #if __unix
228 if (cdrom_drive == -1)
229 cdrom_null_open(cdrom_drive);
230 else
231 #endif
232 ioctl_open(cdrom_drive);
233 model_init();
234 video_init();
235 speaker_init();
236 sound_card_init(sound_card_current);
237 if (GUS)
238 device_add(&gus_device);
239 if (GAMEBLASTER)
240 device_add(&cms_device);
241 if (SSI2001)
242 device_add(&ssi2001_device);
244 pc_reset();
246 pit_reset();
247 /* if (romset==ROM_AMI386 || romset==ROM_AMI486) */fullspeed();
248 mem_updatecache();
249 ali1429_reset();
250 // CPUID=(is486 && (cpuspeed==7 || cpuspeed>=9));
251 // pclog("Init - CPUID %i %i\n",CPUID,cpuspeed);
252 shadowbios=0;
253 voodoo_init();
255 #if __unix
256 if (cdrom_drive == -1)
257 cdrom_null_reset();
258 else
259 #endif
260 ioctl_reset();
261 }
263 void resetpc()
264 {
265 pc_reset();
266 // cpuspeed2=(AT)?2:1;
267 // atfullspeed=0;
268 ///* if (romset==ROM_AMI386 || romset==ROM_AMI486) */fullspeed();
269 shadowbios=0;
270 }
272 void resetpchard()
273 {
274 device_close_all();
275 device_init();
277 timer_reset();
278 sound_reset();
279 mem_resize();
280 fdc_init();
281 model_init();
282 video_init();
283 speaker_init();
284 sound_card_init(sound_card_current);
285 if (GUS)
286 device_add(&gus_device);
287 if (GAMEBLASTER)
288 device_add(&cms_device);
289 if (SSI2001)
290 device_add(&ssi2001_device);
292 pc_reset();
294 resetide();
296 loadnvr();
298 // cpuspeed2 = (AT)?2:1;
299 // atfullspeed = 0;
300 // setpitclock(models[model].cpu[cpu_manufacturer].cpus[cpu].rspeed);
302 shadowbios = 0;
303 ali1429_reset();
305 keyboard_at_reset();
307 // output=3;
309 #if __unix
310 if (cdrom_drive == -1)
311 cdrom_null_reset();
312 else
313 #endif
314 ioctl_reset();
315 }
317 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"};
318 char clockspeeds[3][12][16]=
319 {
320 {"4.77MHz","8MHz","10MHz","12MHz","16MHz"},
321 {"8MHz","12MHz","16MHz","20MHz","25MHz"},
322 {"16MHz","20MHz","25MHz","33MHz","40MHz","50MHz","66MHz","75MHz","80MHz","100MHz","120MHz","133MHz"},
323 };
324 int framecountx=0;
325 int sndcount=0;
326 int oldat70hz;
328 int sreadlnum,swritelnum,segareads,segawrites, scycles_lost;
330 int serial_fifo_read, serial_fifo_write;
332 int emu_fps = 0;
334 void runpc()
335 {
336 char s[200];
337 int done=0;
339 startblit();
340 clockrate = models[model].cpu[cpu_manufacturer].cpus[cpu].rspeed;
341 if (is386) exec386(models[model].cpu[cpu_manufacturer].cpus[cpu].rspeed / 100);
342 else if (AT) exec386(models[model].cpu[cpu_manufacturer].cpus[cpu].rspeed / 100);
343 else execx86(models[model].cpu[cpu_manufacturer].cpus[cpu].rspeed / 100);
344 keyboard_poll_host();
345 keyboard_process();
346 // checkkeys();
347 pollmouse();
348 joystick_poll();
349 endblit();
351 framecountx++;
352 framecount++;
353 if (framecountx>=100)
354 {
355 pclog("onesec\n");
356 framecountx=0;
357 mips=(float)insc/1000000.0f;
358 insc=0;
359 flops=(float)fpucount/1000000.0f;
360 fpucount=0;
361 sreadlnum=readlnum;
362 swritelnum=writelnum;
363 segareads=egareads;
364 segawrites=egawrites;
365 scycles_lost = cycles_lost;
366 updatestatus=1;
367 readlnum=writelnum=0;
368 egareads=egawrites=0;
369 cycles_lost = 0;
370 mmuflush=0;
371 intcount=0;
372 intcount=pitcount=0;
373 emu_fps = frames;
374 frames = 0;
375 }
376 if (win_title_update)
377 {
378 win_title_update=0;
379 sprintf(s, "PCem v9 - %i%% - %s - %s - %s", fps, model_getname(), models[model].cpu[cpu_manufacturer].cpus[cpu].name, (!mousecapture) ? "Click to capture mouse" : "Press CTRL-END or middle button to release mouse");
380 set_window_title(s);
381 }
382 done++;
383 frame++;
384 }
386 void fullspeed()
387 {
388 cpuspeed2=cpuspeed;
389 if (!atfullspeed)
390 {
391 printf("Set fullspeed - %i %i %i\n",is386,AT,cpuspeed2);
392 setpitclock(models[model].cpu[cpu_manufacturer].cpus[cpu].rspeed);
393 // if (is386) setpitclock(clocks[2][cpuspeed2][0]);
394 // else setpitclock(clocks[AT?1:0][cpuspeed2][0]);
395 }
396 atfullspeed=1;
397 nvr_recalc();
398 }
400 void speedchanged()
401 {
402 if (atfullspeed)
403 {
404 cpuspeed2=cpuspeed;
405 setpitclock(models[model].cpu[cpu_manufacturer].cpus[cpu].rspeed);
406 // if (is386) setpitclock(clocks[2][cpuspeed2][0]);
407 // else setpitclock(clocks[AT?1:0][cpuspeed2][0]);
408 }
409 mem_updatecache();
410 nvr_recalc();
411 }
413 void closepc()
414 {
415 atapi->exit();
416 // ioctl_close();
417 dumppic();
418 // output=7;
419 // setpitclock(clocks[0][0][0]);
420 // while (1) runpc();
421 savedisc(0);
422 savedisc(1);
423 dumpregs();
424 closevideo();
425 device_close_all();
426 }
428 /*int main()
429 {
430 initpc();
431 while (!key[KEY_F11])
432 {
433 runpc();
434 }
435 closepc();
436 return 0;
437 }
439 END_OF_MAIN();*/
441 int cga_comp=0;
443 void loadconfig(char *fn)
444 {
445 char s[512];
446 char *p;
448 if (!fn)
449 {
450 append_filename(config_file_default, pcempath, "pcem.cfg", 511);
452 config_load(config_file_default);
453 }
454 else
455 config_load(fn);
457 GAMEBLASTER = config_get_int(NULL, "gameblaster", 0);
458 GUS = config_get_int(NULL, "gus", 0);
459 SSI2001 = config_get_int(NULL, "ssi2001", 0);
461 model = config_get_int(NULL, "model", 14);
463 if (model >= model_count())
464 model = model_count() - 1;
466 romset = model_getromset();
467 cpu_manufacturer = config_get_int(NULL, "cpu_manufacturer", 0);
468 cpu = config_get_int(NULL, "cpu", 0);
470 gfxcard = config_get_int(NULL, "gfxcard", 0);
471 video_speed = config_get_int(NULL, "video_speed", 3);
472 sound_card_current = config_get_int(NULL, "sndcard", SB2);
474 p = (char *)config_get_string(NULL, "disc_a", "");
475 if (p) strcpy(discfns[0], p);
476 else strcpy(discfns[0], "");
478 p = (char *)config_get_string(NULL, "disc_b", "");
479 if (p) strcpy(discfns[1], p);
480 else strcpy(discfns[1], "");
482 mem_size = config_get_int(NULL, "mem_size", 4);
483 cdrom_drive = config_get_int(NULL, "cdrom_drive", 0);
484 cdrom_enabled = config_get_int(NULL, "cdrom_enabled", 0);
486 slowega = config_get_int(NULL, "slow_video", 1);
487 cache = config_get_int(NULL, "cache", 3);
488 cga_comp = config_get_int(NULL, "cga_composite", 0);
490 vid_resize = config_get_int(NULL, "vid_resize", 0);
491 vid_api = config_get_int(NULL, "vid_api", 0);
492 video_fullscreen_scale = config_get_int(NULL, "video_fullscreen_scale", 0);
493 video_fullscreen_first = config_get_int(NULL, "video_fullscreen_first", 1);
495 hdc[0].spt = config_get_int(NULL, "hdc_sectors", 0);
496 hdc[0].hpc = config_get_int(NULL, "hdc_heads", 0);
497 hdc[0].tracks = config_get_int(NULL, "hdc_cylinders", 0);
498 p = (char *)config_get_string(NULL, "hdc_fn", "");
499 if (p) strcpy(ide_fn[0], p);
500 else strcpy(ide_fn[0], "");
501 hdc[1].spt = config_get_int(NULL, "hdd_sectors", 0);
502 hdc[1].hpc = config_get_int(NULL, "hdd_heads", 0);
503 hdc[1].tracks = config_get_int(NULL, "hdd_cylinders", 0);
504 p = (char *)config_get_string(NULL, "hdd_fn", "");
505 if (p) strcpy(ide_fn[1], p);
506 else strcpy(ide_fn[1], "");
507 }
509 void saveconfig()
510 {
511 config_set_int(NULL, "gameblaster", GAMEBLASTER);
512 config_set_int(NULL, "gus", GUS);
513 config_set_int(NULL, "ssi2001", SSI2001);
515 config_set_int(NULL, "model", model);
516 config_set_int(NULL, "cpu_manufacturer", cpu_manufacturer);
517 config_set_int(NULL, "cpu", cpu);
519 config_set_int(NULL, "gfxcard", gfxcard);
520 config_set_int(NULL, "video_speed", video_speed);
521 config_set_int(NULL, "sndcard", sound_card_current);
522 config_set_int(NULL, "cpu_speed", cpuspeed);
523 config_set_int(NULL, "has_fpu", hasfpu);
524 config_set_int(NULL, "slow_video", slowega);
525 config_set_int(NULL, "cache", cache);
526 config_set_int(NULL, "cga_composite", cga_comp);
527 config_set_string(NULL, "disc_a", discfns[0]);
528 config_set_string(NULL, "disc_b", discfns[1]);
529 config_set_int(NULL, "mem_size", mem_size);
530 config_set_int(NULL, "cdrom_drive", cdrom_drive);
531 config_set_int(NULL, "cdrom_enabled", cdrom_enabled);
532 config_set_int(NULL, "vid_resize", vid_resize);
533 config_set_int(NULL, "vid_api", vid_api);
534 config_set_int(NULL, "video_fullscreen_scale", video_fullscreen_scale);
535 config_set_int(NULL, "video_fullscreen_first", video_fullscreen_first);
537 config_set_int(NULL, "hdc_sectors", hdc[0].spt);
538 config_set_int(NULL, "hdc_heads", hdc[0].hpc);
539 config_set_int(NULL, "hdc_cylinders", hdc[0].tracks);
540 config_set_string(NULL, "hdc_fn", ide_fn[0]);
541 config_set_int(NULL, "hdd_sectors", hdc[1].spt);
542 config_set_int(NULL, "hdd_heads", hdc[1].hpc);
543 config_set_int(NULL, "hdd_cylinders", hdc[1].tracks);
544 config_set_string(NULL, "hdd_fn", ide_fn[1]);
546 config_save(config_file_default);
547 }
