OSDN Git Service

[General] Merge Upstream 2017-08-10.
[csp-qt/common_source_project-fm7.git] / source / src / vm / x1 / x1.h
1 /*
2         SHARP X1 Emulator 'eX1'
3         SHARP X1twin Emulator 'eX1twin'
4         SHARP X1turbo Emulator 'eX1turbo'
5
6         Author : Takeda.Toshiya
7         Date   : 2009.03.11-
8
9         [ virtual machine ]
10 */
11
12 #ifndef _X1_H_
13 #define _X1_H_
14
15 #if defined(_X1TURBOZ)
16 #define DEVICE_NAME             "SHARP X1turboZ"
17 #define CONFIG_NAME             "x1turboz"
18 #elif defined(_X1TURBO)
19 #define DEVICE_NAME             "SHARP X1turbo"
20 #define CONFIG_NAME             "x1turbo"
21 #elif defined(_X1TWIN)
22 #define DEVICE_NAME             "SHARP X1twin"
23 #define CONFIG_NAME             "x1twin"
24 #else
25 #define DEVICE_NAME             "SHARP X1"
26 #define CONFIG_NAME             "x1"
27 #endif
28
29 #if defined(_X1TURBO) || defined(_X1TURBOZ)
30 #define _X1TURBO_FEATURE
31 #endif
32
33 // device informations for virtual machine (x1)
34 #define VDP_CLOCK               28636363
35 //#ifdef _X1TURBO_FEATURE
36 //24KHz
37 //#define FRAMES_PER_SEC        55.49
38 //#define LINES_PER_FRAME       448
39 //#define CHARS_PER_LINE        56
40 //#define HD46505_CHAR_CLOCK    (VDP_CLOCK * 1.5 / 32.0)
41 //#else
42 // 15KHz
43 #define FRAMES_PER_SEC          61.94
44 #define LINES_PER_FRAME         258
45 #define CHARS_PER_LINE          56
46 #define HD46505_CHAR_CLOCK      (VDP_CLOCK / 32.0)
47 //#endif
48 #define CPU_CLOCKS              4000000
49 #define SCREEN_WIDTH            640
50 #define SCREEN_HEIGHT           400
51 #define WINDOW_HEIGHT_ASPECT    480
52 #define MAX_DRIVE               4
53 #define IO_ADDR_MAX             0x10000
54 #define HAS_AY_3_8910
55 #define Z80_IO_WAIT
56 #ifdef _X1TURBO_FEATURE
57 #define SINGLE_MODE_DMA
58 #endif
59 #define DATAREC_FAST_FWD_SPEED  16
60 #define DATAREC_FAST_REW_SPEED  16
61 #define PRINTER_STROBE_RISING_EDGE
62 #define SUPPORT_VARIABLE_TIMING
63
64 #ifdef _X1TURBO_FEATURE
65 #define IPL_ROM_FILE_SIZE       0x8000
66 #define IPL_ROM_FILE_NAME       _T("IPLROM.X1T")
67 #define SUB_ROM_FILE_NAME       _T("SUBROM.X1T")
68 #define KBD_ROM_FILE_NAME       _T("KBDROM.X1T")
69 #else
70 #define IPL_ROM_FILE_SIZE       0x1000
71 #define IPL_ROM_FILE_NAME       _T("IPLROM.X1")
72 #define SUB_ROM_FILE_NAME       _T("SUBROM.X1")
73 #define KBD_ROM_FILE_NAME       _T("KBDROM.X1")
74 #endif
75 #define CRC32_MSM80C49_262      0x43EE7D6F      // X1turbo with CMT
76 #define CRC32_MSM80C49_277      0x75904EFB      // X1turbo (not supported yet)
77
78 #ifdef _X1TWIN
79 // device informations for virtual machine (pce)
80 #define PCE_FRAMES_PER_SEC      60
81 #define PCE_LINES_PER_FRAME     262
82 #define PCE_CPU_CLOCKS          7159090
83 #endif
84
85 // device informations for win32
86 #define USE_SPECIAL_RESET
87 #ifdef _X1TURBO_FEATURE
88 #define USE_KEYBOARD_TYPE       2
89 // Keyboard mode B
90 #define KEYBOARD_TYPE_DEFAULT   1
91 #define USE_DRIVE_TYPE          2
92 #endif
93 #define USE_FD1
94 #define USE_FD2
95 #define FD_BASE_NUMBER          0
96 #define USE_TAPE1
97 #define USE_TAPE_BUTTON
98 #ifdef _X1TWIN
99 #define USE_CART1
100 #endif
101 #define NOTIFY_KEY_DOWN
102 #define USE_KEY_LOCKED
103 #define USE_SHIFT_NUMPAD_KEY
104 #define USE_ALT_F10_KEY
105 #define USE_AUTO_KEY            8
106 #define USE_AUTO_KEY_RELEASE    10
107 #define USE_AUTO_KEY_NUMPAD
108 #define USE_MONITOR_TYPE        2
109 #define USE_SCREEN_FILTER
110 #define USE_SCANLINE
111 #define USE_SOUND_TYPE          3
112 // ToDo
113 //#define DATAREC_SOUND
114 #define SUPPORT_ROMA_KANA_CONVERSION
115 // CZ-8BS1 x1
116 #define SOUND_TYPE_DEFAULT      1
117 # if defined(_X1TWIN)
118 # define USE_SOUND_VOLUME       7
119 # else
120 # define USE_SOUND_VOLUME       6
121 # endif
122 #define SUPPORT_TV_RENDER
123 #define USE_JOYSTICK
124 #ifdef _X1TWIN
125 #define USE_JOYSTICK_TYPE       4
126 #define JOYSTICK_TYPE_DEFAULT   0
127 #endif
128 #define USE_JOY_BUTTON_CAPTIONS
129 #define USE_MOUSE
130 #define USE_PRINTER
131 #define USE_PRINTER_TYPE        4
132 #define USE_DEBUGGER
133 #define USE_STATE
134
135 #include "../../common.h"
136 #include "../../fileio.h"
137
138 #ifdef USE_SOUND_VOLUME
139 static const _TCHAR *sound_device_caption[] = {
140         _T("PSG"), _T("CZ-8BS1 #1"), _T("CZ-8BS1 #2"), _T("CMT (Signal)"), _T("Noise (FDD)"), _T("Noise (CMT)"),
141 #if defined(_X1TWIN)
142         _T("PC Engine PSG"),
143 #endif
144 };
145 #endif
146
147 #ifdef USE_JOY_BUTTON_CAPTIONS
148 #ifdef _X1TWIN
149 static const _TCHAR *joy_button_captions[] = {
150         _T("Up"),
151         _T("Down"),
152         _T("Left"),
153         _T("Right"),
154         _T("Button #1"),
155         _T("Button #2"),
156         _T("Select"),
157         _T("Run"),
158         _T("Button #3"),
159         _T("Button #4"),
160         _T("Button #5"),
161         _T("Button #6"),
162 };
163 #else // not X1 Twin
164 static const _TCHAR *joy_button_captions[] = {
165         _T("Up"),
166         _T("Down"),
167         _T("Left"),
168         _T("Right"),
169         _T("Button #1"),
170         _T("Button #2"),
171 };
172 #endif
173 #endif
174 // from X-millenium
175
176 static const uint16_t ANKFONT7f_9f[0x21 * 8] = {
177         0x0000, 0x3000, 0x247f, 0x6c24, 0x484c, 0xce4b, 0x0000, 0x0000,
178
179         0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xffff,
180         0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xffff, 0xffff,
181         0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xffff, 0xffff, 0xffff,
182         0x0000, 0x0000, 0x0000, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff,
183         0x0000, 0x0000, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
184         0x0000, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
185         0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
186         0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
187         0x8080, 0x8080, 0x8080, 0x8080, 0x8080, 0x8080, 0x8080, 0x8080,
188         0xc0c0, 0xc0c0, 0xc0c0, 0xc0c0, 0xc0c0, 0xc0c0, 0xc0c0, 0xc0c0,
189         0xe0e0, 0xe0e0, 0xe0e0, 0xe0e0, 0xe0e0, 0xe0e0, 0xe0e0, 0xe0e0,
190         0xf0f0, 0xf0f0, 0xf0f0, 0xf0f0, 0xf0f0, 0xf0f0, 0xf0f0, 0xf0f0,
191         0xf8f8, 0xf8f8, 0xf8f8, 0xf8f8, 0xf8f8, 0xf8f8, 0xf8f8, 0xf8f8,
192         0xfcfc, 0xfcfc, 0xfcfc, 0xfcfc, 0xfcfc, 0xfcfc, 0xfcfc, 0xfcfc,
193         0xfefe, 0xfefe, 0xfefe, 0xfefe, 0xfefe, 0xfefe, 0xfefe, 0xfefe,
194         0x0101, 0x0202, 0x0404, 0x0808, 0x1010, 0x2020, 0x4040, 0x8080,
195
196         0x0000, 0x0000, 0x0000, 0x0000, 0x00ff, 0x0000, 0x0000, 0x0000,
197         0x1010, 0x1010, 0x1010, 0x1010, 0x1010, 0x1010, 0x1010, 0x1010,
198         0x1010, 0x1010, 0x1010, 0x1010, 0x00ff, 0x0000, 0x0000, 0x0000,
199         0x0000, 0x0000, 0x0000, 0x0000, 0x10ff, 0x1010, 0x1010, 0x1010,
200         0x1010, 0x1010, 0x1010, 0x1010, 0x10f0, 0x1010, 0x1010, 0x1010,
201         0x1010, 0x1010, 0x1010, 0x1010, 0x101f, 0x1010, 0x1010, 0x1010,
202         0x1010, 0x1010, 0x1010, 0x1010, 0x10ff, 0x1010, 0x1010, 0x1010,
203         0x0000, 0x0000, 0x0000, 0x0000, 0x10f0, 0x1010, 0x1010, 0x1010,
204         0x1010, 0x1010, 0x1010, 0x1010, 0x00f0, 0x0000, 0x0000, 0x0000,
205         0x1010, 0x1010, 0x1010, 0x1010, 0x001f, 0x0000, 0x0000, 0x0000,
206         0x0000, 0x0000, 0x0000, 0x0000, 0x101f, 0x1010, 0x1010, 0x1010,
207         0x0000, 0x0000, 0x0000, 0x0000, 0x4080, 0x2020, 0x1010, 0x1010,
208         0x1010, 0x1010, 0x0810, 0x0408, 0x0003, 0x0000, 0x0000, 0x0000,
209         0x1010, 0x1010, 0x2010, 0x4020, 0x0080, 0x0000, 0x0000, 0x0000,
210         0x0000, 0x0000, 0x0000, 0x0000, 0x0403, 0x0808, 0x1010, 0x1010,
211         0x8080, 0x4040, 0x2020, 0x1010, 0x0808, 0x0404, 0x0202, 0x0101
212 };
213
214 static const uint16_t ANKFONTe0_ff[0x20 * 8] = {
215         0x0000, 0x7e3c, 0xffff, 0xdbdb, 0xffff, 0xe7db, 0x7eff, 0x003c,
216         0x0000, 0x423c, 0x8181, 0xa5a5, 0x8181, 0x99a5, 0x4281, 0x003c,
217         0x0000, 0x3810, 0x7c7c, 0xfefe, 0xfefe, 0x106c, 0x7c38, 0x0000,
218         0x0000, 0x6c00, 0xfefe, 0xfefe, 0xfefe, 0x7c7c, 0x1038, 0x0000,
219         0x0000, 0x1010, 0x3838, 0x7c7c, 0x7cfe, 0x387c, 0x1038, 0x0010,
220         0x0000, 0x3810, 0x7c7c, 0x5438, 0xfefe, 0x6cfe, 0x7c10, 0x0000,
221         0x0101, 0x0303, 0x0707, 0x0f0f, 0x1f1f, 0x3f3f, 0x7f7f, 0xffff,
222         0x8080, 0xc0c0, 0xe0e0, 0xf0f0, 0xf8f8, 0xfcfc, 0xfefe, 0xffff,
223         0x8181, 0x4242, 0x2424, 0x1818, 0x1818, 0x2424, 0x4242, 0x8181,
224         0xf0f0, 0xf0f0, 0xf0f0, 0xf0f0, 0x0000, 0x0000, 0x0000, 0x0000,
225         0x0000, 0x0000, 0x0000, 0x0000, 0xf0f0, 0xf0f0, 0xf0f0, 0xf0f0,
226         0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x0000, 0x0000, 0x0000, 0x0000,
227         0x0000, 0x0000, 0x0000, 0x0000, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f,
228         0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0xf0f0, 0xf0f0, 0xf0f0, 0xf0f0,
229         0xf0f0, 0xf0f0, 0xf0f0, 0xf0f0, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f,
230         0x81ff, 0x8181, 0x8181, 0x8181, 0x8181, 0x8181, 0x8181, 0xff81,
231
232         0x55aa, 0x55aa, 0x55aa, 0x55aa, 0x55aa, 0x55aa, 0x55aa, 0x55aa,
233         0x1000, 0x1010, 0xf01e, 0x1010, 0x1010, 0x1010, 0x7e10, 0x00c0,
234         0x1000, 0x2418, 0x7c42, 0x1090, 0x781c, 0x5410, 0xfe54, 0x0000,
235         0x1000, 0x1010, 0xfe10, 0x1010, 0x3030, 0x565c, 0x9090, 0x0010,
236         0x1000, 0x1210, 0xf412, 0x3034, 0x5030, 0x9654, 0x1090, 0x0000,
237         0x0800, 0x8808, 0x5292, 0x1454, 0x2020, 0x5020, 0x465c, 0x0040,
238         0x0000, 0xe23c, 0x8282, 0x82fa, 0x7a82, 0x4242, 0x0044, 0x0000,
239         0x0000, 0x443c, 0x8242, 0xf282, 0x8282, 0x8282, 0x3844, 0x0000,
240         0x0800, 0x5e18, 0xa468, 0xe4be, 0xbea4, 0xb2a2, 0x0a5a, 0x0002,
241         0x0000, 0x2628, 0x4042, 0xe23c, 0x2222, 0x4222, 0x4442, 0x0004,
242         0x0800, 0x0808, 0xda7a, 0x5454, 0x46e4, 0xe442, 0x08c4, 0x0000,
243         0x0000, 0x7e40, 0x8848, 0x28be, 0x2828, 0x3e28, 0x08e8, 0x0008,
244         0x0000, 0x723c, 0x9252, 0x9292, 0x8292, 0x84fc, 0x8484, 0x0000,
245         0x0000, 0x1010, 0x2010, 0x2020, 0x6040, 0x8c50, 0x8286, 0x0000,
246         0x0000, 0x4040, 0x784e, 0x88c0, 0x388e, 0x0848, 0x7e08, 0x0000,
247         0x0000, 0x7c00, 0x0000, 0x0000, 0x10fe, 0x1010, 0x1010, 0x0010
248 };
249
250 class EMU;
251 class DEVICE;
252 class EVENT;
253
254 class DATAREC;
255 class HD46505;
256 class I8255;
257 class IO;
258 class MB8877;
259 class YM2151;
260 //class YM2203;
261 class AY_3_891X;
262 class Z80;
263 class Z80CTC;
264 class Z80SIO;
265 #ifdef _X1TURBO_FEATURE
266 class Z80DMA;
267 #endif
268
269 class DISPLAY;
270 class EMM;
271 class FLOPPY;
272 class IOBUS;
273 class JOYSTICK;
274 class MEMORY;
275 class MOUSE;
276 class PSUB;
277
278 class MCS48;
279 class UPD1990A;
280 class SUB;
281 class KEYBOARD;
282
283 #ifdef _X1TWIN
284 class HUC6280;
285 class PCE;
286 #endif
287 class VM
288 {
289 protected:
290         EMU* emu;
291         
292         // devices for x1
293         EVENT* event;
294         
295         DATAREC* drec;
296         DEVICE* printer;
297         HD46505* crtc;
298         I8255* pio;
299         IO* io;
300         MB8877* fdc;
301         YM2151* opm1;
302         YM2151* opm2;
303 //      YM2203* psg;
304         AY_3_891X* psg;
305         Z80* cpu;
306         Z80CTC* ctc;
307         Z80SIO* sio;
308         Z80CTC* ctc1;
309         Z80CTC* ctc2;
310 #ifdef _X1TURBO_FEATURE
311         Z80DMA* dma;
312 #endif
313         DISPLAY* display;
314         EMM* emm;
315         FLOPPY* floppy;
316         IOBUS* iobus;
317         JOYSTICK* joy;
318         MEMORY* memory;
319         MOUSE* mouse;
320         PSUB* psub;
321         
322         MCS48* cpu_sub;
323         UPD1990A* rtc_sub;
324         I8255* pio_sub;
325         SUB* sub;
326         
327         MCS48* cpu_kbd;
328         KEYBOARD* kbd;
329         
330         bool pseudo_sub_cpu;
331         int sound_type;
332         
333 #ifdef _X1TWIN
334         // device for pce
335         EVENT* pceevent;
336         
337         HUC6280* pcecpu;
338         PCE* pce;
339 #endif
340         
341 public:
342         // ----------------------------------------
343         // initialize
344         // ----------------------------------------
345         
346         VM(EMU* parent_emu);
347         ~VM();
348         
349         // ----------------------------------------
350         // for emulation class
351         // ----------------------------------------
352         
353         // drive virtual machine
354         void reset();
355         void special_reset();
356         void run();
357         double get_frame_rate();
358         
359 #ifdef USE_DEBUGGER
360         // debugger
361         DEVICE *get_cpu(int index);
362 #endif
363         
364         // draw screen
365         void draw_screen();
366         
367         // sound generation
368         void initialize_sound(int rate, int samples);
369         uint16_t* create_sound(int* extra_frames);
370         int get_sound_buffer_ptr();
371 #ifdef USE_SOUND_VOLUME
372         void set_sound_device_volume(int ch, int decibel_l, int decibel_r);
373 #endif
374         
375         // notify key
376         void key_down(int code, bool repeat);
377         void key_up(int code);
378         bool get_caps_locked();
379         bool get_kana_locked();
380         
381         // user interface
382         void open_floppy_disk(int drv, const _TCHAR* file_path, int bank);
383         void close_floppy_disk(int drv);
384         bool is_floppy_disk_inserted(int drv);
385         void is_floppy_disk_protected(int drv, bool value);
386         bool is_floppy_disk_protected(int drv);
387         uint32_t is_floppy_disk_accessed();
388         void play_tape(int drv, const _TCHAR* file_path);
389         void rec_tape(int drv, const _TCHAR* file_path);
390         void close_tape(int drv);
391         bool is_tape_inserted(int drv);
392         bool is_tape_playing(int drv);
393         bool is_tape_recording(int drv);
394         int get_tape_position(int drv);
395         const _TCHAR* get_tape_message(int drv);
396         void push_play(int drv);
397         void push_stop(int drv);
398         void push_fast_forward(int drv);
399         void push_fast_rewind(int drv);
400         void push_apss_forward(int drv);
401         void push_apss_rewind(int drv);
402         bool is_frame_skippable();
403 #ifdef _X1TWIN
404         void open_cart(int drv, const _TCHAR* file_path);
405         void close_cart(int drv);
406         bool is_cart_inserted(int drv);
407 #endif
408         
409         void update_config();
410 #ifdef _X1TURBO_FEATURE
411         void update_dipswitch();
412 #endif
413         void save_state(FILEIO* state_fio);
414         bool load_state(FILEIO* state_fio);
415         
416         // ----------------------------------------
417         // for each device
418         // ----------------------------------------
419         
420         // devices
421         DEVICE* get_device(int id);
422         DEVICE* dummy;
423         DEVICE* first_device;
424         DEVICE* last_device;
425 };
426
427 #endif