OSDN Git Service

[VM][General] Merge Upstream 20180530.
[csp-qt/common_source_project-fm7.git] / source / src / vm / mz700 / mz700.h
1 /*
2         SHARP MZ-700 Emulator 'EmuZ-700'
3         SHARP MZ-800 Emulator 'EmuZ-800'
4         SHARP MZ-1500 Emulator 'EmuZ-1500'
5
6         Author : Takeda.Toshiya
7         Date   : 2008.06.05 -
8
9         [ virtual machine ]
10 */
11
12 #ifndef _MZ700_H_
13 #define _MZ700_H_
14
15 #if defined(_MZ700)
16 #define DEVICE_NAME             "SHARP MZ-700"
17 #define CONFIG_NAME             "mz700"
18 #elif defined(_MZ800)
19 #define DEVICE_NAME             "SHARP MZ-800"
20 #define CONFIG_NAME             "mz800"
21 #elif defined(_MZ1500)
22 #define DEVICE_NAME             "SHARP MZ-1500"
23 #define CONFIG_NAME             "mz1500"
24 #endif
25
26 // device informations for virtual machine
27 #if defined(_MZ800)
28 #define FRAMES_PER_SEC          (3546895.0 / 228.0 / 312.0)
29 #define LINES_PER_FRAME         312
30 #define CPU_CLOCKS              3546895
31 #else
32 #define FRAMES_PER_SEC          (3579545.0 / 228.0 / 262.0)
33 #define LINES_PER_FRAME         262
34 #define CPU_CLOCKS              3579545
35 #endif
36 #define SCREEN_WIDTH            640
37 #define SCREEN_HEIGHT           400
38 #define WINDOW_HEIGHT_ASPECT    480
39 #define IO_ADDR_MAX             0x100
40 #define Z80_MEMORY_WAIT
41 #define Z80_IO_WAIT
42 #if defined(_MZ800) || defined(_MZ1500)
43 #define MAX_DRIVE               4
44 #define HAS_MB8876
45 #endif
46 #if defined(_MZ1500)
47 #define MZ1P17_SW1_4_ON
48 #endif
49
50 // device informations for win32
51 #if defined(_MZ700)
52 #define USE_DIPSWITCH
53 #elif defined(_MZ800)
54 #define USE_BOOT_MODE           2
55 #endif
56 #define USE_TAPE                1
57 #define USE_TAPE_BUTTON
58 #if defined(_MZ800) || defined(_MZ1500)
59 #define USE_FLOPPY_DISK         2
60 #define USE_QUICK_DISK          1
61 #endif
62 #define USE_SHIFT_NUMPAD_KEY
63 #define USE_ALT_F10_KEY
64 #define USE_AUTO_KEY            5
65 #define USE_AUTO_KEY_RELEASE    6
66 #define USE_AUTO_KEY_CAPS
67 #if defined(_MZ700) || defined(_MZ1500)
68 #define USE_AUTO_KEY_NUMPAD
69 #define USE_VM_AUTO_KEY_TABLE
70 #endif
71 #if defined(_MZ800)
72 #define USE_MONITOR_TYPE        2
73 #endif
74 #define USE_SCREEN_FILTER
75 #define USE_SCANLINE
76 #if defined(_MZ700)
77 #define USE_SOUND_VOLUME        3
78 #elif defined(_MZ800)
79 #define USE_SOUND_VOLUME        5
80 #elif defined(_MZ1500)
81 #define USE_SOUND_VOLUME        6
82 #endif
83 #if defined(_MZ1500)
84 #define USE_PRINTER
85 #define USE_PRINTER_TYPE        4
86 #endif
87 #define SUPPORT_TV_RENDER
88 #define USE_DEBUGGER
89 #define USE_STATE
90 #define USE_CPU_Z80
91
92 #if defined(_MZ700) || defined(_MZ1500)
93 static const int vm_auto_key_table_base[][2] = {
94         // thanks Mr.Koucha Youkan
95         {0xa1,  0x300 | 0xbe},  // '¡'    *** MODIFIED ***
96         {0xa2,  0x300 | 0x38},  // '¢'    *** MODIFIED ***
97         {0xa3,  0x300 | 0x39},  // '£'    *** MODIFIED ***
98         {0xa4,  0x300 | 0xbc},  // '¤'    *** MODIFIED ***
99         {0xa5,  0x300 | 0x30},  // '¥'    *** MODIFIED ***
100         {0xa6,  0x200 | 0xdb},  // '¦'    *** MODIFIED ***
101         {0xa7,  0x300 | 0x31},  // '§'
102         {0xa8,  0x300 | 0x32},  // '¨'
103         {0xa9,  0x300 | 0x33},  // '©'
104         {0xaa,  0x300 | 0x34},  // 'ª'
105         {0xab,  0x300 | 0x35},  // '«'
106         {0xac,  0x300 | 0xbd},  // '¬'    *** MODIFIED ***
107         {0xad,  0x300 | 0xde},  // '­'    *** MODIFIED ***
108         {0xae,  0x300 | 0xdc},  // '®'    *** MODIFIED ***
109         {0xaf,  0x300 | 0x43},  // '¯'
110         {0xb0,  0x200 | 0xe2},  // '°'    *** MODIFIED ***
111         {0xb1,  0x200 | 0x31},  // '±'
112         {0xb2,  0x200 | 0x32},  // '²'
113         {0xb3,  0x200 | 0x33},  // '³'
114         {0xb4,  0x200 | 0x34},  // '´'
115         {0xb5,  0x200 | 0x35},  // 'µ'
116         {0xb6,  0x200 | 0x51},  // '¶'
117         {0xb7,  0x200 | 0x57},  // '·'
118         {0xb8,  0x200 | 0x45},  // '¸'
119         {0xb9,  0x200 | 0x52},  // '¹'
120         {0xba,  0x200 | 0x54},  // 'º'
121         {0xbb,  0x200 | 0x41},  // '»'
122         {0xbc,  0x200 | 0x53},  // '¼'
123         {0xbd,  0x200 | 0x44},  // '½'
124         {0xbe,  0x200 | 0x46},  // '¾'
125         {0xbf,  0x200 | 0x47},  // '¿'
126         {0xc0,  0x200 | 0x5a},  // 'À'
127         {0xc1,  0x200 | 0x58},  // 'Á'
128         {0xc2,  0x200 | 0x43},  // 'Â'
129         {0xc3,  0x200 | 0x56},  // 'Ã'
130         {0xc4,  0x200 | 0x42},  // 'Ä'
131         {0xc5,  0x200 | 0x36},  // 'Å'
132         {0xc6,  0x200 | 0x37},  // 'Æ'
133         {0xc7,  0x200 | 0x38},  // 'Ç'
134         {0xc8,  0x200 | 0x39},  // 'È'
135         {0xc9,  0x200 | 0x30},  // 'É'
136         {0xca,  0x200 | 0x59},  // 'Ê'
137         {0xcb,  0x200 | 0x55},  // 'Ë'
138         {0xcc,  0x200 | 0x49},  // 'Ì'
139         {0xcd,  0x200 | 0x4f},  // 'Í'
140         {0xce,  0x200 | 0x50},  // 'Î'
141         {0xcf,  0x200 | 0x48},  // 'Ï'
142         {0xd0,  0x200 | 0x4a},  // 'Ð'
143         {0xd1,  0x200 | 0x4b},  // 'Ñ'
144         {0xd2,  0x200 | 0x4c},  // 'Ò'
145         {0xd3,  0x200 | 0xbb},  // 'Ó'
146         {0xd4,  0x200 | 0xbd},  // 'Ô'    *** MODIFIED ***
147         {0xd5,  0x200 | 0xde},  // 'Õ'    *** MODIFIED ***
148         {0xd6,  0x200 | 0xdc},  // 'Ö'    *** MODIFIED ***
149         {0xd7,  0x200 | 0x4e},  // '×'    *** MODIFIED ***
150         {0xd8,  0x200 | 0x4d},  // 'Ø'    *** MODIFIED ***
151         {0xd9,  0x200 | 0xbc},  // 'Ù'    *** MODIFIED ***
152         {0xda,  0x200 | 0xbe},  // 'Ú'    *** MODIFIED ***
153         {0xdb,  0x200 | 0xbf},  // 'Û'    *** MODIFIED ***
154         {0xdc,  0x200 | 0xc0},  // 'Ü'    *** MODIFIED ***
155         {0xdd,  0x200 | 0x78},  // 'Ý'    *** MODIFIED ***
156         {0xde,  0x200 | 0xba},  // 'Þ'    *** MODIFIED ***
157         {0xdf,  0x200 | 0xdd},  // 'ß'    *** MODIFIED ***
158         {-1,    -1},
159 };
160 #endif
161
162 #include "../../common.h"
163 #include "../../fileio.h"
164 #include "../vm_template.h"
165
166 #ifdef USE_SOUND_VOLUME
167 static const _TCHAR *sound_device_caption[] = {
168 #if defined(_MZ800)
169         _T("PSG"),
170 #elif defined(_MZ1500)
171         _T("PSG #1"), _T("PSG #2"),
172 #endif
173         _T("Beep"), _T("CMT (Signal)"),
174 #if defined(_MZ800) || defined(_MZ1500)
175         _T("Noise (FDD)"),
176 #endif
177         _T("Noise (CMT)"),
178 };
179 #endif
180
181 class csp_state_utils;
182 class EMU;
183 class DEVICE;
184 class EVENT;
185
186 class AND;
187 class DATAREC;
188 class I8253;
189 class I8255;
190 class IO;
191 class PCM1BIT;
192 class Z80;
193
194 //class CMOS;
195 class EMM;
196 class KANJI;
197 class KEYBOARD;
198 class MEMORY;
199 class RAMFILE;
200
201 #if defined(_MZ800) || defined(_MZ1500)
202 class MB8877;
203 class NOT;
204 class SN76489AN;
205 class Z80PIO;
206 class Z80SIO;
207 class FLOPPY;
208 #if defined(_MZ1500)
209 class PSG;
210 #endif
211 class QUICKDISK;
212 #endif
213
214 class VM : public VM_TEMPLATE
215 {
216 protected:
217         //EMU* emu;
218         //csp_state_utils* state_entry;
219         
220         // devices
221         //EVENT* event;
222         
223         AND* and_int;
224         DATAREC* drec;
225         I8253* pit;
226         I8255* pio;
227         IO* io;
228         PCM1BIT* pcm;
229         Z80* cpu;
230         
231 //      CMOS* cmos;
232         EMM* emm;
233         KANJI* kanji;
234         KEYBOARD* keyboard;
235         MEMORY* memory;
236         RAMFILE* ramfile;
237         
238 #if defined(_MZ800) || defined(_MZ1500)
239         AND* and_snd;
240         MB8877* fdc;
241 #if defined(_MZ800)
242         NOT* not_pit;
243         SN76489AN* psg;
244 #elif defined(_MZ1500)
245         DEVICE* printer;
246         NOT* not_reset;
247         NOT* not_strobe;
248         SN76489AN* psg_l;
249         SN76489AN* psg_r;
250 #endif
251         Z80PIO* pio_int;
252         Z80SIO* sio_rs; // RS-232C
253         Z80SIO* sio_qd; // QD
254         
255         FLOPPY* floppy;
256 #if defined(_MZ1500)
257         PSG* psg;
258 #endif
259         QUICKDISK* qd;
260 #endif
261         
262 #if defined(_MZ800)
263         int boot_mode;
264 #endif
265         
266 public:
267         // ----------------------------------------
268         // initialize
269         // ----------------------------------------
270         
271         VM(EMU* parent_emu);
272         ~VM();
273         
274         // ----------------------------------------
275         // for emulation class
276         // ----------------------------------------
277         
278         // drive virtual machine
279         void reset();
280         void run();
281         
282 #ifdef USE_DEBUGGER
283         // debugger
284         DEVICE *get_cpu(int index);
285 #endif
286         
287         // draw screen
288         void draw_screen();
289         
290         // sound generation
291         void initialize_sound(int rate, int samples);
292         uint16_t* create_sound(int* extra_frames);
293         int get_sound_buffer_ptr();
294 #ifdef USE_SOUND_VOLUME
295         void set_sound_device_volume(int ch, int decibel_l, int decibel_r);
296 #endif
297         
298         // user interface
299         void play_tape(int drv, const _TCHAR* file_path);
300         void rec_tape(int drv, const _TCHAR* file_path);
301         void close_tape(int drv);
302         bool is_tape_inserted(int drv);
303         bool is_tape_playing(int drv);
304         bool is_tape_recording(int drv);
305         int get_tape_position(int drv);
306         const _TCHAR* get_tape_message(int drv);
307         void push_play(int drv);
308         void push_stop(int drv);
309         void push_fast_forward(int drv);
310         void push_fast_rewind(int drv);
311         void push_apss_forward(int drv) {}
312         void push_apss_rewind(int drv) {}
313 #if defined(_MZ800) || defined(_MZ1500)
314         void open_quick_disk(int drv, const _TCHAR* file_path);
315         void close_quick_disk(int drv);
316         bool is_quick_disk_inserted(int drv);
317         uint32_t is_quick_disk_accessed();
318         void open_floppy_disk(int drv, const _TCHAR* file_path, int bank);
319         void close_floppy_disk(int drv);
320         bool is_floppy_disk_inserted(int drv);
321         void is_floppy_disk_protected(int drv, bool value);
322         bool is_floppy_disk_protected(int drv);
323         uint32_t is_floppy_disk_accessed();
324 #endif
325         bool is_frame_skippable();
326         
327         void update_config();
328         void decl_state();
329         void save_state(FILEIO* state_fio);
330         bool load_state(FILEIO* state_fio);
331         
332         // ----------------------------------------
333         // for each device
334         // ----------------------------------------
335         
336         // devices
337         DEVICE* get_device(int id);
338         //DEVICE* dummy;
339         //DEVICE* first_device;
340         //DEVICE* last_device;
341 };
342
343 #endif