bugfix, sprites adjustment
[picodrive.git] / Pico / Draw.c
index f20af59..4012770 100644 (file)
@@ -65,9 +65,9 @@ struct TileStrip
 #ifdef _ASM_DRAW_C\r
 void DrawWindow(int tstart, int tend, int prio, int sh);\r
 void BackFill(int reg7, int sh);\r
-void DrawAllSprites(int prio, int sh);\r
+void DrawAllSprites(unsigned char *sprited, int prio, int sh);\r
 void DrawTilesFromCache(int *hc, int sh, int rlim);\r
-void DrawSpritesSHi(unsigned short *sprited);\r
+void DrawSpritesSHi(unsigned char *sprited);\r
 void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells);\r
 void FinalizeLineBGR444(int sh);\r
 void FinalizeLineRGB555(int sh);\r
@@ -1007,8 +1007,6 @@ found:;
   }\r
   else\r
   {\r
-    int old_prio = 0x8000, lo_above_hi = 0;\r
-\r
     for (u = 0; u < max_lines; u++)\r
       *((int *)&HighLnSpr[u][0]) = 0;\r
 \r
@@ -1039,37 +1037,34 @@ found:;
         if (sh && (code2 & 0x6000) == 0x6000)\r
           maybe_op = SPRL_MAY_HAVE_OP;\r
 \r
-        if (onscr_x && !old_prio && (code2 & 0x8000))\r
-          lo_above_hi = SPRL_LO_ABOVE_HI;\r
-        old_prio = code2 & 0x8000;\r
-\r
         entry = ((pd - HighPreSpr) / 2) | ((code2>>8)&0x80);\r
         y = (sy >= DrawScanline) ? sy : DrawScanline;\r
         for (; y < sy + (height<<3) && y < max_lines; y++)\r
         {\r
-          int cnt = HighLnSpr[y][0];\r
+         unsigned char *p = &HighLnSpr[y][0];\r
+          int cnt = p[0];\r
           if (cnt >= max_line_sprites) continue;              // sprite limit?\r
 \r
-          if (HighLnSpr[y][2] >= max_line_sprites*2) {        // tile limit?\r
-            HighLnSpr[y][0] |= 0x80;\r
+          if (p[2] >= max_line_sprites*2) {        // tile limit?\r
+            p[0] |= 0x80;\r
             continue;\r
           }\r
-          HighLnSpr[y][2] += width;\r
+          p[2] += width;\r
 \r
           if (sx == -0x78) {\r
             if (cnt > 0)\r
-              HighLnSpr[y][0] |= 0x80; // masked, no more sprites for this line\r
+              p[0] |= 0x80; // masked, no more sprites for this line\r
             continue;\r
           }\r
           // must keep the first sprite even if it's offscreen, for masking\r
           if (cnt > 0 && !onscr_x) continue; // offscreen x\r
 \r
-          HighLnSpr[y][3+cnt] = entry;\r
-          HighLnSpr[y][0] = cnt + 1;\r
-          if (entry & 0x80)\r
-               HighLnSpr[y][1] |= SPRL_HAVE_HI;\r
-          else HighLnSpr[y][1] |= SPRL_HAVE_LO;\r
-          HighLnSpr[y][1] |= maybe_op|lo_above_hi; // there might be op sprites or priority mess on this line\r
+          p[3+cnt] = entry;\r
+          p[0] = cnt + 1;\r
+          p[1] |= (entry & 0x80) ? SPRL_HAVE_HI : SPRL_HAVE_LO;\r
+          p[1] |= maybe_op; // there might be op sprites on this line\r
+          if (cnt > 0 && (code2 & 0x8000) && !(p[3+cnt-1]&0x80))\r
+            p[1] |= SPRL_LO_ABOVE_HI;\r
         }\r
       }\r
 \r
@@ -1302,7 +1297,7 @@ static void DrawBlankedLine(void)
     PicoScanEnd(DrawScanline);\r
 }\r
 \r
-static int DrawDisplay(int sh, int as)\r
+static int DrawDisplay(int sh)\r
 {\r
   unsigned char *sprited = &HighLnSpr[DrawScanline][0];\r
   struct PicoVideo *pvid=&Pico.video;\r
@@ -1374,7 +1369,7 @@ static int DrawDisplay(int sh, int as)
   else if (rendstatus & PDRAW_INTERLACE)\r
     DrawAllSpritesInterlace(1, sh);\r
   // AS on and have both lo/hi sprites and lo before hi sprites?\r
-  else if (as && (sprited[1] & 0xd0) == 0xd0)\r
+  else if ((sprited[1] & 0xd0) == 0xd0 && (rendstatus & PDRAW_ACC_SPRITES))\r
     DrawSpritesHiAS(sprited, sh);\r
   else if (sh && (sprited[1] & SPRL_MAY_HAVE_OP))\r
     DrawSpritesSHi(sprited);\r
@@ -1412,19 +1407,18 @@ PICO_INTERNAL void PicoFrameStart(void)
 \r
 static void PicoLine(void)\r
 {\r
-  int sh, as = 0;\r
+  int sh;\r
   if (skip_next_line>0) { skip_next_line--; return; } // skip rendering lines\r
 \r
   sh=(Pico.video.reg[0xC]&8)>>3; // shadow/hilight?\r
-  if (rendstatus & PDRAW_ACC_SPRITES) as|=1; // accurate sprites\r
 \r
   if (PicoScanBegin != NULL)\r
     skip_next_line = PicoScanBegin(DrawScanline);\r
 \r
   // Draw screen:\r
-  BackFill(Pico.video.reg[7], sh|as);\r
+  BackFill(Pico.video.reg[7], sh);\r
   if (Pico.video.reg[1]&0x40)\r
-    DrawDisplay(sh, as);\r
+    DrawDisplay(sh);\r
 \r
   if (FinalizeLine != NULL)\r
     FinalizeLine(sh);\r
@@ -1534,7 +1528,7 @@ void PicoDrawShowPalette(unsigned short *screen)
     HighPal[0x40|i] = (unsigned short)((HighPal[i]>>1)&0x738e);\r
   for (i = 0x3f; i >= 0; i--) {\r
     int t=HighPal[i]&0xe71c;t+=0x4208;if(t&0x20)t|=0x1c;if(t&0x800)t|=0x700;if(t&0x10000)t|=0xe000;t&=0xe71c;\r
-    HighPal[0x80|i]=(unsigned short)t;\r
+    HighPal[0x80|i] = (unsigned short)t;\r
   }\r
 \r
   screen += 16*320+8;\r