--- uae/src/od-win32/win32.c 2018/04/24 16:40:31 1.1 +++ uae/src/od-win32/win32.c 2018/04/24 17:03:09 1.1.1.4 @@ -3,145 +3,106 @@ * * Win32 interface * - * Copyright 1997 Mathias Ortmann + * Copyright 1997-1998 Mathias Ortmann + * Copyright 1997-1999 Brian King */ -#ifdef __GNUC__ -#define __int64 long long -#include "machdep/winstuff.h" -#else -#include -#include +/* Uncomment this line if you want the logs time-stamped */ +/* #define TIMESTAMP_LOGS */ + +#include "config.h" +#include "sysconfig.h" + #include #include +#include + +#include #include #include -#include -#include -#include -#include -#endif +#include +#include +#include +#include +#include -#include "config.h" -#include "sysconfig.h" #include "sysdeps.h" - #include "options.h" #include "gensound.h" #include "sounddep/sound.h" #include "uae.h" -#include "threaddep/penguin.h" #include "memory.h" #include "custom.h" #include "events.h" #include "xwin.h" #include "keyboard.h" +#include "keybuf.h" +#include "drawing.h" #include "picasso96.h" - -#include "osdep/win32gui.h" -#include "resource.h" +#include "bsdsocket.h" #include "osdep/win32.h" - -extern struct picasso_vidbuf_description picasso_vidinfo; -#define IHF_WINDOWHIDDEN 6 - -static BOOL (WINAPI *pGetOpenFileNameA) (LPOPENFILENAME); -static HRESULT (WINAPI *pDirectDrawCreate) (GUID FAR *, LPDIRECTDRAW FAR *, IUnknown FAR *); -static HRESULT CALLBACK modesCallback (LPDDSURFACEDESC modeDesc, LPVOID context); - -HWND hAmigaWnd, hMainWnd; -HINSTANCE hInst; -/*DWORD Keys;*/ -static RECT amigawin_rect; +#include "osdep/win32gfx.h" +#include "osdep/win32gui.h" +#include "osdep/dxwrap.h" +#include "autoconf.h" +#include "gui.h" +#include "newcpu.h" +extern void WIN32GFX_WindowMove ( void ); +extern void WIN32GFX_WindowSize ( void ); +unsigned long *win32_stackbase; +unsigned long *win32_freestack[42]; //EXTRA_STACK_SIZE -drive_specs drives[NUM_DRIVES]; -char *start_path = NULL; +/* Comment out the following line if you don't want ZLIB.DLL support */ +#undef USE_ZLIB_DLL -static LPDIRECTDRAW lpDD; -static LPDIRECTDRAWSURFACE lpDDS; -static LPDIRECTDRAWCLIPPER lpDDC; -static LPDIRECTDRAWPALETTE lpDDP; -static DDSURFACEDESC ddsd; -HANDLE hEmuThread; +#ifdef USE_ZLIB_DLL +#include "zlib.h" +#endif -static HDC hBackDC; -static HBITMAP hBackBM; +int useqpc = 0; /* Set to TRUE to use the QueryPerformanceCounter() function instead of rdtsc() */ -static CRITICAL_SECTION csDraw; +static FILE *debugfile = NULL; -#define TITLETEXT PROGNAME " -- Amiga Display" -char VersionStr[256]; -extern int current_width, current_height; +HINSTANCE hInst = NULL; +HMODULE hUIDLL = NULL; -static uae_sem_t picasso_switch_sem; +HWND (WINAPI *pHtmlHelp)(HWND, LPCSTR, UINT, LPDWORD ) = NULL; -static int fullscreen = 0; -int current_width, current_height; -static int current_pixbytes; +HWND hAmigaWnd, hMainWnd; +/*DWORD Keys; */ +RECT amigawin_rect; -static int changemode; +char VersionStr[256]; -static int screen_is_picasso = 0; -static int picasso_fullscreen = 1; -int amiga_fullscreen = 1, customsize = 0; +int in_sizemove = 0; +int manual_painting_needed = 0; +int customsize = 0; int bActive; -int capslock; int toggle_sound; -int process_desired_pri; - -int cycles_per_instruction = 4; -int good_cpu = 0; - -BOOL allow_quit_from_property_sheet = TRUE; BOOL viewing_child = FALSE; -static char scrlinebuf[8192]; /* this is too large, but let's rather play on the safe side here */ -static int scrindirect; - -static void set_linemem (void) -{ - if (scrindirect) - gfxvidinfo.linemem = scrlinebuf; - else - gfxvidinfo.linemem = 0; -} +HKEY hWinUAEKey = NULL; +COLORREF g_dwBackgroundColor = RGB(10, 0, 10); /* Keyboard emulation, Win32 helper routines. */ static LPARAM keysdown[256]; static short numkeysdown; - -int getcapslock (void) -{ - BYTE keyState[256]; - - GetKeyboardState (keyState); - return keyState[VK_CAPITAL] & 1; -} - -int helppressed (void) -{ - return GetAsyncKeyState (VK_END) & 0x8000; -} - -int shiftpressed (void) -{ - return GetAsyncKeyState (VK_SHIFT) & 0x8000 ? 1 : 0; -} - int checkkey (int vkey, LPARAM lParam) { switch (vkey) { - case VK_SHIFT: - case VK_LSHIFT: - case VK_RSHIFT: - case VK_CONTROL: - case VK_LCONTROL: - case VK_RCONTROL: - case VK_MENU: - case VK_LMENU: - case VK_RMENU: + case VK_LWIN: + case VK_RWIN: + case VK_SHIFT: + case VK_LSHIFT: + case VK_RSHIFT: + case VK_CONTROL: + case VK_LCONTROL: + case VK_RCONTROL: + case VK_MENU: + case VK_LMENU: + case VK_RMENU: return GetKeyState (vkey) & 0x8000; } return GetAsyncKeyState (vkey) & 0x8000; @@ -152,6 +113,11 @@ static int mousecx = 160, mousecy = 100, static int mousecl = MAKELONG (160, 100); int mouseactive; +void WIN32_MouseDefaults( void ) +{ + mousecx = 160, mousecy = 100, mousedx = 160, mousedy = 100, mousecl = MAKELONG (160, 100); +} + void setmouseactive (int active) { mousedx = (amigawin_rect.right - amigawin_rect.left) / 2; @@ -164,21 +130,29 @@ void setmouseactive (int active) return; mouseactive = active; - if (active) { - ShowCursor (FALSE); - SetCursorPos (mousecx, mousecy); - SetWindowText (hMainWnd ? hMainWnd : hAmigaWnd, TITLETEXT " [Mouse active - press Alt-Tab to cancel]"); + if (active) + { +#ifdef HARDWARE_SPRITE_EMULATION + if( !WIN32GFX_IsPicassoScreen() ) +#endif + { + ShowCursor (FALSE); + SetCursorPos (mousecx, mousecy); + } + SetWindowText (hMainWnd ? hMainWnd : hAmigaWnd, "UAE/Win32 - [Mouse active - press Alt-Tab to cancel]"); ClipCursor (&amigawin_rect); - } else { + } + else + { ShowCursor (TRUE); - SetWindowText (hMainWnd ? hMainWnd : hAmigaWnd, TITLETEXT); + SetWindowText (hMainWnd ? hMainWnd : hAmigaWnd, "UAE/Win32" ); ClipCursor (NULL); } } static int hascapture = 0; -void setcapture (void) +static void setcapture (void) { if (hascapture) return; @@ -186,7 +160,7 @@ void setcapture (void) SetCapture (hAmigaWnd); } -static __inline__ void releasecapture (void) +void releasecapture (void) { if (!hascapture) return; @@ -194,596 +168,349 @@ static __inline__ void releasecapture (v ReleaseCapture (); } -static void figure_processor_speed (void) +frame_time_t read_processor_time_cyrix (void) { - SYSTEM_INFO sysinfo; - OSVERSIONINFO osinfo; - HKEY hKey; - DWORD value; - DWORD type, size; - unsigned long mhz = 0; - char cpuid[40]; - char *envptr; - - vsynctime = -1; - if ((envptr = getenv ("PROCESSOR_LEVEL")) && atoi (envptr) < 5) - goto bad_cpu; - - if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0L, KEY_READ, &hKey) == ERROR_SUCCESS) { - size = sizeof (value); - if (RegQueryValueEx (hKey, "~MHz", NULL, &type, (LPBYTE) & value, &size) == ERROR_SUCCESS) - mhz = value; - size = sizeof cpuid; - if (RegQueryValueEx (hKey, "VendorIdentifier", NULL, &type, (LPBYTE) cpuid, &size) == ERROR_SUCCESS) { - good_cpu = (strncmp (cpuid, "AuthenticAMD", 12) == 0 - || strncmp (cpuid, "GenuineIntel", 12) == 0); - } - RegCloseKey (hKey); - } - if (!good_cpu) - goto bad_cpu; - -#ifdef FRAME_RATE_HACK - if (mhz == 0) { - frame_time_t t; - DWORD oldpri = GetPriorityClass (GetCurrentProcess ()); - - write_log ("Calibrating delay loop.. "); - - SetPriorityClass (GetCurrentProcess (), REALTIME_PRIORITY_CLASS); - vsynctime = 1; - t = read_processor_time (); - Sleep (1001); - t = 2*read_processor_time () - t; - Sleep (1); - t -= read_processor_time (); - SetPriorityClass (GetCurrentProcess (), oldpri); - - MyOutputDebugString ("ok - %.2f BogoMIPS\n", (double)t / 1000000.0); - vsynctime = t / 50; - return; - } -#endif - if (mhz != 0) { - vsynctime = mhz * 1000000 / 50; - return; - } - write_log ("Could not determine clock speed of your CPU.\n"); - return; -bad_cpu: - write_log ("Processor level too low - disabling frame rate hack\n"); -} - -/* DirectDraw stuff*/ -char *getddrname (HRESULT ddrval) -{ - switch (ddrval) { - case DDERR_ALREADYINITIALIZED: - return "This object is already initialized."; - case DDERR_BLTFASTCANTCLIP: - return "Cannot use BLTFAST with Clipper attached to surface."; - case DDERR_CANNOTATTACHSURFACE: - return "Cannot attach surface."; - case DDERR_CANNOTDETACHSURFACE: - return "Cannot detach surface."; - case DDERR_CANTCREATEDC: - return "Cannot create DC Device Context."; - case DDERR_CANTDUPLICATE: - return "Cannot duplicate."; - case DDERR_CANTLOCKSURFACE: - return "Access to surface refused (no DCI provider)."; - case DDERR_CANTPAGELOCK: - return "PageLock failure."; - case DDERR_CANTPAGEUNLOCK: - return "PageUnlock failure."; - case DDERR_CLIPPERISUSINGHWND: - return "Can't set a clip-list for a Clipper which is attached to an HWND."; - case DDERR_COLORKEYNOTSET: - return "No source colour-key provided."; - case DDERR_CURRENTLYNOTAVAIL: - return "Support unavailable."; - case DDERR_DCALREADYCREATED: - return "Surface already has a Device Context."; - case DDERR_DIRECTDRAWALREADYCREATED: - return "DirectDraw already bound to this process."; - case DDERR_EXCEPTION: - return "Unexpected exception."; - case DDERR_EXCLUSIVEMODEALREADYSET: - return "Already in exclusive mode."; - case DDERR_GENERIC: - return "Undefined"; /* THIS MAKES SENSE! FUCKING M$ */ - - case DDERR_HEIGHTALIGN: - return "Height needs to be aligned."; - case DDERR_HWNDALREADYSET: - return "HWND already set for cooperative level."; - case DDERR_HWNDSUBCLASSED: - return "HWND has been subclassed."; - case DDERR_IMPLICITLYCREATED: - return "Can't restore an implicitly created surface."; - case DDERR_INCOMPATIBLEPRIMARY: - return "New params doesn't match existing primary surface."; - case DDERR_INVALIDCAPS: - return "Device doesn't have requested capabilities."; - case DDERR_INVALIDCLIPLIST: - return "Provided clip-list not supported."; - case DDERR_INVALIDDIRECTDRAWGUID: - return "Invalid GUID."; - case DDERR_INVALIDMODE: - return "Mode not supported."; - case DDERR_INVALIDOBJECT: - return "Invalid object."; - case DDERR_INVALIDPARAMS: - return "Invalid params."; - case DDERR_INVALIDPIXELFORMAT: - return "Device doesn't support requested pixel format."; - case DDERR_INVALIDPOSITION: - return "Overlay position illegal."; - case DDERR_INVALIDRECT: - return "Invalid RECT."; - case DDERR_INVALIDSURFACETYPE: - return "Wrong type of surface."; - case DDERR_LOCKEDSURFACES: - return "Surface locked."; - case DDERR_NO3D: - return "No 3d capabilities."; - case DDERR_NOALPHAHW: - return "No alpha h/w."; - case DDERR_NOBLTHW: - return "No blit h/w."; - case DDERR_NOCLIPLIST: - return "No clip-list."; - case DDERR_NOCLIPPERATTACHED: - return "No Clipper attached."; - case DDERR_NOCOLORCONVHW: - return "No colour-conversion h/w."; - case DDERR_NOCOLORKEY: - return "No colour-key."; - - case DDERR_NOTLOCKED: - return "Not locked."; - case DDERR_NOTPAGELOCKED: - return "Not page-locked."; - case DDERR_NOTPALETTIZED: - return "Not palette-based."; - - case DDERR_OUTOFCAPS: - return "out of caps"; - case DDERR_OUTOFMEMORY: - return "Out of memory."; - case DDERR_OUTOFVIDEOMEMORY: - return "out of video memory."; - case DDERR_PALETTEBUSY: - return "Palette busy."; - case DDERR_PRIMARYSURFACEALREADYEXISTS: - return "Already a primary surface."; - - case DDERR_SURFACEBUSY: - return "Surface busy."; - /*case DDERR_SURFACEOBSCURED: return "Surface is obscured.";*/ - case DDERR_SURFACELOST: - return "Surface lost."; - - case DDERR_UNSUPPORTED: - return "Unsupported."; - case DDERR_UNSUPPORTEDFORMAT: - return "Unsupported format."; - - case DDERR_WASSTILLDRAWING: - return "Was still drawing."; - } - return ""; -} - -static int lockcnt = 0; - -static int do_surfacelock (void) -{ - HRESULT ddrval = IDirectDrawSurface_Lock (lpDDS, NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); - if (ddrval != DD_OK) { - if (ddrval == DDERR_SURFACELOST) - ddrval = IDirectDrawSurface_Restore (lpDDS); - else if (ddrval != DDERR_SURFACEBUSY) - MyOutputDebugString ("lpDDS->Lock() failed - %s (%d)\n", getddrname (ddrval), (unsigned short) ddrval); - return 0; - } - lockcnt++; - return 1; + LARGE_INTEGER counter; + QueryPerformanceCounter( &counter ); + return (frame_time_t)(counter.LowPart); } -void unlockscr (void) -{ - lockcnt--; - IDirectDrawSurface_Unlock (lpDDS, ddsd.lpSurface); -} +#include +jmp_buf catch_test; -static void release_ddraw_stuff (void) +static RETSIGTYPE illhandler(int foo) { - if (lpDD) { - IDirectDraw_RestoreDisplayMode (lpDD); - IDirectDraw_SetCooperativeLevel (lpDD, hAmigaWnd, DDSCL_NORMAL); - } - if (lpDDC) - IDirectDrawClipper_Release (lpDDC); - if (lpDDS) - IDirectDrawSurface_Release (lpDDS); - if (lpDDP) - IDirectDrawPalette_Release (lpDDP); - if (lpDD) - IDirectDraw_Release (lpDD); - lpDDC = 0; - lpDDS = 0; - lpDDP = 0; - lpDD = 0; + rpt_available = 0; + longjmp(catch_test,1); } -static int set_ddraw (int width, int height, int wantfull, int *pbytes, - LPPALETTEENTRY pal) +int have_rdtsc (void) { - int bits = 8 * *pbytes; - HRESULT ddrval; - -#ifdef __GNUC__ - ddrval = (*pDirectDrawCreate) (NULL, &lpDD, NULL); -#else - ddrval = DirectDrawCreate (NULL, &lpDD, NULL); -#endif - if (ddrval != DD_OK) - goto oops; - - ddrval = IDirectDraw_SetCooperativeLevel (lpDD, hAmigaWnd, - (wantfull - ? DDSCL_ALLOWREBOOT | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN - : DDSCL_NORMAL)); - if (ddrval != DD_OK) - goto oops; - - ddrval = IDirectDraw_CreateClipper (lpDD, 0, &lpDDC, NULL); - if (ddrval != DD_OK) { - MyOutputDebugString ("DirectDraw error: Clipper unavailable! (%d)\n", ddrval); - } else { - if (IDirectDrawClipper_SetHWnd (lpDDC, 0, hAmigaWnd) != DD_OK) - MyOutputDebugString ("DirectDraw error: Can't attach HWnd!\n"); - } - - if (wantfull) { - ddrval = IDirectDraw_SetDisplayMode (lpDD, width, height, bits); - if (ddrval != DD_OK) - goto oops; - } - ddsd.dwSize = sizeof (ddsd); - ddsd.dwFlags = DDSD_CAPS; - ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - - ddrval = IDirectDraw_CreateSurface (lpDD, &ddsd, &lpDDS, NULL); - if (ddrval != DD_OK) - goto oops; - - if (! do_surfacelock ()) + rpt_available = 1; + write_log ("Testing the RDTSC instruction ... "); + signal (SIGILL, illhandler); + if (setjmp (catch_test) == 0) + read_processor_time (); + signal (SIGILL, SIG_DFL); + write_log ("done.\n"); + if (! rpt_available) { + write_log ("Your processor does not support the RDTSC instruction.\n"); return 0; - unlockscr (); - - bits = (ddsd.ddpfPixelFormat.dwRGBBitCount + 7) & ~7; - current_pixbytes = *pbytes = bits >> 3; - - if (bits == 8) { - ddrval = IDirectDraw_CreatePalette (lpDD, DDPCAPS_8BIT | DDPCAPS_ALLOW256, - pal, - &lpDDP, NULL); - if (ddrval != DD_OK) - goto oops; - - ddrval = IDirectDrawSurface2_SetPalette (lpDDS, lpDDP); - if (ddrval != DD_OK) - goto oops; - } - /* Set global values for current width,height */ - current_width = width; - current_height = height; - + } return 1; - -oops: - MyOutputDebugString ("DirectDraw initialization failed with %s/%d\n", getddrname (ddrval), ddrval); - return 0; } -/* Color management */ -static int bits_in_mask (unsigned long mask) +static void figure_processor_speed (void) { - int n = 0; - while (mask) { - n += mask & 1; - mask >>= 1; - } - return n; -} + extern volatile frame_time_t vsynctime; + extern unsigned long syncbase; + frame_time_t clockrate; + +#if defined __GNUC__ + if (! have_rdtsc ()) + useqpc = 1; +#else + LARGE_INTEGER freq; -static int mask_shift (unsigned long mask) -{ - int n = 0; - while (!(mask & 1)) { - n++; - mask >>= 1; + __try + { + __asm{rdtsc}; } - return n; -} - -static xcolnr xcol8[4096]; -static PALETTEENTRY colors256[256]; -static int ncols256 = 0; - -static int get_color (int r, int g, int b, xcolnr *cnp) -{ - if (ncols256 == 256) - return 0; - colors256[ncols256].peRed = r * 0x11; - colors256[ncols256].peGreen = g * 0x11; - colors256[ncols256].peBlue = b * 0x11; - colors256[ncols256].peFlags = 0; - *cnp = ncols256; - ncols256++; - return 1; -} - -static void init_colors (void) -{ - if (ncols256 == 0) - alloc_colors256 (get_color); - memcpy (xcol8, xcolors, sizeof xcol8); - - /* init colors */ - - switch (current_pixbytes) { - case 1: - memcpy (xcolors, xcol8, sizeof xcolors); - if (lpDDP != 0) { - HRESULT ddrval = IDirectDrawPalette_SetEntries (lpDDP, 0, 0, 256, colors256); - if (ddrval != DD_OK) - MyOutputDebugString ("DX_SetPalette() failed with %s/%d\n", getddrname (ddrval), ddrval); - } - break; + __except( GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION ) + { + useqpc = 1; + } + if( QueryPerformanceFrequency( &freq ) ) + { + if (freq.LowPart > 90000000) /* looks like CPU freq. */ + write_log( "CLOCKFREQ: QueryPerformanceFrequency() reports %d-MHz\n", freq.LowPart / 1000000 ); + else + write_log( "CLOCKFREQ: QueryPerformanceFrequency() reports %.2f-MHz\n", (float)freq.LowPart / 1000000.0f ); - case 2: - case 3: - case 4: + if( freq.LowPart < 1000000 ) { - int red_bits = bits_in_mask (ddsd.ddpfPixelFormat.dwRBitMask); - int green_bits = bits_in_mask (ddsd.ddpfPixelFormat.dwGBitMask); - int blue_bits = bits_in_mask (ddsd.ddpfPixelFormat.dwBBitMask); - int red_shift = mask_shift (ddsd.ddpfPixelFormat.dwRBitMask); - int green_shift = mask_shift (ddsd.ddpfPixelFormat.dwGBitMask); - int blue_shift = mask_shift (ddsd.ddpfPixelFormat.dwBBitMask); - - alloc_colors64k (red_bits, green_bits, blue_bits, red_shift, - green_shift, blue_shift); + write_log( "CLOCKFREQ: Weird value. Using QueryPerformanceCounter() instead of RDTSC.\n" ); + useqpc = 1; } - break; + rpt_available = 1; } -} - -static void close_windows (void) -{ - int i; - - gfxvidinfo.bufmem = 0; - gfxvidinfo.linemem = 0; - - releasecapture (); - setmouseactive (0); - ClipCursor (NULL); - release_ddraw_stuff (); - - if (!hMainWnd && hAmigaWnd) { - /*ShowWindow (hAmigaWnd, SW_MINIMIZE);*/ - } - if (hAmigaWnd) - DestroyWindow (hAmigaWnd); - if (hMainWnd) - DestroyWindow (hMainWnd); - PostQuitMessage (0); - hMainWnd = 0; - hAmigaWnd = 0; -} - -static void destroy_window (int nowait) -{ - if (currprefs.produce_sound > 1) - stopsound (); - - if (!nowait) { - frame_do_semup = 1; - set_inhibit_frame (5); - uae_sem_wait (&frame_sem); + else + { + write_log( "CLOCKFREQ: No support for clock-rate stuff!\n" ); + rpt_available = 0; } +#endif + SetPriorityClass( GetCurrentProcess(), REALTIME_PRIORITY_CLASS ); + clockrate = read_processor_time(); + Sleep( 1000 ); + clockrate = read_processor_time() - clockrate; + SetPriorityClass( GetCurrentProcess(), NORMAL_PRIORITY_CLASS ); - /*SuspendThread (hEmuThread);*/ - close_windows (); + write_log( "CLOCKFREQ: Measured as %d-MHz\n", clockrate / 1000000 ); + syncbase = clockrate; + vsynctime = syncbase / VBLANK_HZ_PAL; /* default to 50Hz */ } -void displaychange (void) -{ - changemode = 1; - destroy_window (0); -} +static BOOL bDiskChanged = FALSE; -void toggle_fullscreen (void) -{ - changemode = 1; - if (screen_is_picasso) - picasso_fullscreen ^= 1; - else - amiga_fullscreen ^= 1; - destroy_window (0); -} - -int can_draw (void) -{ - return gfxvidinfo.pixbytes != 0; -} - -long FAR PASCAL AmigaWindowProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +static long FAR PASCAL AmigaWindowProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hDC; + short wheeldelta; + static int store_xy = 0; + BOOL minimized; + LPMINMAXINFO lpmmi; + RECT rect; - if (changemode != 0) - return DefWindowProc (hWnd, message, wParam, lParam); - - switch (message) { - case WM_ACTIVATEAPP: - if (bActive = wParam) { - if (fullscreen) { - SetCursor (NULL); - SetCursorPos (mousecx, mousecy); -#ifdef PICASSO96 - if( !picasso96_state.RefreshPending ) - picasso96_state.RefreshPending = 1; -#endif + switch( message ) + { + case WM_PALETTECHANGED: + if( (HWND)wParam != hWnd ) + { + write_log( "WM_PALETTECHANGED Request\n" ); + WIN32GFX_PaletteChange(); + } + break; + case WM_ACTIVATEAPP: + if (bActive = wParam) + { + if( WIN32GFX_IsFullScreen() ) + { + SetCursor (NULL); +#ifndef HARDWARE_SPRITE_EMULATION + SetCursorPos (mousecx, mousecy); +#else + if( !WIN32GFX_IsPicassoScreen() ) + SetCursorPos (mousecx, mousecy); +#endif + } + my_kbd_handler (VK_CAPITAL, 0x3a, TRUE); } - my_kbd_handler (VK_CAPITAL, 0x3a, TRUE); - } else { - if (!fullscreen) - setmouseactive (0); - } - break; + else + { + if( !WIN32GFX_IsFullScreen() ) + setmouseactive (0); + else + { + if( WIN32GFX_IsPicassoScreen() ) + { + WIN32GFX_DisablePicasso(); + } + } + } + break; + case WM_ACTIVATE: + minimized = HIWORD( wParam ); + if (LOWORD (wParam) != WA_INACTIVE) + { + write_log( "WinUAE now active via WM_ACTIVATE\n" ); + if( !minimized ) + { + write_log( "Clear_inhibit_frame\n" ); + clear_inhibit_frame( IHF_WINDOWHIDDEN ); + } + ShowWindow (hWnd, SW_RESTORE); + if( WIN32GFX_IsPicassoScreen() ) + { + WIN32GFX_EnablePicasso(); + } + } + else + { + write_log( "WinUAE now inactive via WM_ACTIVATE\n" ); + if( minimized && !quit_program ) + { + write_log( "Set_inhibit_frame\n" ); + set_inhibit_frame( IHF_WINDOWHIDDEN ); + } + } + break; - case WM_ACTIVATE: - if (LOWORD (wParam) != WA_INACTIVE) { - ShowWindow (hWnd, SW_RESTORE); - } - break; + case WM_SETCURSOR: + if( WIN32GFX_IsFullScreen() ) + { +#ifdef HARDWARE_SPRITE_EMULATION + if( !WIN32GFX_IsPicassoScreen() ) +#endif + SetCursor (NULL); + return TRUE; + } + break; - case WM_SETCURSOR: - if (fullscreen) { - SetCursor (NULL); - return TRUE; - } - break; + case WM_SYSCOMMAND: + switch( wParam & 0xFFF0 ) + { + case SC_MAXIMIZE: + WIN32GFX_ToggleFullScreen(); + return 0; + break; + case SC_MINIMIZE: + WIN32GFX_DisablePicasso(); + break; + } + break; - case WM_SYSCOMMAND: - if (wParam == SC_ZOOM) { - toggle_fullscreen (); - return 0; - } - break; + case WM_KEYUP: + case WM_SYSKEYUP: + numkeysdown--; + keysdown[wParam] = 0; + my_kbd_handler (wParam, (lParam >> 16) & 0x1ff, FALSE); + return 0; + break; - case WM_KEYUP: - case WM_SYSKEYUP: - numkeysdown--; - keysdown[wParam] = 0; - my_kbd_handler (wParam, (lParam >> 16) & 0x1ff, FALSE); - break; - - case WM_KEYDOWN: - case WM_SYSKEYDOWN: - if (LOWORD (lParam) == 1) { - if (numkeysdown) { - int key; - numkeysdown = 0; - - for (key = 256; key--;) { - if (keysdown[key]) { - if (checkkey (key, lParam)) - numkeysdown++; - else { - my_kbd_handler (key, (keysdown[key] >> 16) & 0x1ff, FALSE); - keysdown[key] = 0; - } + case WM_KEYDOWN: + case WM_SYSKEYDOWN: + if (LOWORD (lParam) == 1) + { + if (numkeysdown) + { + int key; + numkeysdown = 0; + + for (key = 256; key--;) + { + if (keysdown[key]) + { + if (checkkey (key, lParam)) + numkeysdown++; + else + { + my_kbd_handler (key, (keysdown[key] >> 16) & 0x1ff, FALSE); + keysdown[key] = 0; + } + } } - } } - if (!keysdown[wParam]) { - keysdown[wParam] = lParam; - numkeysdown++; + if (!keysdown[wParam]) + { + keysdown[wParam] = lParam; + numkeysdown++; } numkeysdown++; my_kbd_handler (wParam, (lParam >> 16) & 0x1ff, TRUE); } break; - case WM_LBUTTONDOWN: + case WM_LBUTTONDBLCLK: // According to MSDN, having CS_DBLCLKS in your window-class + // means that the sequence is WM_LBUTTONDOWN, WM_LBUTTONUP, + // WM_LBUTTONDBLCLK, and WM_LBUTTONUP. + // So we need to make WM_LBUTTONDBLCLK act like WM_LBUTTONDOWN. + case WM_LBUTTONDOWN: if (ievent_alive) { setcapture (); buttonstate[0] = 1; - } else if (!fullscreen && !mouseactive) + } else if (!WIN32GFX_IsFullScreen() && !mouseactive) setmouseactive (1); else buttonstate[0] = 1; break; - case WM_LBUTTONUP: + case WM_LBUTTONUP: releasecapture (); buttonstate[0] = 0; break; - case WM_MBUTTONDOWN: + + case WM_MBUTTONDOWN: if (ievent_alive) setcapture (); buttonstate[1] = 1; break; - case WM_MBUTTONUP: + case WM_MBUTTONUP: releasecapture (); buttonstate[1] = 0; break; - case WM_RBUTTONDOWN: + case WM_RBUTTONDOWN: if (ievent_alive) setcapture (); buttonstate[2] = 1; break; - case WM_RBUTTONUP: + case WM_RBUTTONUP: releasecapture (); buttonstate[2] = 0; break; - case WM_MOUSEMOVE: - if ((mouseactive && !ievent_alive) || fullscreen) { - /* - * In this mode, the mouse pointer is always centered in the window, - * this is ensured by the SetCursorPos call below. - * We don't want to handle messages that result from such a SetCursorPos - * call (recursion!), so exit early if we see one. - */ - if (lParam == mousecl) - break; - lastmx += (signed short) LOWORD (lParam) - mousedx; - lastmy += (signed short) HIWORD (lParam) - mousedy; - if (ievent_alive) { - if (lastmx < 0) - lastmx = 0; - if (lastmx > current_width) - lastmx = current_width; - if (lastmy < 0) - lastmy = 0; - if (lastmy > current_height) - lastmy = current_height; + case WM_VSCROLL: + write_log( "WM_VSCROLL\n" ); + if( LOWORD( wParam ) == SB_LINEDOWN ) + record_key(0x7A<<1); + else if( LOWORD( wParam ) == SB_LINEUP ) + record_key(0x7B<<1); + break; + + case WM_MOUSEWHEEL: + wheeldelta = HIWORD(wParam); + write_log( "WM_MOUSEWHEEL with delta %d\n", wheeldelta ); + if( wheeldelta > 0 ) + record_key(0x7A<<1); + else if( wheeldelta < 0 ) + record_key(0x7B<<1); + break; - } - SetCursorPos (mousecx, mousecy); - break; + case WM_MOUSEMOVE: +#ifndef HARDWARE_SPRITE_EMULATION + if( ( mouseactive && !ievent_alive ) || + WIN32GFX_IsFullScreen() ) +#else + if( ( ( mouseactive && !ievent_alive ) || WIN32GFX_IsFullScreen() ) && + !WIN32GFX_IsPicassoScreen() ) +#endif + { + /* + * In this mode, the mouse pointer is always centered in the window, + * this is ensured by the SetCursorPos call below. + * We don't want to handle messages that result from such a SetCursorPos + * call (recursion!), so exit early if we see one. + */ + if (lParam == mousecl) + break; + lastmx += (signed short) LOWORD (lParam) - mousedx; + lastmy += (signed short) HIWORD (lParam) - mousedy; + if (ievent_alive) + { + if (lastmx < 0) + lastmx = 0; + if (lastmx > WIN32GFX_GetWidth() ) + lastmx = WIN32GFX_GetWidth(); + if (lastmy < 0) + lastmy = 0; + if (lastmy > WIN32GFX_GetHeight() ) + lastmy = WIN32GFX_GetHeight(); + } + SetCursorPos (mousecx, mousecy); + break; } lastmx = (signed short) LOWORD (lParam); lastmy = (signed short) HIWORD (lParam); - break; + break; - case WM_PAINT: - hDC = BeginPaint (hWnd, &ps); - clear_inhibit_frame (IHF_WINDOWHIDDEN); - if (hBackDC) - BitBlt (hDC, ps.rcPaint.left, ps.rcPaint.top, - ps.rcPaint.right - ps.rcPaint.left, - ps.rcPaint.bottom - ps.rcPaint.top, hBackDC, - ps.rcPaint.left, ps.rcPaint.top, SRCCOPY); - else - notice_screen_contents_lost (); + case WM_PAINT: + notice_screen_contents_lost (); + hDC = BeginPaint (hWnd, &ps); + /* Check to see if this WM_PAINT is coming while we've got the GUI visible */ + if( manual_painting_needed ) + { + /* Update the display area */ + if( !WIN32GFX_IsFullScreen() ) + { + if( DirectDraw_GetLockableType() != overlay_surface ) + DX_Blit( 0, 0, 0, 0, WIN32GFX_GetWidth(), WIN32GFX_GetHeight(), BLIT_SRC ); + } + else + { + DirectDraw_Blt( primary_surface, NULL, secondary_surface, NULL, DDBLT_WAIT, NULL ); + } + } EndPaint (hWnd, &ps); + break; - case WM_DROPFILES: + case WM_DROPFILES: if (DragQueryFile ((HDROP) wParam, (UINT) - 1, NULL, 0)) { if (DragQueryFile ((HDROP) wParam, 0, NULL, 0) < 255) DragQueryFile ((HDROP) wParam, 0, changed_prefs.df[0], sizeof (changed_prefs.df[0])); @@ -791,59 +518,91 @@ long FAR PASCAL AmigaWindowProc (HWND hW DragFinish ((HDROP) wParam); break; - case WM_CAPTURECHANGED: - if (lParam != hWnd) + case WM_CAPTURECHANGED: + if ((HWND)lParam != hAmigaWnd) buttonstate[0] = buttonstate[1] = buttonstate[2] = 0; break; - case WM_TIMER: -#if 0 - if (wParam == 2) { - KillTimer (hwnd, timer_id); - timer_id = 0; - ClearVisibleAreaAndRefresh (); - } else -#endif - { - finishjob (); - } + case WM_TIMER: + finishjob (); break; - case WM_USER + 0x200: - DoSomeWeirdPrintingStuff(wParam); + case WM_CREATE: + DragAcceptFiles (hWnd, TRUE); break; - case WM_USER + 0x201: - changemode = 2; - destroy_window (1); - break; + case WM_CLOSE: + uae_quit (); + return 0; - case WM_CREATE: - DragAcceptFiles (hWnd, TRUE); + case WM_WINDOWPOSCHANGED: + if( GetWindowRect( hWnd, &amigawin_rect) ) + { + if( hMainWnd ) + { + if( hWinUAEKey && store_xy++) + { + RegSetValueEx( hWinUAEKey, "xPos", 0, REG_DWORD, (LPBYTE)&amigawin_rect.left, sizeof( LONG ) ); + RegSetValueEx( hWinUAEKey, "yPos", 0, REG_DWORD, (LPBYTE)&amigawin_rect.top, sizeof( LONG ) ); + } + } + } break; - case WM_DESTROY: - changemode = 3; - destroy_window (0); - break; + case WM_MOVING: + case WM_MOVE: + WIN32GFX_WindowMove(); + return TRUE; + + case WM_SIZING: + WIN32GFX_WindowSize(); + return TRUE; + case WM_SIZE: + WIN32GFX_WindowSize(); + return 0; + + case WM_GETMINMAXINFO: + rect.left=0; + rect.top=0; + lpmmi=(LPMINMAXINFO)lParam; + rect.right=320; + rect.bottom=256; + //AdjustWindowRectEx(&rect,WSTYLE,0,0); + lpmmi->ptMinTrackSize.x=rect.right-rect.left; + lpmmi->ptMinTrackSize.y=rect.bottom-rect.top; + return 0; + + default: +#if 0 +#ifdef BSDSOCKET_SUPPORTED + if( message >= 0xB000 && message < 0xB000+MAXPENDINGASYNC*2 ) + { +#if DEBUG_SOCKETS + write_log( "sockmsg(0x%x, 0x%x, 0x%x)\n", message, wParam, lParam ); +#endif + sockmsg( message, wParam, lParam ); + return 0; + } +#endif +#endif + break; } return DefWindowProc (hWnd, message, wParam, lParam); } -long FAR PASCAL MainWindowProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +static long FAR PASCAL MainWindowProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; - RECT rc, rc2; + RECT rc; HDC hDC; - if (changemode != 0) - return DefWindowProc (hWnd, message, wParam, lParam); - switch (message) { case WM_LBUTTONDOWN: + case WM_MOUSEWHEEL: case WM_MOUSEMOVE: case WM_ACTIVATEAPP: + case WM_DROPFILES: case WM_ACTIVATE: case WM_SETCURSOR: case WM_SYSCOMMAND: @@ -856,53 +615,53 @@ long FAR PASCAL MainWindowProc (HWND hWn case WM_MBUTTONUP: case WM_RBUTTONDOWN: case WM_RBUTTONUP: - case WM_DROPFILES: + case WM_MOVING: + case WM_MOVE: + case WM_SIZING: + case WM_SIZE: + case WM_GETMINMAXINFO: case WM_CREATE: case WM_DESTROY: case WM_USER + 0x200: - case WM_USER + 0x201: + case WM_CLOSE: + case WM_HELP: + case WM_DEVICECHANGE: return AmigaWindowProc (hWnd, message, wParam, lParam); case WM_DISPLAYCHANGE: - if (!fullscreen && !changemode && (wParam + 7) / 8 != current_pixbytes) - displaychange (); + if (!WIN32GFX_IsFullScreen && (wParam + 7) / 8 != DirectDraw_GetBytesPerPixel() ) + WIN32GFX_DisplayChangeRequested(); break; case WM_ENTERSIZEMOVE: - if (!fullscreen) { - frame_do_semup = 1; - set_inhibit_frame (5); - uae_sem_wait (&frame_sem); - } + in_sizemove++; break; case WM_EXITSIZEMOVE: - clear_inhibit_frame (5); + in_sizemove--; /* fall through */ case WM_WINDOWPOSCHANGED: - GetWindowRect (hAmigaWnd, &amigawin_rect); + WIN32GFX_WindowMove(); + if( hAmigaWnd && GetWindowRect (hAmigaWnd, &amigawin_rect) ) + { + if (in_sizemove > 0) + break; - if (!fullscreen && hAmigaWnd) { - if (current_pixbytes == 2) { - if (amigawin_rect.left & 1) { - GetWindowRect (hMainWnd, &rc2); - if (1 /*!mon || rc2.left + 4 < GetSystemMetrics (SM_CXSCREEN)*/) - MoveWindow (hMainWnd, rc2.left + 1, rc2.top, + if( !WIN32GFX_IsFullScreen() && hAmigaWnd ) + { + if( amigawin_rect.left & 3 ) + { + RECT rc2; + if( GetWindowRect( hMainWnd, &rc2 ) ) + { + MoveWindow (hMainWnd, rc2.left + 4 - amigawin_rect.left % 4, rc2.top, rc2.right - rc2.left, rc2.bottom - rc2.top, TRUE); - } - } else if (current_pixbytes == 3) { - if (amigawin_rect.left >= 0) { - if (amigawin_rect.left & 3) { - GetWindowRect (hMainWnd, &rc2); - if (1 /*!mon || rc2.left + 4 < GetSystemMetrics (SM_CXSCREEN)*/) - MoveWindow (hMainWnd, rc2.left - amigawin_rect.left % 4, rc2.top, - rc2.right - rc2.left, rc2.bottom - rc2.top, TRUE); } } + //setmouseactive (0); + return 0; } - setmouseactive (0); - return 0; } break; @@ -910,977 +669,934 @@ long FAR PASCAL MainWindowProc (HWND hWn hDC = BeginPaint (hWnd, &ps); GetClientRect (hWnd, &rc); DrawEdge (hDC, &rc, EDGE_SUNKEN, BF_RECT); - EndPaint (hWnd, &ps); break; - case WM_NCLBUTTONDBLCLK: if (wParam == HTCAPTION) { - toggle_fullscreen (); + WIN32GFX_ToggleFullScreen(); return 0; } + break; + default: + break; + } return DefWindowProc (hWnd, message, wParam, lParam); } -static int HasConsole; -static HANDLE stdouthandle; -static HANDLE debugfile; - -/* Console Win32 helper routines */ -void activate_debugger (); - -static BOOL __stdcall ctrlchandler (DWORD type) +void handle_events (void) { - SetConsoleCtrlHandler ((PHANDLER_ROUTINE) ctrlchandler, FALSE); + MSG msg; - if (type == CTRL_C_EVENT) { - activate_debugger (); - return TRUE; + while (PeekMessage (&msg, 0, 0, 0, PM_REMOVE)) { + TranslateMessage (&msg); + DispatchMessage (&msg); } - return FALSE; } +/* Console Win32 helper routines */ +void activate_debugger (); + +/* We're not a console-app anymore! */ void setup_brkhandler (void) { - SetConsoleCtrlHandler ((PHANDLER_ROUTINE) ctrlchandler, TRUE); } void remove_brkhandler (void) { - SetConsoleCtrlHandler ((PHANDLER_ROUTINE) ctrlchandler, FALSE); -} - -int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, - int nCmdShow) -{ - char *posn; - int i; - - hInst = hInstance; - - debugfile = CreateFile ("outfile", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, - 0, NULL); - - for (i = 0; i < NUM_DRIVES; i++) { - drives[i].path[0] = 0; - drives[i].name[0] = 0; - drives[i].rw = TRUE; - } - - /* Get our executable's root-path */ - start_path = xmalloc(MAX_PATH); - GetModuleFileName (hInst, start_path, MAX_PATH); - if (posn = strrchr (start_path, '\\')) - *posn = 0; - - - HasConsole = 0;/*AllocConsole ();*/ - if (HasConsole) - stdouthandle = GetStdHandle (STD_OUTPUT_HANDLE); - - write_log ("UAE " UAEWINVERSION " Win32/DirectX, release " UAEWINRELEASE "\n"); - strcpy (VersionStr, PROGNAME); - write_log ("\n(c) 1995-1997 Bernd Schmidt - Core UAE concept and implementation." - "\n(c) 1996-1997 Mathias Ortmann - Win32 port and enhancements." - "\n(c) 1996-1997 Brian King - Picasso96 and AHI support, GUI.\n" - "\nPress F12 to show the Settings Dialog (GUI), Alt-F4 to quit.\n" - "\nhttp://www.informatik.tu-muenchen.de/~ortmann/uae/\n\n"); - - currprefs.copper_pos = -1; - /*initgfxspecs();*/ - if (initlibs ()) - real_main (__argc, __argv); - cleanuplibs(); - - if (HasConsole) - FreeConsole (); - - return FALSE; } -static int register_classes (void) +int WIN32_RegisterClasses( void ) { WNDCLASS wc; + HDC hDC = GetDC( NULL ); - wc.style = 0; + if( GetDeviceCaps( hDC, NUMCOLORS ) != -1 ) + g_dwBackgroundColor = RGB( 255, 0, 255 ); + ReleaseDC( NULL, hDC ); + + wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_DBLCLKS; wc.lpfnWndProc = AmigaWindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = 0; - wc.hIcon = LoadIcon (GetModuleHandle (NULL), IDI_APPICON); + wc.hIcon = LoadIcon (GetModuleHandle (NULL), MAKEINTRESOURCE( IDI_APPICON ) ); wc.hCursor = LoadCursor (NULL, IDC_ARROW); - wc.hbrBackground = GetStockObject (BLACK_BRUSH); - wc.lpszMenuName = NULL; + wc.lpszMenuName = 0; wc.lpszClassName = "AmigaPowah"; + wc.hbrBackground = CreateSolidBrush( g_dwBackgroundColor ); if (!RegisterClass (&wc)) return 0; - wc.style = 0; + wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = MainWindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = 0; - wc.hIcon = LoadIcon (GetModuleHandle (NULL), IDI_APPICON); + wc.hIcon = LoadIcon (GetModuleHandle (NULL), MAKEINTRESOURCE( IDI_APPICON ) ); wc.hCursor = LoadCursor (NULL, IDC_ARROW); - wc.hbrBackground = GetStockObject (BLACK_BRUSH); - wc.lpszMenuName = NULL; + wc.hbrBackground = CreateSolidBrush( g_dwBackgroundColor ); + wc.lpszMenuName = 0; wc.lpszClassName = "PCsuxRox"; if (!RegisterClass (&wc)) return 0; return 1; } -int graphics_setup (void) -{ - DWORD ddrval; - - if (!register_classes ()) - return 0; +#ifdef __GNUC__ +#undef WINAPI +#define WINAPI +#endif - uae_sem_init (&picasso_switch_sem, 0, 0); - return 1; -} +static HINSTANCE hRichEdit = NULL, hHtmlHelp = NULL; -#define NORMAL_WINDOW_STYLE (WS_VISIBLE | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX) +#ifdef USE_ZLIB_DLL +static HINSTANCE hZlib = NULL; +FARPROC pgzread = NULL, pgzopen = NULL, pgzclose = NULL, pgzwrite = NULL, pgzerror = NULL; +#endif -static int create_windows (void) +int WIN32_CleanupLibraries( void ) { - POINT pt; - - if (!fullscreen) { - RECT rc; - - rc.left = 0; - rc.top = 0; - rc.right = current_width; - rc.bottom = current_height; - rc.right += 4; - rc.bottom += 4; - AdjustWindowRect (&rc, NORMAL_WINDOW_STYLE, FALSE); - - hMainWnd = CreateWindowEx (WS_EX_ACCEPTFILES, - "PCsuxRox", - TITLETEXT, - NORMAL_WINDOW_STYLE, - CW_USEDEFAULT, CW_USEDEFAULT, - rc.right - rc.left, rc.bottom - rc.top, - NULL, - NULL, - 0, - NULL); + if (hRichEdit) + FreeLibrary (hRichEdit); + + if( hHtmlHelp ) + FreeLibrary( hHtmlHelp ); + + if( hUIDLL ) + FreeLibrary( hUIDLL ); + +#ifdef USE_ZLIB_DLL + if( hZlib ) + FreeLibrary( hZlib ); +#endif - if (! hMainWnd) - return 0; - } else - hMainWnd = NULL; + return 1; +} - hAmigaWnd = CreateWindowEx (fullscreen ? WS_EX_TOPMOST : WS_EX_ACCEPTFILES, - "AmigaPowah", - PROGNAME, - hMainWnd ? WS_VISIBLE | WS_CHILD : WS_VISIBLE | WS_POPUP, - hMainWnd ? 2 : CW_USEDEFAULT, hMainWnd ? 2 : CW_USEDEFAULT, - fullscreen ? GetSystemMetrics (SM_CXSCREEN) : current_width, - fullscreen ? GetSystemMetrics (SM_CYSCREEN) : current_height, - hMainWnd, - NULL, - 0, - NULL); - - if (!hAmigaWnd) { - if (hMainWnd) - DestroyWindow (hMainWnd); - return 0; +/* HtmlHelp Initialization - optional component */ +int WIN32_InitHtmlHelp( void ) +{ + int result = 0; + if( hHtmlHelp = LoadLibrary( "HHCTRL.OCX" ) ) + { + pHtmlHelp = ( HWND(WINAPI *)(HWND, LPCSTR, UINT, LPDWORD ) )GetProcAddress( hHtmlHelp, "HtmlHelpA" ); + result = 1; } - if (hMainWnd) - UpdateWindow (hMainWnd); - if (hAmigaWnd) - UpdateWindow (hAmigaWnd); - return 1; + return result; } - -void doPreInit( void ) -{ - void *blah; - DWORD ddrval; -#ifdef __GNUC__ - ddrval = (*pDirectDrawCreate)(NULL,&lpDD,NULL); -#else - ddrval = DirectDrawCreate( NULL, &lpDD, NULL ); -#endif - if (ddrval == DD_OK) - { - //IDirectDraw2_QueryInterface( lpDD, &IID_IDirectDraw2, &blah ); - - mode_count = DX_FillResolutions( &picasso96_pixel_format ); - - // If we've got no command-line arguments, then we use the integrated-GUI - if( ( __argc == 1 ) && - ( GetSettings() == FALSE ) ) - { - MyOutputDebugString("GetSettings() trying to quit...\n"); - shutdownmain(); - } - } -} -BOOL doInit (void) -{ - if (! create_windows ()) - return 0; -#ifdef PICASSO96 - if (screen_is_picasso) { - if (!set_ddraw (current_width, current_height, fullscreen, &picasso_vidinfo.depth, - (LPPALETTEENTRY)&picasso96_state.CLUT)) - goto oops; - picasso_vidinfo.rowbytes = ddsd.lPitch; - } else -#endif - { - gfxvidinfo.pixbytes = 2; - if (!set_ddraw (current_width, current_height, fullscreen, &gfxvidinfo.pixbytes, colors256)) - goto oops; - gfxvidinfo.bufmem = 0; - gfxvidinfo.linemem = 0; - gfxvidinfo.maxblocklines = 0; - gfxvidinfo.width = current_width; - gfxvidinfo.height = current_height; - gfxvidinfo.rowbytes = ddsd.lPitch; - gfxvidinfo.can_double = 1; - } - - if (fullscreen) { - scrindirect = 0; - gfxvidinfo.linemem = 0; - mousecx = 160, mousecy = 100, mousedx = 160, mousedy = 100, mousecl = MAKELONG (160, 100); - } - - if (! do_surfacelock ()) - goto oops; - unlockscr (); - - if ((ddsd.ddpfPixelFormat.dwFlags & (DDPF_RGB | DDPF_PALETTEINDEXED8 | DDPF_RGBTOYUV)) != 0) - { - MyOutputDebugString ("%s mode (bits: %d, pixbytes: %d)\n", fullscreen ? "Full screen" : "Window", - ddsd.ddpfPixelFormat.dwRGBBitCount, current_pixbytes); -#ifdef PICASSO96 - if( ddsd.ddpfPixelFormat.dwRBitMask == 0x0000F800 ) - picasso96_pixel_format |= RGBFF_R5G6B5PC; - else if( ddsd.ddpfPixelFormat.dwRBitMask == 0x00007C00 ) - picasso96_pixel_format |= RGBFF_R5G5B5PC; - else if( ddsd.ddpfPixelFormat.dwBBitMask == 0x0000F800 ) - picasso96_pixel_format |= RGBFF_B5G6R5PC; - else - picasso96_pixel_format |= RGBFF_B5G5R5PC; -#endif - } else { - MyOutputDebugString ("Error: Unsupported pixel format - use a different screen mode\n"); - goto oops; - } -#ifdef PICASSO96 - if (screen_is_picasso) - DX_SetPalette (0, 256); - else +#if 0 +#define TESTING_LANGUAGES +#define TEST_LANGID LANG_GERMAN +//#define TEST_LANGID LANG_FRENCH +//#define TEST_LANGID LANG_TURKISH #endif - init_colors (); - - if (!fullscreen) - MainWindowProc (0, WM_WINDOWPOSCHANGED, 0, 0); - return 1; -oops: - if (hMainWnd) - DestroyWindow (hMainWnd); - if (hAmigaWnd) - DestroyWindow (hAmigaWnd); - return 0; -} +static HMODULE LoadGUI( void ) +{ + HMODULE result = NULL; + LPCTSTR dllname = NULL; + LANGID language = GetUserDefaultLangID() & 0x3FF; // low 9-bits form the primary-language ID +#ifdef TESTING_LANGUAGES + language = TEST_LANGID; +#endif -struct myRGNDATA { - RGNDATAHEADER rdh; - RECT rects[640]; /* fixed buffers suck, but this is _very_ unlikely to overflow */ -} ClipList = { { - sizeof (ClipList), RDH_RECTANGLES, 0, 640 * sizeof (RECT) -} }; - - -/* this is the way the display line is put to screen - * if the display is not 16 bits deep or the window is not fully visible */ -static void clipped_linetoscr (char *dst, char *src, int y) -{ - LPRECT lpRect = ClipList.rects; - int i; - - switch (current_pixbytes) { - case 1: - for (i = ClipList.rdh.nCount; i--; lpRect++) { - if (y >= lpRect->top && y < lpRect->bottom) { - memcpy (dst + lpRect->left, src + lpRect->left, lpRect->right); - } - } + switch( language ) + { + case LANG_AFRIKAANS: + dllname = "WinUAE_Afrikaans.dll"; break; - - case 2: - for (i = ClipList.rdh.nCount; i--; lpRect++) { - if (y >= lpRect->top && y < lpRect->bottom) { - memcpy (dst + lpRect->left*2, src + lpRect->left*2, lpRect->right*2); - } - } + case LANG_ARABIC: + dllname = "WinUAE_Arabic.dll"; break; - - case 3: - for (i = ClipList.rdh.nCount; i--; lpRect++) { - if (y >= lpRect->top && y < lpRect->bottom) { - memcpy (dst + lpRect->left*3, src + lpRect->left*3, lpRect->right*3); - } - } + case LANG_ARMENIAN: + dllname = "WinUAE_Armenian.dll"; + break; + case LANG_ASSAMESE: + dllname = "WinUAE_Assamese.dll"; + break; + case LANG_AZERI: + dllname = "WinUAE_Azeri.dll"; + break; + case LANG_BASQUE: + dllname = "WinUAE_Basque.dll"; + break; + case LANG_BELARUSIAN: + dllname = "WinUAE_Belarusian.dll"; + break; + case LANG_BENGALI: + dllname = "WinUAE_Bengali.dll"; + break; + case LANG_BULGARIAN: + dllname = "WinUAE_Bulgarian.dll"; + break; + case LANG_CATALAN: + dllname = "WinUAE_Catalan.dll"; + break; + case LANG_CHINESE: + dllname = "WinUAE_Chinese.dll"; break; + case LANG_CROATIAN: + dllname = "WinUAE_CroatianSerbian.dll"; + break; + case LANG_CZECH: + dllname = "WinUAE_Czech.dll"; + break; + case LANG_DANISH: + dllname = "WinUAE_Danish.dll"; + break; + case LANG_DUTCH: + dllname = "WinUAE_Dutch.dll"; + break; + case LANG_ESTONIAN: + dllname = "WinUAE_Estonian.dll"; + break; + case LANG_FAEROESE: + dllname = "WinUAE_Faeroese.dll"; + break; + case LANG_FARSI: + dllname = "WinUAE_Farsi.dll"; + break; + case LANG_FINNISH: + dllname = "WinUAE_Finnish.dll"; + break; + case LANG_FRENCH: + dllname = "WinUAE_French.dll"; + break; + case LANG_GEORGIAN: + dllname = "WinUAE_Georgian.dll"; + break; + case LANG_GERMAN: + dllname = "WinUAE_German.dll"; + break; + case LANG_GREEK: + dllname = "WinUAE_Greek.dll"; + break; + case LANG_GUJARATI: + dllname = "WinUAE_Gujarati.dll"; + break; + case LANG_HEBREW: + dllname = "WinUAE_Hebrew.dll"; + break; + case LANG_HINDI: + dllname = "WinUAE_Hindi.dll"; + break; + case LANG_HUNGARIAN: + dllname = "WinUAE_Hungarian.dll"; + break; + case LANG_ICELANDIC: + dllname = "WinUAE_Icelandic.dll"; + break; + case LANG_INDONESIAN: + dllname = "WinUAE_Indonesian.dll"; + break; + case LANG_ITALIAN: + dllname = "WinUAE_Italian.dll"; + break; + case LANG_JAPANESE: + dllname = "WinUAE_Japanese.dll"; + break; + case LANG_KANNADA: + dllname = "WinUAE_Kannada.dll"; + break; + case LANG_KASHMIRI: + dllname = "WinUAE_Kashmiri.dll"; + break; + case LANG_KAZAK: + dllname = "WinUAE_Kazak.dll"; + break; + case LANG_KONKANI: + dllname = "WinUAE_Konkani.dll"; + break; + case LANG_KOREAN: + dllname = "WinUAE_Korean.dll"; + break; + case LANG_LATVIAN: + dllname = "WinUAE_Latvian.dll"; + break; + case LANG_LITHUANIAN: + dllname = "WinUAE_Lithuanian.dll"; + break; + case LANG_MACEDONIAN: + dllname = "WinUAE_Macedonian.dll"; + break; + case LANG_MALAY: + dllname = "WinUAE_Malay.dll"; + break; + case LANG_MALAYALAM: + dllname = "WinUAE_Malayalam.dll"; + break; + case LANG_MANIPURI: + dllname = "WinUAE_Manipuri.dll"; + break; + case LANG_MARATHI: + dllname = "WinUAE_Marathi.dll"; + break; + case LANG_NEPALI: + dllname = "WinUAE_Nepali.dll"; + break; + case LANG_NORWEGIAN: + dllname = "WinUAE_Norwegian.dll"; + break; + case LANG_ORIYA: + dllname = "WinUAE_Oriya.dll"; + break; + case LANG_POLISH: + dllname = "WinUAE_Polish.dll"; + break; + case LANG_PORTUGUESE: + dllname = "WinUAE_Portuguese.dll"; + break; + case LANG_PUNJABI: + dllname = "WinUAE_Punjabi.dll"; + break; + case LANG_ROMANIAN: + dllname = "WinUAE_Romanian.dll"; + break; + case LANG_RUSSIAN: + dllname = "WinUAE_Russian.dll"; + break; + case LANG_SANSKRIT: + dllname = "WinUAE_Sanskrit.dll"; + break; + case LANG_SINDHI: + dllname = "WinUAE_Sindhi.dll"; + break; + case LANG_SLOVAK: + dllname = "WinUAE_Slovak.dll"; + break; + case LANG_SLOVENIAN: + dllname = "WinUAE_Slovenian.dll"; + break; + case LANG_SPANISH: + dllname = "WinUAE_Spanish.dll"; + break; + case LANG_SWAHILI: + dllname = "WinUAE_Swahili.dll"; + break; + case LANG_SWEDISH: + dllname = "WinUAE_Swedish.dll"; + break; + case LANG_TAMIL: + dllname = "WinUAE_Tamil.dll"; + break; + case LANG_TATAR: + dllname = "WinUAE_Tatar.dll"; + break; + case LANG_TELUGU: + dllname = "WinUAE_Telugu.dll"; + break; + case LANG_THAI: + dllname = "WinUAE_Thai.dll"; + break; + case LANG_TURKISH: + dllname = "WinUAE_Turkish.dll"; + break; + case LANG_UKRAINIAN: + dllname = "WinUAE_Ukrainian.dll"; + break; + case LANG_URDU: + dllname = "WinUAE_Urdu.dll"; + break; + case LANG_UZBEK: + dllname = "WinUAE_Uzbek.dll"; + break; + case LANG_VIETNAMESE: + dllname = "WinUAE_Vietnamese.dll"; + break; + case 0x400: + dllname = "guidll.dll"; + break; + } - case 4: - for (i = ClipList.rdh.nCount; i--; lpRect++) { - if (y >= lpRect->top && y < lpRect->bottom) { - memcpy (dst + lpRect->left*4, src + lpRect->left*4, lpRect->right*4); + if( dllname ) + { + TCHAR szFilename[ MAX_PATH ]; + DWORD dwVersionHandle, dwFileVersionInfoSize; + LPVOID lpFileVersionData = NULL; + BOOL success = FALSE; + result = LoadLibrary( dllname ); + if( result && GetModuleFileName( result, (LPTSTR)&szFilename, MAX_PATH ) ) + { + dwFileVersionInfoSize = GetFileVersionInfoSize( szFilename, &dwVersionHandle ); + if( dwFileVersionInfoSize ) + { + if( lpFileVersionData = calloc( 1, dwFileVersionInfoSize ) ) + { + if( GetFileVersionInfo( szFilename, dwVersionHandle, dwFileVersionInfoSize, lpFileVersionData ) ) + { + VS_FIXEDFILEINFO *vsFileInfo = NULL; + UINT uLen; + if( VerQueryValue( lpFileVersionData, TEXT("\\"), (void **)&vsFileInfo, &uLen ) ) + { + if( vsFileInfo && + ( HIWORD(vsFileInfo->dwProductVersionMS) == UAEMAJOR ) + && ( LOWORD(vsFileInfo->dwProductVersionMS) == UAEMINOR ) + && ( HIWORD(vsFileInfo->dwProductVersionLS) == UAESUBREV ) +// Change this to an #if 1 when the WinUAE Release version (as opposed to UAE-core version) +// requires a GUI-DLL change... +#if 0 + && ( LOWORD(vsFileInfo->dwProductVersionLS) == WINUAERELEASE) +#endif + ) + { + success = TRUE; + } + } + } + free( lpFileVersionData ); + } } } - break; + if( result && !success ) + { + FreeLibrary( result ); + result = NULL; + } } -} - -void flush_line(int lineno) -{ - if (scrindirect) - clipped_linetoscr(gfxvidinfo.bufmem + lineno * gfxvidinfo.rowbytes, - scrlinebuf, lineno); -} -void flush_block(int a, int b) -{ -} - -void flush_screen(int a, int b) -{ + return result; } -char *lockscr (void) +#ifndef _WIN32_WCE +/* try to load COMDLG32 and DDRAW, initialize csDraw */ +int WIN32_InitLibraries( void ) { - char *surface, *oldsurface; - DWORD tmp; - LPRECT lpRect; - - if (!do_surfacelock ()) - return NULL; - - surface = ddsd.lpSurface; - oldsurface = gfxvidinfo.bufmem; - if (!fullscreen) { - surface += amigawin_rect.top * ddsd.lPitch + current_pixbytes * amigawin_rect.left; - } - gfxvidinfo.bufmem = surface; - if (surface != oldsurface && ! screen_is_picasso) { - write_log ("Need to init_row_map\n"); - init_row_map (); - } - - scrindirect = 0; - - if (fullscreen) { - set_linemem (); - clear_inhibit_frame (IHF_WINDOWHIDDEN); - return surface; + int result = 1; + /* Determine our processor speed and capabilities */ + figure_processor_speed(); + + /* Make sure we do an InitCommonControls() to get some advanced controls */ + InitCommonControls(); + + hRichEdit = LoadLibrary( "RICHED32.DLL" ); + + hUIDLL = LoadGUI(); + +#ifdef USE_ZLIB_DLL + hZlib = LoadLibrary( "ZLIB.DLL" ); + if( hZlib ) + { + pgzread = GetProcAddress( hZlib, "gzread" ); + pgzopen = GetProcAddress( hZlib, "gzopen" ); + pgzclose = GetProcAddress( hZlib, "gzclose" ); + pgzwrite = GetProcAddress( hZlib, "gzwrite" ); + pgzerror = GetProcAddress( hZlib, "gzerror" ); + if( !pgzread || !pgzopen || !pgzclose || !pgzwrite || !pgzerror) + { + FreeLibrary( hZlib ); + hZlib = NULL; + } } +#endif + return result; +} +#endif - tmp = sizeof (ClipList.rects); +/* Mathias says: "this truly sucks, I'll include a native gunzip() routine soon" */ - /* This is the VERY instruction that drags other threads (input/file system) down when in windowed - * mode - WHY can't Microsoft implement the IsClipListChanged() method as documented? ARGH! */ - if (IDirectDrawClipper_GetClipList (lpDDC, NULL, (LPRGNDATA) & ClipList, &tmp) == DD_OK) { - lpRect = ClipList.rects; +#ifdef USE_ZLIB_DLL +extern FARPROC pgzread, pgzopen, pgzclose, pgzwrite, pgzerror; +#define GZOPEN( X, Y ) (gzFile)pgzopen( X, Y ) +#define GZCLOSE( X ) (int)pgzclose( X ) +#define GZREAD( X, Y, Z ) (int)pgzread( X, Y, Z ) + +#define ZLIB_BUFFER_SIZE 32767 + +/* gzip decompression via zlib */ +static int zlib_gunzip( const char *src, char *dst ) +{ + int result = 0, gzResult = 0; + gzFile zSrc = NULL; + FILE *fDst = NULL; + size_t filesize = 0; + uae_u8 *buffer = NULL; - if (!ClipList.rdh.nCount) { - write_log("ClipList empty\n"); - set_inhibit_frame (IHF_WINDOWHIDDEN); - unlockscr (); - return 0; + if( hZlib ) + { + zSrc = GZOPEN( src, "rb" ); + fDst = fopen( dst, "wb" ); + buffer = xmalloc( ZLIB_BUFFER_SIZE + 1 ); + + if( zSrc && fDst && buffer ) + { + DWORD dwWritten = 0; + result = 1; + do + { + gzResult = GZREAD( zSrc, buffer, ZLIB_BUFFER_SIZE ); + if( gzResult > 0 ) + { + if( fwrite( buffer, gzResult, 1, fDst ) != 1 ) + { + result = 0; + break; + } + } + } while( gzResult == ZLIB_BUFFER_SIZE ); } - - if (ClipList.rdh.nCount != 1 - || lpRect->right - lpRect->left != current_width - || lpRect->bottom - lpRect->top != current_height) + + if( zSrc ) { - scrindirect = 1; - for (tmp = ClipList.rdh.nCount; tmp--; lpRect++) { - lpRect->left -= amigawin_rect.left; - lpRect->right -= amigawin_rect.left; - lpRect->top -= amigawin_rect.top; - lpRect->bottom -= amigawin_rect.top; - - lpRect->right -= lpRect->left; - } + GZCLOSE( zSrc ); } - } - - set_linemem (); - clear_inhibit_frame (IHF_WINDOWHIDDEN); - return surface; -} - -int graphics_init (void) -{ - static int first_time = 1; - if (first_time) - figure_processor_speed (); - first_time = 0; -#ifdef PICASSO96 - if (screen_is_picasso) { - fullscreen = picasso_fullscreen; - current_width = picasso_vidinfo.width; - current_height = picasso_vidinfo.height; - } else -#endif - { - fullscreen = amiga_fullscreen; - current_width = currprefs.gfx_width; - current_height = currprefs.gfx_height; - - if (!fullscreen) { - if (current_height > 290 << currprefs.gfx_linedbl) - current_height = 290 << currprefs.gfx_linedbl; - if (current_width > 800 >> currprefs.gfx_lores) - current_width = 800 >> currprefs.gfx_lores; + + if( fDst ) + { + fclose( fDst ); } - current_width = (current_width + 7) & ~7; } - - if (!doInit ()) - return 0; - - *xcolors = 0; - - return 1; + return result; } +#endif -void graphics_leave (void) -{ - dumpcustom (); -} - -void shutdownmain (void) -{ - changemode = 3; - PostMessage (hAmigaWnd, WM_QUIT, 0, 0); -} - -void workthread(void) -{ - if (use_debugger && debuggable ()) - activate_debugger (); - - do_start_program(); - shutdownmain(); -} +static char *uncompress_error[2] = { "Error: You need zlib.dll to use .adz/.roz files!\n", + "Error: You need xdms.exe (32 bit) to use .dms files!\n" }; -void start_program (void) +int uncompress_hack( int type, const char *src, const char *dst) { - DWORD id; - MSG msg; + int result = 0; + char fullname[1024]; + char buf[1024]; + char cmd[256]; + char *posn = NULL; + STARTUPINFO si = {sizeof si}; + PROCESS_INFORMATION pi; - SetPriorityClass (GetCurrentProcess (), process_desired_pri); + strcpy( fullname, dst ); - hEmuThread = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) workthread, 0, CREATE_SUSPENDED, &id); - SetThreadPriority (hEmuThread, THREAD_PRIORITY_BELOW_NORMAL); - ResumeThread (hEmuThread); - - for (;;) { - int cm; - while (GetMessage (&msg, NULL, 0, 0)) { - TranslateMessage (&msg); - DispatchMessage (&msg); + if( type == 1 ) + { +#ifdef USE_ZLIB_DLL + result = zlib_gunzip( src, fullname ); + if( !result ) + { + gui_message( uncompress_error[type-1] ); } - cm = changemode; - if (cm == 3) - break; + return result; +#else + strcpy( cmd, "gzip.exe -f -d" ); + strcat( fullname, ".gz" ); +#endif + } + else if( type == 2 ) + { + strcpy( cmd, "xdms.exe u" ); + posn = strrchr( fullname, '.' ); + if( posn ) + { + *posn = 0; + strcat( fullname, ".dms" ); + } + } - changemode = 0; - current_pixbytes = 0; - if (!graphics_init ()) - break; + if( CopyFile( src, fullname, FALSE ) ) + { + sprintf (buf, "%s %s +%s", cmd, fullname, dst ); + si.dwFlags = STARTF_USESTDHANDLES; + if( CreateProcess( NULL, buf, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi ) ) + { + WaitForSingleObject( pi.hProcess, INFINITE ); + result = -1; + } + else + { + gui_message( uncompress_error[type-1] ); + } + } - if (cm == 2) { - uae_sem_post (&picasso_switch_sem); - } - clear_inhibit_frame (5); - notice_screen_contents_lost (); - notice_new_xcolors (); + /* Special handling for broken xdms.exe */ + if( type == 2 ) + { + DeleteFile( fullname ); /* Delete the uaeXX.dms file */ + } - notice_new_xcolors (); + return result; +} - /*ResumeThread (hEmuThread);*/ +/* console window for debugging messages */ +/* Brian: disable for release version if you want (TW) */ - if (currprefs.produce_sound > 1) - startsound (); - } -} +#define WRITE_LOG_BUF_SIZE 4096 -void handle_events (void) -{ -} +static int consoleopen = 0; +HANDLE stdinput,stdoutput; -#ifdef CONFIG_FOR_SMP -int uae_sem_initcs (LPCRITICAL_SECTION * cs) +static void openconsole(void) { - *cs = (LPCRITICAL_SECTION) GlobalAlloc (GPTR, sizeof csDraw); - InitializeCriticalSection (*cs); + if(consoleopen) return; + AllocConsole(); + stdinput=GetStdHandle(STD_INPUT_HANDLE); + stdoutput=GetStdHandle(STD_OUTPUT_HANDLE); + SetConsoleMode(stdinput,ENABLE_PROCESSED_INPUT|ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT|ENABLE_PROCESSED_OUTPUT); + consoleopen = 1; } -void uae_sem_enter (LPCRITICAL_SECTION cs) -{ - EnterCriticalSection (cs); -} +/* console functions for debugger */ -void uae_sem_leave (LPCRITICAL_SECTION cs) +void console_out (const char *format,...) { - LeaveCriticalSection (cs); -} + va_list parms; + char buffer[WRITE_LOG_BUF_SIZE]; + DWORD temp; -void uae_sleep (int ms) -{ - Sleep (ms); + va_start (parms, format); + _vsnprintf( buffer, WRITE_LOG_BUF_SIZE-1, format, parms ); + va_end (parms); + openconsole(); + WriteConsole(stdoutput,buffer,strlen(buffer),&temp,0); } -#endif - -/* this is the semaphore for protecting the actual drawing against intermittent window movements */ -void begindrawing (void) +int console_get (char *out, int maxlen) { - EnterCriticalSection (&csDraw); + DWORD len,totallen; + + totallen=0; + while(maxlen>0) + { + ReadConsole(stdinput,out,1,&len,0); + if(*out == 13) break; + out++; + maxlen--; + totallen++; + } + *out=0; + return totallen; } -void enddrawing (void) +void console_flush (void) { - LeaveCriticalSection (&csDraw); } -/* this truly sucks, I'll include a native gunzip() routine soon */ -int gunzip_hack (const char *src, const char *dst) +/* GCC/EGCS wants this write_log in order to work from socket-land and to do traces */ +#ifdef __GNUC__ +void write_log (const char *format, ...) { - char buf[1024]; - STARTUPINFO si = - {sizeof si}; - PROCESS_INFORMATION pi; - - strcpy (buf, dst); - strcat (buf, ".gz"); + int result = 0; + DWORD numwritten; + char buffer[12]; + va_list parms; + int count = 0; + int *blah = NULL; - if (CopyFile (src, buf, FALSE)) { - sprintf (buf, "gzip -f -d \"%s.gz\"", dst); - si.dwFlags = STARTF_USESTDHANDLES; - if (CreateProcess (NULL, buf, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) { - WaitForSingleObject (pi.hProcess, INFINITE); - return -1; - } else { - MyOutputDebugString ("Error: You need gzip.exe (32 bit) to use .adz/.roz files!\n"); - } + if( debugfile ) + { +#if defined HAVE_GETTICKCOUNT && defined TIMESTAMP_LOGS + { + sprintf( buffer, "%7d - ", GetTickCount() ); + fprintf( debugfile, buffer ); + } +#endif + va_start (parms, format); + count = vfprintf( debugfile, format, parms ); + fflush( debugfile ); + if( count >= WRITE_LOG_BUF_SIZE-1 ) + { + fprintf( debugfile, "SHIT in write_log()\n" ); + fflush( debugfile ); + *blah = 0; /* Access Violation here! */ + abort(); + } + else + result = count; + va_end (parms); } - return 0; } - -/* file name requester. hBackBM will hopefully be dropped in the near future. */ -static OPENFILENAME ofn = { - sizeof (OPENFILENAME), - NULL, NULL, "Amiga Disk Files\000*.adf;*.adz\000", - NULL, 0, 0, 0, 256, NULL, 0, "", - 0, - OFN_NOCHANGEDIR | OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, - 0, - 0, - "adf", - 0, - NULL, - NULL -}; - -int requestfname (char *title, char *name) +#else /* MSVC likes this one, and so do I */ +int write_log( const char *format, ... ) { - HDC hDC; - char *result; - RECT rc; -#ifdef PICASSO96 - uae_u8 old_switch_state = picasso96_state.SwitchState; + int result = 0; +#ifdef _DEBUG + DWORD numwritten; #endif + char buffer[ WRITE_LOG_BUF_SIZE ]; + va_list parms; + int count = 0; + int *blah = (int *)0xdeadbeef; - ofn.hwndOwner = hAmigaWnd; - ofn.lpstrTitle = title; - ofn.lpstrFile = name; - - if (pGetOpenFileNameA == 0) - return 0; - - if (IDirectDrawSurface_GetDC (lpDDS, &hDC) == DD_OK) { - if ((hBackBM = CreateCompatibleBitmap (hDC, currprefs.gfx_width, currprefs.gfx_height)) - && (hBackDC = CreateCompatibleDC (hDC))) { - SelectObject (hBackDC, hBackBM); - - if (fullscreen) - BitBlt (hBackDC, 0, 0, currprefs.gfx_width, currprefs.gfx_height, hDC, 0, 0, SRCCOPY); - else { - BitBlt (hBackDC, 0, 0, currprefs.gfx_width, currprefs.gfx_height, hDC, - amigawin_rect.left, amigawin_rect.top, SRCCOPY); - } - } - IDirectDrawSurface_ReleaseDC (lpDDS, hDC); - } - if (!fullscreen) - setmouseactive (0); - - if (title) - result = (char *)((*pGetOpenFileNameA) (&ofn)); - else { - GetSettings (); + va_start (parms, format); + count = _vsnprintf( buffer, WRITE_LOG_BUF_SIZE-1, format, parms ); +#if defined HAVE_GETTICKCOUNT && defined TIMESTAMP_LOGS + { + char buffme[WRITE_LOG_BUF_SIZE]; + sprintf( buffme, "%7d - %s", GetTickCount(), buffer ); + OutputDebugString( buffme ); + if( debugfile ) + fprintf( debugfile, buffme ); + result = strlen( buffme ); } - - if (!fullscreen || !mouseactive) - SetCursor (NULL); - - if (hBackBM) { - if (hBackDC) { - if (fullscreen && IDirectDrawSurface_GetDC (lpDDS, &hDC) == DD_OK) { - BitBlt (hDC, 0, 0, currprefs.gfx_width, currprefs.gfx_height, hBackDC, 0, 0, SRCCOPY); - IDirectDrawSurface_ReleaseDC (lpDDS, hDC); - } - DeleteObject (hBackDC); - hBackDC = NULL; - } - DeleteObject (hBackBM); - hBackBM = NULL; +#else + OutputDebugString( buffer ); + if( debugfile ) + { + fprintf( debugfile, buffer ); + fflush( debugfile ); } - notice_screen_contents_lost (); - - if (result) - return 1; - - return 0; + result = strlen( buffer ); +#endif +#ifdef _DEBUG + openconsole(); + WriteConsole(stdoutput,buffer,strlen(buffer),&numwritten,0); +#endif + va_end (parms); + return result; } - -int DisplayGUI( void ) -{ - HBITMAP hBackBM2 = NULL; -#ifdef PICASSO96 - BITMAPINFO bminfo = { sizeof( BITMAPINFOHEADER ), current_width, -current_height, 1, 8, BI_RGB, 0, 0, 0, 0, 0, &picasso96_state.CLUT }; -#endif - HDC hDC; - void *blah; - RECT rc; - uae_u8 p96_8bit = 0; - - if (pGetOpenFileNameA) - { - if (IDirectDrawSurface_GetDC(lpDDS,&hDC) == DD_OK) - { -#ifdef PICASSO96 - if( picasso96_state.SwitchState && ( picasso96_state.BytesPerPixel == 1 ) ) - { - p96_8bit = 1; - hBackBM2 = CreateDIBSection( hDC, &bminfo, DIB_PAL_COLORS, &blah, NULL, 0 ); - } - else -#endif - hBackBM = CreateCompatibleBitmap( hDC, current_width, current_height ); - - if( (hBackBM2 || hBackBM ) && ( hBackDC = CreateCompatibleDC( hDC ) ) ) - { -#ifdef PICASSO96 - if( hBackBM2 ) - { - SelectObject( hBackDC, hBackBM2 ); - hBackBM = CreateCompatibleBitmap( hDC, current_width, current_height ); - } - else -#endif - SelectObject( hBackDC, hBackBM ); - - if( fullscreen ) - BitBlt( hBackDC, 0, 0, current_width, current_height, hDC, 0, 0, SRCCOPY ); - else - { - GetWindowRect(hAmigaWnd,&rc); - BitBlt(hBackDC,0,0,current_width,current_height,hDC,rc.left,rc.top,SRCCOPY); - } - - IDirectDrawSurface2_SetPalette( lpDDS, NULL ); - if( hBackBM2 ) - BitBlt( hDC, 0, 0, current_width, current_height, hBackDC, 0, 0, SRCCOPY ); - } - IDirectDrawSurface_ReleaseDC( lpDDS, hDC ); - } - - if (!fullscreen) setmouseactive(FALSE); - - GetSettings(); - if( lpDDP ) - IDirectDrawSurface2_SetPalette( lpDDS, lpDDP ); - - if (!fullscreen || !mouseactive) SetCursor(NULL); - - if( hBackBM || hBackBM2 ) - { - if( hBackDC ) - { -#ifdef PICASSO96 - if( p96_8bit ) - { - picasso96_state.RefreshPending = 1; - } - else -#endif - if( fullscreen && IDirectDrawSurface_GetDC( lpDDS, &hDC ) == DD_OK ) - { - BitBlt( hDC, 0, 0, current_width, current_height, hBackDC, 0, 0, SRCCOPY ); - IDirectDrawSurface_ReleaseDC( lpDDS, hDC ); - } - DeleteObject( hBackDC ); - hBackDC = NULL; - } - if( hBackBM2 ) - DeleteObject( hBackBM2 ); - if( hBackBM ) - { - DeleteObject( hBackBM ); - hBackBM = NULL; - } - } - } - return 0; -} - -#ifdef __GNUC__ -#undef WINAPI -#define WINAPI #endif -static HINSTANCE hDDraw = NULL, hComDlg32 = NULL, hRichEdit = NULL; - -int cleanuplibs(void) +int debuggable (void) { - if (hRichEdit) - FreeLibrary(hRichEdit); - if (hDDraw) - FreeLibrary(hDDraw); - if (hComDlg32) - FreeLibrary(hComDlg32); - return 1; + return 0; } -/* try to load COMDLG32 and DDRAW, initialize csDraw, try to obtain the system clock frequency - * from the registry, try to find out if we are running on a Pentium */ -int initlibs (void) +int needmousehack (void) { - /* Make sure we do an InitCommonControls() to get some advanced controls */ - InitCommonControls (); - - if (hComDlg32 = LoadLibrary ("COMDLG32.DLL")) { - pGetOpenFileNameA = (BOOL (WINAPI *) (LPOPENFILENAME)) GetProcAddress (hComDlg32, "GetOpenFileNameA"); - } else - /* System administrator? ROFL! -- Bernd */ - MyOutputDebugString ("COMDLG32.DLL not available. Please contact your system administrator.\n"); - - /* LoadLibrary the richedit control stuff */ - if ((hRichEdit = LoadLibrary ("RICHED32.DLL")) == NULL) { - MyOutputDebugString ("RICHED32.DLL not available. Please contact your system administrator.\n"); - } - if (hDDraw = LoadLibrary ("DDRAW.DLL")) { -#ifdef __GNUC__ - pDirectDrawCreate = (HRESULT (WINAPI *) (GUID FAR *, LPDIRECTDRAW FAR *, IUnknown FAR *)) GetProcAddress (hDDraw, "DirectDrawCreate"); -#endif - InitializeCriticalSection (&csDraw); - - process_desired_pri = IDLE_PRIORITY_CLASS; - + if( WIN32GFX_IsFullScreen() || WIN32GFX_IsPicassoScreen() ) + return 0; + else return 1; - } else - MyOutputDebugString ("You have to install DirectX on your system before you can use UAE.\nRefer to the documentation for further details.\n"); - - return 0; } -void MyOutputDebugString (char *format,...) +void LED (int a) { - char buffer[512]; - va_list parms; - - va_start (parms, format); - vsprintf (buffer, format, parms); - va_end (parms); - write_log (buffer); } -void write_log (const char *txt) +void logging_init( void ) { - DWORD numwritten; -#ifdef _DEBUG - OutputDebugString( txt ); -#endif - fprintf (stderr, "%s", txt); - /* if (HasConsole) - WriteConsole (stdouthandle, txt, strlen (txt), &numwritten, NULL);*/ - WriteFile (debugfile, txt, strlen (txt), &numwritten, NULL); + char debugfilename[MAX_PATH]; + if (1) { + sprintf( debugfilename, "%s\\winuaelog.txt", start_path ); + if( !debugfile ) + debugfile = fopen( debugfilename, "wt" ); + } + write_log ( "%s\n", VersionStr ); + write_log ("\n(c) 1995-2001 Bernd Schmidt - Core UAE concept and implementation." + "\n(c) 1996-1999 Mathias Ortmann - Win32 port and bsdsocket support." + "\n(c) 1996-2001 Brian King - Win32 port, Picasso96 RTG, and GUI." + "\n(c) 1998-2001 Toni Wilen - AGA chipset, NTSC/PAL modes.\n" + "\n(c) 2000-2001 Bernd Meyer - JIT engine.\n" + "\n(c) 2000-2001 Bernd Roesch - MIDI input, many fixes.\n" + "\nPress F12 to show the Settings Dialog (GUI), Alt-F4 to quit." + "\nEnd+F1 changes floppy 0, End+F2 changes floppy 1, etc.\n" + "\nhttp://www.codepoet.com/UAE/\n\n"); } -int debuggable (void) +void logging_cleanup( void ) { - return 1; + if( debugfile ) + fclose( debugfile ); } -int needmousehack (void) +static const char *sound_styles[] = { "waveout_looping", "waveout_dblbuff", "dsound_looping", "dsound_dblbuff", 0 }; + +void target_save_options (FILE *f, struct uae_prefs *p) { - return 1; } -void LED (int on) +int target_parse_option (struct uae_prefs *p, char *option, char *value) { + return 0; } +void WIN32_HandleRegistryStuff( void ) +{ + RGBFTYPE colortype = RGBFB_NONE; + DWORD dwType = REG_DWORD; + DWORD dwDisplayInfoSize = sizeof( colortype ); + DWORD disposition; + char path[MAX_PATH] = ""; + HKEY hWinUAEKeyLocal = NULL; + + /* Create/Open the hWinUAEKey which points to our config-info */ + if( RegCreateKeyEx( HKEY_CLASSES_ROOT, ".uae", 0, "", REG_OPTION_NON_VOLATILE, + KEY_ALL_ACCESS, NULL, &hWinUAEKey, &disposition ) == ERROR_SUCCESS ) + { + // Regardless of opening the existing key, or creating a new key, we will write the .uae filename-extension + // commands in. This way, we're always up to date. -static uae_u16 *ppicasso_format; -static int picasso_modecount; + /* Set our (default) sub-key to point to the "WinUAE" key, which we then create */ + RegSetValueEx( hWinUAEKey, "", 0, REG_SZ, (CONST BYTE *)"WinUAE", strlen( "WinUAE" ) + 1 ); + + if( ( RegCreateKeyEx( HKEY_CLASSES_ROOT, "WinUAE\\shell\\Edit\\command", 0, "", REG_OPTION_NON_VOLATILE, + KEY_ALL_ACCESS, NULL, &hWinUAEKeyLocal, &disposition ) == ERROR_SUCCESS ) ) + { + /* Set our (default) sub-key to BE the "WinUAE" command for editing a configuration */ + sprintf( path, "%s\\WinUAE.exe -f \"%%1\" -s use_gui=yes", start_path ); + RegSetValueEx( hWinUAEKeyLocal, "", 0, REG_SZ, (CONST BYTE *)path, strlen( path ) + 1 ); + } + RegCloseKey( hWinUAEKeyLocal ); + + if( ( RegCreateKeyEx( HKEY_CLASSES_ROOT, "WinUAE\\shell\\Open\\command", 0, "", REG_OPTION_NON_VOLATILE, + KEY_ALL_ACCESS, NULL, &hWinUAEKeyLocal, &disposition ) == ERROR_SUCCESS ) ) + { + /* Set our (default) sub-key to BE the "WinUAE" command for launching a configuration */ + sprintf( path, "%s\\WinUAE.exe -f \"%%1\"", start_path ); + RegSetValueEx( hWinUAEKeyLocal, "", 0, REG_SZ, (CONST BYTE *)path, strlen( path ) + 1 ); + } + RegCloseKey( hWinUAEKeyLocal ); + } + else + { + char szMessage[ MAX_PATH ]; + WIN32GUI_LoadUIString( IDS_REGKEYCREATEFAILED, szMessage, MAX_PATH ); + gui_message( szMessage ); + hWinUAEKey = NULL; + } + RegCloseKey( hWinUAEKey ); + + /* Create/Open the hWinUAEKey which points our config-info */ + if( RegCreateKeyEx( HKEY_CURRENT_USER, "Software\\CodePoet Computing\\WinUAE", 0, "", REG_OPTION_NON_VOLATILE, + KEY_ALL_ACCESS, NULL, &hWinUAEKey, &disposition ) == ERROR_SUCCESS ) + { + if( disposition == REG_CREATED_NEW_KEY ) + { + /* Create and initialize all our sub-keys to the default values */ + colortype = 0; + RegSetValueEx( hWinUAEKey, "DisplayInfo", 0, REG_DWORD, (CONST BYTE *)&colortype, sizeof( colortype ) ); + RegSetValueEx( hWinUAEKey, "xPos", 0, REG_DWORD, (CONST BYTE *)&colortype, sizeof( colortype ) ); + RegSetValueEx( hWinUAEKey, "yPos", 0, REG_DWORD, (CONST BYTE *)&colortype, sizeof( colortype ) ); + RegSetValueEx( hWinUAEKey, "FloppyPath", 0, REG_SZ, (CONST BYTE *)start_path, strlen( start_path ) + 1 ); + RegSetValueEx( hWinUAEKey, "KickstartPath", 0, REG_SZ, (CONST BYTE *)start_path, strlen( start_path ) + 1 ); + RegSetValueEx( hWinUAEKey, "hdfPath", 0, REG_SZ, (CONST BYTE *)start_path, strlen( start_path ) + 1 ); + } + // Set this even when we're opening an existing key, so that the version info is always up to date. + RegSetValueEx( hWinUAEKey, "Version", 0, REG_SZ, (CONST BYTE *)VersionStr, strlen( VersionStr ) + 1 ); + + RegQueryValueEx( hWinUAEKey, "DisplayInfo", 0, &dwType, (LPBYTE)&colortype, &dwDisplayInfoSize ); + if( colortype == 0 ) /* No color information stored in the registry yet */ + { + char szMessage[ 4096 ]; + char szTitle[ MAX_PATH ]; + WIN32GUI_LoadUIString( IDS_GFXCARDCHECK, szMessage, 4096 ); + WIN32GUI_LoadUIString( IDS_GFXCARDTITLE, szTitle, MAX_PATH ); + + if( MessageBox( NULL, szMessage, szTitle, + MB_YESNO | MB_ICONWARNING | MB_TASKMODAL | MB_SETFOREGROUND ) == IDYES ) + { + colortype = WIN32GFX_FigurePixelFormats(0); + RegSetValueEx( hWinUAEKey, "DisplayInfo", 0, REG_DWORD, (CONST BYTE *)&colortype, sizeof( colortype ) ); + } + } + if( colortype ) + { + /* Set the 16-bit pixel format for the appropriate modes */ + WIN32GFX_FigurePixelFormats( colortype ); + } + } + else + { + char szMessage[ MAX_PATH ]; + WIN32GUI_LoadUIString( IDS_REGKEYCREATEFAILED, szMessage, MAX_PATH ); + gui_message( szMessage ); + hWinUAEKey = NULL; + } +} -static HRESULT CALLBACK modesCallback (LPDDSURFACEDESC modeDesc, LPVOID context) +void machdep_init (void) { - int bpp; +} - if (picasso_modecount >= MAX_PICASSO_MODES) - return DDENUMRET_CANCEL; +char *start_path = NULL; +char help_file[ MAX_PATH ]; - if (modeDesc->dwFlags & (DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_REFRESHRATE)) { - bpp = modeDesc->ddpfPixelFormat.dwRGBBitCount; -#ifdef PICASSO96 - switch (bpp) { - case 8: - *ppicasso_format |= RGBFF_CHUNKY; - break; - case 16: - /* figure out which actual format it is using based on the RGB masks */ - - /* Bernd - this doesn't work for some reason. Instead, I figure out the modes in doInit(), - * where I have the surface's description and pixel formats. Damned DirectDraw stuff! - */ - break; - case 24: - /* figure out which actual format it is using based on the RGB masks */ - if (modeDesc->ddpfPixelFormat.dwRBitMask == 0x00FF0000) - *ppicasso_format |= RGBFF_B8G8R8; - else - *ppicasso_format |= RGBFF_R8G8B8; - break; - case 32: - /* figure out which actual format it is using based on the RGB masks */ - if (modeDesc->ddpfPixelFormat.dwRBitMask == 0x00FF0000) - *ppicasso_format |= RGBFF_B8G8R8A8; - else if (modeDesc->ddpfPixelFormat.dwRBitMask == 0x000000FF) - *ppicasso_format |= RGBFF_R8G8B8A8; - else if (modeDesc->ddpfPixelFormat.dwBBitMask == 0xFF000000) - *ppicasso_format |= RGBFF_A8R8G8B8; - else - *ppicasso_format |= RGBFF_A8B8G8R8; - break; - } -#endif - DisplayModes[picasso_modecount].res.width = modeDesc->dwWidth; - DisplayModes[picasso_modecount].res.height = modeDesc->dwHeight; - DisplayModes[picasso_modecount].depth = bpp/8; - if (modeDesc->dwRefreshRate) - { - sprintf(DisplayModes[picasso_modecount].name,"%dx%d, %d-bit, %d Hz",modeDesc->dwWidth, - modeDesc->dwHeight, bpp, modeDesc->dwRefreshRate ); - DisplayModes[picasso_modecount].refresh = modeDesc->dwRefreshRate; - } - else - { - sprintf(DisplayModes[picasso_modecount].name,"%dx%d, %d-bit",modeDesc->dwWidth, - modeDesc->dwHeight, bpp ); - DisplayModes[picasso_modecount].refresh = 75; /* fake a 75-Hz refresh rate... BLAH! */ - } - picasso_modecount++; - } - return DDENUMRET_OK; -} - -int DX_FillResolutions (uae_u16 *ppixel_format) -{ - static int from_preInit = 1; - if( from_preInit ) - { - picasso_modecount = 0; - *ppixel_format = 0; - ppicasso_format = ppixel_format; - - IDirectDraw_EnumDisplayModes (lpDD, 0, NULL, NULL, modesCallback); - from_preInit = 0; - } - return picasso_modecount; -} - -#ifdef PICASSO96 - -void DX_SetPalette (int start, int count) +int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, + int nCmdShow) { - HRESULT ddrval; + char *posn; + HANDLE hMutex; + OSVERSIONINFO osVersion; - if (!screen_is_picasso) - return; +#ifdef __GNUC__ + __asm__ ("leal -2300*1024(%%esp),%0" : "=r" (win32_stackbase) :); +#else +__asm{ + mov eax,esp + sub eax,2300*1024 + mov win32_stackbase,eax + } +#endif - /* Set our DirectX palette here */ - if (lpDDP && (picasso96_state.BytesPerPixel == 1)) { - /* For now, until I figure this out, just set the entire range of CLUT values */ - ddrval = IDirectDrawPalette_SetEntries (lpDDP, 0, 0, 256, (LPPALETTEENTRY) &picasso96_state.CLUT); - if (ddrval != DD_OK) - MyOutputDebugString ("DX_SetPalette() failed with %s/%d\n", getddrname (ddrval), ddrval); - } else - MyOutputDebugString ("ERROR - DX_SetPalette() doesn't have palette, or isn't Chunky mode.\n"); -} + hInst = hInstance; + hMutex = CreateMutex( NULL, FALSE, "WinUAE Instantiated" ); // To tell the installer we're running + + osVersion.dwOSVersionInfoSize = sizeof( OSVERSIONINFO ); + if( GetVersionEx( &osVersion ) ) + { + if( ( osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT ) && + ( osVersion.dwMajorVersion <= 4 ) ) + { + /* WinUAE not supported on this version of Windows... */ + char szWrongOSVersion[ MAX_PATH ]; + WIN32GUI_LoadUIString( IDS_WRONGOSVERSION, szWrongOSVersion, MAX_PATH ); + gui_message( szWrongOSVersion ); + return FALSE; + } + } -void DX_Invalidate (int first, int last) -{ -} + /* Get our executable's root-path */ + if( ( start_path = xmalloc( MAX_PATH ) ) ) + { + GetModuleFileName( NULL, start_path, MAX_PATH ); + if( ( posn = strrchr( start_path, '\\' ) ) ) + *posn = 0; + sprintf( help_file, "%s\\WinUAE.chm", start_path ); -int DX_BitsPerCannon (void) -{ - return 8; -} + sprintf( VersionStr, "WinUAE %d.%d.%d, Release %d%s", UAEMAJOR, UAEMINOR, UAESUBREV, WINUAERELEASE, WINUAEBETA ? WINUAEBETASTR : "" ); -int DX_FillRect (uaecptr addr, uae_u16 X, uae_u16 Y, uae_u16 Width, uae_u16 Height, uae_u32 Pen, uae_u8 Bpp) -{ - return 0; -} + logging_init (); + printf ("Hello, world\n"); -void gfx_set_picasso_state (int on) -{ - if (screen_is_picasso == on) - return; - screen_is_picasso = on; - PostMessage (hAmigaWnd, WM_USER + 0x201, 0, 0); - uae_sem_wait (&picasso_switch_sem); -} + if( WIN32_RegisterClasses() && WIN32_InitLibraries() && DirectDraw_Start() ) + { + struct foo { + DEVMODE actual_devmode; + char overrun[8]; + } devmode; + + DWORD i = 0; + + DirectDraw_EnumDisplayModes( 0, modesCallback ); + + memset( &devmode, 0, sizeof(DEVMODE) + 8 ); + devmode.actual_devmode.dmSize = sizeof(DEVMODE); + devmode.actual_devmode.dmDriverExtra = 8; +#define ENUM_CURRENT_SETTINGS ((DWORD)-1) + if( EnumDisplaySettings( NULL, ENUM_CURRENT_SETTINGS, (LPDEVMODE)&devmode ) ) + { + default_freq = devmode.actual_devmode.dmDisplayFrequency; + write_log( "Your Windows desktop refresh frequency is %d Hz\n", default_freq ); + if( default_freq >= 70 ) + default_freq = 70; + else + default_freq = 60; + } -void gfx_set_picasso_modeinfo (int w, int h, int depth) -{ - depth >>= 3; - if (picasso_vidinfo.width == w - && picasso_vidinfo.height == h - && picasso_vidinfo.depth == depth) - return; + WIN32_HandleRegistryStuff(); + if( WIN32_InitHtmlHelp() == 0 ) + { + char szMessage[ MAX_PATH ]; + WIN32GUI_LoadUIString( IDS_NOHELP, szMessage, MAX_PATH ); + write_log( szMessage ); + } - picasso_vidinfo.width = w; - picasso_vidinfo.height = h; - picasso_vidinfo.depth = depth; - picasso_vidinfo.extra_mem = 1; - - if (screen_is_picasso) { - PostMessage (hAmigaWnd, WM_USER + 0x201, 0, 0); - uae_sem_wait (&picasso_switch_sem); + DirectDraw_Release(); +#ifdef __MINGW32__ + real_main (_argc, _argv); +#else + real_main (__argc, __argv); +#endif + } + free( start_path ); } + + WIN32_CleanupLibraries(); + _fcloseall(); + if( hWinUAEKey ) + RegCloseKey( hWinUAEKey ); + CloseHandle( hMutex ); + return FALSE; } -#endif