OSDN Git Service

[VM] TRY:Use namespace {VMNAME} to separate around VMs. This feature still apply...
[csp-qt/common_source_project-fm7.git] / source / src / vm / fm7 / fm7.h
1 /*
2         FUJITSU FM7 Emulator 'eFM7'
3
4         Author : K.Ohta
5         Date   : 2015.01.01-
6
7         [ virtual machine ]
8 */
9
10 #ifndef _FM7_H_
11 #define _FM7_H_
12
13 #define USE_TAPE 1
14 #define USE_TAPE_PTR
15 #define USE_TAPE_BUTTON
16 #define USE_SCANLINE
17 #define USE_DIPSWITCH
18 #define USE_CPU_TYPE 2
19 #define USE_SPECIAL_RESET
20 #define USE_LED_DEVICE                  3
21 #define USE_MINIMUM_RENDERING 1
22 #define USE_MOUSE
23 #define USE_JOYSTICK
24 #define USE_JOY_BUTTON_CAPTIONS
25 #define USE_PRINTER
26 #define USE_PRINTER_TYPE 4
27 #define USE_AY_3_8910_AS_PSG
28 #define SUPPORT_VARIABLE_TIMING
29
30 #define INDEPENDENT_CAPS_KANA_LED
31 #define NOTIFY_KEY_DOWN
32 //#define NOTIFY_KEY_UP
33 #define NOTIFY_KEY_DOWN_LR_SHIFT
34 #define NOTIFY_KEY_DOWN_LR_MENU
35 #define USE_KEY_LOCKED
36 #define USE_ALT_F10_KEY
37 #define USE_AUTO_KEY            5
38 #define USE_AUTO_KEY_RELEASE    6
39 #define USE_AUTO_KEY_NUMPAD
40 #define USE_SCREEN_FILTER
41 #define USE_STATE
42 #define USE_DEBUGGER
43 #define DATAREC_SOUND
44 #define USE_DIG_RESOLUTION
45
46 #define CPU_TYPE_DEFAULT 0
47
48 #if defined(_FM8)
49 #define DEVICE_NAME             "FUJITSU FM-8"
50 #define CONFIG_NAME             "fm8"
51 #define CAPABLE_Z80
52 #define DIPSWITCH_DEFAULT 0x00000000 
53 #define USE_BUBBLE 2
54 #define BASE_BUBBLE_NUM 0
55 #define MAX_DRIVE  4
56
57 #undef CPU_TYPE_DEFAULT
58 #define CPU_TYPE_DEFAULT 1
59 #define USE_GREEN_DISPLAY
60 #define USE_MONITOR_TYPE 2
61
62 #elif defined(_FM7)
63 #define DEVICE_NAME             "FUJITSU FM-7"
64 #define CONFIG_NAME             "fm7"
65 #define CAPABLE_Z80
66 #define DIPSWITCH_DEFAULT 0x000000000 
67 #define MAX_DRIVE  4
68 #define CAPABLE_JCOMMCARD 1
69 #define USE_GREEN_DISPLAY
70 #define USE_MONITOR_TYPE 2
71
72 #elif defined(_FMNEW7)
73 #define DEVICE_NAME             "FUJITSU FM-NEW7"
74 #define CONFIG_NAME             "fmnew7"
75 #define CAPABLE_Z80
76 #define DIPSWITCH_DEFAULT 0x000000000 
77 #define MAX_DRIVE  4
78 #define CAPABLE_JCOMMCARD 1
79 #define USE_GREEN_DISPLAY
80 #define USE_MONITOR_TYPE 2
81
82 #elif defined(_FM77) || defined(_FM77L2)
83 # if defined(_FM77)
84 #define DEVICE_NAME             "FUJITSU FM-77"
85 #define CONFIG_NAME             "fm77"
86 #define DIPSWITCH_DEFAULT 0x00000001
87 # else
88 #define DEVICE_NAME             "FUJITSU FM-77L2"
89 #define CONFIG_NAME             "fm77l2"
90 #define DIPSWITCH_DEFAULT 0x00000003 
91 # endif
92 //#define USE_DRIVE_TYPE
93 #define _FM77_VARIANTS
94 #define CAPABLE_Z80
95 # ifndef FM77_EXRAM_BANKS
96 #   define FM77_EXRAM_BANKS     3
97 # endif
98 #define MAX_DRIVE  4
99 #define CAPABLE_JCOMMCARD 1
100 #define HAS_2HD
101 #define USE_GREEN_DISPLAY
102 #define USE_MONITOR_TYPE 2
103
104 #elif defined(_FM77L4)
105 #define DEVICE_NAME             "FUJITSU FM-77L4"
106 #define CONFIG_NAME             "fm77l4"
107 #define HAS_TEXTVRAM
108 #define HAS_2HD
109 #define HAS_CYCLESTEAL
110 #define HAS_400LINECARD
111 //#define CAPABLE_KANJI_CLASS2
112 #define _FM77_VARIANTS
113 # define CAPABLE_Z80
114 # ifndef FM77_EXRAM_BANKS
115 #  define FM77_EXRAM_BANKS      3
116 # endif
117 #define DIPSWITCH_DEFAULT 0x00000003 
118 #define MAX_DRIVE  4
119 #define CAPABLE_JCOMMCARD 1
120 #define USE_GREEN_DISPLAY
121 #define USE_MONITOR_TYPE 2
122
123 #elif defined(_FM77AV)
124 #define DEVICE_NAME             "FUJITSU FM77AV"
125 #define CONFIG_NAME             "fm77av"
126 #define _FM77AV_VARIANTS
127 #define DIPSWITCH_DEFAULT 0x80000001 
128 #define MAX_DRIVE  2
129 #define CAPABLE_JCOMMCARD 1
130 #define CAPABLE_DICTROM
131
132 #elif defined(_FM77AV20)
133 #define DEVICE_NAME             "FUJITSU FM77AV20"
134 #define CONFIG_NAME             "fm77av20"
135 #define _FM77AV_VARIANTS
136 #define HAS_2DD_2D
137 #define CAPABLE_DICTROM
138 //#define USE_DRIVE_TYPE 2
139 #define CAPABLE_KANJI_CLASS2
140 #define DIPSWITCH_DEFAULT 0x80000001 
141 #define MAX_DRIVE  2
142
143 #elif defined(_FM77AV20EX)
144 #define DEVICE_NAME             "FUJITSU FM77AV20EX"
145 #define CONFIG_NAME             "fm77av20ex"
146 #define _FM77AV_VARIANTS
147 #define HAS_2DD_2D
148 #define HAS_DMA
149 //#define USE_DRIVE_TYPE 2
150 #define CAPABLE_DICTROM
151 #define CAPABLE_KANJI_CLASS2
152 #define DIPSWITCH_DEFAULT 0x80000001 
153 #define MAX_DRIVE  4
154
155 #elif defined(_FM77AV40)
156 #define DEVICE_NAME             "FUJITSU FM77AV40"
157 #define CONFIG_NAME             "fm77av40"
158 #define _FM77AV_VARIANTS
159 #define HAS_2DD_2D
160 #define HAS_DMA
161 //#define USE_DRIVE_TYPE 2
162 #define CAPABLE_DICTROM
163 #define HAS_400LINE_AV
164 #define CAPABLE_KANJI_CLASS2
165 #ifndef FM77_EXRAM_BANKS
166 #define FM77_EXRAM_BANKS        12
167 #endif
168 #define DIPSWITCH_DEFAULT 0x8000000d 
169 #define MAX_DRIVE  4
170
171 #elif defined(_FM77AV40EX)
172 #define DEVICE_NAME             "FUJITSU FM77AV40EX"
173 #define CONFIG_NAME             "fm77av40ex"
174 #define _FM77AV_VARIANTS
175 #define HAS_2DD_2D
176 #define HAS_DMA
177 //#define USE_DRIVE_TYPE 2
178 #define CAPABLE_DICTROM
179 #define HAS_400LINE_AV
180 #define CAPABLE_KANJI_CLASS2
181 #ifndef FM77_EXRAM_BANKS
182 #define FM77_EXRAM_BANKS        12
183 #endif
184 #define DIPSWITCH_DEFAULT 0x8000000d 
185 #define MAX_DRIVE  4
186
187 #elif defined(_FM77AV40SX)
188 #define DEVICE_NAME             "FUJITSU FM77AV40SX"
189 #define CONFIG_NAME             "fm77av40sx"
190 #define _FM77AV_VARIANTS
191 #define HAS_2DD_2D
192 #define HAS_DMA
193 //#define USE_DRIVE_TYPE 2
194 #define CAPABLE_DICTROM
195 #define HAS_400LINE_AV
196 #define CAPABLE_KANJI_CLASS2
197 # ifndef FM77_EXRAM_BANKS
198 #  define FM77_EXRAM_BANKS      12
199 # endif
200 #define DIPSWITCH_DEFAULT 0x8000000d 
201 #define MAX_DRIVE  4
202
203 #endif
204
205 #if defined(_FM8)
206 #define USE_SOUND_TYPE          2
207 #else
208 #define USE_MOUSE_TYPE          3
209 #define USE_SOUND_TYPE          8
210 #endif
211
212 #ifdef _FM77AV_VARIANTS
213 #define HAS_MMR
214 #define HAS_CYCLESTEAL
215 #elif defined(_FM77_VARIANTS)
216 #define HAS_MMR
217 #define HAS_CYCLESTEAL
218 #define CAPABLE_Z80
219 #endif
220
221 #define USE_BOOT_MODE         8
222
223 // 0 = PSG or NONE
224 // 1 = OPN (+PSG)
225 // 2 = WHG (+PSG)
226 // 3 = WHG + OPN (+PSG)
227 // 4 = THG  (+PSG)
228 // 5 = THG + OPN (+PSG)
229 // 6 = THG + WHG (+PSG)
230 // 7 = THG + WHG + OPN (+PSG)
231 #if defined(_FM8)
232 // WITHOUT PSG?
233 #define SOUND_TYPE_DEFAULT      0
234 #elif defined(_FM7) || defined(_FMNEW7) || defined(_FM77_VARIANTS)
235 // PSG ONLY
236 #define SOUND_TYPE_DEFAULT      0
237 #elif defined(_FM77AV_VARIANTS)
238 // OPN
239 #define SOUND_TYPE_DEFAULT      1
240 #endif
241
242 #if defined(_FM8)
243 #define USE_SOUND_VOLUME        5
244 #else
245 #define USE_SOUND_VOLUME        11
246 #endif
247 #define SUPPORT_TV_RENDER
248
249 #define IGNORE_DISK_CRC_DEFAULT         true
250 // device informations for virtual machine
251
252 // TODO: check refresh rate
253 //#define FRAMES_PER_SEC                60.0962 /* Related to display.cpp */ 
254 #define FRAMES_PER_SEC          59.94 /* Related to display.cpp */ 
255 #if defined(_FM77AV40) || defined(_FM77AV40EX) || defined(_FM77AV40SX) || defined(_FM77L4)
256 #define LINES_PER_FRAME         400
257 #else
258 #define LINES_PER_FRAME         200
259 #endif
260
261 #if defined(_FM77AV40) || defined(_FM77AV40EX) || defined(_FM77AV40SX) || \
262   defined(_FM77AV20) || defined(_FM77AV20EX) || defined(_FM77AV20SX)
263 #define CPU_CLOCKS              2016000 /* 2016 */
264 #else
265 #define CPU_CLOCKS      1798000   /* FM8,7 - 77AV/20? */
266 #endif
267
268
269 /*
270  * If you wish to use software-scanline, define below.
271  * If not, undef.
272  */
273 #define FIXED_FRAMEBUFFER_SIZE
274
275 #if defined(_FM77AV40) || defined(_FM77AV40EX) || defined(_FM77AV40SX) || defined(_FM77L4)
276 #define SCREEN_WIDTH            640
277 #define SCREEN_HEIGHT           400
278 #undef SCREEN_FAKE_WIDTH
279 #undef SCREEN_FAKE_HEIGHT
280 #else /* Not have 400 line */
281
282 #define SCREEN_WIDTH            640
283 #define SCREEN_HEIGHT           200
284 # if defined(FIXED_FRAMEBUFFER_SIZE)
285 #  define SCREEN_FAKE_WIDTH   640
286 #  define SCREEN_FAKE_HEIGHT  400
287 # else
288 #  define SCREEN_FAKE_WIDTH   640
289 #  define SCREEN_FAKE_HEIGHT  200
290 # endif
291
292 # if !defined(FIXED_FRAMEBUFFER_SIZE)
293 #  define SCREEN_Y_ZOOM       2.0
294 # endif
295
296 #endif
297 #define WINDOW_HEIGHT_ASPECT 480
298 #define HAS_MC6809              
299 #define MB8877_MAX_CHIPS        1
300 //#define IO_ADDR_MAX           0x10000
301
302 // device informations for win32
303 #if defined(HAS_2HD)
304 #define USE_FLOPPY_DISK 4
305 #else
306 #define USE_FLOPPY_DISK 2
307 #endif
308 #define BASE_FLOPPY_DISK_NUM 0
309
310 #ifdef BUILD_Z80
311 # ifdef CAPABLE_Z80
312 #  define WITH_Z80
313 # endif
314 #endif
315
316 // DIP Switch description
317 #define SWITCH_CYCLESTEAL 0x00000001
318 #if defined(_FM8)
319 #define SWITCH_URA_RAM    0x00000002
320 #else
321 #define SWITCH_URA_RAM    0x00000000
322 #endif
323 #define SWITCH_INVERT_CMT 0x00000004
324
325 // Belows are optional Hardwares.
326 #if !defined(_FM77_VARIANTS) && !defined(_FM77AV_VARIANTS)
327 #define SWITCH_FDC 0x00010000
328 #else
329 #define SWITCH_FDC 0x00000000
330 #endif
331 #if !defined(_FM77_VARIANTS) && !defined(_FM77AV_VARIANTS)
332 #define SWITCH_Z80 0x00020000
333 #else
334 #define SWITCH_Z80 0x00000000
335 #endif
336 #if defined(_FM77_VARIANTS)
337 #define SWITCH_DICTCARD 0x00040000
338 #else
339 #define SWITCH_DICTCARD 0x00000000
340 #endif
341 #if defined(_FM77AV_VARIANTS) || defined(_FM77_VARIANTS)
342 #define SWITCH_EXTRA_RAM 0x00080000
343 #else
344 #define SWITCH_EXTRA_RAM 0x00000000
345 #endif
346 #define MB8877_NO_BUSY_AFTER_SEEK
347
348 //#define ENABLE_OPENCL // If OpenCL renderer is enabled, define here.
349
350 //#include "../../config.h"
351 #include "../../common.h"
352 #include "../../fileio.h"
353 #include "../vm_template.h"
354
355 #ifdef USE_SOUND_VOLUME
356 static const _TCHAR *sound_device_caption[] = {
357 #if defined(_FM8)
358         _T("PSG(Hack)"),
359         _T("Beep"),
360         _T("CMT (Signal)"),
361         _T("Noise (320KB FDD)"),
362         _T("Noise (CMT)"),
363 #else
364 # if !defined(_FM77AV_VARIANTS)
365         _T("PSG"),
366 # endif
367         _T("OPN (FM)"), _T("OPN (PSG)"), _T("WHG (FM)"), _T("WHG (PSG)"), _T("THG (FM)"), _T("THG (PSG)"),
368         _T("Beep"), _T("CMT (Signal)"),
369 # if defined(_FM77AV_VARIANTS)
370         _T("Keyboard"),
371 # endif
372         _T("Noise (320KB FDD)"),
373 # if defined(HAS_2HD)
374         _T("Noise (1MB FDD/2HD)"),
375 # endif
376         _T("Noise (CMT)"),
377 #endif  
378 };
379 #endif
380 #ifdef USE_JOY_BUTTON_CAPTIONS
381 static const _TCHAR *joy_button_captions[] = {
382         _T("Up"),
383         _T("Down"),
384         _T("Left"),
385         _T("Right"),
386         _T("Button #1(1st)"),
387         _T("Button #2(1st)"),
388         _T("Button #1(2nd)"),
389         _T("Button #2(2nd)"),
390 };
391 #endif
392
393 /*
394  * NOTE:
395  * Below defines are for EVENT::run_cpu().
396  * Please see event.cpp for details.
397  * 20180317 -- K.Ohta.
398  */
399
400 #define USE_CPU_MC6809
401 #if defined(WITH_Z80)
402 #define USE_CPU_Z80
403 #endif
404
405 class EMU;
406 class DEVICE;
407 class EVENT;
408 class FILEIO;
409
410 class AND;
411 #if defined(USE_AY_3_8910_AS_PSG) && !defined(_FM77AV_VARIANTS)
412 class AY_3_891X;
413 #endif
414 #if defined(_FM77AV_VARIANTS)
415 class BEEP;
416 #endif
417 class DATAREC;
418 #if defined(_FM77L4)
419 class HD46505;
420 #endif
421 class I8251;
422 class MB8877;
423 class MC6809;
424 class PCM1BIT;
425 class YM2203;
426 #ifdef WITH_Z80
427 class Z80;
428 class OR;
429 #endif
430
431 #if defined(_FM77AV_VARIANTS)
432 class MB61VH010;
433 #endif
434 #if defined(_FM77AV40) || defined(_FM77AV40EX) || defined(_FM77AV40SX) || \
435     defined(_FM77AV20) || defined(_FM77AV20EX) || defined(_FM77AV20SX)
436 class HD6844;
437 #endif
438
439 namespace FM7 {
440 #if defined(USE_BUBBLE)
441         class BUBBLECASETTE;
442 #endif
443         class DISPLAY;
444 #ifdef CAPABLE_JCOMMCARD
445 class FM7_JCOMMCARD;
446 #endif
447         class FM7_MAINMEM;
448 #if defined(_FM8)
449         class FM8_MAINIO;
450 #else
451         class FM7_MAINIO;
452 #endif
453         class JOYSTICK;
454         class KEYBOARD;
455         class KANJIROM;
456 }
457
458 class VM : public VM_TEMPLATE
459 {
460 protected:
461 //      EMU* emu;
462         
463         // devices
464 //      EVENT* event;
465         
466         DEVICE* dummycpu;
467         MC6809* maincpu;
468         FM7::FM7_MAINMEM* mainmem;
469 #if defined(_FM8)
470         FM7::FM8_MAINIO* mainio;
471 #else
472         FM7::FM7_MAINIO* mainio;
473 #endif
474         MB8877* fdc;
475 #if defined(HAS_2HD)
476         MB8877 *fdc_2HD;
477 #endif
478 #if defined(_FM8)
479         // FM8
480 # if defined(USE_AY_3_8910_AS_PSG)
481         AY_3_891X *psg;
482 # else
483         YM2203* psg;
484 # endif
485 #else
486         // FM7 -
487         YM2203* opn[3];
488 # if !defined(_FM77AV_VARIANTS)
489 #  if defined(USE_AY_3_8910_AS_PSG)
490         AY_3_891X *psg;
491 #else
492         YM2203* psg; // Is right? AY-3-8910 is right device.
493 #  endif
494 # endif
495 #endif
496 #if defined(USE_BUBBLE)
497         FM7::BUBBLECASETTE *bubble_casette[USE_BUBBLE];
498 #endif
499         I8251 *uart[3];
500 # if defined(_FM77AV20) || defined(_FM77AV40) || defined(_FM77AV20EX) || defined(_FM77AV40EX) || defined(_FM77AV40SX)
501         AND *g_rs232c_dtr;
502 #endif
503         
504         //BEEP* beep;
505         PCM1BIT* pcm1bit;
506         DATAREC *drec;
507         FM7::JOYSTICK *joystick;
508         
509 #ifdef  WITH_Z80
510         Z80* z80cpu;
511         AND *g_nmi;
512         OR *g_intr;
513         AND *g_intr_irq;
514         AND *g_intr_firq;
515         AND *g_mainstat;
516 #endif
517         AND *g_substat_display;
518         AND *g_substat_mainhalt;
519         
520         DEVICE* printer;
521         DEVICE* inteli_mouse; 
522    
523         MC6809* subcpu;
524 #if defined(_FM77AV_VARIANTS)
525         MB61VH010 *alu;
526         BEEP *keyboard_beep;
527 #endif
528 #if defined(HAS_DMA)
529         HD6844 *dmac;
530 #endif   
531         FM7::DISPLAY* display;
532         FM7::KEYBOARD* keyboard;
533    
534         FM7::KANJIROM *kanjiclass1;
535 #ifdef CAPABLE_KANJI_CLASS2
536         FM7::KANJIROM *kanjiclass2;
537 #endif
538 #if defined(CAPABLE_JCOMMCARD)
539         MC6809 *jsubcpu;
540         FM7::FM7_JCOMMCARD *jcommcard;
541         AND *g_jsubhalt;
542 #endif
543 #if defined(_FM77L4)
544         HD46505 *l4crtc;
545 #endif
546         bool connect_320kfdc;
547         bool connect_1Mfdc;
548
549 public:
550         // ----------------------------------------
551         // initialize
552         // ----------------------------------------
553         
554         VM(EMU* parent_emu);
555         ~VM();
556         
557         // ----------------------------------------
558         // for emulation class
559         // ----------------------------------------
560         
561         // drive virtual machine
562         void reset();
563         void special_reset();
564         void run();
565         double get_frame_rate();
566         
567 #ifdef USE_DEBUGGER
568         // debugger
569         DEVICE *get_cpu(int index);
570 #endif
571         void connect_bus(void);
572
573         void update_dipswitch(void);
574         // draw screen
575         void draw_screen();
576         
577         // sound generation
578         void initialize_sound(int rate, int samples);
579         uint16_t* create_sound(int* extra_frames);
580         int get_sound_buffer_ptr();
581 #ifdef USE_SOUND_VOLUME
582         void set_sound_device_volume(int ch, int decibel_l, int decibel_r);
583 #endif
584         void set_vm_frame_rate(double fps);
585         
586         // notify key
587         void key_down(int code, bool repeat);
588         void key_up(int code);
589         bool get_caps_locked();
590         bool get_kana_locked();
591         uint32_t get_led_status(); 
592         
593         // user interface
594         void open_floppy_disk(int drv, const _TCHAR* file_path, int bank);
595         void close_floppy_disk(int drv);
596         bool is_floppy_disk_inserted(int drv);
597         void is_floppy_disk_protected(int drv, bool value);
598         bool is_floppy_disk_protected(int drv);
599         uint32_t is_floppy_disk_accessed();
600         
601         void play_tape(int drv, const _TCHAR* file_path);
602         void rec_tape(int drv, const _TCHAR* file_path);
603         void close_tape(int drv);
604         bool is_tape_inserted(int drv);
605         bool is_tape_playing(int drv);
606         bool is_tape_recording(int drv);
607         int get_tape_position(int drv);
608         const _TCHAR* get_tape_message(int drv);
609         
610         bool is_frame_skippable();
611         void push_play(int drv);
612         void push_stop(int drv);
613         void push_fast_forward(int drv);
614         void push_fast_rewind(int drv);
615         void push_apss_forward(int drv);
616         void push_apss_rewind(int drv);
617         void update_config();
618         bool process_state(FILEIO* state_fio, bool loading);
619         
620 #if defined(USE_BUBBLE)
621         void open_bubble_casette(int drv, const _TCHAR *path, int bank);
622         void close_bubble_casette(int drv);
623         bool is_bubble_casette_inserted(int drv);
624         bool is_bubble_casette_protected(int drv);
625         void is_bubble_casette_protected(int drv, bool flag);
626 #endif
627 #if defined(USE_DIG_RESOLUTION)
628         void get_screen_resolution(int *w, int *h);
629 #endif
630 #if defined(USE_MINIMUM_RENDERING)      
631         bool is_screen_changed(void);
632 #endif  
633         // ----------------------------------------
634         // for each device
635         // ----------------------------------------
636         void set_cpu_clock(DEVICE *cpu, uint32_t clocks);
637         // devices
638         DEVICE* get_device(int id);
639 //      DEVICE* dummy;
640 //      DEVICE* first_device;
641 //      DEVICE* last_device;
642 };
643
644 #endif