OSDN Git Service

faa6c86f145a799d11a4e18324081d6c8248e5a2
[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 // for debug
14 //#define _DEBUG_LOG
15 #ifdef _DEBUG_LOG
16         // output fdc debug log
17 //      #define _FDC_DEBUG_LOG
18         // output scsi debug log
19 //      #define _SCSI_DEBUG_LOG
20         // output i/o debug log
21 //      #define _IO_DEBUG_LOG
22 #endif
23
24 #include <stdio.h>
25 #include <assert.h>
26 #include "common.h"
27 #include "config.h"
28 #include "vm/vm.h"
29
30 #if defined(_USE_QT)
31 #include <pthread.h>
32 #define OSD_QT
33 #elif defined(_USE_SDL)
34 #include <pthread.h>
35 #define OSD_SDL
36 #elif defined(_WIN32)
37 #define OSD_WIN32
38 #else
39 // oops!
40 #endif
41
42
43 // OS dependent header files should be included in each osd.h
44 // Please do not include them in emu.h
45
46 #if defined(OSD_QT)
47 #include "qt/osd.h"
48 #elif defined(OSD_SDL)
49 #include "sdl/osd.h"
50 #elif defined(OSD_WIN32)
51 #include "win32/osd.h"
52 #endif
53
54 #ifdef USE_FLOPPY_DISK
55 #define MAX_D88_BANKS 64
56 #endif
57 #ifdef USE_BUBBLE
58 #define MAX_B77_BANKS 16
59 #endif
60
61 class EMU;
62 class FIFO;
63 class FILEIO;
64 class OSD;
65
66 #ifdef USE_DEBUGGER
67 #if defined(OSD_QT)
68 class CSP_DebuggerThread;
69 #endif
70 typedef struct {
71         OSD *osd;
72         VM *vm;
73         int cpu_index;
74         bool running;
75         bool request_terminate;
76 } debugger_thread_t;
77 class CSP_Debugger;
78 #endif
79
80 #if defined(OSD_QT)
81 class USING_FLAGS;
82 class GLDrawClass;
83 class EmuThreadClass;
84 class DrawThreadClass;
85 #endif
86
87 class EMU
88 {
89 protected:
90         VM* vm;
91         OSD* osd;
92 private:
93         _TCHAR app_path[_MAX_PATH];
94         // debugger
95 #ifdef USE_DEBUGGER
96         void initialize_debugger();
97         void release_debugger();
98 #endif
99         
100         
101         // misc
102         int sound_frequency, sound_latency;
103         int sound_rate, sound_samples;
104 #ifdef USE_CPU_TYPE
105         int cpu_type;
106 #endif
107 #ifdef USE_SOUND_TYPE
108         int sound_type;
109 #endif
110 #ifdef USE_PRINTER_TYPE
111         int printer_type;
112 #endif
113         bool now_suspended;
114         // input
115 #ifdef USE_AUTO_KEY
116         FIFO* auto_key_buffer;
117         int auto_key_phase, auto_key_shift;
118         bool shift_pressed;
119         void initialize_auto_key();
120         void release_auto_key();
121         int get_auto_key_code(int code);
122         void set_auto_key_code(int code);
123         void update_auto_key();
124 #endif
125 #ifdef USE_JOYSTICK
126         uint32_t joy_status[4];
127         void update_joystick();
128 #endif
129         
130         // media
131         typedef struct {
132                 _TCHAR path[_MAX_PATH];
133                 bool play;
134                 int bank;
135                 int wait_count;
136         } media_status_t;
137         
138 #ifdef USE_CART
139         media_status_t cart_status[USE_CART];
140 #endif
141 #ifdef USE_FLOPPY_DISK
142         media_status_t floppy_disk_status[USE_FLOPPY_DISK];
143 #endif
144 #ifdef USE_QUICK_DISK
145         media_status_t quick_disk_status[USE_QUICK_DISK];
146 #endif
147 #ifdef USE_HARD_DISK
148         media_status_t hard_disk_status[USE_HARD_DISK];
149 #endif
150 #ifdef USE_TAPE
151         media_status_t tape_status[USE_TAPE];
152 #endif
153 #ifdef USE_COMPACT_DISC
154         media_status_t compact_disc_status[USE_COMPACT_DISC];
155 #endif
156 #ifdef USE_LASER_DISC
157         media_status_t laser_disc_status[USE_LASER_DISC];
158 #endif
159 #ifdef USE_BUBBLE
160         media_status_t bubble_casette_status[USE_BUBBLE];
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         bool load_state_tmp(const _TCHAR* file_path);
176 #endif
177
178 public:
179         // ----------------------------------------
180         // initialize
181         // ----------------------------------------
182 #if defined(OSD_QT)
183         EMU(class Ui_MainWindow *hwnd, GLDrawClass *hinst, USING_FLAGS *p);
184 #elif defined(OSD_WIN32)
185         EMU(HWND hwnd, HINSTANCE hinst);
186 #else
187         EMU();
188 #endif
189         ~EMU();
190
191         // ----------------------------------------
192         // for windows
193         // ----------------------------------------
194 #ifdef OSD_QT
195         // qt dependent
196         EmuThreadClass *get_parent_handler();
197         void set_parent_handler(EmuThreadClass *p, DrawThreadClass *q);
198         VM *get_vm()
199         {
200                 return vm;
201         }
202         OSD *get_osd()
203         {
204                 return osd;
205         }
206         void set_host_cpus(int v);
207         int get_host_cpus();
208 #endif
209         
210         // drive machine
211         double get_frame_rate();
212         int get_frame_interval();
213         bool is_frame_skippable();
214         int run();
215
216         void reset();
217 #ifdef USE_SPECIAL_RESET
218         void special_reset();
219 #endif
220 #ifdef USE_NOTIFY_POWER_OFF
221         void notify_power_off();
222 #endif
223         void power_off();
224         void suspend();
225         void lock_vm();
226         void unlock_vm();
227         void force_unlock_vm();
228         bool is_vm_locked();
229    
230         // input
231 #ifdef OSD_QT
232         void key_modifiers(uint32_t mod);
233 #endif
234         void key_down(int code, bool extended, bool repeat);
235         void key_up(int code, bool extended);
236         void key_char(char code);
237 #ifdef USE_KEY_LOCKED
238         bool get_caps_locked();
239         bool get_kana_locked();
240 #endif
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 set_auto_key_list(char *buf, int size);
253         void set_auto_key_char(char code);
254         void start_auto_key();
255         void stop_auto_key();
256         bool is_auto_key_running()
257         {
258                 return (auto_key_phase != 0);
259         }
260         FIFO* get_auto_key_buffer()
261         {
262                 return auto_key_buffer;
263         }
264 #endif
265         
266         const uint8_t* get_key_buffer();
267 #ifdef USE_JOYSTICK
268         const uint32_t* get_joy_buffer();
269 #endif  
270 #ifdef USE_MOUSE
271         const int* get_mouse_buffer();
272 #endif  
273         // screen
274         int get_window_mode_width(int mode);
275         int get_window_mode_height(int mode);
276         void set_host_window_size(int window_width, int window_height, bool window_mode);
277         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);
278         void set_vm_screen_lines(int lines);
279         
280         int get_vm_window_width();
281         int get_vm_window_height();
282         int get_vm_window_width_aspect();
283         int get_vm_window_height_aspect();
284 #if defined(USE_MINIMUM_RENDERING)
285         bool is_screen_changed();
286 #endif
287         int draw_screen();
288         scrntype_t* get_screen_buffer(int y);
289 #ifdef USE_SCREEN_FILTER
290         void screen_skip_line(bool skip_line);
291 #endif
292 #ifdef ONE_BOARD_MICRO_COMPUTER
293         void get_invalidated_rect(int *left, int *top, int *right, int *bottom);
294         void reload_bitmap();
295 #endif
296 #ifdef OSD_WIN32
297         void invalidate_screen();
298         void update_screen(HDC hdc);
299 #endif
300         void capture_screen();
301         bool start_record_video(int fps);
302         void stop_record_video();
303         bool is_video_recording();
304         // sound
305         int get_sound_rate()
306         {
307                 return sound_rate;
308         }
309         void mute_sound();
310         void start_record_sound();
311         void stop_record_sound();
312         bool is_sound_recording();
313         
314         // video device
315 #if defined(USE_MOVIE_PLAYER) || defined(USE_VIDEO_CAPTURE)
316         void get_video_buffer();
317         void mute_video_dev(bool l, bool r);
318 #endif
319 #ifdef USE_MOVIE_PLAYER
320         bool open_movie_file(const _TCHAR* file_path);
321         void close_movie_file();
322         void play_movie();
323         void stop_movie();
324         void pause_movie();
325         double get_movie_frame_rate();
326         int get_movie_sound_rate();
327         void set_cur_movie_frame(int frame, bool relative);
328         uint32_t get_cur_movie_frame();
329 #endif
330 #ifdef USE_VIDEO_CAPTURE
331         int get_cur_capture_dev_index();
332         int get_num_capture_devs();
333         _TCHAR* get_capture_dev_name(int index);
334         void open_capture_dev(int index, bool pin);
335         void close_capture_dev();
336         void show_capture_dev_filter();
337         void show_capture_dev_pin();
338         void show_capture_dev_source();
339         void set_capture_dev_channel(int ch);
340 #endif
341         
342 #ifdef USE_PRINTER
343         void create_bitmap(bitmap_t *bitmap, int width, int height);
344         void release_bitmap(bitmap_t *bitmap);
345         void create_font(font_t *font, const _TCHAR *family, int width, int height, int rotate, bool bold, bool italic);
346         void release_font(font_t *font);
347         void create_pen(pen_t *pen, int width, uint8_t r, uint8_t g, uint8_t b);
348         void release_pen(pen_t *pen);
349         void clear_bitmap(bitmap_t *bitmap, uint8_t r, uint8_t g, uint8_t b);
350         int get_text_width(bitmap_t *bitmap, font_t *font, const char *text);
351         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);
352         void draw_line_to_bitmap(bitmap_t *bitmap, pen_t *pen, int sx, int sy, int ex, int ey);
353         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);
354         void draw_point_to_bitmap(bitmap_t *bitmap, int x, int y, uint8_t r, uint8_t g, uint8_t b);
355         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);
356         void write_bitmap_to_file(bitmap_t *bitmap, const _TCHAR *file_path);
357 #endif
358         // socket
359 #ifdef USE_SOCKET
360         int get_socket(int ch);
361         void notify_socket_connected(int ch);
362         void notify_socket_disconnected(int ch);
363         bool initialize_socket_tcp(int ch);
364         bool initialize_socket_udp(int ch);
365         bool connect_socket(int ch, uint32_t ipaddr, int port);
366         void disconnect_socket(int ch);
367         bool listen_socket(int ch);
368         void send_socket_data_tcp(int ch);
369         void send_socket_data_udp(int ch, uint32_t ipaddr, int port);
370         void send_socket_data(int ch);
371         void recv_socket_data(int ch);
372 #endif
373         
374         // debugger
375 #ifdef USE_DEBUGGER
376         void open_debugger(int cpu_index);
377         void close_debugger();
378         bool is_debugger_enabled(int cpu_index);
379         bool now_debugging;
380         debugger_thread_t debugger_thread_param;
381 #if defined(OSD_QT)
382         pthread_t debugger_thread_id;
383         CSP_Debugger *hDebugger;
384 #elif defined(OSD_WIN32)
385         HANDLE hDebuggerThread;
386 #else
387         int debugger_thread_id;
388 #endif
389 #endif
390         
391         // debug log
392         void out_debug_log(const _TCHAR* format, ...);
393         void force_out_debug_log(const _TCHAR* format, ...);
394    
395         void out_message(const _TCHAR* format, ...);
396         int message_count;
397         _TCHAR message[1024];
398         
399         // misc
400         void sleep(uint32_t ms);
401
402         // debug log
403 #ifdef _DEBUG_LOG
404         void initialize_debug_log();
405         void release_debug_log();
406         FILE* debug_log;
407 #endif
408         
409         // media
410 #ifdef USE_FLOPPY_DISK
411         struct {
412                 _TCHAR path[_MAX_PATH];
413                 _TCHAR disk_name[MAX_D88_BANKS][128];  // Convert to UTF8
414                 int bank_num;
415                 int cur_bank;
416         } d88_file[USE_FLOPPY_DISK];
417 #endif
418
419         // user interface
420 #ifdef USE_CART
421         void open_cart(int drv, const _TCHAR* file_path);
422         void close_cart(int drv);
423         bool is_cart_inserted(int drv);
424 #endif
425 #ifdef USE_FLOPPY_DISK
426         void open_floppy_disk(int drv, const _TCHAR* file_path, int bank);
427         void close_floppy_disk(int drv);
428         bool is_floppy_disk_inserted(int drv);
429         void is_floppy_disk_protected(int drv, bool value);
430         bool is_floppy_disk_protected(int drv);
431         uint32_t is_floppy_disk_accessed();
432 #endif
433 #ifdef USE_QUICK_DISK
434         void open_quick_disk(int drv, const _TCHAR* file_path);
435         void close_quick_disk(int drv);
436         bool is_quick_disk_inserted(int drv);
437         uint32_t is_quick_disk_accessed();
438 #endif
439 #ifdef USE_HARD_DISK
440         void open_hard_disk(int drv, const _TCHAR* file_path);
441         void close_hard_disk(int drv);
442         bool is_hard_disk_inserted(int drv);
443         uint32_t is_hard_disk_accessed();
444 #endif
445 #ifdef USE_TAPE
446         void play_tape(int drv, const _TCHAR* file_path);
447         void rec_tape(int drv, const _TCHAR* file_path);
448         void close_tape(int drv);
449         bool is_tape_inserted(int drv);
450         bool is_tape_playing(int drv);
451         bool is_tape_recording(int drv);
452         int get_tape_position(int drv);
453         const _TCHAR* get_tape_message(int drv);
454         void push_play(int drv);
455         void push_stop(int drv);
456         void push_fast_forward(int drv);
457         void push_fast_rewind(int drv);
458         void push_apss_forward(int drv);
459         void push_apss_rewind(int drv);
460 #endif
461 #ifdef USE_COMPACT_DISC
462         void open_compact_disc(int drv, const _TCHAR* file_path);
463         void close_compact_disc(int drv);
464         bool is_compact_disc_inserted(int drv);
465         uint32_t is_compact_disc_accessed();
466 #endif
467 #ifdef USE_LASER_DISC
468         void open_laser_disc(int drv, const _TCHAR* file_path);
469         void close_laser_disc(int drv);
470         bool is_laser_disc_inserted(int drv);
471         uint32_t is_laser_disc_accessed();
472 #endif
473 #ifdef USE_BINARY_FILE
474         void load_binary(int drv, const _TCHAR* file_path);
475         void save_binary(int drv, const _TCHAR* file_path);
476 #endif
477 #ifdef USE_BUBBLE
478         struct {
479                 _TCHAR path[_MAX_PATH];
480                 _TCHAR bubble_name[MAX_B77_BANKS][128];  // Convert to UTF8
481                 int bank_num;
482                 int cur_bank;
483         } b77_file[USE_BUBBLE];
484         void open_bubble_casette(int drv, const _TCHAR* file_path, int bank);
485         void close_bubble_casette(int drv);
486         bool is_bubble_casette_inserted(int drv);
487         bool is_bubble_casette_protected(int drv);
488         void is_bubble_casette_protected(int drv, bool value);
489 #endif
490 #ifdef USE_LED_DEVICE
491         uint32_t get_led_status();
492 #endif
493 #ifdef USE_SOUND_VOLUME
494         void set_sound_device_volume(int ch, int decibel_l, int decibel_r);
495 #endif
496         void update_config();
497         // state
498 #ifdef USE_STATE
499         void save_state(const _TCHAR* file_path);
500         void load_state(const _TCHAR* file_path);
501 #endif
502 #ifdef OSD_QT
503         // New APIs
504         void load_sound_file(int id, const _TCHAR *name, int16_t **data, int *dst_size);
505         void free_sound_file(int id, int16_t **data);
506 #endif
507 };
508 #endif // _EMU_H_
509