OSDN Git Service

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