Example #1
0
bool video::init_window(int sizex, int sizey)
{
    assert(win_hInstance != 0);
    g_sizex = sizex; g_sizey = sizey;
    if( !WinInit(win_hInstance, win_iCmdShow, gWndClass, title, false) )
        return DisplayError("Unable to initialize the program's window.");
    running = true;
    if( !DDInit() ) {
        DestroyDDraw();
        goto fail;
    }
    if( !DDOverlayInit() || !DrawOverlay() ) {
        DestroyOverlay();
        DestroyDDraw();
        goto fail;
    }
    DDPIXELFORMAT PixelFormat; memset(&PixelFormat, 0, sizeof(PixelFormat)); PixelFormat.dwSize = sizeof(PixelFormat);
    g_pDDSOverlay->GetPixelFormat(&PixelFormat);
    mask2bits(PixelFormat.dwRBitMask, red_mask, red_shift);
    mask2bits(PixelFormat.dwGBitMask, green_mask, green_shift);
    mask2bits(PixelFormat.dwBBitMask, blue_mask, blue_shift);
    if(PixelFormat.dwFlags == DDPF_RGB)
         depth = char(PixelFormat.dwRGBBitCount);
    else depth = -char(PixelFormat.dwFourCC);
    for(int i = 0, e = sizex * sizey * PixelFormat.dwRGBBitCount / 32, c = get_color(0, 0, 0); i < e; i++)
        g_pImg[i] = c; // clear surface
    ShowWindow(g_hAppWnd, SW_SHOW);
    g_hVSync = CreateThread (
        NULL,          // LPSECURITY_ATTRIBUTES security_attrs
        0,             // SIZE_T stacksize
        (LPTHREAD_START_ROUTINE) thread_vsync,
        this,               // argument
        0, 0);
    SetPriorityClass(g_hVSync, IDLE_PRIORITY_CLASS); // questionable
    return true;
fail:
    g_pImg = new unsigned int[g_sizex * g_sizey];
    return false;
}
Example #2
0
void DDAccurateInit(int resize)
{
        DDPIXELFORMAT DDpf;
        DDSURFACEDESC2 ddsd;

        float OrigW, OrigH, ScaleW, ScaleH;

        OrigW=Form1->ClientWidth;
        OrigH=Form1->ClientHeight;
        if (Form1->StatusBar1->Visible) OrigH -= Form1->StatusBar1->Height;

        if (Form1->BaseWidth==0) Form1->BaseWidth= NoWinR-NoWinL;
        if (Form1->BaseHeight==0) Form1->BaseHeight= NoWinT-NoWinB;

        ScaleW = OrigW / Form1->BaseWidth;
        ScaleH = OrigH / Form1->BaseHeight;

        RasterX=0;
        RasterY=random(256);

        //fill the DDpf structure and get the BytesPerPixel
        ZeroMemory (&DDpf, sizeof(DDpf));
        DDpf.dwSize = sizeof(DDpf);
        m_pddsFrontBuffer->GetPixelFormat(&DDpf);
        BPP = DDpf.dwRGBBitCount/8;

        Paletteised = (BPP==1) ? true:false;
        Scale= tv.AdvancedEffects?2:1;

        //ScanLen=460*BPP;
        ScanLen=(2+machine.tperscanline*2)*BPP;

        switch(zx81.bordersize)
        {
        case BORDERNONE:
                WinL=BlWinL; WinR=BlWinR; WinT=BlWinT; WinB=BlWinB;
                if (zx81.NTSC) { WinT-=24; WinB-=24; }
                break;
        case BORDERSMALL:
                WinL=SmWinL; WinR=SmWinR; WinT=SmWinT; WinB=SmWinB;
                if (zx81.NTSC) { WinT-=24; WinB-=24; }
                break;
        case BORDERNORMAL:
                WinL=NoWinL; WinR=NoWinR; WinT=NoWinT; WinB=NoWinB;
                if (zx81.NTSC) { WinT-=24; WinB-=24; }
                break;
        case BORDERLARGE:
                WinL=LaWinL; WinR=LaWinR; WinT=LaWinT; WinB=LaWinB;
                if (zx81.NTSC) { WinB-=24; }
                break;
        case BORDERFULL:
                WinL=FuWinL; WinR=FuWinR; WinT=FuWinT; WinB=FuWinB;
                if (zx81.NTSC) WinB-=51;
                break;
        }

        ZeroMemory( &ddsd, sizeof( ddsd ) );
        ddsd.dwSize = sizeof( ddsd );
        // Create the backbuffer surface
        ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
        ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;

        if (tv.AdvancedEffects)
        {
                WinL*=2; WinR*=2; WinT*=2; WinB*=2; ScanLen*=2;
                TVW=ddsd.dwWidth = 1024;
                TVH=ddsd.dwHeight = 768;
                HSYNC_TOLLERANCE=HTOL*2; HSYNC_MINLEN=10;
                VSYNC_TOLLERANCE=VTOL*2; VSYNC_MINLEN=350;
        }
        else
        {
                TVW=ddsd.dwWidth = 520;
                TVH=ddsd.dwHeight = 380;
                HSYNC_TOLLERANCE=HTOL; HSYNC_MINLEN=10;
                VSYNC_TOLLERANCE=VTOL; VSYNC_MINLEN=350;
        }

        m_pddsFrame->Release(); m_pddsFrame = NULL;
        m_pDD->CreateSurface(&ddsd, &m_pddsFrame, NULL);

        if (zx81.NTSC) VSYNC_TOLLERANCE-=60;

        if ((resize) && (!Form1->FullScreen))
        {
                Form1->BaseWidth=WinR-WinL;
                Form1->BaseHeight=WinB-WinT;

                OrigW = Form1->BaseWidth * ScaleW;
                OrigH = Form1->BaseHeight * ScaleH;
                if (Form1->StatusBar1->Visible) OrigH += Form1->StatusBar1->Height;

                Form1->ClientWidth = OrigW;
                Form1->ClientHeight = OrigH;
        }

        DDFrame=m_pddsFrame;

        ZeroMemory(&DDFrameSurface, sizeof(DDFrameSurface));
        DDFrameSurface.dwSize = sizeof(DDFrameSurface);
        DDFrame->Lock(NULL, &DDFrameSurface, DDLOCK_WAIT |  DDLOCK_NOSYSLOCK, NULL);
        dest=buffer= (BYTE*)DDFrameSurface.lpSurface;
        TVP=DDFrameSurface.lPitch;

        RecalcPalette();
        RecalcWinSize();
}
Example #3
0
int Game_Init(void *parms = NULL, int num_parms = 0)
{
   // this is called once after the initial window is created and
   // before the main event loop is entered, do all your initialization
   // here
   int retval = 0;
   colors16 = new WORD[65536];

   // create IDirectDraw interface 7.0 object and test for error
   if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)))
   {

      // something bad happened during initialization, buh-bye!
      SendMessage(main_window_handle,WM_CLOSE,0,0);   
      g_ddStepFailure = DDSF_DDACCESS;

      retval = 0;
   }
   else
   {
      // set cooperation to normal since this will be a windowed app
      lpdd->SetCooperativeLevel( main_window_handle, 
                                    DDSCL_FULLSCREEN
                                 |  DDSCL_ALLOWMODEX
                                 |  DDSCL_EXCLUSIVE
                                 |  DDSCL_ALLOWREBOOT
                                 |  DDSCL_MULTITHREADED      );
                                 
      if (FAILED(lpdd->SetDisplayMode( screen_width,
                                       screen_height,
                                       screen_bpp,
                                       0,                // refresh rate (use default)
                                       0              )  // flags..
                )
         )           
      {
         SendMessage(main_window_handle,WM_CLOSE,0,0);   
         g_ddStepFailure = DDSF_SETDISPLAYMODE;
         retval = 0;
      }
      else
      {

         {
            // create direct draw surface..
            memset(&ddsd,0,sizeof(ddsd));
            ddsd.dwSize = sizeof(ddsd);
            ddsd.dwFlags = DDSD_CAPS;
            ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
            if (FAILED(lpdd->CreateSurface(&ddsd,
                                           &lpddsprimary,
                                           NULL) 
                      )
               )
            {
               SendMessage(main_window_handle,WM_CLOSE,0,0);   
               g_ddStepFailure = DDSF_SURFACECREATE;
               retval = 0;
            }
            else
            {
            
               {
                  // now get the pixel format..
                  //
                  
                  memset(&ddpixel,0,sizeof(ddpixel));
                  
                  ddpixel.dwSize = sizeof(ddpixel);
                  
                  lpddsprimary->GetPixelFormat(&ddpixel);
                  
                  if (ddpixel.dwFlags & DDPF_RGB)
                  {
                     // RGB mode..
                     switch(ddpixel.dwRGBBitCount)
                     {
                        case 15:
                           {
                              // 5.5.5
                              g_rgb16bitmode = RGB16MODE_555;
                              makeColors555();
                              
                              MessageBox(main_window_handle,
                              "5.5.5",
                              "bit mode detected...",
                              MB_OK | MB_ICONEXCLAMATION );
                              
                           }
                           break;
                        case 16:
                           {
                              // 5.6.5
                              g_rgb16bitmode = RGB16MODE_565;
                              makeColors565();
                              
                              MessageBox(main_window_handle,
                              "5.6.5",
                              "bit mode detected...",
                              MB_OK | MB_ICONEXCLAMATION );
                           }
                           break;
                        
                        case 24:
                           {
                              // 8.8.8
                           }
                           break;
                        
                        case 32:
                           {
                              // alpha(8) 8.8.8
                           }
                           break;
                           
                        default:
                           {
                           }
                        
                           break;
                     }
                  }
                  
                  retval = 1;            
               }
            }
         }
      }
   }

   // return success or failure or your own return code here
   return(retval);

} // end Game_Init