OSDN Git Service

[VM][General][Qt] Merge upstream 2015-12-31.
[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 //#ifdef _X1TURBO_FEATURE
35 //24KHz
36 //#define FRAMES_PER_SEC        55.49
37 //#define LINES_PER_FRAME       448
38 //#define CHARS_PER_LINE        56
39 //#define HD46505_HORIZ_FREQ    24860
40 //#else
41 // 15KHz
42 #define FRAMES_PER_SEC          61.94
43 #define LINES_PER_FRAME         258
44 #define CHARS_PER_LINE          56
45 #define HD46505_HORIZ_FREQ      15980
46 //#endif
47 #define CPU_CLOCKS              4000000
48 #define SCREEN_WIDTH            640
49 #define SCREEN_HEIGHT           400
50 #define MAX_DRIVE               4
51 #define IO_ADDR_MAX             0x10000
52 #define HAS_AY_3_8910
53 #define Z80_IO_WAIT
54 #ifdef _X1TURBO_FEATURE
55 #define SINGLE_MODE_DMA
56 #endif
57 #define DATAREC_FF_REW_SPEED    16
58 #define SUPPORT_VARIABLE_TIMING
59
60 #ifdef _X1TURBO_FEATURE
61 #define IPL_ROM_FILE_SIZE       0x8000
62 #define IPL_ROM_FILE_NAME       _T("IPLROM.X1T")
63 #define SUB_ROM_FILE_NAME       _T("SUBROM.X1T")
64 #define KBD_ROM_FILE_NAME       _T("KBDROM.X1T")
65 #else
66 #define IPL_ROM_FILE_SIZE       0x1000
67 #define IPL_ROM_FILE_NAME       _T("IPLROM.X1")
68 #define SUB_ROM_FILE_NAME       _T("SUBROM.X1")
69 #define KBD_ROM_FILE_NAME       _T("KBDROM.X1")
70 #endif
71 #define CRC32_MSM80C49_262      0x43EE7D6F      // X1turbo with CMT
72 #define CRC32_MSM80C49_277      0x75904EFB      // X1turbo (not supported yet)
73
74 #ifdef _X1TWIN
75 // device informations for virtual machine (pce)
76 #define PCE_FRAMES_PER_SEC      60
77 #define PCE_LINES_PER_FRAME     262
78 #define PCE_CPU_CLOCKS          7159090
79 #endif
80
81 // device informations for win32
82 #define USE_SPECIAL_RESET
83 #ifdef _X1TURBO_FEATURE
84 #define USE_DEVICE_TYPE         2
85 // Keyboard mode B
86 #define DEVICE_TYPE_DEFAULT     1
87 #define USE_DRIVE_TYPE          2
88 #endif
89 #define USE_FD1
90 #define USE_FD2
91 #define FD_BASE_NUMBER          0
92 #define USE_TAPE
93 #define USE_TAPE_BUTTON
94 #ifdef _X1TWIN
95 #define USE_CART1
96 #endif
97 #define NOTIFY_KEY_DOWN
98 #define USE_SHIFT_NUMPAD_KEY
99 #define USE_ALT_F10_KEY
100 #define USE_AUTO_KEY            8
101 #define USE_AUTO_KEY_RELEASE    10
102 #define USE_MONITOR_TYPE        2
103 #define USE_CRT_FILTER
104 #define USE_SCANLINE
105 #define USE_ACCESS_LAMP
106 #define USE_SOUND_DEVICE_TYPE           3
107 // CZ-8BS1 x1
108 #define SOUND_DEVICE_TYPE_DEFAULT       1
109 #define USE_PRINTER
110 #define USE_DEBUGGER
111 #define USE_STATE
112 #define USE_MOUSE
113 #define USE_KEYBOARD
114 #define USE_JOYSTICK
115
116 #include "../../common.h"
117 #include "../../fileio.h"
118
119 // from X-millenium
120
121 static const uint16 ANKFONT7f_9f[0x21 * 8] = {
122         0x0000, 0x3000, 0x247f, 0x6c24, 0x484c, 0xce4b, 0x0000, 0x0000,
123
124         0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xffff,
125         0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xffff, 0xffff,
126         0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xffff, 0xffff, 0xffff,
127         0x0000, 0x0000, 0x0000, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff,
128         0x0000, 0x0000, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
129         0x0000, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
130         0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
131         0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
132         0x8080, 0x8080, 0x8080, 0x8080, 0x8080, 0x8080, 0x8080, 0x8080,
133         0xc0c0, 0xc0c0, 0xc0c0, 0xc0c0, 0xc0c0, 0xc0c0, 0xc0c0, 0xc0c0,
134         0xe0e0, 0xe0e0, 0xe0e0, 0xe0e0, 0xe0e0, 0xe0e0, 0xe0e0, 0xe0e0,
135         0xf0f0, 0xf0f0, 0xf0f0, 0xf0f0, 0xf0f0, 0xf0f0, 0xf0f0, 0xf0f0,
136         0xf8f8, 0xf8f8, 0xf8f8, 0xf8f8, 0xf8f8, 0xf8f8, 0xf8f8, 0xf8f8,
137         0xfcfc, 0xfcfc, 0xfcfc, 0xfcfc, 0xfcfc, 0xfcfc, 0xfcfc, 0xfcfc,
138         0xfefe, 0xfefe, 0xfefe, 0xfefe, 0xfefe, 0xfefe, 0xfefe, 0xfefe,
139         0x0101, 0x0202, 0x0404, 0x0808, 0x1010, 0x2020, 0x4040, 0x8080,
140
141         0x0000, 0x0000, 0x0000, 0x0000, 0x00ff, 0x0000, 0x0000, 0x0000,
142         0x1010, 0x1010, 0x1010, 0x1010, 0x1010, 0x1010, 0x1010, 0x1010,
143         0x1010, 0x1010, 0x1010, 0x1010, 0x00ff, 0x0000, 0x0000, 0x0000,
144         0x0000, 0x0000, 0x0000, 0x0000, 0x10ff, 0x1010, 0x1010, 0x1010,
145         0x1010, 0x1010, 0x1010, 0x1010, 0x10f0, 0x1010, 0x1010, 0x1010,
146         0x1010, 0x1010, 0x1010, 0x1010, 0x101f, 0x1010, 0x1010, 0x1010,
147         0x1010, 0x1010, 0x1010, 0x1010, 0x10ff, 0x1010, 0x1010, 0x1010,
148         0x0000, 0x0000, 0x0000, 0x0000, 0x10f0, 0x1010, 0x1010, 0x1010,
149         0x1010, 0x1010, 0x1010, 0x1010, 0x00f0, 0x0000, 0x0000, 0x0000,
150         0x1010, 0x1010, 0x1010, 0x1010, 0x001f, 0x0000, 0x0000, 0x0000,
151         0x0000, 0x0000, 0x0000, 0x0000, 0x101f, 0x1010, 0x1010, 0x1010,
152         0x0000, 0x0000, 0x0000, 0x0000, 0x4080, 0x2020, 0x1010, 0x1010,
153         0x1010, 0x1010, 0x0810, 0x0408, 0x0003, 0x0000, 0x0000, 0x0000,
154         0x1010, 0x1010, 0x2010, 0x4020, 0x0080, 0x0000, 0x0000, 0x0000,
155         0x0000, 0x0000, 0x0000, 0x0000, 0x0403, 0x0808, 0x1010, 0x1010,
156         0x8080, 0x4040, 0x2020, 0x1010, 0x0808, 0x0404, 0x0202, 0x0101
157 };
158
159 static const uint16 ANKFONTe0_ff[0x20 * 8] = {
160         0x0000, 0x7e3c, 0xffff, 0xdbdb, 0xffff, 0xe7db, 0x7eff, 0x003c,
161         0x0000, 0x423c, 0x8181, 0xa5a5, 0x8181, 0x99a5, 0x4281, 0x003c,
162         0x0000, 0x3810, 0x7c7c, 0xfefe, 0xfefe, 0x106c, 0x7c38, 0x0000,
163         0x0000, 0x6c00, 0xfefe, 0xfefe, 0xfefe, 0x7c7c, 0x1038, 0x0000,
164         0x0000, 0x1010, 0x3838, 0x7c7c, 0x7cfe, 0x387c, 0x1038, 0x0010,
165         0x0000, 0x3810, 0x7c7c, 0x5438, 0xfefe, 0x6cfe, 0x7c10, 0x0000,
166         0x0101, 0x0303, 0x0707, 0x0f0f, 0x1f1f, 0x3f3f, 0x7f7f, 0xffff,
167         0x8080, 0xc0c0, 0xe0e0, 0xf0f0, 0xf8f8, 0xfcfc, 0xfefe, 0xffff,
168         0x8181, 0x4242, 0x2424, 0x1818, 0x1818, 0x2424, 0x4242, 0x8181,
169         0xf0f0, 0xf0f0, 0xf0f0, 0xf0f0, 0x0000, 0x0000, 0x0000, 0x0000,
170         0x0000, 0x0000, 0x0000, 0x0000, 0xf0f0, 0xf0f0, 0xf0f0, 0xf0f0,
171         0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x0000, 0x0000, 0x0000, 0x0000,
172         0x0000, 0x0000, 0x0000, 0x0000, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f,
173         0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0xf0f0, 0xf0f0, 0xf0f0, 0xf0f0,
174         0xf0f0, 0xf0f0, 0xf0f0, 0xf0f0, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f,
175         0x81ff, 0x8181, 0x8181, 0x8181, 0x8181, 0x8181, 0x8181, 0xff81,
176
177         0x55aa, 0x55aa, 0x55aa, 0x55aa, 0x55aa, 0x55aa, 0x55aa, 0x55aa,
178         0x1000, 0x1010, 0xf01e, 0x1010, 0x1010, 0x1010, 0x7e10, 0x00c0,
179         0x1000, 0x2418, 0x7c42, 0x1090, 0x781c, 0x5410, 0xfe54, 0x0000,
180         0x1000, 0x1010, 0xfe10, 0x1010, 0x3030, 0x565c, 0x9090, 0x0010,
181         0x1000, 0x1210, 0xf412, 0x3034, 0x5030, 0x9654, 0x1090, 0x0000,
182         0x0800, 0x8808, 0x5292, 0x1454, 0x2020, 0x5020, 0x465c, 0x0040,
183         0x0000, 0xe23c, 0x8282, 0x82fa, 0x7a82, 0x4242, 0x0044, 0x0000,
184         0x0000, 0x443c, 0x8242, 0xf282, 0x8282, 0x8282, 0x3844, 0x0000,
185         0x0800, 0x5e18, 0xa468, 0xe4be, 0xbea4, 0xb2a2, 0x0a5a, 0x0002,
186         0x0000, 0x2628, 0x4042, 0xe23c, 0x2222, 0x4222, 0x4442, 0x0004,
187         0x0800, 0x0808, 0xda7a, 0x5454, 0x46e4, 0xe442, 0x08c4, 0x0000,
188         0x0000, 0x7e40, 0x8848, 0x28be, 0x2828, 0x3e28, 0x08e8, 0x0008,
189         0x0000, 0x723c, 0x9252, 0x9292, 0x8292, 0x84fc, 0x8484, 0x0000,
190         0x0000, 0x1010, 0x2010, 0x2020, 0x6040, 0x8c50, 0x8286, 0x0000,
191         0x0000, 0x4040, 0x784e, 0x88c0, 0x388e, 0x0848, 0x7e08, 0x0000,
192         0x0000, 0x7c00, 0x0000, 0x0000, 0x10fe, 0x1010, 0x1010, 0x0010
193 };
194
195 class EMU;
196 class DEVICE;
197 class EVENT;
198
199 class DATAREC;
200 class HD46505;
201 class I8255;
202 class IO;
203 class MB8877;
204 class YM2151;
205 class YM2203;
206 class Z80;
207 class Z80CTC;
208 class Z80SIO;
209 #ifdef _X1TURBO_FEATURE
210 class Z80DMA;
211 #endif
212
213 class DISPLAY;
214 class EMM;
215 class FLOPPY;
216 class IOBUS;
217 class JOYSTICK;
218 class MEMORY;
219 class MOUSE;
220 class PSUB;
221
222 class MCS48;
223 class UPD1990A;
224 class SUB;
225 class KEYBOARD;
226
227 #ifdef _X1TWIN
228 class HUC6280;
229 class PCE;
230 #endif
231
232 class VM
233 {
234 protected:
235         EMU* emu;
236         
237         // devices for x1
238         EVENT* event;
239         
240         DATAREC* drec;
241         DEVICE* printer;
242         HD46505* crtc;
243         I8255* pio;
244         IO *io;
245         MB8877* fdc;
246         YM2151* opm1;
247         YM2151* opm2;
248         YM2203* psg;
249         Z80* cpu;
250         Z80CTC* ctc;
251         Z80SIO* sio;
252         Z80CTC* ctc1;
253         Z80CTC* ctc2;
254 #ifdef _X1TURBO_FEATURE
255         Z80DMA* dma;
256 #endif
257         
258         DISPLAY* display;
259         EMM* emm;
260         FLOPPY* floppy;
261         IOBUS* iobus;
262         JOYSTICK* joy;
263         MEMORY* memory;
264         MOUSE* mouse;
265         PSUB* psub;
266         
267         MCS48* cpu_sub;
268         UPD1990A* rtc_sub;
269         I8255* pio_sub;
270         SUB* sub;
271         
272         MCS48* cpu_kbd;
273         KEYBOARD* kbd;
274         
275         bool pseudo_sub_cpu;
276         int sound_device_type;
277         
278 #ifdef _X1TWIN
279         // device for pce
280         EVENT* pceevent;
281         
282         HUC6280* pcecpu;
283         PCE* pce;
284 #endif
285         
286 public:
287         // ----------------------------------------
288         // initialize
289         // ----------------------------------------
290         
291         VM(EMU* parent_emu);
292         ~VM();
293         
294         // ----------------------------------------
295         // for emulation class
296         // ----------------------------------------
297         
298         // drive virtual machine
299         void reset();
300         void special_reset();
301         void run();
302         double frame_rate();
303         
304 #ifdef USE_DEBUGGER
305         // debugger
306         DEVICE *get_cpu(int index);
307 #endif
308         
309         // draw screen
310         void draw_screen();
311         int access_lamp();
312         
313         // sound generation
314         void initialize_sound(int rate, int samples);
315         uint16* create_sound(int* extra_frames);
316         int sound_buffer_ptr();
317         
318         // notify key
319         void key_down(int code, bool repeat);
320         void key_up(int code);
321         
322         // user interface
323         void open_disk(int drv, const _TCHAR* file_path, int bank);
324         void close_disk(int drv);
325         bool disk_inserted(int drv);
326         void set_disk_protected(int drv, bool value);
327         bool get_disk_protected(int drv);
328         void play_tape(const _TCHAR* file_path);
329         void rec_tape(const _TCHAR* file_path);
330         void close_tape();
331         bool tape_inserted();
332         bool tape_playing();
333         bool tape_recording();
334         int tape_position();
335         void push_play();
336         void push_stop();
337         void push_fast_forward();
338         void push_fast_rewind();
339         void push_apss_forward();
340         void push_apss_rewind();
341         bool now_skip();
342 #ifdef _X1TWIN
343         void open_cart(int drv, const _TCHAR* file_path);
344         void close_cart(int drv);
345         bool cart_inserted(int drv);
346 #endif
347         
348         void update_config();
349 #ifdef _X1TURBO_FEATURE
350         void update_dipswitch();
351 #endif
352         void save_state(FILEIO* state_fio);
353         bool load_state(FILEIO* state_fio);
354         
355         // ----------------------------------------
356         // for each device
357         // ----------------------------------------
358         
359         // devices
360         DEVICE* get_device(int id);
361         DEVICE* dummy;
362         DEVICE* first_device;
363         DEVICE* last_device;
364 };
365
366 #endif