PCem

view src/win.c @ 119:e4da69090d05

Video cards defines replaced with enumerator. Patch from SA1988.
author TomW
date Wed Jul 09 19:21:16 2014 +0100
parents c5989dbbc2ce
children 457f666b38c1
line source
1 #define BITMAP WINDOWS_BITMAP
2 #include <windows.h>
3 #include <windowsx.h>
4 #undef BITMAP
6 #include <commctrl.h>
7 #include <commdlg.h>
9 #include <process.h>
11 #include <string.h>
12 #include <stdio.h>
13 #include <stdarg.h>
14 #include <stdlib.h>
15 #include "ibm.h"
16 #include "video.h"
17 #include "resources.h"
18 #include "cpu.h"
19 #include "ide.h"
20 #include "model.h"
21 #include "nvr.h"
22 #include "sound.h"
24 #include "plat-midi.h"
25 #include "plat-keyboard.h"
27 #include "win.h"
28 #include "win-ddraw.h"
29 #include "win-ddraw-fs.h"
30 #include "win-d3d.h"
31 #include "win-d3d-fs.h"
32 //#include "win-opengl.h"
34 uint64_t timer_freq;
36 static struct
37 {
38 void (*init)(HWND h);
39 void (*close)();
40 void (*resize)(int x, int y);
41 } vid_apis[2][2] =
42 {
43 {
44 ddraw_init, ddraw_close, NULL,
45 d3d_init, d3d_close, d3d_resize
46 },
47 {
48 ddraw_fs_init, ddraw_fs_close, NULL,
49 d3d_fs_init, d3d_fs_close, NULL
50 },
51 };
53 #define TIMER_1SEC 1
55 int winsizex=640,winsizey=480;
56 int gfx_present[GFX_MAX];
57 #undef cs
58 CRITICAL_SECTION cs;
60 HANDLE mainthreadh;
62 int infocus=1;
64 int drawits=0;
66 int romspresent[ROM_MAX];
67 int quited=0;
69 RECT oldclip;
70 int mousecapture=0;
72 /* Declare Windows procedure */
73 LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
74 LRESULT CALLBACK subWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
76 HWND ghwnd;
78 HINSTANCE hinstance;
80 HMENU menu;
82 extern int updatestatus;
84 int pause=0;
86 static int win_doresize = 0;
88 static int leave_fullscreen_flag = 0;
90 void updatewindowsize(int x, int y)
91 {
92 RECT r;
93 if (vid_resize) return;
95 winsizex=x; winsizey=y;
96 win_doresize = 1;
97 }
99 void releasemouse()
100 {
101 if (mousecapture)
102 {
103 ClipCursor(&oldclip);
104 ShowCursor(TRUE);
105 mousecapture = 0;
106 }
107 }
109 void startblit()
110 {
111 EnterCriticalSection(&cs);
112 }
114 void endblit()
115 {
116 LeaveCriticalSection(&cs);
117 }
119 void leave_fullscreen()
120 {
121 leave_fullscreen_flag = 1;
122 }
124 void mainthread(LPVOID param)
125 {
126 int t = 0;
127 int frames = 0;
128 DWORD old_time, new_time;
130 // Sleep(500);
131 drawits=0;
132 old_time = GetTickCount();
133 while (!quited)
134 {
135 if (updatestatus)
136 {
137 updatestatus = 0;
138 if (status_is_open)
139 SendMessage(status_hwnd, WM_USER, 0, 0);
140 }
141 new_time = GetTickCount();
142 drawits += new_time - old_time;
143 old_time = new_time;
144 if (drawits > 0 && !pause)
145 {
146 drawits-=10; if (drawits>50) drawits=0;
147 runpc();
148 frames++;
149 if (frames >= 200 && nvr_dosave)
150 {
151 frames = 0;
152 nvr_dosave = 0;
153 savenvr();
154 }
155 }
156 else
157 Sleep(1);
159 if (!video_fullscreen && win_doresize)
160 {
161 RECT r;
162 GetWindowRect(ghwnd, &r);
163 MoveWindow(ghwnd, r.left, r.top,
164 winsizex + (GetSystemMetrics(SM_CXFIXEDFRAME) * 2),
165 winsizey + (GetSystemMetrics(SM_CYFIXEDFRAME) * 2) + GetSystemMetrics(SM_CYMENUSIZE) + GetSystemMetrics(SM_CYCAPTION) + 1,
166 TRUE);
167 win_doresize = 0;
168 }
170 if (leave_fullscreen_flag)
171 {
172 leave_fullscreen_flag = 0;
173 SendMessage(ghwnd, WM_LEAVEFULLSCREEN, 0, 0);
174 }
175 }
176 }
178 static void initmenu(void)
179 {
180 int c;
181 HMENU m;
182 char s[32];
183 m=GetSubMenu(menu,2); /*Settings*/
184 m=GetSubMenu(m,1); /*CD-ROM*/
186 /* Loop through each Windows drive letter and test to see if
187 it's a CDROM */
188 for (c='A';c<='Z';c++)
189 {
190 sprintf(s,"%c:\\",c);
191 if (GetDriveType(s)==DRIVE_CDROM)
192 {
193 sprintf(s, "Host CD/DVD Drive (%c:)", c);
194 AppendMenu(m,MF_STRING,IDM_CDROM_REAL+c,s);
195 }
196 }
197 }
199 void get_executable_name(char *s, int size)
200 {
201 GetModuleFileName(hinstance, s, size);
202 }
204 void set_window_title(char *s)
205 {
206 if (video_fullscreen)
207 return;
208 SetWindowText(ghwnd, s);
209 }
211 uint64_t timer_read()
212 {
213 LARGE_INTEGER qpc_time;
214 QueryPerformanceCounter(&qpc_time);
215 return qpc_time.QuadPart;
216 }
218 int WINAPI WinMain (HINSTANCE hThisInstance,
219 HINSTANCE hPrevInstance,
220 LPSTR lpszArgument,
221 int nFunsterStil)
223 {
224 HWND hwnd; /* This is the handle for our window */
225 MSG messages; /* Here messages to the application are saved */
226 WNDCLASSEX wincl; /* Data structure for the windowclass */
227 int c, d;
228 LARGE_INTEGER qpc_freq;
230 hinstance=hThisInstance;
231 /* The Window structure */
232 wincl.hInstance = hThisInstance;
233 wincl.lpszClassName = szClassName;
234 wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
235 wincl.style = CS_DBLCLKS; /* Catch double-clicks */
236 wincl.cbSize = sizeof (WNDCLASSEX);
238 /* Use default icon and mouse-pointer */
239 wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
240 wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
241 wincl.hCursor = NULL;//LoadCursor (NULL, IDC_ARROW);
242 wincl.lpszMenuName = NULL; /* No menu */
243 wincl.cbClsExtra = 0; /* No extra bytes after the window class */
244 wincl.cbWndExtra = 0; /* structure or the window instance */
245 /* Use Windows's default color as the background of the window */
246 wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
248 /* Register the window class, and if it fails quit the program */
249 if (!RegisterClassEx(&wincl))
250 return 0;
252 wincl.lpszClassName = szSubClassName;
253 wincl.lpfnWndProc = subWindowProcedure; /* This function is called by windows */
255 if (!RegisterClassEx(&wincl))
256 return 0;
258 menu = LoadMenu(hThisInstance, TEXT("MainMenu"));
259 initmenu();
261 /* The class is registered, let's create the program*/
262 hwnd = CreateWindowEx (
263 0, /* Extended possibilites for variation */
264 szClassName, /* Classname */
265 "PCem v8.1", /* Title Text */
266 WS_OVERLAPPEDWINDOW&~WS_SIZEBOX, /* default window */
267 CW_USEDEFAULT, /* Windows decides the position */
268 CW_USEDEFAULT, /* where the window ends up on the screen */
269 640+(GetSystemMetrics(SM_CXFIXEDFRAME)*2), /* The programs width */
270 480+(GetSystemMetrics(SM_CYFIXEDFRAME)*2)+GetSystemMetrics(SM_CYMENUSIZE)+GetSystemMetrics(SM_CYCAPTION)+1, /* and height in pixels */
271 HWND_DESKTOP, /* The window is a child-window to desktop */
272 menu, /* Menu */
273 hThisInstance, /* Program Instance handler */
274 NULL /* No Window Creation data */
275 );
277 /* Make the window visible on the screen */
278 ShowWindow (hwnd, nFunsterStil);
280 // win_set_window(hwnd);
282 ghwnd=hwnd;
284 midi_init();
285 atexit(midi_close);
287 initpc();
289 vid_apis[0][vid_api].init(ghwnd);
291 if (vid_resize) SetWindowLong(hwnd, GWL_STYLE, WS_OVERLAPPEDWINDOW|WS_VISIBLE);
292 else SetWindowLong(hwnd, GWL_STYLE, (WS_OVERLAPPEDWINDOW&~WS_SIZEBOX&~WS_THICKFRAME&~WS_MAXIMIZEBOX)|WS_VISIBLE);
294 if (!cdrom_enabled)
295 CheckMenuItem(menu, IDM_CDROM_DISABLED, MF_CHECKED);
296 else
297 CheckMenuItem(menu, IDM_CDROM_REAL + cdrom_drive, MF_CHECKED);
298 if (vid_resize) CheckMenuItem(menu, IDM_VID_RESIZE, MF_CHECKED);
299 CheckMenuItem(menu, IDM_VID_DDRAW + vid_api, MF_CHECKED);
300 CheckMenuItem(menu, IDM_VID_FS_FULL + video_fullscreen_scale, MF_CHECKED);
301 // set_display_switch_mode(SWITCH_BACKGROUND);
303 d=romset;
304 for (c=0;c<ROM_MAX;c++)
305 {
306 romset=c;
307 romspresent[c]=loadbios();
308 pclog("romset %i - %i\n", c, romspresent[c]);
309 }
311 for (c = 0; c < ROM_MAX; c++)
312 {
313 if (romspresent[c])
314 break;
315 }
316 if (c == ROM_MAX)
317 {
318 MessageBox(hwnd,"No ROMs present!\nYou must have at least one romset to use PCem.","PCem fatal error",MB_OK);
319 return 0;
320 }
322 romset=d;
323 c=loadbios();
325 if (!c)
326 {
327 if (romset!=-1) MessageBox(hwnd,"Configured romset not available.\nDefaulting to available romset.","PCem error",MB_OK);
328 for (c=0;c<ROM_MAX;c++)
329 {
330 if (romspresent[c])
331 {
332 romset = c;
333 model = model_getmodel(romset);
334 saveconfig();
335 resetpchard();
336 break;
337 }
338 }
339 }
342 for (c = 0; c < GFX_MAX; c++)
343 gfx_present[c] = video_card_available(video_old_to_new(c));
345 if (!video_card_available(video_old_to_new(gfxcard)))
346 {
347 if (romset!=-1) MessageBox(hwnd,"Configured video BIOS not available.\nDefaulting to available romset.","PCem error",MB_OK);
348 for (c = GFX_MAX-1; c >= 0; c--)
349 {
350 if (gfx_present[c])
351 {
352 gfxcard = c;
353 saveconfig();
354 resetpchard();
355 break;
356 }
357 }
358 }
360 loadbios();
362 timeBeginPeriod(1);
364 atexit(releasemouse);
366 // QueryPerformanceFrequency(&counter_base);
367 /// QueryPerformanceCounter(&counter_posold);
368 // counter_posold.QuadPart*=100;
370 InitializeCriticalSection(&cs);
371 mainthreadh=(HANDLE)_beginthread(mainthread,0,NULL);
372 SetThreadPriority(mainthreadh, THREAD_PRIORITY_HIGHEST);
375 updatewindowsize(640, 480);
377 QueryPerformanceFrequency(&qpc_freq);
378 timer_freq = qpc_freq.QuadPart;
380 // focus=1;
381 // setrefresh(100);
383 // ShowCursor(TRUE);
385 /* Run the message loop. It will run until GetMessage() returns 0 */
386 while (!quited)
387 {
388 /* if (infocus)
389 {
390 if (drawits)
391 {
392 drawits--;
393 if (drawits>10) drawits=0;
394 runpc();
395 }
396 //; else
397 // sleep(0);
398 if ((key[KEY_LCONTROL] || key[KEY_RCONTROL]) && key[KEY_END] && mousecapture)
399 {
400 ClipCursor(&oldclip);
401 mousecapture=0;
402 }
403 }*/
405 while (GetMessage(&messages,NULL,0,0) && !quited)
406 {
407 if (messages.message==WM_QUIT) quited=1;
408 TranslateMessage(&messages);
409 DispatchMessage(&messages);
410 if ((key[KEY_LCONTROL] || key[KEY_RCONTROL]) && key[KEY_END] && mousecapture)
411 {
412 ClipCursor(&oldclip);
413 ShowCursor(TRUE);
414 mousecapture=0;
415 }
416 }
418 quited=1;
419 // else
420 // sleep(10);
421 }
423 startblit();
424 // pclog("Sleep 1000\n");
425 Sleep(200);
426 // pclog("TerminateThread\n");
427 TerminateThread(mainthreadh,0);
428 // pclog("Quited? %i\n",quited);
429 // pclog("Closepc\n");
430 closepc();
431 // pclog("dumpregs\n");
433 vid_apis[video_fullscreen][vid_api].close();
435 timeEndPeriod(1);
436 // dumpregs();
437 if (mousecapture)
438 {
439 ClipCursor(&oldclip);
440 ShowCursor(TRUE);
441 }
443 UnregisterClass(szSubClassName, hinstance);
444 UnregisterClass(szClassName, hinstance);
446 // pclog("Ending! %i %i\n",messages.wParam,quited);
447 return messages.wParam;
448 }
450 char openfilestring[260];
451 int getfile(HWND hwnd, char *f, char *fn)
452 {
453 OPENFILENAME ofn; // common dialog box structure
454 BOOL r;
455 DWORD err;
457 // Initialize OPENFILENAME
458 ZeroMemory(&ofn, sizeof(ofn));
459 ofn.lStructSize = sizeof(ofn);
460 ofn.hwndOwner = hwnd;
461 ofn.lpstrFile = openfilestring;
462 //
463 // Set lpstrFile[0] to '\0' so that GetOpenFileName does not
464 // use the contents of szFile to initialize itself.
465 //
466 // ofn.lpstrFile[0] = '\0';
467 strcpy(ofn.lpstrFile,fn);
468 ofn.nMaxFile = sizeof(openfilestring);
469 ofn.lpstrFilter = f;//"All\0*.*\0Text\0*.TXT\0";
470 ofn.nFilterIndex = 1;
471 ofn.lpstrFileTitle = NULL;
472 ofn.nMaxFileTitle = 0;
473 ofn.lpstrInitialDir = NULL;
474 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
476 // Display the Open dialog box.
478 pclog("GetOpenFileName - lpstrFile = %s\n", ofn.lpstrFile);
479 r = GetOpenFileName(&ofn);
480 if (r)
481 {
482 pclog("GetOpenFileName return true\n");
483 return 0;
484 }
485 pclog("GetOpenFileName return false\n");
486 err = CommDlgExtendedError();
487 pclog("CommDlgExtendedError return %04X\n", err);
488 return 1;
489 }
491 int getsfile(HWND hwnd, char *f, char *fn)
492 {
493 OPENFILENAME ofn; // common dialog box structure
494 BOOL r;
495 DWORD err;
497 // Initialize OPENFILENAME
498 ZeroMemory(&ofn, sizeof(ofn));
499 ofn.lStructSize = sizeof(ofn);
500 ofn.hwndOwner = hwnd;
501 ofn.lpstrFile = openfilestring;
502 //
503 // Set lpstrFile[0] to '\0' so that GetOpenFileName does not
504 // use the contents of szFile to initialize itself.
505 //
506 // ofn.lpstrFile[0] = '\0';
507 strcpy(ofn.lpstrFile,fn);
508 ofn.nMaxFile = sizeof(openfilestring);
509 ofn.lpstrFilter = f;//"All\0*.*\0Text\0*.TXT\0";
510 ofn.nFilterIndex = 1;
511 ofn.lpstrFileTitle = NULL;
512 ofn.nMaxFileTitle = 0;
513 ofn.lpstrInitialDir = NULL;
514 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
516 // Display the Open dialog box.
518 pclog("GetSaveFileName - lpstrFile = %s\n", ofn.lpstrFile);
519 r = GetSaveFileName(&ofn);
520 if (r)
521 {
522 pclog("GetSaveFileName return true\n");
523 return 0;
524 }
525 pclog("GetSaveFileName return false\n");
526 err = CommDlgExtendedError();
527 pclog("CommDlgExtendedError return %04X\n", err);
528 return 1;
529 }
534 HHOOK hKeyboardHook;
536 LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam )
537 {
538 if (nCode < 0 || nCode != HC_ACTION || (!mousecapture && !video_fullscreen))
539 return CallNextHookEx( hKeyboardHook, nCode, wParam, lParam);
541 KBDLLHOOKSTRUCT* p = (KBDLLHOOKSTRUCT*)lParam;
543 if (p->vkCode == VK_TAB && p->flags & LLKHF_ALTDOWN) return 1; //disable alt-tab
544 if (p->vkCode == VK_SPACE && p->flags & LLKHF_ALTDOWN) return 1; //disable alt-tab
545 if((p->vkCode == VK_LWIN) || (p->vkCode == VK_RWIN)) return 1;//disable windows keys
546 if (p->vkCode == VK_ESCAPE && p->flags & LLKHF_ALTDOWN) return 1;//disable alt-escape
547 BOOL bControlKeyDown = GetAsyncKeyState (VK_CONTROL) >> ((sizeof(SHORT) * 8) - 1);//checks ctrl key pressed
548 if (p->vkCode == VK_ESCAPE && bControlKeyDown) return 1; //disable ctrl-escape
550 return CallNextHookEx( hKeyboardHook, nCode, wParam, lParam );
551 }
553 LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
554 {
555 HMENU hmenu;
556 RECT rect;
557 // pclog("Message %i %08X\n",message,message);
558 switch (message)
559 {
560 case WM_CREATE:
561 SetTimer(hwnd, TIMER_1SEC, 1000, NULL);
562 hKeyboardHook = SetWindowsHookEx( WH_KEYBOARD_LL, LowLevelKeyboardProc, GetModuleHandle(NULL), 0 );
563 break;
565 case WM_COMMAND:
566 // pclog("WM_COMMAND %i\n",LOWORD(wParam));
567 hmenu=GetMenu(hwnd);
568 switch (LOWORD(wParam))
569 {
570 case IDM_FILE_RESET:
571 pause=1;
572 Sleep(100);
573 resetpc();
574 pause=0;
575 break;
576 case IDM_FILE_HRESET:
577 pause=1;
578 Sleep(100);
579 resetpchard();
580 pause=0;
581 break;
582 case IDM_FILE_EXIT:
583 PostQuitMessage (0); /* send a WM_QUIT to the message queue */
584 break;
585 case IDM_DISC_A:
586 if (!getfile(hwnd,"Disc image (*.IMG;*.IMA)\0*.IMG;*.IMA\0All files (*.*)\0*.*\0",discfns[0]))
587 {
588 savedisc(0);
589 loaddisc(0,openfilestring);
590 saveconfig();
591 }
592 break;
593 case IDM_DISC_B:
594 if (!getfile(hwnd,"Disc image (*.IMG;*.IMA)\0*.IMG;*.IMA\0All files (*.*)\0*.*\0",discfns[1]))
595 {
596 savedisc(1);
597 loaddisc(1,openfilestring);
598 saveconfig();
599 }
600 break;
601 case IDM_EJECT_A:
602 savedisc(0);
603 ejectdisc(0);
604 saveconfig();
605 break;
606 case IDM_EJECT_B:
607 savedisc(1);
608 ejectdisc(1);
609 saveconfig();
610 break;
611 case IDM_HDCONF:
612 hdconf_open(hwnd);
613 break;
614 case IDM_CONFIG:
615 config_open(hwnd);
616 break;
617 case IDM_STATUS:
618 status_open(hwnd);
619 break;
621 case IDM_VID_RESIZE:
622 vid_resize=!vid_resize;
623 CheckMenuItem(hmenu, IDM_VID_RESIZE, (vid_resize)?MF_CHECKED:MF_UNCHECKED);
624 if (vid_resize) SetWindowLong(hwnd, GWL_STYLE, WS_OVERLAPPEDWINDOW|WS_VISIBLE);
625 else SetWindowLong(hwnd, GWL_STYLE, (WS_OVERLAPPEDWINDOW&~WS_SIZEBOX&~WS_THICKFRAME&~WS_MAXIMIZEBOX)|WS_VISIBLE);
626 GetWindowRect(hwnd,&rect);
627 SetWindowPos(hwnd, 0, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_FRAMECHANGED);
628 saveconfig();
629 break;
631 case IDM_VID_DDRAW: case IDM_VID_D3D:
632 startblit();
633 CheckMenuItem(hmenu, IDM_VID_DDRAW + vid_api, MF_UNCHECKED);
634 vid_apis[0][vid_api].close();
635 vid_api = LOWORD(wParam) - IDM_VID_DDRAW;
636 CheckMenuItem(hmenu, IDM_VID_DDRAW + vid_api, MF_CHECKED);
637 vid_apis[0][vid_api].init(ghwnd);
638 endblit();
639 saveconfig();
640 device_force_redraw();
641 break;
643 case IDM_VID_FULLSCREEN:
644 if (video_fullscreen_first)
645 {
646 video_fullscreen_first = 0;
647 MessageBox(hwnd, "Use CTRL + ALT + PAGE DOWN to return to windowed mode", "PCem", MB_OK);
648 }
649 startblit();
650 mouse_close();
651 vid_apis[0][vid_api].close();
652 video_fullscreen = 1;
653 vid_apis[1][vid_api].init(ghwnd);
654 mouse_init();
655 endblit();
656 device_force_redraw();
657 break;
659 case IDM_VID_FS_FULL:
660 case IDM_VID_FS_43:
661 case IDM_VID_FS_SQ:
662 case IDM_VID_FS_INT:
663 CheckMenuItem(hmenu, IDM_VID_FS_FULL + video_fullscreen_scale, MF_UNCHECKED);
664 video_fullscreen_scale = LOWORD(wParam) - IDM_VID_FS_FULL;
665 CheckMenuItem(hmenu, IDM_VID_FS_FULL + video_fullscreen_scale, MF_CHECKED);
666 saveconfig();
667 break;
669 case IDM_CDROM_DISABLED:
670 if (cdrom_enabled)
671 {
672 if (MessageBox(NULL,"This will reset PCem!\nOkay to continue?","PCem",MB_OKCANCEL) != IDOK)
673 break;
674 }
675 CheckMenuItem(hmenu, IDM_CDROM_REAL + cdrom_drive, MF_UNCHECKED);
676 CheckMenuItem(hmenu, IDM_CDROM_DISABLED, MF_CHECKED);
677 CheckMenuItem(hmenu, IDM_CDROM_EMPTY, MF_UNCHECKED);
678 if (cdrom_enabled)
679 {
680 cdrom_enabled = 0;
681 saveconfig();
682 resetpchard();
683 }
684 break;
686 case IDM_CDROM_EMPTY:
687 if (!cdrom_enabled)
688 {
689 if (MessageBox(NULL,"This will reset PCem!\nOkay to continue?","PCem",MB_OKCANCEL) != IDOK)
690 break;
691 }
692 atapi->exit();
693 ioctl_open(0);
694 CheckMenuItem(hmenu, IDM_CDROM_REAL + cdrom_drive, MF_UNCHECKED);
695 CheckMenuItem(hmenu, IDM_CDROM_DISABLED, MF_UNCHECKED);
696 cdrom_drive=0;
697 CheckMenuItem(hmenu, IDM_CDROM_EMPTY, MF_CHECKED);
698 saveconfig();
699 if (!cdrom_enabled)
700 {
701 cdrom_enabled = 1;
702 saveconfig();
703 resetpchard();
704 }
705 break;
706 default:
707 if (LOWORD(wParam)>=IDM_CDROM_REAL && LOWORD(wParam)<(IDM_CDROM_REAL+100))
708 {
709 if (!cdrom_enabled)
710 {
711 if (MessageBox(NULL,"This will reset PCem!\nOkay to continue?","PCem",MB_OKCANCEL) != IDOK)
712 break;
713 }
714 atapi->exit();
715 ioctl_open(LOWORD(wParam)-IDM_CDROM_REAL);
716 CheckMenuItem(hmenu, IDM_CDROM_REAL + cdrom_drive, MF_UNCHECKED);
717 CheckMenuItem(hmenu, IDM_CDROM_DISABLED, MF_UNCHECKED);
718 cdrom_drive = LOWORD(wParam) - IDM_CDROM_REAL;
719 CheckMenuItem(hmenu, IDM_CDROM_REAL + cdrom_drive, MF_CHECKED);
720 saveconfig();
721 if (!cdrom_enabled)
722 {
723 cdrom_enabled = 1;
724 saveconfig();
725 resetpchard();
726 }
727 }
728 break;
729 }
730 return 0;
732 case WM_SETFOCUS:
733 infocus=1;
734 // QueryPerformanceCounter(&counter_posold);
735 // pclog("Set focus!\n");
736 break;
737 case WM_KILLFOCUS:
738 infocus=0;
739 if (mousecapture)
740 {
741 ClipCursor(&oldclip);
742 ShowCursor(TRUE);
743 mousecapture=0;
744 }
745 // pclog("Lost focus!\n");
746 break;
748 case WM_LBUTTONUP:
749 if (!mousecapture && !video_fullscreen)
750 {
751 RECT pcclip;
753 GetClipCursor(&oldclip);
754 GetWindowRect(hwnd, &pcclip);
755 pcclip.left += GetSystemMetrics(SM_CXFIXEDFRAME) + 10;
756 pcclip.right -= GetSystemMetrics(SM_CXFIXEDFRAME) + 10;
757 pcclip.top += GetSystemMetrics(SM_CXFIXEDFRAME) + GetSystemMetrics(SM_CYMENUSIZE) + GetSystemMetrics(SM_CYCAPTION) + 10;
758 pcclip.bottom -= GetSystemMetrics(SM_CXFIXEDFRAME) + 10;
759 ClipCursor(&pcclip);
760 mousecapture = 1;
761 ShowCursor(FALSE);
762 }
763 break;
765 case WM_MBUTTONUP:
766 releasemouse();
767 break;
769 case WM_ENTERMENULOOP:
770 // if (key[KEY_ALT] || key[KEY_ALTGR]) return 0;
771 break;
773 case WM_SIZE:
774 winsizex=lParam&0xFFFF;
775 winsizey=lParam>>16;
777 if (vid_apis[video_fullscreen][vid_api].resize)
778 {
779 startblit();
780 vid_apis[video_fullscreen][vid_api].resize(winsizex, winsizey);
781 endblit();
782 }
784 if (mousecapture)
785 {
786 RECT pcclip;
788 GetWindowRect(hwnd, &pcclip);
789 pcclip.left += GetSystemMetrics(SM_CXFIXEDFRAME) + 10;
790 pcclip.right -= GetSystemMetrics(SM_CXFIXEDFRAME) + 10;
791 pcclip.top += GetSystemMetrics(SM_CXFIXEDFRAME) + GetSystemMetrics(SM_CYMENUSIZE) + GetSystemMetrics(SM_CYCAPTION) + 10;
792 pcclip.bottom -= GetSystemMetrics(SM_CXFIXEDFRAME) + 10;
793 ClipCursor(&pcclip);
794 }
795 break;
797 case WM_TIMER:
798 if (wParam == TIMER_1SEC)
799 onesec();
800 break;
802 case WM_RESETD3D:
803 startblit();
804 if (video_fullscreen)
805 d3d_fs_reset();
806 else
807 d3d_reset();
808 endblit();
809 break;
811 case WM_LEAVEFULLSCREEN:
812 startblit();
813 mouse_close();
814 vid_apis[1][vid_api].close();
815 video_fullscreen = 0;
816 vid_apis[0][vid_api].init(ghwnd);
817 mouse_init();
818 endblit();
819 device_force_redraw();
820 break;
822 case WM_KEYDOWN:
823 case WM_SYSKEYDOWN:
824 case WM_KEYUP:
825 case WM_SYSKEYUP:
826 // if (mousecapture)
827 return 0;
828 // return DefWindowProc (hwnd, message, wParam, lParam);
831 case WM_DESTROY:
832 UnhookWindowsHookEx( hKeyboardHook );
833 KillTimer(hwnd, TIMER_1SEC);
834 PostQuitMessage (0); /* send a WM_QUIT to the message queue */
835 break;
837 case WM_SYSCOMMAND:
838 if (wParam == SC_KEYMENU && HIWORD(lParam) <= 0 && (video_fullscreen || mousecapture))
839 return 0; /*disable ALT key for menu*/
841 default:
842 // pclog("Def %08X %i\n",message,message);
843 return DefWindowProc (hwnd, message, wParam, lParam);
844 }
845 return 0;
846 }
848 LRESULT CALLBACK subWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
849 {
850 switch (message)
851 {
852 default:
853 return DefWindowProc(hwnd, message, wParam, lParam);
854 }
855 return 0;
856 }