some support for vdp debug reg
[picodrive.git] / pico / videoport.c
index 3f26d58..fe96139 100644 (file)
@@ -29,6 +29,13 @@ static __inline void AutoIncrement(void)
   Pico.video.addr=(unsigned short)(Pico.video.addr+Pico.video.reg[0xf]);\r
 }\r
 \r
+static NOINLINE void VideoWrite128(u32 a, u16 d)\r
+{\r
+  // nasty\r
+  a = ((a & 2) >> 1) | ((a & 0x400) >> 9) | (a & 0x3FC) | ((a & 0x1F800) >> 1);\r
+  ((u8 *)Pico.vram)[a] = d;\r
+}\r
+\r
 static void VideoWrite(u16 d)\r
 {\r
   unsigned int a=Pico.video.addr;\r
@@ -43,6 +50,10 @@ static void VideoWrite(u16 d)
     case 3: Pico.m.dirtyPal = 1;\r
             Pico.cram [(a>>1)&0x003f]=d; break; // wraps (Desert Strike)\r
     case 5: Pico.vsram[(a>>1)&0x003f]=d; break;\r
+    case 0x81:\r
+      a |= Pico.video.addr_u << 16;\r
+      VideoWrite128(a, d);\r
+      break;\r
     //default:elprintf(EL_ANOMALY, "VDP write %04x with bad type %i", d, Pico.video.type); break;\r
   }\r
 \r
@@ -186,6 +197,17 @@ static void DmaSlow(int len, unsigned int source)
       }\r
       break;\r
 \r
+    case 0x81: // vram 128k\r
+      a |= Pico.video.addr_u << 16;\r
+      for(; len; len--)\r
+      {\r
+        VideoWrite128(a, base[source++ & mask]);\r
+        // AutoIncrement\r
+        a = (a + inc) & 0x1ffff;\r
+      }\r
+      Pico.video.addr_u = a >> 16;\r
+      break;\r
+\r
     default:\r
       if (Pico.video.type != 0 || (EL_LOGMASK & EL_VDPDMA))\r
         elprintf(EL_VDPDMA|EL_ANOMALY, "DMA with bad type %i", Pico.video.type);\r
@@ -303,20 +325,23 @@ static NOINLINE void CommandDma(void)
   Pico.video.reg[0x16] = source >> 8;\r
 }\r
 \r
-static void CommandChange(void)\r
+static NOINLINE void CommandChange(void)\r
 {\r
-  struct PicoVideo *pvid=&Pico.video;\r
-  unsigned int cmd=0,addr=0;\r
+  struct PicoVideo *pvid = &Pico.video;\r
+  unsigned int cmd, addr;\r
 \r
-  cmd=pvid->command;\r
+  cmd = pvid->command;\r
 \r
   // Get type of transfer 0xc0000030 (v/c/vsram read/write)\r
-  pvid->type=(unsigned char)(((cmd>>2)&0xc)|(cmd>>30));\r
+  pvid->type = (u8)(((cmd >> 2) & 0xc) | (cmd >> 30));\r
+  if (pvid->type == 1) // vram\r
+    pvid->type |= pvid->reg[1] & 0x80; // 128k\r
 \r
   // Get address 0x3fff0003\r
-  addr =(cmd>>16)&0x3fff;\r
-  addr|=(cmd<<14)&0xc000;\r
-  pvid->addr=(unsigned short)addr;\r
+  addr  = (cmd >> 16) & 0x3fff;\r
+  addr |= (cmd << 14) & 0xc000;\r
+  pvid->addr = (u16)addr;\r
+  pvid->addr_u = (u8)((cmd >> 2) & 1);\r
 }\r
 \r
 static void DrawSync(int blank_on)\r
@@ -336,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
@@ -367,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
@@ -448,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