OSDN Git Service

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