2 NEC PC-9801 Emulator 'ePC-9801'
3 NEC PC-9801E/F/M Emulator 'ePC-9801E'
4 NEC PC-9801U Emulator 'ePC-9801U'
5 NEC PC-9801VF Emulator 'ePC-9801VF'
6 NEC PC-9801VM Emulator 'ePC-9801VM'
7 NEC PC-9801VX Emulator 'ePC-9801VX'
8 NEC PC-9801RA Emulator 'ePC-9801RA'
9 NEC PC-98XA Emulator 'ePC-98XA'
10 NEC PC-98XL Emulator 'ePC-98XL'
11 NEC PC-98RL Emulator 'ePC-98RL'
12 NEC PC-98DO Emulator 'ePC-98DO'
14 Author : Takeda.Toshiya
21 #include "../../emu.h"
22 #include "../device.h"
25 #if defined(SUPPORT_OLD_BUZZER)
29 #if defined(USE_HARD_DISK)
30 #include "../harddisk.h"
37 #if defined(HAS_I386) || defined(HAS_I486)
39 #elif defined(HAS_I86) || defined(HAS_V30)
46 #include "../memory.h"
49 #if !defined(SUPPORT_OLD_BUZZER)
50 #include "../pcm1bit.h"
52 //#include "../pcpr201.h"
53 #include "../prnfile.h"
54 #if defined(SUPPORT_SASI_IF) || defined(SUPPORT_SCSI_IF)
55 #include "../scsi_hdd.h"
56 #include "../scsi_host.h"
58 #include "../tms3631.h"
59 #include "../upd1990a.h"
60 #include "../upd7220.h"
61 #include "../upd765a.h"
62 #include "../ym2203.h"
65 #include "../debugger.h"
68 #if defined(SUPPORT_24BIT_ADDRESS) || defined(SUPPORT_32BIT_ADDRESS)
79 #if defined(SUPPORT_SASI_IF)
81 #include "sasi_bios.h"
83 #if defined(SUPPORT_SCSI_IF)
86 #if defined(SUPPORT_IDE_IF)
90 #if defined(SUPPORT_CMT_IF)
93 #if defined(SUPPORT_24BIT_ADDRESS) || defined(SUPPORT_32BIT_ADDRESS)
96 using PC9801::DISPLAY;
99 using PC9801::FMSOUND;
100 using PC9801::JOYSTICK;
101 using PC9801::KEYBOARD;
102 using PC9801::MEMBUS;
104 #if defined(SUPPORT_SASI_IF)
108 #if defined(SUPPORT_SCSI_IF)
111 #if defined(SUPPORT_IDE_IF)
115 #if defined(SUPPORT_320KB_FDD_IF)
116 #include "../pc80s31k.h"
119 #if defined(SUPPORT_CMT_IF)
123 #if defined(_PC98DO) || defined(_PC98DOPLUS)
124 #include "../pc80s31k.h"
126 #include "../pc8801/pc88.h"
129 #if defined(_PC98DO) || defined(_PC98DOPLUS)
132 // ----------------------------------------------------------------------------
134 // ----------------------------------------------------------------------------
136 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
139 #if defined(_PC98DO) || defined(_PC98DOPLUS)
140 boot_mode = config.boot_mode;
142 int cpu_clocks = CPU_CLOCKS;
143 #if defined(PIT_CLOCK_8MHZ)
144 pit_clock_8mhz = true;
146 pit_clock_8mhz = false;
148 #if defined(_PC9801E)
149 if(config.cpu_type != 0) {
151 cpu_clocks = 4992030;
152 pit_clock_8mhz = false;
154 #elif defined(_PC9801VM) || defined(_PC98DO) || defined(_PC98DOPLUS) || defined(_PC9801VX) || defined(_PC98XL)
155 if(config.cpu_type != 0) {
156 // 10MHz/16MHz -> 8MHz
157 cpu_clocks = 7987248;
158 pit_clock_8mhz = true;
160 #elif defined(_PC9801RA) || defined(_PC98RL)
161 if(config.cpu_type != 0) {
163 cpu_clocks = 15974496;
164 pit_clock_8mhz = true;
167 int pit_clocks = pit_clock_8mhz ? 1996812 : 2457600;
169 sound_type = config.sound_type;
172 first_device = last_device = NULL;
173 dummy = new DEVICE(this, emu); // must be 1st device
174 event = new EVENT(this, emu); // must be 2nd device
176 #if defined(SUPPORT_OLD_BUZZER)
177 beep = new BEEP(this, emu);
179 beep = new PCM1BIT(this, emu);
181 dma = new I8237(this, emu);
182 #if defined(SUPPORT_CMT_IF)
183 sio_cmt = new I8251(this, emu); // for cmt
184 sio_cmt->set_device_name(_T("8251 SIO (CMT)"));
186 sio_rs = new I8251(this, emu); // for rs232c
187 sio_rs->set_device_name(_T("8251 SIO (RS-232C)"));
188 sio_kbd = new I8251(this, emu); // for keyboard
189 sio_kbd->set_device_name(_T("8251 SIO (Keyboard)"));
190 pit = new I8253(this, emu);
191 #if defined(SUPPORT_320KB_FDD_IF)
192 pio_fdd = new I8255(this, emu); // for 320kb fdd i/f
193 pio_fdd->set_device_name(_T("8255 PIO (320KB I/F)"));
195 pio_mouse = new I8255(this, emu); // for mouse
196 pio_mouse->set_device_name(_T("8255 PIO (Mouse)"));
197 pio_sys = new I8255(this, emu); // for system port
198 pio_sys->set_device_name(_T("8255 PIO (System)"));
199 pio_prn = new I8255(this, emu); // for printer
200 pio_prn->set_device_name(_T("8255 PIO (Printer)"));
201 pic = new I8259(this, emu);
202 #if defined(HAS_I386) || defined(HAS_I486)
203 cpu = new I386(this, emu); // 80386, 80486
204 #elif defined(HAS_I86) || defined(HAS_V30)
205 cpu = new I286(this, emu);// 8086, V30, 80286
207 cpu = new I286(this, emu);
210 cpu->set_device_name(_T("CPU(i8086)"));
211 #elif defined(HAS_I386)
212 cpu->set_device_name(_T("CPU(i386)"));
213 #elif defined(HAS_I486)
214 cpu->set_device_name(_T("CPU(i486)"));
215 #elif defined(HAS_PENTIUM)
216 cpu->set_device_name(_T("CPU(Pentium)"));
217 #elif defined(HAS_V33A)
218 cpu->set_device_name(_T("CPU(V33A)"));
219 #elif defined(HAS_V30)
220 cpu->set_device_name(_T("CPU(V30)"));
222 cpu->set_device_name(_T("CPU(i286)"));
224 io = new IO(this, emu);
225 rtcreg = new LS244(this, emu);
226 rtcreg->set_device_name(_T("74LS244 (RTC)"));
227 //memory = new MEMORY(this, emu);
228 memory = new MEMBUS(this, emu);
229 not_busy = new NOT(this, emu);
230 not_busy->set_device_name(_T("NOT Gate (Printer Busy)"));
231 #if defined(HAS_I86) || defined(HAS_V30)
232 not_prn = new NOT(this, emu);
233 not_prn->set_device_name(_T("NOT Gate (Printer IRQ)"));
235 rtc = new UPD1990A(this, emu);
236 #if defined(SUPPORT_2HD_FDD_IF)
237 fdc_2hd = new UPD765A(this, emu);
238 fdc_2hd->set_device_name(_T("uPD765A FDC (2HD I/F)"));
240 #if defined(SUPPORT_2DD_FDD_IF)
241 fdc_2dd = new UPD765A(this, emu);
242 fdc_2dd->set_device_name(_T("uPD765A FDC (2DD I/F)"));
244 #if defined(SUPPORT_2HD_2DD_FDD_IF)
245 fdc = new UPD765A(this, emu);
246 fdc->set_device_name(_T("uPD765A FDC (2HD/2DD I/F)"));
248 noise_seek = new NOISE(this, emu);
249 noise_head_down = new NOISE(this, emu);
250 noise_head_up = new NOISE(this, emu);
251 #if defined(SUPPORT_SASI_IF)
252 sasi_host = new SCSI_HOST(this, emu);
253 sasi_hdd = new SASI_HDD(this, emu);
254 sasi_hdd->set_device_name(_T("SASI Hard Disk Drive"));
255 sasi_hdd->scsi_id = 0;
256 sasi_hdd->bytes_per_sec = 625 * 1024; // 625KB/s
257 for(int i = 0; i < USE_HARD_DISK; i++) {
258 sasi_hdd->set_disk_handler(i, new HARDDISK(emu));
260 sasi_hdd->set_context_interface(sasi_host);
261 sasi_host->set_context_target(sasi_hdd);
263 #if defined(SUPPORT_SCSI_IF)
264 scsi_host = new SCSI_HOST(this, emu);
265 for(int i = 0; i < USE_HARD_DISK; i++) {
266 scsi_hdd[i] = new SCSI_HDD(this, emu);
267 scsi_hdd[i]->set_device_name(_T("SCSI Hard Disk Drive #%d"), i + 1);
268 scsi_hdd[i]->scsi_id = i;
269 scsi_hdd[i]->set_disk_handler(0, new HARDDISK(emu));
270 scsi_hdd[i]->set_context_interface(scsi_host);
271 scsi_host->set_context_target(scsi_hdd[i]);
274 gdc_chr = new UPD7220(this, emu);
275 gdc_chr->set_device_name(_T("uPD7220 GDC (Character)"));
276 gdc_gfx = new UPD7220(this, emu);
277 gdc_gfx->set_device_name(_T("uPD7220 GDC (Graphics)"));
279 if(sound_type == 0 || sound_type == 1) {
280 opn = new YM2203(this, emu);
281 #ifdef SUPPORT_PC98_OPNA
282 opn->set_device_name(_T("YM2608 OPNA (PC-9801-86)"));
283 opn->is_ym2608 = true;
285 opn->set_device_name(_T("YM2203 OPN (PC-9801-26)"));
286 opn->is_ym2608 = false;
288 fmsound = new FMSOUND(this, emu);
289 joystick = new JOYSTICK(this, emu);
290 } else if(sound_type == 2 || sound_type == 3) {
291 tms3631 = new TMS3631(this, emu);
292 tms3631->set_device_name(_T("TMS3631 SSG (PC-9801-14)"));
293 pit_14 = new I8253(this, emu);
294 pit_14->set_device_name(_T("8253 PIT (PC-9801-14)"));
295 pio_14 = new I8255(this, emu);
296 pio_14->set_device_name(_T("8255 PIO (PC-9801-14)"));
297 maskreg_14 = new LS244(this, emu);
298 maskreg_14->set_device_name(_T("74LS244 (PC-9801-14)"));
300 if(config.printer_type == 0) {
301 printer = new PRNFILE(this, emu);
302 // } else if(config.printer_type == 1) {
303 // printer = new PCPR201(this, emu);
308 #if defined(SUPPORT_CMT_IF)
309 cmt = new CMT(this, emu);
311 #if defined(SUPPORT_24BIT_ADDRESS) || defined(SUPPORT_32BIT_ADDRESS)
312 cpureg = new CPUREG(this, emu);
314 display = new DISPLAY(this, emu);
315 dmareg = new DMAREG(this, emu);
316 floppy = new FLOPPY(this, emu);
317 keyboard = new KEYBOARD(this, emu);
318 mouse = new MOUSE(this, emu);
319 #if defined(SUPPORT_SASI_IF)
320 sasi = new SASI(this, emu);
321 sasi_bios = new BIOS(this, emu);
323 #if defined(SUPPORT_SCSI_IF)
324 scsi = new SCSI(this, emu);
326 #if defined(SUPPORT_IDE_IF)
327 ide = new IDE(this, emu);
330 #if defined(SUPPORT_320KB_FDD_IF)
332 pio_sub = new I8255(this, emu);
333 pio_sub->set_device_name(_T("8255 PIO (320KB FDD)"));
334 pc80s31k = new PC80S31K(this, emu);
335 pc80s31k->set_device_name(_T("PC-80S31K (320KB FDD)"));
336 fdc_sub = new UPD765A(this, emu);
337 fdc_sub->set_device_name(_T("uPD765A FDC (320KB FDD)"));
338 cpu_sub = new Z80(this, emu);
339 cpu_sub->set_device_name(_T("Z80 CPU (320KB FDD)"));
351 9 (INT3) PC-9801-27 (SASI), PC-9801-55 (SCSI), or IDE
352 10 (INT41) FDC (640KB I/F)
353 11 (INT42) FDC (1MB I/F)
354 12 (INT5) PC-9801-26(K) or PC-9801-14
361 event->set_context_cpu(cpu, cpu_clocks);
362 #if defined(SUPPORT_320KB_FDD_IF)
363 event->set_context_cpu(cpu_sub, 4000000);
365 event->set_context_sound(beep);
366 if(sound_type == 0 || sound_type == 1) {
367 event->set_context_sound(opn);
368 } else if(sound_type == 2 || sound_type == 3) {
369 event->set_context_sound(tms3631);
371 event->set_context_sound(noise_seek);
372 event->set_context_sound(noise_head_down);
373 event->set_context_sound(noise_head_up);
375 dma->set_context_memory(memory);
377 // dma ch.1: memory refresh
378 #if defined(SUPPORT_2HD_FDD_IF)
379 dma->set_context_ch2(fdc_2hd);
380 dma->set_context_tc2(fdc_2hd, SIG_UPD765A_TC, 1);
382 #if defined(SUPPORT_2DD_FDD_IF)
383 dma->set_context_ch3(fdc_2dd);
384 dma->set_context_tc3(fdc_2dd, SIG_UPD765A_TC, 1);
386 #if defined(SUPPORT_2HD_2DD_FDD_IF)
387 #if !defined(SUPPORT_HIRESO)
388 dma->set_context_ch2(fdc);
389 dma->set_context_ch3(fdc);
390 dma->set_context_tc2(fdc, SIG_UPD765A_TC, 1);
391 dma->set_context_tc3(fdc, SIG_UPD765A_TC, 1);
393 dma->set_context_ch1(fdc);
394 dma->set_context_tc1(fdc, SIG_UPD765A_TC, 1);
397 // sio_rs->set_context_rxrdy(pic, SIG_I8259_CHIP0 | SIG_I8259_IR4, 1);
398 sio_kbd->set_context_rxrdy(pic, SIG_I8259_CHIP0 | SIG_I8259_IR1, 1);
399 pit->set_context_ch0(pic, SIG_I8259_CHIP0 | SIG_I8259_IR0, 1);
400 #if defined(SUPPORT_OLD_BUZZER)
401 // pit ch.1: memory refresh
404 pit->set_context_ch1(beep, SIG_PCM1BIT_SIGNAL, 1);
407 pit->set_constant_clock(0, pit_clocks);
408 pit->set_constant_clock(1, pit_clocks);
409 pit->set_constant_clock(2, pit_clocks);
410 pio_mouse->set_context_port_c(mouse, SIG_MOUSE_PORT_C, 0xf0, 0);
411 #if defined(SUPPORT_HIRESO)
412 // sysport port.c bit7,5: sysport port.b bit4,3
413 pio_sys->set_context_port_c(pio_sys, SIG_I8255_PORT_B, 0x80, -3); // SHUT0
414 pio_sys->set_context_port_c(pio_sys, SIG_I8255_PORT_B, 0x20, -2); // SHUT1
416 // sysport port.c bit6: printer strobe
417 #if defined(SUPPORT_OLD_BUZZER)
418 pio_sys->set_context_port_c(beep, SIG_BEEP_MUTE, 0x08, 0);
420 pio_sys->set_context_port_c(beep, SIG_PCM1BIT_MUTE, 0x08, 0);
422 // sysport port.c bit2: enable txrdy interrupt
423 // sysport port.c bit1: enable txempty interrupt
424 // sysport port.c bit0: enable rxrdy interrupt
425 pio_prn->set_context_port_a(printer, SIG_PRINTER_DATA, 0xff, 0);
426 pio_prn->set_context_port_c(printer, SIG_PRINTER_STROBE, 0x80, 0);
427 if(config.printer_type == 0) {
428 PRNFILE *prnfile = (PRNFILE *)printer;
429 prnfile->set_context_busy(not_busy, SIG_NOT_INPUT, 1);
430 // } else if(config.printer_type == 1) {
431 // PRNFILE *pcpr201 = (PCPR201 *)printer;
432 // pcpr201->set_context_busy(not_busy, SIG_NOT_INPUT, 1);
434 not_busy->set_context_out(pio_prn, SIG_I8255_PORT_B, 4);
435 #if defined(HAS_I86) || defined(HAS_V30)
436 pio_prn->set_context_port_c(not_prn, SIG_NOT_INPUT, 8, 0);
437 not_prn->set_context_out(pic, SIG_I8259_CHIP1 | SIG_I8259_IR0, 1);
439 rtcreg->set_context_output(rtc, SIG_UPD1990A_CMD, 0x07, 0);
440 rtcreg->set_context_output(rtc, SIG_UPD1990A_DIN, 0x20, 0);
441 rtcreg->set_context_output(rtc, SIG_UPD1990A_STB, 0x08, 0);
442 rtcreg->set_context_output(rtc, SIG_UPD1990A_CLK, 0x10, 0);
443 pic->set_context_cpu(cpu);
444 rtc->set_context_dout(pio_sys, SIG_I8255_PORT_B, 1);
446 if(sound_type == 0 || sound_type == 1) {
447 opn->set_context_irq(pic, SIG_I8259_CHIP1 | SIG_I8259_IR4, 1);
448 opn->set_context_port_b(joystick, SIG_JOYSTICK_SELECT, 0xc0, 0);
449 fmsound->set_context_opn(opn);
450 joystick->set_context_opn(opn);
451 } else if(sound_type == 2 || sound_type == 3) {
452 pio_14->set_context_port_a(tms3631, SIG_TMS3631_ENVELOP1, 0xff, 0);
453 pio_14->set_context_port_b(tms3631, SIG_TMS3631_ENVELOP2, 0xff, 0);
454 pio_14->set_context_port_c(tms3631, SIG_TMS3631_DATAREG, 0xff, 0);
455 maskreg_14->set_context_output(tms3631, SIG_TMS3631_MASKREG, 0xff, 0);
456 pit_14->set_constant_clock(2, 1996800 / 8);
457 pit_14->set_context_ch2(pic, SIG_I8259_CHIP1 | SIG_I8259_IR4, 1);
460 #if defined(SUPPORT_24BIT_ADDRESS) || defined(SUPPORT_32BIT_ADDRESS)
461 cpureg->set_context_cpu(cpu);
463 display->set_context_pic(pic);
464 display->set_context_gdc_chr(gdc_chr, gdc_chr->get_ra());
465 display->set_context_gdc_gfx(gdc_gfx, gdc_gfx->get_ra(), gdc_gfx->get_cs());
466 dmareg->set_context_dma(dma);
467 keyboard->set_context_sio(sio_kbd);
468 memory->set_context_display(display);
469 mouse->set_context_pic(pic);
470 mouse->set_context_pio(pio_mouse);
472 #if defined(SUPPORT_2HD_FDD_IF)
473 fdc_2hd->set_context_irq(floppy, SIG_FLOPPY_2HD_IRQ, 1);
474 fdc_2hd->set_context_drq(floppy, SIG_FLOPPY_2HD_DRQ, 1);
475 fdc_2hd->set_context_noise_seek(noise_seek);
476 fdc_2hd->set_context_noise_head_down(noise_head_down);
477 fdc_2hd->set_context_noise_head_up(noise_head_up);
478 fdc_2hd->raise_irq_when_media_changed = true;
479 floppy->set_context_fdc_2hd(fdc_2hd);
481 #if defined(SUPPORT_2DD_FDD_IF)
482 fdc_2dd->set_context_irq(floppy, SIG_FLOPPY_2DD_IRQ, 1);
483 fdc_2dd->set_context_drq(floppy, SIG_FLOPPY_2DD_DRQ, 1);
484 fdc_2dd->set_context_noise_seek(noise_seek);
485 fdc_2dd->set_context_noise_head_down(noise_head_down);
486 fdc_2dd->set_context_noise_head_up(noise_head_up);
487 fdc_2dd->raise_irq_when_media_changed = true;
488 floppy->set_context_fdc_2dd(fdc_2dd);
490 #if defined(SUPPORT_2HD_2DD_FDD_IF)
491 fdc->set_context_irq(floppy, SIG_FLOPPY_IRQ, 1);
492 fdc->set_context_drq(floppy, SIG_FLOPPY_DRQ, 1);
493 fdc->set_context_noise_seek(noise_seek);
494 fdc->set_context_noise_head_down(noise_head_down);
495 fdc->set_context_noise_head_up(noise_head_up);
496 fdc->raise_irq_when_media_changed = true;
497 floppy->set_context_fdc(fdc);
499 floppy->set_context_dma(dma);
500 floppy->set_context_pic(pic);
502 #if defined(SUPPORT_SASI_IF)
503 #if !defined(SUPPORT_HIRESO)
504 sasi_host->set_context_irq(pio_sys, SIG_I8255_PORT_B, 0x10);
506 sasi_host->set_context_irq(sasi, SIG_SASI_IRQ, 1);
507 sasi_host->set_context_drq(sasi, SIG_SASI_DRQ, 1);
509 dma->set_context_ch3(sasi_host);
510 dma->set_context_tc3(sasi, SIG_SASI_TC, 1);
512 dma->set_context_ch0(sasi_host);
513 dma->set_context_tc0(sasi, SIG_SASI_TC, 1);
515 sasi->set_context_host(sasi_host);
516 sasi->set_context_hdd(sasi_hdd);
517 sasi->set_context_dma(dma);
518 sasi->set_context_pic(pic);
520 sasi_bios->set_context_sasi(sasi);
521 sasi_bios->set_context_memory(memory);
522 sasi_bios->set_context_cpu(cpu);
523 sasi_bios->set_context_pic(pic);
524 cpu->set_context_bios(sasi_bios);
527 #if defined(SUPPORT_SCSI_IF)
528 dma->set_context_ch0(scsi);
529 scsi->set_context_dma(dma);
530 scsi->set_context_pic(pic);
532 #if defined(SUPPORT_IDE_IF)
533 dma->set_context_ch0(ide);
534 ide->set_context_dma(dma);
535 ide->set_context_pic(pic);
538 #if defined(SUPPORT_CMT_IF)
539 sio_cmt->set_context_out(cmt, SIG_CMT_OUT);
540 // sio_cmt->set_context_txrdy(cmt, SIG_CMT_TXRDY, 1);
541 // sio_cmt->set_context_rxrdy(cmt, SIG_CMT_RXRDY, 1);
542 // sio_cmt->set_context_txe(cmt, SIG_CMT_TXEMP, 1);
543 cmt->set_context_sio(sio_cmt);
547 cpu->set_context_mem(memory);
548 cpu->set_context_io(io);
549 cpu->set_context_intr(pic);
550 #ifdef SINGLE_MODE_DMA
551 cpu->set_context_dma(dma);
554 cpu->set_context_debugger(new DEBUGGER(this, emu));
557 #if defined(SUPPORT_320KB_FDD_IF)
559 pc80s31k->set_context_cpu(cpu_sub);
560 pc80s31k->set_context_fdc(fdc_sub);
561 pc80s31k->set_context_pio(pio_sub);
562 pio_fdd->set_context_port_a(pio_sub, SIG_I8255_PORT_A, 0xff, 0);
563 pio_fdd->set_context_port_b(pio_sub, SIG_I8255_PORT_A, 0xff, 0);
564 pio_fdd->set_context_port_c(pio_sub, SIG_I8255_PORT_C, 0x0f, 4);
565 pio_fdd->set_context_port_c(pio_sub, SIG_I8255_PORT_C, 0xf0, -4);
566 pio_fdd->clear_ports_by_cmdreg = true;
567 pio_sub->set_context_port_a(pio_fdd, SIG_I8255_PORT_B, 0xff, 0);
568 pio_sub->set_context_port_b(pio_fdd, SIG_I8255_PORT_A, 0xff, 0);
569 pio_sub->set_context_port_c(pio_fdd, SIG_I8255_PORT_C, 0x0f, 4);
570 pio_sub->set_context_port_c(pio_fdd, SIG_I8255_PORT_C, 0xf0, -4);
571 pio_sub->clear_ports_by_cmdreg = true;
572 fdc_sub->set_context_irq(cpu_sub, SIG_CPU_IRQ, 1);
573 fdc_sub->set_context_noise_seek(noise_seek);
574 fdc_sub->set_context_noise_head_down(noise_head_down);
575 fdc_sub->set_context_noise_head_up(noise_head_up);
576 cpu_sub->set_context_mem(pc80s31k);
577 cpu_sub->set_context_io(pc80s31k);
578 cpu_sub->set_context_intr(pc80s31k);
580 cpu_sub->set_context_debugger(new DEBUGGER(this, emu));
585 io->set_iomap_alias_rw(0x0000, pic, 0);
586 io->set_iomap_alias_rw(0x0002, pic, 1);
587 io->set_iomap_alias_rw(0x0008, pic, 2);
588 io->set_iomap_alias_rw(0x000a, pic, 3);
590 io->set_iomap_alias_rw(0x0001, dma, 0x00);
591 io->set_iomap_alias_rw(0x0003, dma, 0x01);
592 io->set_iomap_alias_rw(0x0005, dma, 0x02);
593 io->set_iomap_alias_rw(0x0007, dma, 0x03);
594 io->set_iomap_alias_rw(0x0009, dma, 0x04);
595 io->set_iomap_alias_rw(0x000b, dma, 0x05);
596 io->set_iomap_alias_rw(0x000d, dma, 0x06);
597 io->set_iomap_alias_rw(0x000f, dma, 0x07);
598 io->set_iomap_alias_rw(0x0011, dma, 0x08);
599 io->set_iomap_alias_w (0x0013, dma, 0x09);
600 io->set_iomap_alias_w (0x0015, dma, 0x0a);
601 io->set_iomap_alias_w (0x0017, dma, 0x0b);
602 io->set_iomap_alias_w (0x0019, dma, 0x0c);
603 io->set_iomap_alias_rw(0x001b, dma, 0x0d);
604 io->set_iomap_alias_w (0x001d, dma, 0x0e);
605 io->set_iomap_alias_w (0x001f, dma, 0x0f);
606 io->set_iomap_single_w(0x0021, dmareg);
607 io->set_iomap_single_w(0x0023, dmareg);
608 io->set_iomap_single_w(0x0025, dmareg);
609 io->set_iomap_single_w(0x0027, dmareg);
610 #if defined(SUPPORT_24BIT_ADDRESS) || defined(SUPPORT_32BIT_ADDRESS)
611 io->set_iomap_single_w(0x0029, dmareg);
613 #if defined(SUPPORT_32BIT_ADDRESS)
614 io->set_iomap_single_w(0x0e05, dmareg);
615 io->set_iomap_single_w(0x0e07, dmareg);
616 io->set_iomap_single_w(0x0e09, dmareg);
617 io->set_iomap_single_w(0x0e0b, dmareg);
620 io->set_iomap_single_w(0x0020, rtcreg);
622 io->set_iomap_alias_rw(0x0030, sio_rs, 0);
623 io->set_iomap_alias_rw(0x0032, sio_rs, 1);
625 io->set_iomap_alias_rw(0x0031, pio_sys, 0);
626 io->set_iomap_alias_rw(0x0033, pio_sys, 1);
627 io->set_iomap_alias_rw(0x0035, pio_sys, 2);
628 io->set_iomap_alias_w (0x0037, pio_sys, 3);
630 io->set_iomap_alias_rw(0x0040, pio_prn, 0);
631 io->set_iomap_alias_rw(0x0042, pio_prn, 1);
632 io->set_iomap_alias_rw(0x0044, pio_prn, 2);
633 io->set_iomap_alias_w (0x0046, pio_prn, 3);
635 io->set_iomap_alias_rw(0x0041, sio_kbd, 0);
636 io->set_iomap_alias_rw(0x0043, sio_kbd, 1);
638 #if defined(SUPPORT_24BIT_ADDRESS) || defined(SUPPORT_32BIT_ADDRESS)
639 io->set_iomap_single_w(0x0050, cpureg);
640 io->set_iomap_single_w(0x0052, cpureg);
643 #if defined(SUPPORT_320KB_FDD_IF)
644 io->set_iomap_alias_rw(0x0051, pio_fdd, 0);
645 io->set_iomap_alias_rw(0x0053, pio_fdd, 1);
646 io->set_iomap_alias_rw(0x0055, pio_fdd, 2);
647 io->set_iomap_alias_w (0x0057, pio_fdd, 3);
650 io->set_iomap_alias_rw(0x0060, gdc_chr, 0);
651 io->set_iomap_alias_rw(0x0062, gdc_chr, 1);
653 io->set_iomap_single_w(0x64, display);
654 io->set_iomap_single_w(0x68, display);
655 #if defined(SUPPORT_16_COLORS)
656 io->set_iomap_single_w(0x6a, display);
658 io->set_iomap_single_w(0x6c, display);
659 io->set_iomap_single_w(0x6e, display);
661 io->set_iomap_single_w(0x70, display);
662 io->set_iomap_single_w(0x72, display);
663 io->set_iomap_single_w(0x74, display);
664 io->set_iomap_single_w(0x76, display);
665 io->set_iomap_single_w(0x78, display);
666 io->set_iomap_single_w(0x7a, display);
667 #if defined(SUPPORT_GRCG)
668 #if !defined(SUPPORT_HIRESO)
669 io->set_iomap_single_w(0x007c, display);
670 io->set_iomap_single_w(0x007e, display);
672 io->set_iomap_single_w(0x00a4, display);
673 io->set_iomap_single_w(0x00a6, display);
677 #if defined(SUPPORT_SASI_IF)
678 io->set_iomap_single_rw(0x0080, sasi);
679 io->set_iomap_single_rw(0x0082, sasi);
681 #if defined(SUPPORT_SCSI_IF)
682 io->set_iomap_single_rw(0x0cc0, scsi);
683 io->set_iomap_single_rw(0x0cc2, scsi);
684 io->set_iomap_single_rw(0x0cc4, scsi);
686 #if defined(SUPPORT_IDE_IF)
687 io->set_iomap_single_rw(0x0640, ide);
688 io->set_iomap_single_rw(0x0642, ide);
689 io->set_iomap_single_rw(0x0644, ide);
690 io->set_iomap_single_rw(0x0646, ide);
691 io->set_iomap_single_rw(0x0648, ide);
692 io->set_iomap_single_rw(0x064a, ide);
693 io->set_iomap_single_rw(0x064c, ide);
694 io->set_iomap_single_rw(0x064e, ide);
695 io->set_iomap_single_rw(0x074c, ide);
696 io->set_iomap_single_rw(0x074e, ide);
699 io->set_iomap_alias_rw(0x00a0, gdc_gfx, 0);
700 io->set_iomap_alias_rw(0x00a2, gdc_gfx, 1);
702 #if defined(SUPPORT_2ND_VRAM) && !defined(SUPPORT_HIRESO)
703 io->set_iomap_single_rw(0x00a4, display);
704 io->set_iomap_single_rw(0x00a6, display);
706 io->set_iomap_single_rw(0xa8, display);
707 io->set_iomap_single_rw(0xaa, display);
708 io->set_iomap_single_rw(0xac, display);
709 io->set_iomap_single_rw(0xae, display);
711 // io->set_iomap_single_w(0xa1, display);
712 // io->set_iomap_single_w(0xa3, display);
713 // io->set_iomap_single_w(0xa5, display);
714 io->set_iomap_single_rw(0xa1, display);
715 io->set_iomap_single_rw(0xa3, display);
716 io->set_iomap_single_rw(0xa5, display);
717 io->set_iomap_single_rw(0xa9, display);
718 #if defined(SUPPORT_EGC)
719 io->set_iomap_range_rw(0x04a0, 0x04af, display);
722 io->set_iomap_alias_rw(0x0071, pit, 0);
723 io->set_iomap_alias_rw(0x0073, pit, 1);
724 io->set_iomap_alias_rw(0x0075, pit, 2);
725 io->set_iomap_alias_w (0x0077, pit, 3);
727 io->set_iomap_single_rw(0x0090, floppy);
728 io->set_iomap_single_rw(0x0092, floppy);
729 io->set_iomap_single_rw(0x0094, floppy);
730 io->set_iomap_single_rw(0x0096, floppy);
731 #if defined(SUPPORT_2HD_2DD_FDD_IF)
732 #if !defined(SUPPORT_HIRESO)
733 io->set_iomap_single_rw(0x00be, floppy);
735 //#if !defined(_PC98XA) && !defined(_PC98XL)
736 io->set_iomap_single_w (0x00be, floppy);
740 #if !defined(SUPPORT_HIRESO)
741 io->set_iomap_single_rw(0x00c8, floppy);
742 io->set_iomap_single_rw(0x00ca, floppy);
743 io->set_iomap_single_rw(0x00cc, floppy);
744 io->set_iomap_single_rw(0x00ce, floppy);
747 #if defined(SUPPORT_CMT_IF)
748 io->set_iomap_alias_rw(0x0091, sio_cmt, 0);
749 io->set_iomap_alias_rw(0x0093, sio_cmt, 1);
750 io->set_iomap_single_w(0x0095, cmt);
751 io->set_iomap_single_w(0x0097, cmt);
754 #if defined(SUPPORT_24BIT_ADDRESS) || defined(SUPPORT_32BIT_ADDRESS)
755 io->set_iomap_single_rw(0x00f0, cpureg);
756 io->set_iomap_single_rw(0x00f2, cpureg);
758 #if defined(SUPPORT_32BIT_ADDRESS)
759 io->set_iomap_single_rw(0x00f6, cpureg);
762 if(sound_type == 0 || sound_type == 1) {
763 io->set_iomap_single_rw(0x0188, fmsound);
764 io->set_iomap_single_rw(0x018a, fmsound);
765 #ifdef SUPPORT_PC98_OPNA
766 io->set_iomap_single_rw(0x018c, fmsound);
767 io->set_iomap_single_rw(0x018e, fmsound);
768 io->set_iomap_single_rw(0xa460, fmsound);
770 } else if(sound_type == 2 || sound_type == 3) {
771 io->set_iomap_alias_rw(0x0088, pio_14, 0);
772 io->set_iomap_alias_rw(0x008a, pio_14, 1);
773 io->set_iomap_alias_rw(0x008c, pio_14, 2);
774 io->set_iomap_alias_w(0x008e, pio_14, 3);
775 io->set_iovalue_single_r(0x008e, 0x08);
776 io->set_iomap_single_w(0x0188, maskreg_14);
777 io->set_iomap_single_w(0x018a, maskreg_14);
778 io->set_iomap_alias_rw(0x018c, pit_14, 2);
779 io->set_iomap_alias_w(0x018e, pit_14, 3);
780 // io->set_iovalue_single_r(0x018e, 0x00); // INT0
781 // io->set_iovalue_single_r(0x018e, 0x40); // INT41
782 io->set_iovalue_single_r(0x018e, 0x80); // INT5
783 // io->set_iovalue_single_r(0x018e, 0xc0); // INT6
786 //#if !defined(SUPPORT_HIRESO)
787 // io->set_iovalue_single_r(0x0431, 0x04); // bit2: 1 = Normal mode, 0 = Hireso mode
789 // io->set_iovalue_single_r(0x0431, 0x00);
791 #if defined(SUPPORT_ITF_ROM)
792 io->set_iomap_single_w(0x043d, memory);
794 #if !defined(SUPPORT_HIRESO)
795 io->set_iomap_single_w(0x043f, memory);
797 #if defined(SUPPORT_24BIT_ADDRESS) || defined(SUPPORT_32BIT_ADDRESS)
798 #if !defined(_PC98XA)
799 io->set_iomap_single_rw(0x0439, memory);
801 #if !defined(SUPPORT_HIRESO)
802 io->set_iomap_single_rw(0x0461, memory);
803 io->set_iomap_single_rw(0x0463, memory);
805 io->set_iomap_single_rw(0x0091, memory);
806 io->set_iomap_single_rw(0x0093, memory);
808 io->set_iomap_single_r(0x0567, memory);
810 #if defined(SUPPORT_32BIT_ADDRESS)
811 io->set_iomap_single_w(0x053d, memory);
814 #if !(defined(_PC9801) || defined(_PC9801E) || defined(SUPPORT_HIRESO))
815 io->set_iomap_alias_rw(0x3fd9, pit, 0);
816 io->set_iomap_alias_rw(0x3fdb, pit, 1);
817 io->set_iomap_alias_rw(0x3fdd, pit, 2);
818 io->set_iomap_alias_w (0x3fdf, pit, 3);
821 #if !defined(SUPPORT_HIRESO)
822 io->set_iomap_alias_rw(0x7fd9, pio_mouse, 0);
823 io->set_iomap_alias_rw(0x7fdb, pio_mouse, 1);
824 io->set_iomap_alias_rw(0x7fdd, pio_mouse, 2);
825 io->set_iomap_alias_w (0x7fdf, pio_mouse, 3);
826 io->set_iomap_single_rw(0xbfdb, mouse);
828 io->set_iomap_alias_rw(0x0061, pio_mouse, 0);
829 io->set_iomap_alias_rw(0x0063, pio_mouse, 1);
830 io->set_iomap_alias_rw(0x0065, pio_mouse, 2);
831 io->set_iomap_alias_rw(0x0067, pio_mouse, 3);
834 #if defined(_PC98DO) || defined(_PC98DOPLUS)
835 pc88event = new EVENT(this, emu);
836 pc88event->set_device_name(_T("Event Manager (PC-8801)"));
837 pc88event->set_frames_per_sec(60);
838 pc88event->set_lines_per_frame(260);
840 pc88 = new PC88(this, emu);
841 pc88->set_context_event_manager(pc88event);
842 pc88sio = new I8251(this, emu);
843 pc88sio->set_device_name(_T("8251 SIO (PC-8801)"));
844 pc88sio->set_context_event_manager(pc88event);
845 pc88pio = new I8255(this, emu);
846 pc88pio->set_device_name(_T("8255 PIO (PC-8801)"));
847 pc88pio->set_context_event_manager(pc88event);
848 pc88pcm = new PCM1BIT(this, emu);
849 pc88pcm->set_device_name(_T("1-Bit PCM Sound (PC-8801)"));
850 pc88pcm->set_context_event_manager(pc88event);
851 pc88rtc = new UPD1990A(this, emu);
852 pc88rtc->set_device_name(_T("uPD1990A RTC (PC-8801)"));
853 pc88rtc->set_context_event_manager(pc88event);
854 pc88opn1 = new YM2203(this, emu);
855 #ifdef SUPPORT_PC88_OPNA
856 pc88opn1->set_device_name(_T("YM2608 OPNA (PC-8801)"));
857 pc88opn1->is_ym2608 = true;
859 pc88opn1->set_device_name(_T("YM2203 OPN (PC-8801)"));
860 pc88opn1->is_ym2608 = false;
862 pc88opn1->set_context_event_manager(pc88event);
863 pc88cpu = new Z80(this, emu);
864 pc88cpu->set_device_name(_T("Z80 CPU (PC-8801)"));
865 pc88cpu->set_context_event_manager(pc88event);
867 if(config.printer_type == 0) {
868 pc88prn = new PRNFILE(this, emu);
869 pc88prn->set_context_event_manager(pc88event);
870 // } else if(config.printer_type == 1) {
871 // pc88prn = new PCPR201(this, emu);
872 // pc88prn->set_context_event_manager(pc88event);
877 pc88sub = new PC80S31K(this, emu);
878 pc88sub->set_device_name(_T("PC-80S31K (PC-8801 Sub)"));
879 pc88sub->set_context_event_manager(pc88event);
880 pc88pio_sub = new I8255(this, emu);
881 pc88pio_sub->set_device_name(_T("8255 PIO (PC-8801 Sub)"));
882 pc88pio_sub->set_context_event_manager(pc88event);
883 pc88fdc_sub = new UPD765A(this, emu);
884 pc88fdc_sub->set_device_name(_T("uPD765A FDC (PC-8801 Sub)"));
885 pc88fdc_sub->set_context_event_manager(pc88event);
886 pc88noise_seek = new NOISE(this, emu);
887 pc88noise_seek->set_context_event_manager(pc88event);
888 pc88noise_head_down = new NOISE(this, emu);
889 pc88noise_head_down->set_context_event_manager(pc88event);
890 pc88noise_head_up = new NOISE(this, emu);
891 pc88noise_head_up->set_context_event_manager(pc88event);
892 pc88cpu_sub = new Z80(this, emu);
893 pc88cpu_sub->set_device_name(_T("Z80 CPU (PC-8801 Sub)"));
894 pc88cpu_sub->set_context_event_manager(pc88event);
896 pc88event->set_context_cpu(pc88cpu, (config.cpu_type == 1) ? 3993624 : 7987248);
897 pc88event->set_context_cpu(pc88cpu_sub, 3993624);
898 pc88event->set_context_sound(pc88opn1);
899 pc88event->set_context_sound(pc88pcm);
900 pc88event->set_context_sound(pc88noise_seek);
901 pc88event->set_context_sound(pc88noise_head_down);
902 pc88event->set_context_sound(pc88noise_head_up);
904 pc88->set_context_cpu(pc88cpu);
905 pc88->set_context_opn1(pc88opn1);
906 pc88->set_context_pcm(pc88pcm);
907 pc88->set_context_pio(pc88pio);
908 pc88->set_context_prn(pc88prn);
909 pc88->set_context_rtc(pc88rtc);
910 pc88->set_context_sio(pc88sio);
911 pc88cpu->set_context_mem(pc88);
912 pc88cpu->set_context_io(pc88);
913 pc88cpu->set_context_intr(pc88);
915 pc88cpu->set_context_debugger(new DEBUGGER(this, emu));
917 pc88opn1->set_context_irq(pc88, SIG_PC88_OPN1_IRQ, 1);
918 pc88sio->set_context_rxrdy(pc88, SIG_PC88_USART_IRQ, 1);
919 pc88sio->set_context_out(pc88, SIG_PC88_USART_OUT);
921 pc88sub->set_context_cpu(pc88cpu_sub);
922 pc88sub->set_context_fdc(pc88fdc_sub);
923 pc88sub->set_context_pio(pc88pio_sub);
924 pc88pio->set_context_port_a(pc88pio_sub, SIG_I8255_PORT_B, 0xff, 0);
925 pc88pio->set_context_port_b(pc88pio_sub, SIG_I8255_PORT_A, 0xff, 0);
926 pc88pio->set_context_port_c(pc88pio_sub, SIG_I8255_PORT_C, 0x0f, 4);
927 pc88pio->set_context_port_c(pc88pio_sub, SIG_I8255_PORT_C, 0xf0, -4);
928 pc88pio->clear_ports_by_cmdreg = true;
929 pc88pio_sub->set_context_port_a(pc88pio, SIG_I8255_PORT_B, 0xff, 0);
930 pc88pio_sub->set_context_port_b(pc88pio, SIG_I8255_PORT_A, 0xff, 0);
931 pc88pio_sub->set_context_port_c(pc88pio, SIG_I8255_PORT_C, 0x0f, 4);
932 pc88pio_sub->set_context_port_c(pc88pio, SIG_I8255_PORT_C, 0xf0, -4);
933 pc88pio_sub->clear_ports_by_cmdreg = true;
934 pc88fdc_sub->set_context_irq(pc88cpu_sub, SIG_CPU_IRQ, 1);
935 pc88fdc_sub->set_context_noise_seek(pc88noise_seek);
936 pc88fdc_sub->set_context_noise_head_down(pc88noise_head_down);
937 pc88fdc_sub->set_context_noise_head_up(pc88noise_head_up);
938 pc88cpu_sub->set_context_mem(pc88sub);
939 pc88cpu_sub->set_context_io(pc88sub);
940 pc88cpu_sub->set_context_intr(pc88sub);
942 pc88cpu_sub->set_context_debugger(new DEBUGGER(this, emu));
946 // initialize all devices
947 #if defined(__GIT_REPO_VERSION)
948 strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
950 for(DEVICE* device = first_device; device; device = device->next_device) {
951 device->initialize();
954 #if defined(_PC9801) || defined(_PC9801E)
955 fdc_2hd->get_disk_handler(0)->drive_num = 0;
956 fdc_2hd->get_disk_handler(1)->drive_num = 1;
957 fdc_2dd->get_disk_handler(0)->drive_num = 2;
958 fdc_2dd->get_disk_handler(1)->drive_num = 3;
959 fdc_sub->get_disk_handler(0)->drive_num = 4;
960 fdc_sub->get_disk_handler(1)->drive_num = 5;
961 #elif defined(_PC9801VF) || defined(_PC9801U)
962 fdc_2dd->get_disk_handler(0)->drive_num = 0;
963 fdc_2dd->get_disk_handler(1)->drive_num = 1;
964 #elif defined(_PC98DO) || defined(_PC98DOPLUS)
965 fdc->get_disk_handler(0)->drive_num = 0;
966 fdc->get_disk_handler(1)->drive_num = 1;
967 pc88fdc_sub->get_disk_handler(0)->drive_num = 2;
968 pc88fdc_sub->get_disk_handler(1)->drive_num = 3;
970 fdc->get_disk_handler(0)->drive_num = 0;
971 fdc->get_disk_handler(1)->drive_num = 1;
973 #if defined(USE_HARD_DISK)
974 for(int drv = 0; drv < USE_HARD_DISK; drv++) {
975 if(!(config.last_hard_disk_path[drv][0] != _T('\0') && FILEIO::IsFileExisting(config.last_hard_disk_path[drv]))) {
976 #if defined(SUPPORT_SASI_IF)
977 create_local_path(config.last_hard_disk_path[drv], _MAX_PATH, _T("SASI%d.DAT"), drv);
979 #if defined(SUPPORT_SCSI_IF)
980 create_local_path(config.last_hard_disk_path[drv], _MAX_PATH, _T("SCSI%d.DAT"), drv);
982 #if defined(SUPPORT_IDE_IF)
983 create_local_path(config.last_hard_disk_path[drv], _MAX_PATH, _T("IDE%d.DAT"), drv);
992 // delete all devices
993 for(DEVICE* device = first_device; device;) {
994 DEVICE *next_device = device->next_device;
997 device = next_device;
1001 DEVICE* VM::get_device(int id)
1003 for(DEVICE* device = first_device; device; device = device->next_device) {
1004 if(device->this_device_id == id) {
1011 // ----------------------------------------------------------------------------
1012 // drive virtual machine
1013 // ----------------------------------------------------------------------------
1017 // reset all devices
1018 for(DEVICE* device = first_device; device; device = device->next_device) {
1021 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1022 for(DEVICE* device = first_device; device; device = device->next_device) {
1027 // initial device settings
1028 uint8_t port_a, port_b, port_c;
1030 port_a = 0xf0; // Clear mouse buttons and counters
1032 #if defined(_PC98XA)
1033 port_b |= (uint8_t)((RAM_SIZE - 0x100000) / 0x40000);
1035 #if defined(SUPPORT_HIRESO)
1036 port_b |= 0x80; // DIP SW 1-4, 1 = External FDD #3/#4, 0 = #1/#2
1038 port_b |= 0x40; // DIP SW 3-6, 1 = Enable internal RAM 80000h-9FFFFh
1039 #if defined(_PC98RL)
1040 port_b |= 0x10; // DIP SW 3-3, 1 = DMA ch.0 for SASI-HDD
1042 #if defined(USE_CPU_TYPE)
1043 if(config.cpu_type != 0) {
1044 #if !defined(SUPPORT_HIRESO)
1045 port_b |= 0x02; // SPDSW, 1 = 10MHz, 0 = 12MHz
1047 port_b |= 0x01; // SPDSW, 1 = 8/16MHz, 0 = 10/20MHz
1053 #if defined(SUPPORT_HIRESO)
1054 // port_c |= 0x08; // MODSW, 1 = Normal Mode, 0 = Hirezo Mode
1056 #if defined(HAS_V30) || defined(HAS_V33)
1057 port_c |= 0x04; // DIP SW 3-8, 1 = V30, 0 = 80x86
1059 pio_mouse->write_signal(SIG_I8255_PORT_A, port_a, 0xff);
1060 pio_mouse->write_signal(SIG_I8255_PORT_B, port_b, 0xff);
1061 pio_mouse->write_signal(SIG_I8255_PORT_C, port_c, 0xff);
1064 port_a |= 0x80; // DIP SW 2-8, 1 = GDC 2.5MHz, 0 = GDC 5MHz
1065 port_a |= 0x40; // DIP SW 2-7, 1 = Do not control FD motor
1066 port_a |= 0x20; // DIP SW 2-6, 1 = Enable internal HD
1067 // port_a |= 0x10; // DIP SW 2-5, 1 = Initialize emory switch
1068 // port_a |= 0x08; // DIP SW 2-4, 1 = 20 lines, 0 = 25 lines
1069 // port_a |= 0x04; // DIP SW 2-3, 1 = 40 columns, 0 = 80 columns
1070 port_a |= 0x02; // DIP SW 2-2, 1 = BASIC mode, 0 = Terminal mode
1071 port_a |= 0x01; // DIP SW 2-1, 1 = Normal mode, 0 = LT mode
1073 port_b |= 0x80; // RS-232C CI#, 1 = OFF
1074 port_b |= 0x40; // RS-232C CS#, 1 = OFF
1075 port_b |= 0x20; // RS-232C CD#, 1 = OFF
1076 #if !defined(SUPPORT_HIRESO)
1077 // port_b |= 0x10; // INT3, 1 = Active, 0 = Inactive
1078 port_b |= 0x08; // DIP SW 1-1, 1 = Hiresolution CRT, 0 = Standard CRT
1080 port_b |= 0x10; // SHUT0
1081 port_b |= 0x08; // SHUT1
1083 // port_b |= 0x04; // IMCK, 1 = Parity error occurs in internal RAM
1084 // port_b |= 0x02; // EMCK, 1 = Parity error occurs in external RAM
1085 // port_b |= 0x01; // CDAT
1087 port_c |= 0x80; // SHUT0
1088 port_c |= 0x40; // PSTBM, 1 = Mask printer's PSTB#
1089 port_c |= 0x20; // SHUT1
1090 port_c |= 0x10; // MCHKEN, 1 = Enable parity check for RAM
1091 port_c |= 0x08; // BUZ, 1 = Stop buzzer
1092 port_c |= 0x04; // TXRE, 1 = Enable IRQ from RS-232C 8251A TXRDY
1093 port_c |= 0x02; // TXEE, 1 = Enable IRQ from RS-232C 8251A TXEMPTY
1094 port_c |= 0x01; // RXRE, 1 = Enable IRQ from RS-232C 8251A RXRDY
1095 pio_sys->write_signal(SIG_I8255_PORT_A, port_a, 0xff);
1096 pio_sys->write_signal(SIG_I8255_PORT_B, port_b, 0xff);
1097 pio_sys->write_signal(SIG_I8255_PORT_C, port_c, 0xff);
1100 #if defined(_PC9801)
1101 // port_b |= 0x80; // TYP1, 0 = PC-9801 (first)
1102 // port_b |= 0x40; // TYP0, 0
1103 #elif defined(_PC9801U)
1104 port_b |= 0x80; // TYP1, 1 = PC-9801U
1105 port_b |= 0x40; // TYP0, 1
1107 port_b |= 0x80; // TYP1, 1 = Other PC-9801 series
1108 // port_b |= 0x40; // TYP0, 0
1110 if(pit_clock_8mhz) {
1111 port_b |= 0x20; // MOD, 1 = System clock 8MHz, 0 = 5/10MHz
1113 port_b |= 0x10; // DIP SW 1-3, 1 = Don't use LCD
1114 #if !defined(SUPPORT_16_COLORS)
1115 port_b |= 0x08; // DIP SW 1-8, 1 = Standard graphic mode, 0 = Enhanced graphic mode
1117 port_b |= 0x04; // Printer BUSY#, 1 = Inactive, 0 = Active (BUSY)
1118 #if defined(HAS_V30) || defined(HAS_V33)
1119 port_b |= 0x02; // CPUT, 1 = V30/V33, 0 = 80x86
1121 #if defined(_PC9801VF) || defined(_PC9801U)
1122 port_b |= 0x01; // VF, 1 = PC-9801VF/U
1124 pio_prn->write_signal(SIG_I8255_PORT_B, port_b, 0xff);
1126 #if defined(SUPPORT_320KB_FDD_IF)
1127 pio_fdd->write_signal(SIG_I8255_PORT_A, 0xff, 0xff);
1128 pio_fdd->write_signal(SIG_I8255_PORT_B, 0xff, 0xff);
1129 pio_fdd->write_signal(SIG_I8255_PORT_C, 0xff, 0xff);
1131 #if defined(SUPPORT_2DD_FDD_IF)
1132 fdc_2dd->write_signal(SIG_UPD765A_FREADY, 1, 1); // 2DD FDC RDY is pulluped
1135 if(sound_type == 0 || sound_type == 1) {
1136 // opn->write_signal(SIG_YM2203_PORT_A, 0x3f, 0xff); // PC-9801-26(K) INT0
1137 // opn->write_signal(SIG_YM2203_PORT_A, 0xbf, 0xff); // PC-9801-26(K) INT41
1138 opn->write_signal(SIG_YM2203_PORT_A, 0xff, 0xff); // PC-9801-26(K) INT5
1139 // opn->write_signal(SIG_YM2203_PORT_A, 0x7f, 0xff); // PC-9801-26(K) INT6
1142 #if defined(SUPPORT_OLD_BUZZER)
1143 beep->write_signal(SIG_BEEP_ON, 1, 1);
1144 beep->write_signal(SIG_BEEP_MUTE, 1, 1);
1146 beep->write_signal(SIG_PCM1BIT_ON, 1, 1);
1147 beep->write_signal(SIG_PCM1BIT_MUTE, 1, 1);
1150 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1151 pc88opn1->set_reg(0x29, 3); // for Misty Blue
1152 pc88pio->write_signal(SIG_I8255_PORT_C, 0, 0xff);
1153 pc88pio_sub->write_signal(SIG_I8255_PORT_C, 0, 0xff);
1159 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1160 if(boot_mode != 0) {
1167 double VM::get_frame_rate()
1169 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1170 if(config.boot_mode != 0) {
1171 return pc88event->get_frame_rate();
1174 return event->get_frame_rate();
1177 // ----------------------------------------------------------------------------
1179 // ----------------------------------------------------------------------------
1182 DEVICE *VM::get_cpu(int index)
1184 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1185 if(index == 0 && boot_mode == 0) {
1187 } else if(index == 1 && boot_mode != 0) {
1189 } else if(index == 2 && boot_mode != 0) {
1195 #if defined(SUPPORT_320KB_FDD_IF)
1196 } else if(index == 1) {
1205 // ----------------------------------------------------------------------------
1207 // ----------------------------------------------------------------------------
1209 void VM::draw_screen()
1211 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1212 if(boot_mode != 0) {
1213 pc88->draw_screen();
1216 display->draw_screen();
1219 // ----------------------------------------------------------------------------
1221 // ----------------------------------------------------------------------------
1223 void VM::initialize_sound(int rate, int samples)
1225 // init sound manager
1226 event->initialize_sound(rate, samples);
1229 #if defined(SUPPORT_OLD_BUZZER)
1230 beep->initialize_sound(rate, 2400, 8000);
1232 beep->initialize_sound(rate, 8000);
1234 if(sound_type == 0 || sound_type == 1) {
1235 if(opn->is_ym2608) {
1236 opn->initialize_sound(rate, 7987248, samples, 0, 0);
1238 opn->initialize_sound(rate, 3993624, samples, 0, 0);
1240 } else if(sound_type == 2 || sound_type == 3) {
1241 tms3631->initialize_sound(rate, 8000);
1244 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1245 // init sound manager
1246 pc88event->initialize_sound(rate, samples);
1249 if(pc88opn1->is_ym2608) {
1250 pc88opn1->initialize_sound(rate, 7987248, samples, 0, 0);
1252 pc88opn1->initialize_sound(rate, 3993624, samples, 0, 0);
1254 pc88pcm->initialize_sound(rate, 8000);
1258 uint16_t* VM::create_sound(int* extra_frames)
1260 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1261 if(boot_mode != 0) {
1262 return pc88event->create_sound(extra_frames);
1265 return event->create_sound(extra_frames);
1268 int VM::get_sound_buffer_ptr()
1270 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1271 if(boot_mode != 0) {
1272 return pc88event->get_sound_buffer_ptr();
1275 return event->get_sound_buffer_ptr();
1278 #ifdef USE_SOUND_VOLUME
1279 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
1282 if(sound_type == 0 || sound_type == 1) {
1283 opn->set_volume(0, decibel_l, decibel_r);
1285 } else if(ch-- == 0) {
1286 if(sound_type == 0 || sound_type == 1) {
1287 opn->set_volume(1, decibel_l, decibel_r);
1289 #if defined(SUPPORT_PC98_OPNA)
1290 } else if(ch-- == 0) {
1291 if(sound_type == 0 || sound_type == 1) {
1292 opn->set_volume(2, decibel_l, decibel_r);
1294 } else if(ch-- == 0) {
1295 if(sound_type == 0 || sound_type == 1) {
1296 opn->set_volume(3, decibel_l, decibel_r);
1299 } else if(ch-- == 0) {
1300 if(sound_type == 2 || sound_type == 3) {
1301 tms3631->set_volume(0, decibel_l, decibel_r);
1303 } else if(ch-- == 0) {
1304 beep->set_volume(0, decibel_l, decibel_r);
1305 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1306 } else if(ch-- == 0) {
1307 pc88opn1->set_volume(0, decibel_l, decibel_r);
1308 } else if(ch-- == 0) {
1309 pc88opn1->set_volume(1, decibel_l, decibel_r);
1310 #if defined(SUPPORT_PC88_OPNA)
1311 } else if(ch-- == 0) {
1312 pc88opn1->set_volume(2, decibel_l, decibel_r);
1313 } else if(ch-- == 0) {
1314 pc88opn1->set_volume(3, decibel_l, decibel_r);
1316 } else if(ch-- == 0) {
1317 pc88pcm->set_volume(0, decibel_l, decibel_r);
1319 } else if(ch-- == 0) {
1320 noise_seek->set_volume(0, decibel_l, decibel_r);
1321 noise_head_down->set_volume(0, decibel_l, decibel_r);
1322 noise_head_up->set_volume(0, decibel_l, decibel_r);
1323 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1324 pc88noise_seek->set_volume(0, decibel_l, decibel_r);
1325 pc88noise_head_down->set_volume(0, decibel_l, decibel_r);
1326 pc88noise_head_up->set_volume(0, decibel_l, decibel_r);
1332 // ----------------------------------------------------------------------------
1334 // ----------------------------------------------------------------------------
1336 void VM::key_down(int code, bool repeat)
1338 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1339 if(boot_mode != 0) {
1340 pc88->key_down(code, repeat);
1343 keyboard->key_down(code, repeat);
1346 void VM::key_up(int code)
1348 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1349 if(boot_mode != 0) {
1350 // pc88->key_up(code);
1353 keyboard->key_up(code);
1356 bool VM::get_caps_locked()
1358 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1359 if(boot_mode != 0) {
1360 return pc88->get_caps_locked();
1363 return keyboard->get_caps_locked();
1366 bool VM::get_kana_locked()
1368 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1369 if(boot_mode != 0) {
1370 return pc88->get_kana_locked();
1373 return keyboard->get_kana_locked();
1376 // ----------------------------------------------------------------------------
1378 // ----------------------------------------------------------------------------
1380 void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
1382 UPD765A *controller = get_floppy_disk_controller(drv);
1384 if(controller != NULL) {
1385 controller->open_disk(drv & 1, file_path, bank);
1389 void VM::close_floppy_disk(int drv)
1391 UPD765A *controller = get_floppy_disk_controller(drv);
1393 if(controller != NULL) {
1394 controller->close_disk(drv & 1);
1398 bool VM::is_floppy_disk_inserted(int drv)
1400 DISK *handler = get_floppy_disk_handler(drv);
1402 if(handler != NULL) {
1403 return handler->inserted;
1408 void VM::is_floppy_disk_protected(int drv, bool value)
1410 DISK *handler = get_floppy_disk_handler(drv);
1412 if(handler != NULL) {
1413 handler->write_protected = value;
1417 bool VM::is_floppy_disk_protected(int drv)
1419 DISK *handler = get_floppy_disk_handler(drv);
1421 if(handler != NULL) {
1422 return handler->write_protected;
1427 uint32_t VM::is_floppy_disk_accessed()
1429 uint32_t status = 0;
1431 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1432 if(boot_mode != 0) {
1433 status = pc88fdc_sub->read_signal(0) & 3;
1435 status = fdc->read_signal(0) & 3;
1438 for(int drv = 0; drv < USE_FLOPPY_DISK; drv += 2) {
1439 UPD765A *controller = get_floppy_disk_controller(drv);
1441 if(controller != NULL) {
1442 status |= (controller->read_signal(0) & 3) << drv;
1449 UPD765A *VM::get_floppy_disk_controller(int drv)
1451 #if defined(_PC9801) || defined(_PC9801E)
1452 if(drv == 0 || drv == 1) {
1454 } else if(drv == 2 || drv == 3) {
1456 } else if(drv == 4 || drv == 5) {
1459 #elif defined(_PC9801VF) || defined(_PC9801U)
1460 if(drv == 0 || drv == 1) {
1463 #elif defined(_PC98DO) || defined(_PC98DOPLUS)
1464 if(drv == 0 || drv == 1) {
1466 } else if(drv == 2 || drv == 3) {
1470 if(drv == 0 || drv == 1) {
1477 DISK *VM::get_floppy_disk_handler(int drv)
1479 UPD765A *controller = get_floppy_disk_controller(drv);
1481 if(controller != NULL) {
1482 return controller->get_disk_handler(drv & 1);
1487 #if defined(USE_HARD_DISK)
1488 void VM::open_hard_disk(int drv, const _TCHAR* file_path)
1490 if(drv < USE_HARD_DISK) {
1491 #if defined(SUPPORT_SASI_IF)
1492 sasi_hdd->open(drv, file_path, 256);
1494 #if defined(SUPPORT_SCSI_IF)
1495 scsi_hdd[drv]->open(0, file_path, 512);
1497 #if defined(SUPPORT_IDE_IF)
1498 ide_hdd[drv]->open(0, file_path, 512);
1503 void VM::close_hard_disk(int drv)
1505 if(drv < USE_HARD_DISK) {
1506 #if defined(SUPPORT_SASI_IF)
1507 sasi_hdd->close(drv);
1509 #if defined(SUPPORT_SCSI_IF)
1510 scsi_hdd[drv]->close(0);
1512 #if defined(SUPPORT_IDE_IF)
1513 ide_hdd[drv]->close(0);
1518 bool VM::is_hard_disk_inserted(int drv)
1520 if(drv < USE_HARD_DISK) {
1521 #if defined(SUPPORT_SASI_IF)
1522 return sasi_hdd->mounted(drv);
1524 #if defined(SUPPORT_SCSI_IF)
1525 return scsi_hdd[drv]->mounted(0);
1527 #if defined(SUPPORT_IDE_IF)
1528 return ide_hdd[drv]->mounted(0);
1534 uint32_t VM::is_hard_disk_accessed()
1536 uint32_t status = 0;
1538 for(int drv = 0; drv < USE_HARD_DISK; drv++) {
1539 #if defined(SUPPORT_SASI_IF)
1540 if(sasi_hdd->accessed(drv)) {
1544 #if defined(SUPPORT_SCSI_IF)
1545 if(scsi_hdd[drv]->accessed(0)) {
1549 #if defined(SUPPORT_IDE_IF)
1550 if(ide_hdd[drv]->accessed(0)) {
1559 #if defined(USE_TAPE)
1560 void VM::play_tape(int drv, const _TCHAR* file_path)
1562 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1563 pc88->play_tape(file_path);
1565 cmt->play_tape(file_path);
1569 void VM::rec_tape(int drv, const _TCHAR* file_path)
1571 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1572 pc88->rec_tape(file_path);
1574 cmt->rec_tape(file_path);
1578 void VM::close_tape(int drv)
1580 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1587 bool VM::is_tape_inserted(int drv)
1589 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1590 return pc88->is_tape_inserted();
1592 return cmt->is_tape_inserted();
1597 bool VM::is_frame_skippable()
1599 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1600 if(boot_mode != 0) {
1601 // return pc88event->is_frame_skippable();
1602 return pc88->is_frame_skippable();
1605 return event->is_frame_skippable();
1608 void VM::update_config()
1610 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1611 if(boot_mode != config.boot_mode) {
1612 // boot mode is changed !!!
1613 boot_mode = config.boot_mode;
1617 for(DEVICE* device = first_device; device; device = device->next_device) {
1618 device->update_config();
1622 #define STATE_VERSION 14
1624 bool VM::process_state(FILEIO* state_fio, bool loading)
1626 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
1629 for(DEVICE* device = first_device; device; device = device->next_device) {
1630 // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
1631 // const char *name = typeid(*device).name();
1632 // But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
1633 const char *name = device->get_device_name();
1634 int len = strlen(name);
1635 if(!state_fio->StateCheckInt32(len)) {
1637 printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
1641 if(!state_fio->StateCheckBuffer(name, len, 1)) {
1643 printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
1647 if(!device->process_state(state_fio, loading)) {
1649 printf("Data loading Error: DEVID=%d\n", device->this_device_id);
1654 state_fio->StateValue(pit_clock_8mhz);
1655 #if defined(_PC98DO) || defined(_PC98DOPLUS)
1656 state_fio->StateValue(boot_mode);
1658 state_fio->StateValue(sound_type);