some poor timing improvement attempts
[picodrive.git] / pico / videoport.c
index b14e70f..0af4bbc 100644 (file)
@@ -361,8 +361,9 @@ PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d)
   //  elprintf(EL_STATUS, "PicoVideoWrite [%06x] %04x", a, d);\r
   a&=0x1c;\r
 \r
-  if (a==0x00) // Data port 0 or 2\r
+  switch (a)\r
   {\r
+  case 0x00: // Data port 0 or 2\r
     // try avoiding the sync..\r
     if (Pico.m.scanline < 224 && (pvid->reg[1]&0x40) &&\r
         !(!pvid->pending &&\r
@@ -392,11 +393,9 @@ PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d)
     if ((pvid->command&0x80) && (pvid->reg[1]&0x10) && (pvid->reg[0x17]>>6)==2)\r
       DmaFill(d);\r
 \r
-    return;\r
-  }\r
+    break;\r
 \r
-  if (a==0x04) // Control (command) port 4 or 6\r
-  {\r
+  case 0x04: // Control (command) port 4 or 6\r
     if (pvid->pending)\r
     {\r
       // Low word of command:\r
@@ -473,6 +472,35 @@ update_irq:
         pvid->pending=1;\r
       }\r
     }\r
+    break;\r
+\r
+  // case 0x08: // 08 0a - HV counter - lock up\r
+  // case 0x0c: // 0c 0e - HV counter - lock up\r
+  // case 0x10: // 10 12 - PSG - handled by caller\r
+  // case 0x14: // 14 16 - PSG - handled by caller\r
+  // case 0x18: // 18 1a - no effect?\r
+  case 0x1c: // 1c 1e - debug\r
+    pvid->debug = d;\r
+    pvid->debug_p = 0;\r
+    if (d & (1 << 6)) {\r
+      pvid->debug_p |= PVD_KILL_A | PVD_KILL_B;\r
+      pvid->debug_p |= PVD_KILL_S_LO | PVD_KILL_S_HI;\r
+    }\r
+    switch ((d >> 7) & 3) {\r
+      case 1:\r
+        pvid->debug_p &= ~(PVD_KILL_S_LO | PVD_KILL_S_HI);\r
+        pvid->debug_p |= PVD_FORCE_S;\r
+        break;\r
+      case 2:\r
+        pvid->debug_p &= ~PVD_KILL_A;\r
+        pvid->debug_p |= PVD_FORCE_A;\r
+        break;\r
+      case 3:\r
+        pvid->debug_p &= ~PVD_KILL_B;\r
+        pvid->debug_p |= PVD_FORCE_B;\r
+        break;\r
+    }\r
+    break;\r
   }\r
 }\r
 \r
@@ -535,43 +563,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 (%i) @ %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 (%i) @ %06x", d, SekCyclesDone(), SekPc);\r
+  return d;\r
 }\r
 \r
 // vim:shiftwidth=2:ts=2:expandtab\r