OSDN Git Service

Merge branch 'master' of github.com:Artanejp/common_source_project-fm7
[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_TAPE1
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
29 #define NOTIFY_KEY_DOWN
30 //#define NOTIFY_KEY_UP
31 #define NOTIFY_KEY_DOWN_LR_SHIFT
32 #define NOTIFY_KEY_DOWN_LR_MENU
33 #define USE_ALT_F10_KEY
34 #define USE_AUTO_KEY            5
35 #define USE_AUTO_KEY_RELEASE    6
36 #define USE_SCREEN_FILTER
37 #define USE_STATE
38 #define USE_DEBUGGER
39 #define DATAREC_SOUND
40 #define USE_DIG_RESOLUTION
41 #define SUPPORT_ROMA_KANA_CONVERSION
42
43 #if defined(_FM8)
44 #define DEVICE_NAME             "FUJITSU FM-8"
45 #define CONFIG_NAME             "fm8"
46 #define CAPABLE_Z80
47 #define DIPSWITCH_DEFAULT 0x00000000 
48 #define USE_BUBBLE1
49 #define USE_BUBBLE2
50 #define MAX_BUBBLE 2
51
52 #elif defined(_FM7)
53 #define DEVICE_NAME             "FUJITSU FM-7"
54 #define CONFIG_NAME             "fm7"
55 #define CAPABLE_Z80
56 #define DIPSWITCH_DEFAULT 0x000000000 
57
58 #elif defined(_FMNEW7)
59 #define DEVICE_NAME             "FUJITSU FM-NEW7"
60 #define CONFIG_NAME             "fmnew7"
61 #define CAPABLE_Z80
62 #define DIPSWITCH_DEFAULT 0x000000000 
63
64 #elif defined(_FM77) || defined(_FM77L2)
65 # if defined(_FM77)
66 #define DEVICE_NAME             "FUJITSU FM-77"
67 #define CONFIG_NAME             "fm77"
68 #define DIPSWITCH_DEFAULT 0x00000001
69
70 # else
71 #define DEVICE_NAME             "FUJITSU FM-77L2"
72 #define CONFIG_NAME             "fm77l2"
73 #define DIPSWITCH_DEFAULT 0x00000003 
74 # endif
75 //#define USE_DRIVE_TYPE
76 #define _FM77_VARIANTS
77 #define CAPABLE_Z80
78 # ifndef FM77_EXRAM_BANKS
79 #   define FM77_EXRAM_BANKS     3
80 # endif
81
82 #elif defined(_FM77L4)
83 #define DEVICE_NAME             "FUJITSU FM-77L4"
84 #define CONFIG_NAME             "fm77l4"
85 #define HAS_MMR
86 #define HAS_TEXTVRAM
87 #define HAS_2HD
88 #define HAS_CYCLESTEAL
89 #define HAS_400LINECARD
90 //#define CAPABLE_KANJI_CLASS2
91 #define _FM77_VARIANTS
92 #define CAPABLE_Z80
93 # ifndef FM77_EXRAM_BANKS
94 #  define FM77_EXRAM_BANKS      3
95 # endif
96 #define DIPSWITCH_DEFAULT 0x00000003 
97
98 #elif defined(_FM77AV)
99 #define DEVICE_NAME             "FUJITSU FM77AV"
100 #define CONFIG_NAME             "fm77av"
101 #define _FM77AV_VARIANTS
102 #define DIPSWITCH_DEFAULT 0x80000001 
103
104 #elif defined(_FM77AV20)
105 #define DEVICE_NAME             "FUJITSU FM77AV20"
106 #define CONFIG_NAME             "fm77av20"
107 #define _FM77AV_VARIANTS
108 #define HAS_MMR
109 #define HAS_2DD_2D
110 #define CAPABLE_DICTROM
111 //#define USE_DRIVE_TYPE 2
112 #define CAPABLE_KANJI_CLASS2
113 #define DIPSWITCH_DEFAULT 0x80000001 
114
115 #elif defined(_FM77AV20EX)
116 #define DEVICE_NAME             "FUJITSU FM77AV20EX"
117 #define CONFIG_NAME             "fm77av20ex"
118 #define _FM77AV_VARIANTS
119 #define HAS_MMR
120 #define HAS_2DD_2D
121 #define HAS_DMA
122 //#define USE_DRIVE_TYPE 2
123 #define CAPABLE_DICTROM
124 #define CAPABLE_KANJI_CLASS2
125 #define DIPSWITCH_DEFAULT 0x80000001 
126
127 #elif defined(_FM77AV40)
128 #define DEVICE_NAME             "FUJITSU FM77AV40"
129 #define CONFIG_NAME             "fm77av40"
130 #define _FM77AV_VARIANTS
131 #define HAS_2DD_2D
132 #define HAS_DMA
133 //#define USE_DRIVE_TYPE 2
134 #define CAPABLE_DICTROM
135 #define HAS_400LINE_AV
136 #define CAPABLE_KANJI_CLASS2
137 #ifndef FM77_EXRAM_BANKS
138 #define FM77_EXRAM_BANKS        12
139 #endif
140 #define DIPSWITCH_DEFAULT 0x8000000d 
141
142 #elif defined(_FM77AV40EX)
143 #define DEVICE_NAME             "FUJITSU FM77AV40EX"
144 #define CONFIG_NAME             "fm77av40ex"
145 #define _FM77AV_VARIANTS
146 #define HAS_2DD_2D
147 #define HAS_DMA
148 //#define USE_DRIVE_TYPE 2
149 #define CAPABLE_DICTROM
150 #define HAS_400LINE_AV
151 #define CAPABLE_KANJI_CLASS2
152 #ifndef FM77_EXRAM_BANKS
153 #define FM77_EXRAM_BANKS        12
154 #endif
155 #define DIPSWITCH_DEFAULT 0x8000000d 
156
157 #elif defined(_FM77AV40SX)
158 #define DEVICE_NAME             "FUJITSU FM77AV40SX"
159 #define CONFIG_NAME             "fm77av40sx"
160 #define _FM77AV_VARIANTS
161 #define HAS_2DD_2D
162 #define HAS_DMA
163 //#define USE_DRIVE_TYPE 2
164 #define CAPABLE_DICTROM
165 #define HAS_400LINE_AV
166 #define CAPABLE_KANJI_CLASS2
167 # ifndef FM77_EXRAM_BANKS
168 #  define FM77_EXRAM_BANKS      12
169 # endif
170 #define DIPSWITCH_DEFAULT 0x8000000d 
171
172 #endif
173
174 #if defined(_FM8)
175 #define USE_SOUND_TYPE          2
176 #else
177 #define USE_MOUSE_TYPE          3
178 #define USE_SOUND_TYPE          8
179 #endif
180
181 #ifdef _FM77AV_VARIANTS
182 //#define CAPABLE_KANJI_CLASS2
183 #define HAS_MMR
184 #define HAS_CYCLESTEAL
185 #elif defined(_FM77_VARIANTS)
186 #define HAS_MMR
187 #define HAS_CYCLESTEAL
188 #define CAPABLE_Z80
189 #endif
190
191 #if defined(_FM77_VARIANTS)
192 #define USE_BOOT_MODE         4
193 #elif defined(_FM8)
194 #define USE_BOOT_MODE         4
195 #elif defined(_FM7) || defined(_FMNEW7)
196 #define USE_BOOT_MODE         3
197 #else
198 #define USE_BOOT_MODE         2
199 #endif
200
201 // 0 = PSG or NONE
202 // 1 = OPN (+PSG)
203 // 2 = WHG (+PSG)
204 // 3 = WHG + OPN (+PSG)
205 // 4 = THG  (+PSG)
206 // 5 = THG + OPN (+PSG)
207 // 6 = THG + WHG (+PSG)
208 // 7 = THG + WHG + OPN (+PSG)
209 #if defined(_FM8)
210 // WITHOUT PSG?
211 #define SOUND_TYPE_DEFAULT      0
212 #elif defined(_FM7) || defined(_FMNEW7) || defined(_FM77_VARIANTS)
213 // PSG ONLY
214 #define SOUND_TYPE_DEFAULT      0
215 #elif defined(_FM77AV_VARIANTS)
216 // OPN
217 #define SOUND_TYPE_DEFAULT      1
218 #endif
219
220 #if defined(_FM8)
221 #define USE_SOUND_VOLUME        5
222 #else
223 #define USE_SOUND_VOLUME        11
224 #endif
225 #define SUPPORT_TV_RENDER
226
227 #define IGNORE_DISK_CRC_DEFAULT         true
228 // device informations for virtual machine
229
230 // TODO: check refresh rate
231 #define FRAMES_PER_SEC          59.94
232 #if defined(_FM77AV40) || defined(_FM77AV40EX) || defined(_FM77AV40SX) || defined(_FM77L4)
233 #define LINES_PER_FRAME         400
234 #else
235 #define LINES_PER_FRAME         200
236 #endif
237
238 #if defined(_FM77AV40) || defined(_FM77AV40EX) || defined(_FM77AV40SX) || \
239     defined(_FM77AV20) || defined(_FM77AV20EX) || defined(_FM77AV20SX)
240 #define CPU_CLOCKS              2016000
241 #elif defined(_FM8)
242 #define CPU_CLOCKS              1095000
243 #else
244 #define CPU_CLOCKS              2000000
245 #endif
246
247 # if defined(_FM77AV40) || defined(_FM77AV40EX) || defined(_FM77AV40SX) || defined(_FM77L4)
248 #define SCREEN_WIDTH            640
249 #define SCREEN_HEIGHT           400
250 #undef SCREEN_FAKE_WIDTH
251 #undef SCREEN_FAKE_HEIGHT
252 #else
253 #define SCREEN_WIDTH            640
254 #define SCREEN_HEIGHT           200
255 #define SCREEN_FAKE_WIDTH   640
256 #define SCREEN_FAKE_HEIGHT  400
257 #endif
258 #define WINDOW_HEIGHT_ASPECT 480
259 #define HAS_MC6809              
260 #define MB8877_MAX_CHIPS        1
261 //#define IO_ADDR_MAX           0x10000
262
263 // device informations for win32
264 #define USE_FD1
265 #define USE_FD2
266 #define MAX_FD 2
267 #define MAX_DRIVE 4
268
269 #if defined(HAS_2HD)
270 #define USE_FD3
271 #define USE_FD4
272 #undef  MAX_FD
273 #undef  MAX_DRIVE
274 #define MAX_FD 6
275 #define MAX_DRIVE 8
276 #endif
277
278
279 #ifdef BUILD_Z80
280 # ifdef CAPABLE_Z80
281 #  define WITH_Z80
282 # endif
283 #endif
284
285 // DIP Switch description
286 #define SWITCH_CYCLESTEAL 0x00000001
287 #if defined(_FM8)
288 #define SWITCH_URA_RAM    0x00000002
289 #else
290 #define SWITCH_URA_RAM    0x00000000
291 #endif
292 #define SWITCH_INVERT_CMT 0x00000004
293
294 // Belows are optional Hardwares.
295 #if !defined(_FM77_VARIANTS) && !defined(_FM77AV_VARIANTS)
296 #define SWITCH_FDC 0x00010000
297 #else
298 #define SWITCH_FDC 0x00000000
299 #endif
300 #if !defined(_FM77_VARIANTS) && !defined(_FM77AV_VARIANTS)
301 #define SWITCH_Z80 0x00020000
302 #else
303 #define SWITCH_Z80 0x00000000
304 #endif
305 #if defined(_FM77_VARIANTS)
306 #define SWITCH_DICTCARD 0x00040000
307 #else
308 #define SWITCH_DICTCARD 0x00000000
309 #endif
310 #if defined(_FM77AV_VARIANTS) || defined(_FM77_VARIANTS)
311 #define SWITCH_EXTRA_RAM 0x00080000
312 #else
313 #define SWITCH_EXTRA_RAM 0x00000000
314 #endif
315 #define MB8877_NO_BUSY_AFTER_SEEK
316
317 //#define ENABLE_OPENCL // If OpenCL renderer is enabled, define here.
318
319 //#include "../../config.h"
320 #include "../../common.h"
321 #include "../../fileio.h"
322
323 #ifdef USE_SOUND_VOLUME
324 static const _TCHAR *sound_device_caption[] = {
325 #if defined(_FM8)
326         _T("PSG(Hack)"),
327         _T("Beep"),
328         _T("CMT (Signal)"),
329         _T("Noise (FDD)"),
330         _T("Noise (CMT)"),
331 #else
332 # if !defined(_FM77AV_VARIANTS)
333         _T("PSG"),
334 # endif
335         _T("OPN (FM)"), _T("OPN (PSG)"), _T("WHG (FM)"), _T("WHG (PSG)"), _T("THG (FM)"), _T("THG (PSG)"),
336         _T("Beep"), _T("CMT (Signal)"),
337 # if defined(_FM77AV_VARIANTS)
338         _T("Keyboard"),
339 # endif
340         _T("Noise (FDD)"), _T("Noise (CMT)"),
341 #endif  
342 };
343 #endif
344 #ifdef USE_JOY_BUTTON_CAPTIONS
345 static const _TCHAR *joy_button_captions[] = {
346         _T("Up"),
347         _T("Down"),
348         _T("Left"),
349         _T("Right"),
350         _T("Button #1(1st)"),
351         _T("Button #2(1st)"),
352         _T("Button #1(2nd)"),
353         _T("Button #2(2nd)"),
354 };
355 #endif
356
357 class EMU;
358 class DEVICE;
359 class EVENT;
360 class FILEIO;
361
362 #if defined(_FM77AV_VARIANTS)
363 class BEEP;
364 #endif
365 class PCM1BIT;
366 class MC6809;
367 class YM2203;
368 class MB8877;
369 class MEMORY;
370 class DATAREC;
371 #if defined(USE_AY_3_8910_AS_PSG) && !defined(_FM77AV_VARIANTS)
372 class AY_3_891X;
373 #endif
374 #if defined(_FM8)
375 class BUBBLECASETTE;
376 #endif
377 #if defined(USE_LED_DEVICE)
378 class DUMMYDEVICE;
379 #endif
380
381 class DISPLAY;
382 #if defined(_FM77AV_VARIANTS)
383 class MB61VH010;
384 #endif
385 #if defined(_FM77AV40) || defined(_FM77AV40EX) || defined(_FM77AV40SX) || \
386     defined(_FM77AV20) || defined(_FM77AV20EX) || defined(_FM77AV20SX)
387 class HD6844;
388 #endif
389 class FM7_MAINMEM;
390 class FM7_MAINIO;
391 class KEYBOARD;
392 class KANJIROM;
393 class JOYSTICK;
394
395 #if WITH_Z80
396 class Z80;
397 #endif
398 class VM {
399 protected:
400         EMU* emu;
401         
402         // devices
403         EVENT* event;
404         
405         MC6809* maincpu;
406         FM7_MAINMEM* mainmem;
407         FM7_MAINIO* mainio;
408 #if defined(USE_LED_DEVICE)
409         DUMMYDEVICE* led_terminate;
410 #else
411         DEVICE* led_terminate;
412 #endif
413         MB8877* fdc;
414 #if defined(_FM8)
415         // FM8
416 # if defined(USE_AY_3_8910_AS_PSG)
417         AY_3_891X *psg;
418 # else
419         YM2203* psg;
420 # endif
421 #else
422         // FM7 -
423         YM2203* opn[3];
424 # if !defined(_FM77AV_VARIANTS)
425 #  if defined(USE_AY_3_8910_AS_PSG)
426         AY_3_891X *psg;
427 #else
428         YM2203* psg; // Is right? AY-3-8910 is right device.
429 #  endif
430 # endif
431 #endif
432 #if defined(_FM8)
433         BUBBLECASETTE *bubble_casette[2];
434 #endif
435         //BEEP* beep;
436         PCM1BIT* pcm1bit;
437         DATAREC *drec;
438         JOYSTICK *joystick;
439         
440 #ifdef  WITH_Z80
441         Z80* z80cpu;
442 #endif
443         DEVICE* printer;
444         DEVICE* inteli_mouse; 
445    
446         DEVICE *dummycpu;
447         MC6809* subcpu;
448 #if defined(_FM77AV_VARIANTS)
449         MB61VH010 *alu;
450         BEEP *keyboard_beep;
451 #endif
452 #if defined(HAS_DMA)
453         HD6844 *dmac;
454 #endif   
455         DISPLAY* display;
456         KEYBOARD* keyboard;
457    
458         KANJIROM *kanjiclass1;
459 #ifdef CAPABLE_KANJI_CLASS2
460         KANJIROM *kanjiclass2;
461 #endif
462         bool connect_320kfdc;
463         bool connect_1Mfdc;
464 public:
465         // ----------------------------------------
466         // initialize
467         // ----------------------------------------
468         
469         VM(EMU* parent_emu);
470         ~VM();
471         
472         // ----------------------------------------
473         // for emulation class
474         // ----------------------------------------
475         
476         // drive virtual machine
477         void reset();
478         void special_reset();
479         void run();
480         double get_frame_rate();
481 #if defined(USE_LED_DEVICE)
482         uint32_t get_led_status();
483 #endif
484         
485 #ifdef USE_DEBUGGER
486         // debugger
487         DEVICE *get_cpu(int index);
488 #endif
489         void initialize(void);
490         void connect_bus(void);
491
492         void update_dipswitch(void);
493         // draw screen
494         void draw_screen();
495         
496         // sound generation
497         void initialize_sound(int rate, int samples);
498         uint16_t* create_sound(int* extra_frames);
499         int get_sound_buffer_ptr();
500 #ifdef USE_SOUND_VOLUME
501         void set_sound_device_volume(int ch, int decibel_l, int decibel_r);
502 #endif
503         
504         // notify key
505         void key_down(int code, bool repeat);
506         void key_up(int code);
507         
508         // user interface
509         void open_floppy_disk(int drv, const _TCHAR* file_path, int bank);
510         void close_floppy_disk(int drv);
511         bool is_floppy_disk_inserted(int drv);
512         void is_floppy_disk_protected(int drv, bool value);
513         bool is_floppy_disk_protected(int drv);
514         uint32_t is_floppy_disk_accessed();
515         
516         void play_tape(int drv, const _TCHAR* file_path);
517         void rec_tape(int drv, const _TCHAR* file_path);
518         void close_tape(int drv);
519         bool is_tape_inserted(int drv);
520         bool is_tape_playing(int drv);
521         bool is_tape_recording(int drv);
522         int get_tape_position(int drv);
523         const _TCHAR* get_tape_message(int drv);
524         
525         bool is_frame_skippable();
526         void push_play(int drv);
527         void push_stop(int drv);
528         void push_fast_forward(int drv);
529         void push_fast_rewind(int drv);
530         void push_apss_forward(int drv);
531         void push_apss_rewind(int drv);
532         void update_config();
533         void save_state(FILEIO* state_fio);
534         bool load_state(FILEIO* state_fio);
535 #if defined(USE_BUBBLE1)
536         void open_bubble_casette(int drv, const _TCHAR *path, int bank);
537         void close_bubble_casette(int drv);
538         bool is_bubble_casette_inserted(int drv);
539         bool is_bubble_casette_protected(int drv);
540         void is_bubble_casette_protected(int drv, bool flag);
541 #endif
542 #if defined(USE_DIG_RESOLUTION)
543         void get_screen_resolution(int *w, int *h);
544 #endif
545 #if defined(USE_MINIMUM_RENDERING)      
546         bool is_screen_changed(void);
547 #endif  
548         // ----------------------------------------
549         // for each device
550         // ----------------------------------------
551         void set_cpu_clock(DEVICE *cpu, uint32_t clocks);
552         // devices
553         DEVICE* get_device(int id);
554         DEVICE* dummy;
555         DEVICE* first_device;
556         DEVICE* last_device;
557 };
558
559 #endif