OSDN Git Service

[General][VM][FM7][CMake] Build at least eFM77AV40EX.
[csp-qt/common_source_project-fm7.git] / source / src / vm / fm7 / fm7.cpp
1 /*
2  * FM7 -> VM
3  * (C) 2015 K.Ohta <whatisthis.sowhat _at_ gmail.com>
4  * History:
5  *   Feb 27, 2015 : Initial
6  */
7
8 #include "fm7.h"
9 #include "../../emu.h"
10 #include "../../config.h"
11 #include "../device.h"
12 #include "../event.h"
13 #include "../memory.h"
14 #include "../prnfile.h"
15
16 #ifdef USE_DEBUGGER
17 #include "../debugger.h"
18 #endif
19
20 #include "../datarec.h"
21 #include "../disk.h"
22
23 #include "../mc6809.h"
24 #include "../z80.h"
25 #include "../mb8877.h"
26
27 #include "../pcm1bit.h"
28 #include "../ym2203.h"
29 #if defined(_FM77AV_VARIANTS)
30 #include "mb61vh010.h"
31 #include "../beep.h"
32 #endif
33 #if defined(HAS_DMA)
34 #include "hd6844.h"
35 #endif
36
37 #if defined(USE_LED_DEVICE)
38 #include "./dummydevice.h"
39 #else
40 #define SIG_DUMMYDEVICE_BIT0 0
41 #define SIG_DUMMYDEVICE_BIT1 1
42 #define SIG_DUMMYDEVICE_BIT2 2
43 #endif
44
45 #include "./fm7_mainio.h"
46 #include "./fm7_mainmem.h"
47 #include "./fm7_display.h"
48 #include "./fm7_keyboard.h"
49 #include "./joystick.h"
50
51 #include "./kanjirom.h"
52
53 VM::VM(EMU* parent_emu): emu(parent_emu)
54 {
55         
56         first_device = last_device = NULL;
57 #if defined(_FM8)
58         psg = NULL;
59 #else   
60 # if defined(_FM77AV_VARIANTS)
61         opn[0] = opn[1] = opn[2] = NULL;
62 # else   
63         opn[0] = opn[1] = opn[2] = psg = NULL; 
64 # endif
65 #endif
66         dummy = new DEVICE(this, emu);  // must be 1st device
67         event = new EVENT(this, emu);   // must be 2nd device
68         
69         dummycpu = new DEVICE(this, emu);
70         maincpu = new MC6809(this, emu);
71         subcpu = new MC6809(this, emu);
72 #ifdef WITH_Z80
73         z80cpu = new Z80(this, emu);
74 #endif
75         // basic devices
76 #if defined(_FM8) || defined(_FM7) || defined(_FMNEW7)
77         if((config.dipswitch & FM7_DIPSW_CONNECT_KANJIROM) != 0) {
78                 kanjiclass1 = new KANJIROM(this, emu, false);
79         }
80 #else
81         kanjiclass1 = new KANJIROM(this, emu, false);
82 #endif  
83 #ifdef CAPABLE_KANJI_CLASS2
84         kanjiclass2 = new KANJIROM(this, emu, true);
85 #endif
86         joystick  = new JOYSTICK(this, emu);
87         
88         // I/Os
89         drec = new DATAREC(this, emu);
90         pcm1bit = new PCM1BIT(this, emu);
91         fdc  = new MB8877(this, emu);
92 #if defined(HAS_DMA)
93         dmac = new HD6844(this, emu);
94 #endif   
95 #if defined(_FM8)
96         psg = new YM2203(this, emu);
97 #else   
98         opn[0] = new YM2203(this, emu); // OPN
99         opn[1] = new YM2203(this, emu); // WHG
100         opn[2] = new YM2203(this, emu); // THG
101 # if !defined(_FM77AV_VARIANTS)
102         psg = new YM2203(this, emu);
103 # endif
104 #endif
105 #if defined(_FM77AV_VARIANTS)
106         alu = new MB61VH010(this, emu);
107         keyboard_beep = new BEEP(this, emu);
108 #endif  
109         display = new DISPLAY(this, emu);       
110         printer = new PRNFILE(this, emu);
111         mainio  = new FM7_MAINIO(this, emu);
112         mainmem = new FM7_MAINMEM(this, emu);
113         keyboard = new KEYBOARD(this, emu);
114
115 #if defined(USE_LED_DEVICE)
116         led_terminate = new DUMMYDEVICE(this, emu);
117 #else
118         led_terminate = new DEVICE(this, emu);
119 #endif
120         // MEMORIES must set before initialize().
121         maincpu->set_context_mem(mainmem);
122         subcpu->set_context_mem(display);
123 #ifdef WITH_Z80
124         z80cpu->set_context_mem(mainmem);
125 #endif
126 #ifdef USE_DEBUGGER
127         maincpu->set_context_debugger(new DEBUGGER(this, emu));
128         subcpu->set_context_debugger(new DEBUGGER(this, emu));
129 # ifdef WITH_Z80
130         z80cpu->set_context_debugger(new DEBUGGER(this, emu));
131 # endif
132 #endif
133         connect_bus();
134         initialize();
135 }
136
137 VM::~VM()
138 {
139         // delete all devices
140         for(DEVICE* device = first_device; device;) {
141                 DEVICE *next_device = device->next_device;
142                 device->release();
143                 delete device;
144                 device = next_device;
145         }
146 }
147
148 DEVICE* VM::get_device(int id)
149 {
150         for(DEVICE* device = first_device; device; device = device->next_device) {
151                 if(device->this_device_id == id) {
152                         return device;
153                 }
154         }
155         return NULL;
156 }
157
158
159 void VM::initialize(void)
160 {
161         clock_low = false;
162         
163 }
164
165
166 void VM::connect_bus(void)
167 {
168         uint32_t mainclock;
169         uint32_t subclock;
170
171         /*
172          * CLASS CONSTRUCTION
173          *
174          * VM 
175          *  |-> MAINCPU -> MAINMEM -> MAINIO -> MAIN DEVICES
176          *  |             |        |      
177          *  | -> SUBCPU  -> SUBMEM  -> SUBIO -> SUB DEVICES
178          *  | -> DISPLAY
179          *  | -> KEYBOARD
180          *
181          *  MAINMEM can access SUBMEM/IO, when SUBCPU is halted.
182          *  MAINMEM and SUBMEM can access DISPLAY and KEYBOARD with exclusive.
183          *  MAINCPU can access MAINMEM.
184          *  SUBCPU  can access SUBMEM.
185          *  DISPLAY : R/W from MAINCPU and SUBCPU.
186          *  KEYBOARD : R/W
187          *
188          */
189         event->set_frames_per_sec(FRAMES_PER_SEC);
190         event->set_lines_per_frame(LINES_PER_FRAME);
191         event->set_context_cpu(dummycpu, (CPU_CLOCKS * 3) / 8); // MAYBE FIX With eFM77AV40/20.
192         //event->set_context_cpu(dummycpu, (int)(4.9152 * 1000.0 * 1000.0 / 4.0));
193         
194 #if defined(_FM8)
195         mainclock = MAINCLOCK_SLOW;
196         subclock = SUBCLOCK_SLOW;
197 #else
198         if(config.cpu_type == 0) {
199                 // 2MHz
200                 subclock = SUBCLOCK_NORMAL;
201                 mainclock = MAINCLOCK_NORMAL;
202         } else {
203                 // 1.2MHz
204                 mainclock = MAINCLOCK_SLOW;
205                 subclock = SUBCLOCK_SLOW;
206         }
207         //if((config.dipswitch & FM7_DIPSW_CYCLESTEAL) != 0) subclock = subclock / 3;
208 #endif
209         event->set_context_cpu(maincpu, mainclock);
210         event->set_context_cpu(subcpu,  subclock);
211    
212 #ifdef WITH_Z80
213         event->set_context_cpu(z80cpu,  4000000);
214         z80cpu->write_signal(SIG_CPU_BUSREQ, 1, 1);
215 #endif
216
217         event->set_context_sound(pcm1bit);
218 #if defined(_FM8)
219         event->set_context_sound(psg);
220         event->set_context_sound(drec);
221 #else
222         event->set_context_sound(opn[0]);
223         event->set_context_sound(opn[1]);
224         event->set_context_sound(opn[2]);
225 # if !defined(_FM77AV_VARIANTS)
226         event->set_context_sound(psg);
227 # endif
228         event->set_context_sound(drec);
229 # if defined(_FM77AV_VARIANTS)
230         event->set_context_sound(keyboard_beep);
231 # endif
232 #endif   
233 #if !defined(_FM77AV_VARIANTS) && !defined(_FM77L4)
234         event->register_frame_event(display);
235 #endif  
236         mainio->set_context_maincpu(maincpu);
237         mainio->set_context_subcpu(subcpu);
238         
239         mainio->set_context_display(display);
240 #if defined(_FM8) || defined(_FM7) || defined(_FMNEW7)
241         if((config.dipswitch & FM7_DIPSW_CONNECT_KANJIROM) != 0) {
242                 mainio->set_context_kanjirom_class1(kanjiclass1);
243         }
244 #else
245         mainio->set_context_kanjirom_class1(kanjiclass1);
246 #endif  
247         mainio->set_context_mainmem(mainmem);
248         mainio->set_context_keyboard(keyboard);
249         mainio->set_context_printer(printer);
250         mainio->set_context_printer_reset(printer, SIG_PRINTER_RESET, 0xffffffff); 
251 #if defined(CAPABLE_KANJI_CLASS2)
252         mainio->set_context_kanjirom_class2(kanjiclass2);
253 #endif
254
255         keyboard->set_context_break_line(mainio, FM7_MAINIO_PUSH_BREAK, 0xffffffff);
256         keyboard->set_context_int_line(mainio, FM7_MAINIO_KEYBOARDIRQ, 0xffffffff);
257         keyboard->set_context_int_line(display, SIG_FM7_SUB_KEY_FIRQ, 0xffffffff);
258 #if defined(_FM77AV_VARIANTS)
259         keyboard->set_context_beep(keyboard_beep);
260 #endif  
261         keyboard->set_context_rxrdy(display, SIG_FM7KEY_RXRDY, 0x01);
262         keyboard->set_context_key_ack(display, SIG_FM7KEY_ACK, 0x01);
263         keyboard->set_context_ins_led( led_terminate, SIG_DUMMYDEVICE_BIT0, 0xffffffff);
264         keyboard->set_context_caps_led(led_terminate, SIG_DUMMYDEVICE_BIT1, 0xffffffff);
265         keyboard->set_context_kana_led(led_terminate, SIG_DUMMYDEVICE_BIT2, 0xffffffff);
266    
267         drec->set_context_ear(mainio, FM7_MAINIO_CMT_RECV, 0xffffffff);
268         //drec->set_context_remote(mainio, FM7_MAINIO_CMT_REMOTE, 0xffffffff);
269         mainio->set_context_datarec(drec);
270         
271         mainmem->set_context_mainio(mainio);
272         mainmem->set_context_display(display);
273         mainmem->set_context_maincpu(maincpu);
274 #if defined(CAPABLE_DICTROM)
275         mainmem->set_context_kanjirom_class1(kanjiclass1);
276 #endif  
277         display->set_context_mainio(mainio);
278         display->set_context_subcpu(subcpu);
279         display->set_context_keyboard(keyboard);
280
281         mainio->set_context_clock_status(mainmem, FM7_MAINIO_CLOCKMODE, 0xffffffff);
282         mainio->set_context_clock_status(display, SIG_DISPLAY_CLOCK, 0xffffffff);
283         
284         subcpu->set_context_bus_halt(display, SIG_FM7_SUB_HALT, 0xffffffff);
285         subcpu->set_context_bus_halt(mainmem, SIG_FM7_SUB_HALT, 0xffffffff);
286
287 #if defined(_FM77_VARIANTS) || defined(_FM77AV_VARIANTS)
288         display->set_context_kanjiclass1(kanjiclass1);
289 #endif  
290 #if defined(CAPABLE_KANJI_CLASS2)
291         display->set_context_kanjiclass2(kanjiclass2);
292 #endif   
293 #if defined(_FM77AV_VARIANTS)
294         display->set_context_alu(alu);
295         alu->set_context_memory(display);
296 #endif  
297         // Palette, VSYNC, HSYNC, Multi-page, display mode. 
298         mainio->set_context_display(display);
299         
300         //FDC
301         mainio->set_context_fdc(fdc);
302         fdc->set_context_irq(mainio, FM7_MAINIO_FDC_IRQ, 0x1);
303         fdc->set_context_drq(mainio, FM7_MAINIO_FDC_DRQ, 0x1);
304         // SOUND
305         mainio->set_context_beep(pcm1bit);
306 #if defined(_FM8)       
307         mainio->set_context_psg(psg);
308 #else
309 # if !defined(_FM77AV_VARIANTS)
310         mainio->set_context_psg(psg);
311 # endif
312         opn[0]->set_context_irq(mainio, FM7_MAINIO_OPN_IRQ, 0xffffffff);
313         mainio->set_context_opn(opn[0], 0);
314         //joystick->set_context_opn(opn[0]);
315         mainio->set_context_joystick(joystick);
316         opn[0]->set_context_port_b(joystick, FM7_JOYSTICK_MOUSE_STROBE, 0xff, 0);
317         
318         opn[1]->set_context_irq(mainio, FM7_MAINIO_WHG_IRQ, 0xffffffff);
319         mainio->set_context_opn(opn[1], 1);
320         opn[2]->set_context_irq(mainio, FM7_MAINIO_THG_IRQ, 0xffffffff);
321         mainio->set_context_opn(opn[2], 2);
322 #endif   
323         subcpu->set_context_bus_halt(display, SIG_FM7_SUB_HALT, 0xffffffff);
324         subcpu->set_context_bus_clr(display, SIG_FM7_SUB_USE_CLR, 0x0000000f);
325    
326         event->register_frame_event(joystick);
327 #if defined(HAS_DMA)
328         dmac->set_context_src(fdc, 0);
329         dmac->set_context_dst(mainmem, 0);
330         dmac->set_context_int_line(mainio, 0, FM7_MAINIO_DMA_INT, 0xffffffff);
331         dmac->set_context_drq_line(maincpu, 1, SIG_CPU_BUSREQ, 0xffffffff);
332         mainio->set_context_dmac(dmac);
333 #endif
334         for(DEVICE* device = first_device; device; device = device->next_device) {
335                 device->initialize();
336         }
337         for(int i = 0; i < 2; i++) {
338 #if defined(_FM77AV20) || defined(_FM77AV20EX) || \
339         defined(_FM77AV40SX) || defined(_FM77AV40EX) || defined(_FM77AV40SX)
340                 fdc->set_drive_type(i, DRIVE_TYPE_2DD);
341 #else
342                 fdc->set_drive_type(i, DRIVE_TYPE_2D);
343 #endif
344 #if defined(_FM77AV_VARIANTS)
345                 fdc->set_drive_rpm(i, 360);
346 #else           
347                 fdc->set_drive_rpm(i, 360);
348 #endif          
349                 fdc->set_drive_mfm(i, true);
350         }
351 #if defined(_FM77) || defined(_FM77L4)
352         for(int i = 2; i < 4; i++) {
353                 fdc->set_drive_type(i, DRIVE_TYPE_2HD);
354                 fdc->set_drive_rpm(i, 360);
355                 fdc->set_drive_mfm(i, true);
356         }
357 #endif
358         
359 }  
360
361 void VM::update_config()
362 {
363         uint32_t vol1, vol2, tmpv;
364         int ii, i_limit;
365
366         for(DEVICE* device = first_device; device; device = device->next_device) {
367                 device->update_config();
368         }
369         //update_dipswitch();
370 }
371
372 void VM::reset()
373 {
374         // reset all devices
375         for(DEVICE* device = first_device; device; device = device->next_device) {
376                 device->reset();
377         }
378 #if !defined(_FM77AV_VARIANTS) || defined(_FM8)
379         psg->set_reg(0x27, 0); // stop timer
380         psg->set_reg(0x2e, 0);  // set prescaler
381         psg->write_signal(SIG_YM2203_MUTE, 0x00, 0x01); // Okay?
382 #endif
383 #if !defined(_FM8)
384         for(int i = 0; i < 3; i++) {
385                 opn[i]->set_reg(0x27, 0); // stop timer
386                 opn[i]->set_reg(0x2e, 0);       // set prescaler
387                 opn[i]->write_signal(SIG_YM2203_MUTE, 0x00, 0x01); // Okay?
388         }
389 #endif
390 }
391
392 void VM::special_reset()
393 {
394         // BREAK + RESET
395         mainio->write_signal(FM7_MAINIO_PUSH_BREAK, 1, 1);
396         mainio->reset();
397         mainmem->reset();
398         
399 #if defined(FM77AV_VARIANTS)    
400         mainio->write_signal(FM7_MAINIO_HOT_RESET, 1, 1);
401 #endif  
402         display->reset();
403         subcpu->reset();
404         mainio->write_signal(FM7_MAINIO_PUSH_BREAK, 1, 1);
405         maincpu->reset();
406         event->register_event(mainio, EVENT_UP_BREAK, 10000.0 * 1000.0, false, NULL);
407 }
408
409 void VM::run()
410 {
411         event->drive();
412 }
413
414 double VM::get_frame_rate()
415 {
416         return event->get_frame_rate();
417 }
418
419 #if defined(USE_LED_DEVICE)
420 uint32_t VM::get_led_status()
421 {
422         return led_terminate->read_signal(SIG_DUMMYDEVICE_READWRITE);
423 }
424 #endif // USE_LED_DEVICE
425
426
427 // ----------------------------------------------------------------------------
428 // debugger
429 // ----------------------------------------------------------------------------
430
431 #ifdef USE_DEBUGGER
432 DEVICE *VM::get_cpu(int index)
433 {
434         if(index == 0) {
435                 return maincpu;
436         } else if(index == 1) {
437                 return subcpu;
438         }
439 #if defined(_WITH_Z80)
440         else if(index == 2) {
441                 return z80cpu;
442         }
443 #endif
444         return NULL;
445 }
446 #endif
447
448 // ----------------------------------------------------------------------------
449 // draw screen
450 // ----------------------------------------------------------------------------
451
452 void VM::draw_screen()
453 {
454         display->draw_screen();
455 }
456
457 uint32_t VM::get_access_lamp_status()
458 {
459         uint32_t status = fdc->read_signal(0);
460         return (status & (1 | 4)) ? 1 : (status & (2 | 8)) ? 2 : 0;
461 }
462
463 void VM::initialize_sound(int rate, int samples)
464 {
465         // init sound manager
466         event->initialize_sound(rate, samples);
467         // init sound gen
468 #if defined(_FM8)
469         psg->initialize_sound(rate, (int)(4.9152 * 1000.0 * 1000.0 / 4.0), samples, 0, 0);
470 #else   
471         opn[0]->initialize_sound(rate, (int)(4.9152 * 1000.0 * 1000.0 / 4.0), samples, 0, 0);
472         opn[1]->initialize_sound(rate, (int)(4.9152 * 1000.0 * 1000.0 / 4.0), samples, 0, 0);
473         opn[2]->initialize_sound(rate, (int)(4.9152 * 1000.0 * 1000.0 / 4.0), samples, 0, 0);
474 # if !defined(_FM77AV_VARIANTS)   
475         psg->initialize_sound(rate, (int)(4.9152 * 1000.0 * 1000.0 / 4.0), samples, 0, 0);
476 # endif
477 # if defined(_FM77AV_VARIANTS)
478         keyboard_beep->initialize_sound(rate, 2400.0, 512);
479 # endif
480 #endif  
481         pcm1bit->initialize_sound(rate, 2000);
482         //drec->init_pcm(rate, 0);
483 }
484
485 uint16* VM::create_sound(int* extra_frames)
486 {
487         uint16* p = event->create_sound(extra_frames);
488         return p;
489 }
490
491 int VM::get_sound_buffer_ptr()
492 {
493         int pos = event->get_sound_buffer_ptr();
494         return pos; 
495 }
496
497 #ifdef USE_SOUND_VOLUME
498 void VM::set_sound_device_volume(int ch, int decibel_l, int decibel_r)
499 {
500 #if !defined(_FM77AV_VARIANTS)
501         if(ch-- == 0) {
502                 psg->set_volume(0, decibel_l, decibel_r);
503                 psg->set_volume(1, decibel_l, decibel_r);
504         } else
505 #endif
506 #if !defined(_FM8)              
507         if(ch-- == 0) {
508                 opn[0]->set_volume(0, decibel_l, decibel_r);
509         } else if(ch-- == 0) {
510                 opn[0]->set_volume(1, decibel_l, decibel_r);
511         } else if(ch-- == 0) {
512                 opn[1]->set_volume(0, decibel_l, decibel_r);
513         } else if(ch-- == 0) {
514                 opn[1]->set_volume(1, decibel_l, decibel_r);
515         } else if(ch-- == 0) {
516                 opn[2]->set_volume(0, decibel_l, decibel_r);
517         } else if(ch-- == 0) {
518                 opn[2]->set_volume(1, decibel_l, decibel_r);
519         } else
520 #endif  
521         if(ch-- == 0) {
522                 pcm1bit->set_volume(0, decibel_l, decibel_r);
523         } else if(ch-- == 0) {
524                 drec->set_volume(0, decibel_l, decibel_r);
525         }
526 }
527 #endif
528
529 // ----------------------------------------------------------------------------
530 // notify key
531 // ----------------------------------------------------------------------------
532
533 void VM::key_down(int code, bool repeat)
534 {
535         if(!repeat) {
536                 keyboard->key_down(code);
537         }
538 }
539
540 void VM::key_up(int code)
541 {
542         keyboard->key_up(code);
543 }
544
545 // ----------------------------------------------------------------------------
546 // user interface
547 // ----------------------------------------------------------------------------
548
549 void VM::open_floppy_disk(int drv, const _TCHAR* file_path, int bank)
550 {
551         fdc->open_disk(drv, file_path, bank);
552 }
553
554 void VM::close_floppy_disk(int drv)
555 {
556         fdc->close_disk(drv);
557 }
558
559 bool VM::is_floppy_disk_inserted(int drv)
560 {
561         return fdc->is_disk_inserted(drv);
562 }
563
564 void VM::is_floppy_disk_protected(int drv, bool value)
565 {
566         fdc->is_disk_protected(drv, value);
567 }
568
569 bool VM::is_floppy_disk_protected(int drv)
570 {
571         return fdc->is_disk_protected(drv);
572 }
573
574 void VM::play_tape(const _TCHAR* file_path)
575 {
576         drec->play_tape(file_path);
577 }
578
579 void VM::rec_tape(const _TCHAR* file_path)
580 {
581         drec->rec_tape(file_path);
582 }
583
584 void VM::close_tape()
585 {
586         drec->close_tape();
587 }
588
589 bool VM::is_tape_inserted()
590 {
591         return drec->is_tape_inserted();
592 }
593
594 bool VM::is_tape_playing()
595 {
596         return drec->is_tape_playing();
597 }
598
599 bool VM::is_tape_recording()
600 {
601         return drec->is_tape_recording();
602 }
603
604 int VM::get_tape_position()
605 {
606         return drec->get_tape_position();
607 }
608
609 void VM::push_play()
610 {
611         drec->set_ff_rew(0);
612         drec->set_remote(true);
613 }
614
615
616 void VM::push_stop()
617 {
618         drec->set_remote(false);
619 }
620
621 void VM::push_fast_forward()
622 {
623         drec->set_ff_rew(1);
624         drec->set_remote(true);
625 }
626
627 void VM::push_fast_rewind()
628 {
629         drec->set_ff_rew(-1);
630         drec->set_remote(true);
631 }
632
633 void VM::push_apss_forward()
634 {
635         drec->do_apss(1);
636 }
637
638 void VM::push_apss_rewind()
639 {
640         drec->do_apss(-1);
641 }
642
643 bool VM::is_frame_skippable()
644 {
645         return event->is_frame_skippable();
646 }
647
648 void VM::update_dipswitch()
649 {
650         // bit0         0=High 1=Standard
651         // bit2         0=5"2D 1=5"2HD
652   //    io->set_iovalue_single_r(0x1ff0, (config.monitor_type & 1) | ((config.drive_type & 1) << 2));
653 }
654
655 void VM::set_cpu_clock(DEVICE *cpu, uint32_t clocks) {
656         event->set_secondary_cpu_clock(cpu, clocks);
657 }
658
659 #define STATE_VERSION   2
660 void VM::save_state(FILEIO* state_fio)
661 {
662         state_fio->FputUint32_BE(STATE_VERSION);
663         
664         for(DEVICE* device = first_device; device; device = device->next_device) {
665                 device->save_state(state_fio);
666         }
667         { // V1
668                 state_fio->FputBool(clock_low);
669         }
670 }
671
672 bool VM::load_state(FILEIO* state_fio)
673 {
674         uint32_t version = state_fio->FgetUint32_BE();
675         int i = 1;
676         if(version > STATE_VERSION) {
677                 return false;
678         }
679         for(DEVICE* device = first_device; device; device = device->next_device) {
680                 if(!device->load_state(state_fio)) {
681                         printf("Load Error: DEVID=%d\n", device->this_device_id);
682                         return false;
683                 }
684         }
685         if(version >= 1) {// V1 
686                 clock_low   = state_fio->FgetBool();
687                 if(version == 2) return true;
688         }
689         return false;
690 }
691
692 #ifdef USE_DIG_RESOLUTION
693 void VM::get_screen_resolution(int *w, int *h)
694 {
695         switch(display->get_screen_mode()) {
696         case DISPLAY_MODE_8_200L:
697         case DISPLAY_MODE_8_200L_TEXT:
698                 *w = 640;
699                 *h = 200;
700                 break;
701         case DISPLAY_MODE_8_400L:
702         case DISPLAY_MODE_8_400L_TEXT:
703                 *w = 640;
704                 *h = 400;
705                 break;
706         case DISPLAY_MODE_4096:
707         case DISPLAY_MODE_256k:
708                 *w = 320;
709                 *h = 200;
710                 break;
711         default:
712                 *w = 640;
713                 *h = 200;
714                 break;
715         }
716 }
717 #endif
718
719 bool VM::is_screen_changed()
720 {
721         bool f = true;
722 #if defined(USE_MINIMUM_RENDERING)
723         f = display->screen_update();
724         display->reset_screen_update();
725 #endif  
726         return f;
727 }