OSDN Git Service

[BUILD] Set SOVERSION and GIT hash automatically.
[csp-qt/common_source_project-fm7.git] / source / src / vm / fmr50 / fmr50.cpp
1 /*
2         FUJITSU FMR-50 Emulator 'eFMR-50'
3         FUJITSU FMR-60 Emulator 'eFMR-60'
4
5         Author : Takeda.Toshiya
6         Date   : 2008.04.28 -
7
8         [ virtual machine ]
9 */
10
11 #include "fmr50.h"
12 #include "../../emu.h"
13 #include "../device.h"
14 #include "../event.h"
15
16 #include "../harddisk.h"
17 #include "../hd46505.h"
18 #ifdef _FMR60
19 #include "../hd63484.h"
20 #endif
21 #include "../i8251.h"
22 #include "../i8253.h"
23 #include "../i8259.h"
24 #if defined(HAS_I286)
25 #include "../i286.h"
26 #else
27 #include "../i386.h"
28 #endif
29 #include "../io.h"
30 #include "../mb8877.h"
31 #include "../msm58321.h"
32 #include "../noise.h"
33 #include "../pcm1bit.h"
34 #include "../scsi_hdd.h"
35 #include "../scsi_host.h"
36 #include "../upd71071.h"
37
38 #ifdef USE_DEBUGGER
39 #include "../debugger.h"
40 #endif
41
42 #include "bios.h"
43 #include "cmos.h"
44 #include "floppy.h"
45 #include "keyboard.h"
46 #include "memory.h"
47 #include "scsi.h"
48 //#include "serial.h"
49 #include "timer.h"
50
51 // ----------------------------------------------------------------------------
52 // initialize
53 // ----------------------------------------------------------------------------
54
55 VM::VM(EMU* parent_emu) : VM_TEMPLATE(parent_emu)
56 {
57 /*
58         Machine ID & CPU ID
59
60         FMR-50FD/HD/LT  0xF8
61         FMR-50FX/HX     0xE0
62         FMR-50SFX/SHX   0xE8
63         FMR-50LT        0xF8
64         FMR-50NBX       0x28
65         FMR-50NB        0x60
66         FMR-50NE/T      0x08
67         FMR-CARD        0x70
68
69         80286           0x00
70         80386           0x01
71         80386SX         0x03
72         80486           0x02
73 */
74         static const int cpu_clock[] = {
75 #if defined(HAS_I286)
76                  8000000, 12000000
77 #elif defined(HAS_I386)
78                 16000000, 20000000
79 #elif defined(HAS_I486)
80                 20000000, 25000000
81 #endif
82         };
83         
84 #if defined(_FMR60) && (defined(HAS_I386) || defined(HAS_I486) || defined(HAS_PENTIUM))
85         uint8_t machine_id = 0xf0;      // FMR-70/80
86 #else
87         uint8_t machine_id = 0xf8;      // FMR-50/60
88 #endif
89         
90         FILEIO* fio = new FILEIO();
91         if(fio->Fopen(create_local_path(_T("MACHINE.ID")), FILEIO_READ_BINARY)) {
92                 machine_id = fio->Fgetc();
93                 fio->Fclose();
94         }
95         delete fio;
96         
97         machine_id &= ~7;
98 #if defined(HAS_I286)
99         machine_id |= 0;        // 286
100 #elif defined(HAS_I386)
101 //      machine_id |= 1;        // 386DX
102         machine_id |= 3;        // 386SX
103 #elif defined(HAS_I486)
104         machine_id |= 2;        // 486SX/DX
105 #endif
106         
107         // create devices
108         first_device = last_device = NULL;
109         dummy = new DEVICE(this, emu);  // must be 1st device
110         event = new EVENT(this, emu);   // must be 2nd device
111         dummy->set_device_name(_T("1st Dummy"));
112
113 #if defined(HAS_I286)
114         cpu = new I286(this, emu);
115 #else
116         cpu = new I386(this, emu);
117 #endif
118 #if defined(HAS_I286)
119         cpu->set_device_name(_T("CPU(i286)"));
120 #elif defined(HAS_I386)
121         cpu->set_device_name(_T("CPU(i386)"));
122 #elif defined(HAS_I486)
123         cpu->set_device_name(_T("CPU(i486)"));
124 #elif defined(HAS_PENTIUM)
125         cpu->set_device_name(_T("CPU(Pentium)"));
126 #endif
127         crtc = new HD46505(this, emu);
128 #ifdef _FMR60
129         acrtc = new HD63484(this, emu);
130 #endif
131         
132         sio = new I8251(this, emu);
133         pit0 = new I8253(this, emu);
134         pit0->set_device_name(_T("8253 PIT #0"));
135         pit1 = new I8253(this, emu);
136         pit1->set_device_name(_T("8253 PIT #1"));
137         pic = new I8259(this, emu);
138         io = new IO(this, emu);
139         fdc = new MB8877(this, emu);
140         fdc->set_context_noise_seek(new NOISE(this, emu));
141         fdc->set_context_noise_head_down(new NOISE(this, emu));
142         fdc->set_context_noise_head_up(new NOISE(this, emu));
143         rtc = new MSM58321(this, emu);
144         pcm = new PCM1BIT(this, emu);
145         
146         scsi_host = new SCSI_HOST(this, emu);
147         for(int i = 0; i < USE_HARD_DISK; i++) {
148                 scsi_hdd[i] = new SCSI_HDD(this, emu);
149                 scsi_hdd[i]->set_device_name(_T("SCSI Hard Disk Drive #%d"), i + 1);
150                 scsi_hdd[i]->scsi_id = i;
151                 scsi_hdd[i]->set_disk_handler(0, new HARDDISK(emu));
152                 scsi_hdd[i]->set_context_interface(scsi_host);
153                 scsi_host->set_context_target(scsi_hdd[i]);
154         }
155         dma = new UPD71071(this, emu);
156         if(FILEIO::IsFileExisting(create_local_path(_T("IPL.ROM")))) {
157                 bios = NULL;
158         } else {
159                 bios = new BIOS(this, emu);
160         }
161         cmos = new CMOS(this, emu);
162         floppy = new FLOPPY(this, emu);
163         keyboard = new KEYBOARD(this, emu);
164         memory = new MEMORY(this, emu);
165         scsi = new SCSI(this, emu);
166 //      serial = new SERIAL(this, emu);
167         timer = new TIMER(this, emu);
168         // set contexts
169         event->set_context_cpu(cpu, cpu_clock[config.cpu_type & 1]);
170         event->set_context_sound(pcm);
171         event->set_context_sound(fdc->get_context_noise_seek());
172         event->set_context_sound(fdc->get_context_noise_head_down());
173         event->set_context_sound(fdc->get_context_noise_head_up());
174         
175 /*      pic     0       timer
176                 1       keyboard
177                 2       rs-232c
178                 3       ex rs-232c
179                 4       (option)
180                 5       (option)
181                 6       floppy drive or dma ???
182                 7       (slave)
183                 8       scsi
184                 9       (option)
185                 10      (option)
186                 11      (option)
187                 12      printer
188                 13      (option)
189                 14      (option)
190                 15      (reserve)
191
192         dma     0       floppy drive
193                 1       hard drive
194                 2       (option)
195                 3       (reserve)
196 */
197         crtc->set_context_disp(memory, SIG_MEMORY_DISP, 1);
198         crtc->set_context_vsync(memory, SIG_MEMORY_VSYNC, 1);
199 #ifdef _FMR60
200         acrtc->set_vram_ptr((uint16_t*)memory->get_vram(), 0x80000);
201 #endif
202         pit0->set_context_ch0(timer, SIG_TIMER_CH0, 1);
203         pit0->set_context_ch1(timer, SIG_TIMER_CH1, 1);
204         pit0->set_context_ch2(pcm, SIG_PCM1BIT_SIGNAL, 1);
205         pit0->set_constant_clock(0, 307200);
206         pit0->set_constant_clock(1, 307200);
207         pit0->set_constant_clock(2, 307200);
208         pit1->set_constant_clock(1, 1228800);
209         pic->set_context_cpu(cpu);
210         fdc->set_context_drq(dma, SIG_UPD71071_CH0, 1);
211         fdc->set_context_irq(floppy, SIG_FLOPPY_IRQ, 1);
212         rtc->set_context_data(timer, SIG_TIMER_RTC, 0x0f, 0);
213         rtc->set_context_busy(timer, SIG_TIMER_RTC, 0x80);
214         scsi_host->set_context_irq(scsi, SIG_SCSI_IRQ, 1);
215         scsi_host->set_context_drq(scsi, SIG_SCSI_DRQ, 1);
216         dma->set_context_memory(memory);
217         dma->set_context_ch0(fdc);
218         dma->set_context_ch1(scsi_host);
219         
220         floppy->set_context_fdc(fdc);
221         floppy->set_context_pic(pic);
222         keyboard->set_context_pic(pic);
223         memory->set_context_cpu(cpu);
224         memory->set_machine_id(machine_id);
225         memory->set_context_crtc(crtc);
226         memory->set_chregs_ptr(crtc->get_regs());
227         scsi->set_context_dma(dma);
228         scsi->set_context_pic(pic);
229         scsi->set_context_host(scsi_host);
230         timer->set_context_pcm(pcm);
231         timer->set_context_pic(pic);
232         timer->set_context_rtc(rtc);
233         
234         // cpu bus
235         cpu->set_context_mem(memory);
236         cpu->set_context_io(io);
237         cpu->set_context_intr(pic);
238         if(bios) {
239                 bios->set_context_mem(memory);
240                 bios->set_context_io(io);
241                 bios->set_cmos_ptr(cmos->get_cmos());
242                 bios->set_vram_ptr(memory->get_vram());
243                 bios->set_cvram_ptr(memory->get_cvram());
244 #ifdef _FMR60
245                 bios->set_avram_ptr(memory->get_avram());
246 #else
247                 bios->set_kvram_ptr(memory->get_kvram());
248 #endif
249                 cpu->set_context_bios(bios);
250         }
251 #ifdef SINGLE_MODE_DMA
252         cpu->set_context_dma(dma);
253 #endif
254 #ifdef USE_DEBUGGER
255         cpu->set_context_debugger(new DEBUGGER(this, emu));
256 #endif
257         
258         // i/o bus
259         io->set_iomap_alias_rw(0x00, pic, I8259_ADDR_CHIP0 | 0);
260         io->set_iomap_alias_rw(0x02, pic, I8259_ADDR_CHIP0 | 1);
261         io->set_iomap_alias_rw(0x10, pic, I8259_ADDR_CHIP1 | 0);
262         io->set_iomap_alias_rw(0x12, pic, I8259_ADDR_CHIP1 | 1);
263         io->set_iomap_single_rw(0x20, memory);  // reset
264         io->set_iomap_single_r(0x21, memory);   // cpu misc
265         io->set_iomap_single_w(0x22, memory);   // dma
266         io->set_iomap_single_rw(0x24, memory);  // dma
267         io->set_iomap_single_r(0x26, timer);
268         io->set_iomap_single_r(0x27, timer);
269         io->set_iomap_single_r(0x30, memory);   // cpu id
270         io->set_iomap_alias_rw(0x40, pit0, 0);
271         io->set_iomap_alias_rw(0x42, pit0, 1);
272         io->set_iomap_alias_rw(0x44, pit0, 2);
273         io->set_iomap_alias_rw(0x46, pit0, 3);
274         io->set_iomap_alias_rw(0x50, pit1, 0);
275         io->set_iomap_alias_rw(0x52, pit1, 1);
276         io->set_iomap_alias_rw(0x54, pit1, 2);
277         io->set_iomap_alias_rw(0x56, pit1, 3);
278         io->set_iomap_single_rw(0x60, timer);
279         io->set_iomap_single_rw(0x70, timer);
280         io->set_iomap_single_w(0x80, timer);
281 #ifdef _FMRCARD
282         io->set_iomap_single_w(0x90, cmos);
283 #endif
284         io->set_iomap_range_rw(0xa0, 0xaf, dma);
285         io->set_iomap_alias_rw(0x200, fdc, 0);
286         io->set_iomap_alias_rw(0x202, fdc, 1);
287         io->set_iomap_alias_rw(0x204, fdc, 2);
288         io->set_iomap_alias_rw(0x206, fdc, 3);
289         io->set_iomap_single_rw(0x208, floppy);
290         io->set_iomap_single_rw(0x20c, floppy);
291         io->set_iomap_single_rw(0x400, memory); // crtc
292         io->set_iomap_single_rw(0x402, memory); // crtc
293         io->set_iomap_single_rw(0x404, memory); // crtc
294         io->set_iomap_single_w(0x408, memory);  // crtc
295         io->set_iomap_single_rw(0x40a, memory); // crtc
296         io->set_iomap_single_rw(0x40c, memory); // crtc
297         io->set_iomap_single_rw(0x40e, memory); // crtc
298         io->set_iomap_alias_rw(0x500, crtc, 0);
299         io->set_iomap_alias_rw(0x502, crtc, 1);
300 #ifdef _FMR60
301         io->set_iomap_range_rw(0x520, 0x523, acrtc);
302 #endif
303         io->set_iomap_single_rw(0x600, keyboard);
304         io->set_iomap_single_rw(0x602, keyboard);
305         io->set_iomap_single_rw(0x604, keyboard);
306         io->set_iomap_alias_rw(0xa00, sio, 0);
307         io->set_iomap_alias_rw(0xa02, sio, 1);
308 //      io->set_iomap_single_r(0xa04, serial);
309 //      io->set_iomap_single_r(0xa06, serial);
310 //      io->set_iomap_single_w(0xa08, serial);
311         io->set_iomap_single_rw(0xc30, scsi);
312         io->set_iomap_single_rw(0xc32, scsi);
313         io->set_iomap_range_rw(0x3000, 0x3fff, cmos);
314         io->set_iomap_range_rw(0xfd98, 0xfd9f, memory); // crtc
315         io->set_iomap_single_rw(0xfda0, memory);        // crtc
316         
317         // initialize all devices
318 #if defined(__GIT_REPO_VERSION)
319         strncpy(_git_revision, __GIT_REPO_VERSION, sizeof(_git_revision) - 1);
320 #endif
321         for(DEVICE* device = first_device; device; device = device->next_device) {
322                 device->initialize();
323         }
324
325         for(int drv = 0; drv < USE_HARD_DISK; drv++) {
326 #ifdef OPEN_HARD_DISK_IN_RESET
327                 create_local_path(hd_file_path[drv], _MAX_PATH, _T("SCSI%d.DAT"), drv);
328 #else
329                 open_hard_disk_tmp(drv, create_local_path(_T("SCSI%d.DAT"), drv));
330 #endif
331         }
332         if(bios) {
333                 for(int drv = 0; drv < MAX_DRIVE; drv++) {
334                         bios->set_floppy_disk_handler(drv, fdc->get_disk_handler(drv));
335                 }
336                 for(int drv = 0; drv < USE_HARD_DISK; drv++) {
337                         bios->set_hard_disk_handler(drv, scsi_hdd[drv]->get_disk_handler(0));
338                 }
339         }
340         decl_state();
341 }
342
343 VM::~VM()
344 {
345         // delete all devices
346         for(DEVICE* device = first_device; device;) {
347                 DEVICE *next_device = device->next_device;
348                 device->release();
349                 delete device;
350                 device = next_device;
351         }
352 }
353
354 DEVICE* VM::get_device(int id)
355 {
356         for(DEVICE* device = first_device; device; device = device->next_device) {
357                 if(device->this_device_id == id) {
358                         return device;
359                 }
360         }
361         return NULL;
362 }
363
364 // ----------------------------------------------------------------------------
365 // drive virtual machine
366 // ----------------------------------------------------------------------------
367
368 void VM::reset()
369 {
370         // reset all devices
371         for(DEVICE* device = first_device; device; device = device->next_device) {
372                 device->reset();
373         }
374         // temporary fix...
375         for(DEVICE* device = first_device; device; device = device->next_device) {
376                 device->reset();
377         }
378         
379 #if defined(OPEN_HARD_DISK_IN_RESET)
380         // open/close hard disk images
381         for(int drv = 0; drv < USE_HARD_DISK; drv++) {
382                 if(hd_file_path[drv][0] != _T('\0')) {
383                         open_hard_disk_tmp(drv, hd_file_path[drv]);
384                 } else {
385                         close_hard_disk_tmp(drv);
386                 }
387         }
388 #endif
389 }
390
391 void VM::run()
392 {
393         event->drive();
394 }
395
396 // ----------------------------------------------------------------------------
397 // debugger
398 // ----------------------------------------------------------------------------
399
400 #ifdef USE_DEBUGGER
401 DEVICE *VM::get_cpu(int index)
402 {
403         if(index == 0) {
404                 return cpu;
405         }
406         return NULL;
407 }
408 #endif
409
410 // ----------------------------------------------------------------------------
411 // draw screen
412 // ----------------------------------------------------------------------------
413
414 void VM::draw_screen()
415 {
416         memory->draw_screen();
417 }
418
419 // ----------------------------------------------------------------------------
420 // soud manager
421 // ----------------------------------------------------------------------------
422
423 void VM::initialize_sound(int rate, int samples)
424 {
425         // init sound manager
426         event->initialize_sound(rate, samples);
427         
428         // init sound gen
429         pcm->initialize_sound(rate, 8000);
430 }
431
432 uint16_t* VM::create_sound(int* extra_frames)
433 {
434         return event->create_sound(extra_frames);
435 }
436
437 int VM::get_sound_buffer_ptr()
438 {
439         return event->get_sound_buffer_ptr();
440 }
441
442 #ifdef USE_SOUND_VOLUME
443 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
444 {
445         if(ch == 0) {
446                 pcm->set_volume(0, decibel_l, decibel_r);
447         } else if(ch == 1) {
448                 fdc->get_context_noise_seek()->set_volume(0, decibel_l, decibel_r);
449                 fdc->get_context_noise_head_down()->set_volume(0, decibel_l, decibel_r);
450                 fdc->get_context_noise_head_up()->set_volume(0, decibel_l, decibel_r);
451         }
452 }
453 #endif
454
455 // ----------------------------------------------------------------------------
456 // notify key
457 // ----------------------------------------------------------------------------
458
459 void VM::key_down(int code, bool repeat)
460 {
461         keyboard->key_down(code);
462 }
463
464 void VM::key_up(int code)
465 {
466         keyboard->key_up(code);
467 }
468
469 // ----------------------------------------------------------------------------
470 // user interface
471 // ----------------------------------------------------------------------------
472
473 void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
474 {
475         fdc->open_disk(drv, file_path, bank);
476         floppy->change_disk(drv);
477 }
478
479 void VM::close_floppy_disk(int drv)
480 {
481         fdc->close_disk(drv);
482 }
483
484 bool VM::is_floppy_disk_inserted(int drv)
485 {
486         return fdc->is_disk_inserted(drv);
487 }
488
489 void VM::is_floppy_disk_protected(int drv, bool value)
490 {
491         fdc->is_disk_protected(drv, value);
492 }
493
494 bool VM::is_floppy_disk_protected(int drv)
495 {
496         return fdc->is_disk_protected(drv);
497 }
498
499 uint32_t VM::is_floppy_disk_accessed()
500 {
501         uint32_t status = fdc->read_signal(0);
502         if(bios) {
503                 status |= bios->read_signal(0);
504         }
505         return status;
506 }
507
508 void VM::open_hard_disk(int drv, const _TCHAR* file_path)
509 {
510         if(drv < USE_HARD_DISK) {
511 #if defined(OPEN_HARD_DISK_IN_RESET)
512                 my_tcscpy_s(hd_file_path[drv], _MAX_PATH, file_path);
513 #else
514                 open_hard_disk_tmp(drv, file_path);
515 #endif
516         }
517 }
518
519 void VM::close_hard_disk(int drv)
520 {
521         if(drv < USE_HARD_DISK) {
522 #if defined(OPEN_HARD_DISK_IN_RESET)
523                 hd_file_path[drv][0] = _T('\0');
524 #else
525                 close_hard_disk_tmp(drv);
526 #endif
527         }
528 }
529
530 bool VM::is_hard_disk_inserted(int drv)
531 {
532         if(drv < USE_HARD_DISK) {
533 #if defined(OPEN_HARD_DISK_IN_RESET)
534                 return (hd_file_path[drv][0] != _T('\0'));
535 #else
536                 return is_hard_disk_inserted_tmp(drv);
537 #endif
538         }
539         return false;
540 }
541
542 uint32_t VM::is_hard_disk_accessed()
543 {
544         uint32_t status = 0;
545         for(int drv = 0; drv < USE_HARD_DISK; drv++) {
546                 if(scsi_hdd[drv]->get_disk_handler(0)->accessed()) {
547                         status |= 1 << drv;
548                 }
549         }
550         return status;
551 }
552
553 void VM::open_hard_disk_tmp(int drv, const _TCHAR* file_path)
554 {
555         if(drv < USE_HARD_DISK) {
556                 scsi_hdd[drv]->get_disk_handler(0)->open(file_path, 512);
557         }
558 }
559
560 void VM::close_hard_disk_tmp(int drv)
561 {
562         if(drv < USE_HARD_DISK) {
563                 scsi_hdd[drv]->get_disk_handler(0)->close();
564         }
565 }
566
567 bool VM::is_hard_disk_inserted_tmp(int drv)
568 {
569         if(drv < USE_HARD_DISK) {
570                 return scsi_hdd[drv]->get_disk_handler(0)->mounted();
571         }
572         return false;
573 }
574
575 bool VM::is_frame_skippable()
576 {
577         return event->is_frame_skippable();
578 }
579
580 void VM::update_config()
581 {
582         for(DEVICE* device = first_device; device; device = device->next_device) {
583                 device->update_config();
584         }
585 }
586
587 #define STATE_VERSION   6
588
589 #include "../../statesub.h"
590 #include "../../qt/gui/csp_logger.h"
591 extern CSP_Logger DLL_PREFIX_I *csp_logger;
592
593 void VM::decl_state(void)
594 {
595 #if defined(_FMR50)
596 #  if defined(HAS_I286)
597         state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FMR_50_I286_HEAD")), csp_logger);
598 #  elif defined(HAS_I386)
599         state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FMR_50_I386_HEAD")), csp_logger);
600 #  elif defined(HAS_I486)
601         state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FMR_50_I486_HEAD")), csp_logger);
602 #  elif defined(HAS_PENTIUM)
603         state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FMR_250_HEAD")), csp_logger);
604 #  else
605         state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FMR_50_SERIES_HEAD")), csp_logger);
606 #  endif        
607 #elif defined(_FMR60)
608 #  if defined(HAS_I286)
609         state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FMR_60_HEAD")), csp_logger);
610 #  elif defined(HAS_I386)
611         state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FMR_70_HEAD")), csp_logger);
612 #  elif defined(HAS_I486)
613         state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FMR_80_HEAD")), csp_logger);
614 #  elif defined(HAS_PENTIUM)
615         state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FMR_280_HEAD")), csp_logger);
616 #  else
617         state_entry = new csp_state_utils(STATE_VERSION, 0, (_TCHAR *)(_T("CSP::FMR_60_SERIES_HEAD")), csp_logger);
618 #  endif        
619 #endif
620         
621         for(DEVICE* device = first_device; device; device = device->next_device) {
622                 device->decl_state();
623         }
624 }
625
626 void VM::save_state(FILEIO* state_fio)
627 {
628         //state_fio->FputUint32(STATE_VERSION);
629         
630         if(state_entry != NULL) {
631                 state_entry->save_state(state_fio);
632         }
633         for(DEVICE* device = first_device; device; device = device->next_device) {
634                 device->save_state(state_fio);
635         }
636 }
637
638 bool VM::load_state(FILEIO* state_fio)
639 {
640         //if(state_fio->FgetUint32() != STATE_VERSION) {
641         //      return false;
642         //}
643         bool mb = false;
644         if(state_entry != NULL) {
645                 mb = state_entry->load_state(state_fio);
646         }
647         if(!mb) {
648                 emu->out_debug_log("INFO: HEADER DATA ERROR");
649                 return false;
650         }
651         for(DEVICE* device = first_device; device; device = device->next_device) {
652                 if(!device->load_state(state_fio)) {
653                         return false;
654                 }
655         }
656         return true;
657 }
658