OSDN Git Service

[VM][UI][Qt] General : Merge upstream 2015-08-01.
[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 // 4:3
82 #define SCREEN_WIDTH_ASPECT 640 
83 #define SCREEN_HEIGHT_ASPECT 400
84 #define WINDOW_WIDTH_ASPECT 640 
85 #define WINDOW_HEIGHT_ASPECT 480
86
87 // device informations for win32
88 #define USE_SPECIAL_RESET
89 #ifdef _X1TURBO_FEATURE
90 #define USE_DEVICE_TYPE         2
91 // Keyboard mode B
92 #define DEVICE_TYPE_DEFAULT     1
93 #define USE_DRIVE_TYPE          2
94 #endif
95 #define USE_FD1
96 #define USE_FD2
97 #define FD_BASE_NUMBER          0
98 #define USE_TAPE
99 #define USE_TAPE_BUTTON
100 #define USE_TAPE_PTR
101 #ifdef _X1TWIN
102 #define USE_CART1
103 #endif
104 #define NOTIFY_KEY_DOWN
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_MONITOR_TYPE        2
110 #define USE_CRT_FILTER
111 #define USE_SCANLINE
112 #define USE_ACCESS_LAMP
113 #define USE_DISK_WRITE_PROTECT
114 #define USE_SOUND_DEVICE_TYPE   3
115 #define USE_SOUND_DEVICE_TYPE           3
116 // CZ-8BS1 x1
117 #define SOUND_DEVICE_TYPE_DEFAULT       1
118 //#define USE_DEBUGGER
119 #define USE_STATE
120
121 #include "../../common.h"
122 #include "../../fileio.h"
123
124 class EMU;
125 class DEVICE;
126 class EVENT;
127
128 class DATAREC;
129 class HD46505;
130 class I8255;
131 class IO;
132 class MB8877;
133 class YM2151;
134 class YM2203;
135 class Z80;
136 class Z80CTC;
137 class Z80SIO;
138 #ifdef _X1TURBO_FEATURE
139 class Z80DMA;
140 #endif
141
142 class DISPLAY;
143 class EMM;
144 class FLOPPY;
145 class IOBUS;
146 class JOYSTICK;
147 class MEMORY;
148 class MOUSE;
149 class PRINTER;
150 class PSUB;
151
152 class MCS48;
153 class UPD1990A;
154 class SUB;
155 class KEYBOARD;
156
157 #ifdef _X1TWIN
158 class HUC6280;
159 class PCE;
160 #endif
161
162 class VM
163 {
164 protected:
165         EMU* emu;
166         
167         // devices for x1
168         EVENT* event;
169         
170         DATAREC* drec;
171         HD46505* crtc;
172         I8255* pio;
173         IO *io;
174         MB8877* fdc;
175         YM2151* opm1;
176         YM2151* opm2;
177         YM2203* psg;
178         Z80* cpu;
179         Z80CTC* ctc;
180         Z80SIO* sio;
181         Z80CTC* ctc1;
182         Z80CTC* ctc2;
183 #ifdef _X1TURBO_FEATURE
184         Z80DMA* dma;
185 #endif
186         
187         DISPLAY* display;
188         EMM* emm;
189         FLOPPY* floppy;
190         IOBUS* iobus;
191         JOYSTICK* joy;
192         MEMORY* memory;
193         MOUSE* mouse;
194         PRINTER* printer;
195         PSUB* psub;
196         
197         MCS48* cpu_sub;
198         UPD1990A* rtc_sub;
199         I8255* pio_sub;
200         SUB* sub;
201         
202         MCS48* cpu_kbd;
203         KEYBOARD* kbd;
204         
205         bool pseudo_sub_cpu;
206         int sound_device_type;
207         
208 #ifdef _X1TWIN
209         // device for pce
210         EVENT* pceevent;
211         
212         HUC6280* pcecpu;
213         PCE* pce;
214 #endif
215         
216 public:
217         // ----------------------------------------
218         // initialize
219         // ----------------------------------------
220         
221         VM(EMU* parent_emu);
222         ~VM();
223         
224         // ----------------------------------------
225         // for emulation class
226         // ----------------------------------------
227         
228         // drive virtual machine
229         void reset();
230         void special_reset();
231         void run();
232         double frame_rate();
233         
234 #ifdef USE_DEBUGGER
235         // debugger
236         DEVICE *get_cpu(int index);
237 #endif
238         
239         // draw screen
240         void draw_screen();
241         int access_lamp();
242         
243         // sound generation
244         void initialize_sound(int rate, int samples);
245         uint16* create_sound(int* extra_frames);
246         int sound_buffer_ptr();
247         
248         // notify key
249         void key_down(int code, bool repeat);
250         void key_up(int code);
251         
252         // user interface
253         void open_disk(int drv, _TCHAR* file_path, int bank);
254         void close_disk(int drv);
255         bool disk_inserted(int drv);
256         void set_disk_protected(int drv, bool value);
257         bool get_disk_protected(int drv);
258         void play_tape(_TCHAR* file_path);
259         void rec_tape(_TCHAR* file_path);
260         void close_tape();
261         bool tape_inserted();
262         void push_play();
263         void push_stop();
264         void push_fast_forward();
265         void push_fast_rewind();
266         void push_apss_forward();
267         void push_apss_rewind();
268         bool now_skip();
269 #if defined(USE_TAPE_PTR)
270         int get_tape_ptr(void);
271 #endif
272         bool get_tape_play(void);
273 #ifdef _X1TWIN
274         void open_cart(int drv, _TCHAR* file_path);
275         void close_cart(int drv);
276         bool cart_inserted(int drv);
277 #endif
278         
279         void update_config();
280 #ifdef _X1TURBO_FEATURE
281         void update_dipswitch();
282 #endif
283         void save_state(FILEIO* state_fio);
284         bool load_state(FILEIO* state_fio);
285         
286         // ----------------------------------------
287         // for each device
288         // ----------------------------------------
289         
290         // devices
291         DEVICE* get_device(int id);
292         DEVICE* dummy;
293         DEVICE* first_device;
294         DEVICE* last_device;
295 };
296
297 #endif