scroll size improvement
[picodrive.git] / pico / draw.c
index 7dbdc34..2aa37f8 100644 (file)
@@ -394,8 +394,11 @@ static void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells,
 \r
   ts.xmask=(1<<shift[width])-1; // X Mask in tiles (0x1f-0x7f)\r
   ymask=(height<<8)|0xff;       // Y Mask in pixels\r
-  if(width == 1)   ymask&=0x1ff;\r
-  else if(width>1) ymask =0x0ff;\r
+  switch (width) {\r
+    case 1: ymask &= 0x1ff; break;\r
+    case 2: ymask =  0x007; break;\r
+    case 3: ymask =  0x0ff; break;\r
+  }\r
 \r
   // Find name table:\r
   if (plane_sh&1) ts.nametab=(pvid->reg[4]&0x07)<<12; // B\r
@@ -954,7 +957,7 @@ static void DrawSpritesHiAS(unsigned char *sprited, int sh)
 // Index + 0  :    hhhhvvvv ----hhvv yyyyyyyy yyyyyyyy // v, h: vert./horiz. size\r
 // Index + 4  :    xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8\r
 \r
-void PrepareSprites(int full)\r
+static NOINLINE void PrepareSprites(int full)\r
 {\r
   const struct PicoVideo *pvid=&Pico.video;\r
   const struct PicoEState *est=&Pico.est;\r
@@ -1117,16 +1120,9 @@ found:;
 static void DrawAllSprites(unsigned char *sprited, int prio, int sh,\r
                            struct PicoEState *est)\r
 {\r
-  int rs = est->rendstatus;\r
   unsigned char *p;\r
   int cnt;\r
 \r
-  if (rs & (PDRAW_SPRITES_MOVED|PDRAW_DIRTY_SPRITES)) {\r
-    //elprintf(EL_STATUS, "PrepareSprites(%i)", (rs>>4)&1);\r
-    PrepareSprites(rs & PDRAW_DIRTY_SPRITES);\r
-    est->rendstatus = rs & ~(PDRAW_SPRITES_MOVED|PDRAW_DIRTY_SPRITES);\r
-  }\r
-\r
   cnt = sprited[0] & 0x7f;\r
   if (cnt == 0) return;\r
 \r
@@ -1161,8 +1157,6 @@ void BackFill(int reg7, int sh, struct PicoEState *est)
 \r
 // --------------------------------------------\r
 \r
-unsigned short HighPal[0x100];\r
-\r
 #ifndef _ASM_DRAW_C\r
 void PicoDoHighPal555(int sh, int line, struct PicoEState *est)\r
 {\r
@@ -1172,7 +1166,7 @@ void PicoDoHighPal555(int sh, int line, struct PicoEState *est)
   Pico.m.dirtyPal = 0;\r
 \r
   spal = (void *)Pico.cram;\r
-  dpal = (void *)HighPal;\r
+  dpal = (void *)est->HighPal;\r
 \r
   for (i = 0; i < 0x40 / 2; i++) {\r
     t = spal[i];\r
@@ -1206,7 +1200,7 @@ void FinalizeLine555(int sh, int line, struct PicoEState *est)
 {\r
   unsigned short *pd=est->DrawLineDest;\r
   unsigned char  *ps=est->HighCol+8;\r
-  unsigned short *pal=HighPal;\r
+  unsigned short *pal=est->HighPal;\r
   int len;\r
 \r
   if (Pico.m.dirtyPal)\r
@@ -1253,9 +1247,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(HighPal, Pico.cram, 0x40*2);\r
+      blockcpy(est->HighPal, Pico.cram, 0x40*2);\r
     } else if (dirty_count == 11) {\r
-      blockcpy(HighPal+0x40, Pico.cram, 0x40*2);\r
+      blockcpy(est->HighPal+0x40, Pico.cram, 0x40*2);\r
     }\r
   }\r
 \r
@@ -1290,6 +1284,12 @@ static int DrawDisplay(int sh)
   int win=0,edge=0,hvwind=0;\r
   int maxw,maxcells;\r
 \r
+  if (est->rendstatus & (PDRAW_SPRITES_MOVED|PDRAW_DIRTY_SPRITES)) {\r
+    // elprintf(EL_STATUS, "PrepareSprites(%i)", (est->rendstatus>>4)&1);\r
+    PrepareSprites(est->rendstatus & PDRAW_DIRTY_SPRITES);\r
+    est->rendstatus &= ~(PDRAW_SPRITES_MOVED|PDRAW_DIRTY_SPRITES);\r
+  }\r
+\r
   est->rendstatus &= ~(PDRAW_SHHI_DONE|PDRAW_PLANE_HI_PRIO);\r
 \r
   if (pvid->reg[12]&1) {\r
@@ -1333,7 +1333,7 @@ static int DrawDisplay(int sh)
     DrawLayer(0|(sh<<1), HighCacheA, 0, maxcells, est);\r
   /* - sprites low - */\r
   if (!(PicoDrawMask & PDRAW_SPRITES_LOW_ON));\r
-  else if (Pico.est.rendstatus & PDRAW_INTERLACE)\r
+  else if (est->rendstatus & PDRAW_INTERLACE)\r
     DrawAllSpritesInterlace(0, sh);\r
   else if (sprited[1] & SPRL_HAVE_LO)\r
     DrawAllSprites(sprited, 0, sh, est);\r
@@ -1354,7 +1354,7 @@ static int DrawDisplay(int sh)
       DrawTilesFromCache(HighCacheA, sh, maxw, est);\r
   /* - sprites hi - */\r
   if (!(PicoDrawMask & PDRAW_SPRITES_HI_ON));\r
-  else if (Pico.est.rendstatus & PDRAW_INTERLACE)\r
+  else if (est->rendstatus & PDRAW_INTERLACE)\r
     DrawAllSpritesInterlace(1, sh);\r
   // have sprites without layer pri bit ontop of sprites with that bit\r
   else if ((sprited[1] & 0xd0) == 0xd0 && (PicoOpt & POPT_ACC_SPRITES))\r
@@ -1496,15 +1496,16 @@ void PicoDrawSync(int to, int blank_last_line)
 // also works for fast renderer\r
 void PicoDrawUpdateHighPal(void)\r
 {\r
+  struct PicoEState *est = &Pico.est;\r
   int sh = (Pico.video.reg[0xC] & 8) >> 3; // shadow/hilight?\r
   if (PicoOpt & POPT_ALT_RENDERER)\r
     sh = 0; // no s/h support\r
 \r
   PicoDoHighPal555(sh, 0, &Pico.est);\r
-  if (Pico.est.rendstatus & PDRAW_SONIC_MODE) {\r
+  if (est->rendstatus & PDRAW_SONIC_MODE) {\r
     // FIXME?\r
-    memcpy(HighPal + 0x40, HighPal, 0x40*2);\r
-    memcpy(HighPal + 0x80, HighPal, 0x40*2);\r
+    memcpy(est->HighPal + 0x40, est->HighPal, 0x40*2);\r
+    memcpy(est->HighPal + 0x80, est->HighPal, 0x40*2);\r
   }\r
 }\r
 \r