OSDN Git Service

[VM] Add PC-8001/mk2/8801/mk2.
[csp-qt/common_source_project-fm7.git] / source / src / vm / pc8801 / pc8801.h
1 /*
2         NEC PC-8001 Emulator 'ePC-8001'
3         NEC PC-8001mkII Emulator 'ePC-8001mkII'
4         NEC PC-8001mkIISR Emulator 'ePC-8001mkIISR'
5         NEC PC-8801 Emulator 'ePC-8801'
6         NEC PC-8801mkII Emulator 'ePC-8801mkII'
7         NEC PC-8801MA Emulator 'ePC-8801MA'
8
9         Author : Takeda.Toshiya
10         Date   : 2012.02.16-
11
12         [ virtual machine ]
13 */
14
15 #ifndef _PC8801_H_
16 #define _PC8801_H_
17
18 #if defined(_PC8801MA)
19 #define DEVICE_NAME             "NEC PC-8801MA"
20 #define CONFIG_NAME             "pc8801ma"
21 #elif defined(_PC8801MK2)
22 #define DEVICE_NAME             "NEC PC-8801mkII"
23 #define CONFIG_NAME             "pc8801mk2"
24 #elif defined(_PC8801)
25 #define DEVICE_NAME             "NEC PC-8801"
26 #define CONFIG_NAME             "pc8801"
27 #elif defined(_PC8001SR)
28 #define DEVICE_NAME             "NEC PC-8001mkIISR"
29 #define CONFIG_NAME             "pc8001mk2sr"
30 #elif defined(_PC8001MK2)
31 #define DEVICE_NAME             "NEC PC-8001mkII"
32 #define CONFIG_NAME             "pc8001mk2"
33 #elif defined(_PC8001)
34 #define DEVICE_NAME             "NEC PC-8001"
35 #define CONFIG_NAME             "pc8001"
36 #endif
37
38 #if defined(_PC8001) || defined(_PC8001MK2) || defined(_PC8001SR)
39 #define PC8001_VARIANT
40 #else
41 #define PC8801_VARIANT
42 #endif
43 #if defined(_PC8801MA)
44 #define PC8801SR_VARIANT
45 #endif
46
47 #if defined(PC8001_VARIANT)
48         #define MODE_PC80_V1    0
49         #define MODE_PC80_V2    1
50         #define MODE_PC80_N     2
51 #else
52         #define MODE_PC88_V1S   0
53         #define MODE_PC88_V1H   1
54         #define MODE_PC88_V2    2
55         #define MODE_PC88_N     3
56 #endif
57
58 #if defined(_PC8801MA)
59         #define SUPPORT_PC88_KANJI1
60         #define SUPPORT_PC88_KANJI2
61         #define SUPPORT_PC88_DICTIONARY
62         #define SUPPORT_PC88_HIGH_CLOCK
63         #define SUPPORT_PC88_OPN1
64         #define SUPPORT_PC88_OPN2
65         #define SUPPORT_PC88_OPNA
66         #define SUPPORT_PC88_CDROM
67         #define SUPPORT_PC88_VAB
68         #define SUPPORT_PC88_HMB20
69         #define SUPPORT_PC88_JOYSTICK
70         #if defined(SUPPORT_PC88_VAB)
71                 // X88000
72                 #define PC88_EXRAM_BANKS        8
73                 #define PC88_VAB_PAGE           1
74         #else
75                 #define PC88_EXRAM_BANKS        4
76         #endif
77         #define HAS_UPD4990A
78 #elif defined(_PC8801MK2)
79         #define SUPPORT_PC88_KANJI1
80 //      #define SUPPORT_PC88_KANJI2
81         #define SUPPORT_PC88_OPN2
82         #define SUPPORT_PC88_OPNA
83 #elif defined(_PC8801)
84         #define SUPPORT_PC88_KANJI1
85 //      #define SUPPORT_PC88_KANJI2
86 //      #define SUPPORT_PC88_OPN2
87 //      #define SUPPORT_PC88_OPNA
88 #elif defined(_PC8001SR)
89         #define SUPPORT_PC88_KANJI1
90 //      #define SUPPORT_PC88_KANJI2
91         #define SUPPORT_PC88_OPN1
92         #define SUPPORT_PC88_OPN2
93         #define SUPPORT_PC88_OPNA
94         #define PC88_EXRAM_BANKS        1
95 #elif defined(_PC8001MK2)
96         #define SUPPORT_PC88_KANJI1
97 //      #define SUPPORT_PC88_KANJI2
98         #define SUPPORT_PC88_OPN2
99         #define SUPPORT_PC88_OPNA
100         #define PC88_EXRAM_BANKS        1
101 #elif defined(_PC8001)
102 //      #define SUPPORT_PC88_KANJI1
103 //      #define SUPPORT_PC88_KANJI2
104 //      #define SUPPORT_PC88_OPN2
105 //      #define SUPPORT_PC88_OPNA
106 #endif
107 #define SUPPORT_PC88_PCG8100
108
109 // device informations for virtual machine
110 #define FRAMES_PER_SEC          62.422
111 #define LINES_PER_FRAME         260
112 #define CPU_CLOCKS              3993624
113 #define SCREEN_WIDTH            640
114 #define SCREEN_HEIGHT           400
115 #define WINDOW_HEIGHT_ASPECT    480
116 #define MAX_DRIVE               2
117 #define UPD765A_NO_ST1_EN_OR_FOR_RESULT7
118 #if defined(PC8801_VARIANT)
119 #define PC80S31K_NO_WAIT
120 #endif
121 #if defined(SUPPORT_PC88_CDROM)
122 #define SCSI_HOST_AUTO_ACK
123 #define SCSI_DEV_IMMEDIATE_SELECT
124 #endif
125 #define Z80_MEMORY_WAIT
126 #define OVERRIDE_SOUND_FREQ_48000HZ     55467
127
128 // device informations for win32
129 #if defined(PC8001_VARIANT)
130 #define USE_BOOT_MODE           3
131 #define USE_CPU_TYPE            2
132 #else
133 #define USE_BOOT_MODE           4
134 #define USE_CPU_TYPE            3
135 #endif
136 #if defined(_PC8801MA)
137 // V2 mode, 4MHz
138 #define BOOT_MODE_DEFAULT       2
139 #define CPU_TYPE_DEFAULT        1
140 #endif
141 #define USE_DIPSWITCH
142 #define USE_JOYSTICK_TYPE       2
143 #define USE_FLOPPY_DISK         2
144 #define USE_TAPE                1
145 #define TAPE_BINARY_ONLY
146 #if defined(SUPPORT_PC88_CDROM)
147 #define USE_COMPACT_DISC        1
148 #endif
149 #define USE_KEY_LOCKED
150 // slow enough for N88-\93ú\96{\8cêBASIC
151 #define USE_AUTO_KEY            8
152 #define USE_AUTO_KEY_RELEASE    10
153 #define USE_AUTO_KEY_NUMPAD
154 #define USE_MONITOR_TYPE        2
155 #define USE_SCREEN_FILTER
156 #define USE_SCANLINE
157
158 #if defined(_PC8801MA)
159         #define USE_SOUND_TYPE          6       // OPNA,OPN,OPN+OPNA,OPN+OPN,OPNA+OPNA,OPNA+OPN
160 #elif defined(_PC8001SR)
161         #define USE_SOUND_TYPE          3       // OPN,OPN+OPN,OPN+OPNA
162 #elif defined(_PC8001MK2) || defined(_PC8801MK2)
163         #define USE_SOUND_TYPE          3       // None,OPN,OPNA
164 #endif
165 #if defined(SUPPORT_PC88_OPN1)
166         #if defined(SUPPORT_PC88_OPNA)
167                 #define SOUND_VOLUME_OPN1       4
168         #else
169                 #define SOUND_VOLUME_OPN1       2
170         #endif
171 #else
172         #define SOUND_VOLUME_OPN1       0
173 #endif
174 #if defined(SUPPORT_PC88_OPN2)
175         #if defined(SUPPORT_PC88_OPNA)
176                 #define SOUND_VOLUME_OPN2       4
177         #else
178                 #define SOUND_VOLUME_OPN2       2
179         #endif
180 #else
181         #define SOUND_VOLUME_OPN2       0
182 #endif
183  #if defined(SUPPORT_PC88_CDROM)
184 #define SOUND_VOLUME_CDROM      1
185         #define SOUND_VOLUME_CDROM      1
186 #else
187         #define SOUND_VOLUME_CDROM      0
188 #endif
189 #if defined(SUPPORT_PC88_HMB20)
190         #define SOUND_VOLUME_HMB20      1
191 #else
192         #define SOUND_VOLUME_HMB20      0
193 #endif
194 #if defined(SUPPORT_PC88_PCG8100)
195         #define SOUND_VOLUME_PCG8100    1
196 #else
197         #define SOUND_VOLUME_PCG8100    0
198 #endif
199 #define USE_SOUND_VOLUME        (SOUND_VOLUME_OPN1 + SOUND_VOLUME_OPN2 + SOUND_VOLUME_CDROM + SOUND_VOLUME_HMB20 + SOUND_VOLUME_PCG8100 + 1 + 1)
200
201 #define SUPPORT_TV_RENDER
202 #define USE_JOYSTICK
203 #define USE_MOUSE
204 #define USE_PRINTER
205 #define USE_PRINTER_TYPE        3
206 #define USE_DEBUGGER
207 #define USE_STATE
208 #define USE_CPU_Z80
209
210 #include "../../common.h"
211 #include "../../fileio.h"
212 #include "../vm_template.h"
213
214 #ifdef USE_SOUND_VOLUME
215 static const _TCHAR *sound_device_caption[USE_SOUND_VOLUME] = {
216 #ifdef SUPPORT_PC88_OPN1
217         _T("OPN1 (FM)"), _T("OPN1 (PSG)"),
218 #ifdef SUPPORT_PC88_OPNA
219         _T("OPN1 (ADPCM)"), _T("OPN1 (Rhythm)"),
220 #endif
221 #endif
222 #ifdef SUPPORT_PC88_OPN2
223         _T("OPN2 (FM)"), _T("OPN2 (PSG)"),
224 #ifdef SUPPORT_PC88_OPNA
225         _T("OPN2 (ADPCM)"), _T("OPN2 (Rhythm)"),
226 #endif
227 #endif
228 #ifdef SUPPORT_PC88_CDROM
229         _T("CD-DA"),
230 #endif
231 #ifdef SUPPORT_PC88_HMB20
232         _T("HMB-20"),
233 #endif
234 #ifdef SUPPORT_PC88_PCG8100
235         _T("PCG-8100"),
236 #endif
237         _T("Beep"), _T("Noise (FDD)"),
238 };
239 #endif
240
241 class EMU;
242 class DEVICE;
243 class EVENT;
244
245 class I8251;
246 class I8255;
247 class NOISE;
248 class PCM1BIT;
249 class UPD1990A;
250 #if defined(SUPPORT_PC88_OPN1) || defined(SUPPORT_PC88_OPN2)
251 class YM2203;
252 #endif
253 class Z80;
254
255 class PC80S31K;
256 class UPD765A;
257
258 #ifdef SUPPORT_PC88_CDROM
259 class SCSI_HOST;
260 class SCSI_CDROM;
261 #endif
262
263 #ifdef SUPPORT_PC88_HMB20
264 class YM2151;
265 #endif
266
267 #ifdef SUPPORT_PC88_PCG8100
268 class I8253;
269 #endif
270 namespace PC88DEV {
271         class PC88;
272 }
273 class VM : public VM_TEMPLATE
274 {
275 protected:
276         //EMU* emu;
277         //csp_state_utils* state_entry;
278         
279         // devices
280         EVENT* pc88event;
281         
282         DEVICE* pc88prn;
283         I8251* pc88sio;
284         I8255* pc88pio;
285         PCM1BIT* pc88pcm;
286         UPD1990A* pc88rtc;
287 #ifdef SUPPORT_PC88_OPN1
288         YM2203* pc88opn1;
289 #endif
290 #ifdef SUPPORT_PC88_OPN2
291         YM2203* pc88opn2;
292 #endif
293         DEVICE* dummycpu;
294         Z80* pc88cpu;
295         
296         PC80S31K* pc88sub;
297         I8255* pc88pio_sub;
298         UPD765A* pc88fdc_sub;
299         NOISE* pc88noise_seek;
300         NOISE* pc88noise_head_down;
301         NOISE* pc88noise_head_up;
302         Z80* pc88cpu_sub;
303
304 #ifdef SUPPORT_PC88_CDROM
305         SCSI_HOST* pc88scsi_host;
306         SCSI_CDROM* pc88scsi_cdrom;
307 #endif
308
309 #ifdef SUPPORT_PC88_HMB20
310         YM2151* pc88opm;
311 #endif
312         
313 #ifdef SUPPORT_PC88_PCG8100
314         I8253* pc88pit;
315         PCM1BIT* pc88pcm0;
316         PCM1BIT* pc88pcm1;
317         PCM1BIT* pc88pcm2;
318 #endif
319         
320         PC88DEV::PC88* pc88;
321         
322         int boot_mode;
323         
324 public:
325         // ----------------------------------------
326         // initialize
327         // ----------------------------------------
328         
329         VM(EMU* parent_emu);
330         ~VM();
331         
332         // ----------------------------------------
333         // for emulation class
334         // ----------------------------------------
335         
336         // drive virtual machine
337         void reset();
338         void run();
339         double get_frame_rate();
340         
341 #ifdef USE_DEBUGGER
342         // debugger
343         DEVICE *get_cpu(int index);
344 #endif
345         
346         // draw screen
347         void draw_screen();
348         
349         // sound generation
350         void initialize_sound(int rate, int samples);
351         uint16_t* create_sound(int* extra_frames);
352         int get_sound_buffer_ptr();
353 #ifdef USE_SOUND_VOLUME
354         void set_sound_device_volume(int ch, int decibel_l, int decibel_r);
355 #endif
356         
357         // notify key
358         void key_down(int code, bool repeat);
359         void key_up(int code);
360         bool get_caps_locked();
361         bool get_kana_locked();
362         
363         // user interface
364         void open_floppy_disk(int drv, const _TCHAR* file_path, int bank);
365         void close_floppy_disk(int drv);
366         bool is_floppy_disk_inserted(int drv);
367         void is_floppy_disk_protected(int drv, bool value);
368         bool is_floppy_disk_protected(int drv);
369         uint32_t is_floppy_disk_accessed();
370         void play_tape(int drv, const _TCHAR* file_path);
371         void rec_tape(int drv, const _TCHAR* file_path);
372         void close_tape(int drv);
373         bool is_tape_inserted(int drv);
374 #ifdef SUPPORT_PC88_CDROM
375         void open_compact_disc(int drv, const _TCHAR* file_path);
376         void close_compact_disc(int drv);
377         bool is_compact_disc_inserted(int drv);
378         uint32_t is_compact_disc_accessed();
379 #endif
380         bool is_frame_skippable();
381         
382         void update_config();
383         bool process_state(FILEIO* state_fio, bool loading);
384         
385         // ----------------------------------------
386         // for each device
387         // ----------------------------------------
388         
389         // devices
390         DEVICE* get_device(int id);
391         //DEVICE* dummy;
392         //DEVICE* first_device;
393         //DEVICE* last_device;
394 };
395
396 #endif