for(int i = 0; i < 24;) { systemGbPalette[i++] = (0x1f) | (0x1f << 5) | (0x1f << 10); systemGbPalette[i++] = (0x15) | (0x15 << 5) | (0x15 << 10); systemGbPalette[i++] = (0x0c) | (0x0c << 5) | (0x0c << 10); systemGbPalette[i++] = 0; }
bool Direct3DDisplay::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:    {      RECT r;      ::GetWindowRect(GetDesktopWindow(), &r);      theApp.fsWidth = r.right - r.left;      theApp.fsHeight = r.bottom - r.top;      /* Need to fix this code later. For now, Fullscreen takes the whole         screen.         int scaleX = (fsWidth / sizeX);         int scaleY = (fsHeight / sizeY);         int min = scaleX < scaleY ? scaleX : scaleY;         surfaceSizeX = sizeX * min;         surfaceSizeY = sizeY * min;         if(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 = 0;  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;  if(theApp.videoOption > VIDEO_4X) {    winSizeX = theApp.fsWidth;    winSizeY = theApp.fsHeight;  }    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();    d3dDLL = LoadLibrary("D3D8.DLL");  LPDIRECT3D8 (WINAPI *D3DCreate)(UINT);  if(d3dDLL != NULL) {        D3DCreate = (LPDIRECT3D8 (WINAPI *)(UINT))      GetProcAddress(d3dDLL, "Direct3DCreate8");    if(D3DCreate == NULL) {      theApp.directXMessage("Direct3DCreate8");      return FALSE;    }  } else {    theApp.directXMessage("D3D8.DLL");    return FALSE;  }  pD3D = D3DCreate(120);      if(pD3D == NULL) {    winlog("Error creating Direct3D object\n");    return FALSE;  }    theApp.mode320Available = FALSE;  theApp.mode640Available = FALSE;  theApp.mode800Available = FALSE;  D3DDISPLAYMODE mode;  pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &mode);    switch(mode.Format) {  case D3DFMT_R8G8B8:    systemColorDepth = 24;    systemRedShift = 19;    systemGreenShift = 11;    systemBlueShift = 3;    break;  case D3DFMT_X8R8G8B8:    systemColorDepth = 32;    systemRedShift = 19;    systemGreenShift = 11;    systemBlueShift = 3;    Init_2xSaI(32);    break;  case D3DFMT_R5G6B5:    systemColorDepth = 16;    systemRedShift = 11;    systemGreenShift = 6;    systemBlueShift = 0;        Init_2xSaI(565);    break;  case D3DFMT_X1R5G5B5:    systemColorDepth = 16;    systemRedShift = 10;    systemGreenShift = 5;    systemBlueShift = 0;    Init_2xSaI(555);    break;  default:    systemMessage(0,"Unsupport D3D format %d", mode.Format);    return false;  }  theApp.fsColorDepth = systemColorDepth;#ifdef MMX  if(!theApp.disableMMX)    cpu_mmx = theApp.detectMMX();  else    cpu_mmx = 0;#endif    screenFormat = mode.Format;  // check for available fullscreen modes  ZeroMemory(&dpp, sizeof(dpp));  dpp.Windowed = TRUE;  dpp.BackBufferFormat = mode.Format;  dpp.BackBufferCount = 1;  dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;  dpp.BackBufferWidth = theApp.surfaceSizeX;  dpp.BackBufferHeight = theApp.surfaceSizeY;    HRESULT hret = pD3D->CreateDevice(D3DADAPTER_DEFAULT,                                    D3DDEVTYPE_HAL,                                    pWnd->GetSafeHwnd(),                                    D3DCREATE_SOFTWARE_VERTEXPROCESSING,                                    &dpp,                                    &pDevice);  if(!SUCCEEDED(hret)) {    winlog("Error creating Direct3DDevice %08x\n", hret);    return false;  }    restoreDeviceObjects();  switch(systemColorDepth) {  case 16:    {      for(int i = 0; i < 0x10000; i++) {        systemColorMap16[i] = ((i & 0x1f) << systemRedShift) |          (((i & 0x3e0) >> 5) << systemGreenShift) |          (((i & 0x7c00) >> 10) << systemBlueShift);      }    }    break;  case 24:  case 32:    {      for(int i = 0; i < 0x10000; i++) {        systemColorMap32[i] = ((i & 0x1f) << systemRedShift) |          (((i & 0x3e0) >> 5) << systemGreenShift) |          (((i & 0x7c00) >> 10) << systemBlueShift);      }          }    break;  }  for(int i = 0; i < 24;) {    systemGbPalette[i++] = (0x1f) | (0x1f << 5) | (0x1f << 10);    systemGbPalette[i++] = (0x15) | (0x15 << 5) | (0x15 << 10);    systemGbPalette[i++] = (0x0c) | (0x0c << 5) | (0x0c << 10);    systemGbPalette[i++] = 0;  }    theApp.updateFilter();  theApp.updateIFB();  if(failed)    return false;    pWnd->DragAcceptFiles(TRUE);    return TRUE;  }