OSDN Git Service

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