OSDN Git Service

[General] Merge Updtream 2020-08-10.
[csp-qt/common_source_project-fm7.git] / source / src / vm / mz2500 / mz2500.cpp
1 /*
2         SHARP MZ-2500 Emulator 'EmuZ-2500'
3
4         Author : Takeda.Toshiya
5         Date   : 2006.11.24 -
6
7         [ virtual machine ]
8 */
9
10 #include "mz2500.h"
11 #include "../../emu.h"
12 #include "../device.h"
13 #include "../event.h"
14
15 #include "../datarec.h"
16 #include "../disk.h"
17 #include "../harddisk.h"
18 #include "../i8253.h"
19 #include "../i8255.h"
20 #include "../io.h"
21 #include "../mb8877.h"
22 #include "../mz1p17.h"
23 #include "../noise.h"
24 #include "../pcm1bit.h"
25 //#include "../pcpr201.h"
26 #include "../prnfile.h"
27 #include "../rp5c01.h"
28 #include "../scsi_hdd.h"
29 #include "../scsi_host.h"
30 #include "../w3100a.h"
31 #include "../ym2203.h"
32 #include "../z80.h"
33 #include "../z80pio.h"
34 #include "../z80sio.h"
35
36 #ifdef USE_DEBUGGER
37 #include "../debugger.h"
38 #endif
39
40 #include "calendar.h"
41 #include "cmt.h"
42 #include "crtc.h"
43 #include "floppy.h"
44 #include "interrupt.h"
45 #include "joystick.h"
46 #include "keyboard.h"
47 #include "./memory.h"
48 #include "mouse.h"
49 #include "mz1e26.h"
50 #include "mz1e30.h"
51 #include "mz1r13.h"
52 #include "mz1r37.h"
53 #include "printer.h"
54 #include "serial.h"
55 #include "timer.h"
56
57 using MZ2500::CALENDAR;
58 using MZ2500::CMT;
59 using MZ2500::CRTC;
60 using MZ2500::FLOPPY;
61 using MZ2500::INTERRUPT;
62 using MZ2500::JOYSTICK;
63 using MZ2500::KEYBOARD;
64 using MZ2500::MEMORY;
65 using MZ2500::MOUSE;
66 using MZ2500::MZ1E26;
67 using MZ2500::MZ1E30;
68 using MZ2500::MZ1R13;
69 using MZ2500::MZ1R37;
70 using MZ2500::PRINTER;
71 using MZ2500::SERIAL;
72 using MZ2500::TIMER;
73
74 // ----------------------------------------------------------------------------
75 // initialize
76 // ----------------------------------------------------------------------------
77
78 VM::VM(EMU_TEMPLATE* parent_emu) : VM_TEMPLATE(parent_emu)
79 {
80         // create devices
81         first_device = last_device = NULL;
82         dummy = new DEVICE(this, emu);  // must be 1st device
83         event = new EVENT(this, emu);   // must be 2nd device
84         dummy->set_device_name(_T("1st Dummy"));
85         
86         drec = new DATAREC(this, emu);
87         drec->set_context_noise_play(new NOISE(this, emu));
88         drec->set_context_noise_stop(new NOISE(this, emu));
89         drec->set_context_noise_fast(new NOISE(this, emu));
90         pit = new I8253(this, emu);
91         pio_i = new I8255(this, emu);
92         io = new IO(this, emu);
93         fdc = new MB8877(this, emu);
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 #ifdef USE_DEBUGGER
98 //      fdc->set_context_debugger(new DEBUGGER(this, emu));
99 #endif
100         pcm = new PCM1BIT(this, emu);
101 #ifdef USE_DEBUGGER
102 //      pcm->set_context_debugger(new DEBUGGER(this, emu));
103 #endif
104         rtc = new RP5C01(this, emu);    // RP-5C15
105         sasi_host = new SCSI_HOST(this, emu);
106         sasi_hdd = new SASI_HDD(this, emu);
107         sasi_hdd->set_device_name(_T("SASI Hard Disk Drive"));
108         sasi_hdd->scsi_id = 0;
109         sasi_hdd->bytes_per_sec = 32 * 1024; // 32KB/s
110         for(int i = 0; i < USE_HARD_DISK; i++) {
111                 sasi_hdd->set_disk_handler(i, new HARDDISK(emu));
112         }
113         sasi_hdd->set_context_interface(sasi_host);
114         sasi_host->set_context_target(sasi_hdd);
115         w3100a = new W3100A(this, emu);
116         opn = new YM2203(this, emu);
117 #ifdef USE_DEBUGGER
118         opn->set_context_debugger(new DEBUGGER(this, emu));
119 #endif
120         cpu = new Z80(this, emu);
121         pio = new Z80PIO(this, emu);
122         sio = new Z80SIO(this, emu);
123
124         pio_i->set_device_name(_T("i8255 PIO(CMT/CRTC)"));
125         pio->set_device_name(_T("Z80 PIO(KEYBOARD/CRTC)"));
126         sio->set_device_name(_T("Z80 SIO(MOUSE)"));
127
128         
129         calendar = new CALENDAR(this, emu);
130         cmt = new CMT(this, emu);
131         crtc = new CRTC(this, emu);
132         floppy = new FLOPPY(this, emu);
133         interrupt = new INTERRUPT(this, emu);
134         joystick = new JOYSTICK(this, emu);
135         keyboard = new KEYBOARD(this, emu);
136         memory = new MEMORY(this, emu);
137         mouse = new MOUSE(this, emu);
138         mz1e26 = new MZ1E26(this, emu);
139         mz1e30 = new MZ1E30(this, emu);
140         mz1r13 = new MZ1R13(this, emu);
141         mz1r37 = new MZ1R37(this, emu);
142         printer = new PRINTER(this, emu);
143         serial = new SERIAL(this, emu);
144         timer = new TIMER(this, emu);
145         // set contexts
146         event->set_context_cpu(cpu);
147         event->set_context_sound(opn);
148         event->set_context_sound(pcm);
149         event->set_context_sound(drec);
150         event->set_context_sound(fdc->get_context_noise_seek());
151         event->set_context_sound(fdc->get_context_noise_head_down());
152         event->set_context_sound(fdc->get_context_noise_head_up());
153         event->set_context_sound(drec->get_context_noise_play());
154         event->set_context_sound(drec->get_context_noise_stop());
155         event->set_context_sound(drec->get_context_noise_fast());
156         
157         drec->set_context_ear(cmt, SIG_CMT_OUT, 1);
158         drec->set_context_remote(cmt, SIG_CMT_REMOTE, 1);
159         drec->set_context_end(cmt, SIG_CMT_END, 1);
160         drec->set_context_top(cmt, SIG_CMT_TOP, 1);
161         
162         pit->set_context_ch0(interrupt, SIG_INTERRUPT_I8253, 1);
163         pit->set_context_ch0(pit, SIG_I8253_CLOCK_1, 1);
164         pit->set_context_ch1(pit, SIG_I8253_CLOCK_2, 1);
165         pit->set_constant_clock(0, 31250);
166         pio_i->set_context_port_a(cmt, SIG_CMT_PIO_PA, 0xff, 0);
167         pio_i->set_context_port_c(cmt, SIG_CMT_PIO_PC, 0xff, 0);
168         pio_i->set_context_port_c(crtc, SIG_CRTC_MASK, 0x01, 0);
169         pio_i->set_context_port_c(pcm, SIG_PCM1BIT_SIGNAL, 0x04, 0);
170         // Sound:: Force realtime rendering. This is temporally fix. 20161024 K.O
171         //pcm->set_realtime_render(true);
172
173         
174         rtc->set_context_alarm(interrupt, SIG_INTERRUPT_RP5C15, 1);
175         rtc->set_context_pulse(opn, SIG_YM2203_PORT_B, 8);
176         sasi_host->set_context_irq(mz1e30, SIG_MZ1E30_IRQ, 1);
177         sasi_host->set_context_drq(mz1e30, SIG_MZ1E30_DRQ, 1);
178         opn->set_context_port_a(floppy, SIG_FLOPPY_REVERSE, 0x02, 0);
179         opn->set_context_port_a(crtc, SIG_CRTC_PALLETE, 0x04, 0);
180         opn->set_context_port_a(mouse, SIG_MOUSE_SEL, 0x08, 0);
181         pio->set_context_port_a(crtc, SIG_CRTC_COLUMN_SIZE, 0x20, 0);
182         pio->set_context_port_a(keyboard, SIG_KEYBOARD_COLUMN, 0x1f, 0);
183         sio->set_context_dtr(1, mouse, SIG_MOUSE_DTR, 1);
184         
185         calendar->set_context_rtc(rtc);
186         cmt->set_context_pio(pio_i);
187         cmt->set_context_drec(drec);
188         crtc->set_context_mem(memory);
189         crtc->set_context_int(interrupt);
190         crtc->set_context_pio(pio_i);
191         crtc->set_vram_ptr(memory->get_vram());
192         crtc->set_tvram_ptr(memory->get_tvram());
193         crtc->set_kanji_ptr(memory->get_kanji());
194         crtc->set_pcg_ptr(memory->get_pcg());
195         floppy->set_context_fdc(fdc);
196         keyboard->set_context_pio_i(pio_i);
197         keyboard->set_context_pio(pio);
198         memory->set_context_cpu(cpu);
199         memory->set_context_crtc(crtc);
200         mouse->set_context_sio(sio);
201         mz1e30->set_context_host(sasi_host);
202         if(config.printer_type == 0) {  
203                 printer->set_context_prn(new PRNFILE(this, emu));
204         } else if(config.printer_type == 1) {
205                 MZ1P17 *mz1p17 = new MZ1P17(this, emu);
206                 mz1p17->mode = MZ1P17_MODE_MZ1;
207                 printer->set_context_prn(mz1p17);
208 //      } else if(config.printer_type == 2) {
209 //              printer->set_context_prn(new PCPR201(this, emu));
210         } else {
211                 printer->set_context_prn(dummy);
212         }
213         serial->set_context_sio(sio);
214         timer->set_context_pit(pit);
215         
216         // cpu bus
217         cpu->set_context_mem(memory);
218         cpu->set_context_io(io);
219         cpu->set_context_intr(pio);
220 #ifdef USE_DEBUGGER
221         cpu->set_context_debugger(new DEBUGGER(this, emu));
222 #endif
223         
224         // z80 family daisy chain
225         pio->set_context_intr(cpu, 0);
226         pio->set_context_child(sio);
227         sio->set_context_intr(cpu, 1);
228         sio->set_context_child(interrupt);
229         interrupt->set_context_intr(cpu, 2);
230         
231         // i/o bus
232         io->set_iomap_range_rw(0x60, 0x63, w3100a);
233         io->set_iomap_range_rw(0xa0, 0xa3, serial);
234         io->set_iomap_range_rw(0xa4, 0xa5, mz1e30);
235         io->set_iomap_range_rw(0xa8, 0xa9, mz1e30);
236         io->set_iomap_range_rw(0xac, 0xad, mz1r37);
237         io->set_iomap_single_w(0xae, crtc);
238         io->set_iomap_range_rw(0xb0, 0xb3, serial);
239         io->set_iomap_range_rw(0xb4, 0xb5, memory);
240         io->set_iomap_range_rw(0xb8, 0xb9, mz1r13);
241         io->set_iomap_range_rw(0xbc, 0xbf, crtc);
242         io->set_iomap_range_w(0xc6, 0xc7, interrupt);
243         io->set_iomap_range_rw(0xc8, 0xc9, opn);
244         io->set_iomap_single_rw(0xca, mz1e26);
245         io->set_iomap_single_rw(0xcc, calendar);
246         io->set_iomap_single_w(0xcd, serial);
247         io->set_iomap_range_w(0xce, 0xcf, memory);
248         io->set_iomap_range_rw(0xd8, 0xdb, fdc);
249         io->set_iomap_range_w(0xdc, 0xdd, floppy);
250         io->set_iomap_range_rw(0xe0, 0xe3, pio_i);
251         io->set_iomap_range_rw(0xe4, 0xe7, pit);
252         io->set_iomap_range_rw(0xe8, 0xeb, pio);
253         io->set_iomap_single_rw(0xef, joystick);
254         io->set_iomap_range_w(0xf0, 0xf3, timer);
255         io->set_iomap_range_rw(0xf4, 0xf7, crtc);
256         io->set_iomap_range_rw(0xfe, 0xff, printer);
257         
258         io->set_iowait_range_rw(0xc8, 0xc9, 1);
259         io->set_iowait_single_rw(0xcc, 3);
260         io->set_iowait_range_rw(0xd8, 0xdf, 1);
261         io->set_iowait_range_rw(0xe8, 0xeb, 1);
262         
263         // initialize all devices
264 #if defined(__GIT_REPO_VERSION)
265         strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
266 #endif
267         for(DEVICE* device = first_device; device; device = device->next_device) {
268                 device->initialize();
269         }
270
271         for(int drv = 0; drv < MAX_DRIVE; drv++) {
272 //              if(config.drive_type) {
273 //                      fdc->set_drive_type(drv, DRIVE_TYPE_2D);
274 //              } else {
275                         fdc->set_drive_type(drv, DRIVE_TYPE_2DD);
276 //              }
277         }
278         for(int drv = 0; drv < USE_HARD_DISK; drv++) {
279                 if(!(config.last_hard_disk_path[drv][0] != _T('\0') && FILEIO::IsFileExisting(config.last_hard_disk_path[drv]))) {
280                         create_local_path(config.last_hard_disk_path[drv], _MAX_PATH, _T("SASI%d.DAT"), drv);
281                 }
282         }
283         monitor_type = config.monitor_type;
284 }
285
286 VM::~VM()
287 {
288         // delete all devices
289         for(DEVICE* device = first_device; device;) {
290                 DEVICE *next_device = device->next_device;
291                 device->release();
292                 delete device;
293                 device = next_device;
294         }
295 }
296
297 DEVICE* VM::get_device(int id)
298 {
299         for(DEVICE* device = first_device; device; device = device->next_device) {
300                 if(device->this_device_id == id) {
301                         return device;
302                 }
303         }
304         return NULL;
305 }
306
307 // ----------------------------------------------------------------------------
308 // drive virtual machine
309 // ----------------------------------------------------------------------------
310
311 void VM::reset()
312 {
313         // reset all devices
314         for(DEVICE* device = first_device; device; device = device->next_device) {
315                 device->reset();
316         }
317         
318         // set initial port status
319         opn->write_signal(SIG_YM2203_PORT_B, (monitor_type & 2) ? 0x77 : 0x37, 0xff);
320 }
321
322 void VM::special_reset(int num)
323 {
324         // reset all devices
325 //      for(DEVICE* device = first_device; device; device = device->next_device) {
326 //              device->special_reset();
327 //      }
328         memory->special_reset(num);
329         cpu->reset();
330 }
331
332 void VM::run()
333 {
334         event->drive();
335 }
336
337 double VM::get_frame_rate()
338 {
339         return event->get_frame_rate();
340 }
341
342 // ----------------------------------------------------------------------------
343 // debugger
344 // ----------------------------------------------------------------------------
345
346 #ifdef USE_DEBUGGER
347 DEVICE *VM::get_cpu(int index)
348 {
349         if(index == 0) {
350                 return cpu;
351         }
352         return NULL;
353 }
354 #endif
355
356 // ----------------------------------------------------------------------------
357 // draw screen
358 // ----------------------------------------------------------------------------
359
360 void VM::draw_screen()
361 {
362         crtc->draw_screen();
363 }
364
365 // ----------------------------------------------------------------------------
366 // soud manager
367 // ----------------------------------------------------------------------------
368
369 void VM::initialize_sound(int rate, int samples)
370 {
371         // init sound manager
372         event->initialize_sound(rate, samples);
373         
374         // init sound gen
375         opn->initialize_sound(rate, 2000000, samples, 0, -8);
376         pcm->initialize_sound(rate, 4096);
377 }
378
379 uint16_t* VM::create_sound(int* extra_frames)
380 {
381         return event->create_sound(extra_frames);
382 }
383
384 int VM::get_sound_buffer_ptr()
385 {
386         return event->get_sound_buffer_ptr();
387 }
388
389 #ifdef USE_SOUND_VOLUME
390 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
391 {
392         if(ch == 0) {
393                 opn->set_volume(0, decibel_l, decibel_r);
394         } else if(ch == 1) {
395                 opn->set_volume(1, decibel_l, decibel_r);
396         } else if(ch == 2) {
397                 pcm->set_volume(0, decibel_l, decibel_r);
398         } else if(ch == 3) {
399                 drec->set_volume(0, decibel_l, decibel_r);
400         } else if(ch == 4) {
401                 drec->set_volume(1, decibel_l, decibel_r);
402         } else if(ch == 5) {
403                 fdc->get_context_noise_seek()->set_volume(0, decibel_l, decibel_r);
404                 fdc->get_context_noise_head_down()->set_volume(0, decibel_l, decibel_r);
405                 fdc->get_context_noise_head_up()->set_volume(0, decibel_l, decibel_r);
406         } else if(ch == 6) {
407                 drec->get_context_noise_play()->set_volume(0, decibel_l, decibel_r);
408                 drec->get_context_noise_stop()->set_volume(0, decibel_l, decibel_r);
409                 drec->get_context_noise_fast()->set_volume(0, decibel_l, decibel_r);
410         }
411 }
412 #endif
413
414 // ----------------------------------------------------------------------------
415 // socket
416 // ----------------------------------------------------------------------------
417
418 void VM::notify_socket_connected(int ch)
419 {
420         w3100a->notify_connected(ch);
421 }
422
423 void VM::notify_socket_disconnected(int ch)
424 {
425         w3100a->notify_disconnected(ch);
426 }
427
428 uint8_t* VM::get_socket_send_buffer(int ch, int* size)
429 {
430         return w3100a->get_send_buffer(ch, size);
431 }
432
433 void VM::inc_socket_send_buffer_ptr(int ch, int size)
434 {
435         w3100a->inc_send_buffer_ptr(ch, size);
436 }
437
438 uint8_t* VM::get_socket_recv_buffer0(int ch, int* size0, int* size1)
439 {
440         return w3100a->get_recv_buffer0(ch, size0, size1);
441 }
442
443 uint8_t* VM::get_socket_recv_buffer1(int ch)
444 {
445         return w3100a->get_recv_buffer1(ch);
446 }
447
448 void VM::inc_socket_recv_buffer_ptr(int ch, int size)
449 {
450         w3100a->inc_recv_buffer_ptr(ch, size);
451 }
452
453 // ----------------------------------------------------------------------------
454 // user interface
455 // ----------------------------------------------------------------------------
456
457 void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
458 {
459         fdc->open_disk(drv, file_path, bank);
460         
461         if(fdc->get_media_type(drv) == MEDIA_TYPE_2DD) {
462                 if(fdc->get_drive_type(drv) == DRIVE_TYPE_2D) {
463                         fdc->set_drive_type(drv, DRIVE_TYPE_2DD);
464                 }
465         } else if(fdc->get_media_type(drv) == MEDIA_TYPE_2D) {
466                 if(fdc->get_drive_type(drv) == DRIVE_TYPE_2DD) {
467                         fdc->set_drive_type(drv, DRIVE_TYPE_2D);
468                 }
469         }
470 }
471
472 void VM::close_floppy_disk(int drv)
473 {
474         fdc->close_disk(drv);
475 }
476
477 bool VM::is_floppy_disk_inserted(int drv)
478 {
479         return fdc->is_disk_inserted(drv);
480 }
481
482 void VM::is_floppy_disk_protected(int drv, bool value)
483 {
484         fdc->is_disk_protected(drv, value);
485 }
486
487 bool VM::is_floppy_disk_protected(int drv)
488 {
489         return fdc->is_disk_protected(drv);
490 }
491
492 uint32_t VM::is_floppy_disk_accessed()
493 {
494         return fdc->read_signal(0);
495 }
496
497 void VM::open_hard_disk(int drv, const _TCHAR* file_path)
498 {
499         if(drv < USE_HARD_DISK) {
500                 sasi_hdd->open(drv, file_path, 256);
501         }
502 }
503
504 void VM::close_hard_disk(int drv)
505 {
506         if(drv < USE_HARD_DISK) {
507                 sasi_hdd->close(drv);
508         }
509 }
510
511 bool VM::is_hard_disk_inserted(int drv)
512 {
513         if(drv < USE_HARD_DISK) {
514                 return sasi_hdd->mounted(drv);
515         }
516         return false;
517 }
518
519 uint32_t VM::is_hard_disk_accessed()
520 {
521         uint32_t status = 0;
522         
523         for(int drv = 0; drv < USE_HARD_DISK; drv++) {
524                 if(sasi_hdd->accessed(drv)) {
525                         status |= 1 << drv;
526                 }
527         }
528         return status;
529 }
530
531 void VM::play_tape(int drv, const _TCHAR* file_path)
532 {
533         bool remote = drec->get_remote();
534         bool opened = drec->play_tape(file_path);
535         
536         if(opened && remote) {
537                 // if machine already sets remote on, start playing now
538                 push_play(drv);
539         }
540         cmt->close_tape();
541         cmt->play_tape(opened);
542 }
543
544 void VM::rec_tape(int drv, const _TCHAR* file_path)
545 {
546         bool remote = drec->get_remote();
547         bool opened = drec->rec_tape(file_path);
548         
549         if(opened && remote) {
550                 // if machine already sets remote on, start recording now
551                 push_play(drv);
552         }
553         cmt->close_tape();
554         cmt->rec_tape(opened);
555 }
556
557 void VM::close_tape(int drv)
558 {
559         emu->lock_vm();
560         drec->close_tape();
561         emu->unlock_vm();
562         drec->set_remote(false);
563         cmt->close_tape();
564 }
565
566 bool VM::is_tape_inserted(int drv)
567 {
568         return drec->is_tape_inserted();
569 }
570
571 bool VM::is_tape_playing(int drv)
572 {
573         return drec->is_tape_playing();
574 }
575
576 bool VM::is_tape_recording(int drv)
577 {
578         return drec->is_tape_recording();
579 }
580
581 int VM::get_tape_position(int drv)
582 {
583         return drec->get_tape_position();
584 }
585
586 const _TCHAR* VM::get_tape_message(int drv)
587 {
588         return drec->get_message();
589 }
590
591 void VM::push_play(int drv)
592 {
593         drec->set_remote(false);
594         drec->set_ff_rew(0);
595         drec->set_remote(true);
596 }
597
598 void VM::push_stop(int drv)
599 {
600         drec->set_remote(false);
601 }
602
603 void VM::push_fast_forward(int drv)
604 {
605         drec->set_remote(false);
606         drec->set_ff_rew(1);
607         drec->set_remote(true);
608 }
609
610 void VM::push_fast_rewind(int drv)
611 {
612         drec->set_remote(false);
613         drec->set_ff_rew(-1);
614         drec->set_remote(true);
615 }
616
617 bool VM::is_frame_skippable()
618 {
619         return event->is_frame_skippable();
620 }
621
622 void VM::update_config()
623 {
624         for(DEVICE* device = first_device; device; device = device->next_device) {
625                 device->update_config();
626         }
627 }
628
629 double VM::get_current_usec()
630 {
631         if(event == NULL) return 0.0;
632         return event->get_current_usec();
633 }
634
635 uint64_t VM::get_current_clock_uint64()
636 {
637                 if(event == NULL) return (uint64_t)0;
638                 return event->get_current_clock_uint64();
639 }
640
641 #define STATE_VERSION   8
642
643 bool VM::process_state(FILEIO* state_fio, bool loading)
644 {
645         if(!state_fio->StateCheckUint32(STATE_VERSION)) {
646                 return false;
647         }
648         for(DEVICE* device = first_device; device; device = device->next_device) {
649                 // Note: typeid(foo).name is fixed by recent ABI.Not dec 6.
650                 // const char *name = typeid(*device).name();
651                 //       But, using get_device_name() instead of typeid(foo).name() 20181008 K.O
652                 const char *name = device->get_device_name();
653                 int len = (int)strlen(name);
654                 
655                 if(!state_fio->StateCheckInt32(len)) {
656                         if(loading) {
657                                 printf("Class name len Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
658                         }
659                         return false;
660                 }
661                 if(!state_fio->StateCheckBuffer(name, len, 1)) {
662                         if(loading) {
663                                 printf("Class name Error: DEVID=%d EXPECT=%s\n", device->this_device_id, name);
664                         }
665                         return false;
666                 }
667                 if(!device->process_state(state_fio, loading)) {
668                         if(loading) {
669                                 printf("Data loading Error: DEVID=%d\n", device->this_device_id);
670                         }
671                         return false;
672                 }
673         }
674         // Machine specified.
675         state_fio->StateValue(monitor_type);
676         return true;
677 }