md vdp, fix v_counter reading, some cleanup
authorkub <derkub@gmail.com>
Fri, 14 Jun 2024 21:05:37 +0000 (23:05 +0200)
committerkub <derkub@gmail.com>
Fri, 14 Jun 2024 22:12:11 +0000 (00:12 +0200)
pico/videoport.c

index 4adf7a7..1410d1e 100644 (file)
@@ -944,13 +944,8 @@ PICO_INTERNAL_ASM void PicoVideoWrite(u32 a,unsigned short d)
         }\r
 \r
         d &= 0xff;\r
-        if (num == 0 && !(pvid->reg[0]&2) && (d&2))\r
-          pvid->hv_latch = PicoVideoRead(0x08);\r
-        if (num == 12 && ((pvid->reg[12]^d)&0x01))\r
-          PicoVideoFIFOMode(pvid->reg[1]&0x40, d & 1);\r
 \r
         if (num == 1 && ((pvid->reg[1]^d)&0x40)) {\r
-          PicoVideoFIFOMode(d & 0x40, pvid->reg[12]&1);\r
           // handle line blanking before line rendering. Only the last switch\r
           // before the 1st sync for other reasons is honoured.\r
           PicoVideoSync(1);\r
@@ -965,15 +960,21 @@ PICO_INTERNAL_ASM void PicoVideoWrite(u32 a,unsigned short d)
         switch (num)\r
         {\r
           case 0x00:\r
+            if ((~dold&d)&2) {\r
+              unsigned c = SekCyclesDone() - Pico.t.m68c_line_start;\r
+              pvid->hv_latch = VdpFIFO.fifo_hcounts[c/clkdiv] | (pvid->v_counter << 8);\r
+            }\r
             elprintf(EL_INTSW, "hint_onoff: %i->%i [%u] pend=%i @ %06x", (dold&0x10)>>4,\r
                     (d&0x10)>>4, SekCyclesDone(), (pvid->pending_ints&0x10)>>4, SekPc);\r
             goto update_irq;\r
           case 0x01:\r
-            elprintf(EL_INTSW, "vint_onoff: %i->%i [%u] pend=%i @ %06x", (dold&0x20)>>5,\r
-                    (d&0x20)>>5, SekCyclesDone(), (pvid->pending_ints&0x20)>>5, SekPc);\r
+            if ((d^dold)&0x40)\r
+              PicoVideoFIFOMode(d & 0x40, pvid->reg[12]&1);\r
             if (!(pvid->status & PVS_VB2))\r
               pvid->status &= ~SR_VB;\r
             pvid->status |= ((d >> 3) ^ SR_VB) & SR_VB; // forced blanking\r
+            elprintf(EL_INTSW, "vint_onoff: %i->%i [%u] pend=%i @ %06x", (dold&0x20)>>5,\r
+                    (d&0x20)>>5, SekCyclesDone(), (pvid->pending_ints&0x20)>>5, SekPc);\r
             goto update_irq;\r
           case 0x05:\r
           case 0x06:\r
@@ -982,7 +983,10 @@ PICO_INTERNAL_ASM void PicoVideoWrite(u32 a,unsigned short d)
           case 0x0c:\r
             // renderers should update their palettes if sh/hi mode is changed\r
             if ((d^dold)&8) Pico.m.dirtyPal = 1;\r
-            if ((d^dold)&1) Pico.est.rendstatus |= PDRAW_DIRTY_SPRITES;\r
+            if ((d^dold)&1) {\r
+              PicoVideoFIFOMode(pvid->reg[1]&0x40, d & 1);\r
+              Pico.est.rendstatus |= PDRAW_DIRTY_SPRITES;\r
+            }\r
             break;\r
           default:\r
             return;\r
@@ -1154,8 +1158,11 @@ unsigned char PicoVideoRead8CtlL(int is_from_z80)
 \r
 unsigned char PicoVideoRead8HV_H(int is_from_z80)\r
 {\r
-  elprintf(EL_HVCNT, "vcounter: %02x [%u] @ %06x", Pico.video.v_counter, SekCyclesDone(), SekPc);\r
-  return Pico.video.v_counter;\r
+  u32 d = Pico.video.v_counter;\r
+  if (Pico.video.reg[0]&2)\r
+    d = Pico.video.hv_latch >> 8;\r
+  elprintf(EL_HVCNT, "vcounter: %02x [%u] @ %06x", d, SekCyclesDone(), SekPc);\r
+  return d;\r
 }\r
 \r
 // FIXME: broken\r