OSDN Git Service

8626e9d815f12e2da82afaba6a1fdd212bf77194
[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 write_io8(uint32_t addr, uint32_t data) {
129                 port = data & 0xFF;
130         }
131         uint32_t 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 YM2203(this, emu);
162         psg = new AY_3_891X(this, emu);
163         pcm = new PCM1BIT(this, emu);
164 #if !defined(_MSX1_VARIANTS)
165         rtc = new RP5C01(this, emu);
166         vdp = new V99X8(this, emu);
167 #else
168         vdp = new TMS9918A(this, emu);
169 #endif
170         cpu = new Z80(this, emu);
171         
172         joystick = new JOYSTICK(this, emu);
173         keyboard = new KEYBOARD(this, emu);
174         memory = new MEMORY_EX(this, emu);
175 #if !defined(_MSX1_VARIANTS)
176         rtcif = new RTCIF(this, emu);
177 #endif
178 //      slot0 = new SLOT0(this, emu);   // #0: main memory
179 //      slot1 = new SLOT1(this, emu);   // #1: rom-cartridge or msx-dos
180 //      slot2 = new SLOT2(this, emu);   // #2: fdd-cartridge or p-basic
181 //      slot3 = new SLOT3(this, emu);   // #3: rom-cartridge or ram-cartridge
182         slot_mainrom = new SLOT_MAINROM(this, emu);
183         slot_cart[0] = new SLOT_CART(this, emu);
184         slot_cart[1] = new SLOT_CART(this, emu);
185         sound_cart[0] = new SOUND_CART(this, emu);
186         sound_cart[1] = new SOUND_CART(this, emu);
187         kanjirom = new KANJIROM(this, emu);
188 #ifdef USE_PRINTER
189         printer = new PRINTER(this, emu);
190 #endif
191 #if defined(LDC_SLOT)
192         slot_ldc = new SLOT_LDC(this, emu);
193 #endif
194 #if defined(MAPPERRAM_SLOT)
195         slot_ram = new SLOT_MAPPERRAM(this, emu);
196 #endif
197 #if defined(RAM64K_SLOT)
198         slot_ram = new SLOT_RAM64K(this, emu);
199 #endif
200 #if defined(SUBROM_SLOT)
201         slot_subrom = new SLOT_SUBROM(this, emu);
202 #endif
203 #if defined(FIRMWARE32K1_SLOT)
204         slot_firmware32k1 = new SLOT_FIRMWARE32K(this, emu);
205 #endif
206 #if defined(FIRMWARE32K2_SLOT)
207         slot_firmware32k2 = new SLOT_FIRMWARE32K(this, emu);
208 #endif
209 #if defined(FDD_PATCH_SLOT)
210         slot_fdd_patch = new SLOT_FDD_PATCH(this, emu);
211 #endif
212 #if defined(MSXDOS2_SLOT)
213         slot_msxdos2 = new SLOT_MSXDOS2(this, emu);
214 #endif
215         ym2413 = new YM2413(this, emu);
216 #if defined(MSXMUSIC_SLOT)
217         slot_msxmusic = new SLOT_MSXMUSIC(this, emu);
218 #endif
219 #if defined(MSX_PSG_STEREO)
220         psg_stereo = new PSG_STEREO(this, emu);
221 #endif
222         
223         // set contexts
224         event->set_context_cpu(cpu);
225 #if defined(MSX_PSG_STEREO)
226         event->set_context_sound(psg_stereo);
227 #else
228         event->set_context_sound(psg);
229 #endif
230         event->set_context_sound(pcm);
231         event->set_context_sound(drec);
232 #if defined(LDC_SLOT)
233         event->set_context_sound(ldp);
234 #endif
235         event->set_context_sound(ym2413);
236         event->set_context_sound(sound_cart[0]);
237         event->set_context_sound(sound_cart[1]);
238         event->set_context_sound(drec->get_context_noise_play());
239         event->set_context_sound(drec->get_context_noise_stop());
240         event->set_context_sound(drec->get_context_noise_fast());
241         slot_cart[0]->set_context_sound(sound_cart[0]);
242         slot_cart[1]->set_context_sound(sound_cart[1]);
243         
244         drec->set_context_ear(psg, SIG_AY_3_891X_PORT_A, 0x80);
245         pio->set_context_port_a(memory, SIG_MEMORY_SEL, 0xff, 0);
246         pio->set_context_port_c(keyboard, SIG_KEYBOARD_COLUMN, 0x0f, 0);
247         pio->set_context_port_c(not_remote, SIG_NOT_INPUT, 0x10, 0);
248         not_remote->set_context_out(drec, SIG_DATAREC_REMOTE, 1);
249         pio->set_context_port_c(drec, SIG_DATAREC_MIC, 0x20, 0);
250         pio->set_context_port_c(pcm, SIG_PCM1BIT_SIGNAL, 0x80, 0);
251         psg->set_context_port_b(joystick, SIG_JOYSTICK_SEL, 0x40, 0);
252         vdp->set_context_irq(cpu, SIG_CPU_IRQ, 1);
253 #if defined(LDC_SLOT)
254         pio->set_context_port_c(slot_ldc, SIG_LDC_MUTE, 0x10, 0);
255         ldp->set_context_exv(slot_ldc, SIG_LDC_EXV, 1);
256         ldp->set_context_ack(slot_ldc, SIG_LDC_ACK, 1);
257         ldp->set_context_sound(psg, SIG_AY_3_891X_PORT_A, 0x80);
258 #endif
259         
260         joystick->set_context_psg(psg);
261 //      keyboard->set_context_cpu(cpu);
262         keyboard->set_context_pio(pio);
263 //      memory->set_context_slot(0, slot0);
264 //      memory->set_context_slot(1, slot1);
265 //      memory->set_context_slot(2, slot2);
266 //      memory->set_context_slot(3, slot3);
267         memory->set_context_slot_dummy(dummy);
268         memory->set_context_slot(MAINROM_SLOT, slot_mainrom);
269         memory->set_context_slot(CART1_SLOT, slot_cart[0]);
270 #if defined(CART2_SLOT)
271         memory->set_context_slot(CART2_SLOT, slot_cart[1]);
272 #endif
273 #if defined(LDC_SLOT)
274         memory->set_context_slot(LDC_SLOT, slot_ldc);
275 #endif
276 #if defined(MAPPERRAM_SLOT)
277         memory->set_context_slot(MAPPERRAM_SLOT, slot_ram);
278         memory->set_context_mapper(slot_ram);
279 #endif
280 #if defined(RAM64K_SLOT)
281         memory->set_context_slot(RAM64K_SLOT, slot_ram);
282 #endif
283 #if defined(SUBROM_SLOT)
284         memory->set_context_slot(SUBROM_SLOT, slot_subrom);
285 #endif
286 #if defined(FIRMWARE32K1_SLOT)
287         slot_firmware32k1->set_context_filename(FIRMWARE32K1_FILENAME);
288         memory->set_context_slot(FIRMWARE32K1_SLOT, slot_firmware32k1);
289 #endif
290 #if defined(FIRMWARE32K2_SLOT)
291         slot_firmware32k2->set_context_filename(FIRMWARE32K2_FILENAME);
292         memory->set_context_slot(FIRMWARE32K2_SLOT, slot_firmware32k2);
293 #endif
294 #if defined(FDD_PATCH_SLOT)
295         memory->set_context_slot(FDD_PATCH_SLOT, slot_fdd_patch);
296         memory->set_context_fdd_patch(slot_fdd_patch);
297 #endif
298 #if defined(MSXDOS2_SLOT)
299         memory->set_context_slot(MSXDOS2_SLOT, slot_msxdos2);
300 #endif
301 #if defined(MSXMUSIC_SLOT)
302         memory->set_context_slot(MSXMUSIC_SLOT, slot_msxmusic);
303 #endif
304 #if defined(_MSX_VDP_MESS) && defined(FDD_PATCH_SLOT)
305         memory->set_context_vdp(vdp);
306 #endif
307
308 #if !defined(_MSX1_VARIANTS)
309         rtcif->set_context_rtc(rtc);
310 #endif
311 #if defined(LDC_SLOT)
312         slot_ldc->set_context_cpu(cpu);
313         slot_ldc->set_context_ldp(ldp);
314         slot_ldc->set_context_vdp(vdp);
315 #endif
316         
317 #ifdef USE_PRINTER
318         if(config.printer_type == 0) {  
319                 printer->set_context_prn(new PRNFILE(this, emu));
320 #if defined(_MZP)
321         } else if(config.printer_type == 1) {
322                 MZ1P17 *mz1p17 = new MZ1P17(this, emu);
323                 mz1p17->mode = MZ1P17_MODE_X1;
324                 printer->set_context_prn(mz1p17);
325         } else if(config.printer_type == 2) {
326                 MZ1P17 *mz1p17 = new MZ1P17(this, emu);
327                 mz1p17->mode = MZ1P17_MODE_MZ80P4;
328                 printer->set_context_prn(mz1p17);
329 #else
330 //      } else if(config.printer_type == 1) {
331 //              HXP560 *hxp560 = new HXP560(this, emu);
332 //              printer->set_context_prn(hxp560);
333 //      } else if(config.printer_type == 2) {
334 //              printer->set_context_prn(new PCPR201(this, emu));
335 #endif
336         } else {
337 //              printer->set_context_prn(dummy);
338                 printer->set_context_prn(printer);
339         }
340 #endif
341
342         // cpu bus
343         cpu->set_context_mem(memory);
344         cpu->set_context_io(io);
345         cpu->set_context_intr(dummy);
346 #if defined(FDD_PATCH_SLOT)
347         cpu->set_context_bios(memory);
348 #endif
349 #ifdef USE_DEBUGGER
350         cpu->set_context_debugger(new DEBUGGER(this, emu));
351 #endif
352         
353         // i/o bus
354 #if !defined(_MSX1_VARIANTS)
355         io->set_iomap_range_rw(0xb4, 0xb5, rtcif);
356         io->set_iomap_range_rw(0x98, 0x9b, vdp);
357 #else
358         io->set_iomap_range_rw(0x98, 0x99, vdp);
359 #endif
360         io->set_iomap_range_rw(0xa8, 0xab, pio);
361 #if defined(MSX_PSG_STEREO)
362         psg_stereo->set_context_psg(psg);
363         io->set_iomap_alias_w(0xa0, psg_stereo, 0);     // PSG ch
364         io->set_iomap_alias_w(0xa1, psg_stereo, 1);     // PSG data
365         io->set_iomap_alias_r(0xa2, psg_stereo, 1);     // PSG data
366 #else
367         io->set_iomap_alias_w(0xa0, psg, 0);    // PSG ch
368         io->set_iomap_alias_w(0xa1, psg, 1);    // PSG data
369         io->set_iomap_alias_r(0xa2, psg, 1);    // PSG data
370 #endif
371         io->set_iomap_range_rw(0xfc, 0xff, memory);
372         io->set_iomap_range_rw(0xd8, 0xdb, kanjirom);
373 #ifdef USE_PRINTER
374         io->set_iomap_range_rw(0x90, 0x91, printer);
375 #endif
376         io->set_iomap_range_rw(0x7c, 0x7d, ym2413);
377         
378 #ifdef USE_PORT_F4
379         static PORT_F4 *port_f4;
380         port_f4 = new PORT_F4(this, emu);
381         io->set_iomap_range_rw(0xf4, 0xf4, port_f4);
382 #endif
383
384         // initialize all devices
385 #if defined(__GIT_REPO_VERSION)
386         strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
387 #endif
388         for(DEVICE* device = first_device; device; device = device->next_device) {
389                 device->initialize();
390         }
391 }
392
393 VM::~VM()
394 {
395         // delete all devices
396         for(DEVICE* device = first_device; device;) {
397                 DEVICE *next_device = device->next_device;
398                 device->release();
399                 delete device;
400                 device = next_device;
401         }
402 }
403
404 DEVICE* VM::get_device(int id)
405 {
406         for(DEVICE* device = first_device; device; device = device->next_device) {
407                 if(device->this_device_id == id) {
408                         return device;
409                 }
410         }
411         return NULL;
412 }
413
414 // ----------------------------------------------------------------------------
415 // drive virtual machine
416 // ----------------------------------------------------------------------------
417
418 void VM::reset()
419 {
420         // reset all devices
421         for(DEVICE* device = first_device; device; device = device->next_device) {
422                 device->reset();
423         }
424 }
425
426 void VM::run()
427 {
428         event->drive();
429 }
430
431 // ----------------------------------------------------------------------------
432 // debugger
433 // ----------------------------------------------------------------------------
434
435 #ifdef USE_DEBUGGER
436 DEVICE *VM::get_cpu(int index)
437 {
438         if(index == 0) {
439                 return cpu;
440         }
441         return NULL;
442 }
443 #endif
444
445 // ----------------------------------------------------------------------------
446 // draw screen
447 // ----------------------------------------------------------------------------
448
449 void VM::draw_screen()
450 {
451         vdp->draw_screen();
452 }
453
454 // ----------------------------------------------------------------------------
455 // soud manager
456 // ----------------------------------------------------------------------------
457
458 void VM::initialize_sound(int rate, int samples)
459 {
460         // init sound manager
461         event->initialize_sound(rate, samples);
462         
463         // init sound gen
464 #if defined(MSX_PSG_STEREO)
465         psg_stereo->initialize_sound(rate, 3579545, samples, 0, 0);
466 #else
467         psg->initialize_sound(rate, 3579545, samples, 0, 0);
468 #endif
469         pcm->initialize_sound(rate, 8000);
470 #if defined(LDC_SLOT)
471         ldp->initialize_sound(rate, samples);
472 #endif
473         ym2413->initialize_sound(rate, 3579545, samples);
474         sound_cart[0]->initialize_sound(rate, 3579545, samples);
475         sound_cart[1]->initialize_sound(rate, 3579545, samples);
476 }
477
478 uint16_t* VM::create_sound(int* extra_frames)
479 {
480         return event->create_sound(extra_frames);
481 }
482
483 int VM::get_sound_buffer_ptr()
484 {
485         return event->get_sound_buffer_ptr();
486 }
487
488 #if defined(LDC_SLOT)
489 void VM::movie_sound_callback(uint8_t *buffer, long size)
490 {
491         ldp->movie_sound_callback(buffer, size);
492 }
493 #endif
494
495 #ifdef USE_SOUND_VOLUME
496 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
497 {
498         if(ch == 0) {
499 #if defined(MSX_PSG_STEREO)
500         psg_stereo->set_volume(1, decibel_l, decibel_r);
501 #else
502         psg->set_volume(1, decibel_l, decibel_r);
503 #endif
504         } else if(ch == 1) {
505                 pcm->set_volume(0, decibel_l, decibel_r);
506         } else if(ch == 2) {
507                 drec->set_volume(0, decibel_l, decibel_r);
508 #if defined(_PX7)
509         } else if(ch-- == 3) {
510                 ldp->set_volume(0, decibel_l, decibel_r);
511 #endif
512         } else if(ch == 3) {
513                 sound_cart[0]->set_volume(0, decibel_l, decibel_r);
514         } else if(ch == 4) {
515                 sound_cart[1]->set_volume(0, decibel_l, decibel_r);
516         } else if(ch == 5) {
517                 ym2413->set_volume(0, decibel_l, decibel_r);
518         } else if(ch == 6) {
519                 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
520                 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
521                 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
522         }
523 }
524 #endif
525
526 // ----------------------------------------------------------------------------
527 // user interface
528 // ----------------------------------------------------------------------------
529
530 void VM::open_cart(int drv, const _TCHAR* file_path)
531 {
532         if(drv < 2) {
533                 slot_cart[drv]->open_cart(file_path);
534         }
535         reset();
536 }
537
538 void VM::close_cart(int drv)
539 {
540         if(drv < 2) {
541                 slot_cart[drv]->close_cart();
542         }
543         reset();
544 }
545
546 bool VM::is_cart_inserted(int drv)
547 {
548         if(drv < 2) {
549                 return slot_cart[drv]->is_cart_inserted();
550         } else {
551                 return false;
552         }
553 }
554
555 void VM::play_tape(int drv, const _TCHAR* file_path)
556 {
557         drec->play_tape(file_path);
558 //      drec->set_remote(true);
559 }
560
561 void VM::rec_tape(int drv, const _TCHAR* file_path)
562 {
563         drec->rec_tape(file_path);
564 //      drec->set_remote(true);
565 }
566
567 void VM::close_tape(int drv)
568 {
569         emu->lock_vm();
570         drec->close_tape();
571         emu->unlock_vm();
572 //      drec->set_remote(false);
573 }
574
575 bool VM::is_tape_inserted(int drv)
576 {
577         return drec->is_tape_inserted();
578 }
579
580 bool VM::is_tape_playing(int drv)
581 {
582         return drec->is_tape_playing();
583 }
584
585 bool VM::is_tape_recording(int drv)
586 {
587         return drec->is_tape_recording();
588 }
589
590 int VM::get_tape_position(int drv)
591 {
592         return drec->get_tape_position();
593 }
594
595 const _TCHAR* VM::get_tape_message(int drv)
596 {
597         return drec->get_message();
598 }
599
600 void VM::push_play(int drv)
601 {
602         drec->set_ff_rew(0);
603         drec->set_remote(true);
604 }
605
606 void VM::push_stop(int drv)
607 {
608         drec->set_remote(false);
609 }
610
611 void VM::push_fast_forward(int drv)
612 {
613         drec->set_ff_rew(1);
614         drec->set_remote(true);
615 }
616
617 void VM::push_fast_rewind(int drv)
618 {
619         drec->set_ff_rew(-1);
620         drec->set_remote(true);
621 }
622
623 #if defined(LDC_SLOT)
624 void VM::open_laser_disc(int drv, const _TCHAR* file_path)
625 {
626         ldp->open_disc(file_path);
627 }
628
629 void VM::close_laser_disc(int drv)
630 {
631         ldp->close_disc();
632 }
633
634 bool VM::is_laser_disc_inserted(int drv)
635 {
636         return ldp->is_disc_inserted();
637 }
638
639 uint32_t VM::is_laser_disc_accessed()
640 {
641         return ldp->read_signal(0);
642 }
643 #endif
644
645 #if defined(FDD_PATCH_SLOT)
646 void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
647 {
648         memory->open_disk(drv, file_path, bank);
649 }
650
651 void VM::close_floppy_disk(int drv)
652 {
653         memory->close_disk(drv);
654 }
655
656 bool VM::is_floppy_disk_inserted(int drv)
657 {
658         return memory->is_disk_inserted(drv);
659 }
660
661 void VM::is_floppy_disk_protected(int drv, bool value)
662 {
663         memory->is_disk_protected(drv, value);
664 }
665
666 bool VM::is_floppy_disk_protected(int drv)
667 {
668         return memory->is_disk_protected(drv);
669 }
670
671 uint32_t VM::is_floppy_disk_accessed()
672 {
673         return memory->read_signal(0);
674 }
675 #endif
676
677 bool VM::is_frame_skippable()
678 {
679         return event->is_frame_skippable();
680 }
681
682 void VM::update_config()
683 {
684         for(DEVICE* device = first_device; device; device = device->next_device) {
685                 device->update_config();
686         }
687 }
688
689 #define STATE_VERSION   5
690
691 bool VM::process_state(FILEIO* state_fio, bool loading)
692 {
693         if(!state_fio->StateCheckUint32(STATE_VERSION)) {
694                 return false;
695         }
696         for(DEVICE* device = first_device; device; device = device->next_device) {
697                 // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
698                 // const char *name = typeid(*device).name();
699                 //       But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
700                 const char *name = device->get_device_name();
701                 int len = strlen(name);
702                 
703                 if(!state_fio->StateCheckInt32(len)) {
704                         if(loading) {
705                                 printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
706                         }
707                         return false;
708                 }
709                 if(!state_fio->StateCheckBuffer(name, len, 1)) {
710                         if(loading) {
711                                 printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
712                         }
713                         return false;
714                 }
715                 if(!device->process_state(state_fio, loading)) {
716                         if(loading) {
717                                 printf("Data loading Error: DEVID=%d\n", device->this_device_id);
718                         }
719                         return false;
720                 }
721         }
722         // Machine specified.
723         return true;
724 }