OSDN Git Service

[VM][Qt][FM7] FM7 series: Fix some software has not booted, need to (destruct and...
[csp-qt/common_source_project-fm7.git] / source / src / emu.h
1 /*
2         Skelton for retropc emulator
3
4         Author : Takeda.Toshiya
5         Date   : 2006.08.18 -
6
7         [ win32 emulation i/f ]
8 */
9
10 #ifndef _EMU_H_
11 #define _EMU_H_
12
13
14 #if defined(_USE_QT)
15 # include <SDL.h>
16 # include "simd_types.h"
17 #endif // _USE_WIN32
18
19 // for debug
20 //#define _DEBUG_LOG
21 #ifdef _DEBUG_LOG
22         // output fdc debug log
23 //      #define _FDC_DEBUG_LOG
24         // output scsi debug log
25 //      #define _SCSI_DEBUG_LOG
26         // output i/o debug log
27 //      #define _IO_DEBUG_LOG
28 #endif
29
30 #include <stdio.h>
31 #include <assert.h>
32 #include "common.h"
33 #include "config.h"
34 #include "vm/vm.h"
35 #if defined(USE_FD1)
36 #include "vm/disk.h"
37 #endif
38
39
40 #if defined(_USE_QT)
41 #define OSD_QT
42 #elif defined(_USE_SDL)
43 #define OSD_SDL
44 #elif defined(_WIN32)
45 #define OSD_WIN32
46 #else
47 // oops!
48 #endif
49
50
51 // OS dependent header files should be included in each osd.h
52 // Please do not include them in emu.h
53
54 #if defined(OSD_QT)
55 #include "qt/osd.h"
56 #elif defined(OSD_SDL)
57 #include "sdl/osd.h"
58 #elif defined(OSD_WIN32)
59 #include "win32/osd.h"
60 #endif
61
62 #ifdef USE_FD1
63 #define MAX_D88_BANKS 64
64 #endif
65
66 #ifdef USE_SOCKET
67 #define SOCKET_MAX 4
68 #define SOCKET_BUFFER_MAX 0x100000
69 #endif
70
71
72 class EMU;
73 class FIFO;
74 class FILEIO;
75 class OSD;
76
77 #ifdef USE_DEBUGGER
78 typedef struct {
79         OSD *osd;
80         VM *vm;
81         int cpu_index;
82         bool running;
83         bool request_terminate;
84 } debugger_thread_t;
85 class CSP_Debugger;
86 #endif
87
88 #if defined(OSD_QT)
89 class GLDrawClass;
90 class EmuThreadClass;
91 class DrawThreadClass;
92 #endif
93
94 class EMU
95 {
96 protected:
97         VM* vm;
98         OSD* osd;
99 private:
100         _TCHAR app_path[_MAX_PATH];
101         // debugger
102 #ifdef USE_DEBUGGER
103         void initialize_debugger();
104         void release_debugger();
105 #endif
106         
107         // debug log
108 #ifdef _DEBUG_LOG
109         void initialize_debug_log();
110         void release_debug_log();
111         FILE* debug_log;
112 #endif
113         
114         // misc
115         int sound_rate, sound_samples;
116 #ifdef USE_CPU_TYPE
117         int cpu_type;
118 #endif
119 #ifdef USE_SOUND_DEVICE_TYPE
120         int sound_device_type;
121 #endif
122 #ifdef USE_PRINTER
123         int printer_device_type;
124 #endif
125         bool now_suspended;
126         // input
127 #ifdef USE_AUTO_KEY
128         FIFO* auto_key_buffer;
129         int auto_key_phase, auto_key_shift;
130         void initialize_auto_key();
131         void release_auto_key();
132         void update_auto_key();
133 #endif
134 #ifdef USE_JOYSTICK
135         uint32_t joy_status[4];
136         void update_joystick();
137 #endif
138         
139         // media
140         typedef struct {
141                 _TCHAR path[_MAX_PATH];
142                 bool play;
143                 int bank;
144                 int wait_count;
145         } media_status_t;
146         
147 #ifdef USE_CART1
148         media_status_t cart_status[MAX_CART];
149 #endif
150 #ifdef USE_FD1
151         media_status_t floppy_disk_status[MAX_FD];
152 #endif
153 #ifdef USE_QD1
154         media_status_t quick_disk_status[MAX_QD];
155 #endif
156 #ifdef USE_TAPE
157         media_status_t tape_status;
158 #endif
159 #ifdef USE_LASER_DISC
160         media_status_t laser_disc_status;
161 #endif
162         
163         void initialize_media();
164         void update_media();
165         void restore_media();
166         
167         void clear_media_status(media_status_t *status)
168         {
169                 status->path[0] = _T('\0');
170                 status->wait_count = 0;
171         }
172         
173         // state
174 #ifdef USE_STATE
175         void save_state_tmp(const _TCHAR* file_path);
176         bool load_state_tmp(const _TCHAR* file_path);
177 #endif
178
179 public:
180         // ----------------------------------------
181         // initialize
182         // ----------------------------------------
183 #if defined(OSD_QT)
184         EMU(class Ui_MainWindow *hwnd, GLDrawClass *hinst);
185 #elif defined(OSD_WIN32)
186         EMU(HWND hwnd, HINSTANCE hinst);
187 #else
188         EMU();
189 #endif
190         ~EMU();
191
192         // ----------------------------------------
193         // for windows
194         // ----------------------------------------
195 #ifdef OSD_QT
196         // qt dependent
197         EmuThreadClass *get_parent_handler();
198         void set_parent_handler(EmuThreadClass *p, DrawThreadClass *q);
199         VM *get_vm()
200         {
201                 return vm;
202         }
203         OSD *get_osd()
204         {
205                 return osd;
206         }
207         void set_host_cpus(int v);
208         int get_host_cpus();
209 #ifdef USE_MOUSE
210                 void set_mouse_pointer(int x, int y);
211                 void set_mouse_button(int button);
212                 int get_mouse_button();
213 #endif
214 #endif
215         
216         // drive machine
217         int get_frame_interval();
218         bool is_frame_skippable();
219         int run();
220
221         void reset();
222 #ifdef USE_SPECIAL_RESET
223         void special_reset();
224 #endif
225 #ifdef USE_NOTIFY_POWER_OFF
226         void notify_power_off();
227 #endif
228         void power_off();
229         void suspend();
230         void lock_vm();
231         void unlock_vm();
232         void force_unlock_vm();
233         bool is_vm_locked();
234    
235         // input
236 #ifdef OSD_QT
237         void key_modifiers(uint32_t mod);
238 #endif
239         void key_down(int code, bool repeat);
240         void key_up(int code);
241         void key_lost_focus();
242 #ifdef ONE_BOARD_MICRO_COMPUTER
243         void press_button(int num);
244 #endif
245 #ifdef USE_MOUSE
246         void enable_mouse();
247         void disable_mouse();
248         void toggle_mouse();
249         bool is_mouse_enabled();
250 #endif  
251 #ifdef USE_AUTO_KEY
252         void start_auto_key();
253         void stop_auto_key();
254         bool is_auto_key_running()
255         {
256                 return (auto_key_phase != 0);
257         }
258         FIFO* get_auto_key_buffer()
259         {
260                 return auto_key_buffer;
261         }
262 #endif
263         
264         const uint8_t* get_key_buffer();
265 #ifdef USE_JOYSTICK
266         const uint32_t* get_joy_buffer();
267 #endif  
268 #ifdef USE_MOUSE
269         const int* get_mouse_buffer();
270 #endif  
271         // screen
272         int get_window_width(int mode);
273         int get_window_height(int mode);
274         void set_host_window_size(int window_width, int window_height, bool window_mode);
275         void set_vm_screen_size(int screen_width, int screen_height, int window_width, int window_height, int window_width_aspect, int window_height_aspect);
276         int get_vm_window_width();
277         int get_vm_window_height();
278         int get_vm_window_width_aspect();
279         int get_vm_window_height_aspect();
280 #if defined(USE_MINIMUM_RENDERING)
281         bool is_screen_changed();
282 #endif
283         int draw_screen();
284         scrntype_t* get_screen_buffer(int y);
285 #ifdef USE_CRT_FILTER
286         void screen_skip_line(bool skip_line);
287 #endif
288 #ifdef ONE_BOARD_MICRO_COMPUTER
289         void reload_bitmap();
290 #endif
291 #ifdef OSD_WIN32
292         void update_screen(HDC hdc);
293 #endif
294         void capture_screen();
295         bool start_record_video(int fps);
296         void stop_record_video();
297         bool is_video_recording();
298         
299         // sound
300         void mute_sound();
301         void start_record_sound();
302         void stop_record_sound();
303         bool is_sound_recording();
304         
305         // video device
306 #if defined(USE_MOVIE_PLAYER) || defined(USE_VIDEO_CAPTURE)
307         void get_video_buffer();
308         void mute_video_dev(bool l, bool r);
309 #endif
310 #ifdef USE_MOVIE_PLAYER
311         bool open_movie_file(const _TCHAR* file_path);
312         void close_movie_file();
313         void play_movie();
314         void stop_movie();
315         void pause_movie();
316         double get_movie_frame_rate();
317         int get_movie_sound_rate();
318         void set_cur_movie_frame(int frame, bool relative);
319         uint32_t get_cur_movie_frame();
320 #endif
321 #ifdef USE_VIDEO_CAPTURE
322         int get_cur_capture_dev_index();
323         int get_num_capture_devs();
324         _TCHAR* get_capture_dev_name(int index);
325         void open_capture_dev(int index, bool pin);
326         void close_capture_dev();
327         void show_capture_dev_filter();
328         void show_capture_dev_pin();
329         void show_capture_dev_source();
330         void set_capture_dev_channel(int ch);
331 #endif
332         
333 #ifdef USE_PRINTER
334         void create_bitmap(bitmap_t *bitmap, int width, int height);
335         void release_bitmap(bitmap_t *bitmap);
336         void create_font(font_t *font, const _TCHAR *family, int width, int height, int rotate, bool bold, bool italic);
337         void release_font(font_t *font);
338         void create_pen(pen_t *pen, int width, uint8_t r, uint8_t g, uint8_t b);
339         void release_pen(pen_t *pen);
340         void clear_bitmap(bitmap_t *bitmap, uint8_t r, uint8_t g, uint8_t b);
341         int get_text_width(bitmap_t *bitmap, font_t *font, const char *text);
342         void draw_text_to_bitmap(bitmap_t *bitmap, font_t *font, int x, int y, const char *text, uint8_t r, uint8_t g, uint8_t b);
343         void draw_line_to_bitmap(bitmap_t *bitmap, pen_t *pen, int sx, int sy, int ex, int ey);
344         void draw_rectangle_to_bitmap(bitmap_t *bitmap, int x, int y, int width, int height, uint8_t r, uint8_t g, uint8_t b);
345         void draw_point_to_bitmap(bitmap_t *bitmap, int x, int y, uint8_t r, uint8_t g, uint8_t b);
346         void stretch_bitmap(bitmap_t *dest, int dest_x, int dest_y, int dest_width, int dest_height, bitmap_t *source, int source_x, int source_y, int source_width, int source_height);
347         void write_bitmap_to_file(bitmap_t *bitmap, const _TCHAR *file_path);
348 #endif
349         // socket
350 #ifdef USE_SOCKET
351         int get_socket(int ch);
352         void notify_socket_connected(int ch);
353         void notify_socket_disconnected(int ch);
354         bool initialize_socket_tcp(int ch);
355         bool initialize_socket_udp(int ch);
356         bool connect_socket(int ch, uint32_t ipaddr, int port);
357         void disconnect_socket(int ch);
358         bool listen_socket(int ch);
359         void send_socket_data_tcp(int ch);
360         void send_socket_data_udp(int ch, uint32_t ipaddr, int port);
361         void send_socket_data(int ch);
362         void recv_socket_data(int ch);
363 #endif
364         
365         // debugger
366 #ifdef USE_DEBUGGER
367         void open_debugger(int cpu_index);
368         void close_debugger();
369         bool is_debugger_enabled(int cpu_index);
370         bool now_debugging;
371         debugger_thread_t debugger_thread_param;
372 #if defined(OSD_QT)
373         SDL_Thread *debugger_thread_id;
374         CSP_Debugger *hDebugger;
375 #elif defined(OSD_WIN32)
376         HANDLE hDebuggerThread;
377 #else
378         int debugger_thread_id;
379 #endif
380 #endif
381         
382         // debug log
383         void out_debug_log(const _TCHAR* format, ...);
384         void force_out_debug_log(const _TCHAR* format, ...);
385    
386         void out_message(const _TCHAR* format, ...);
387         int message_count;
388         _TCHAR message[1024];
389         
390         // misc
391         void sleep(uint32_t ms);
392
393         // debug log
394 #ifdef _DEBUG_LOG
395         void initialize_debug_log();
396         void release_debug_log();
397         FILE* debug_log;
398 #endif
399         
400         // media
401 #ifdef USE_FD1
402         struct {
403                 _TCHAR path[_MAX_PATH];
404                 _TCHAR disk_name[MAX_D88_BANKS][128];  // Convert to UTF8
405                 int bank_num;
406                 int cur_bank;
407         } d88_file[MAX_FD];
408 #endif
409
410         // user interface
411 #ifdef USE_CART1
412         void open_cart(int drv, const _TCHAR* file_path);
413         void close_cart(int drv);
414         bool is_cart_inserted(int drv);
415 #endif
416 #ifdef USE_FD1
417         void open_floppy_disk(int drv, const _TCHAR* file_path, int bank);
418         void close_floppy_disk(int drv);
419         bool is_floppy_disk_inserted(int drv);
420         void is_floppy_disk_protected(int drv, bool value);
421         bool is_floppy_disk_protected(int drv);
422 #endif
423 #ifdef USE_QD1
424         void open_quick_disk(int drv, const _TCHAR* file_path);
425         void close_quick_disk(int drv);
426         bool is_quick_disk_inserted(int drv);
427 #endif
428 #ifdef USE_TAPE
429         void play_tape(const _TCHAR* file_path);
430         void rec_tape(const _TCHAR* file_path);
431         void close_tape();
432         bool is_tape_inserted();
433 # ifndef TAPE_BINARY_ONLY
434         bool is_tape_playing();
435         bool is_tape_recording();
436         int get_tape_position();
437 # endif
438 # ifdef USE_TAPE_BUTTON
439         void push_play();
440         void push_stop();
441         void push_fast_forward();
442         void push_fast_rewind();
443         void push_apss_forward();
444         void push_apss_rewind();
445 # endif
446 #endif
447 #ifdef USE_LASER_DISC
448         void open_laser_disc(const _TCHAR* file_path);
449         void close_laser_disc();
450         bool is_laser_disc_inserted();
451 #endif
452 #ifdef USE_BINARY_FILE1
453         void load_binary(int drv, const _TCHAR* file_path);
454         void save_binary(int drv, const _TCHAR* file_path);
455 #endif
456 #ifdef USE_ACCESS_LAMP
457         uint32_t get_access_lamp_status(void);
458 #endif  
459 #ifdef USE_LED_DEVICE
460         uint32_t get_led_status(void);
461 #endif
462 #ifdef USE_SOUND_VOLUME
463         void set_sound_device_volume(int ch, int decibel_l, int decibel_r);
464 #endif
465         void update_config();
466         // state
467 #ifdef USE_STATE
468         void save_state();
469         void load_state();
470 #endif
471 };
472 #endif // _EMU_H_
473