OSDN Git Service

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