]> git.sesse.net Git - pistorm/blobdiff - platforms/amiga/rtg/rtg_driver_amiga/pigfx-2.c
Add somewhat proper RTG vsync handling
[pistorm] / platforms / amiga / rtg / rtg_driver_amiga / pigfx-2.c
index 996dffdfffdd13aa0dfe9b8eca23e1129b45b06d..eb0bb57051d84e525ab51778da2f75ef0f477de8 100644 (file)
@@ -80,6 +80,7 @@ void SetClearMask (__REGA0(struct BoardInfo *b), __REGD0(UBYTE mask));
 void SetReadPlane (__REGA0(struct BoardInfo *b), __REGD0(UBYTE plane));
 
 void WaitVerticalSync (__REGA0(struct BoardInfo *b), __REGD0(BOOL toggle));
+BOOL GetVSyncState(__REGA0(struct BoardInfo *b), __REGD0(BOOL toggle));
 
 void FillRect (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD w), __REGD3(WORD h), __REGD4(ULONG color), __REGD5(UBYTE mask), __REGD7(RGBFTYPE format));
 void InvertRect (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD w), __REGD3(WORD h), __REGD4(UBYTE mask), __REGD7(RGBFTYPE format));
@@ -305,7 +306,7 @@ int __attribute__((used)) InitCard(__REGA0(struct BoardInfo* b)) {
     //b->SetSplitPosition = (void *)NULL;
     //b->ReInitMemory = (void *)NULL;
     //b->WriteYUVRect = (void *)NULL;
-    //b->GetVSyncState = (void *)NULL;
+    b->GetVSyncState = (void *)GetVSyncState;
     //b->GetVBeamPos = (void *)NULL;
     //b->SetDPMSLevel = (void *)NULL;
     //b->ResetChip = (void *)NULL;
@@ -461,8 +462,18 @@ void SetClearMask (__REGA0(struct BoardInfo *b), __REGD0(UBYTE mask)) {
 void SetReadPlane (__REGA0(struct BoardInfo *b), __REGD0(UBYTE plane)) {
 }
 
+static uint16_t vblank;
+
 void WaitVerticalSync (__REGA0(struct BoardInfo *b), __REGD0(BOOL toggle)) {
-    // I don't know why this one has a bool in D0, but it isn't used for anything.
+    vblank = 0;
+    do {
+        READSHORT(RTG_WAITVSYNC, vblank);
+    } while (!vblank);
+}
+
+BOOL GetVSyncState(__REGA0(struct BoardInfo *b), __REGD0(BOOL toggle)) {
+    READSHORT(RTG_INVBLANK, vblank);
+    return vblank;
 }
 
 void FillRect (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD w), __REGD3(WORD h), __REGD4(ULONG color), __REGD5(UBYTE mask), __REGD7(RGBFTYPE format)) {
@@ -552,6 +563,7 @@ void BlitRectNoMaskComplete (__REGA0(struct BoardInfo *b), __REGA1(struct Render
 }
 
 void BlitTemplate (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGA2(struct Template *t), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD w), __REGD3(WORD h), __REGD4(UBYTE mask), __REGD7(RGBFTYPE format)) {
+#ifndef IRTG
     if (!r || !t) return;
     if (w < 1 || h < 1) return;
 
@@ -584,9 +596,13 @@ void BlitTemplate (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r),
     WRITEBYTE(RTG_U81, mask);
     WRITEBYTE(RTG_U82, t->DrawMode);
     WRITESHORT(RTG_COMMAND, RTGCMD_BLITTEMPLATE);
+#else
+    IWRITECMD(RTGCMD_BLITTEMPLATE);
+#endif
 }
 
 void BlitPattern (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGA2(struct Pattern *p), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD w), __REGD3(WORD h), __REGD4(UBYTE mask), __REGD7(RGBFTYPE format)) {
+#ifndef IRTG
     if (!r || !p) return;
     if (w < 1 || h < 1) return;
 
@@ -619,6 +635,9 @@ void BlitPattern (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), _
     WRITEBYTE(RTG_U82, p->DrawMode);
     WRITEBYTE(RTG_U83, (1 << p->Size));
     WRITESHORT(RTG_COMMAND, RTGCMD_BLITPATTERN);
+#else
+    IWRITECMD(RTGCMD_BLITPATTERN);
+#endif
 }
 
 void DrawLine (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGA2(struct Line *l), __REGD0(UBYTE mask), __REGD7(RGBFTYPE format)) {
@@ -653,6 +672,8 @@ void DrawLine (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __RE
 }
 
 void BlitPlanar2Chunky (__REGA0(struct BoardInfo *b), __REGA1(struct BitMap *bm), __REGA2(struct RenderInfo *r), __REGD0(SHORT x), __REGD1(SHORT y), __REGD2(SHORT dx), __REGD3(SHORT dy), __REGD4(SHORT w), __REGD5(SHORT h), __REGD6(UBYTE minterm), __REGD7(UBYTE mask)) {
+// iRTG path disabled for now, since it's really slow, see note in rtg-gfx.c.
+//#ifndef IRTG    
     if (!b || !r)
         return;
 
@@ -710,6 +731,9 @@ void BlitPlanar2Chunky (__REGA0(struct BoardInfo *b), __REGA1(struct BitMap *bm)
     WRITEBYTE(RTG_U83, bm->Depth);
 
     WRITESHORT(RTG_COMMAND, RTGCMD_P2C);
+//#else
+//    IWRITECMD(RTGCMD_P2C);
+//#endif
 }
 
 void BlitPlanar2Direct (__REGA0(struct BoardInfo *b), __REGA1(struct BitMap *bm), __REGA2(struct RenderInfo *r), __REGA3(struct ColorIndexMapping *clut), __REGD0(SHORT x), __REGD1(SHORT y), __REGD2(SHORT dx), __REGD3(SHORT dy), __REGD4(SHORT w), __REGD5(SHORT h), __REGD6(UBYTE minterm), __REGD7(UBYTE mask)) {