OSDN Git Service

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