Esempio n. 1
0
bool DirectDrawDisplay::initialize()
{
  theApp.sizeX = 240;
  theApp.sizeY = 160;

  switch(theApp.videoOption) {
  case VIDEO_1X:
    theApp.surfaceSizeX = theApp.sizeX;
    theApp.surfaceSizeY = theApp.sizeY;
    break;
  case VIDEO_2X:
    theApp.surfaceSizeX = theApp.sizeX * 2;
    theApp.surfaceSizeY = theApp.sizeY * 2;
    break;
  case VIDEO_3X:
    theApp.surfaceSizeX = theApp.sizeX * 3;
    theApp.surfaceSizeY = theApp.sizeY * 3;
    break;
  case VIDEO_4X:
    theApp.surfaceSizeX = theApp.sizeX * 4;
    theApp.surfaceSizeY = theApp.sizeY * 4;
    break;
  case VIDEO_320x240:
  case VIDEO_640x480:
  case VIDEO_800x600:
  case VIDEO_OTHER:
    {
      int scaleX = (theApp.fsWidth / theApp.sizeX);
      int scaleY = (theApp.fsHeight / theApp.sizeY);
      int min = scaleX < scaleY ? scaleX : scaleY;
      if(theApp.fsMaxScale)
        min = min > theApp.fsMaxScale ? theApp.fsMaxScale : min;
      theApp.surfaceSizeX = theApp.sizeX * min;
      theApp.surfaceSizeY = theApp.sizeY * min;
      if(theApp.fullScreenStretch) {
        theApp.surfaceSizeX = theApp.fsWidth;
        theApp.surfaceSizeY = theApp.fsHeight;
      }
    }
    break;
  }
  
  theApp.rect.left = 0;
  theApp.rect.top = 0;
  theApp.rect.right = theApp.sizeX;
  theApp.rect.bottom = theApp.sizeY;

  theApp.dest.left = 0;
  theApp.dest.top = 0;
  theApp.dest.right = theApp.surfaceSizeX;
  theApp.dest.bottom = theApp.surfaceSizeY;

  DWORD style = WS_POPUP | WS_VISIBLE;
  DWORD styleEx = 0;
  
  if(theApp.videoOption <= VIDEO_4X)
    style |= WS_OVERLAPPEDWINDOW;
  else
    styleEx = WS_EX_TOPMOST;

  if(theApp.videoOption <= VIDEO_4X)
    AdjustWindowRectEx(&theApp.dest, style, TRUE, styleEx);
  else
    AdjustWindowRectEx(&theApp.dest, style, FALSE, styleEx);    

  int winSizeX = theApp.dest.right-theApp.dest.left;
  int winSizeY = theApp.dest.bottom-theApp.dest.top;

  int x = 0;
  int y = 0;

  if(theApp.videoOption <= VIDEO_4X) {
    x = theApp.windowPositionX;
    y = theApp.windowPositionY;
  }

  // Create a window
  MainWnd *pWnd = new MainWnd;
  theApp.m_pMainWnd = pWnd;

  pWnd->CreateEx(styleEx,
                 theApp.wndClass,
                 "VisualBoyAdvance",
                 style,
                 x,y,winSizeX,winSizeY,
                 NULL,
                 0);
  
  if (!(HWND)*pWnd) {
    winlog("Error creating Window %08x\n", GetLastError());
    return FALSE;
  }

  
  theApp.updateMenuBar();
  
  theApp.adjustDestRect();
  
  GUID *guid = NULL;
  if(theApp.ddrawEmulationOnly)
    guid = (GUID *)DDCREATE_EMULATIONONLY;

  if(theApp.pVideoDriverGUID)
    guid = theApp.pVideoDriverGUID;

  ddrawDLL = AfxLoadLibrary("DDRAW.DLL");
  HRESULT (WINAPI *DDrawCreateEx)(GUID *,LPVOID *,REFIID,IUnknown *);  
  if(ddrawDLL != NULL) {    
    DDrawCreateEx = (HRESULT (WINAPI *)(GUID *,LPVOID *,REFIID,IUnknown *))
      GetProcAddress(ddrawDLL, "DirectDrawCreateEx");

    if(DDrawCreateEx == NULL) {
      theApp.directXMessage("DirectDrawCreateEx");
      return FALSE;
    }
  } else {
    theApp.directXMessage("DDRAW.DLL");
    return FALSE;
  }

  theApp.ddrawUsingEmulationOnly = theApp.ddrawEmulationOnly;
  
  HRESULT hret = DDrawCreateEx(guid,
                               (void **)&pDirectDraw,
                               IID_IDirectDraw7,
                               NULL);
    
  if(hret != DD_OK) {
    winlog("Error creating DirectDraw object %08x\n", hret);
    if(theApp.ddrawEmulationOnly) {
      // disable emulation only setting in case of failure
      regSetDwordValue("ddrawEmulationOnly", 0);
    }
    //    errorMessage(myLoadString(IDS_ERROR_DISP_DRAWCREATE), hret);
    return FALSE;
  }

  if(theApp.ddrawDebug) {
    DDCAPS driver;
    DDCAPS hel;
    ZeroMemory(&driver, sizeof(driver));
    ZeroMemory(&hel, sizeof(hel));
    driver.dwSize = sizeof(driver);
    hel.dwSize = sizeof(hel);
    pDirectDraw->GetCaps(&driver, &hel);
    int i;
    DWORD *p = (DWORD *)&driver;
    for(i = 0; i < (int)driver.dwSize; i+=4)
      winlog("Driver CAPS %2d: %08x\n", i>>2, *p++);
    p = (DWORD *)&hel;
    for(i = 0; i < (int)hel.dwSize; i+=4)
      winlog("HEL CAPS %2d: %08x\n", i>>2, *p++);
  }
Esempio n. 2
0
int winVideoModeSelect(CWnd *pWnd, GUID **guid)
{
#ifdef _AFXDLL
  HINSTANCE h = AfxLoadLibrary("ddraw.dll");
#else
  HMODULE h = LoadLibrary( _T("ddraw.dll") );
#endif
 
  // If ddraw.dll doesn't exist in the search path,
  // then DirectX probably isn't installed, so fail.
  if (!h)
    return -1;
  
  gDriverCnt = 0;
  
  // Note that you must know which version of the
  // function to retrieve (see the following text).
  // For this example, we use the ANSI version.
  LPDIRECTDRAWENUMERATEEX lpDDEnumEx;
  lpDDEnumEx = (LPDIRECTDRAWENUMERATEEX)
    GetProcAddress(h,"DirectDrawEnumerateExA");
 
  // If the function is there, call it to enumerate all display 
  // devices attached to the desktop, and any non-display DirectDraw
  // devices.
  if (lpDDEnumEx)
    lpDDEnumEx(DDEnumCallbackEx, NULL, 
               DDENUM_ATTACHEDSECONDARYDEVICES |
               DDENUM_NONDISPLAYDEVICES 
               );
  else {
    /*
     * We must be running on an old version of DirectDraw.
     * Therefore MultiMon isn't supported. Fall back on
     * DirectDrawEnumerate to enumerate standard devices on a 
     * single-monitor system.
     */
    BOOL (WINAPI *lpDDEnum)(LPDDENUMCALLBACK, LPVOID);
    
    lpDDEnum = (BOOL (WINAPI *)(LPDDENUMCALLBACK, LPVOID))
      GetProcAddress(h, "DirectDrawEnumerateA");
    if(lpDDEnum)
      lpDDEnum(DDEnumCallback,NULL);
    
    /* Note that it could be handy to let the OldCallback function
     * be a wrapper for a DDEnumCallbackEx. 
     * 
     * Such a function would look like:
     *    BOOL FAR PASCAL OldCallback(GUID FAR *lpGUID,
     *                                LPSTR pDesc,
     *                                LPSTR pName,
     *                                LPVOID pContext)
     *    {
     *         return Callback(lpGUID,pDesc,pName,pContext,NULL);
     *    }
     */
  }

  int selected = 0;

  if(gDriverCnt > 1) {
    VideoDriverSelect d(pWnd);

    INT_PTR selected = d.DoModal();

    if(selected == -1) {
#ifdef _AFXDLL
      AfxFreeLibrary( h );
#else
      FreeLibrary( h );
#endif
      
      return -1;
    }
  }

  HRESULT (WINAPI *DDrawCreateEx)(GUID *,LPVOID *,REFIID,IUnknown *);  
  DDrawCreateEx = (HRESULT (WINAPI *)(GUID *,LPVOID *,REFIID,IUnknown *))
    GetProcAddress(h, "DirectDrawCreateEx");

  LPDIRECTDRAW7 ddraw = NULL;
  if(DDrawCreateEx) {
    HRESULT hret = DDrawCreateEx(Drivers[selected].pGUID,
                                 (void **)&ddraw,
                                 IID_IDirectDraw7,
                                 NULL);
    if(hret != DD_OK) {
      systemMessage(0, "Error during DirectDrawCreateEx: %08x", hret);
#ifdef _AFXDLL
      AfxFreeLibrary( h );
#else
      FreeLibrary( h );
#endif
      return -1;
    }
  } else {
    // should not happen....
    systemMessage(0, "Error getting DirectDrawCreateEx");
#ifdef _AFXDLL
    AfxFreeLibrary( h );
#else
    FreeLibrary( h );
#endif
    return -1;
  }  
  
  VideoMode dlg(ddraw, pWnd);

  INT_PTR res = dlg.DoModal();

  if(res != -1) {
    *guid = Drivers[selected].pGUID;
  }
  ddraw->Release();
  ddraw = NULL;

  // If the library was loaded by calling LoadLibrary(),
  // then you must use FreeLibrary() to let go of it.
#ifdef _AFXDLL
  AfxFreeLibrary( h );
#else
  FreeLibrary( h );
#endif

  return (int)res;
}