OSDN Git Service

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