OSDN Git Service

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