let it build on msvc
[picodrive.git] / pico / draw.c
index e2e4fb4..83010a4 100644 (file)
@@ -129,19 +129,12 @@ static void funcname(int sx, unsigned int pack, int pal)     \
 }\r
 \r
 \r
-#ifdef _ASM_DRAW_C_AMIPS\r
-int TileNorm(int sx, unsigned int pack, int pal);\r
-int TileFlip(int sx, unsigned int pack, int pal);\r
-#else\r
-\r
 #define pix_just_write(x) \\r
   if (t) pd[x]=pal|t\r
 \r
 TileNormMaker(TileNorm,pix_just_write)\r
 TileFlipMaker(TileFlip,pix_just_write)\r
 \r
-#endif\r
-\r
 #ifndef _ASM_DRAW_C\r
 \r
 // draw a sprite pixel, process operator colors\r
@@ -222,7 +215,7 @@ static void DrawStrip(struct TileStrip *ts, int lflags, int cellskip)
   {\r
     unsigned int pack;\r
 \r
-    code = Pico.vram[ts->nametab + (tilex & ts->xmask)];\r
+    code = PicoMem.vram[ts->nametab + (tilex & ts->xmask)];\r
     if (code == blank)\r
       continue;\r
     if ((code >> 15) | (lflags & LF_FORCE)) { // high priority tile\r
@@ -242,7 +235,7 @@ static void DrawStrip(struct TileStrip *ts, int lflags, int cellskip)
       pal=((code>>9)&0x30)|sh;\r
     }\r
 \r
-    pack = *(unsigned int *)(Pico.vram + addr);\r
+    pack = *(unsigned int *)(PicoMem.vram + addr);\r
     if (!pack) {\r
       blank = code;\r
       continue;\r
@@ -268,7 +261,11 @@ static void DrawStripVSRam(struct TileStrip *ts, int plane_sh, int cellskip)
   // Draw tiles across screen:\r
   tilex=(-ts->hscroll)>>3;\r
   dx=((ts->hscroll-1)&7)+1;\r
-  if(dx != 8) cell--; // have hscroll, start with negative cell\r
+  if (ts->hscroll & 0x0f) {\r
+    int adj = ((ts->hscroll ^ dx) >> 3) & 1;\r
+    cell -= adj + 1;\r
+    ts->cells -= adj;\r
+  }\r
   cell+=cellskip;\r
   tilex+=cellskip;\r
   dx+=cellskip<<3;\r
@@ -281,7 +278,7 @@ static void DrawStripVSRam(struct TileStrip *ts, int plane_sh, int cellskip)
     //if((cell&1)==0)\r
     {\r
       int line,vscroll;\r
-      vscroll=Pico.vsram[(plane_sh&1)+(cell&~1)];\r
+      vscroll=PicoMem.vsram[(plane_sh&1)+(cell&~1)];\r
 \r
       // Find the line in the name table\r
       line=(vscroll+scan)&ts->line&0xffff; // ts->line is really ymask ..\r
@@ -289,7 +286,7 @@ static void DrawStripVSRam(struct TileStrip *ts, int plane_sh, int cellskip)
       ty=(line&7)<<1; // Y-Offset into tile\r
     }\r
 \r
-    code=Pico.vram[ts->nametab+nametabadd+(tilex&ts->xmask)];\r
+    code=PicoMem.vram[ts->nametab+nametabadd+(tilex&ts->xmask)];\r
     if (code==blank) continue;\r
     if (code>>15) { // high priority tile\r
       int cval = code | (dx<<16) | (ty<<25);\r
@@ -307,7 +304,7 @@ static void DrawStripVSRam(struct TileStrip *ts, int plane_sh, int cellskip)
       pal=((code>>9)&0x30)|((plane_sh<<5)&0x40);\r
     }\r
 \r
-    pack = *(unsigned int *)(Pico.vram + addr);\r
+    pack = *(unsigned int *)(PicoMem.vram + addr);\r
     if (!pack) {\r
       blank = code;\r
       continue;\r
@@ -343,7 +340,7 @@ void DrawStripInterlace(struct TileStrip *ts)
   {\r
     unsigned int pack;\r
 \r
-    code=Pico.vram[ts->nametab+(tilex&ts->xmask)];\r
+    code = PicoMem.vram[ts->nametab + (tilex & ts->xmask)];\r
     if (code==blank) continue;\r
     if (code>>15) { // high priority tile\r
       int cval = (code&0xfc00) | (dx<<16) | (ty<<25);\r
@@ -363,7 +360,7 @@ void DrawStripInterlace(struct TileStrip *ts)
       pal=((code>>9)&0x30);\r
     }\r
 \r
-    pack = *(unsigned int *)(Pico.vram + addr);\r
+    pack = *(unsigned int *)(PicoMem.vram + addr);\r
     if (!pack) {\r
       blank = code;\r
       continue;\r
@@ -416,11 +413,11 @@ static void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells,
   htab+=plane_sh&1; // A or B\r
 \r
   // Get horizontal scroll value, will be masked later\r
-  ts.hscroll=Pico.vram[htab&0x7fff];\r
+  ts.hscroll = PicoMem.vram[htab & 0x7fff];\r
 \r
   if((pvid->reg[12]&6) == 6) {\r
     // interlace mode 2\r
-    vscroll=Pico.vsram[plane_sh&1]; // Get vertical scroll value\r
+    vscroll = PicoMem.vsram[plane_sh & 1]; // Get vertical scroll value\r
 \r
     // Find the line in the name table\r
     ts.line=(vscroll+(est->DrawScanline<<1))&((ymask<<1)|1);\r
@@ -433,7 +430,7 @@ static void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells,
     ts.line=ymask|(shift[width]<<24); // save some stuff instead of line\r
     DrawStripVSRam(&ts, plane_sh, cellskip);\r
   } else {\r
-    vscroll=Pico.vsram[plane_sh&1]; // Get vertical scroll value\r
+    vscroll = PicoMem.vsram[plane_sh & 1]; // Get vertical scroll value\r
 \r
     // Find the line in the name table\r
     ts.line=(vscroll+est->DrawScanline)&ymask;\r
@@ -470,7 +467,7 @@ static void DrawWindow(int tstart, int tend, int prio, int sh,
 \r
   if (!(est->rendstatus & PDRAW_WND_DIFF_PRIO)) {\r
     // check the first tile code\r
-    code=Pico.vram[nametab+tilex];\r
+    code = PicoMem.vram[nametab + tilex];\r
     // if the whole window uses same priority (what is often the case), we may be able to skip this field\r
     if ((code>>15) != prio) return;\r
   }\r
@@ -487,7 +484,7 @@ static void DrawWindow(int tstart, int tend, int prio, int sh,
       int dx, addr;\r
       int pal;\r
 \r
-      code=Pico.vram[nametab+tilex];\r
+      code = PicoMem.vram[nametab + tilex];\r
       if (code==blank) continue;\r
       if ((code>>15) != prio) {\r
         est->rendstatus |= PDRAW_WND_DIFF_PRIO;\r
@@ -498,7 +495,7 @@ static void DrawWindow(int tstart, int tend, int prio, int sh,
       addr=(code&0x7ff)<<4;\r
       if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip\r
 \r
-      pack = *(unsigned int *)(Pico.vram + addr);\r
+      pack = *(unsigned int *)(PicoMem.vram + addr);\r
       if (!pack) {\r
         blank = code;\r
         continue;\r
@@ -519,7 +516,7 @@ static void DrawWindow(int tstart, int tend, int prio, int sh,
       int dx, addr;\r
       int pal;\r
 \r
-      code=Pico.vram[nametab+tilex];\r
+      code = PicoMem.vram[nametab + tilex];\r
       if(code==blank) continue;\r
       if((code>>15) != prio) {\r
         est->rendstatus |= PDRAW_WND_DIFF_PRIO;\r
@@ -540,7 +537,7 @@ static void DrawWindow(int tstart, int tend, int prio, int sh,
       addr=(code&0x7ff)<<4;\r
       if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip\r
 \r
-      pack = *(unsigned int *)(Pico.vram + addr);\r
+      pack = *(unsigned int *)(PicoMem.vram + addr);\r
       if (!pack) {\r
         blank = code;\r
         continue;\r
@@ -594,7 +591,7 @@ static void DrawTilesFromCache(int *hc, int sh, int rlim, struct PicoEState *est
       addr = (code & 0x7ff) << 4;\r
       addr += code >> 25; // y offset into tile\r
 \r
-      pack = *(unsigned int *)(Pico.vram + addr);\r
+      pack = *(unsigned int *)(PicoMem.vram + addr);\r
       if (!pack) {\r
         blank = (short)code;\r
         continue;\r
@@ -622,7 +619,7 @@ static void DrawTilesFromCache(int *hc, int sh, int rlim, struct PicoEState *est
       *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf;\r
       *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf;\r
 \r
-      pack = *(unsigned int *)(Pico.vram + addr);\r
+      pack = *(unsigned int *)(PicoMem.vram + addr);\r
       if (!pack)\r
         continue;\r
 \r
@@ -724,7 +721,7 @@ static void DrawSprite(int *sprite, int sh)
     if(sx<=0)   continue;\r
     if(sx>=328) break; // Offscreen\r
 \r
-    pack = *(unsigned int *)(Pico.vram + (tile & 0x7fff));\r
+    pack = *(unsigned int *)(PicoMem.vram + (tile & 0x7fff));\r
     fTileFunc(sx, pack, pal);\r
   }\r
 }\r
@@ -744,7 +741,7 @@ static NOINLINE void DrawTilesFromCacheForced(const int *hc)
 \r
     dx = (code >> 16) & 0x1ff;\r
     pal = ((code >> 9) & 0x30);\r
-    pack = *(unsigned int *)(Pico.vram + addr);\r
+    pack = *(unsigned int *)(PicoMem.vram + addr);\r
 \r
     if (code & 0x0800) TileFlip_and(dx, pack, pal);\r
     else               TileNorm_and(dx, pack, pal);\r
@@ -790,7 +787,7 @@ static void DrawSpriteInterlace(unsigned int *sprite)
     if(sx<=0)   continue;\r
     if(sx>=328) break; // Offscreen\r
 \r
-    pack = *(unsigned int *)(Pico.vram + (tile & 0x7fff));\r
+    pack = *(unsigned int *)(PicoMem.vram + (tile & 0x7fff));\r
     if (code & 0x0800) TileFlip(sx, pack, pal);\r
     else               TileNorm(sx, pack, pal);\r
   }\r
@@ -812,7 +809,7 @@ static NOINLINE void DrawAllSpritesInterlace(int pri, int sh)
     unsigned int *sprite;\r
     int code, sx, sy, height;\r
 \r
-    sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite\r
+    sprite=(unsigned int *)(PicoMem.vram+((table+(link<<2))&0x7ffc)); // Find sprite\r
 \r
     // get sprite info\r
     code = sprite[0];\r
@@ -915,7 +912,7 @@ static void DrawSpritesSHi(unsigned char *sprited, const struct PicoEState *est)
       if(sx<=0)   continue;\r
       if(sx>=328) break; // Offscreen\r
 \r
-      pack = *(unsigned int *)(Pico.vram + (tile & 0x7fff));\r
+      pack = *(unsigned int *)(PicoMem.vram + (tile & 0x7fff));\r
       fTileFunc(sx, pack, pal);\r
     }\r
   }\r
@@ -989,7 +986,7 @@ static void DrawSpritesHiAS(unsigned char *sprited, int sh)
       if(sx<=0)   continue;\r
       if(sx>=328) break; // Offscreen\r
 \r
-      pack = *(unsigned int *)(Pico.vram + (tile & 0x7fff));\r
+      pack = *(unsigned int *)(PicoMem.vram + (tile & 0x7fff));\r
       fTileFunc(sx, pack, pal);\r
     }\r
   }\r
@@ -1049,7 +1046,7 @@ static NOINLINE void PrepareSprites(int full)
       unsigned int *sprite;\r
       int code2, sx, sy, height;\r
 \r
-      sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite\r
+      sprite=(unsigned int *)(PicoMem.vram+((table+(link<<2))&0x7ffc)); // Find sprite\r
 \r
       // parse sprite info\r
       code2 = sprite[1];\r
@@ -1102,7 +1099,7 @@ found:;
       unsigned int *sprite;\r
       int code, code2, sx, sy, hv, height, width;\r
 \r
-      sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite\r
+      sprite=(unsigned int *)(PicoMem.vram+((table+(link<<2))&0x7ffc)); // Find sprite\r
 \r
       // parse sprite info\r
       code = sprite[0];\r
@@ -1226,7 +1223,7 @@ void PicoDoHighPal555(int sh, int line, struct PicoEState *est)
 \r
   Pico.m.dirtyPal = 0;\r
 \r
-  spal = (void *)Pico.cram;\r
+  spal = (void *)PicoMem.cram;\r
   dpal = (void *)est->HighPal;\r
 \r
   for (i = 0; i < 0x40 / 2; i++) {\r
@@ -1308,9 +1305,9 @@ static void FinalizeLine8bit(int sh, int line, struct PicoEState *est)
     rs |= PDRAW_SONIC_MODE;\r
     est->rendstatus = rs;\r
     if (dirty_count == 3) {\r
-      blockcpy(est->HighPal, Pico.cram, 0x40*2);\r
+      blockcpy(est->HighPal, PicoMem.cram, 0x40*2);\r
     } else if (dirty_count == 11) {\r
-      blockcpy(est->HighPal+0x40, Pico.cram, 0x40*2);\r
+      blockcpy(est->HighPal+0x40, PicoMem.cram, 0x40*2);\r
     }\r
   }\r
 \r
@@ -1620,7 +1617,7 @@ void PicoDrawSetOutBuf(void *dest, int increment)
 {\r
   DrawLineDestBase = dest;\r
   DrawLineDestIncrement = increment;\r
-  Pico.est.DrawLineDest = DrawLineDestBase + Pico.est.DrawScanline * increment;\r
+  Pico.est.DrawLineDest = (char *)DrawLineDestBase + Pico.est.DrawScanline * increment;\r
 }\r
 \r
 void PicoDrawSetInternalBuf(void *dest, int increment)\r