OSDN Git Service

d51aa0449b4c3058bc93f077eb07ddc00602391e
[csp-qt/common_source_project-fm7.git] / source / src / vm / mz700 / mz700.cpp
1 /*
2         SHARP MZ-700 Emulator 'EmuZ-700'
3         SHARP MZ-800 Emulator 'EmuZ-800'
4         SHARP MZ-1500 Emulator 'EmuZ-1500'
5
6         Author : Takeda.Toshiya
7         Date   : 2008.06.05 -
8
9         [ virtual machine ]
10 */
11
12 #include "mz700.h"
13 #include "../../emu.h"
14 #include "../device.h"
15 #include "../event.h"
16
17 #include "../and.h"
18 #include "../datarec.h"
19 #include "../i8253.h"
20 #include "../i8255.h"
21 #include "../io.h"
22 #include "../noise.h"
23 #include "../pcm1bit.h"
24 #include "../z80.h"
25
26 #ifdef USE_DEBUGGER
27 #include "../debugger.h"
28 #endif
29
30 //#include "cmos.h"
31 #include "emm.h"
32 #include "kanji.h"
33 #include "keyboard.h"
34 #include "memory.h"
35 #include "ramfile.h"
36
37 #if defined(_MZ800) || defined(_MZ1500)
38 #include "../disk.h"
39 #include "../mb8877.h"
40 #include "../not.h"
41 #include "../sn76489an.h"
42 #include "../z80pio.h"
43 #include "../z80sio.h"
44 #include "floppy.h"
45 #if defined(_MZ1500)
46 #include "../mz1p17.h"
47 #include "../prnfile.h"
48 #include "psg.h"
49 #endif
50 #include "quickdisk.h"
51 #endif
52
53 // ----------------------------------------------------------------------------
54 // initialize
55 // ----------------------------------------------------------------------------
56
57 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
58 {
59 #if defined(_MZ800)
60         boot_mode = config.boot_mode;
61 #endif
62         
63         // create devices
64         first_device = last_device = NULL;
65         dummy = new DEVICE(this, emu);  // must be 1st device
66         event = new EVENT(this, emu);   // must be 2nd device
67
68         dummy->set_device_name(_T("1st Dummy"));
69
70         and_int = new AND(this, emu);
71         and_int->set_device_name(_T("AND Gate (IRQ)"));
72    
73         drec = new DATAREC(this, emu);
74         drec->set_context_noise_play(new NOISE(this, emu));
75         drec->set_context_noise_stop(new NOISE(this, emu));
76         drec->set_context_noise_fast(new NOISE(this, emu));
77         pit = new I8253(this, emu);
78         pio = new I8255(this, emu);
79         io = new IO(this, emu);
80         pcm = new PCM1BIT(this, emu);
81         cpu = new Z80(this, emu);
82
83 //      cmos = new CMOS(this, emu);
84         emm = new EMM(this, emu);
85         kanji = new KANJI(this, emu);
86         keyboard = new KEYBOARD(this, emu);
87         memory = new MEMORY(this, emu);
88         ramfile = new RAMFILE(this, emu);
89
90 #if defined(_MZ800) || defined(_MZ1500)
91         and_snd = new AND(this, emu);
92         and_snd->set_device_name(_T("AND Gate (Sound)"));
93         fdc = new MB8877(this, emu);    // mb8876
94         fdc->set_context_noise_seek(new NOISE(this, emu));
95         fdc->set_context_noise_head_down(new NOISE(this, emu));
96         fdc->set_context_noise_head_up(new NOISE(this, emu));
97 #if defined(_MZ800)
98         not_pit = new NOT(this, emu);
99         not_pit->set_device_name(_T("NOT Gate (PIT)"));
100         psg = new SN76489AN(this, emu);
101 #elif defined(_MZ1500)
102         if(config.printer_type == 0) {
103                 printer = new PRNFILE(this, emu);
104         } else if(config.printer_type == 1) {
105                 printer = new MZ1P17(this, emu);
106         } else {
107                 printer = dummy;
108         }
109         not_reset = new NOT(this, emu);
110         not_reset->set_device_name(_T("NOT Gate (Reset)"));
111         not_strobe = new NOT(this, emu);
112         not_strobe->set_device_name(_T("NOT Gate (Prinet Strobe)"));
113         psg_l = new SN76489AN(this, emu);
114         psg_l->set_device_name(_T("SN76489AN PSG (Left)"));
115         psg_r = new SN76489AN(this, emu);
116         psg_r->set_device_name(_T("SN76489AN PSG (Right)"));
117 #endif
118         pio_int = new Z80PIO(this, emu);
119         pio_int->set_device_name(_T("Z80 PIO(Interrupt)"));
120         sio_rs = new Z80SIO(this, emu);
121         sio_rs->set_device_name(_T("Z80 SIO(RS-232C)"));
122         sio_qd = new Z80SIO(this, emu);
123         sio_qd->set_device_name(_T("Z80 SIO(Quick Disk)"));
124         
125         floppy = new FLOPPY(this, emu);
126 #if defined(_MZ1500)
127         psg = new PSG(this, emu);
128 #endif
129         qd = new QUICKDISK(this, emu);
130 #endif
131         
132         // set contexts
133         event->set_context_cpu(cpu);
134         event->set_context_sound(pcm);
135 #if defined(_MZ800)
136         event->set_context_sound(psg);
137 #elif defined(_MZ1500)
138         event->set_context_sound(psg_l);
139         event->set_context_sound(psg_r);
140 #endif
141         event->set_context_sound(drec);
142 #if defined(_MZ800) || defined(_MZ1500)
143         event->set_context_sound(fdc->get_context_noise_seek());
144         event->set_context_sound(fdc->get_context_noise_head_down());
145         event->set_context_sound(fdc->get_context_noise_head_up());
146 #endif
147         event->set_context_sound(drec->get_context_noise_play());
148         event->set_context_sound(drec->get_context_noise_stop());
149         event->set_context_sound(drec->get_context_noise_fast());
150         
151         // VRAM/PCG wait
152         memory->set_context_cpu(cpu);
153         
154         // memory mapped I/O
155         memory->set_context_pio(pio);
156         memory->set_context_pit(pit);
157         
158 #if defined(_MZ1500)
159         // psg mixer
160         psg->set_context_psg_l(psg_l);
161         psg->set_context_psg_r(psg_r);
162 #endif
163         
164 #if defined(_MZ800)
165         // 8253:CLK#0 <- 1.10MHz
166         pit->set_constant_clock(0, 1100000);
167 #else
168         // 8253:CLK#0 <- 895KHz
169         pit->set_constant_clock(0, CPU_CLOCKS / 4);
170 #endif
171         
172 #if defined(_MZ800) || defined(_MZ1500)
173         // 8253:OUT#0 AND 8255:PC0 -> SPEAKER
174         pit->set_context_ch0(and_snd, SIG_AND_BIT_0, 1);
175         pio->set_context_port_c(and_snd, SIG_AND_BIT_1, 1, 0);
176         and_snd->set_context_out(pcm, SIG_PCM1BIT_SIGNAL, 1);
177         and_snd->set_mask(SIG_AND_BIT_0 | SIG_AND_BIT_1);
178         // Sound:: Force realtime rendering. This is temporally fix. 20161024 K.O
179 #else
180         // 8253:OUT#0 -> SPEAKER
181         pit->set_context_ch0(pcm, SIG_PCM1BIT_SIGNAL, 1);
182         // Sound:: Force realtime rendering. This is temporally fix. 20161024 K.O
183 #endif
184 #if defined(_MZ800)
185         // 8253:OUT#0 -> NOT -> Z80PIO:PA4
186         pit->set_context_ch0(not_pit, SIG_NOT_INPUT, 1);
187         not_pit->set_context_out(pio_int, SIG_Z80PIO_PORT_A, 0x10);
188 #elif defined(_MZ1500)
189         // 8253:OUT#0 -> Z80PIO:PA4
190         pit->set_context_ch0(pio_int, SIG_Z80PIO_PORT_A, 0x10);
191 #endif
192         
193         // 8253:CLK#1 <- 15.7KHz
194         pit->set_constant_clock(1, CPU_CLOCKS / 228);
195         
196         // 8253:OUT#1 -> 8253:CLK#2
197         pit->set_context_ch1(pit, SIG_I8253_CLOCK_2, 1);
198         
199         // 8253:OUT#2 (N)AND 8255:PC2 -> Z80:INT
200         pit->set_context_ch2(and_int, SIG_AND_BIT_0, 1);
201         pio->set_context_port_c(and_int, SIG_AND_BIT_1, 4, 0);
202         and_int->set_context_out(cpu, SIG_CPU_IRQ, 1);
203         and_int->set_mask(SIG_AND_BIT_0 | SIG_AND_BIT_1);
204         
205 #if defined(_MZ1500)
206         // 8253:OUT#2 -> Z80PIO:PA5
207         pit->set_context_ch2(pio_int, SIG_Z80PIO_PORT_A, 0x20);
208 #endif
209         
210         // 8255:PA0-3 -> KEYBOARD:STROBE
211         pio->set_context_port_a(keyboard, SIG_KEYBOARD_COLUMN, 0x0f, 0);
212 #if defined(_MZ800)
213         // 8255:PA4 -> JOYSTICK #1
214         // 8255:PA5 -> JOYSTICK #2
215 #endif
216         // 8255:PA7 -> 556 RESET
217         
218         // 8255:PB0-7 <- KEYBOARD:DATA
219         keyboard->set_context_pio(pio);
220         
221         // 8255:PC0 -> AND -> SPEAKER
222         // 8255:PC1 -> DATA RECORDER:WRITE DATA
223         pio->set_context_port_c(drec, SIG_DATAREC_MIC, 0x02, 0);
224         // 8255:PC2 -> (N)AND -> Z80:INT
225         // 8255:PC3 -> DATA RECORDER:MOTOR ON/OFF
226         pio->set_context_port_c(drec, SIG_DATAREC_TRIG, 0x08, 0);
227         // 8255:PC4 <- DATA RECORDER:MOTOR REMOTE
228         drec->set_context_remote(pio, SIG_I8255_PORT_C, 0x10);
229         // 8255:PC5 <- DATA RECORDER:READ DATA
230         drec->set_context_ear(pio, SIG_I8255_PORT_C, 0x20);
231         // 8255:PC6 <- MEMORY:556 OUT (1.5KHz)
232         // 8255:PC7 <- MEMORY:VBLANK
233         
234 #if defined(_MZ800) || defined(_MZ1500)
235         // Z80PIO:PA2 <- GND
236         // Z80PIO:PA3 <- GND
237 #if defined(_MZ800)
238         // Z80PIO:PA4 <- NOT <- 8253:OUT#0
239         // Z80PIO:PA5 <- HBLANK
240         memory->set_context_pio_int(pio_int);
241 #elif defined(_MZ1500)
242         // Z80PIO:PA0 <- PRINTER:RDA (BUSY)
243         // Z80PIO:PA1 <- PRINTER:STA (PE)
244         if(config.printer_type == 0) {
245                 PRNFILE *prnfile = (PRNFILE *)printer;
246                 prnfile->set_context_busy(pio_int, SIG_Z80PIO_PORT_A, 0x01);
247         } else if(config.printer_type == 1) {
248                 MZ1P17 *mz1p17 = (MZ1P17 *)printer;
249                 mz1p17->mode = MZ1P17_MODE_MZ2;
250                 mz1p17->set_context_busy(pio_int, SIG_Z80PIO_PORT_A, 0x01);
251         }
252         // Z80PIO:PA4 <- 8253:OUT#0
253         // Z80PIO:PA5 <- 8253:OUT#2
254         // Z80PIO:PA6 -> NOT -> PRINTER:IRT (RESET)
255         // Z80PIO:PA7 -> NOT -> PRINTER:RDP (STROBE)
256         // Z80PIO:PB  -> PRINTER:DATA
257         pio_int->set_context_port_a(not_reset, SIG_NOT_INPUT, 0x40, 0);
258         not_reset->set_context_out(printer, SIG_PRINTER_RESET, 0x01);
259         pio_int->set_context_port_a(not_strobe, SIG_NOT_INPUT, 0x80, 0);
260         not_strobe->set_context_out(printer, SIG_PRINTER_STROBE, 0x01);
261         pio_int->set_context_port_b(printer, SIG_PRINTER_DATA, 0xff, 0);
262 #endif
263 #endif
264         
265 #if defined(_MZ800) || defined(_MZ1500)
266         // Z80SIO:RTSA -> QD:WRGA
267         sio_qd->set_context_rts(0, qd, QUICKDISK_SIO_RTSA, 1);
268         // Z80SIO:DTRB -> QD:MTON
269         sio_qd->set_context_dtr(1, qd, QUICKDISK_SIO_DTRB, 1);
270         // Z80SIO:SENDA -> QD:RECV
271         sio_qd->set_context_sync(0, qd, QUICKDISK_SIO_SYNC, 1);
272         sio_qd->set_context_rxdone(0, qd, QUICKDISK_SIO_RXDONE, 1);
273         sio_qd->set_context_send(0, qd, QUICKDISK_SIO_DATA);
274         sio_qd->set_context_break(0, qd, QUICKDISK_SIO_BREAK, 1);
275         // Z80SIO:CTSA <- QD:PROTECT
276         // Z80SIO:DCDA <- QD:INSERT
277         // Z80SIO:DCDB <- QD:HOE
278         qd->set_context_sio(sio_qd);
279         
280         sio_rs->set_tx_clock(0, 1200 * 16);     // 1200 baud
281         sio_rs->set_rx_clock(0, 1200 * 16);     // baud-rate can be changed by jumper pin
282         sio_rs->set_tx_clock(1, 1200 * 16);
283         sio_rs->set_rx_clock(1, 1200 * 16);
284         
285         sio_qd->set_tx_clock(0, 101562.5);
286         sio_qd->set_rx_clock(0, 101562.5);
287         sio_qd->set_tx_clock(1, 101562.5);
288         sio_qd->set_rx_clock(1, 101562.5);
289         
290         // floppy drives
291         floppy->set_context_cpu(cpu);
292         floppy->set_context_fdc(fdc);
293         fdc->set_context_drq(floppy, SIG_FLOPPY_DRQ, 1);
294 #endif
295         
296         // cpu bus
297         cpu->set_context_mem(memory);
298         cpu->set_context_io(io);
299 #if defined(_MZ800) || defined(_MZ1500)
300         cpu->set_context_intr(pio_int);
301         // z80 family daisy chain
302         // 0=8253:OUT2
303         pio_int->set_context_intr(cpu, 1);
304         pio_int->set_context_child(sio_rs);
305         sio_rs->set_context_intr(cpu, 2);
306         sio_rs->set_context_child(sio_qd);
307         sio_qd->set_context_intr(cpu, 3);
308 #else
309         cpu->set_context_intr(dummy);
310 #endif
311 #ifdef USE_DEBUGGER
312         cpu->set_context_debugger(new DEBUGGER(this, emu));
313 #endif
314         
315         // emm
316         io->set_iomap_range_rw(0x00, 0x03, emm);
317         // kanji
318         io->set_iomap_range_rw(0xb8, 0xb9, kanji);
319         // ramfile
320         io->set_iomap_range_rw(0xea, 0xeb, ramfile);
321         // cmos
322 //      io->set_iomap_range_rw(0xf8, 0xfa, cmos);
323         
324 #if defined(_MZ800)
325         // 8255/8253
326         io->set_iomap_range_rw(0xd0, 0xd3, pio);
327         io->set_iomap_range_rw(0xd4, 0xd7, pit);
328 #endif
329         
330 #if defined(_MZ800) || defined(_MZ1500)
331         // floppy drives
332         io->set_iomap_range_rw(0xd8, 0xdb, fdc);
333         io->set_iomap_range_w(0xdc, 0xdf, floppy);
334 #endif
335         
336         // memory mapper
337 #if defined(_MZ800)
338         io->set_iomap_range_r(0xe0, 0xe1, memory);
339         io->set_iomap_range_w(0xe0, 0xe6, memory);
340 #elif defined(_MZ1500)
341         io->set_iomap_range_w(0xe0, 0xe6, memory);
342 #else
343         io->set_iomap_range_w(0xe0, 0xe4, memory);
344 #endif
345         
346 #if defined(_MZ800)
347         // crtc
348         io->set_iomap_range_w(0xcc, 0xcf, memory);
349         io->set_iomap_single_r(0xce, memory);
350         // palette
351         io->set_iomap_single_w(0xf0, memory);
352 #elif defined(_MZ1500)
353         // palette
354         io->set_iomap_range_w(0xf0, 0xf1, memory);
355 #endif
356         
357 #if defined(_MZ800)
358         // joystick
359 //      io->set_iomap_range_r(0xf0, 0xf1, joystick);
360 #endif
361         
362         // psg
363 #if defined(_MZ800)
364         io->set_iomap_single_w(0xf2, psg);
365 #elif defined(_MZ1500)
366         io->set_iomap_single_w(0xe9, psg);
367         io->set_iomap_single_w(0xf2, psg_l);
368         io->set_iomap_single_w(0xf3, psg_r);
369 #endif
370         
371 #if defined(_MZ800) || defined(_MZ1500)
372         // z80pio/sio
373         // z80pio and z80sio*2
374         static const int z80_sio_addr[4] = {0, 2, 1, 3};
375         static const int z80_pio_addr[4] = {1, 3, 0, 2};
376         for(int i = 0; i < 4; i++) {
377                 io->set_iomap_alias_rw(0xb0 + i, sio_rs, z80_sio_addr[i]);
378                 io->set_iomap_alias_rw(0xf4 + i, sio_qd, z80_sio_addr[i]);
379                 io->set_iomap_alias_rw(0xfc + i, pio_int, z80_pio_addr[i]);
380         }
381 #else
382         // printer
383         io->set_iovalue_single_r(0xfe, 0xc0);
384 #endif
385         
386         // initialize all devices
387 #if defined(__GIT_REPO_VERSION)
388         strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
389 #endif
390         for(DEVICE* device = first_device; device; device = device->next_device) {
391                 device->initialize();
392         }
393 #if defined(_MZ800) || defined(_MZ1500)
394         for(int drv = 0; drv < MAX_DRIVE; drv++) {
395 //              if(config.drive_type) {
396                         fdc->set_drive_type(drv, DRIVE_TYPE_2DD);
397 //              } else {
398 //                      fdc->set_drive_type(drv, DRIVE_TYPE_2D);
399 //              }
400         }
401 #endif
402         decl_state();
403 }
404
405 VM::~VM()
406 {
407         // delete all devices
408         for(DEVICE* device = first_device; device;) {
409                 DEVICE *next_device = device->next_device;
410                 device->release();
411                 delete device;
412                 device = next_device;
413         }
414 }
415
416 DEVICE* VM::get_device(int id)
417 {
418         for(DEVICE* device = first_device; device; device = device->next_device) {
419                 if(device->this_device_id == id) {
420                         return device;
421                 }
422         }
423         return NULL;
424 }
425
426 // ----------------------------------------------------------------------------
427 // drive virtual machine
428 // ----------------------------------------------------------------------------
429
430 void VM::reset()
431 {
432         // reset all devices
433         for(DEVICE* device = first_device; device; device = device->next_device) {
434                 device->reset();
435         }
436         and_int->write_signal(SIG_AND_BIT_0, 0, 1);     // CLOCK = L
437         and_int->write_signal(SIG_AND_BIT_1, 1, 1);     // INTMASK = H
438 #if defined(_MZ800) || defined(_MZ1500)
439         and_snd->write_signal(SIG_AND_BIT_1, 1, 1);     // SNDMASK = H
440 #endif
441 #if defined(_MZ1500)
442         pio_int->write_signal(SIG_Z80PIO_PORT_A, 0x02, 0x03);   // BUSY = L, PE = H
443 #endif
444 }
445
446 void VM::run()
447 {
448         event->drive();
449 }
450
451 // ----------------------------------------------------------------------------
452 // debugger
453 // ----------------------------------------------------------------------------
454
455 #ifdef USE_DEBUGGER
456 DEVICE *VM::get_cpu(int index)
457 {
458         if(index == 0) {
459                 return cpu;
460         }
461         return NULL;
462 }
463 #endif
464
465 // ----------------------------------------------------------------------------
466 // draw screen
467 // ----------------------------------------------------------------------------
468
469 void VM::draw_screen()
470 {
471         memory->draw_screen();
472 }
473
474 // ----------------------------------------------------------------------------
475 // soud manager
476 // ----------------------------------------------------------------------------
477
478 void VM::initialize_sound(int rate, int samples)
479 {
480         // init sound manager
481         event->initialize_sound(rate, samples);
482         
483         // init sound gen
484         pcm->initialize_sound(rate, 8000);
485 #if defined(_MZ800)
486         psg->initialize_sound(rate, 3579545, 8000);
487 #elif defined(_MZ1500)
488         psg_l->initialize_sound(rate, 3579545, 8000);
489         psg_r->initialize_sound(rate, 3579545, 8000);
490 #endif
491 }
492
493 uint16_t* VM::create_sound(int* extra_frames)
494 {
495         return event->create_sound(extra_frames);
496 }
497
498 int VM::get_sound_buffer_ptr()
499 {
500         return event->get_sound_buffer_ptr();
501 }
502
503 #ifdef USE_SOUND_VOLUME
504 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
505 {
506 #if defined(_MZ800)
507         if(ch-- == 0) {
508                 psg->set_volume(0, decibel_l, decibel_r);
509         } else
510 #elif defined(_MZ1500)
511         if(ch-- == 0) {
512                 psg_l->set_volume(0, decibel_l, decibel_r);
513         } else if(ch-- == 0) {
514                 psg_r->set_volume(0, decibel_l, decibel_r);
515         } else
516 #endif
517         if(ch-- == 0) {
518                 pcm->set_volume(0, decibel_l, decibel_r);
519         } else if(ch-- == 0) {
520                 drec->set_volume(0, decibel_l, decibel_r);
521 #if defined(_MZ800) || defined(_MZ1500)
522         } else if(ch-- == 0) {
523                 fdc->get_context_noise_seek()->set_volume(0, decibel_l, decibel_r);
524                 fdc->get_context_noise_head_down()->set_volume(0, decibel_l, decibel_r);
525                 fdc->get_context_noise_head_up()->set_volume(0, decibel_l, decibel_r);
526 #endif
527         } else if(ch-- == 0) {
528                 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
529                 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
530                 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
531         }
532 }
533 #endif
534
535 // ----------------------------------------------------------------------------
536 // user interface
537 // ----------------------------------------------------------------------------
538
539 void VM::play_tape(int drv, const _TCHAR* file_path)
540 {
541         drec->play_tape(file_path);
542 //      drec->set_remote(true);
543 }
544
545 void VM::rec_tape(int drv, const _TCHAR* file_path)
546 {
547         drec->rec_tape(file_path);
548 //      drec->set_remote(true);
549 }
550
551 void VM::close_tape(int drv)
552 {
553         emu->lock_vm();
554         drec->close_tape();
555         emu->unlock_vm();
556
557         //drec->set_remote(false);
558 }
559
560 bool VM::is_tape_inserted(int drv)
561 {
562         return drec->is_tape_inserted();
563 }
564
565 bool VM::is_tape_playing(int drv)
566 {
567         return drec->is_tape_playing();
568 }
569
570 bool VM::is_tape_recording(int drv)
571 {
572         return drec->is_tape_recording();
573 }
574
575 int VM::get_tape_position(int drv)
576 {
577         return drec->get_tape_position();
578 }
579
580 const _TCHAR* VM::get_tape_message(int drv)
581 {
582         return drec->get_message();
583 }
584
585 void VM::push_play(int drv)
586 {
587         drec->set_ff_rew(0);
588         drec->set_remote(true);
589 }
590
591 void VM::push_stop(int drv)
592 {
593         drec->set_remote(false);
594 }
595
596 void VM::push_fast_forward(int drv)
597 {
598         drec->set_ff_rew(1);
599         drec->set_remote(true);
600 }
601
602 void VM::push_fast_rewind(int drv)
603 {
604         drec->set_ff_rew(-1);
605         drec->set_remote(true);
606 }
607
608 #if defined(_MZ800) || defined(_MZ1500)
609 void VM::open_quick_disk(int drv, const _TCHAR* file_path)
610 {
611         if(drv == 0) {
612                 qd->open_disk(file_path);
613         }
614 }
615
616 void VM::close_quick_disk(int drv)
617 {
618         if(drv == 0) {
619                 qd->close_disk();
620         }
621 }
622
623 bool VM::is_quick_disk_inserted(int drv)
624 {
625         if(drv == 0) {
626                 return qd->is_disk_inserted();
627         } else {
628                 return false;
629         }
630 }
631
632 uint32_t VM::is_quick_disk_accessed()
633 {
634         return qd->read_signal(0);
635 }
636
637 void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
638 {
639         fdc->open_disk(drv, file_path, bank);
640         
641         if(fdc->get_media_type(drv) == MEDIA_TYPE_2DD) {
642                 if(fdc->get_drive_type(drv) == DRIVE_TYPE_2D) {
643                         fdc->set_drive_type(drv, DRIVE_TYPE_2DD);
644                 }
645         } else if(fdc->get_media_type(drv) == MEDIA_TYPE_2D) {
646                 if(fdc->get_drive_type(drv) == DRIVE_TYPE_2DD) {
647                         fdc->set_drive_type(drv, DRIVE_TYPE_2D);
648                 }
649         }
650 }
651
652 void VM::close_floppy_disk(int drv)
653 {
654         fdc->close_disk(drv);
655 }
656
657 bool VM::is_floppy_disk_inserted(int drv)
658 {
659         return fdc->is_disk_inserted(drv);
660 }
661
662 void VM::is_floppy_disk_protected(int drv, bool value)
663 {
664         fdc->is_disk_protected(drv, value);
665 }
666
667 bool VM::is_floppy_disk_protected(int drv)
668 {
669         return fdc->is_disk_protected(drv);
670 }
671
672 uint32_t VM::is_floppy_disk_accessed()
673 {
674         return fdc->read_signal(0);
675 }
676 #endif
677
678 bool VM::is_frame_skippable()
679 {
680         return event->is_frame_skippable();
681 }
682
683 void VM::update_config()
684 {
685 #if defined(_MZ800)
686         if(boot_mode != config.boot_mode) {
687                 // boot mode is changed !!!
688                 boot_mode = config.boot_mode;
689                 reset();
690         } else {
691 #endif
692                 for(DEVICE* device = first_device; device; device = device->next_device) {
693                         device->update_config();
694                 }
695 #if defined(_MZ800)
696         }
697 #endif
698 }
699
700 #define STATE_VERSION   3
701
702 #include "../../statesub.h"
703 #include "../../qt/gui/csp_logger.h"
704 extern CSP_Logger DLL_PREFIX_I *csp_logger;
705
706 void VM::decl_state(void)
707 {
708         state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::MZ700_SERIES_HEAD")), csp_logger);
709 #if defined(_MZ800)
710         DECL_STATE_ENTRY_INT32(boot_mode);
711 #endif
712         for(DEVICE* device = first_device; device; device = device->next_device) {
713                 device->decl_state();
714         }
715 }
716
717 void VM::save_state(FILEIO* state_fio)
718 {
719         if(state_entry != NULL) {
720                 state_entry->save_state(state_fio);
721         }
722         for(DEVICE* device = first_device; device; device = device->next_device) {
723                 device->save_state(state_fio);
724         }
725 }
726
727 bool VM::load_state(FILEIO* state_fio)
728 {
729         bool mb = false;
730         if(state_entry != NULL) {
731                 mb = state_entry->load_state(state_fio);
732         }
733         if(!mb) {
734                 printf("INFO: HEADER DATA ERROR\n");
735                 return false;
736         }
737         for(DEVICE* device = first_device; device; device = device->next_device) {
738                 if(!device->load_state(state_fio)) {
739                         printf("INFO: DATA ERROR at DEVID=%d\n", device->this_device_id);
740                         return false;
741                 }
742         }
743         return true;
744 }
745