OSDN Git Service

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