OSDN Git Service

34fd5f180ed4ff20932e6b58e7ea27912dc9505d
[csp-qt/common_source_project-fm7.git] / source / src / vm / pc9801 / pc9801.h
1 /*
2         NEC PC-9801 Emulator 'ePC-9801'
3         NEC PC-9801E/F/M Emulator 'ePC-9801E'
4         NEC PC-98DO Emulator 'ePC-98DO'
5
6         Author : Takeda.Toshiya
7         Date   : 2010.09.15-
8
9         [ virtual machine ]
10 */
11
12 #ifndef _PC9801_H_
13 #define _PC9801_H_
14
15 #if defined(_PC9801)
16 #define DEVICE_NAME             "NEC PC-9801"
17 #define CONFIG_NAME             "pc9801"
18 #elif defined(_PC9801E)
19 #define DEVICE_NAME             "NEC PC-9801E/F/M"
20 #define CONFIG_NAME             "pc9801e"
21 #elif defined(_PC9801U)
22 #define DEVICE_NAME             "NEC PC-9801U"
23 #define CONFIG_NAME             "pc9801u"
24 #elif defined(_PC9801VF)
25 #define DEVICE_NAME             "NEC PC-9801VF"
26 #define CONFIG_NAME             "pc9801vf"
27 #elif defined(_PC9801VM)
28 #define DEVICE_NAME             "NEC PC-9801VM"
29 #define CONFIG_NAME             "pc9801vm"
30 #elif defined(_PC98DO)
31 #define DEVICE_NAME             "NEC PC-98DO"
32 #define CONFIG_NAME             "pc98do"
33 #elif defined(_PC98DOPLUS)
34 #define DEVICE_NAME             "NEC PC-98DO+"
35 #define CONFIG_NAME             "pc98do+"
36 #else
37 #endif
38
39 #if defined(_PC9801) || defined(_PC9801E)
40 #define SUPPORT_CMT_IF
41 #define SUPPORT_2HD_FDD_IF
42 #define SUPPORT_2DD_FDD_IF
43 #define SUPPORT_320KB_FDD_IF
44 #define SUPPORT_OLD_BUZZER
45 #elif defined(_PC9801VF) || defined(_PC9801U)
46 #define SUPPORT_2DD_FDD_IF
47 #else
48 #define SUPPORT_2HD_2DD_FDD_IF
49 #endif
50
51 #if !(defined(_PC9801) || defined(_PC9801U))
52 #define SUPPORT_2ND_VRAM
53 #endif
54 #if !(defined(_PC9801) || defined(_PC9801E))
55 #define SUPPORT_16_COLORS
56 #endif
57
58
59 // PC-9801-86
60 //#define SUPPORT_PC98_OPNA
61
62 #if defined(_PC98DO) || defined(_PC98DOPLUS)
63 #define MODE_PC98       0
64 #define MODE_PC88_V1S   1
65 #define MODE_PC88_V1H   2
66 #define MODE_PC88_V2    3
67 #define MODE_PC88_N     4
68 //#define SUPPORT_PC88_DICTIONARY
69 #define SUPPORT_PC88_HIGH_CLOCK
70 //#define SUPPORT_PC88_JOYSTICK
71 #define PC88_EXRAM_BANKS        4
72 #endif
73 #if defined(_PC98DOPLUS)
74 #define SUPPORT_PC88_OPNA
75 #define SUPPORT_PC88_SB2
76 #endif
77
78 // device informations for virtual machine
79 #define FRAMES_PER_SEC          56.4
80 #define LINES_PER_FRAME         440
81 #if defined(_PC9801)
82 #define CPU_CLOCKS              4992030
83 #define PIT_CLOCK_5MHZ
84 #elif defined(_PC9801E) || defined(_PC9801U) || defined(_PC9801VF)
85 #define CPU_CLOCKS              7987248
86 #define PIT_CLOCK_8MHZ
87 #elif defined(_PC98DOPLUS)
88 #define CPU_CLOCKS              15974496
89 #define PIT_CLOCK_8MHZ
90 #else
91 #define CPU_CLOCKS              9984060
92 #define PIT_CLOCK_5MHZ
93 #endif
94 #define SCREEN_WIDTH            640
95 #define SCREEN_HEIGHT           400
96 #define MAX_DRIVE               2
97 #define UPD765A_NO_ST1_EN_OR_FOR_RESULT7
98 #if defined(_PC98DO) || defined(_PC98DOPLUS)
99 #define PC80S31K_NO_WAIT
100 #endif
101 #define UPD7220_MSB_FIRST
102 #define UPD7220_HORIZ_FREQ      24830
103 #if defined(_PC9801) || defined(_PC9801E)
104 #define HAS_I86
105 #elif defined(_PC98DOPLUS)
106 #define HAS_V33A
107 #else
108 #define HAS_V30
109 #endif
110 #if defined(_PC98DO) || defined(_PC98DOPLUS)
111 #define HAS_UPD4990A
112 #define Z80_MEMORY_WAIT
113 #endif
114 #if defined(SUPPORT_PC98_OPNA) || defined(SUPPORT_PC88_OPNA)
115 #define HAS_YM2608
116 #endif
117 #define I8259_MAX_CHIPS         2
118 #define SINGLE_MODE_DMA
119 #define MEMORY_ADDR_MAX         0x100000
120 #define MEMORY_BANK_SIZE        0x800
121 #define IO_ADDR_MAX             0x10000
122 #define OVERRIDE_SOUND_FREQ_48000HZ     55467
123 #define SUPPORT_VARIABLE_TIMING
124
125 // device informations for win32
126 #if defined(_PC98DO) || defined(_PC98DOPLUS)
127 #define USE_BOOT_MODE           5
128 #define USE_DIPSWITCH
129 #endif
130 #if defined(_PC9801E) || defined(_PC9801VM) || defined(_PC98DO) || defined(_PC98DOPLUS)
131 #define USE_CPU_TYPE            2
132 #endif
133 #define USE_FD1
134 #define USE_FD2
135 #if defined(_PC9801) || defined(_PC9801E)
136 // for 640KB drives
137 #define USE_FD3
138 #define USE_FD4
139 // for 320KB drives
140 #define USE_FD5
141 #define USE_FD6
142 #elif defined(_PC98DO) || defined(_PC98DOPLUS)
143 // for PC-8801 drives
144 #define USE_FD3
145 #define USE_FD4
146 #endif
147 #if defined(SUPPORT_CMT_IF) || defined(_PC98DO) || defined(_PC98DOPLUS)
148 #define USE_TAPE
149 #define TAPE_BINARY_ONLY
150 #endif
151 #define NOTIFY_KEY_DOWN
152 #define USE_SHIFT_NUMPAD_KEY
153 #define USE_ALT_F10_KEY
154 #if defined(_PC98DO) || defined(_PC98DOPLUS)
155 // slow enough for N88-\93ú\96{\8cêBASIC
156 #define USE_AUTO_KEY            8
157 #define USE_AUTO_KEY_RELEASE    10
158 #define USE_MONITOR_TYPE        2
159 #define USE_SCANLINE
160 #else
161 #define USE_AUTO_KEY            5
162 #define USE_AUTO_KEY_RELEASE    6
163 #endif
164 #define USE_CRT_FILTER
165 #define USE_SCREEN_ROTATE
166 #define USE_ACCESS_LAMP
167 #define USE_SOUND_DEVICE_TYPE   4
168 #if defined(_PC98DO) || defined(_PC98DOPLUS)
169 #if    defined(SUPPORT_PC98_OPNA) &&  defined(SUPPORT_PC88_OPNA)
170 #define USE_SOUND_VOLUME        (4 + 1 + 1 + 4 + 1)
171 #elif  defined(SUPPORT_PC98_OPNA) && !defined(SUPPORT_PC88_OPNA)
172 #define USE_SOUND_VOLUME        (4 + 1 + 1 + 2 + 1)
173 #elif !defined(SUPPORT_PC98_OPNA) &&  defined(SUPPORT_PC88_OPNA)
174 #define USE_SOUND_VOLUME        (2 + 1 + 1 + 4 + 1)
175 #elif !defined(SUPPORT_PC98_OPNA) && !defined(SUPPORT_PC88_OPNA)
176 #define USE_SOUND_VOLUME        (2 + 1 + 1 + 2 + 1)
177 #endif
178 #else
179 #if defined(SUPPORT_PC98_OPNA)
180 #define USE_SOUND_VOLUME        (4 + 1 + 1)
181 #else
182 #define USE_SOUND_VOLUME        (2 + 1 + 1)
183 #endif
184 #endif
185 #define USE_PRINTER
186 #define USE_PRINTER_TYPE        4
187 #define USE_DEBUGGER
188 #define USE_STATE
189 #define USE_MOUSE
190 #define USE_JOYSTICK
191 #define USE_CRT_MONITOR_4_3 1
192
193 #include "../../common.h"
194 #include "../../fileio.h"
195
196 #ifdef USE_SOUND_VOLUME
197 static const _TCHAR *sound_device_caption[] = {
198 #if defined(SUPPORT_PC98_OPNA)
199         _T("PC-9801-86 (FM)"), _T("PC-9801-86 (PSG)"), _T("PC-9801-86 (ADPCM)"), _T("PC-9801-86 (Rhythm)"),
200 #else
201         _T("PC-9801-26 (FM)"), _T("PC-9801-26 (PSG)"),
202 #endif
203         _T("PC-9801-14"), _T("Beep"),
204 #if defined(_PC98DO) || defined(_PC98DOPLUS)
205 #if defined(SUPPORT_PC88_OPNA)
206         _T("PC-88 OPNA (FM)"), _T("PC-88 OPNA (PSG)"), _T("PC-88 OPNA (ADPCM)"), _T("PC-88 OPNA (Rhythm)"),
207 #else
208         _T("PC-88 OPN (FM)"), _T("PC-88 OPN (PSG)"),
209 #endif
210         _T("PC-88 Beep"), 
211 #endif
212 };
213 static const bool sound_device_monophonic[] = {
214 #if defined(SUPPORT_PC98_OPNA)
215         true, true, true, true,
216 #else
217         true, true,
218 #endif
219         false, false,
220 #if defined(_PC98DO) || defined(_PC98DOPLUS)
221 #if defined(SUPPORT_PC88_OPNA)
222         true, true, true, true,
223 #else
224         true, true,
225 #endif
226         false,
227 #endif
228 };
229 #endif
230
231 class EMU;
232 class DEVICE;
233 class EVENT;
234
235 #if defined(SUPPORT_OLD_BUZZER)
236 class BEEP;
237 #endif
238 class I8237;
239 class I8251;
240 class I8253;
241 class I8255;
242 class I8259;
243 class I286;
244 class IO;
245 class LS244;
246 class MEMORY;
247 class NOT;
248 #if !defined(SUPPORT_OLD_BUZZER)
249 class PCM1BIT;
250 #endif
251 class TMS3631;
252 class UPD1990A;
253 class UPD7220;
254 class UPD765A;
255 class YM2203;
256
257 #if defined(SUPPORT_CMT_IF)
258 class CMT;
259 #endif
260 class DISPLAY;
261 class FLOPPY;
262 class FMSOUND;
263 class JOYSTICK;
264 class KEYBOARD;
265 class MOUSE;
266
267 #if defined(SUPPORT_320KB_FDD_IF)
268 // 320kb fdd drives
269 class PC80S31K;
270 class Z80;
271 #endif
272
273 #if defined(_PC98DO) || defined(_PC98DOPLUS)
274 class PC80S31K;
275 class PC88;
276 class Z80;
277 #endif
278
279 class VM
280 {
281 protected:
282         EMU* emu;
283         
284         // devices
285         EVENT* event;
286         
287 #if defined(SUPPORT_OLD_BUZZER)
288         BEEP* beep;
289 #else
290         PCM1BIT* beep;
291 #endif
292         DEVICE* printer;
293         I8237* dma;
294 #if defined(SUPPORT_CMT_IF)
295         I8251* sio_cmt;
296 #endif
297         I8251* sio_rs;
298         I8251* sio_kbd;
299         I8253* pit;
300 #if defined(SUPPORT_320KB_FDD_IF)
301         I8255* pio_fdd;
302 #endif
303         I8255* pio_mouse;
304         I8255* pio_sys;
305         I8255* pio_prn;
306         I8259* pic;
307         I286* cpu;
308         IO* io;
309         LS244* dmareg1;
310         LS244* dmareg2;
311         LS244* dmareg3;
312         LS244* dmareg0;
313         LS244* rtcreg;
314         MEMORY* memory;
315         NOT* not_busy;
316 #if defined(HAS_I86) || defined(HAS_V30)
317         NOT* not_prn;
318 #endif
319         UPD1990A* rtc;
320 #if defined(SUPPORT_2HD_FDD_IF)
321         UPD765A* fdc_2hd;
322 #endif
323 #if defined(SUPPORT_2DD_FDD_IF)
324         UPD765A* fdc_2dd;
325 #endif
326 #if defined(SUPPORT_2HD_2DD_FDD_IF)
327         UPD765A* fdc;
328 #endif
329         UPD7220* gdc_chr;
330         UPD7220* gdc_gfx;
331         YM2203* opn;
332         
333 #if defined(SUPPORT_CMT_IF)
334         CMT* cmt;
335 #endif
336         DISPLAY* display;
337         FLOPPY* floppy;
338         FMSOUND* fmsound;
339         JOYSTICK* joystick;
340         KEYBOARD* keyboard;
341         MOUSE* mouse;
342         
343         // PC-9801-14
344         TMS3631* tms3631;
345         I8253* pit_14;
346         I8255* pio_14;
347         LS244* maskreg_14;
348         
349 #if defined(SUPPORT_320KB_FDD_IF)
350         // 320kb fdd drives
351         I8255* pio_sub;
352         PC80S31K *pc80s31k;
353         UPD765A* fdc_sub;
354         Z80* cpu_sub;
355 #endif
356         
357         // memory
358         uint8 ram[0xa0000];
359         uint8 ipl[0x18000];
360         uint8 sound_bios[0x4000];
361 #if defined(_PC9801) || defined(_PC9801E)
362         uint8 fd_bios_2hd[0x1000];
363         uint8 fd_bios_2dd[0x1000];
364 #endif
365         bool pit_clock_8mhz;
366
367         // sound
368         int sound_device_type;
369         
370 #if defined(_PC98DO) || defined(_PC98DOPLUS)
371         EVENT* pc88event;
372         
373         PC88* pc88;
374         DEVICE* pc88prn;
375         I8251* pc88sio;
376         I8255* pc88pio;
377         PCM1BIT* pc88pcm;
378         UPD1990A* pc88rtc;
379         YM2203* pc88opn;
380         Z80* pc88cpu;
381         
382         PC80S31K* pc88sub;
383         I8255* pc88pio_sub;
384         UPD765A* pc88fdc_sub;
385         Z80* pc88cpu_sub;
386         
387         int boot_mode;
388 #endif
389         
390 public:
391         // ----------------------------------------
392         // initialize
393         // ----------------------------------------
394         
395         VM(EMU* parent_emu);
396         ~VM();
397         
398         // ----------------------------------------
399         // for emulation class
400         // ----------------------------------------
401         
402         // drive virtual machine
403         void reset();
404         void run();
405         double frame_rate();
406         
407 #ifdef USE_DEBUGGER
408         // debugger
409         DEVICE *get_cpu(int index);
410 #endif
411         
412         // draw screen
413         void draw_screen();
414         int access_lamp();
415         
416         // sound generation
417         void initialize_sound(int rate, int samples);
418         uint16* create_sound(int* extra_frames);
419         int sound_buffer_ptr();
420 #ifdef USE_SOUND_VOLUME
421         void set_sound_device_volume(int ch, int decibel_l, int decibel_r);
422 #endif
423         
424         // notify key
425         void key_down(int code, bool repeat);
426         void key_up(int code);
427         
428         // user interface
429         void open_disk(int drv, const _TCHAR* file_path, int bank);
430         void close_disk(int drv);
431         bool disk_inserted(int drv);
432         void set_disk_protected(int drv, bool value);
433         bool get_disk_protected(int drv);
434 #if defined(SUPPORT_CMT_IF) || defined(_PC98DO) || defined(_PC98DOPLUS)
435         void play_tape(const _TCHAR* file_path);
436         void rec_tape(const _TCHAR* file_path);
437         void close_tape();
438         bool tape_inserted();
439 #endif
440         bool now_skip();
441         
442         void update_config();
443         void save_state(FILEIO* state_fio);
444         bool load_state(FILEIO* state_fio);
445         
446         // ----------------------------------------
447         // for each device
448         // ----------------------------------------
449         
450         // devices
451         DEVICE* get_device(int id);
452         DEVICE* dummy;
453         DEVICE* first_device;
454         DEVICE* last_device;
455 };
456
457 #endif