OSDN Git Service

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