Annotation of uae/src/od-win32/win32.c, revision 1.1.1.4

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.