OSDN Git Service

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