OSDN Git Service

2c303d0dc3e30b1d5e8cdb4e6d06c5f36aa830e3
[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 // DirectX
14 #define DIRECTSOUND_VERSION     0x900
15 #define DIRECT3D_VERSION        0x900
16 #define DIRECTINPUT_VERSION     0x500
17
18 // for debug
19 //#define _DEBUG_LOG
20 #ifdef _DEBUG_LOG
21         // output fdc debug log
22 //      #define _FDC_DEBUG_LOG
23         // output i/o debug log
24 //      #define _IO_DEBUG_LOG
25 #endif
26
27 #if defined(_USE_AGAR)
28 # include <SDL/SDL.h>
29 # include <agar/core.h>
30 # include <agar/gui.h>
31 # include "simd_types.h"
32 // Wrapper of WIN32->*nix
33
34 #ifndef _MAX_PATH
35  #define _MAX_PATH AG_PATHNAME_MAX
36 #endif
37
38 #elif defined(_USE_QT)
39 # include <SDL2/SDL.h>
40 //# include "menuclasses.h"
41 //# include "mainwidget.h"
42 //# include "qt_gldraw.h"
43 //# include "emu_utils.h"
44 //# include "qt_main.h"
45 # include "simd_types.h"
46 // Wrapper of WIN32->*nix
47
48 #ifndef _MAX_PATH
49  #ifdef MAX_PATH
50    #define _MAX_PATH MAX_PATH
51  #else
52    #define MAX_PATH 2048
53    #define _MAX_PATH 2048
54  #endif
55 #endif
56
57 #else // _USE_WIN32
58 #include <windows.h>
59 #include <windowsx.h>
60 #include <mmsystem.h>
61 #include <process.h>
62
63 #endif // _USE_WIN32
64
65 #include <stdio.h>
66 #include <assert.h>
67 #include "common.h"
68 #include "config.h"
69 #include "vm/vm.h"
70 #if defined(USE_FD1)
71 #include "vm/disk.h"
72 #endif
73
74 #if defined(_USE_AGAR)
75 #include "agar_input.h"
76 #elif defined(_USE_QT)
77 #include "qt_input.h"
78 #endif
79
80 #if defined(_USE_AGAR) || defined(_USE_QT)
81 # define WM_RESIZE  1
82 #define WM_SOCKET0 2
83 #define WM_SOCKET1 3
84 #define WM_SOCKET2 4
85 #define WM_SOCKET3 5
86 #else // WIN32
87 #define WM_RESIZE  (WM_USER + 1)
88 #define WM_SOCKET0 (WM_USER + 2)
89 #define WM_SOCKET1 (WM_USER + 3)
90 #define WM_SOCKET2 (WM_USER + 4)
91 #define WM_SOCKET3 (WM_USER + 5)
92 #endif
93
94 #if defined(USE_LASER_DISC) || defined(USE_VIDEO_CAPTURE)
95 #define USE_DIRECT_SHOW
96 #endif
97
98 #ifdef USE_VIDEO_CAPTURE
99 #define MAX_CAPTURE_DEVS 8
100 #endif
101
102 #ifndef SCREEN_WIDTH_ASPECT
103 #define SCREEN_WIDTH_ASPECT SCREEN_WIDTH
104 #endif
105 #ifndef SCREEN_HEIGHT_ASPECT
106 #define SCREEN_HEIGHT_ASPECT SCREEN_HEIGHT
107 #endif
108 #ifndef WINDOW_WIDTH
109 #define WINDOW_WIDTH SCREEN_WIDTH_ASPECT
110 #endif
111 #ifndef WINDOW_HEIGHT
112 #define WINDOW_HEIGHT SCREEN_HEIGHT_ASPECT
113 #endif
114
115 #if defined(_USE_AGAR) || defined(_USE_SDL) || defined(_USE_QT)
116
117 typedef struct {
118    Sint16 **pSoundBuf;
119    int *uBufSize;
120    int *nSndWritePos;
121    int *nSndDataLen;
122    SDL_sem **pSndApplySem;
123    Uint8 *iTotalVolume;
124    bool *bSndExit;
125    bool *bSoundDebug;
126 } sdl_snddata_t;
127
128 #else // WIN32
129 #pragma comment(lib, "d3d9.lib")
130 #pragma comment(lib, "d3dx9.lib")
131 #include <d3d9.h>
132 #include <d3dx9.h>
133 #include <d3d9types.h>
134
135 #include <dsound.h>
136 #include <vfw.h>
137
138 #pragma comment(lib, "dinput.lib")
139 #pragma comment(lib, "dxguid.lib")
140 #include <dinput.h>
141
142 #ifdef USE_DIRECT_SHOW
143 #pragma comment(lib, "strmiids.lib")
144 #include <dshow.h>
145 //#include <qedit.h>
146 EXTERN_C const CLSID CLSID_SampleGrabber;
147 EXTERN_C const CLSID CLSID_NullRenderer;
148 EXTERN_C const IID IID_ISampleGrabberCB;
149 MIDL_INTERFACE("0579154A-2B53-4994-B0D0-E773148EFF85")
150 ISampleGrabberCB : public IUnknown {
151 public:
152         virtual HRESULT STDMETHODCALLTYPE SampleCB( double SampleTime,IMediaSample *pSample) = 0;
153         virtual HRESULT STDMETHODCALLTYPE BufferCB( double SampleTime,BYTE *pBuffer,long BufferLen) = 0;
154 };
155 EXTERN_C const IID IID_ISampleGrabber;
156 MIDL_INTERFACE("6B652FFF-11FE-4fce-92AD-0266B5D7C78F")
157 ISampleGrabber : public IUnknown {
158 public:
159         virtual HRESULT STDMETHODCALLTYPE SetOneShot( BOOL OneShot) = 0;
160         virtual HRESULT STDMETHODCALLTYPE SetMediaType( const AM_MEDIA_TYPE *pType) = 0;
161         virtual HRESULT STDMETHODCALLTYPE GetConnectedMediaType( AM_MEDIA_TYPE *pType) = 0;
162         virtual HRESULT STDMETHODCALLTYPE SetBufferSamples( BOOL BufferThem) = 0;
163         virtual HRESULT STDMETHODCALLTYPE GetCurrentBuffer( /* [out][in] */ long *pBufferSize,/* [out] */ long *pBuffer) = 0;
164         virtual HRESULT STDMETHODCALLTYPE GetCurrentSample( /* [retval][out] */ IMediaSample **ppSample) = 0;
165         virtual HRESULT STDMETHODCALLTYPE SetCallback( ISampleGrabberCB *pCallback,long WhichMethodToCallback) = 0;
166 };
167 #endif
168
169 #ifdef __cplusplus
170 #ifdef USE_LASER_DISC
171 class CMySampleGrabberCB : public ISampleGrabberCB {
172 private:
173         VM *vm;
174 public:
175         CMySampleGrabberCB(VM *vm_ptr)
176         {
177                 vm = vm_ptr;
178         }
179         STDMETHODIMP_(ULONG) AddRef()
180         {
181                 return 2;
182         }
183         STDMETHODIMP_(ULONG) Release()
184         {
185                 return 1;
186         }
187         STDMETHODIMP QueryInterface(REFIID riid, void **ppv)
188         {
189                 if(riid == IID_ISampleGrabberCB || riid == IID_IUnknown) {
190                         *ppv = (void *) static_cast<ISampleGrabberCB*>(this);
191                         return NOERROR;
192                 }
193                 return E_NOINTERFACE;
194         }
195         STDMETHODIMP SampleCB(double SampleTime, IMediaSample *pSample)
196         {
197                 return S_OK;
198         }
199         STDMETHODIMP BufferCB(double dblSampleTime, BYTE *pBuffer, long lBufferSize)
200         {
201                 vm->movie_sound_callback(pBuffer, lBufferSize);
202                 return S_OK;
203         }
204 };
205 #endif
206 #endif
207 #endif
208
209 #ifdef USE_SOCKET
210 # if defined(_USE_AGAR) || defined(_USE_SDL)
211 # elif defined(_USE_QT)
212 # else // _WIN32
213 #  include <winsock.h>
214 # endif
215 #endif
216
217 // check memory leaks
218 #ifdef _DEBUG
219 #define _CRTDBG_MAP_ALLOC
220 #include <crtdbg.h>
221 #define malloc(s) _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
222 #define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
223 #endif
224
225 #ifdef USE_FD1
226 #define MAX_D88_BANKS 64
227 #endif
228
229 #ifdef USE_SOCKET
230 #define SOCKET_MAX 4
231 #define SOCKET_BUFFER_MAX 0x100000
232 #endif
233
234 #ifdef __cplusplus
235 class EMU;
236 class FIFO;
237 class FILEIO;
238 #endif
239 #if defined(_USE_QT)
240 class GLDrawClass;
241 #endif
242
243 #if defined(_USE_AGAR) || defined(_USE_QT)
244         typedef Uint32 scrntype;
245 #else
246 typedef struct {
247         PAVISTREAM pAVICompressed;
248         scrntype* lpBmpSource;
249         LPBITMAPINFOHEADER pbmInfoHeader;
250         DWORD dwAVIFileSize;
251         LONG lAVIFrames;
252         int frames;
253         int result;
254 } video_thread_t;
255 #endif
256
257 #ifdef USE_DEBUGGER
258 typedef struct {
259         EMU *emu;
260         VM *vm;
261         int cpu_index;
262         bool running;
263         bool request_terminate;
264 } debugger_thread_t;
265 #endif
266
267 #ifdef __cplusplus
268 class EMU
269 {
270 protected:
271         VM* vm;
272 #if defined(_USE_AGAR) || defined(_USE_SDL) || defined(_USE_QT)
273         SDL_sem *pVMSemaphore; // To be thread safed.
274 #endif
275 private:
276         // ----------------------------------------
277         // input
278         // ----------------------------------------
279         void initialize_input();
280         void release_input();
281         void update_input();
282         void key_down_sub(int code, bool repeat);
283         void key_up_sub(int code);
284         
285 #if !defined(_USE_AGAR) && !defined(_USE_SDL) && !defined(_USE_QT)
286         LPDIRECTINPUT lpdi;
287         LPDIRECTINPUTDEVICE lpdikey;
288         LPDIRECTINPUTDEVICE lpdijoy;
289         bool dinput_key_ok;
290         bool dinput_joy_ok;
291 #endif
292    
293         uint8 keycode_conv[256];
294         uint8 key_status[256];  // windows key code mapping
295         uint32_t modkey_status;
296         uint8 key_dik_prev[256];
297 #ifdef USE_SHIFT_NUMPAD_KEY
298         uint8 key_converted[256];
299         bool key_shift_pressed, key_shift_released;
300 #endif
301         bool lost_focus;
302         
303         uint32 joy_status[2];   // joystick #1, #2 (b0 = up, b1 = down, b2 = left, b3 = right, b4- = buttons
304         int joy_num;
305         uint32 joy_mask[2];
306         
307         int mouse_status[3];    // x, y, button (b0 = left, b1 = right)
308         bool mouse_enabled;
309         
310 #ifdef USE_AUTO_KEY
311         FIFO* autokey_buffer;
312         int autokey_phase, autokey_shift;
313 #endif
314         
315         // ----------------------------------------
316         // screen
317         // ----------------------------------------
318         void initialize_screen();
319         void release_screen();
320 #if !defined(_USE_AGAR) && !defined(_USE_SDL) && !defined(_USE_QT)
321         void create_dib_section(HDC hdc, int width, int height, HDC *hdcDib, HBITMAP *hBmp, HBITMAP *hOldBmp, LPBYTE *lpBuf, scrntype **lpBmp, LPBITMAPINFO *lpDib);
322 #endif  
323         // screen settings
324         int screen_width, screen_height;
325         int screen_width_aspect, screen_height_aspect;
326         int window_width, window_height;
327         int display_width, display_height;
328         bool screen_size_changed;
329         
330 #if defined(_USE_AGAR)
331
332 #elif defined(_USE_QT)
333
334 #else
335         HDC hdcDibSource;
336         scrntype* lpBmpSource;
337         LPBITMAPINFO lpDibSource;
338         LPBITMAPINFOHEADER pbmInfoHeader;
339 #endif
340    
341         int source_width, source_height;
342         int source_width_aspect, source_height_aspect;
343         int stretched_width, stretched_height;
344         int stretch_pow_x, stretch_pow_y;
345         int screen_dest_x, screen_dest_y;
346         bool stretch_screen;
347         
348         // update flags
349         bool first_draw_screen;
350         bool first_invalidate;
351         bool self_invalidate;
352         
353         // screen buffer
354 #if defined(_USE_AGAR) || defined(_USE_SDL) || defined(_USE_QT)
355         
356 #ifdef USE_SCREEN_ROTATE
357         // rotate buffer
358 #endif
359         
360         // stretch buffer
361         bool render_to_GL;
362         bool render_to_SDLFB;
363         bool use_GL;
364         bool use_SDLFB;
365         bool render_with_OpenCL;
366         bool single_window;
367         bool wait_vsync;
368 #ifdef _USE_QT
369         QImage *pPseudoVram;
370 #else
371         Uint32 *pPseudoVram;
372 #endif
373         // record video
374 #ifdef _USE_QT
375         _TCHAR video_file_name[_MAX_PATH];
376 #else
377         _TCHAR video_file_name[AG_PATHNAME_MAX];
378 #endif
379         int rec_video_fps;
380         double rec_video_run_frames;
381         double rec_video_frames;
382         
383 //      LPBITMAPINFO lpDibRec;
384 //      PAVIFILE pAVIFile;
385 //      PAVISTREAM pAVIStream;
386 //      PAVISTREAM pAVICompressed;
387 //      AVICOMPRESSOPTIONS opts;
388 //      DWORD dwAVIFileSize;
389 //      LONG lAVIFrames;
390         
391 //      HDC hdcDibRec;
392 //      HBITMAP hBmpRec, hOldBmpRec;
393 //      LPBYTE lpBufRec;
394 //      scrntype* lpBmpRec;
395         
396         bool use_video_thread;
397 #if defined(_USE_QT)
398 #else
399         AG_Thread hVideoThread;
400 #endif
401         //video_thread_t video_thread_param;
402
403         // ----------------------------------------
404         // sound
405         // ----------------------------------------
406         void initialize_sound();
407         void release_sound();
408         void update_sound(int* extra_frames);
409         //void AudioCallbackSDL(void *udata, Uint8 *stream, int len);
410
411         sdl_snddata_t snddata;
412         int sound_rate, sound_samples;
413         bool sound_ok, sound_started, now_mute;
414         SDL_AudioSpec SndSpecReq, SndSpecPresented;
415         //Uint8 iTotalVolume;
416         // direct sound
417         bool first_half;
418         
419         // record sound
420 #if defined(_USE_QT)
421         _TCHAR sound_file_name[_MAX_PATH];
422 #else
423         _TCHAR sound_file_name[AG_PATHNAME_MAX];
424 #endif
425         FILEIO* rec;
426         int rec_bytes;
427         int rec_buffer_ptr;
428
429 #else // _WIN32
430         HDC hdcDib;
431         HBITMAP hBmp, hOldBmp;
432         LPBYTE lpBuf;
433         scrntype* lpBmp;
434         LPBITMAPINFO lpDib;
435         
436 #ifdef USE_SCREEN_ROTATE
437         // rotate buffer
438         HDC hdcDibRotate;
439         HBITMAP hBmpRotate, hOldBmpRotate;
440         LPBYTE lpBufRotate;
441         scrntype* lpBmpRotate;
442         LPBITMAPINFO lpDibRotate;
443 #endif
444         
445         // stretch buffer
446         HDC hdcDibStretch1;
447         HBITMAP hBmpStretch1, hOldBmpStretch1;
448         LPBYTE lpBufStretch1;
449         scrntype* lpBmpStretch1;
450         LPBITMAPINFO lpDibStretch1;
451         
452         HDC hdcDibStretch2;
453         HBITMAP hBmpStretch2, hOldBmpStretch2;
454         LPBYTE lpBufStretch2;
455         scrntype* lpBmpStretch2;
456         LPBITMAPINFO lpDibStretch2;
457         
458         // for direct3d9
459         LPDIRECT3D9 lpd3d9;
460         LPDIRECT3DDEVICE9 lpd3d9Device;
461         LPDIRECT3DSURFACE9 lpd3d9Surface;
462         LPDIRECT3DSURFACE9 lpd3d9OffscreenSurface;
463         scrntype *lpd3d9Buffer;
464         bool render_to_d3d9Buffer;
465         bool use_d3d9;
466         bool wait_vsync;
467         // record video
468         _TCHAR video_file_name[_MAX_PATH];
469         int rec_video_fps;
470         double rec_video_run_frames;
471         double rec_video_frames;
472 #endif  
473         
474 #if defined(_USE_AGAR) || defined(_USE_SDL) || defined(_USE_QT)
475 #else
476         LPBITMAPINFO lpDibRec;
477         PAVIFILE pAVIFile;
478         PAVISTREAM pAVIStream;
479         PAVISTREAM pAVICompressed;
480         AVICOMPRESSOPTIONS opts;
481         DWORD dwAVIFileSize;
482         LONG lAVIFrames;
483         
484         HDC hdcDibRec;
485         HBITMAP hBmpRec, hOldBmpRec;
486         LPBYTE lpBufRec;
487         scrntype* lpBmpRec;
488
489         bool use_video_thread;
490         HANDLE hVideoThread;
491         video_thread_t video_thread_param;
492
493         void initialize_sound();
494         void release_sound();
495         void update_sound(int* extra_frames);
496         
497         int sound_rate, sound_samples;
498         bool sound_ok, sound_started, now_mute;
499
500 #endif
501    
502         
503         // ----------------------------------------
504         // sound
505         // ----------------------------------------
506 #if defined(_USE_AGAR) || defined(_USE_QT)
507 #else
508         // direct sound
509         LPDIRECTSOUND lpds;
510         LPDIRECTSOUNDBUFFER lpdsb, lpdsp;
511         bool first_half;
512         
513         // record sound
514         _TCHAR sound_file_name[_MAX_PATH];
515         FILEIO* rec;
516         int rec_bytes;
517         int rec_buffer_ptr;
518 #endif
519 #endif
520    
521 #if defined(_USE_AGAR)
522         // ----------------------------------------
523         // direct show
524         // ----------------------------------------
525         void initialize_display_agar();
526         void release_display_agar();
527 #elif defined(_USE_QT)
528 #ifdef USE_LASER_DISC
529         double movie_frame_rate;
530         int movie_sound_rate;
531         bool now_movie_play, now_movie_pause;
532 #endif
533 #else
534 #ifdef USE_DIRECT_SHOW
535         // ----------------------------------------
536         // direct show
537         // ----------------------------------------
538         void initialize_direct_show();
539         void release_direct_show();
540         void create_direct_show_dib_section();
541         void release_direct_show_dib_section();
542         
543         IGraphBuilder *pGraphBuilder;
544         IBaseFilter *pVideoBaseFilter;
545         IBaseFilter *pCaptureBaseFilter;
546         ICaptureGraphBuilder2 *pCaptureGraphBuilder2;
547         ISampleGrabber *pVideoSampleGrabber;
548         IBaseFilter *pSoundBaseFilter;
549         ISampleGrabber *pSoundSampleGrabber;
550         CMySampleGrabberCB *pSoundCallBack;
551         IMediaControl *pMediaControl;
552         IMediaSeeking *pMediaSeeking;
553         IMediaPosition *pMediaPosition;
554         IVideoWindow *pVideoWindow;
555         IBasicVideo *pBasicVideo;
556         IBasicAudio *pBasicAudio;
557         bool bTimeFormatFrame;
558         bool bVerticalReversed;
559         
560         HDC hdcDibDShow;
561         HBITMAP hBmpDShow, hOldBmpDShow;
562         LPBYTE lpBufDShow;
563         scrntype* lpBmpDShow;
564         LPBITMAPINFO lpDibDShow;
565         
566         int direct_show_width, direct_show_height;
567         bool direct_show_mute[2];
568 #ifdef USE_LASER_DISC
569         double movie_frame_rate;
570         int movie_sound_rate;
571         bool now_movie_play, now_movie_pause;
572 #endif
573 #ifdef USE_VIDEO_CAPTURE
574         void enum_capture_devs();
575         bool connect_capture_dev(int index, bool pin);
576         int cur_capture_dev_index;
577         int num_capture_devs;
578         _TCHAR capture_dev_name[MAX_CAPTURE_DEVS][256];
579 #endif
580 #endif
581 #endif // _WIN32
582    
583         // ----------------------------------------
584         // media
585         // ----------------------------------------
586         typedef struct {
587                 _TCHAR path[_MAX_PATH];
588                 bool play;
589                 int bank;
590                 int wait_count;
591         } media_status_t;
592         
593 #ifdef USE_CART1
594         media_status_t cart_status[MAX_CART];
595 #endif
596 #ifdef USE_FD1
597         media_status_t disk_status[MAX_FD];
598 #endif
599 #ifdef USE_QD1
600         media_status_t quickdisk_status[MAX_QD];
601 #endif
602 #ifdef USE_TAPE
603         media_status_t tape_status;
604 #endif
605 #ifdef USE_LASER_DISC
606         media_status_t laser_disc_status;
607 #endif
608         
609         void initialize_media();
610         void update_media();
611         void restore_media();
612         
613         void clear_media_status(media_status_t *status)
614         {
615                 status->path[0] = _T('\0');
616                 status->wait_count = 0;
617         }
618         
619         // ----------------------------------------
620         // printer
621         // ----------------------------------------
622         void initialize_printer();
623         void release_printer();
624         void reset_printer();
625         void update_printer();
626         void open_printer_file();
627         void close_printer_file();
628 #ifdef _USE_QT
629         _TCHAR prn_file_name[_MAX_PATH];
630 #else
631         _TCHAR prn_file_name[AG_PATHNAME_MAX];
632 #endif
633         FILEIO *prn_fio;
634         int prn_data, prn_wait_frames;
635         bool prn_strobe;
636         
637 #ifdef USE_SOCKET
638         // ----------------------------------------
639         // socket
640         // ----------------------------------------
641         void initialize_socket();
642         void release_socket();
643         void update_socket();
644         
645         int soc[SOCKET_MAX];
646         bool is_tcp[SOCKET_MAX];
647         struct sockaddr_in udpaddr[SOCKET_MAX];
648         int socket_delay[SOCKET_MAX];
649         char recv_buffer[SOCKET_MAX][SOCKET_BUFFER_MAX];
650         int recv_r_ptr[SOCKET_MAX], recv_w_ptr[SOCKET_MAX];
651 #endif
652         
653 #ifdef USE_DEBUGGER
654         // ----------------------------------------
655         // debugger
656         // ----------------------------------------
657         void initialize_debugger();
658         void release_debugger();
659 #if defined(_USE_AGAR)
660         AG_Thread hDebuggerThread;
661 #elif defined(_USE_QT)
662 #else
663         HANDLE hDebuggerThread;
664 #endif
665         debugger_thread_t debugger_thread_param;
666 #endif
667         
668 #ifdef _DEBUG_LOG
669         // ----------------------------------------
670         // debug log
671         // ----------------------------------------
672         void initialize_debug_log();
673         void release_debug_log();
674         FILE* debug_log;
675 #endif
676         
677 #ifdef USE_STATE
678         // ----------------------------------------
679         // state
680         // ----------------------------------------
681         void save_state_tmp(_TCHAR* file_path);
682         bool load_state_tmp(_TCHAR* file_path);
683 #endif
684         
685         // ----------------------------------------
686         // misc
687         // ----------------------------------------
688 #ifdef USE_CPU_TYPE
689         int cpu_type;
690 #endif
691 #ifdef USE_SOUND_DEVICE_TYPE
692         int sound_device_type;
693 #endif
694         _TCHAR app_path[_MAX_PATH];
695         bool now_suspended;
696         
697 public:
698         bool bDrawLine[SCREEN_HEIGHT];
699         uint32_t *getJoyStatPtr(void) {
700            return joy_status;
701         }
702    
703         // ----------------------------------------
704         // initialize
705         // ----------------------------------------
706 #if defined(_USE_AGAR)
707         EMU(AG_Window *hwnd, AG_Widget *hinst);
708 #elif defined(_USE_QT)
709         EMU(class Ui_MainWindow*, GLDrawClass*);
710 #else
711         EMU(HWND hwnd, HINSTANCE hinst);
712 #endif
713         ~EMU();
714
715         _TCHAR* application_path()
716         {
717                 return app_path;
718         }
719         _TCHAR* bios_path(_TCHAR* file_name);
720 #if defined(_USE_AGAR) || defined(_USE_SDL) || defined(_USE_QT)
721         // To be thread safety.
722         void LockVM(void) {
723            if(pVMSemaphore) SDL_SemWait(pVMSemaphore);
724         }
725         void UnlockVM(void) {
726            if(pVMSemaphore) SDL_SemPost(pVMSemaphore);
727         }
728 #endif
729 #ifdef _USE_QT
730         QImage *getPseudoVramClass(void) { return pPseudoVram;}
731 #endif
732         // ----------------------------------------
733         // for windows
734         // ----------------------------------------
735 #if defined(_USE_AGAR)
736         AG_Window *main_window_handle;
737         AG_Widget *instance_handle;
738         bool use_opengl;
739         bool use_opencl;
740 #elif defined(_USE_QT)
741         class Ui_MainWindow *main_window_handle;
742         GLDrawClass *instance_handle;
743         bool use_opengl;
744         bool use_opencl;
745 #else
746         HWND main_window_handle;
747         HINSTANCE instance_handle;
748         bool vista_or_later;
749 #endif  
750         // drive virtual machine
751         int frame_interval();
752         int run();
753         void reset();
754 #ifdef USE_SPECIAL_RESET
755         void special_reset();
756 #endif
757 #ifdef USE_POWER_OFF
758         void notify_power_off();
759 #endif
760         void suspend();
761         
762         // media
763 #ifdef USE_FD1
764         struct {
765                 _TCHAR path[_MAX_PATH];
766 //              struct {
767 //                      _TCHAR name[128]; // Convert to UTF8
768 //              //      int offset;
769 //              } bank[MAX_D88_BANKS];
770                 _TCHAR disk_name[MAX_D88_BANKS][128];  // Convert to UTF8
771                 int bank_num;
772                 int cur_bank;
773         } d88_file[MAX_FD];
774 #endif
775        int get_access_lamp(void);
776         
777         // user interface
778 #ifdef USE_CART1
779         void open_cart(int drv, _TCHAR* file_path);
780         void close_cart(int drv);
781         bool cart_inserted(int drv);
782 #endif
783 #ifdef USE_FD1
784         void open_disk(int drv, _TCHAR* file_path, int bank);
785         void close_disk(int drv);
786         bool disk_inserted(int drv);
787         bool is_write_protected_fd(int drv);
788         void write_protect_fd(int drv, bool flag);
789 #endif
790 #ifdef USE_QD1
791         void open_quickdisk(int drv, _TCHAR* file_path);
792         void close_quickdisk(int drv);
793         bool quickdisk_inserted(int drv);
794 #endif
795 #ifdef USE_TAPE
796         void play_tape(_TCHAR* file_path);
797         void rec_tape(_TCHAR* file_path);
798         void close_tape();
799         bool tape_inserted();
800 # ifdef USE_TAPE_PTR
801         int get_tape_ptr() {
802            return vm->get_tape_ptr();
803         }
804 # endif
805 #endif
806 #ifdef USE_TAPE_BUTTON
807         void push_play();
808         void push_stop();
809         void push_fast_forward();
810         void push_fast_rewind();
811         void push_apss_forward();
812         void push_apss_rewind();
813         bool get_tape_play(void)
814         {
815                 return vm->get_tape_play();
816         }
817 #endif
818 #ifdef USE_LASER_DISC
819         void open_laser_disc(_TCHAR* file_path);
820         void close_laser_disc();
821         bool laser_disc_inserted();
822 #endif
823 #ifdef USE_BINARY_FILE1
824         void load_binary(int drv, _TCHAR* file_path);
825         void save_binary(int drv, _TCHAR* file_path);
826 #endif
827         bool now_skip();
828         
829         void start_rec_sound();
830         void stop_rec_sound();
831         void restart_rec_sound();
832         bool now_rec_sound;
833         
834         void capture_screen();
835         bool start_rec_video(int fps);
836         void stop_rec_video();
837         void restart_rec_video();
838         bool now_rec_video;
839         
840         void update_config();
841         
842 #ifdef USE_STATE
843         void save_state();
844         void load_state();
845 #endif
846         
847         // input device
848 #if defined(_USE_QT)
849        void key_mod(uint32 mod) {
850             modkey_status = mod;
851        }
852 #endif
853         void key_down(int code, bool repeat);
854         void key_up(int code);
855         void key_lost_focus()
856         {
857                 lost_focus = true;
858         }
859         uint32 recent_key_sym;
860         uint32 recent_key_mod;
861         uint32 recent_key_unicode;
862 #ifdef USE_BUTTON
863         void press_button(int num);
864 #endif
865         
866         void enable_mouse();
867         void disenable_mouse();
868         void toggle_mouse();
869         bool get_mouse_enabled()
870         {
871                 return mouse_enabled;
872         }
873         
874 #ifdef USE_AUTO_KEY
875         void start_auto_key();
876         void stop_auto_key();
877         bool now_auto_key()
878         {
879                 return (autokey_phase != 0);
880         }
881 #endif
882         
883         // screen
884         int get_window_width(int mode);
885         int get_window_height(int mode);
886         void set_display_size(int width, int height, bool window_mode);
887         int draw_screen();
888 #if defined(_USE_AGAR)
889         void update_screen(AG_Widget *target);
890 #elif defined(_USE_QT)
891         void update_screen(GLDrawClass *glv);
892 #else
893         void update_screen(HDC hdc);
894 #endif
895 #ifdef USE_BITMAP
896         void reload_bitmap()
897         {
898                 first_invalidate = true;
899         }
900 #endif
901         
902         // sound
903         void mute_sound();
904         
905 #ifdef USE_VIDEO_CAPTURE
906         // video capture
907         int get_cur_capture_dev_index()
908         {
909                 return cur_capture_dev_index;
910         }
911         int get_num_capture_devs()
912         {
913                 return num_capture_devs;
914         }
915         _TCHAR* get_capture_dev_name(int index)
916         {
917                 return capture_dev_name[index];
918         }
919         void open_capture_dev(int index, bool pin);
920         void close_capture_dev();
921         void show_capture_dev_filter();
922         void show_capture_dev_pin();
923         void show_capture_dev_source();
924 #endif
925         
926 #ifdef USE_SOCKET
927         // socket
928         int get_socket(int ch)
929         {
930                 return soc[ch];
931         }
932         void socket_connected(int ch);
933         void socket_disconnected(int ch);
934         void send_data(int ch);
935         void recv_data(int ch);
936 #endif
937         
938 #ifdef USE_DEBUGGER
939         // debugger
940         void open_debugger(int cpu_index);
941         void close_debugger();
942         bool debugger_enabled(int cpu_index);
943         bool now_debugging;
944 #endif
945         
946         // ----------------------------------------
947         // for virtual machine
948         // ----------------------------------------
949         
950         // power off
951         void power_off()
952         {
953 #if defined(_USE_AGAR)
954
955 #elif defined(_USE_QT)
956            
957 #else
958                 PostMessage(main_window_handle, WM_CLOSE, 0, 0L);
959 #endif
960         }
961         
962         // input device
963         uint8* key_buffer()
964         {
965                 return key_status;
966         }
967         uint32* joy_buffer()
968         {
969                 return joy_status;
970         }
971         int* mouse_buffer()
972         {
973                 return mouse_status;
974         }
975         
976         // screen
977         void change_screen_size(int sw, int sh, int swa, int sha, int ww, int wh);
978         int get_screen_width_aspect(void) {return screen_width_aspect;}
979         int get_screen_height_aspect(void) {return screen_height_aspect;}
980         scrntype* screen_buffer(int y);
981 #ifdef USE_CRT_FILTER
982         bool screen_skip_line;
983 #endif
984         
985         // timer
986         void get_host_time(cur_time_t* time);
987         
988         // printer
989         void printer_out(uint8 value);
990         void printer_strobe(bool value);
991         
992 #ifdef USE_DIRECT_SHOW
993         // direct show
994         void get_direct_show_buffer();
995         void mute_direct_show_dev(bool l, bool r);
996         
997 #ifdef USE_LASER_DISC
998         bool open_movie_file(_TCHAR* file_path);
999         void close_movie_file();
1000         
1001         void play_movie();
1002         void stop_movie();
1003         void pause_movie();
1004         
1005         double get_movie_frame_rate()
1006         {
1007                 return movie_frame_rate;
1008         }
1009         int get_movie_sound_rate()
1010         {
1011                 return movie_sound_rate;
1012         }
1013         void set_cur_movie_frame(int frame, bool relative);
1014         uint32 get_cur_movie_frame();
1015 #endif
1016 #ifdef USE_VIDEO_CAPTURE
1017         void set_capture_dev_channel(int ch);
1018 #endif
1019 #endif
1020         
1021 #ifdef USE_SOCKET
1022         // socket
1023         bool init_socket_tcp(int ch);
1024         bool init_socket_udp(int ch);
1025         bool connect_socket(int ch, uint32 ipaddr, int port);
1026         void disconnect_socket(int ch);
1027         bool listen_socket(int ch);
1028         void send_data_tcp(int ch);
1029         void send_data_udp(int ch, uint32 ipaddr, int port);
1030 #endif
1031         
1032         // debug log
1033         void out_debug_log(const _TCHAR* format, ...);
1034         
1035         void out_message(const _TCHAR* format, ...);
1036         int message_count;
1037         _TCHAR message[_MAX_PATH];
1038 };
1039 #endif
1040
1041