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 GDIDisplay::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 = 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();    theApp.mode320Available = false;  theApp.mode640Available = false;  theApp.mode800Available = false;    HDC dc = GetDC(NULL);  HBITMAP hbm = CreateCompatibleBitmap(dc, 1, 1);  BITMAPINFO *bi = (BITMAPINFO *)info;  ZeroMemory(bi, sizeof(info));  bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);  GetDIBits(dc, hbm, 0, 1, NULL, (LPBITMAPINFO)info, DIB_RGB_COLORS);    GetDIBits(dc, hbm, 0, 1, NULL, (LPBITMAPINFO)info, DIB_RGB_COLORS);  DeleteObject(hbm);  ReleaseDC(NULL, dc);  if(bi->bmiHeader.biCompression == BI_BITFIELDS) {    systemColorDepth = bi->bmiHeader.biBitCount;    if(systemColorDepth == 15)      systemColorDepth = 16;    systemRedShift = calculateShift(*((DWORD *)&bi->bmiColors[0]));    systemGreenShift = calculateShift(*((DWORD *)&bi->bmiColors[1]));    systemBlueShift = calculateShift(*((DWORD *)&bi->bmiColors[2]));    if(systemColorDepth == 16) {      if(systemGreenShift == 6) {        Init_2xSaI(565);        RGB_LOW_BITS_MASK=0x821;      } else {        Init_2xSaI(555);        RGB_LOW_BITS_MASK=0x421;              }    } else if(systemColorDepth == 32)      Init_2xSaI(32);  } else {    systemColorDepth = 32;    systemRedShift = 19;    systemGreenShift = 11;    systemBlueShift = 3;    Init_2xSaI(32);      }  theApp.fsColorDepth = systemColorDepth;  if(systemColorDepth == 24)    theApp.filterFunction = NULL;#ifdef MMX  if(!theApp.disableMMX)    cpu_mmx = theApp.detectMMX();  else    cpu_mmx = 0;#endif    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();    pWnd->DragAcceptFiles(TRUE);    return TRUE;  }