dfxvideo: allow frameskip in interlace mode too
[pcsx_rearmed.git] / plugins / dfxvideo / gpu.c
index 50d45d5..b384526 100644 (file)
@@ -51,6 +51,8 @@ DATAREGISTERMODES DataWriteMode;
 DATAREGISTERMODES DataReadMode;
 
 BOOL              bSkipNextFrame = FALSE;
+BOOL              fskip_frameReady;
+DWORD             lace_count_since_flip;
 DWORD             dwLaceCnt=0;
 short             sDispWidths[8] = {256,320,512,640,368,384,512,640};
 PSXDisplay_t      PSXDisplay;
@@ -59,6 +61,7 @@ long              lSelectedSlot=0;
 BOOL              bDoLazyUpdate=FALSE;
 uint32_t          lGPUInfoVals[16];
 static int        iFakePrimBusy=0;
+static uint32_t   vBlank=0;
 
 ////////////////////////////////////////////////////////////////////////
 // some misc external display funcs
@@ -204,22 +207,36 @@ static void updateDisplay(void)                               // UPDATE DISPLAY
 
  if(UseFrameSkip)                                      // skip ?
   {
-   if(!bSkipNextFrame) DoBufferSwap();                 // -> to skip or not to skip
-   if(dwActFixes&0xa0)                                 // -> pc fps calculation fix/old skipping fix
+   if(fskip_frameReady)
     {
-     if((fps_skip < fFrameRateHz) && !(bSkipNextFrame))  // -> skip max one in a row
-         {bSkipNextFrame = TRUE; fps_skip=fFrameRateHz;}
-     else bSkipNextFrame = FALSE;
+     DoBufferSwap();                                   // -> to skip or not to skip
+     fskip_frameReady=FALSE;
+     bDoVSyncUpdate=FALSE;                             // vsync done
     }
-   else FrameSkip();
   }
  else                                                  // no skip ?
   {
    bSkipNextFrame = FALSE;
    DoBufferSwap();                                     // -> swap
+   bDoVSyncUpdate=FALSE;                               // vsync done
   }
+}
+
+static void decideSkip(void)
+{
+ if(!bDoVSyncUpdate)
+   return;
+
+ lace_count_since_flip=0;
+ fskip_frameReady=!bSkipNextFrame;
 
-  bDoVSyncUpdate=FALSE;                                // vsync done
+ if(dwActFixes&0xa0)                                   // -> pc fps calculation fix/old skipping fix
+  {
+   if((fps_skip < fFrameRateHz) && !bSkipNextFrame)    // -> skip max one in a row
+       {bSkipNextFrame = TRUE; fps_skip=fFrameRateHz;}
+   else bSkipNextFrame = FALSE;
+  }
+ else FrameSkip();
 }
 
 ////////////////////////////////////////////////////////////////////////
@@ -375,7 +392,7 @@ static void updateDisplayIfChanged(void)                      // UPDATE DISPLAY
 
  if(iFrameLimit==2) SetAutoFrameCap();                 // -> set it
 
- if(UseFrameSkip) updateDisplay();                     // stupid stuff when frame skipping enabled
+ if(UseFrameSkip) decideSkip();                        // stupid stuff when frame skipping enabled
 }
 
 ////////////////////////////////////////////////////////////////////////
@@ -384,8 +401,8 @@ static void updateDisplayIfChanged(void)                      // UPDATE DISPLAY
 
 void CALLBACK GPUupdateLace(void)                      // VSYNC
 {
- if(!(dwActFixes&1))
-  lGPUstatusRet^=0x80000000;                           // odd/even bit
//if(!(dwActFixes&1))
// lGPUstatusRet^=0x80000000;                           // odd/even bit
 
  //pcsx-rearmed: removed, this is handled by core
  //if(!(dwActFixes&32))                                  // std fps limitation?
@@ -393,6 +410,8 @@ void CALLBACK GPUupdateLace(void)                      // VSYNC
 
  if(PSXDisplay.Interlaced)                             // interlaced mode?
   {
+   lGPUstatusRet^=0x80000000;                          // odd/even bit?
+
    if(bDoVSyncUpdate && PSXDisplay.DisplayMode.x>0 && PSXDisplay.DisplayMode.y>0)
     {
      updateDisplay();
@@ -402,20 +421,24 @@ void CALLBACK GPUupdateLace(void)                      // VSYNC
   {
    if(dwActFixes&64)                                   // lazy screen update fix
     {
-     if(bDoLazyUpdate && !UseFrameSkip) 
+     if(bDoLazyUpdate)
       updateDisplay(); 
      bDoLazyUpdate=FALSE;
     }
    else
     {
-     if((bDoVSyncUpdate && !UseFrameSkip)              // some primitives drawn?
-      || bDoVSyncUpdate >= 8)                          // not syned for a while
+     if(bDoVSyncUpdate)                                // some primitives drawn?
        updateDisplay();                                // -> update display
     }
   }
 
- if(bDoVSyncUpdate)                                    // if display not synced
-  bDoVSyncUpdate++;                                    // count how many times
+ if(UseFrameSkip) {                                    // frame over-skip guard
+  lace_count_since_flip++;
+  if(lace_count_since_flip > 8) {
+   bSkipNextFrame=FALSE;
+   fskip_frameReady=TRUE;
+  }
+ }
 }
 
 ////////////////////////////////////////////////////////////////////////
@@ -450,7 +473,7 @@ uint32_t CALLBACK GPUreadStatus(void)             // READ STATUS
      GPUIsReadyForCommands;
     }
   }
- return lGPUstatusRet;
+ return lGPUstatusRet | vBlank;
 }
 
 ////////////////////////////////////////////////////////////////////////
@@ -552,9 +575,9 @@ void CALLBACK GPUwriteStatus(uint32_t gdata)      // WRITE STATUS
 
      if (!(PSXDisplay.Interlaced))                      // stupid frame skipping option
       {
-       if(UseFrameSkip)  updateDisplay();
        if(dwActFixes&64) bDoLazyUpdate=TRUE;
       }
+     if(UseFrameSkip)  decideSkip();
     }return;
    //--------------------------------------------------//
    // setting width
@@ -1103,3 +1126,9 @@ long CALLBACK GPUfreeze(uint32_t ulGetFreezeData,GPUFreeze_t * pF)
 
  return 1;
 }
+
+void CALLBACK GPUvBlank(int val)
+{
+ vBlank=val?0x80000000:0;
+}
+