|
|
1.1 root 1: /*
2: * UAE - The Un*x Amiga Emulator
3: *
4: * Win32 interface
5: *
1.1.1.4 root 6: * Copyright 1997-1998 Mathias Ortmann
7: * Copyright 1997-1999 Brian King
1.1 root 8: */
9:
1.1.1.4 root 10: /* Uncomment this line if you want the logs time-stamped */
11: /* #define TIMESTAMP_LOGS */
12:
1.1.1.2 root 13: #include "config.h"
14: #include "sysconfig.h"
15:
1.1 root 16: #include <stdlib.h>
17: #include <stdarg.h>
1.1.1.2 root 18: #include <signal.h>
19:
20: #include <windows.h>
1.1 root 21: #include <commctrl.h>
22: #include <commdlg.h>
1.1.1.4 root 23: #include <shellapi.h>
24: #include <zmouse.h>
25: #include <ddraw.h>
26: #include <dbt.h>
27: #include <math.h>
1.1 root 28:
29: #include "sysdeps.h"
30: #include "options.h"
31: #include "gensound.h"
32: #include "sounddep/sound.h"
33: #include "uae.h"
34: #include "memory.h"
35: #include "custom.h"
36: #include "events.h"
37: #include "xwin.h"
38: #include "keyboard.h"
1.1.1.4 root 39: #include "keybuf.h"
40: #include "drawing.h"
1.1 root 41: #include "picasso96.h"
1.1.1.4 root 42: #include "bsdsocket.h"
1.1.1.2 root 43: #include "osdep/win32.h"
1.1.1.4 root 44: #include "osdep/win32gfx.h"
1.1 root 45: #include "osdep/win32gui.h"
1.1.1.4 root 46: #include "osdep/dxwrap.h"
47: #include "autoconf.h"
48: #include "gui.h"
49: #include "newcpu.h"
50: extern void WIN32GFX_WindowMove ( void );
51: extern void WIN32GFX_WindowSize ( void );
52: unsigned long *win32_stackbase;
53: unsigned long *win32_freestack[42]; //EXTRA_STACK_SIZE
1.1 root 54:
1.1.1.4 root 55: /* Comment out the following line if you don't want ZLIB.DLL support */
56: #undef USE_ZLIB_DLL
1.1.1.2 root 57:
1.1.1.4 root 58: #ifdef USE_ZLIB_DLL
59: #include "zlib.h"
60: #endif
1.1.1.2 root 61:
1.1.1.4 root 62: int useqpc = 0; /* Set to TRUE to use the QueryPerformanceCounter() function instead of rdtsc() */
1.1.1.2 root 63:
1.1.1.4 root 64: static FILE *debugfile = NULL;
1.1 root 65:
1.1.1.4 root 66: HINSTANCE hInst = NULL;
67: HMODULE hUIDLL = NULL;
1.1 root 68:
1.1.1.4 root 69: HWND (WINAPI *pHtmlHelp)(HWND, LPCSTR, UINT, LPDWORD ) = NULL;
1.1 root 70:
1.1.1.4 root 71: HWND hAmigaWnd, hMainWnd;
72: /*DWORD Keys; */
73: RECT amigawin_rect;
1.1 root 74:
1.1.1.2 root 75: char VersionStr[256];
1.1 root 76:
1.1.1.4 root 77: int in_sizemove = 0;
78: int manual_painting_needed = 0;
1.1.1.2 root 79: int customsize = 0;
1.1 root 80:
81: int bActive;
82: int toggle_sound;
83:
84: BOOL viewing_child = FALSE;
85:
1.1.1.4 root 86: HKEY hWinUAEKey = NULL;
87: COLORREF g_dwBackgroundColor = RGB(10, 0, 10);
1.1 root 88:
89: /* Keyboard emulation, Win32 helper routines. */
90: static LPARAM keysdown[256];
91: static short numkeysdown;
92: int checkkey (int vkey, LPARAM lParam)
93: {
94: switch (vkey) {
1.1.1.4 root 95: case VK_LWIN:
96: case VK_RWIN:
1.1.1.2 root 97: case VK_SHIFT:
98: case VK_LSHIFT:
99: case VK_RSHIFT:
100: case VK_CONTROL:
101: case VK_LCONTROL:
102: case VK_RCONTROL:
103: case VK_MENU:
104: case VK_LMENU:
105: case VK_RMENU:
1.1 root 106: return GetKeyState (vkey) & 0x8000;
107: }
108: return GetAsyncKeyState (vkey) & 0x8000;
109: }
110:
111: /* Mouse emulation, Win32 interface */
112: static int mousecx = 160, mousecy = 100, mousedx = 160, mousedy = 100;
113: static int mousecl = MAKELONG (160, 100);
114: int mouseactive;
115:
1.1.1.4 root 116: void WIN32_MouseDefaults( void )
117: {
118: mousecx = 160, mousecy = 100, mousedx = 160, mousedy = 100, mousecl = MAKELONG (160, 100);
119: }
120:
1.1 root 121: void setmouseactive (int active)
122: {
123: mousedx = (amigawin_rect.right - amigawin_rect.left) / 2;
124: mousedy = (amigawin_rect.bottom - amigawin_rect.top) / 2;
125: mousecl = MAKELONG (mousedx, mousedy);
126: mousecx = amigawin_rect.left + mousedx;
127: mousecy = amigawin_rect.top + mousedy;
128:
129: if (active == mouseactive)
130: return;
131: mouseactive = active;
132:
1.1.1.4 root 133: if (active)
134: {
135: #ifdef HARDWARE_SPRITE_EMULATION
136: if( !WIN32GFX_IsPicassoScreen() )
137: #endif
138: {
139: ShowCursor (FALSE);
140: SetCursorPos (mousecx, mousecy);
141: }
142: SetWindowText (hMainWnd ? hMainWnd : hAmigaWnd, "UAE/Win32 - [Mouse active - press Alt-Tab to cancel]");
1.1 root 143: ClipCursor (&amigawin_rect);
1.1.1.4 root 144: }
145: else
146: {
1.1 root 147: ShowCursor (TRUE);
1.1.1.4 root 148: SetWindowText (hMainWnd ? hMainWnd : hAmigaWnd, "UAE/Win32" );
1.1 root 149: ClipCursor (NULL);
150: }
151: }
152:
153: static int hascapture = 0;
154:
1.1.1.2 root 155: static void setcapture (void)
1.1 root 156: {
157: if (hascapture)
158: return;
159: hascapture++;
160: SetCapture (hAmigaWnd);
161: }
162:
1.1.1.4 root 163: void releasecapture (void)
1.1 root 164: {
165: if (!hascapture)
166: return;
167: hascapture--;
168: ReleaseCapture ();
169: }
170:
1.1.1.4 root 171: frame_time_t read_processor_time_cyrix (void)
1.1.1.2 root 172: {
1.1.1.4 root 173: LARGE_INTEGER counter;
174: QueryPerformanceCounter( &counter );
175: return (frame_time_t)(counter.LowPart);
1.1.1.2 root 176: }
177:
1.1.1.4 root 178: #include <setjmp.h>
179: jmp_buf catch_test;
180:
181: static RETSIGTYPE illhandler(int foo)
1.1 root 182: {
1.1.1.4 root 183: rpt_available = 0;
184: longjmp(catch_test,1);
185: }
1.1 root 186:
1.1.1.4 root 187: int have_rdtsc (void)
188: {
1.1.1.2 root 189: rpt_available = 1;
1.1.1.4 root 190: write_log ("Testing the RDTSC instruction ... ");
1.1.1.2 root 191: signal (SIGILL, illhandler);
1.1.1.4 root 192: if (setjmp (catch_test) == 0)
193: read_processor_time ();
1.1.1.2 root 194: signal (SIGILL, SIG_DFL);
1.1.1.4 root 195: write_log ("done.\n");
1.1.1.2 root 196: if (! rpt_available) {
1.1.1.4 root 197: write_log ("Your processor does not support the RDTSC instruction.\n");
1.1 root 198: return 0;
199: }
200: return 1;
201: }
202:
1.1.1.4 root 203: static void figure_processor_speed (void)
1.1 root 204: {
1.1.1.4 root 205: extern volatile frame_time_t vsynctime;
206: extern unsigned long syncbase;
207: frame_time_t clockrate;
208:
209: #if defined __GNUC__
210: if (! have_rdtsc ())
211: useqpc = 1;
1.1.1.2 root 212: #else
1.1.1.4 root 213: LARGE_INTEGER freq;
1.1.1.2 root 214:
1.1.1.4 root 215: __try
216: {
217: __asm{rdtsc};
1.1.1.2 root 218: }
1.1.1.4 root 219: __except( GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION )
220: {
221: useqpc = 1;
1.1.1.2 root 222: }
1.1.1.4 root 223: if( QueryPerformanceFrequency( &freq ) )
224: {
225: if (freq.LowPart > 90000000) /* looks like CPU freq. */
226: write_log( "CLOCKFREQ: QueryPerformanceFrequency() reports %d-MHz\n", freq.LowPart / 1000000 );
227: else
228: write_log( "CLOCKFREQ: QueryPerformanceFrequency() reports %.2f-MHz\n", (float)freq.LowPart / 1000000.0f );
1.1 root 229:
1.1.1.4 root 230: if( freq.LowPart < 1000000 )
231: {
232: write_log( "CLOCKFREQ: Weird value. Using QueryPerformanceCounter() instead of RDTSC.\n" );
233: useqpc = 1;
1.1 root 234: }
1.1.1.4 root 235: rpt_available = 1;
1.1.1.2 root 236: }
1.1.1.4 root 237: else
238: {
239: write_log( "CLOCKFREQ: No support for clock-rate stuff!\n" );
240: rpt_available = 0;
1.1 root 241: }
1.1.1.4 root 242: #endif
243: SetPriorityClass( GetCurrentProcess(), REALTIME_PRIORITY_CLASS );
244: clockrate = read_processor_time();
245: Sleep( 1000 );
246: clockrate = read_processor_time() - clockrate;
247: SetPriorityClass( GetCurrentProcess(), NORMAL_PRIORITY_CLASS );
248:
249: write_log( "CLOCKFREQ: Measured as %d-MHz\n", clockrate / 1000000 );
250: syncbase = clockrate;
251: vsynctime = syncbase / VBLANK_HZ_PAL; /* default to 50Hz */
1.1 root 252: }
253:
1.1.1.4 root 254: static BOOL bDiskChanged = FALSE;
1.1 root 255:
1.1.1.2 root 256: static long FAR PASCAL AmigaWindowProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1.1 root 257: {
258: PAINTSTRUCT ps;
259: HDC hDC;
1.1.1.4 root 260: short wheeldelta;
261: static int store_xy = 0;
262: BOOL minimized;
263: LPMINMAXINFO lpmmi;
264: RECT rect;
1.1 root 265:
1.1.1.4 root 266: switch( message )
267: {
268: case WM_PALETTECHANGED:
269: if( (HWND)wParam != hWnd )
270: {
271: write_log( "WM_PALETTECHANGED Request\n" );
272: WIN32GFX_PaletteChange();
273: }
274: break;
275: case WM_ACTIVATEAPP:
276: if (bActive = wParam)
277: {
278: if( WIN32GFX_IsFullScreen() )
279: {
280: SetCursor (NULL);
281: #ifndef HARDWARE_SPRITE_EMULATION
282: SetCursorPos (mousecx, mousecy);
283: #else
284: if( !WIN32GFX_IsPicassoScreen() )
285: SetCursorPos (mousecx, mousecy);
286: #endif
287: }
288: my_kbd_handler (VK_CAPITAL, 0x3a, TRUE);
1.1 root 289: }
1.1.1.4 root 290: else
291: {
292: if( !WIN32GFX_IsFullScreen() )
293: setmouseactive (0);
294: else
295: {
296: if( WIN32GFX_IsPicassoScreen() )
297: {
298: WIN32GFX_DisablePicasso();
299: }
300: }
301: }
302: break;
303: case WM_ACTIVATE:
304: minimized = HIWORD( wParam );
305: if (LOWORD (wParam) != WA_INACTIVE)
306: {
307: write_log( "WinUAE now active via WM_ACTIVATE\n" );
308: if( !minimized )
309: {
1.1.1.5 ! root 310: if( currprefs.win32_iconified_nospeed )
! 311: {
! 312: SetPriorityClass( GetCurrentProcess(), NORMAL_PRIORITY_CLASS );
! 313: }
! 314: if( currprefs.win32_iconified_nosound )
! 315: {
! 316: resume_sound();
! 317: }
! 318:
1.1.1.4 root 319: clear_inhibit_frame( IHF_WINDOWHIDDEN );
320: }
321: ShowWindow (hWnd, SW_RESTORE);
322: if( WIN32GFX_IsPicassoScreen() )
323: {
324: WIN32GFX_EnablePicasso();
325: }
326: }
327: else
328: {
329: write_log( "WinUAE now inactive via WM_ACTIVATE\n" );
330: if( minimized && !quit_program )
331: {
1.1.1.5 ! root 332: if( currprefs.win32_iconified_nospeed )
! 333: {
! 334: SetPriorityClass( GetCurrentProcess(), IDLE_PRIORITY_CLASS );
! 335: }
! 336: if( currprefs.win32_iconified_nosound )
! 337: {
! 338: pause_sound ();
! 339: }
1.1.1.4 root 340: set_inhibit_frame( IHF_WINDOWHIDDEN );
341: }
342: }
343: break;
1.1 root 344:
1.1.1.4 root 345: case WM_SETCURSOR:
346: if( WIN32GFX_IsFullScreen() )
347: {
348: #ifdef HARDWARE_SPRITE_EMULATION
349: if( !WIN32GFX_IsPicassoScreen() )
350: #endif
351: SetCursor (NULL);
352: return TRUE;
353: }
354: break;
1.1 root 355:
1.1.1.4 root 356: case WM_SYSCOMMAND:
357: switch( wParam & 0xFFF0 )
358: {
359: case SC_MAXIMIZE:
360: WIN32GFX_ToggleFullScreen();
361: return 0;
362: break;
363: case SC_MINIMIZE:
364: WIN32GFX_DisablePicasso();
365: break;
366: }
367: break;
1.1 root 368:
1.1.1.4 root 369: case WM_KEYUP:
370: case WM_SYSKEYUP:
371: numkeysdown--;
372: keysdown[wParam] = 0;
373: my_kbd_handler (wParam, (lParam >> 16) & 0x1ff, FALSE);
374: return 0;
375: break;
1.1 root 376:
1.1.1.2 root 377: case WM_KEYDOWN:
378: case WM_SYSKEYDOWN:
1.1.1.4 root 379: if (LOWORD (lParam) == 1)
380: {
381: if (numkeysdown)
382: {
383: int key;
384: numkeysdown = 0;
385:
386: for (key = 256; key--;)
387: {
388: if (keysdown[key])
389: {
390: if (checkkey (key, lParam))
391: numkeysdown++;
392: else
393: {
394: my_kbd_handler (key, (keysdown[key] >> 16) & 0x1ff, FALSE);
395: keysdown[key] = 0;
396: }
397: }
1.1 root 398: }
399: }
1.1.1.4 root 400: if (!keysdown[wParam])
401: {
402: keysdown[wParam] = lParam;
403: numkeysdown++;
1.1 root 404: }
405: numkeysdown++;
406: my_kbd_handler (wParam, (lParam >> 16) & 0x1ff, TRUE);
407: }
408: break;
409:
1.1.1.4 root 410: case WM_LBUTTONDBLCLK: // According to MSDN, having CS_DBLCLKS in your window-class
411: // means that the sequence is WM_LBUTTONDOWN, WM_LBUTTONUP,
412: // WM_LBUTTONDBLCLK, and WM_LBUTTONUP.
413: // So we need to make WM_LBUTTONDBLCLK act like WM_LBUTTONDOWN.
1.1.1.2 root 414: case WM_LBUTTONDOWN:
1.1 root 415: if (ievent_alive) {
416: setcapture ();
417: buttonstate[0] = 1;
1.1.1.4 root 418: } else if (!WIN32GFX_IsFullScreen() && !mouseactive)
1.1 root 419: setmouseactive (1);
420: else
421: buttonstate[0] = 1;
422: break;
423:
1.1.1.2 root 424: case WM_LBUTTONUP:
1.1 root 425: releasecapture ();
426: buttonstate[0] = 0;
427: break;
428:
1.1.1.4 root 429:
1.1.1.2 root 430: case WM_MBUTTONDOWN:
1.1 root 431: if (ievent_alive)
432: setcapture ();
433: buttonstate[1] = 1;
434: break;
435:
1.1.1.2 root 436: case WM_MBUTTONUP:
1.1 root 437: releasecapture ();
438: buttonstate[1] = 0;
439: break;
440:
1.1.1.2 root 441: case WM_RBUTTONDOWN:
1.1 root 442: if (ievent_alive)
443: setcapture ();
444: buttonstate[2] = 1;
445: break;
446:
1.1.1.2 root 447: case WM_RBUTTONUP:
1.1 root 448: releasecapture ();
449: buttonstate[2] = 0;
450: break;
451:
1.1.1.4 root 452: case WM_VSCROLL:
453: write_log( "WM_VSCROLL\n" );
454: if( LOWORD( wParam ) == SB_LINEDOWN )
455: record_key(0x7A<<1);
456: else if( LOWORD( wParam ) == SB_LINEUP )
457: record_key(0x7B<<1);
458: break;
459:
460: case WM_MOUSEWHEEL:
461: wheeldelta = HIWORD(wParam);
462: write_log( "WM_MOUSEWHEEL with delta %d\n", wheeldelta );
463: if( wheeldelta > 0 )
464: record_key(0x7A<<1);
465: else if( wheeldelta < 0 )
466: record_key(0x7B<<1);
467: break;
1.1 root 468:
1.1.1.4 root 469: case WM_MOUSEMOVE:
470: #ifndef HARDWARE_SPRITE_EMULATION
471: if( ( mouseactive && !ievent_alive ) ||
472: WIN32GFX_IsFullScreen() )
473: #else
474: if( ( ( mouseactive && !ievent_alive ) || WIN32GFX_IsFullScreen() ) &&
475: !WIN32GFX_IsPicassoScreen() )
476: #endif
477: {
478: /*
479: * In this mode, the mouse pointer is always centered in the window,
480: * this is ensured by the SetCursorPos call below.
481: * We don't want to handle messages that result from such a SetCursorPos
482: * call (recursion!), so exit early if we see one.
483: */
484: if (lParam == mousecl)
485: break;
486: lastmx += (signed short) LOWORD (lParam) - mousedx;
487: lastmy += (signed short) HIWORD (lParam) - mousedy;
488: if (ievent_alive)
489: {
490: if (lastmx < 0)
491: lastmx = 0;
492: if (lastmx > WIN32GFX_GetWidth() )
493: lastmx = WIN32GFX_GetWidth();
494: if (lastmy < 0)
495: lastmy = 0;
496: if (lastmy > WIN32GFX_GetHeight() )
497: lastmy = WIN32GFX_GetHeight();
498: }
499: SetCursorPos (mousecx, mousecy);
500: break;
1.1 root 501: }
502: lastmx = (signed short) LOWORD (lParam);
503: lastmy = (signed short) HIWORD (lParam);
1.1.1.4 root 504: break;
1.1 root 505:
1.1.1.2 root 506: case WM_PAINT:
507: notice_screen_contents_lost ();
1.1.1.4 root 508:
509: hDC = BeginPaint (hWnd, &ps);
510: /* Check to see if this WM_PAINT is coming while we've got the GUI visible */
511: if( manual_painting_needed )
512: {
513: /* Update the display area */
514: if( !WIN32GFX_IsFullScreen() )
515: {
516: if( DirectDraw_GetLockableType() != overlay_surface )
517: DX_Blit( 0, 0, 0, 0, WIN32GFX_GetWidth(), WIN32GFX_GetHeight(), BLIT_SRC );
518: }
519: else
520: {
521: DirectDraw_Blt( primary_surface, NULL, secondary_surface, NULL, DDBLT_WAIT, NULL );
522: }
523: }
524: EndPaint (hWnd, &ps);
525:
1.1 root 526: break;
527:
1.1.1.2 root 528: case WM_DROPFILES:
1.1 root 529: if (DragQueryFile ((HDROP) wParam, (UINT) - 1, NULL, 0)) {
530: if (DragQueryFile ((HDROP) wParam, 0, NULL, 0) < 255)
531: DragQueryFile ((HDROP) wParam, 0, changed_prefs.df[0], sizeof (changed_prefs.df[0]));
532: }
533: DragFinish ((HDROP) wParam);
534: break;
535:
1.1.1.2 root 536: case WM_CAPTURECHANGED:
537: if ((HWND)lParam != hAmigaWnd)
1.1 root 538: buttonstate[0] = buttonstate[1] = buttonstate[2] = 0;
539: break;
540:
1.1.1.2 root 541: case WM_TIMER:
542: finishjob ();
1.1 root 543: break;
544:
1.1.1.2 root 545: case WM_CREATE:
1.1 root 546: DragAcceptFiles (hWnd, TRUE);
547: break;
548:
1.1.1.2 root 549: case WM_CLOSE:
550: uae_quit ();
551: return 0;
552:
553: case WM_WINDOWPOSCHANGED:
1.1.1.4 root 554: if( GetWindowRect( hWnd, &amigawin_rect) )
555: {
556: if( hMainWnd )
557: {
558: if( hWinUAEKey && store_xy++)
559: {
560: RegSetValueEx( hWinUAEKey, "xPos", 0, REG_DWORD, (LPBYTE)&amigawin_rect.left, sizeof( LONG ) );
561: RegSetValueEx( hWinUAEKey, "yPos", 0, REG_DWORD, (LPBYTE)&amigawin_rect.top, sizeof( LONG ) );
562: }
563: }
564: }
1.1 root 565: break;
1.1.1.4 root 566:
567: case WM_MOVING:
568: case WM_MOVE:
569: WIN32GFX_WindowMove();
570: return TRUE;
571:
572: case WM_SIZING:
573: WIN32GFX_WindowSize();
574: return TRUE;
575: case WM_SIZE:
576: WIN32GFX_WindowSize();
577: return 0;
578:
579: case WM_GETMINMAXINFO:
580: rect.left=0;
581: rect.top=0;
582: lpmmi=(LPMINMAXINFO)lParam;
583: rect.right=320;
584: rect.bottom=256;
585: //AdjustWindowRectEx(&rect,WSTYLE,0,0);
586: lpmmi->ptMinTrackSize.x=rect.right-rect.left;
587: lpmmi->ptMinTrackSize.y=rect.bottom-rect.top;
588: return 0;
589:
590: default:
591: #if 0
592: #ifdef BSDSOCKET_SUPPORTED
593: if( message >= 0xB000 && message < 0xB000+MAXPENDINGASYNC*2 )
594: {
595: #if DEBUG_SOCKETS
596: write_log( "sockmsg(0x%x, 0x%x, 0x%x)\n", message, wParam, lParam );
597: #endif
598: sockmsg( message, wParam, lParam );
599: return 0;
600: }
601: #endif
602: #endif
603: break;
1.1 root 604: }
605:
606: return DefWindowProc (hWnd, message, wParam, lParam);
607: }
608:
1.1.1.2 root 609: static long FAR PASCAL MainWindowProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1.1 root 610: {
611: PAINTSTRUCT ps;
1.1.1.2 root 612: RECT rc;
1.1 root 613: HDC hDC;
614:
615: switch (message) {
616: case WM_LBUTTONDOWN:
1.1.1.4 root 617: case WM_MOUSEWHEEL:
1.1 root 618: case WM_MOUSEMOVE:
619: case WM_ACTIVATEAPP:
1.1.1.4 root 620: case WM_DROPFILES:
1.1 root 621: case WM_ACTIVATE:
622: case WM_SETCURSOR:
623: case WM_SYSCOMMAND:
624: case WM_KEYUP:
625: case WM_SYSKEYUP:
626: case WM_KEYDOWN:
627: case WM_SYSKEYDOWN:
628: case WM_LBUTTONUP:
629: case WM_MBUTTONDOWN:
630: case WM_MBUTTONUP:
631: case WM_RBUTTONDOWN:
632: case WM_RBUTTONUP:
1.1.1.4 root 633: case WM_MOVING:
634: case WM_MOVE:
635: case WM_SIZING:
636: case WM_SIZE:
637: case WM_GETMINMAXINFO:
1.1 root 638: case WM_CREATE:
639: case WM_DESTROY:
640: case WM_USER + 0x200:
1.1.1.2 root 641: case WM_CLOSE:
1.1.1.4 root 642: case WM_HELP:
643: case WM_DEVICECHANGE:
1.1 root 644: return AmigaWindowProc (hWnd, message, wParam, lParam);
645:
646: case WM_DISPLAYCHANGE:
1.1.1.4 root 647: if (!WIN32GFX_IsFullScreen && (wParam + 7) / 8 != DirectDraw_GetBytesPerPixel() )
648: WIN32GFX_DisplayChangeRequested();
1.1 root 649: break;
1.1.1.4 root 650:
1.1 root 651: case WM_ENTERSIZEMOVE:
1.1.1.2 root 652: in_sizemove++;
1.1 root 653: break;
654:
655: case WM_EXITSIZEMOVE:
1.1.1.2 root 656: in_sizemove--;
1.1 root 657: /* fall through */
658:
659: case WM_WINDOWPOSCHANGED:
1.1.1.4 root 660: WIN32GFX_WindowMove();
661: if( hAmigaWnd && GetWindowRect (hAmigaWnd, &amigawin_rect) )
662: {
663: if (in_sizemove > 0)
664: break;
1.1.1.2 root 665:
1.1.1.4 root 666: if( !WIN32GFX_IsFullScreen() && hAmigaWnd )
667: {
668: if( amigawin_rect.left & 3 )
669: {
670: RECT rc2;
671: if( GetWindowRect( hMainWnd, &rc2 ) )
672: {
673: MoveWindow (hMainWnd, rc2.left + 4 - amigawin_rect.left % 4, rc2.top,
674: rc2.right - rc2.left, rc2.bottom - rc2.top, TRUE);
675: }
1.1 root 676: }
1.1.1.4 root 677: //setmouseactive (0);
678: return 0;
1.1 root 679: }
680: }
681: break;
682:
683: case WM_PAINT:
684: hDC = BeginPaint (hWnd, &ps);
685: GetClientRect (hWnd, &rc);
686: DrawEdge (hDC, &rc, EDGE_SUNKEN, BF_RECT);
687: EndPaint (hWnd, &ps);
688: break;
689: case WM_NCLBUTTONDBLCLK:
690: if (wParam == HTCAPTION) {
1.1.1.4 root 691: WIN32GFX_ToggleFullScreen();
1.1 root 692: return 0;
693: }
1.1.1.2 root 694: break;
1.1.1.4 root 695: default:
696: break;
697:
1.1 root 698: }
699:
700: return DefWindowProc (hWnd, message, wParam, lParam);
701: }
702:
1.1.1.4 root 703: void handle_events (void)
1.1 root 704: {
1.1.1.4 root 705: MSG msg;
1.1 root 706:
1.1.1.4 root 707: while (PeekMessage (&msg, 0, 0, 0, PM_REMOVE)) {
708: TranslateMessage (&msg);
709: DispatchMessage (&msg);
1.1 root 710: }
711: }
712:
1.1.1.4 root 713: /* Console Win32 helper routines */
714: void activate_debugger ();
715:
716: /* We're not a console-app anymore! */
1.1 root 717: void setup_brkhandler (void)
718: {
719: }
720:
721: void remove_brkhandler (void)
722: {
723: }
724:
1.1.1.4 root 725: int WIN32_RegisterClasses( void )
1.1 root 726: {
727: WNDCLASS wc;
1.1.1.4 root 728: HDC hDC = GetDC( NULL );
729:
730: if( GetDeviceCaps( hDC, NUMCOLORS ) != -1 )
731: g_dwBackgroundColor = RGB( 255, 0, 255 );
732: ReleaseDC( NULL, hDC );
1.1 root 733:
1.1.1.4 root 734: wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_DBLCLKS;
1.1 root 735: wc.lpfnWndProc = AmigaWindowProc;
736: wc.cbClsExtra = 0;
737: wc.cbWndExtra = 0;
738: wc.hInstance = 0;
1.1.1.4 root 739: wc.hIcon = LoadIcon (GetModuleHandle (NULL), MAKEINTRESOURCE( IDI_APPICON ) );
1.1 root 740: wc.hCursor = LoadCursor (NULL, IDC_ARROW);
1.1.1.2 root 741: wc.lpszMenuName = 0;
1.1 root 742: wc.lpszClassName = "AmigaPowah";
1.1.1.4 root 743: wc.hbrBackground = CreateSolidBrush( g_dwBackgroundColor );
1.1 root 744: if (!RegisterClass (&wc))
745: return 0;
746:
1.1.1.4 root 747: wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
1.1 root 748: wc.lpfnWndProc = MainWindowProc;
749: wc.cbClsExtra = 0;
750: wc.cbWndExtra = 0;
751: wc.hInstance = 0;
1.1.1.4 root 752: wc.hIcon = LoadIcon (GetModuleHandle (NULL), MAKEINTRESOURCE( IDI_APPICON ) );
1.1 root 753: wc.hCursor = LoadCursor (NULL, IDC_ARROW);
1.1.1.4 root 754: wc.hbrBackground = CreateSolidBrush( g_dwBackgroundColor );
1.1.1.2 root 755: wc.lpszMenuName = 0;
1.1 root 756: wc.lpszClassName = "PCsuxRox";
757: if (!RegisterClass (&wc))
758: return 0;
759: return 1;
760: }
761:
1.1.1.4 root 762: #ifdef __GNUC__
763: #undef WINAPI
764: #define WINAPI
765: #endif
1.1.1.2 root 766:
1.1.1.4 root 767: static HINSTANCE hRichEdit = NULL, hHtmlHelp = NULL;
1.1 root 768:
1.1.1.4 root 769: #ifdef USE_ZLIB_DLL
770: static HINSTANCE hZlib = NULL;
771: FARPROC pgzread = NULL, pgzopen = NULL, pgzclose = NULL, pgzwrite = NULL, pgzerror = NULL;
772: #endif
1.1.1.2 root 773:
1.1.1.4 root 774: int WIN32_CleanupLibraries( void )
1.1.1.2 root 775: {
1.1.1.4 root 776: if (hRichEdit)
777: FreeLibrary (hRichEdit);
778:
779: if( hHtmlHelp )
780: FreeLibrary( hHtmlHelp );
1.1.1.2 root 781:
1.1.1.4 root 782: if( hUIDLL )
783: FreeLibrary( hUIDLL );
1.1.1.2 root 784:
1.1.1.4 root 785: #ifdef USE_ZLIB_DLL
786: if( hZlib )
787: FreeLibrary( hZlib );
788: #endif
1.1 root 789:
1.1.1.4 root 790: return 1;
791: }
1.1 root 792:
1.1.1.4 root 793: /* HtmlHelp Initialization - optional component */
794: int WIN32_InitHtmlHelp( void )
795: {
796: int result = 0;
797: if( hHtmlHelp = LoadLibrary( "HHCTRL.OCX" ) )
798: {
799: pHtmlHelp = ( HWND(WINAPI *)(HWND, LPCSTR, UINT, LPDWORD ) )GetProcAddress( hHtmlHelp, "HtmlHelpA" );
800: result = 1;
1.1 root 801: }
802:
803:
1.1.1.4 root 804: return result;
1.1 root 805: }
806:
1.1.1.4 root 807: #if 0
808: #define TESTING_LANGUAGES
809: #define TEST_LANGID LANG_GERMAN
810: //#define TEST_LANGID LANG_FRENCH
811: //#define TEST_LANGID LANG_TURKISH
812: #endif
1.1.1.2 root 813:
1.1.1.4 root 814: static HMODULE LoadGUI( void )
1.1 root 815: {
1.1.1.4 root 816: HMODULE result = NULL;
817: LPCTSTR dllname = NULL;
818: LANGID language = GetUserDefaultLangID() & 0x3FF; // low 9-bits form the primary-language ID
819: #ifdef TESTING_LANGUAGES
820: language = TEST_LANGID;
821: #endif
1.1 root 822:
1.1.1.4 root 823: switch( language )
824: {
825: case LANG_AFRIKAANS:
826: dllname = "WinUAE_Afrikaans.dll";
1.1 root 827: break;
1.1.1.4 root 828: case LANG_ARABIC:
829: dllname = "WinUAE_Arabic.dll";
1.1 root 830: break;
1.1.1.4 root 831: case LANG_ARMENIAN:
832: dllname = "WinUAE_Armenian.dll";
833: break;
834: case LANG_ASSAMESE:
835: dllname = "WinUAE_Assamese.dll";
836: break;
837: case LANG_AZERI:
838: dllname = "WinUAE_Azeri.dll";
839: break;
840: case LANG_BASQUE:
841: dllname = "WinUAE_Basque.dll";
842: break;
843: case LANG_BELARUSIAN:
844: dllname = "WinUAE_Belarusian.dll";
845: break;
846: case LANG_BENGALI:
847: dllname = "WinUAE_Bengali.dll";
848: break;
849: case LANG_BULGARIAN:
850: dllname = "WinUAE_Bulgarian.dll";
851: break;
852: case LANG_CATALAN:
853: dllname = "WinUAE_Catalan.dll";
854: break;
855: case LANG_CHINESE:
856: dllname = "WinUAE_Chinese.dll";
857: break;
858: case LANG_CROATIAN:
859: dllname = "WinUAE_CroatianSerbian.dll";
860: break;
861: case LANG_CZECH:
862: dllname = "WinUAE_Czech.dll";
863: break;
864: case LANG_DANISH:
865: dllname = "WinUAE_Danish.dll";
866: break;
867: case LANG_DUTCH:
868: dllname = "WinUAE_Dutch.dll";
869: break;
870: case LANG_ESTONIAN:
871: dllname = "WinUAE_Estonian.dll";
872: break;
873: case LANG_FAEROESE:
874: dllname = "WinUAE_Faeroese.dll";
875: break;
876: case LANG_FARSI:
877: dllname = "WinUAE_Farsi.dll";
878: break;
879: case LANG_FINNISH:
880: dllname = "WinUAE_Finnish.dll";
881: break;
882: case LANG_FRENCH:
883: dllname = "WinUAE_French.dll";
884: break;
885: case LANG_GEORGIAN:
886: dllname = "WinUAE_Georgian.dll";
887: break;
888: case LANG_GERMAN:
889: dllname = "WinUAE_German.dll";
890: break;
891: case LANG_GREEK:
892: dllname = "WinUAE_Greek.dll";
893: break;
894: case LANG_GUJARATI:
895: dllname = "WinUAE_Gujarati.dll";
896: break;
897: case LANG_HEBREW:
898: dllname = "WinUAE_Hebrew.dll";
899: break;
900: case LANG_HINDI:
901: dllname = "WinUAE_Hindi.dll";
902: break;
903: case LANG_HUNGARIAN:
904: dllname = "WinUAE_Hungarian.dll";
905: break;
906: case LANG_ICELANDIC:
907: dllname = "WinUAE_Icelandic.dll";
908: break;
909: case LANG_INDONESIAN:
910: dllname = "WinUAE_Indonesian.dll";
911: break;
912: case LANG_ITALIAN:
913: dllname = "WinUAE_Italian.dll";
914: break;
915: case LANG_JAPANESE:
916: dllname = "WinUAE_Japanese.dll";
917: break;
918: case LANG_KANNADA:
919: dllname = "WinUAE_Kannada.dll";
920: break;
921: case LANG_KASHMIRI:
922: dllname = "WinUAE_Kashmiri.dll";
923: break;
924: case LANG_KAZAK:
925: dllname = "WinUAE_Kazak.dll";
926: break;
927: case LANG_KONKANI:
928: dllname = "WinUAE_Konkani.dll";
929: break;
930: case LANG_KOREAN:
931: dllname = "WinUAE_Korean.dll";
932: break;
933: case LANG_LATVIAN:
934: dllname = "WinUAE_Latvian.dll";
935: break;
936: case LANG_LITHUANIAN:
937: dllname = "WinUAE_Lithuanian.dll";
938: break;
939: case LANG_MACEDONIAN:
940: dllname = "WinUAE_Macedonian.dll";
941: break;
942: case LANG_MALAY:
943: dllname = "WinUAE_Malay.dll";
944: break;
945: case LANG_MALAYALAM:
946: dllname = "WinUAE_Malayalam.dll";
947: break;
948: case LANG_MANIPURI:
949: dllname = "WinUAE_Manipuri.dll";
950: break;
951: case LANG_MARATHI:
952: dllname = "WinUAE_Marathi.dll";
953: break;
954: case LANG_NEPALI:
955: dllname = "WinUAE_Nepali.dll";
956: break;
957: case LANG_NORWEGIAN:
958: dllname = "WinUAE_Norwegian.dll";
959: break;
960: case LANG_ORIYA:
961: dllname = "WinUAE_Oriya.dll";
962: break;
963: case LANG_POLISH:
964: dllname = "WinUAE_Polish.dll";
965: break;
966: case LANG_PORTUGUESE:
967: dllname = "WinUAE_Portuguese.dll";
968: break;
969: case LANG_PUNJABI:
970: dllname = "WinUAE_Punjabi.dll";
971: break;
972: case LANG_ROMANIAN:
973: dllname = "WinUAE_Romanian.dll";
974: break;
975: case LANG_RUSSIAN:
976: dllname = "WinUAE_Russian.dll";
977: break;
978: case LANG_SANSKRIT:
979: dllname = "WinUAE_Sanskrit.dll";
980: break;
981: case LANG_SINDHI:
982: dllname = "WinUAE_Sindhi.dll";
983: break;
984: case LANG_SLOVAK:
985: dllname = "WinUAE_Slovak.dll";
986: break;
987: case LANG_SLOVENIAN:
988: dllname = "WinUAE_Slovenian.dll";
989: break;
990: case LANG_SPANISH:
991: dllname = "WinUAE_Spanish.dll";
992: break;
993: case LANG_SWAHILI:
994: dllname = "WinUAE_Swahili.dll";
995: break;
996: case LANG_SWEDISH:
997: dllname = "WinUAE_Swedish.dll";
998: break;
999: case LANG_TAMIL:
1000: dllname = "WinUAE_Tamil.dll";
1001: break;
1002: case LANG_TATAR:
1003: dllname = "WinUAE_Tatar.dll";
1004: break;
1005: case LANG_TELUGU:
1006: dllname = "WinUAE_Telugu.dll";
1007: break;
1008: case LANG_THAI:
1009: dllname = "WinUAE_Thai.dll";
1010: break;
1011: case LANG_TURKISH:
1012: dllname = "WinUAE_Turkish.dll";
1.1 root 1013: break;
1.1.1.4 root 1014: case LANG_UKRAINIAN:
1015: dllname = "WinUAE_Ukrainian.dll";
1016: break;
1017: case LANG_URDU:
1018: dllname = "WinUAE_Urdu.dll";
1019: break;
1020: case LANG_UZBEK:
1021: dllname = "WinUAE_Uzbek.dll";
1022: break;
1023: case LANG_VIETNAMESE:
1024: dllname = "WinUAE_Vietnamese.dll";
1025: break;
1026: case 0x400:
1027: dllname = "guidll.dll";
1028: break;
1029: }
1.1 root 1030:
1.1.1.4 root 1031: if( dllname )
1032: {
1033: TCHAR szFilename[ MAX_PATH ];
1034: DWORD dwVersionHandle, dwFileVersionInfoSize;
1035: LPVOID lpFileVersionData = NULL;
1036: BOOL success = FALSE;
1037: result = LoadLibrary( dllname );
1038: if( result && GetModuleFileName( result, (LPTSTR)&szFilename, MAX_PATH ) )
1039: {
1040: dwFileVersionInfoSize = GetFileVersionInfoSize( szFilename, &dwVersionHandle );
1041: if( dwFileVersionInfoSize )
1042: {
1043: if( lpFileVersionData = calloc( 1, dwFileVersionInfoSize ) )
1044: {
1045: if( GetFileVersionInfo( szFilename, dwVersionHandle, dwFileVersionInfoSize, lpFileVersionData ) )
1046: {
1047: VS_FIXEDFILEINFO *vsFileInfo = NULL;
1048: UINT uLen;
1049: if( VerQueryValue( lpFileVersionData, TEXT("\\"), (void **)&vsFileInfo, &uLen ) )
1050: {
1051: if( vsFileInfo &&
1052: ( HIWORD(vsFileInfo->dwProductVersionMS) == UAEMAJOR )
1053: && ( LOWORD(vsFileInfo->dwProductVersionMS) == UAEMINOR )
1054: && ( HIWORD(vsFileInfo->dwProductVersionLS) == UAESUBREV )
1055: // Change this to an #if 1 when the WinUAE Release version (as opposed to UAE-core version)
1056: // requires a GUI-DLL change...
1057: #if 0
1058: && ( LOWORD(vsFileInfo->dwProductVersionLS) == WINUAERELEASE)
1059: #endif
1060: )
1061: {
1062: success = TRUE;
1063: }
1064: }
1065: }
1066: free( lpFileVersionData );
1067: }
1068: }
1069: }
1070: if( result && !success )
1071: {
1072: FreeLibrary( result );
1073: result = NULL;
1.1 root 1074: }
1075: }
1076:
1.1.1.4 root 1077: return result;
1.1 root 1078: }
1079:
1.1.1.4 root 1080: #ifndef _WIN32_WCE
1081: /* try to load COMDLG32 and DDRAW, initialize csDraw */
1082: int WIN32_InitLibraries( void )
1.1 root 1083: {
1.1.1.4 root 1084: int result = 1;
1085: /* Determine our processor speed and capabilities */
1086: figure_processor_speed();
1087:
1088: /* Make sure we do an InitCommonControls() to get some advanced controls */
1089: InitCommonControls();
1090:
1091: hRichEdit = LoadLibrary( "RICHED32.DLL" );
1092:
1093: hUIDLL = LoadGUI();
1.1 root 1094:
1.1.1.4 root 1095: #ifdef USE_ZLIB_DLL
1096: hZlib = LoadLibrary( "ZLIB.DLL" );
1097: if( hZlib )
1098: {
1099: pgzread = GetProcAddress( hZlib, "gzread" );
1100: pgzopen = GetProcAddress( hZlib, "gzopen" );
1101: pgzclose = GetProcAddress( hZlib, "gzclose" );
1102: pgzwrite = GetProcAddress( hZlib, "gzwrite" );
1103: pgzerror = GetProcAddress( hZlib, "gzerror" );
1104: if( !pgzread || !pgzopen || !pgzclose || !pgzwrite || !pgzerror)
1105: {
1106: FreeLibrary( hZlib );
1107: hZlib = NULL;
1108: }
1109: }
1110: #endif
1111: return result;
1.1 root 1112: }
1.1.1.4 root 1113: #endif
1.1 root 1114:
1.1.1.4 root 1115: /* Mathias says: "this truly sucks, I'll include a native gunzip() routine soon" */
1.1 root 1116:
1.1.1.4 root 1117: #ifdef USE_ZLIB_DLL
1118: extern FARPROC pgzread, pgzopen, pgzclose, pgzwrite, pgzerror;
1119: #define GZOPEN( X, Y ) (gzFile)pgzopen( X, Y )
1120: #define GZCLOSE( X ) (int)pgzclose( X )
1121: #define GZREAD( X, Y, Z ) (int)pgzread( X, Y, Z )
1122:
1123: #define ZLIB_BUFFER_SIZE 32767
1124:
1125: /* gzip decompression via zlib */
1126: static int zlib_gunzip( const char *src, char *dst )
1127: {
1128: int result = 0, gzResult = 0;
1129: gzFile zSrc = NULL;
1130: FILE *fDst = NULL;
1131: size_t filesize = 0;
1132: uae_u8 *buffer = NULL;
1.1 root 1133:
1.1.1.4 root 1134: if( hZlib )
1135: {
1136: zSrc = GZOPEN( src, "rb" );
1137: fDst = fopen( dst, "wb" );
1138: buffer = xmalloc( ZLIB_BUFFER_SIZE + 1 );
1139:
1140: if( zSrc && fDst && buffer )
1141: {
1142: DWORD dwWritten = 0;
1143: result = 1;
1144: do
1145: {
1146: gzResult = GZREAD( zSrc, buffer, ZLIB_BUFFER_SIZE );
1147: if( gzResult > 0 )
1148: {
1149: if( fwrite( buffer, gzResult, 1, fDst ) != 1 )
1150: {
1151: result = 0;
1152: break;
1153: }
1154: }
1155: } while( gzResult == ZLIB_BUFFER_SIZE );
1156: }
1157:
1158: if( zSrc )
1159: {
1160: GZCLOSE( zSrc );
1.1 root 1161: }
1.1.1.4 root 1162:
1163: if( fDst )
1.1 root 1164: {
1.1.1.4 root 1165: fclose( fDst );
1.1 root 1166: }
1167: }
1.1.1.4 root 1168: return result;
1.1 root 1169: }
1.1.1.4 root 1170: #endif
1.1 root 1171:
1.1.1.4 root 1172: static char *uncompress_error[2] = { "Error: You need zlib.dll to use .adz/.roz files!\n",
1173: "Error: You need xdms.exe (32 bit) to use .dms files!\n" };
1.1 root 1174:
1.1.1.4 root 1175: int uncompress_hack( int type, const char *src, const char *dst)
1.1 root 1176: {
1.1.1.4 root 1177: int result = 0;
1178: char fullname[1024];
1179: char buf[1024];
1180: char cmd[256];
1181: char *posn = NULL;
1182: STARTUPINFO si = {sizeof si};
1183: PROCESS_INFORMATION pi;
1.1 root 1184:
1.1.1.4 root 1185: strcpy( fullname, dst );
1.1 root 1186:
1.1.1.4 root 1187: if( type == 1 )
1188: {
1189: #ifdef USE_ZLIB_DLL
1190: result = zlib_gunzip( src, fullname );
1191: if( !result )
1192: {
1193: gui_message( uncompress_error[type-1] );
1194: }
1195: return result;
1196: #else
1197: strcpy( cmd, "gzip.exe -f -d" );
1198: strcat( fullname, ".gz" );
1199: #endif
1200: }
1201: else if( type == 2 )
1202: {
1203: strcpy( cmd, "xdms.exe u" );
1204: posn = strrchr( fullname, '.' );
1205: if( posn )
1206: {
1207: *posn = 0;
1208: strcat( fullname, ".dms" );
1209: }
1210: }
1.1 root 1211:
1.1.1.4 root 1212: if( CopyFile( src, fullname, FALSE ) )
1213: {
1214: sprintf (buf, "%s %s +%s", cmd, fullname, dst );
1215: si.dwFlags = STARTF_USESTDHANDLES;
1216: if( CreateProcess( NULL, buf, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi ) )
1217: {
1218: WaitForSingleObject( pi.hProcess, INFINITE );
1219: result = -1;
1220: }
1221: else
1222: {
1223: gui_message( uncompress_error[type-1] );
1224: }
1225: }
1.1 root 1226:
1.1.1.4 root 1227: /* Special handling for broken xdms.exe */
1228: if( type == 2 )
1229: {
1230: DeleteFile( fullname ); /* Delete the uaeXX.dms file */
1.1.1.2 root 1231: }
1.1 root 1232:
1.1.1.4 root 1233: return result;
1.1 root 1234: }
1235:
1.1.1.4 root 1236: /* console window for debugging messages */
1237: /* Brian: disable for release version if you want (TW) */
1.1 root 1238:
1.1.1.4 root 1239: #define WRITE_LOG_BUF_SIZE 4096
1240:
1241: static int consoleopen = 0;
1242: HANDLE stdinput,stdoutput;
1.1 root 1243:
1.1.1.4 root 1244: static void openconsole(void)
1.1 root 1245: {
1.1.1.4 root 1246: if(consoleopen) return;
1247: AllocConsole();
1248: stdinput=GetStdHandle(STD_INPUT_HANDLE);
1249: stdoutput=GetStdHandle(STD_OUTPUT_HANDLE);
1250: SetConsoleMode(stdinput,ENABLE_PROCESSED_INPUT|ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT|ENABLE_PROCESSED_OUTPUT);
1251: consoleopen = 1;
1.1 root 1252: }
1253:
1.1.1.4 root 1254: /* console functions for debugger */
1.1 root 1255:
1.1.1.4 root 1256: void console_out (const char *format,...)
1257: {
1258: va_list parms;
1259: char buffer[WRITE_LOG_BUF_SIZE];
1260: DWORD temp;
1.1 root 1261:
1.1.1.4 root 1262: va_start (parms, format);
1263: _vsnprintf( buffer, WRITE_LOG_BUF_SIZE-1, format, parms );
1264: va_end (parms);
1265: openconsole();
1266: WriteConsole(stdoutput,buffer,strlen(buffer),&temp,0);
1.1 root 1267: }
1268:
1.1.1.4 root 1269: int console_get (char *out, int maxlen)
1.1.1.2 root 1270: {
1.1.1.4 root 1271: DWORD len,totallen;
1.1 root 1272:
1.1.1.4 root 1273: totallen=0;
1274: while(maxlen>0)
1275: {
1276: ReadConsole(stdinput,out,1,&len,0);
1277: if(*out == 13) break;
1278: out++;
1279: maxlen--;
1280: totallen++;
1.1 root 1281: }
1.1.1.4 root 1282: *out=0;
1283: return totallen;
1.1 root 1284: }
1.1.1.2 root 1285:
1.1.1.4 root 1286: void console_flush (void)
1.1.1.2 root 1287: {
1288: }
1.1 root 1289:
1.1.1.4 root 1290: /* GCC/EGCS wants this write_log in order to work from socket-land and to do traces */
1.1 root 1291: #ifdef __GNUC__
1.1.1.4 root 1292: void write_log (const char *format, ...)
1.1 root 1293: {
1.1.1.4 root 1294: int result = 0;
1295: DWORD numwritten;
1296: char buffer[12];
1297: va_list parms;
1298: int count = 0;
1299: int *blah = NULL;
1.1 root 1300:
1.1.1.4 root 1301: if( debugfile )
1302: {
1303: #if defined HAVE_GETTICKCOUNT && defined TIMESTAMP_LOGS
1304: {
1305: sprintf( buffer, "%7d - ", GetTickCount() );
1306: fprintf( debugfile, buffer );
1307: }
1308: #endif
1309: va_start (parms, format);
1310: count = vfprintf( debugfile, format, parms );
1311: fflush( debugfile );
1312: if( count >= WRITE_LOG_BUF_SIZE-1 )
1313: {
1314: fprintf( debugfile, "SHIT in write_log()\n" );
1315: fflush( debugfile );
1316: *blah = 0; /* Access Violation here! */
1317: abort();
1318: }
1.1.1.2 root 1319: else
1.1.1.4 root 1320: result = count;
1321: va_end (parms);
1.1.1.2 root 1322: }
1.1 root 1323: }
1.1.1.4 root 1324: #else /* MSVC likes this one, and so do I */
1325: int write_log( const char *format, ... )
1.1 root 1326: {
1.1.1.4 root 1327: int result = 0;
1328: #ifdef _DEBUG
1.1.1.2 root 1329: DWORD numwritten;
1.1.1.4 root 1330: #endif
1331: char buffer[ WRITE_LOG_BUF_SIZE ];
1.1 root 1332: va_list parms;
1.1.1.4 root 1333: int count = 0;
1334: int *blah = (int *)0xdeadbeef;
1.1 root 1335:
1336: va_start (parms, format);
1.1.1.4 root 1337: count = _vsnprintf( buffer, WRITE_LOG_BUF_SIZE-1, format, parms );
1338: #if defined HAVE_GETTICKCOUNT && defined TIMESTAMP_LOGS
1339: {
1340: char buffme[WRITE_LOG_BUF_SIZE];
1341: sprintf( buffme, "%7d - %s", GetTickCount(), buffer );
1342: OutputDebugString( buffme );
1343: if( debugfile )
1344: fprintf( debugfile, buffme );
1345: result = strlen( buffme );
1346: }
1347: #else
1348: OutputDebugString( buffer );
1349: if( debugfile )
1350: {
1351: fprintf( debugfile, buffer );
1352: fflush( debugfile );
1353: }
1354: result = strlen( buffer );
1355: #endif
1356: #ifdef _DEBUG
1357: openconsole();
1358: WriteConsole(stdoutput,buffer,strlen(buffer),&numwritten,0);
1359: #endif
1.1 root 1360: va_end (parms);
1.1.1.4 root 1361: return result;
1.1 root 1362: }
1.1.1.4 root 1363: #endif
1.1 root 1364:
1365: int debuggable (void)
1366: {
1.1.1.4 root 1367: return 0;
1.1 root 1368: }
1369:
1370: int needmousehack (void)
1371: {
1.1.1.4 root 1372: if( WIN32GFX_IsFullScreen() || WIN32GFX_IsPicassoScreen() )
1373: return 0;
1374: else
1375: return 1;
1.1 root 1376: }
1377:
1.1.1.2 root 1378: void LED (int a)
1.1 root 1379: {
1380: }
1381:
1.1.1.4 root 1382: void logging_init( void )
1.1 root 1383: {
1.1.1.4 root 1384: char debugfilename[MAX_PATH];
1385: if (1) {
1386: sprintf( debugfilename, "%s\\winuaelog.txt", start_path );
1387: if( !debugfile )
1388: debugfile = fopen( debugfilename, "wt" );
1.1 root 1389: }
1.1.1.4 root 1390: write_log ( "%s\n", VersionStr );
1391: write_log ("\n(c) 1995-2001 Bernd Schmidt - Core UAE concept and implementation."
1392: "\n(c) 1996-1999 Mathias Ortmann - Win32 port and bsdsocket support."
1393: "\n(c) 1996-2001 Brian King - Win32 port, Picasso96 RTG, and GUI."
1394: "\n(c) 1998-2001 Toni Wilen - AGA chipset, NTSC/PAL modes.\n"
1395: "\n(c) 2000-2001 Bernd Meyer - JIT engine.\n"
1396: "\n(c) 2000-2001 Bernd Roesch - MIDI input, many fixes.\n"
1397: "\nPress F12 to show the Settings Dialog (GUI), Alt-F4 to quit."
1398: "\nEnd+F1 changes floppy 0, End+F2 changes floppy 1, etc.\n"
1399: "\nhttp://www.codepoet.com/UAE/\n\n");
1.1 root 1400: }
1.1.1.2 root 1401:
1.1.1.4 root 1402: void logging_cleanup( void )
1.1 root 1403: {
1.1.1.4 root 1404: if( debugfile )
1405: fclose( debugfile );
1.1 root 1406: }
1407:
1.1.1.4 root 1408: static const char *sound_styles[] = { "waveout_looping", "waveout_dblbuff", "dsound_looping", "dsound_dblbuff", 0 };
1.1 root 1409:
1.1.1.4 root 1410: void target_save_options (FILE *f, struct uae_prefs *p)
1.1 root 1411: {
1.1.1.5 ! root 1412: fprintf (f, "win32.middle_mouse=%s\n", p->win32_middle_mouse ? "true" : "false");
! 1413: fprintf (f, "win32.logfile=%s\n", p->win32_logfile ? "true" : "false");
! 1414: fprintf (f, "win32.map_drives=%s\n", p->win32_automount_drives ? "true" : "false" );
! 1415: fprintf (f, "win32.serial_port=%s\n", p->use_serial ? p->sername : "none" );
! 1416: fprintf (f, "win32.parallel_port=%s\n", p->prtname[0] ? p->prtname : "none" );
! 1417: fprintf (f, "win32.iconified_nospeed=%s\n", p->win32_iconified_nospeed ? "true" : "false");
! 1418: fprintf (f, "win32.iconified_nosound=%s\n", p->win32_iconified_nosound ? "true" : "false");
! 1419: fprintf (f, "win32.no_overlay=%s\n", p->win32_no_overlay ? "true" : "false" );
1.1 root 1420: }
1421:
1.1.1.4 root 1422: int target_parse_option (struct uae_prefs *p, char *option, char *value)
1.1 root 1423: {
1.1.1.5 ! root 1424: int result = (cfgfile_yesno (option, value, "middle_mouse", &p->win32_middle_mouse)
! 1425: || cfgfile_yesno (option, value, "logfile", &p->win32_logfile)
! 1426: || cfgfile_yesno (option, value, "no_overlay", &p->win32_no_overlay)
! 1427: || cfgfile_yesno (option, value, "map_drives", &p->automount_drives)
! 1428: || cfgfile_yesno (option, value, "iconified_nospeed", &p->win32_iconified_nospeed)
! 1429: || cfgfile_yesno (option, value, "iconified_nosound", &p->win32_iconified_nosound)
! 1430: || cfgfile_string (option, value, "serial_port", &p->sername[0], 256)
! 1431: || cfgfile_string (option, value, "parallel_port", &p->prtname[0], 256));
! 1432:
! 1433: if (p->sername[0] == 'n')
! 1434: p->use_serial = 0;
! 1435: else
! 1436: p->use_serial = 1;
! 1437:
1.1 root 1438: return 0;
1439: }
1440:
1.1.1.4 root 1441: void WIN32_HandleRegistryStuff( void )
1.1 root 1442: {
1.1.1.4 root 1443: RGBFTYPE colortype = RGBFB_NONE;
1444: DWORD dwType = REG_DWORD;
1445: DWORD dwDisplayInfoSize = sizeof( colortype );
1446: DWORD disposition;
1447: char path[MAX_PATH] = "";
1448: HKEY hWinUAEKeyLocal = NULL;
1449:
1450: /* Create/Open the hWinUAEKey which points to our config-info */
1451: if( RegCreateKeyEx( HKEY_CLASSES_ROOT, ".uae", 0, "", REG_OPTION_NON_VOLATILE,
1452: KEY_ALL_ACCESS, NULL, &hWinUAEKey, &disposition ) == ERROR_SUCCESS )
1453: {
1454: // Regardless of opening the existing key, or creating a new key, we will write the .uae filename-extension
1455: // commands in. This way, we're always up to date.
1.1 root 1456:
1.1.1.4 root 1457: /* Set our (default) sub-key to point to the "WinUAE" key, which we then create */
1458: RegSetValueEx( hWinUAEKey, "", 0, REG_SZ, (CONST BYTE *)"WinUAE", strlen( "WinUAE" ) + 1 );
1.1 root 1459:
1.1.1.4 root 1460: if( ( RegCreateKeyEx( HKEY_CLASSES_ROOT, "WinUAE\\shell\\Edit\\command", 0, "", REG_OPTION_NON_VOLATILE,
1461: KEY_ALL_ACCESS, NULL, &hWinUAEKeyLocal, &disposition ) == ERROR_SUCCESS ) )
1462: {
1463: /* Set our (default) sub-key to BE the "WinUAE" command for editing a configuration */
1464: sprintf( path, "%s\\WinUAE.exe -f \"%%1\" -s use_gui=yes", start_path );
1465: RegSetValueEx( hWinUAEKeyLocal, "", 0, REG_SZ, (CONST BYTE *)path, strlen( path ) + 1 );
1466: }
1467: RegCloseKey( hWinUAEKeyLocal );
1468:
1469: if( ( RegCreateKeyEx( HKEY_CLASSES_ROOT, "WinUAE\\shell\\Open\\command", 0, "", REG_OPTION_NON_VOLATILE,
1470: KEY_ALL_ACCESS, NULL, &hWinUAEKeyLocal, &disposition ) == ERROR_SUCCESS ) )
1471: {
1472: /* Set our (default) sub-key to BE the "WinUAE" command for launching a configuration */
1473: sprintf( path, "%s\\WinUAE.exe -f \"%%1\"", start_path );
1474: RegSetValueEx( hWinUAEKeyLocal, "", 0, REG_SZ, (CONST BYTE *)path, strlen( path ) + 1 );
1475: }
1476: RegCloseKey( hWinUAEKeyLocal );
1477: }
1478: else
1479: {
1480: char szMessage[ MAX_PATH ];
1481: WIN32GUI_LoadUIString( IDS_REGKEYCREATEFAILED, szMessage, MAX_PATH );
1482: gui_message( szMessage );
1483: hWinUAEKey = NULL;
1484: }
1485: RegCloseKey( hWinUAEKey );
1486:
1487: /* Create/Open the hWinUAEKey which points our config-info */
1488: if( RegCreateKeyEx( HKEY_CURRENT_USER, "Software\\CodePoet Computing\\WinUAE", 0, "", REG_OPTION_NON_VOLATILE,
1489: KEY_ALL_ACCESS, NULL, &hWinUAEKey, &disposition ) == ERROR_SUCCESS )
1490: {
1491: if( disposition == REG_CREATED_NEW_KEY )
1492: {
1493: /* Create and initialize all our sub-keys to the default values */
1494: colortype = 0;
1495: RegSetValueEx( hWinUAEKey, "DisplayInfo", 0, REG_DWORD, (CONST BYTE *)&colortype, sizeof( colortype ) );
1496: RegSetValueEx( hWinUAEKey, "xPos", 0, REG_DWORD, (CONST BYTE *)&colortype, sizeof( colortype ) );
1497: RegSetValueEx( hWinUAEKey, "yPos", 0, REG_DWORD, (CONST BYTE *)&colortype, sizeof( colortype ) );
1498: RegSetValueEx( hWinUAEKey, "FloppyPath", 0, REG_SZ, (CONST BYTE *)start_path, strlen( start_path ) + 1 );
1499: RegSetValueEx( hWinUAEKey, "KickstartPath", 0, REG_SZ, (CONST BYTE *)start_path, strlen( start_path ) + 1 );
1500: RegSetValueEx( hWinUAEKey, "hdfPath", 0, REG_SZ, (CONST BYTE *)start_path, strlen( start_path ) + 1 );
1501: }
1502: // Set this even when we're opening an existing key, so that the version info is always up to date.
1503: RegSetValueEx( hWinUAEKey, "Version", 0, REG_SZ, (CONST BYTE *)VersionStr, strlen( VersionStr ) + 1 );
1504:
1505: RegQueryValueEx( hWinUAEKey, "DisplayInfo", 0, &dwType, (LPBYTE)&colortype, &dwDisplayInfoSize );
1506: if( colortype == 0 ) /* No color information stored in the registry yet */
1507: {
1508: char szMessage[ 4096 ];
1509: char szTitle[ MAX_PATH ];
1510: WIN32GUI_LoadUIString( IDS_GFXCARDCHECK, szMessage, 4096 );
1511: WIN32GUI_LoadUIString( IDS_GFXCARDTITLE, szTitle, MAX_PATH );
1512:
1513: if( MessageBox( NULL, szMessage, szTitle,
1514: MB_YESNO | MB_ICONWARNING | MB_TASKMODAL | MB_SETFOREGROUND ) == IDYES )
1515: {
1516: colortype = WIN32GFX_FigurePixelFormats(0);
1517: RegSetValueEx( hWinUAEKey, "DisplayInfo", 0, REG_DWORD, (CONST BYTE *)&colortype, sizeof( colortype ) );
1518: }
1519: }
1520: if( colortype )
1521: {
1522: /* Set the 16-bit pixel format for the appropriate modes */
1523: WIN32GFX_FigurePixelFormats( colortype );
1524: }
1525: }
1526: else
1527: {
1528: char szMessage[ MAX_PATH ];
1529: WIN32GUI_LoadUIString( IDS_REGKEYCREATEFAILED, szMessage, MAX_PATH );
1530: gui_message( szMessage );
1531: hWinUAEKey = NULL;
1.1 root 1532: }
1.1.1.2 root 1533: }
1534:
1535: void machdep_init (void)
1536: {
1537: }
1538:
1.1.1.4 root 1539: char *start_path = NULL;
1540: char help_file[ MAX_PATH ];
1.1.1.2 root 1541:
1542: int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
1543: int nCmdShow)
1544: {
1.1.1.4 root 1545: char *posn;
1546: HANDLE hMutex;
1547: OSVERSIONINFO osVersion;
1.1.1.2 root 1548:
1.1.1.4 root 1549: #ifdef __GNUC__
1550: __asm__ ("leal -2300*1024(%%esp),%0" : "=r" (win32_stackbase) :);
1551: #else
1552: __asm{
1553: mov eax,esp
1554: sub eax,2300*1024
1555: mov win32_stackbase,eax
1556: }
1557: #endif
1.1.1.2 root 1558:
1.1.1.4 root 1559: hInst = hInstance;
1560: hMutex = CreateMutex( NULL, FALSE, "WinUAE Instantiated" ); // To tell the installer we're running
1561:
1562: osVersion.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
1563: if( GetVersionEx( &osVersion ) )
1.1.1.2 root 1564: {
1.1.1.4 root 1565: if( ( osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT ) &&
1566: ( osVersion.dwMajorVersion <= 4 ) )
1567: {
1568: /* WinUAE not supported on this version of Windows... */
1569: char szWrongOSVersion[ MAX_PATH ];
1570: WIN32GUI_LoadUIString( IDS_WRONGOSVERSION, szWrongOSVersion, MAX_PATH );
1571: gui_message( szWrongOSVersion );
1572: return FALSE;
1.1.1.2 root 1573: }
1.1.1.4 root 1574: }
1.1.1.2 root 1575:
1.1.1.4 root 1576: /* Get our executable's root-path */
1577: if( ( start_path = xmalloc( MAX_PATH ) ) )
1578: {
1579: GetModuleFileName( NULL, start_path, MAX_PATH );
1580: if( ( posn = strrchr( start_path, '\\' ) ) )
1581: *posn = 0;
1582: sprintf( help_file, "%s\\WinUAE.chm", start_path );
1.1.1.2 root 1583:
1.1.1.4 root 1584: sprintf( VersionStr, "WinUAE %d.%d.%d, Release %d%s", UAEMAJOR, UAEMINOR, UAESUBREV, WINUAERELEASE, WINUAEBETA ? WINUAEBETASTR : "" );
1.1.1.2 root 1585:
1.1.1.4 root 1586: logging_init ();
1587: printf ("Hello, world\n");
1.1.1.2 root 1588:
1.1.1.4 root 1589: if( WIN32_RegisterClasses() && WIN32_InitLibraries() && DirectDraw_Start() )
1590: {
1591: struct foo {
1592: DEVMODE actual_devmode;
1593: char overrun[8];
1594: } devmode;
1595:
1596: DWORD i = 0;
1597:
1598: DirectDraw_EnumDisplayModes( 0, modesCallback );
1599:
1600: memset( &devmode, 0, sizeof(DEVMODE) + 8 );
1601: devmode.actual_devmode.dmSize = sizeof(DEVMODE);
1602: devmode.actual_devmode.dmDriverExtra = 8;
1603: #define ENUM_CURRENT_SETTINGS ((DWORD)-1)
1604: if( EnumDisplaySettings( NULL, ENUM_CURRENT_SETTINGS, (LPDEVMODE)&devmode ) )
1605: {
1606: default_freq = devmode.actual_devmode.dmDisplayFrequency;
1607: write_log( "Your Windows desktop refresh frequency is %d Hz\n", default_freq );
1608: if( default_freq >= 70 )
1609: default_freq = 70;
1610: else
1611: default_freq = 60;
1612: }
1613:
1614: WIN32_HandleRegistryStuff();
1615: if( WIN32_InitHtmlHelp() == 0 )
1616: {
1617: char szMessage[ MAX_PATH ];
1618: WIN32GUI_LoadUIString( IDS_NOHELP, szMessage, MAX_PATH );
1619: write_log( szMessage );
1620: }
1621:
1622: DirectDraw_Release();
1623: #ifdef __MINGW32__
1624: real_main (_argc, _argv);
1.1.1.2 root 1625: #else
1.1.1.4 root 1626: real_main (__argc, __argv);
1.1.1.2 root 1627: #endif
1.1.1.4 root 1628: }
1629: free( start_path );
1630: }
1631:
1632: WIN32_CleanupLibraries();
1633: _fcloseall();
1634: if( hWinUAEKey )
1635: RegCloseKey( hWinUAEKey );
1636: CloseHandle( hMutex );
1.1.1.2 root 1637: return FALSE;
1638: }
1.1.1.4 root 1639:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.