2 Skelton for retropc emulator
4 Author : K.Ohta <whatisthis.sowhat _at_ gmail.com>
23 #include "../config.h"
24 #include "../fileio.h"
26 #if !defined(Q_OS_WIN32)
35 SDL_sem **pSndApplySem;
43 #if defined(USE_MOVIE_PLAYER) || defined(USE_VIDEO_CAPTURE)
44 ISampleGrabberCB : public IUnknown {
46 virtual HRESULT STDMETHODCALLTYPE SampleCB( double SampleTime,IMediaSample *pSample) = 0;
47 virtual HRESULT STDMETHODCALLTYPE BufferCB( double SampleTime,BYTE *pBuffer,long BufferLen) = 0;
49 EXTERN_C const IID IID_ISampleGrabber;
50 MIDL_INTERFACE("6B652FFF-11FE-4fce-92AD-0266B5D7C78F")
51 ISampleGrabber : public IUnknown {
53 virtual HRESULT STDMETHODCALLTYPE SetOneShot( BOOL OneShot) = 0;
54 virtual HRESULT STDMETHODCALLTYPE SetMediaType( const AM_MEDIA_TYPE *pType) = 0;
55 virtual HRESULT STDMETHODCALLTYPE GetConnectedMediaType( AM_MEDIA_TYPE *pType) = 0;
56 virtual HRESULT STDMETHODCALLTYPE SetBufferSamples( BOOL BufferThem) = 0;
57 virtual HRESULT STDMETHODCALLTYPE GetCurrentBuffer( /* [out][in] */ long *pBufferSize,/* [out] */ long *pBuffer) = 0;
58 virtual HRESULT STDMETHODCALLTYPE GetCurrentSample( /* [retval][out] */ IMediaSample **ppSample) = 0;
59 virtual HRESULT STDMETHODCALLTYPE SetCallback( ISampleGrabberCB *pCallback,long WhichMethodToCallback) = 0;
62 #ifdef USE_MOVIE_PLAYER
63 class CMySampleGrabberCB : public ISampleGrabberCB {
67 CMySampleGrabberCB(VM *vm_ptr)
71 STDMETHODIMP_(ULONG) AddRef()
75 STDMETHODIMP_(ULONG) Release()
79 STDMETHODIMP QueryInterface(REFIID riid, void **ppv)
81 if(riid == IID_ISampleGrabberCB || riid == IID_IUnknown) {
82 *ppv = (void *) static_cast<ISampleGrabberCB*>(this);
87 STDMETHODIMP SampleCB(double SampleTime, IMediaSample *pSample)
91 STDMETHODIMP BufferCB(double dblSampleTime, BYTE *pBuffer, long lBufferSize)
93 vm->movie_sound_callback(pBuffer, lBufferSize);
100 #define WM_RESIZE (WM_USER + 1)
101 #define WM_SOCKET0 (WM_USER + 2)
102 #define WM_SOCKET1 (WM_USER + 3)
103 #define WM_SOCKET2 (WM_USER + 4)
104 #define WM_SOCKET3 (WM_USER + 5)
108 #define SOCKET_BUFFER_MAX 0x100000
111 #ifdef USE_VIDEO_CAPTURE
112 #define MAX_CAPTURE_DEVS 8
115 // check memory leaks
117 //#define _CRTDBG_MAP_ALLOC
118 //#include <crtdbg.h>
119 //#define malloc(s) _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
120 //#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
123 typedef struct screen_buffer_s {
125 //HBITMAP hBmp, hOldBmp;
132 //PAVISTREAM pAVICompressed;
134 //LPBITMAPINFOHEADER pbmInfoHeader;
139 } rec_video_thread_param_t;
142 #include "mainwidget.h"
143 #include "qt_gldraw.h"
144 #include "agar_logger.h"
147 class EmuThreadClass;
148 class DrawThreadClass;
155 class OSD : public QThread
161 EmuThreadClass *parent_thread;
162 QSemaphore *VMSemaphore;
163 _TCHAR auto_key_str[2048];
164 sdl_snddata_t snddata;
166 _TCHAR app_path[_MAX_PATH];
169 FILE *hStdIn, *hStdOut;
170 FIFO *osd_console_input;
171 bool osd_console_opened;
173 void initialize_input();
174 void release_input();
175 void key_down_sub(int code, bool repeat);
176 void key_up_sub(int code);
177 scrntype *get_buffer(screen_buffer_t *p, int y);
179 // bool dinput_joy_ok;
181 uint8 keycode_conv[256];
182 uint8 key_status[256]; // windows key code mapping
183 uint8 key_dik_prev[256];
184 #ifdef USE_SHIFT_NUMPAD_KEY
185 uint8 key_converted[256];
186 bool key_shift_pressed, key_shift_released;
188 uint32_t modkey_status;
191 uint32 joy_status[2]; // joystick #1, #2 (b0 = up, b1 = down, b2 = left, b3 = right, b4- = buttons
195 int mouse_status[3]; // x, y, button (b0 = left, b1 = right)
202 Qt::CursorShape mouse_shape;
205 FIFO* autokey_buffer;
206 int autokey_phase, autokey_shift;
207 int autokey_table[256];
213 void initialize_screen();
214 void release_screen();
215 void initialize_screen_buffer(screen_buffer_t *buffer, int width, int height, int mode);
216 void release_screen_buffer(screen_buffer_t *buffer);
217 #ifdef USE_CRT_FILTER
218 void apply_crt_fileter_to_screen_buffer(screen_buffer_t *source, screen_buffer_t *dest);
219 void apply_crt_filter_x3_y3(screen_buffer_t *source, screen_buffer_t *dest);
220 void apply_crt_filter_x3_y2(screen_buffer_t *source, screen_buffer_t *dest);
221 void apply_crt_filter_x2_y3(screen_buffer_t *source, screen_buffer_t *dest);
222 void apply_crt_filter_x2_y2(screen_buffer_t *source, screen_buffer_t *dest);
223 void apply_crt_filter_x1_y1(screen_buffer_t *source, screen_buffer_t *dest);
225 #ifdef USE_SCREEN_ROTATE
226 void rotate_screen_buffer(screen_buffer_t *source, screen_buffer_t *dest);
228 void stretch_screen_buffer(screen_buffer_t *source, screen_buffer_t *dest);
229 int add_video_frames();
231 screen_buffer_t vm_screen_buffer;
232 screen_buffer_t video_screen_buffer;
233 #ifdef USE_CRT_FILTER
234 screen_buffer_t filtered_screen_buffer;
236 screen_buffer_t* draw_screen_buffer;
238 int host_window_width, host_window_height;
239 bool host_window_mode;
240 int base_window_width, base_window_height;
241 int vm_screen_width, vm_screen_height, vm_screen_width_aspect, vm_screen_height_aspect;
242 int draw_screen_width, draw_screen_height;
245 _TCHAR video_file_name[_MAX_PATH];
247 double rec_video_run_frames;
248 double rec_video_frames;
250 //LPBITMAPINFO lpDibRec;
252 //PAVISTREAM pAVIStream;
253 //PAVISTREAM pAVICompressed;
254 //AVICOMPRESSOPTIONS AVIOpts;
257 //HANDLE hVideoThread;
258 rec_video_thread_param_t rec_video_thread_param;
260 bool first_draw_screen;
261 bool first_invalidate;
262 bool self_invalidate;
265 void initialize_sound(int rate, int samples);
266 void release_sound();
268 int sound_rate, sound_samples;
269 bool sound_ok, sound_started, now_mute;
270 bool sound_first_half;
272 _TCHAR sound_file_name[_MAX_PATH];
273 FILEIO* rec_sound_fio;
275 int rec_sound_buffer_ptr;
278 #if defined(USE_MOVIE_PLAYER) || defined(USE_VIDEO_CAPTURE)
280 void initialize_video();
281 void release_video();
283 //IGraphBuilder *pGraphBuilder;
284 //IBaseFilter *pVideoBaseFilter;
285 //IBaseFilter *pCaptureBaseFilter;
286 //ICaptureGraphBuilder2 *pCaptureGraphBuilder2;
287 //ISampleGrabber *pVideoSampleGrabber;
288 //IBaseFilter *pSoundBaseFilter;
289 //ISampleGrabber *pSoundSampleGrabber;
290 //CMySampleGrabberCB *pSoundCallBack;
291 //IMediaControl *pMediaControl;
292 //IMediaSeeking *pMediaSeeking;
293 //IMediaPosition *pMediaPosition;
294 //IVideoWindow *pVideoWindow;
295 //IBasicVideo *pBasicVideo;
296 //IBasicAudio *pBasicAudio;
297 //bool bTimeFormatFrame;
298 //bool bVerticalReversed;
300 screen_buffer_t dshow_screen_buffer;
301 int direct_show_width, direct_show_height;
302 bool direct_show_mute[2];
304 #ifdef USE_MOVIE_PLAYER
305 double movie_frame_rate;
306 int movie_sound_rate;
308 #ifdef USE_VIDEO_CAPTURE
309 void enum_capture_devs();
310 bool connect_capture_dev(int index, bool pin);
311 int cur_capture_dev_index;
312 int num_capture_devs;
313 _TCHAR capture_dev_name[MAX_CAPTURE_DEVS][256];
315 _TCHAR prn_file_name[_MAX_PATH];
317 int prn_data, prn_wait_frames;
322 void initialize_socket();
323 void release_socket();
326 bool is_tcp[SOCKET_MAX];
327 //struct sockaddr_in udpaddr[SOCKET_MAX];
328 int socket_delay[SOCKET_MAX];
329 char recv_buffer[SOCKET_MAX][SOCKET_BUFFER_MAX];
330 int recv_r_ptr[SOCKET_MAX], recv_w_ptr[SOCKET_MAX];
340 class Ui_MainWindow *main_window_handle;
344 void initialize(int rate, int samples);
349 _TCHAR* application_path()
353 _TCHAR* bios_path(const _TCHAR* file_name);
354 void get_host_time(cur_time_t* time);
355 void sleep(uint32 ms);
356 void create_date_file_name(_TCHAR *name, int length, const _TCHAR *extension);
359 void open_console(_TCHAR* title);
360 void close_console();
361 unsigned int get_console_code_page();
362 bool is_console_active();
363 void set_console_text_attribute(unsigned short attr);
364 void write_console(_TCHAR* buffer, unsigned int length);
365 int read_console_input(_TCHAR* buffer);
369 void key_down(int code, bool repeat);
370 void key_up(int code);
371 void key_lost_focus()
375 #ifdef ONE_BOARD_MICRO_COMPUTER
376 void press_button(int num);
378 # if !defined(Q_OS_WIN) && !defined(Q_OS_CYGWIN)
379 uint16_t GetAsyncKeyState(uint32_t vk); // Win32 GetAsyncKeyState() wrappeer.
381 void key_modifiers(uint32 mod) {
385 void disenable_mouse();
387 bool get_mouse_enabled()
389 return mouse_enabled;
391 //QImage *getPseudoVramClass(void) { return pPseudoVram;}
392 void set_mouse_pointer(int x, int y) {
396 void set_mouse_button(int button) {
397 mouse_button = button;
399 int get_mouse_button() {
403 void start_auto_key();
404 void stop_auto_key();
407 return (autokey_phase != 0);
424 void reset_printer() {
425 close_printer_file();
429 void update_printer() {
430 if(prn_fio->IsOpened() && --prn_wait_frames == 0) {
431 close_printer_file();
434 void printer_out(uint8 value) {
437 void printer_strobe(bool value) {
438 bool falling = (prn_strobe && !value);
442 if(!prn_fio->IsOpened()) {
448 prn_fio->Fputc(prn_data);
450 #ifdef SUPPORT_VARIABLE_TIMING
451 prn_wait_frames = (int)(vm->frame_rate() * 10.0 + 0.5);
453 prn_wait_frames = (int)(FRAMES_PER_SEC * 10.0 + 0.5);
458 void initialize_printer();
459 void release_printer();
460 void open_printer_file() {
461 create_date_file_name(prn_file_name, _MAX_PATH, _T("txt"));
462 prn_fio->Fopen(bios_path(prn_file_name), FILEIO_WRITE_BINARY);
465 void close_printer_file() {
466 if(prn_fio->IsOpened()) {
467 // remove if the file size is less than 2 bytes
468 bool remove = (prn_fio->Ftell() < 2);
471 FILEIO::RemoveFile(bios_path(prn_file_name));
477 int get_window_width(int mode);
478 int get_window_height(int mode);
479 void set_window_size(int window_width, int window_height, bool window_mode);
480 void set_vm_screen_size(int width, int height, int width_aspect, int height_aspect, int window_width, int window_height);
481 scrntype* get_vm_screen_buffer(int y);
483 #ifdef ONE_BOARD_MICRO_COMPUTER
486 first_invalidate = true;
489 void capture_screen();
490 bool start_rec_video(int fps);
491 void stop_rec_video();
492 void restart_rec_video();
493 void add_extra_frames(int extra_frames);
495 #ifdef USE_CRT_FILTER
496 bool screen_skip_line;
500 void update_sound(int* extra_frames);
503 void start_rec_sound();
504 void stop_rec_sound();
505 void restart_rec_sound();
508 #if defined(USE_MOVIE_PLAYER) || defined(USE_VIDEO_CAPTURE)
509 // common video device
510 void get_video_buffer();
511 void mute_video_dev(bool l, bool r);
513 #ifdef USE_MOVIE_PLAYER
514 bool open_movie_file(const _TCHAR* file_path);
515 void close_movie_file();
519 double get_movie_frame_rate()
521 return movie_frame_rate;
523 int get_movie_sound_rate()
525 return movie_sound_rate;
527 void set_cur_movie_frame(int frame, bool relative);
528 uint32 get_cur_movie_frame();
529 bool now_movie_play, now_movie_pause;
531 #ifdef USE_VIDEO_CAPTURE
532 int get_cur_capture_dev_index()
534 return cur_capture_dev_index;
536 int get_num_capture_devs()
538 return num_capture_devs;
540 _TCHAR* get_capture_dev_name(int index)
542 return capture_dev_name[index];
544 void open_capture_dev(int index, bool pin);
545 void close_capture_dev();
546 void show_capture_dev_filter();
547 void show_capture_dev_pin();
548 void show_capture_dev_source();
549 void set_capture_dev_channel(int ch);
554 int get_socket(int ch)
558 void socket_connected(int ch);
559 void socket_disconnected(int ch);
560 void update_socket();
561 bool init_socket_tcp(int ch);
562 bool init_socket_udp(int ch);
563 bool connect_socket(int ch, uint32 ipaddr, int port);
564 void disconnect_socket(int ch);
565 bool listen_socket(int ch);
566 void send_data_tcp(int ch);
567 void send_data_udp(int ch, uint32 ipaddr, int port);
568 void send_data(int ch);
569 void recv_data(int ch);
573 void update_screen();
574 void set_parent_thread(EmuThreadClass *parent);
575 EmuThreadClass *get_parent_handler();
576 void set_draw_thread(DrawThreadClass *handler);
578 VMSemaphore->acquire(1);
580 void unlock_vm(void){
581 VMSemaphore->release(1);
583 void force_unlock_vm(void){
584 while(VMSemaphore->available() < 1) VMSemaphore->release(1);
588 void set_auto_key_string(QByteArray);
590 void do_write_inputdata(QString s);
591 void do_close_debugger_console();
592 void do_close_debugger_thread();
595 int sig_update_screen(screen_buffer_t *);
596 int sig_save_screen(const char *);
597 int sig_close_window(void);
598 int sig_resize_vm_screen(QImage *, int, int);
599 int sig_put_string_debugger(QString);
600 int sig_debugger_finished();