OSDN Git Service

[VM][LOGGER][OSD][VM_TEMPLATE] Add API to log with VM's time.
[csp-qt/common_source_project-fm7.git] / source / src / vm / msx / msx_ex.cpp
1 /*
2         Common Source Code Project
3         MSX Series (experimental)
4
5         Origin : src/vm/msx/msx.cpp
6
7         modified by umaiboux
8         Date   : 2016.03.xx-
9
10         [ virtual machine ]
11 */
12
13 //#define USE_PORT_F4
14
15 #include "msx_ex.h"
16 #include "../../emu.h"
17 #include "../device.h"
18 #include "../event.h"
19
20 #include "../datarec.h"
21 #include "../i8255.h"
22 #include "../io.h"
23 #if defined(LDC_SLOT)
24 #include "../ld700.h"
25 #endif
26 #include "../noise.h"
27 #include "../not.h"
28 //#include "../ym2203.h"
29 #include "../ay_3_891x.h"
30 #include "../pcm1bit.h"
31 #if !defined(_MSX1_VARIANTS)
32 #include "../rp5c01.h"
33 #if defined(_MSX_VDP_MESS)
34 #include "../v9938.h"
35 #else
36 #include "../v99x8.h"
37 #endif
38 #else
39 #include "../tms9918a.h"
40 #endif
41 #include "../z80.h"
42
43 #ifdef USE_DEBUGGER
44 #include "../debugger.h"
45 #endif
46
47 #include "joystick.h"
48 #include "keyboard.h"
49 #include "memory_ex.h"
50 #if !defined(_MSX1_VARIANTS)
51 #include "rtcif.h"
52 #endif
53 #include "kanjirom.h"
54 #include "sound_cart.h"
55 #ifdef USE_PRINTER
56 #include "printer.h"
57 //#include "../pcpr201.h"
58 #include "../prnfile.h"
59 #if defined(_MZP)
60 // test
61 #include "../mz1p17.h"
62 #endif
63 #endif
64 #include "../ym2413.h"
65
66 #if defined(MSX_PSG_STEREO)
67 #include "psg_stereo.h"
68 #endif
69
70 using MSX::JOYSTICK;
71 using MSX::KEYBOARD;
72 using MSX::MEMORY_EX;
73 #if !defined(_MSX1_VARIANTS)
74 using MSX::RTCIF;
75 #endif
76 using MSX::SLOT_MAINROM;
77 using MSX::SLOT_CART;
78 using MSX::SOUND_CART;
79 using MSX::KANJIROM;
80 #if defined(MSX_PSG_STEREO)
81 using MSX::PSG_STEREO;
82 #endif
83 #ifdef USE_PRINTER
84 using MSX::PRINTER;
85 #endif
86 #if defined(LDC_SLOT)
87 using MSX::SLOT_LDC;
88 #endif
89 #if defined(MAPPERRAM_SLOT)
90 using MSX::SLOT_MAPPERRAM;
91 #endif
92 #if defined(RAM64K_SLOT)
93 using MSX::SLOT_RAM64K;
94 #endif
95 #if defined(SUBROM_SLOT)
96 using MSX::SLOT_SUBROM;
97 #endif
98 #if defined(FIRMWARE32K1_SLOT)
99 using MSX::SLOT_FIRMWARE32K;
100 #endif
101 #if defined(FIRMWARE32K2_SLOT)
102 using MSX::SLOT_FIRMWARE32K;
103 #endif
104 #if defined(FDD_PATCH_SLOT)
105 using MSX::SLOT_FDD_PATCH;
106 #endif
107 #if defined(MSXDOS2_SLOT)
108 using MSX::SLOT_MSXDOS2;
109 #endif
110 #if defined(MSXMUSIC_SLOT)
111 using MSX::SLOT_MSXMUSIC;
112 #endif
113
114
115 #ifdef USE_PORT_F4
116 class PORT_F4 : public DEVICE
117 {
118 private:
119         uint8_t port;
120         
121 public:
122         PORT_F4(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) {
123                 port = 0;
124         }
125         ~PORT_F4() {}
126         
127         // common functions
128         void __FASTCALL write_io8(uint32_t addr, uint32_t data) {
129                 port = data & 0xFF;
130         }
131         uint32_t __FASTCALL read_io8(uint32_t addr) {
132                 return port&0xFF;
133         }
134         void reset() {
135                 port = 0;
136         }
137 };
138 #endif
139
140 // ----------------------------------------------------------------------------
141 // initialize
142 // ----------------------------------------------------------------------------
143
144 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
145 {
146         // create devices
147         first_device = last_device = NULL;
148         dummy = new DEVICE(this, emu);  // must be 1st device
149         event = new EVENT(this, emu);   // must be 2nd device
150         
151         drec = new DATAREC(this, emu);
152         drec->set_context_noise_play(new NOISE(this, emu));
153         drec->set_context_noise_stop(new NOISE(this, emu));
154         drec->set_context_noise_fast(new NOISE(this, emu));
155         pio = new I8255(this, emu);
156         io = new IO(this, emu);
157 #if defined(LDC_SLOT)
158         ldp = new LD700(this, emu);
159 #endif
160         not_remote = new NOT(this, emu);
161         psg = new AY_3_891X(this, emu);
162 #ifdef USE_DEBUGGER
163         psg->set_context_debugger(new DEBUGGER(this, emu));
164 #endif
165         pcm = new PCM1BIT(this, emu);
166 #ifdef USE_DEBUGGER
167 //      pcm->set_context_debugger(new DEBUGGER(this, emu));
168 #endif
169 #if !defined(_MSX1_VARIANTS)
170         rtc = new RP5C01(this, emu);
171         vdp = new V99X8(this, emu);
172 #else
173         vdp = new TMS9918A(this, emu);
174 #ifdef USE_DEBUGGER
175         vdp->set_context_debugger(new DEBUGGER(this, emu));
176 #endif
177 #endif
178         cpu = new Z80(this, emu);
179         
180         joystick = new JOYSTICK(this, emu);
181         keyboard = new KEYBOARD(this, emu);
182         memory = new MEMORY_EX(this, emu);
183 #if !defined(_MSX1_VARIANTS)
184         rtcif = new RTCIF(this, emu);
185 #endif
186 //      slot0 = new SLOT0(this, emu);   // #0: main memory
187 //      slot1 = new SLOT1(this, emu);   // #1: rom-cartridge or msx-dos
188 //      slot2 = new SLOT2(this, emu);   // #2: fdd-cartridge or p-basic
189 //      slot3 = new SLOT3(this, emu);   // #3: rom-cartridge or ram-cartridge
190         slot_mainrom = new SLOT_MAINROM(this, emu);
191         slot_cart[0] = new SLOT_CART(this, emu);
192         slot_cart[1] = new SLOT_CART(this, emu);
193         sound_cart[0] = new SOUND_CART(this, emu);
194         sound_cart[1] = new SOUND_CART(this, emu);
195         kanjirom = new KANJIROM(this, emu);
196 #ifdef USE_PRINTER
197         printer = new PRINTER(this, emu);
198 #endif
199 #if defined(LDC_SLOT)
200         slot_ldc = new SLOT_LDC(this, emu);
201 #endif
202 #if defined(MAPPERRAM_SLOT)
203         slot_ram = new SLOT_MAPPERRAM(this, emu);
204 #endif
205 #if defined(RAM64K_SLOT)
206         slot_ram = new SLOT_RAM64K(this, emu);
207 #endif
208 #if defined(SUBROM_SLOT)
209         slot_subrom = new SLOT_SUBROM(this, emu);
210 #endif
211 #if defined(FIRMWARE32K1_SLOT)
212         slot_firmware32k1 = new SLOT_FIRMWARE32K(this, emu);
213 #endif
214 #if defined(FIRMWARE32K2_SLOT)
215         slot_firmware32k2 = new SLOT_FIRMWARE32K(this, emu);
216 #endif
217 #if defined(FDD_PATCH_SLOT)
218         slot_fdd_patch = new SLOT_FDD_PATCH(this, emu);
219 #endif
220 #if defined(MSXDOS2_SLOT)
221         slot_msxdos2 = new SLOT_MSXDOS2(this, emu);
222 #endif
223         ym2413 = new YM2413(this, emu);
224 #if defined(MSXMUSIC_SLOT)
225         slot_msxmusic = new SLOT_MSXMUSIC(this, emu);
226 #endif
227 #if defined(MSX_PSG_STEREO)
228         psg_stereo = new PSG_STEREO(this, emu);
229 #endif
230         
231         // set contexts
232         event->set_context_cpu(cpu);
233 #if defined(MSX_PSG_STEREO)
234         event->set_context_sound(psg_stereo);
235 #else
236         event->set_context_sound(psg);
237 #endif
238         event->set_context_sound(pcm);
239         event->set_context_sound(drec);
240 #if defined(LDC_SLOT)
241         event->set_context_sound(ldp);
242 #endif
243         event->set_context_sound(ym2413);
244         event->set_context_sound(sound_cart[0]);
245         event->set_context_sound(sound_cart[1]);
246         event->set_context_sound(drec->get_context_noise_play());
247         event->set_context_sound(drec->get_context_noise_stop());
248         event->set_context_sound(drec->get_context_noise_fast());
249         slot_cart[0]->set_context_sound(sound_cart[0]);
250         slot_cart[1]->set_context_sound(sound_cart[1]);
251         
252         drec->set_context_ear(psg, SIG_AY_3_891X_PORT_A, 0x80);
253         pio->set_context_port_a(memory, SIG_MEMORY_SEL, 0xff, 0);
254         pio->set_context_port_c(keyboard, SIG_KEYBOARD_COLUMN, 0x0f, 0);
255         pio->set_context_port_c(not_remote, SIG_NOT_INPUT, 0x10, 0);
256         not_remote->set_context_out(drec, SIG_DATAREC_REMOTE, 1);
257         pio->set_context_port_c(drec, SIG_DATAREC_MIC, 0x20, 0);
258         pio->set_context_port_c(pcm, SIG_PCM1BIT_SIGNAL, 0x80, 0);
259         psg->set_context_port_b(joystick, SIG_JOYSTICK_SEL, 0x40, 0);
260         vdp->set_context_irq(cpu, SIG_CPU_IRQ, 1);
261 #if defined(LDC_SLOT)
262         pio->set_context_port_c(slot_ldc, SIG_LDC_MUTE, 0x10, 0);
263         ldp->set_context_exv(slot_ldc, SIG_LDC_EXV, 1);
264         ldp->set_context_ack(slot_ldc, SIG_LDC_ACK, 1);
265         ldp->set_context_sound(psg, SIG_AY_3_891X_PORT_A, 0x80);
266 #endif
267         
268         joystick->set_context_psg(psg);
269 //      keyboard->set_context_cpu(cpu);
270         keyboard->set_context_pio(pio);
271 //      memory->set_context_slot(0, slot0);
272 //      memory->set_context_slot(1, slot1);
273 //      memory->set_context_slot(2, slot2);
274 //      memory->set_context_slot(3, slot3);
275         memory->set_context_slot_dummy(dummy);
276         memory->set_context_slot(MAINROM_SLOT, slot_mainrom);
277         memory->set_context_slot(CART1_SLOT, slot_cart[0]);
278 #if defined(CART2_SLOT)
279         memory->set_context_slot(CART2_SLOT, slot_cart[1]);
280 #endif
281 #if defined(LDC_SLOT)
282         memory->set_context_slot(LDC_SLOT, slot_ldc);
283 #endif
284 #if defined(MAPPERRAM_SLOT)
285         memory->set_context_slot(MAPPERRAM_SLOT, slot_ram);
286         memory->set_context_mapper(slot_ram);
287 #endif
288 #if defined(RAM64K_SLOT)
289         memory->set_context_slot(RAM64K_SLOT, slot_ram);
290 #endif
291 #if defined(SUBROM_SLOT)
292         memory->set_context_slot(SUBROM_SLOT, slot_subrom);
293 #endif
294 #if defined(FIRMWARE32K1_SLOT)
295         slot_firmware32k1->set_context_filename(FIRMWARE32K1_FILENAME);
296         memory->set_context_slot(FIRMWARE32K1_SLOT, slot_firmware32k1);
297 #endif
298 #if defined(FIRMWARE32K2_SLOT)
299         slot_firmware32k2->set_context_filename(FIRMWARE32K2_FILENAME);
300         memory->set_context_slot(FIRMWARE32K2_SLOT, slot_firmware32k2);
301 #endif
302 #if defined(FDD_PATCH_SLOT)
303         memory->set_context_slot(FDD_PATCH_SLOT, slot_fdd_patch);
304         memory->set_context_fdd_patch(slot_fdd_patch);
305 #endif
306 #if defined(MSXDOS2_SLOT)
307         memory->set_context_slot(MSXDOS2_SLOT, slot_msxdos2);
308 #endif
309 #if defined(MSXMUSIC_SLOT)
310         memory->set_context_slot(MSXMUSIC_SLOT, slot_msxmusic);
311 #endif
312 #if defined(_MSX_VDP_MESS) && defined(FDD_PATCH_SLOT)
313         memory->set_context_vdp(vdp);
314 #endif
315
316 #if !defined(_MSX1_VARIANTS)
317         rtcif->set_context_rtc(rtc);
318 #endif
319 #if defined(LDC_SLOT)
320         slot_ldc->set_context_cpu(cpu);
321         slot_ldc->set_context_ldp(ldp);
322         slot_ldc->set_context_vdp(vdp);
323 #endif
324         
325 #ifdef USE_PRINTER
326         if(config.printer_type == 0) {  
327                 printer->set_context_prn(new PRNFILE(this, emu));
328 #if defined(_MZP)
329         } else if(config.printer_type == 1) {
330                 MZ1P17 *mz1p17 = new MZ1P17(this, emu);
331                 mz1p17->mode = MZ1P17_MODE_X1;
332                 printer->set_context_prn(mz1p17);
333         } else if(config.printer_type == 2) {
334                 MZ1P17 *mz1p17 = new MZ1P17(this, emu);
335                 mz1p17->mode = MZ1P17_MODE_MZ80P4;
336                 printer->set_context_prn(mz1p17);
337 #else
338 //      } else if(config.printer_type == 1) {
339 //              HXP560 *hxp560 = new HXP560(this, emu);
340 //              printer->set_context_prn(hxp560);
341 //      } else if(config.printer_type == 2) {
342 //              printer->set_context_prn(new PCPR201(this, emu));
343 #endif
344         } else {
345 //              printer->set_context_prn(dummy);
346                 printer->set_context_prn(printer);
347         }
348 #endif
349
350         // cpu bus
351         cpu->set_context_mem(memory);
352         cpu->set_context_io(io);
353         cpu->set_context_intr(dummy);
354 #if defined(FDD_PATCH_SLOT)
355         cpu->set_context_bios(memory);
356 #endif
357 #ifdef USE_DEBUGGER
358         cpu->set_context_debugger(new DEBUGGER(this, emu));
359 #endif
360         
361         // i/o bus
362 #if !defined(_MSX1_VARIANTS)
363         io->set_iomap_range_rw(0xb4, 0xb5, rtcif);
364         io->set_iomap_range_rw(0x98, 0x9b, vdp);
365 #else
366         io->set_iomap_range_rw(0x98, 0x99, vdp);
367 #endif
368         io->set_iomap_range_rw(0xa8, 0xab, pio);
369 #if defined(MSX_PSG_STEREO)
370         psg_stereo->set_context_psg(psg);
371         io->set_iomap_alias_w(0xa0, psg_stereo, 0);     // PSG ch
372         io->set_iomap_alias_w(0xa1, psg_stereo, 1);     // PSG data
373         io->set_iomap_alias_r(0xa2, psg_stereo, 1);     // PSG data
374 #else
375         io->set_iomap_alias_w(0xa0, psg, 0);    // PSG ch
376         io->set_iomap_alias_w(0xa1, psg, 1);    // PSG data
377         io->set_iomap_alias_r(0xa2, psg, 1);    // PSG data
378 #endif
379         io->set_iomap_range_rw(0xfc, 0xff, memory);
380         io->set_iomap_range_rw(0xd8, 0xdb, kanjirom);
381 #ifdef USE_PRINTER
382         io->set_iomap_range_rw(0x90, 0x91, printer);
383 #endif
384         io->set_iomap_range_rw(0x7c, 0x7d, ym2413);
385         
386 #ifdef USE_PORT_F4
387         static PORT_F4 *port_f4;
388         port_f4 = new PORT_F4(this, emu);
389         io->set_iomap_range_rw(0xf4, 0xf4, port_f4);
390 #endif
391
392         // initialize all devices
393 #if defined(__GIT_REPO_VERSION)
394         strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
395 #endif
396         for(DEVICE* device = first_device; device; device = device->next_device) {
397                 device->initialize();
398         }
399 }
400
401 VM::~VM()
402 {
403         // delete all devices
404         for(DEVICE* device = first_device; device;) {
405                 DEVICE *next_device = device->next_device;
406                 device->release();
407                 delete device;
408                 device = next_device;
409         }
410 }
411
412 DEVICE* VM::get_device(int id)
413 {
414         for(DEVICE* device = first_device; device; device = device->next_device) {
415                 if(device->this_device_id == id) {
416                         return device;
417                 }
418         }
419         return NULL;
420 }
421
422 // ----------------------------------------------------------------------------
423 // drive virtual machine
424 // ----------------------------------------------------------------------------
425
426 void VM::reset()
427 {
428         // reset all devices
429         for(DEVICE* device = first_device; device; device = device->next_device) {
430                 device->reset();
431         }
432 }
433
434 void VM::run()
435 {
436         event->drive();
437 }
438
439 // ----------------------------------------------------------------------------
440 // debugger
441 // ----------------------------------------------------------------------------
442
443 #ifdef USE_DEBUGGER
444 DEVICE *VM::get_cpu(int index)
445 {
446         if(index == 0) {
447                 return cpu;
448         }
449         return NULL;
450 }
451 #endif
452
453 // ----------------------------------------------------------------------------
454 // draw screen
455 // ----------------------------------------------------------------------------
456
457 void VM::draw_screen()
458 {
459         vdp->draw_screen();
460 }
461
462 // ----------------------------------------------------------------------------
463 // soud manager
464 // ----------------------------------------------------------------------------
465
466 void VM::initialize_sound(int rate, int samples)
467 {
468         // init sound manager
469         event->initialize_sound(rate, samples);
470         
471         // init sound gen
472 #if defined(MSX_PSG_STEREO)
473         psg_stereo->initialize_sound(rate, 3579545, samples, 0, 0);
474 #else
475         psg->initialize_sound(rate, 3579545, samples, 0, 0);
476 #endif
477         pcm->initialize_sound(rate, 8000);
478 #if defined(LDC_SLOT)
479         ldp->initialize_sound(rate, samples);
480 #endif
481         ym2413->initialize_sound(rate, 3579545, samples);
482         sound_cart[0]->initialize_sound(rate, 3579545, samples);
483         sound_cart[1]->initialize_sound(rate, 3579545, samples);
484 }
485
486 uint16_t* VM::create_sound(int* extra_frames)
487 {
488         return event->create_sound(extra_frames);
489 }
490
491 int VM::get_sound_buffer_ptr()
492 {
493         return event->get_sound_buffer_ptr();
494 }
495
496 #if defined(LDC_SLOT)
497 void VM::movie_sound_callback(uint8_t *buffer, long size)
498 {
499         ldp->movie_sound_callback(buffer, size);
500 }
501 #endif
502
503 #ifdef USE_SOUND_VOLUME
504 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
505 {
506         if(ch == 0) {
507 #if defined(MSX_PSG_STEREO)
508         psg_stereo->set_volume(1, decibel_l, decibel_r);
509 #else
510         psg->set_volume(1, decibel_l, decibel_r);
511 #endif
512         } else if(ch == 1) {
513                 pcm->set_volume(0, decibel_l, decibel_r);
514         } else if(ch == 2) {
515                 drec->set_volume(0, decibel_l, decibel_r);
516 #if defined(_PX7)
517         } else if(ch-- == 3) {
518                 ldp->set_volume(0, decibel_l, decibel_r);
519 #endif
520         } else if(ch == 3) {
521                 sound_cart[0]->set_volume(0, decibel_l, decibel_r);
522         } else if(ch == 4) {
523                 sound_cart[1]->set_volume(0, decibel_l, decibel_r);
524         } else if(ch == 5) {
525                 ym2413->set_volume(0, decibel_l, decibel_r);
526         } else if(ch == 6) {
527                 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
528                 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
529                 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
530         }
531 }
532 #endif
533
534 // ----------------------------------------------------------------------------
535 // user interface
536 // ----------------------------------------------------------------------------
537
538 void VM::open_cart(int drv, const _TCHAR* file_path)
539 {
540         if(drv < 2) {
541                 slot_cart[drv]->open_cart(file_path);
542         }
543         reset();
544 }
545
546 void VM::close_cart(int drv)
547 {
548         if(drv < 2) {
549                 slot_cart[drv]->close_cart();
550         }
551         reset();
552 }
553
554 bool VM::is_cart_inserted(int drv)
555 {
556         if(drv < 2) {
557                 return slot_cart[drv]->is_cart_inserted();
558         } else {
559                 return false;
560         }
561 }
562
563 void VM::play_tape(int drv, const _TCHAR* file_path)
564 {
565         bool remote = drec->get_remote();
566         
567         if(drec->play_tape(file_path) && remote) {
568                 // if machine already sets remote on, start playing now
569                 push_play(drv);
570         }
571 }
572
573 void VM::rec_tape(int drv, const _TCHAR* file_path)
574 {
575         bool remote = drec->get_remote();
576         
577         if(drec->rec_tape(file_path) && remote) {
578                 // if machine already sets remote on, start recording now
579                 push_play(drv);
580         }
581 }
582
583 void VM::close_tape(int drv)
584 {
585         emu->lock_vm();
586         drec->close_tape();
587         emu->unlock_vm();
588         drec->set_remote(false);
589 }
590
591 bool VM::is_tape_inserted(int drv)
592 {
593         return drec->is_tape_inserted();
594 }
595
596 bool VM::is_tape_playing(int drv)
597 {
598         return drec->is_tape_playing();
599 }
600
601 bool VM::is_tape_recording(int drv)
602 {
603         return drec->is_tape_recording();
604 }
605
606 int VM::get_tape_position(int drv)
607 {
608         return drec->get_tape_position();
609 }
610
611 const _TCHAR* VM::get_tape_message(int drv)
612 {
613         return drec->get_message();
614 }
615
616 void VM::push_play(int drv)
617 {
618         drec->set_remote(false);
619         drec->set_ff_rew(0);
620         drec->set_remote(true);
621 }
622
623 void VM::push_stop(int drv)
624 {
625         drec->set_remote(false);
626 }
627
628 void VM::push_fast_forward(int drv)
629 {
630         drec->set_remote(false);
631         drec->set_ff_rew(1);
632         drec->set_remote(true);
633 }
634
635 void VM::push_fast_rewind(int drv)
636 {
637         drec->set_remote(false);
638         drec->set_ff_rew(-1);
639         drec->set_remote(true);
640 }
641
642 #if defined(LDC_SLOT)
643 void VM::open_laser_disc(int drv, const _TCHAR* file_path)
644 {
645         ldp->open_disc(file_path);
646 }
647
648 void VM::close_laser_disc(int drv)
649 {
650         ldp->close_disc();
651 }
652
653 bool VM::is_laser_disc_inserted(int drv)
654 {
655         return ldp->is_disc_inserted();
656 }
657
658 uint32_t VM::is_laser_disc_accessed()
659 {
660         return ldp->read_signal(0);
661 }
662 #endif
663
664 #if defined(FDD_PATCH_SLOT)
665 void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
666 {
667         memory->open_disk(drv, file_path, bank);
668 }
669
670 void VM::close_floppy_disk(int drv)
671 {
672         memory->close_disk(drv);
673 }
674
675 bool VM::is_floppy_disk_inserted(int drv)
676 {
677         return memory->is_disk_inserted(drv);
678 }
679
680 void VM::is_floppy_disk_protected(int drv, bool value)
681 {
682         memory->is_disk_protected(drv, value);
683 }
684
685 bool VM::is_floppy_disk_protected(int drv)
686 {
687         return memory->is_disk_protected(drv);
688 }
689
690 uint32_t VM::is_floppy_disk_accessed()
691 {
692         return memory->read_signal(0);
693 }
694 #endif
695
696 bool VM::is_frame_skippable()
697 {
698         return event->is_frame_skippable();
699 }
700
701 void VM::update_config()
702 {
703         for(DEVICE* device = first_device; device; device = device->next_device) {
704                 device->update_config();
705         }
706 }
707
708 double VM::get_current_usec()
709 {
710         if(event == NULL) return 0.0;
711         return event->get_current_usec();
712 }
713
714 uint64_t VM::get_current_clock_uint64()
715 {
716                 if(event == NULL) return (uint64_t)0;
717                 return event->get_current_clock_uint64();
718 }
719
720 #define STATE_VERSION   6
721
722 bool VM::process_state(FILEIO* state_fio, bool loading)
723 {
724         if(!state_fio->StateCheckUint32(STATE_VERSION)) {
725                 return false;
726         }
727         for(DEVICE* device = first_device; device; device = device->next_device) {
728                 // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
729                 // const char *name = typeid(*device).name();
730                 //       But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
731                 const char *name = device->get_device_name();
732                 int len = strlen(name);
733                 
734                 if(!state_fio->StateCheckInt32(len)) {
735                         if(loading) {
736                                 printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
737                         }
738                         return false;
739                 }
740                 if(!state_fio->StateCheckBuffer(name, len, 1)) {
741                         if(loading) {
742                                 printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
743                         }
744                         return false;
745                 }
746                 if(!device->process_state(state_fio, loading)) {
747                         if(loading) {
748                                 printf("Data loading Error: DEVID=%d\n", device->this_device_id);
749                         }
750                         return false;
751                 }
752         }
753         // Machine specified.
754         return true;
755 }