OSDN Git Service

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