OSDN Git Service

54c86dff80431fbb33115e893caae6d766779024
[csp-qt/common_source_project-fm7.git] / source / src / vm / pc6001 / pc6001.cpp
1 /*
2         NEC PC-6001 Emulator 'yaPC-6001'
3         NEC PC-6001mkII Emulator 'yaPC-6201'
4         NEC PC-6001mkIISR Emulator 'yaPC-6401'
5         NEC PC-6601 Emulator 'yaPC-6601'
6         NEC PC-6601SR Emulator 'yaPC-6801'
7
8         Author : tanam
9         Date   : 2013.07.15-
10
11         [ virtual machine ]
12 */
13
14 #include "pc6001.h"
15 #include "../../emu.h"
16 #include "../device.h"
17 #include "../event.h"
18
19 #include "../disk.h"
20 #include "../i8255.h"
21 #include "../io.h"
22 #ifdef _PC6001
23 #include "../mc6847.h"
24 #include "display.h"
25 #else
26 #include "../upd7752.h"
27 #endif
28 #include "../noise.h"
29 #include "../pc6031.h"
30 #include "../pc80s31k.h"
31 #include "../prnfile.h"
32 #include "../upd765a.h"
33 #if defined(_PC6001MK2SR) || defined(_PC6601SR)
34 #include "../ym2203.h"
35 #else
36 #include "../ay_3_891x.h"
37 #endif
38 #include "../z80.h"
39
40 #include "../datarec.h"
41 #include "../mcs48.h"
42
43 #ifdef USE_DEBUGGER
44 #include "../debugger.h"
45 #endif
46
47 #if defined(_PC6601) || defined(_PC6601SR)
48 #include "floppy.h"
49 #endif
50 #include "joystick.h"
51 #include "memory.h"
52 #include "psub.h"
53 #include "sub.h"
54 #include "timer.h"
55
56 // ----------------------------------------------------------------------------
57 // initialize
58 // ----------------------------------------------------------------------------
59
60 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
61 {
62         support_pc80s31k = FILEIO::IsFileExisting(create_local_path(_T("DISK.ROM")));
63 #ifdef _PC6601SR
64         support_sub_cpu = false;
65 #else
66         support_sub_cpu = FILEIO::IsFileExisting(create_local_path(_T(SUB_CPU_ROM_FILE_NAME)));
67 #endif
68         
69         // create devices
70         first_device = last_device = NULL;
71         dummy = new DEVICE(this, emu);  // must be 1st device
72         event = new EVENT(this, emu);   // must be 2nd device
73         
74         pio_sub = new I8255(this, emu);
75         io = new IO(this, emu);
76         noise_seek = new NOISE(this, emu);
77         noise_head_down = new NOISE(this, emu);
78         noise_head_up = new NOISE(this, emu);
79 #if defined(_PC6001MK2SR) || defined(_PC6601SR)
80         psg = new YM2203(this, emu);
81 #else
82         psg = new AY_3_891X(this, emu);
83 #endif
84         cpu = new Z80(this, emu);
85         
86         if(config.printer_type == 0) {
87                 printer = new PRNFILE(this, emu);
88         } else {
89                 printer = dummy;
90         }
91         
92 #if defined(_PC6601) || defined(_PC6601SR)
93         floppy = new FLOPPY(this, emu);
94         floppy->set_context_noise_seek(noise_seek);
95 //      floppy->set_context_noise_head_down(noise_head_down);
96 //      floppy->set_context_noise_head_up(noise_head_up);
97 #endif
98         joystick = new JOYSTICK(this, emu);
99         memory = new PC6001_MEMORY(this, emu);
100         timer = new TIMER(this, emu);
101         
102         // set contexts
103         event->set_context_cpu(cpu);
104         event->set_context_sound(psg);
105         event->set_context_sound(noise_seek);
106         event->set_context_sound(noise_head_down);
107         event->set_context_sound(noise_head_up);
108         
109         pio_sub->set_context_port_b(printer, SIG_PRINTER_DATA, 0xff, 0);
110         pio_sub->set_context_port_c(printer, SIG_PRINTER_STROBE, 0x01, 0);
111         pio_sub->set_context_port_c(memory, SIG_MEMORY_PIO_PORT_C, 0x06, 0);    // CRTKILL,CGSWN
112         
113 #ifdef _PC6001
114         display = new DISPLAY(this, emu);
115         vdp = new MC6847(this, emu);
116         display->set_context_vdp(vdp);
117         display->set_vram_ptr(memory->get_vram());
118         display->set_context_timer(timer);
119         vdp->load_font_image(create_local_path(_T("CGROM60.60")));
120         vdp->set_context_cpu(cpu);
121         pio_sub->set_context_port_c(vdp, SIG_MC6847_ENABLE, 0x02, 0);   // CRTKILL
122 #else
123         voice = new UPD7752(this, emu);
124         event->set_context_sound(voice);
125         memory->set_context_timer(timer);
126 #endif
127         memory->set_context_cpu(cpu);
128         joystick->set_context_psg(psg);
129         
130         timer->set_context_cpu(cpu);
131 #ifndef _PC6001
132         timer->set_context_memory(memory);
133 #endif
134         if(support_sub_cpu) {
135                 cpu_sub = new MCS48(this, emu);
136                 cpu_sub->set_device_name(_T("MCS48 MCU (Sub)"));
137                 sub = new SUB(this, emu);
138                 drec = new DATAREC(this, emu);
139                 drec->set_device_name(_T("Data Recorder (Sub)"));
140                 drec->set_context_noise_play(new NOISE(this, emu));
141                 drec->set_context_noise_stop(new NOISE(this, emu));
142                 drec->set_context_noise_fast(new NOISE(this, emu));
143                 event->set_context_cpu(cpu_sub, 8000000);
144                 event->set_context_sound(drec);
145                 event->set_context_sound(drec->get_context_noise_play());
146                 event->set_context_sound(drec->get_context_noise_stop());
147                 event->set_context_sound(drec->get_context_noise_fast());
148                 cpu_sub->set_context_mem(new MCS48MEM(this, emu));
149                 cpu_sub->set_context_io(sub);
150 #ifdef USE_DEBUGGER
151                 cpu_sub->set_context_debugger(new DEBUGGER(this, emu));
152 #endif
153                 sub->set_context_pio(pio_sub);
154                 sub->set_context_drec(drec);
155                 sub->set_context_timer(timer);
156                 pio_sub->set_context_port_c(cpu_sub, SIG_CPU_IRQ, 0x80, 0);
157                 drec->set_context_ear(sub, SIG_SUB_DATAREC, 1);
158                 timer->set_context_sub(sub);
159         } else {
160                 psub = new PSUB(this, emu);
161                 psub->set_context_pio(pio_sub);
162                 psub->set_context_timer(timer);
163                 timer->set_context_sub(psub);
164                 cpu_sub = NULL;
165         }
166         if(support_pc80s31k) {
167                 pio_fdd = new I8255(this, emu);
168                 pio_fdd->set_device_name(_T("8255 PIO (FDD I/F)"));
169                 pio_pc80s31k = new I8255(this, emu);
170                 pio_pc80s31k->set_device_name(_T("8255 PIO (320KB FDD)"));
171                 pc80s31k = new PC80S31K(this, emu);
172                 pc80s31k->set_device_name(_T("PC-80S31K (320KB FDD)"));
173                 fdc_pc80s31k = new UPD765A(this, emu);
174                 fdc_pc80s31k->set_device_name(_T("uPD765A FDC (320KB FDD)"));
175                 cpu_pc80s31k = new Z80(this, emu);
176                 cpu_pc80s31k->set_device_name(_T("Z80 CPU (320KB FDD)"));
177                 
178                 event->set_context_cpu(cpu_pc80s31k, 4000000);
179                 
180                 pc80s31k->set_context_cpu(cpu_pc80s31k);
181                 pc80s31k->set_context_fdc(fdc_pc80s31k);
182                 pc80s31k->set_context_pio(pio_pc80s31k);
183                 pio_fdd->set_context_port_a(pio_pc80s31k, SIG_I8255_PORT_B, 0xff, 0);
184                 pio_fdd->set_context_port_b(pio_pc80s31k, SIG_I8255_PORT_A, 0xff, 0);
185                 pio_fdd->set_context_port_c(pio_pc80s31k, SIG_I8255_PORT_C, 0x0f, 4);
186                 pio_fdd->set_context_port_c(pio_pc80s31k, SIG_I8255_PORT_C, 0xf0, -4);
187                 pio_fdd->clear_ports_by_cmdreg = true;
188                 pio_pc80s31k->set_context_port_a(pio_fdd, SIG_I8255_PORT_B, 0xff, 0);
189                 pio_pc80s31k->set_context_port_b(pio_fdd, SIG_I8255_PORT_A, 0xff, 0);
190                 pio_pc80s31k->set_context_port_c(pio_fdd, SIG_I8255_PORT_C, 0x0f, 4);
191                 pio_pc80s31k->set_context_port_c(pio_fdd, SIG_I8255_PORT_C, 0xf0, -4);
192                 pio_pc80s31k->clear_ports_by_cmdreg = true;
193                 fdc_pc80s31k->set_context_irq(cpu_pc80s31k, SIG_CPU_IRQ, 1);
194                 fdc_pc80s31k->set_context_noise_seek(noise_seek);
195                 fdc_pc80s31k->set_context_noise_head_down(noise_head_down);
196                 fdc_pc80s31k->set_context_noise_head_up(noise_head_up);
197                 cpu_pc80s31k->set_context_mem(pc80s31k);
198                 cpu_pc80s31k->set_context_io(pc80s31k);
199                 cpu_pc80s31k->set_context_intr(pc80s31k);
200 #ifdef USE_DEBUGGER
201                 cpu_pc80s31k->set_context_debugger(new DEBUGGER(this, emu));
202 #endif
203 #if defined(_PC6601) || defined(_PC6601SR)
204                 floppy->set_context_ext(pio_fdd);
205 #endif
206         } else {
207                 pc6031 = new PC6031(this, emu);
208                 pc6031->set_context_noise_seek(noise_seek);
209 //              pc6031->set_context_noise_head_down(noise_head_down);
210 //              pc6031->set_context_noise_head_up(noise_head_up);
211 #if defined(_PC6601) || defined(_PC6601SR)
212                 floppy->set_context_ext(pc6031);
213 #endif
214                 cpu_pc80s31k = NULL;
215         }
216         
217         // cpu bus
218         cpu->set_context_mem(memory);
219         cpu->set_context_io(io);
220         cpu->set_context_intr(timer);
221 #ifdef USE_DEBUGGER
222         cpu->set_context_debugger(new DEBUGGER(this, emu));
223 #endif
224         
225         // i/o bus
226         if(support_sub_cpu) {
227                 io->set_iomap_range_rw(0x90, 0x93, sub);
228         } else {
229                 io->set_iomap_range_rw(0x90, 0x93, psub);
230         }
231         io->set_iomap_alias_w(0xa0, psg, 0);                    // PSG ch
232         io->set_iomap_alias_w(0xa1, psg, 1);                    // PSG data
233         io->set_iomap_alias_r(0xa2, psg, 1);                    // PSG data
234 #if defined(_PC6601SR) || defined(_PC6001MK2SR)
235         io->set_iomap_alias_r(0xa3, psg, 0);                    // FM status
236         io->set_iomap_range_rw(0x40, 0x6f, memory);             // VRAM addr
237 #endif
238 #ifdef _PC6001
239         io->set_iomap_single_w(0xb0, display);                  // VRAM addr
240         io->set_iomap_single_w(0x00, memory);                   // MEMORY MAP
241 #else
242         io->set_iomap_single_w(0xb0, memory);                   // VRAM addr
243         io->set_iomap_range_rw(0xc0, 0xcf, memory);             // VRAM addr
244         io->set_iomap_range_rw(0xe0, 0xe3, voice);              // VOICE
245 #if defined(_PC6601) || defined(_PC6601SR)
246         io->set_iomap_range_rw(0xb8, 0xbf, timer);              // IRQ
247         io->set_iomap_range_rw(0xfa, 0xfb, timer);              // IRQ
248 #endif
249         io->set_iomap_range_rw(0xf3, 0xf7, timer);              // IRQ/Timer
250 #endif
251         
252 #if defined(_PC6601) || defined(_PC6601SR)
253         io->set_iomap_range_rw(0xb1, 0xb3, floppy);             // DISK DRIVE
254         io->set_iomap_range_rw(0xb5, 0xb7, floppy);             // DISK DRIVE (Mirror)
255         io->set_iomap_range_rw(0xd0, 0xde, floppy);             // DISK DRIVE
256 #else
257         io->set_iovalue_single_r(0xb1, 0x01);
258 #if defined(_PC6601SR)
259         io->set_iovalue_single_r(0xb2, 0x02);
260 #elif defined(_PC6001MK2SR)
261         io->set_iovalue_single_r(0xb2, 0x00);
262 #endif
263         
264         if(support_pc80s31k) {
265                 io->set_iomap_range_rw(0xd0, 0xd2, pio_fdd);
266                 io->set_iomap_single_w(0xd3, pio_fdd);
267         } else {
268                 io->set_iomap_range_rw(0xd0, 0xd3, pc6031);
269         }
270 #endif
271         io->set_iomap_range_rw(0xf0, 0xf2, memory);             // MEMORY MAP
272         
273         // initialize all devices
274 #if defined(__GIT_REPO_VERSION)
275         strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
276 #endif
277         for(DEVICE* device = first_device; device; device = device->next_device) {
278                 device->initialize();
279         }
280
281         if(support_sub_cpu) {
282                 // load rom images after cpustate is allocated
283 #ifdef _PC6601SR
284 #else
285                 cpu_sub->load_rom_image(create_local_path(_T(SUB_CPU_ROM_FILE_NAME)));
286 #endif
287         }
288         int drive_num = 0;
289 #if defined(_PC6601) || defined(_PC6601SR)
290         floppy->get_disk_handler(0)->drive_num = drive_num++;
291         floppy->get_disk_handler(1)->drive_num = drive_num++;
292 #endif
293         if(support_pc80s31k) {
294                 fdc_pc80s31k->get_disk_handler(0)->drive_num = drive_num++;
295                 fdc_pc80s31k->get_disk_handler(1)->drive_num = drive_num++;
296         } else {
297                 pc6031->get_disk_handler(0)->drive_num = drive_num++;
298                 pc6031->get_disk_handler(1)->drive_num = drive_num++;
299         }
300 }
301
302 VM::~VM()
303 {
304         // delete all devices
305         for(DEVICE* device = first_device; device;) {
306                 DEVICE *next_device = device->next_device;
307                 device->release();
308                 delete device;
309                 device = next_device;
310         }
311 }
312
313 DEVICE* VM::get_device(int id)
314 {
315         for(DEVICE* device = first_device; device; device = device->next_device) {
316                 if(device->this_device_id == id) {
317                         return device;
318                 }
319         }
320         return NULL;
321 }
322
323 // ----------------------------------------------------------------------------
324 // drive virtual machine
325 // ----------------------------------------------------------------------------
326 void VM::reset()
327 {
328         // reset all devices
329         for(DEVICE* device = first_device; device; device = device->next_device) {
330                 device->reset();
331         }
332         if(support_pc80s31k) {
333                 pio_fdd->write_signal(SIG_I8255_PORT_C, 0, 0xff);
334                 pio_pc80s31k->write_signal(SIG_I8255_PORT_C, 0, 0xff);
335         }
336 }
337
338 void VM::run()
339 {
340         event->drive();
341 }
342
343 // ----------------------------------------------------------------------------
344 // debugger
345 // ----------------------------------------------------------------------------
346
347 #ifdef USE_DEBUGGER
348 DEVICE *VM::get_cpu(int index)
349 {
350         if(index == 0) {
351                 return cpu;
352         } else if(index == 1) {
353                 return cpu_sub;
354         } else if(index == 2) {
355                 return cpu_pc80s31k;
356         }
357         return NULL;
358 }
359 #endif
360
361 // ----------------------------------------------------------------------------
362 // draw screen
363 // ----------------------------------------------------------------------------
364
365 void VM::draw_screen()
366 {
367 #ifdef _PC6001
368         display->draw_screen();
369 #else
370         memory->draw_screen();
371 #endif
372 }
373 // ----------------------------------------------------------------------------
374 // soud manager
375 // ----------------------------------------------------------------------------
376
377 void VM::initialize_sound(int rate, int samples)
378 {
379         // init sound manager
380         event->initialize_sound(rate, samples);
381         
382         // init sound gen
383         psg->initialize_sound(rate, 4000000, samples, 0, 0);
384 #ifndef _PC6001
385         voice->initialize_sound(rate);
386 #endif
387 }
388
389 uint16_t* VM::create_sound(int* extra_frames)
390 {
391         return event->create_sound(extra_frames);
392 }
393
394 int VM::get_sound_buffer_ptr()
395 {
396         return event->get_sound_buffer_ptr();
397 }
398
399 #ifdef USE_SOUND_VOLUME
400 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
401 {
402         if(ch-- == 0) {
403                 psg->set_volume(1, decibel_l, decibel_r);
404 #if !defined(_PC6001)
405         } else if(ch-- == 0) {
406                 voice->set_volume(0, decibel_l, decibel_r);
407 #endif
408         } else if(ch-- == 0) {
409                 if(support_sub_cpu) {
410                         drec->set_volume(0, decibel_l, decibel_r);
411                 }
412         } else if(ch-- == 0) {
413                 noise_seek->set_volume(0, decibel_l, decibel_r);
414                 noise_head_down->set_volume(0, decibel_l, decibel_r);
415                 noise_head_up->set_volume(0, decibel_l, decibel_r);
416         } else if(ch-- == 0) {
417                 if(support_sub_cpu) {
418                         drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
419                         drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
420                         drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
421                 }
422         }
423 }
424 #endif
425
426 // ----------------------------------------------------------------------------
427 // notify key
428 // ----------------------------------------------------------------------------
429
430 void VM::key_down(int code, bool repeat)
431 {
432         if(!support_sub_cpu) {
433                 psub->key_down(code);
434         }
435 }
436
437 void VM::key_up(int code)
438 {
439         if(!support_sub_cpu) {
440                 psub->key_up(code);
441         }
442 }
443
444 // ----------------------------------------------------------------------------
445 // user interface
446 // ----------------------------------------------------------------------------
447
448 void VM::open_cart(int drv, const _TCHAR* file_path)
449 {
450         if(drv == 0) {
451                 memory->open_cart(file_path);
452                 reset();
453         }
454 }
455
456 void VM::close_cart(int drv)
457 {
458         if(drv == 0) {
459                 memory->close_cart();
460                 reset();
461         }
462 }
463
464 bool VM::is_cart_inserted(int drv)
465 {
466         if(drv == 0) {
467                 return memory->is_cart_inserted();
468         } else {
469                 return false;
470         }
471 }
472
473 void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
474 {
475 #if defined(_PC6601) || defined(_PC6601SR)
476         if(drv < 2) {
477                 floppy->open_disk(drv, file_path, bank);
478                 return;
479         } else {
480                 drv -= 2;
481         }
482 #endif
483         if(support_pc80s31k) {
484                 fdc_pc80s31k->open_disk(drv, file_path, bank);
485         } else {
486                 pc6031->open_disk(drv, file_path, bank);
487         }
488 }
489
490 void VM::close_floppy_disk(int drv)
491 {
492 #if defined(_PC6601) || defined(_PC6601SR)
493         if(drv < 2) {
494                 floppy->close_disk(drv);
495                 return;
496         } else {
497                 drv -= 2;
498         }
499 #endif
500         if(support_pc80s31k) {
501                 fdc_pc80s31k->close_disk(drv);
502         } else {
503                 pc6031->close_disk(drv);
504         }
505 }
506
507 bool VM::is_floppy_disk_inserted(int drv)
508 {
509 #if defined(_PC6601) || defined(_PC6601SR)
510         if(drv < 2) {
511                 return floppy->is_disk_inserted(drv);
512         } else {
513                 drv -= 2;
514         }
515 #endif
516         if(support_pc80s31k) {
517                 return fdc_pc80s31k->is_disk_inserted(drv);
518         } else {
519                 return pc6031->is_disk_inserted(drv);
520         }
521 }
522
523 void VM::is_floppy_disk_protected(int drv, bool value)
524 {
525 #if defined(_PC6601) || defined(_PC6601SR)
526         if(drv < 2) {
527                 floppy->is_disk_protected(drv, value);
528                 return;
529         } else {
530                 drv -= 2;
531         }
532 #endif
533         if(support_pc80s31k) {
534                 fdc_pc80s31k->is_disk_protected(drv, value);
535         } else {
536                 pc6031->is_disk_protected(drv, value);
537         }
538 }
539
540 bool VM::is_floppy_disk_protected(int drv)
541 {
542 #if defined(_PC6601) || defined(_PC6601SR)
543         if(drv < 2) {
544                 return floppy->is_disk_protected(drv);
545         } else {
546                 drv -= 2;
547         }
548 #endif
549         if(support_pc80s31k) {
550                 return fdc_pc80s31k->is_disk_protected(drv);
551         } else {
552                 return pc6031->is_disk_protected(drv);
553         }
554 }
555
556 uint32_t VM::is_floppy_disk_accessed()
557 {
558         uint32_t status = 0; /// fdc->read_signal(0);
559         if(support_pc80s31k) {
560                 status |= fdc_pc80s31k->read_signal(0);
561         } else {
562                 status |= pc6031->read_signal(0);
563         }
564 #if defined(_PC6601) || defined(_PC6601SR)
565         status <<= 2;
566         status |= floppy->read_signal(0);
567 #endif
568         return status;
569 }
570
571 void VM::play_tape(int drv, const _TCHAR* file_path)
572 {
573         if(support_sub_cpu) {
574                 // support both p6/p6t and wav
575                 drec->play_tape(file_path);
576 //              drec->set_remote(true);
577         } else {
578                 // support only p6/p6t
579                 psub->play_tape(file_path);
580         }
581 }
582
583 void VM::rec_tape(int drv, const _TCHAR* file_path)
584 {
585         if(support_sub_cpu) {
586                 // support both p6/p6t and wav
587                 sub->rec_tape(file_path);       // temporary
588 //              drec->rec_tape(file_path);
589 //              drec->set_remote(true);
590         } else {
591                 // support both p6/p6t and wav
592                 psub->rec_tape(file_path);
593         }
594 }
595
596 void VM::close_tape(int drv)
597 {
598         if(support_sub_cpu) {
599                 if(sub->is_tape_inserted()) {
600                         sub->close_tape();      // temporary
601                 } else {
602                         emu->lock_vm();
603                         drec->close_tape();
604                         emu->unlock_vm();
605 //                      drec->set_remote(false);
606                 }
607         } else {
608                 psub->close_tape();
609         }
610 }
611
612 bool VM::is_tape_inserted(int drv)
613 {
614         if(support_sub_cpu) {
615                 return drec->is_tape_inserted() || sub->is_tape_inserted();
616         } else {
617                 return psub->is_tape_inserted();
618         }
619 }
620
621 bool VM::is_tape_playing(int drv)
622 {
623         if(support_sub_cpu) {
624                 return drec->is_tape_playing();
625         } else {
626                 return false;
627         }
628 }
629
630 bool VM::is_tape_recording(int drv)
631 {
632         if(support_sub_cpu) {
633                 return drec->is_tape_recording();
634         } else {
635                 return false;
636         }
637 }
638
639 int VM::get_tape_position(int drv)
640 {
641         if(support_sub_cpu) {
642                 return drec->get_tape_position();
643         } else {
644                 return 0;
645         }
646 }
647
648 const _TCHAR* VM::get_tape_message(int drv)
649 {
650         if(support_sub_cpu) {
651                 return drec->get_message();
652         } else {
653                 return NULL;
654         }
655 }
656
657 void VM::push_play(int drv)
658 {
659         if(support_sub_cpu) {
660                 drec->set_ff_rew(0);
661                 drec->set_remote(true);
662         }
663 }
664
665 void VM::push_stop(int drv)
666 {
667         if(support_sub_cpu) {
668                 drec->set_remote(false);
669         }
670 }
671
672 void VM::push_fast_forward(int drv)
673 {
674         if(support_sub_cpu) {
675                 drec->set_ff_rew(1);
676                 drec->set_remote(true);
677         }
678 }
679
680 void VM::push_fast_rewind(int drv)
681 {
682         if(support_sub_cpu) {
683                 drec->set_ff_rew(-1);
684                 drec->set_remote(true);
685         }
686 }
687
688 bool VM::is_frame_skippable()
689 {
690         return event->is_frame_skippable();
691 }
692
693 void VM::update_config()
694 {
695         for(DEVICE* device = first_device; device; device = device->next_device) {
696                 device->update_config();
697         }
698 }
699
700 #define STATE_VERSION   6
701
702 bool VM::process_state(FILEIO* state_fio, bool loading)
703 {
704         if(!state_fio->StateCheckUint32(STATE_VERSION)) {
705                 return false;
706         }
707         for(DEVICE* device = first_device; device; device = device->next_device) {
708                 // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
709                 // const char *name = typeid(*device).name();
710                 //       But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
711                 const char *name = device->get_device_name();
712                 int len = strlen(name);
713                 
714                 if(!state_fio->StateCheckInt32(len)) {
715                         if(loading) {
716                                 printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
717                         }
718                         return false;
719                 }
720                 if(!state_fio->StateCheckBuffer(name, len, 1)) {
721                         if(loading) {
722                                 printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
723                         }
724                         return false;
725                 }
726                 if(!device->process_state(state_fio, loading)) {
727                         if(loading) {
728                                 printf("Data loading Error: DEVID=%d\n", device->this_device_id);
729                         }
730                         return false;
731                 }
732         }
733         // Machine specified.
734         state_fio->StateInt32(sr_mode);
735         return true;
736 }