vdp timing hacks
[picodrive.git] / pico / videoport.c
index fe96139..4da3ce3 100644 (file)
@@ -223,7 +223,7 @@ static void DmaCopy(int len)
   unsigned char *vr = (unsigned char *) Pico.vram;\r
   unsigned char inc=Pico.video.reg[0xf];\r
   int source;\r
-  elprintf(EL_VDPDMA, "DmaCopy len %i [%i]", len, SekCyclesDone());\r
+  elprintf(EL_VDPDMA, "DmaCopy len %i [%u]", len, SekCyclesDone());\r
 \r
   Pico.m.dma_xfers += len;\r
   if (Pico.m.dma_xfers < len)\r
@@ -254,7 +254,7 @@ static NOINLINE void DmaFill(int data)
   int len, l;\r
 \r
   len = GetDmaLength();\r
-  elprintf(EL_VDPDMA, "DmaFill len %i inc %i [%i]", len, inc, SekCyclesDone());\r
+  elprintf(EL_VDPDMA, "DmaFill len %i inc %i [%u]", len, inc, SekCyclesDone());\r
 \r
   Pico.m.dma_xfers += len;\r
   if (Pico.m.dma_xfers < len) // lame 16bit var\r
@@ -377,14 +377,12 @@ PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d)
     }\r
 \r
     // preliminary FIFO emulation for Chaos Engine, The (E)\r
-    if (!(pvid->status&8) && (pvid->reg[1]&0x40) && !(PicoOpt&POPT_DIS_VDP_FIFO)) // active display?\r
+    if (!(pvid->status & SR_VB) && (pvid->reg[1] & 0x40) && !(PicoOpt&POPT_DIS_VDP_FIFO)) // active display?\r
     {\r
-      pvid->status&=~0x200; // FIFO no longer empty\r
-      pvid->lwrite_cnt++;\r
-      if (pvid->lwrite_cnt >= 4) pvid->status|=0x100; // FIFO full\r
-      if (pvid->lwrite_cnt >  4) {\r
-        SekCyclesBurnRun(32); // penalty // 488/12-8\r
-      }\r
+      int use = pvid->type == 1 ? 2 : 1;\r
+      pvid->lwrite_cnt -= use;\r
+      if (pvid->lwrite_cnt < 0)\r
+        SekCyclesLeft = 0;\r
       elprintf(EL_ASVDP, "VDP data write: %04x [%06x] {%i} #%i @ %06x", d, Pico.video.addr,\r
                Pico.video.type, pvid->lwrite_cnt, SekPc);\r
     }\r
@@ -430,11 +428,11 @@ PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d)
         switch (num)\r
         {\r
           case 0x00:\r
-            elprintf(EL_INTSW, "hint_onoff: %i->%i [%i] pend=%i @ %06x", (dold&0x10)>>4,\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 [%i] pend=%i @ %06x", (dold&0x20)>>5,\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
@@ -551,7 +549,7 @@ PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a)
          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
+    elprintf(EL_HVCNT, "hv: %02x %02x [%u] @ %06x", d, Pico.video.v_counter, SekCyclesDone(), SekPc);\r
     return d | (Pico.video.v_counter << 8);\r
   }\r
 \r
@@ -563,43 +561,54 @@ PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a)
   return 0;\r
 }\r
 \r
-unsigned int PicoVideoRead8(unsigned int a)\r
+unsigned char PicoVideoRead8DataH(void)\r
 {\r
-  unsigned int d;\r
-  a&=0x1d;\r
+  return VideoRead() >> 8;\r
+}\r
 \r
-  switch (a)\r
-  {\r
-    case 0: return VideoRead() >> 8;\r
-    case 1: return VideoRead() & 0xff;\r
-    case 4: // control port/status reg\r
-      d = Pico.video.status >> 8;\r
-      if (d&1) Pico.video.status&=~0x100; // FIFO no longer full\r
-      Pico.video.pending = 0;\r
-      elprintf(EL_SR, "SR read (h): %02x @ %06x", d, SekPc);\r
-      return d;\r
-    case 5:\r
-      d = Pico.video.status & 0xff;\r
-      //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 (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
-    case 8: // hv counter\r
-      elprintf(EL_HVCNT, "vcounter: %02x (%i) @ %06x", Pico.video.v_counter, SekCyclesDone(), SekPc);\r
-      return Pico.video.v_counter;\r
-    case 9:\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
-      elprintf(EL_HVCNT, "hcounter: %02x (%i) @ %06x", d, SekCyclesDone(), SekPc);\r
-      return d;\r
-  }\r
+unsigned char PicoVideoRead8DataL(void)\r
+{\r
+  return VideoRead();\r
+}\r
 \r
-  return 0;\r
+// FIXME: broken mess\r
+unsigned char PicoVideoRead8CtlH(void)\r
+{\r
+  u8 d = (u8)(Pico.video.status >> 8);\r
+  if (d & 1)\r
+    Pico.video.status &= ~0x100; // FIFO no longer full\r
+  Pico.video.pending = 0;\r
+  elprintf(EL_SR, "SR read (h): %02x @ %06x", d, SekPc);\r
+  return d;\r
+}\r
+\r
+unsigned char PicoVideoRead8CtlL(void)\r
+{\r
+  u8 d = (u8)Pico.video.status;\r
+  //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 (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
+}\r
+\r
+unsigned char PicoVideoRead8HV_H(void)\r
+{\r
+  elprintf(EL_HVCNT, "vcounter: %02x [%u] @ %06x", Pico.video.v_counter, SekCyclesDone(), SekPc);\r
+  return Pico.video.v_counter;\r
+}\r
+\r
+// FIXME: broken\r
+unsigned char PicoVideoRead8HV_L(void)\r
+{\r
+  u32 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
+  elprintf(EL_HVCNT, "hcounter: %02x [%u] @ %06x", d, SekCyclesDone(), SekPc);\r
+  return d;\r
 }\r
 \r
 // vim:shiftwidth=2:ts=2:expandtab\r