OSDN Git Service

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