eliminate texrels (wip)
[picodrive.git] / pico / videoport.c
index ab02af8..1e67ddb 100644 (file)
@@ -8,8 +8,8 @@
  */\r
 \r
 #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
@@ -22,7 +22,7 @@ typedef unsigned int   u32;
 \r
 int (*PicoDmaHook)(unsigned int source, int len, unsigned short **srcp, unsigned short **limitp) = NULL;\r
 \r
-static __inline void AutoIncrement(void)\r
+static INLINE void AutoIncrement(void)\r
 {\r
   Pico.video.addr=(unsigned short)(Pico.video.addr+Pico.video.reg[0xf]);\r
 }\r
@@ -36,7 +36,7 @@ static void VideoWrite(u16 d)
     case 1: if(a&1) d=(u16)((d<<8)|(d>>8)); // If address is odd, bytes are swapped (which game needs this?)\r
             Pico.vram [(a>>1)&0x7fff]=d;\r
             if (a - ((unsigned)(Pico.video.reg[5]&0x7f) << 9) < 0x400)\r
-              rendstatus |= PDRAW_DIRTY_SPRITES;\r
+              Pico.est.rendstatus |= PDRAW_DIRTY_SPRITES;\r
             break;\r
     case 3: Pico.m.dirtyPal = 1;\r
             Pico.cram [(a>>1)&0x003f]=d; break; // wraps (Desert Strike)\r
@@ -93,8 +93,7 @@ static void DmaSlow(int len)
     SekCyclesDone(), SekPc);\r
 \r
   Pico.m.dma_xfers += len;\r
-  if ((PicoAHW & PAHW_MCD) && (PicoOpt & POPT_EN_MCD_PSYNC)) SekCyclesBurn(CheckDMA());\r
-  else SekEndTimeslice(SekCyclesLeftNoMCD - CheckDMA());\r
+  SekCyclesBurnRun(CheckDMA());\r
 \r
   if ((source&0xe00000)==0xe00000) { // Ram\r
     pd=(u16 *)(Pico.ram+(source&0xfffe));\r
@@ -157,7 +156,7 @@ static void DmaSlow(int len)
       if (inc == 2 && !(a&1) && a+len*2 < 0x10000)\r
       {\r
         // most used DMA mode\r
-        memcpy16(r + (a>>1), pd, len);\r
+        pmemcpy16(r + (a>>1), pd, len);\r
         a += len*2;\r
       }\r
       else\r
@@ -173,7 +172,7 @@ static void DmaSlow(int len)
           //if(pd >= pdend) pd-=0x8000; // should be good for RAM, bad for ROM\r
         }\r
       }\r
-      rendstatus |= PDRAW_DIRTY_SPRITES;\r
+      Pico.est.rendstatus |= PDRAW_DIRTY_SPRITES;\r
       break;\r
 \r
     case 3: // cram\r
@@ -208,7 +207,8 @@ static void DmaSlow(int len)
       break;\r
 \r
     default:\r
-      elprintf(EL_VDPDMA|EL_ANOMALY, "DMA with bad type %i", Pico.video.type);\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
       break;\r
   }\r
   // remember addr\r
@@ -241,7 +241,7 @@ static void DmaCopy(int len)
   }\r
   // remember addr\r
   Pico.video.addr=a;\r
-  rendstatus |= PDRAW_DIRTY_SPRITES;\r
+  Pico.est.rendstatus |= PDRAW_DIRTY_SPRITES;\r
 }\r
 \r
 // check: Contra, Megaman\r
@@ -280,7 +280,7 @@ static void DmaFill(int data)
   // update length\r
   Pico.video.reg[0x13] = Pico.video.reg[0x14] = 0; // Dino Dini's Soccer (E) (by Haze)\r
 \r
-  rendstatus |= PDRAW_DIRTY_SPRITES;\r
+  Pico.est.rendstatus |= PDRAW_DIRTY_SPRITES;\r
 }\r
 \r
 static void CommandDma(void)\r
@@ -319,7 +319,7 @@ static void CommandChange(void)
 static void DrawSync(int blank_on)\r
 {\r
   if (Pico.m.scanline < 224 && !(PicoOpt & POPT_ALT_RENDERER) &&\r
-      !PicoSkipFrame && DrawScanline <= Pico.m.scanline) {\r
+      !PicoSkipFrame && Pico.est.DrawScanline <= Pico.m.scanline) {\r
     //elprintf(EL_ANOMALY, "sync");\r
     PicoDrawSync(Pico.m.scanline, blank_on);\r
   }\r
@@ -361,8 +361,7 @@ PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d)
         pvid->lwrite_cnt++;\r
         if (pvid->lwrite_cnt >= 4) pvid->status|=0x100; // FIFO full\r
         if (pvid->lwrite_cnt >  4) {\r
-          SekCyclesBurn(32); // penalty // 488/12-8\r
-          if (SekCycleCnt>=SekCycleAim) SekEndRun(0);\r
+          SekCyclesBurnRun(32); // penalty // 488/12-8\r
         }\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
@@ -397,7 +396,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
@@ -412,7 +412,7 @@ PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d)
             goto update_irq;\r
           case 0x05:\r
             //elprintf(EL_STATUS, "spritep moved to %04x", (unsigned)(Pico.video.reg[5]&0x7f) << 9);\r
-            if (d^dold) rendstatus |= PDRAW_SPRITES_MOVED;\r
+            if (d^dold) Pico.est.rendstatus |= PDRAW_SPRITES_MOVED;\r
             break;\r
           case 0x0c:\r
             // renderers should update their palettes if sh/hi mode is changed\r
@@ -424,7 +424,7 @@ PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d)
 update_irq:\r
 #ifndef EMU_CORE_DEBUG\r
         // update IRQ level\r
-        if (!SekShouldInterrupt) // hack\r
+        if (!SekShouldInterrupt()) // hack\r
         {\r
           int lines, pints, irq=0;\r
           lines = (pvid->reg[1] & 0x20) | (pvid->reg[0] & 0x10);\r
@@ -458,7 +458,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
@@ -488,12 +489,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
@@ -527,7 +527,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
@@ -535,7 +535,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
@@ -545,3 +545,5 @@ unsigned int PicoVideoRead8(unsigned int a)
 \r
   return 0;\r
 }\r
+\r
+// vim:shiftwidth=2:ts=2:expandtab\r