OSDN Git Service

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