FAMEC idle loops, PSP port sync, minor adjustments
[picodrive.git] / Pico / Draw.c
index f20af59..c076624 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
@@ -1472,58 +1466,66 @@ void PicoDrawSetColorFormat(int which)
 }\r
 \r
 /* debug and fun */\r
+#define GREEN1  0x0700\r
+#ifdef USE_BGR555\r
+ #define YELLOW1 0x071c\r
+ #define BLUE1   0xf000\r
+ #define RED1    0x001e\r
+#else\r
+ #define YELLOW1 0xe700\r
+ #define BLUE1   0x001e\r
+ #define RED1    0xf000\r
+#endif\r
+\r
 static void set16(unsigned short *p, unsigned short d, int cnt)\r
 {\r
   while (cnt-- > 0)\r
     *p++ = d;\r
 }\r
 \r
-void PicoDrawShowSpriteStats(unsigned short *screen)\r
+void PicoDrawShowSpriteStats(unsigned short *screen, int stride)\r
 {\r
   int lines, i, u, step;\r
   unsigned short *dest;\r
   unsigned char *p;\r
 \r
-  memset(screen, 0, 320*240*2);\r
   step = (320-4*4-1) / MAX_LINE_SPRITES;\r
   lines = 240;\r
   if (!Pico.m.pal || !(Pico.video.reg[1]&8))\r
-    lines = 224, screen += 320*8;\r
+    lines = 224, screen += stride*8;\r
 \r
   for (i = 0; i < lines; i++)\r
   {\r
-    dest = screen + 320*i;\r
+    dest = screen + stride*i;\r
     p = &HighLnSpr[i][0];\r
 \r
     // sprite graphs\r
     for (u = 0; u < (p[0] & 0x7f); u++) {\r
-      set16(dest, (p[3+u] & 0x80) ? 0xe700 : 0x0700, step);\r
+      set16(dest, (p[3+u] & 0x80) ? YELLOW1 : GREEN1, step);\r
       dest += step;\r
     }\r
 \r
     // flags\r
-    dest = screen + 320*i + 320-4*4;\r
-    if (p[1] & SPRL_HAVE_LO)     set16(dest+4*0, 0x0700, 4);\r
-    if (p[1] & SPRL_HAVE_HI)     set16(dest+4*1, 0xe700, 4);\r
-    if (p[1] & SPRL_MAY_HAVE_OP) set16(dest+4*2, 0x001e, 4);\r
-    if (p[1] & SPRL_LO_ABOVE_HI) set16(dest+4*3, 0xf000, 4);\r
+    dest = screen + stride*i + 320-4*4;\r
+    if (p[1] & SPRL_HAVE_LO)     set16(dest+4*0, GREEN1,  4);\r
+    if (p[1] & SPRL_HAVE_HI)     set16(dest+4*1, YELLOW1, 4);\r
+    if (p[1] & SPRL_MAY_HAVE_OP) set16(dest+4*2, BLUE1,   4);\r
+    if (p[1] & SPRL_LO_ABOVE_HI) set16(dest+4*3, RED1,    4);\r
   }\r
 \r
   // draw grid\r
   for (i = step*5; i <= 320-4*4-1; i += step*5) {\r
     for (u = 0; u < lines; u++)\r
-      screen[i + u*320] = 0x182;\r
+      screen[i + u*stride] = 0x182;\r
   }\r
 }\r
 \r
-void PicoDrawShowPalette(unsigned short *screen)\r
+void PicoDrawShowPalette(unsigned short *screen, int stride)\r
 {\r
   unsigned int *spal=(void *)Pico.cram;\r
   unsigned int *dpal=(void *)HighPal;\r
   int x, y, i;\r
 \r
-  memset(screen, 0, 320*240*2);\r
-\r
   for (i = 0x3f/2; i >= 0; i--)\r
 #ifdef USE_BGR555\r
     dpal[i] = ((spal[i]&0x000f000f)<< 1)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)<<4);\r
@@ -1534,23 +1536,23 @@ 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
+  screen += 16*stride+8;\r
   for (y = 0; y < 8*4; y++)\r
     for (x = 0; x < 8*16; x++)\r
-      screen[x + y*320] = HighPal[x/8 + (y/8)*16];\r
+      screen[x + y*stride] = HighPal[x/8 + (y/8)*16];\r
 \r
   screen += 160;\r
   for (y = 0; y < 8*4; y++)\r
     for (x = 0; x < 8*16; x++)\r
-      screen[x + y*320] = HighPal[(x/8 + (y/8)*16) | 0x40];\r
+      screen[x + y*stride] = HighPal[(x/8 + (y/8)*16) | 0x40];\r
 \r
-  screen += 320*48;\r
+  screen += stride*48;\r
   for (y = 0; y < 8*4; y++)\r
     for (x = 0; x < 8*16; x++)\r
-      screen[x + y*320] = HighPal[(x/8 + (y/8)*16) | 0x80];\r
+      screen[x + y*stride] = HighPal[(x/8 + (y/8)*16) | 0x80];\r
 \r
   Pico.m.dirtyPal = 1;\r
 }\r