OSDN Git Service

Merge branch 'master' of github.com:Artanejp/common_source_project-fm7
[csp-qt/common_source_project-fm7.git] / source / src / vm / pc8801 / pc8801.h
1 /*
2         NEC PC-8801MA Emulator 'ePC-8801MA'
3         NEC PC-8001mkIISR Emulator 'ePC-8001mkIISR'
4
5         Author : Takeda.Toshiya
6         Date   : 2012.02.16-
7
8         [ virtual machine ]
9 */
10
11 #ifndef _PC8801_H_
12 #define _PC8801_H_
13
14 #if defined(_PC8801MA)
15 #define DEVICE_NAME             "NEC PC-8801MA"
16 #define CONFIG_NAME             "pc8801ma"
17 #elif defined(_PC8001SR)
18 #define DEVICE_NAME             "NEC PC-8001mkIISR"
19 #define CONFIG_NAME             "pc8001mk2sr"
20 #endif
21
22 #if defined(_PC8001SR)
23 #define MODE_PC80_V1    0
24 #define MODE_PC80_V2    1
25 #define MODE_PC80_N     2
26 #else
27 #define MODE_PC88_V1S   0
28 #define MODE_PC88_V1H   1
29 #define MODE_PC88_V2    2
30 #define MODE_PC88_N     3
31 #endif
32
33 #if defined(_PC8801MA)
34 #define SUPPORT_PC88_DICTIONARY
35 #define SUPPORT_PC88_HIGH_CLOCK
36 #define SUPPORT_PC88_OPNA
37 #define SUPPORT_PC88_SB2
38 #define PC88_EXRAM_BANKS        4
39 #define HAS_UPD4990A
40 #endif
41 #define SUPPORT_PC88_JOYSTICK
42 #define SUPPORT_PC88_PCG8100
43
44 // device informations for virtual machine
45 #define FRAMES_PER_SEC          62.422
46 #define LINES_PER_FRAME         260
47 #define CPU_CLOCKS              3993624
48 #define SCREEN_WIDTH            640
49 #define SCREEN_HEIGHT           400
50 #define WINDOW_HEIGHT_ASPECT    480
51 #define MAX_DRIVE               2
52 #define UPD765A_NO_ST1_EN_OR_FOR_RESULT7
53 #if defined(_PC8801MA)
54 #define PC80S31K_NO_WAIT
55 #endif
56 #if defined(SUPPORT_PC88_OPNA) || defined(SUPPORT_PC88_SB2)
57 #define HAS_YM2608
58 #endif
59 #define Z80_MEMORY_WAIT
60 #define OVERRIDE_SOUND_FREQ_48000HZ     55467
61 #define SUPPORT_VARIABLE_TIMING
62
63 // device informations for win32
64 #if defined(_PC8001SR)
65 #define USE_BOOT_MODE           3
66 #define USE_CPU_TYPE            2
67 #else
68 #define USE_BOOT_MODE           4
69 #define USE_CPU_TYPE            3
70 #endif
71 #if defined(_PC8801MA)
72 // V2 mode, 4MHz
73 #define BOOT_MODE_DEFAULT       2
74 #define CPU_TYPE_DEFAULT        1
75 #endif
76 #define USE_DIPSWITCH
77 #define USE_JOYSTICK_TYPE       2
78 #define USE_FLOPPY_DISK         2
79 #define USE_TAPE                1
80 #define TAPE_BINARY_ONLY
81 #define NOTIFY_KEY_DOWN
82 #define USE_KEY_LOCKED
83 #define USE_SHIFT_NUMPAD_KEY
84 #define USE_ALT_F10_KEY
85 // slow enough for N88-\93ú\96{\8cêBASIC
86 #define USE_AUTO_KEY            8
87 #define USE_AUTO_KEY_RELEASE    10
88 #define USE_AUTO_KEY_NUMPAD
89 #define USE_MONITOR_TYPE        2
90 #define USE_SCREEN_FILTER
91 #define USE_SCANLINE
92 #ifdef SUPPORT_PC88_OPNA
93 #ifdef SUPPORT_PC88_SB2
94 #define USE_SOUND_TYPE          6
95 #else
96 #define USE_SOUND_TYPE          2
97 #endif
98 #endif
99 #if    defined(SUPPORT_PC88_OPNA) &&  defined(SUPPORT_PC88_SB2) &&  defined(SUPPORT_PC88_PCG8100)
100 #define USE_SOUND_VOLUME        (4 + 4 + 1 + 1 + 1)
101 #elif  defined(SUPPORT_PC88_OPNA) &&  defined(SUPPORT_PC88_SB2) && !defined(SUPPORT_PC88_PCG8100)
102 #define USE_SOUND_VOLUME        (4 + 4 + 0 + 1 + 1)
103 #elif  defined(SUPPORT_PC88_OPNA) && !defined(SUPPORT_PC88_SB2) &&  defined(SUPPORT_PC88_PCG8100)
104 #define USE_SOUND_VOLUME        (4 + 0 + 1 + 1 + 1)
105 #elif  defined(SUPPORT_PC88_OPNA) && !defined(SUPPORT_PC88_SB2) && !defined(SUPPORT_PC88_PCG8100)
106 #define USE_SOUND_VOLUME        (4 + 0 + 0 + 1 + 1)
107 #elif !defined(SUPPORT_PC88_OPNA) &&  defined(SUPPORT_PC88_SB2) &&  defined(SUPPORT_PC88_PCG8100)
108 #define USE_SOUND_VOLUME        (2 + 2 + 1 + 1 + 1)
109 #elif !defined(SUPPORT_PC88_OPNA) &&  defined(SUPPORT_PC88_SB2) && !defined(SUPPORT_PC88_PCG8100)
110 #define USE_SOUND_VOLUME        (2 + 2 + 0 + 1 + 1)
111 #elif !defined(SUPPORT_PC88_OPNA) && !defined(SUPPORT_PC88_SB2) &&  defined(SUPPORT_PC88_PCG8100)
112 #define USE_SOUND_VOLUME        (2 + 0 + 1 + 1 + 1)
113 #elif !defined(SUPPORT_PC88_OPNA) && !defined(SUPPORT_PC88_SB2) && !defined(SUPPORT_PC88_PCG8100)
114 #define USE_SOUND_VOLUME        (2 + 0 + 0 + 1 + 1)
115 #endif
116
117 #define SUPPORT_TV_RENDER
118 #define USE_JOYSTICK
119 #define USE_MOUSE
120 #define USE_PRINTER
121 #define USE_PRINTER_TYPE        3
122 #define USE_DEBUGGER
123 #define USE_STATE
124 #define USE_CPU_Z80
125
126 #include "../../common.h"
127 #include "../../fileio.h"
128
129 #ifdef USE_SOUND_VOLUME
130 static const _TCHAR *sound_device_caption[] = {
131 #ifdef SUPPORT_PC88_OPNA
132         _T("OPNA (FM)"), _T("OPNA (PSG)"), _T("OPNA (ADPCM)"), _T("OPNA (Rhythm)"),
133 #else
134         _T("OPN (FM)"), _T("OPN (PSG)"),
135 #endif
136 #ifdef SUPPORT_PC88_SB2
137 #ifdef SUPPORT_PC88_OPNA
138         _T("SB2 (FM)"), _T("SB2 (PSG)"), _T("SB2 (ADPCM)"), _T("SB2 (Rhythm)"),
139 #else
140         _T("SB2 (FM)"), _T("SB2 (PSG)"),
141 #endif
142 #endif
143 #ifdef SUPPORT_PC88_PCG8100
144         _T("PCG-8100"),
145 #endif
146         _T("Beep"), _T("Noise (FDD)"),
147 };
148 #endif
149
150 class csp_state_utils;
151 class EMU;
152 class DEVICE;
153 class EVENT;
154
155 class I8251;
156 class I8255;
157 class NOISE;
158 class PCM1BIT;
159 class UPD1990A;
160 class YM2203;
161 class Z80;
162
163 class PC80S31K;
164 class UPD765A;
165
166 #ifdef SUPPORT_PC88_PCG8100
167 class I8253;
168 #endif
169 class PC88;
170
171 class VM
172 {
173 protected:
174         EMU* emu;
175         csp_state_utils* state_entry;
176         
177         // devices
178         EVENT* pc88event;
179         
180         DEVICE* pc88prn;
181         I8251* pc88sio;
182         I8255* pc88pio;
183         PCM1BIT* pc88pcm;
184         UPD1990A* pc88rtc;
185         YM2203* pc88opn;
186 #ifdef SUPPORT_PC88_SB2
187         YM2203* pc88sb2;
188 #endif
189         DEVICE* dummycpu;
190         Z80* pc88cpu;
191         
192         PC80S31K* pc88sub;
193         I8255* pc88pio_sub;
194         UPD765A* pc88fdc_sub;
195         NOISE* pc88noise_seek;
196         NOISE* pc88noise_head_down;
197         NOISE* pc88noise_head_up;
198         Z80* pc88cpu_sub;
199 #ifdef SUPPORT_PC88_PCG8100
200         I8253* pc88pit;
201         PCM1BIT* pc88pcm0;
202         PCM1BIT* pc88pcm1;
203         PCM1BIT* pc88pcm2;
204 #endif
205         
206         PC88* pc88;
207         
208         int boot_mode;
209         
210 public:
211         // ----------------------------------------
212         // initialize
213         // ----------------------------------------
214         
215         VM(EMU* parent_emu);
216         ~VM();
217         
218         // ----------------------------------------
219         // for emulation class
220         // ----------------------------------------
221         
222         // drive virtual machine
223         void reset();
224         void run();
225         double get_frame_rate();
226         
227 #ifdef USE_DEBUGGER
228         // debugger
229         DEVICE *get_cpu(int index);
230 #endif
231         
232         // draw screen
233         void draw_screen();
234         
235         // sound generation
236         void initialize_sound(int rate, int samples);
237         uint16_t* create_sound(int* extra_frames);
238         int get_sound_buffer_ptr();
239 #ifdef USE_SOUND_VOLUME
240         void set_sound_device_volume(int ch, int decibel_l, int decibel_r);
241 #endif
242         
243         // notify key
244         void key_down(int code, bool repeat);
245         void key_up(int code);
246         bool get_caps_locked();
247         bool get_kana_locked();
248         
249         // user interface
250         void open_floppy_disk(int drv, const _TCHAR* file_path, int bank);
251         void close_floppy_disk(int drv);
252         bool is_floppy_disk_inserted(int drv);
253         void is_floppy_disk_protected(int drv, bool value);
254         bool is_floppy_disk_protected(int drv);
255         uint32_t is_floppy_disk_accessed();
256         void play_tape(int drv, const _TCHAR* file_path);
257         void rec_tape(int drv, const _TCHAR* file_path);
258         void close_tape(int drv);
259         bool is_tape_inserted(int drv);
260         bool is_frame_skippable();
261         
262         void update_config();
263         void decl_state();
264         void save_state(FILEIO* state_fio);
265         bool load_state(FILEIO* state_fio);
266         
267         // ----------------------------------------
268         // for each device
269         // ----------------------------------------
270         
271         // devices
272         DEVICE* get_device(int id);
273         DEVICE* dummy;
274         DEVICE* first_device;
275         DEVICE* last_device;
276 };
277
278 #endif