OSDN Git Service

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