make hcnt code friendly with split timeslices
[picodrive.git] / pico / videoport.c
index 42f55c8..1e60686 100644 (file)
@@ -10,6 +10,7 @@
 #include "pico_int.h"\r
 #include "cd/gfx_cd.h"\r
 \r
+int line_base_cycles;\r
 extern const unsigned char  hcounts_32[];\r
 extern const unsigned char  hcounts_40[];\r
 \r
@@ -396,7 +397,8 @@ PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d)
           return;\r
         }\r
 \r
-        if (num == 1 && !(d&0x40) && SekCyclesLeft > 390) blank_on = 1;\r
+        if (num == 1 && !(d&0x40) && SekCyclesDone() - line_base_cycles <= 488-390)\r
+          blank_on = 1;\r
         DrawSync(blank_on);\r
         pvid->reg[num]=(unsigned char)d;\r
         switch (num)\r
@@ -457,7 +459,8 @@ PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a)
     unsigned int d;\r
     d=pv->status;\r
     //if (PicoOpt&POPT_ALT_RENDERER) d|=0x0020; // sprite collision (Shadow of the Beast)\r
-    if (SekCyclesLeft < 84+4)      d|=0x0004; // H-Blank (Sonic3 vs)\r
+    if (SekCyclesDone() - line_base_cycles >= 488-88)\r
+      d|=0x0004; // H-Blank (Sonic3 vs)\r
 \r
     d |= ((pv->reg[1]&0x40)^0x40) >> 3;  // set V-Blank if display is disabled\r
     d |= (pv->pending_ints&0x20)<<2;     // V-int pending?\r
@@ -487,12 +490,11 @@ PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a)
   if ((a&0x1c)==0x08)\r
   {\r
     unsigned int d;\r
-    int lineCycles;\r
 \r
-    lineCycles = (488-SekCyclesLeft)&0x1ff;\r
+    d = (SekCyclesDone() - line_base_cycles) & 0x1ff; // FIXME\r
     if (Pico.video.reg[12]&1)\r
-         d = hcounts_40[lineCycles];\r
-    else d = hcounts_32[lineCycles];\r
+         d = hcounts_40[d];\r
+    else d = hcounts_32[d];\r
 \r
     elprintf(EL_HVCNT, "hv: %02x %02x (%i) @ %06x", d, Pico.video.v_counter, SekCyclesDone(), SekPc);\r
     return d | (Pico.video.v_counter << 8);\r
@@ -526,7 +528,7 @@ unsigned int PicoVideoRead8(unsigned int a)
       //if (PicoOpt&POPT_ALT_RENDERER) d|=0x0020; // sprite collision (Shadow of the Beast)\r
       d |= ((Pico.video.reg[1]&0x40)^0x40) >> 3;  // set V-Blank if display is disabled\r
       d |= (Pico.video.pending_ints&0x20)<<2;     // V-int pending?\r
-      if (SekCyclesLeft < 84+4) d |= 4;    // H-Blank\r
+      if (SekCyclesDone() - line_base_cycles >= 488-88) d |= 4;    // H-Blank\r
       Pico.video.pending = 0;\r
       elprintf(EL_SR, "SR read (l): %02x @ %06x", d, SekPc);\r
       return d;\r
@@ -534,7 +536,7 @@ unsigned int PicoVideoRead8(unsigned int a)
       elprintf(EL_HVCNT, "vcounter: %02x (%i) @ %06x", Pico.video.v_counter, SekCyclesDone(), SekPc);\r
       return Pico.video.v_counter;\r
     case 9:\r
-      d = (488-SekCyclesLeft)&0x1ff;\r
+      d = (SekCyclesDone() - line_base_cycles) & 0x1ff; // FIXME\r
       if (Pico.video.reg[12]&1)\r
            d = hcounts_40[d];\r
       else d = hcounts_32[d];\r