\r
static int HighCacheA[41+1]; // caches for high layers\r
static int HighCacheB[41+1];\r
-static int HighCacheS[80+1]; // and sprites\r
int HighPreSpr[80*2+1]; // slightly preprocessed sprites\r
-int *HighCacheS_ptr;\r
\r
#define MAX_LINE_SPRITES 30\r
unsigned char HighLnSpr[240][2 + MAX_LINE_SPRITES]; // sprite_count, tile_count, [spritep]...\r
\r
//unsigned short ppt[] = { 0x0f11, 0x0ff1, 0x01f1, 0x011f, 0x01ff, 0x0f1f, 0x0f0e, 0x0e7c };\r
\r
-static void (*DrawAllSpritesLoPri)(int *hcache, int prio, int sh) = NULL;\r
-static void (*DrawAllSpritesHiPri)(int *hcache, int prio, int sh) = NULL;\r
+static void (*DrawAllSpritesLoPri)(int prio, int sh) = NULL;\r
+static void (*DrawAllSpritesHiPri)(int prio, int sh) = NULL;\r
\r
struct TileStrip\r
{\r
#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 *hcache, int prio, int sh);\r
+void DrawAllSprites(int prio, int sh);\r
void DrawTilesFromCache(int *hc, int sh, int rlim);\r
-void DrawSpritesFromCache(int *hc, int prio, int sh);\r
+void DrawSpritesSHi(int prio, int sh);\r
void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells);\r
void FinalizeLineBGR444(int sh);\r
void FinalizeLineRGB555(int sh);\r
if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X\r
\r
tile &= 0x7ff; tile<<=4; tile+=(row&7)<<1; // Tile address\r
+ delta<<=4; // Delta of address\r
\r
pal=(code>>9)&0x30;\r
-\r
- // assume there will be no sprites with both normal and operator pixels..\r
- if ((code&0x8000) || (sh && pal == 0x30) || as) {\r
- *HighCacheS_ptr++ = ((code&0x8000)<<16)|(tile<<16)|((code&0x0800)<<5)|((sx<<6)&0x0000ffc0)|pal|((sprite[0]>>16)&0xf);\r
- // we need all for accurate sprites, cached will be used to do proper priorities\r
- if (!as && (code&0x8000)) return;\r
- }\r
-\r
- delta<<=4; // Delta of address\r
pal|=((sh|as)<<6);\r
\r
if (sh && (code&0x6000) == 0x6000) {\r
}\r
\r
\r
-static void DrawAllSpritesInterlace(int *hcache, int pri, int sh)\r
+static void DrawAllSpritesInterlace(int pri, int sh)\r
{\r
struct PicoVideo *pvid=&Pico.video;\r
int i,u,table,link=0,sline=DrawScanline<<1;\r
// Go through sprites backwards:\r
for (i-- ;i>=0; i--)\r
DrawSpriteInterlace(sprites[i]);\r
-\r
- HighCacheS[0] = 1; // just to fool main code\r
}\r
\r
\r
#ifndef _ASM_DRAW_C\r
-static void DrawSpritesFromCache(int *hc, int prio, int sh)\r
+// Index + 0 : hhhhvvvv ----hhvv yyyyyyyy yyyyyyyy // v, h: vert./horiz. size\r
+// Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8\r
+static void DrawSpritesSHi(int prio, int sh)\r
{\r
- int code, tile, sx, delta, width;\r
- int pal;\r
int (*fTileFunc)(int sx,int addr,int pal);\r
+ unsigned char *p;\r
+ int cnt;\r
+\r
+ cnt = HighLnSpr[DrawScanline][0] & 0x7f;\r
+ if (cnt == 0) return;\r
\r
- // prio[31]:tile[30:17]:flipx[16]:sx[15:6]:pal[5:4]:delta_width[3:0]\r
+ p = &HighLnSpr[DrawScanline][2];\r
\r
- while ((code=*hc++))\r
+ // Go through sprites backwards:\r
+ for (cnt--; cnt >= 0; cnt--)\r
{\r
- pal=(code&0x30);\r
- delta=code&0xf;\r
- width=delta>>2; delta&=3;\r
- width++; delta++; // Width and height in tiles\r
- if (code&0x10000) delta=-delta; // Flip X\r
- delta<<=4;\r
- tile=((unsigned int)code>>17)<<1; // also has prio\r
- sx=(code<<16)>>22; // sx can be negative (start offscreen), so sign extend\r
+ int *sprite, code, pal, tile, sx, sy;\r
+ int offs, delta, width, height, row;\r
+\r
+ offs = (p[cnt] & 0x7f) * 2;\r
+ sprite = HighPreSpr + offs;\r
+ code = sprite[1];\r
+ pal = (code>>9)&0x30;\r
\r
if (sh && pal == 0x30)\r
{\r
- if (code & 0x80000000) // hi priority\r
+ if (code & 0x8000) // hi priority\r
{\r
- if(code&0x10000) fTileFunc=TileFlipSH;\r
- else fTileFunc=TileNormSH;\r
+ if (code&0x800) fTileFunc=TileFlipSH;\r
+ else fTileFunc=TileNormSH;\r
} else {\r
- if(code&0x10000) fTileFunc=TileFlipSH_onlyop_lp;\r
- else fTileFunc=TileNormSH_onlyop_lp;\r
+ if (code&0x800) fTileFunc=TileFlipSH_onlyop_lp;\r
+ else fTileFunc=TileNormSH_onlyop_lp;\r
}\r
} else {\r
- if(code&0x10000) fTileFunc=TileFlip;\r
- else fTileFunc=TileNorm;\r
+ if (!(code & 0x8000)) continue; // non-operator low sprite, already drawn\r
+ if (code&0x800) fTileFunc=TileFlip;\r
+ else fTileFunc=TileNorm;\r
}\r
\r
+ // parse remaining sprite data\r
+ sy=sprite[0];\r
+ sx=code>>16; // X\r
+ width=sy>>28;\r
+ height=(sy>>24)&7; // Width and height in tiles\r
+ sy=(sy<<16)>>16; // Y\r
+\r
+ row=DrawScanline-sy; // Row of the sprite we are on\r
+\r
+ if (code&0x1000) row=(height<<3)-1-row; // Flip Y\r
+\r
+ tile=code + (row>>3); // Tile number increases going down\r
+ delta=height; // Delta to increase tile by going right\r
+ if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X\r
+\r
+ tile &= 0x7ff; tile<<=4; tile+=(row&7)<<1; // Tile address\r
+ delta<<=4; // Delta of address\r
+\r
for (; width; width--,sx+=8,tile+=delta)\r
{\r
if(sx<=0) continue;\r
}\r
#endif\r
\r
-static void DrawSpritesFromCacheAS(int *hc, int prio, int sh)\r
+static void DrawSpritesHiAS(int prio, int sh)\r
{\r
- int code, tile, sx, delta, width;\r
- int pal, *hce, *hco;\r
int (*fTileFunc)(int sx,int addr,int pal);\r
+ unsigned char *p;\r
+ int entry, cnt, sh_cnt = 0;\r
+\r
+ cnt = HighLnSpr[DrawScanline][0] & 0x7f;\r
+ if (cnt == 0) return;\r
\r
- // prio[31]:tile[30:17]:flipx[16]:sx[15:6]:pal[5:4]:delta_width[3:0]\r
+ p = &HighLnSpr[DrawScanline][2];\r
\r
- /* walk the sprite cache backwards.. */\r
- hco = hce = HighCacheS_ptr;\r
- while (hce > hc)\r
+ // Go through sprites:\r
+ for (entry = 0; entry < cnt; entry++)\r
{\r
- code=*(--hce);\r
- pal=(code&0x30);\r
- delta=code&0xf;\r
- width=delta>>2; delta&=3;\r
- width++; delta++; // Width and height in tiles\r
- if (code&0x10000) delta=-delta; // Flip X\r
- delta<<=4;\r
- tile=((unsigned int)code>>17)<<1;\r
- sx=(code<<16)>>22; // sx can be negative (start offscreen), so sign extend\r
-\r
- if (code & 0x80000000) // hi priority\r
+ int *sprite, code, pal, tile, sx, sy;\r
+ int offs, delta, width, height, row;\r
+\r
+ offs = (p[entry] & 0x7f) * 2;\r
+ sprite = HighPreSpr + offs;\r
+ code = sprite[1];\r
+ pal = (code>>9)&0x30;\r
+\r
+ if (code & 0x8000) // hi priority\r
{\r
if (sh && pal == 0x30)\r
{\r
- if(code&0x10000) fTileFunc=TileFlipAS_noop;\r
- else fTileFunc=TileNormAS_noop;\r
+ if (code&0x800) fTileFunc=TileFlipAS_noop;\r
+ else fTileFunc=TileNormAS_noop;\r
} else {\r
- if(code&0x10000) fTileFunc=TileFlipAS;\r
- else fTileFunc=TileNormAS;\r
+ if (code&0x800) fTileFunc=TileFlipAS;\r
+ else fTileFunc=TileNormAS;\r
}\r
} else {\r
- if(code&0x10000) fTileFunc=TileFlipAS_onlymark;\r
- else fTileFunc=TileNormAS_onlymark;\r
+ if (code&0x800) fTileFunc=TileFlipAS_onlymark;\r
+ else fTileFunc=TileNormAS_onlymark;\r
}\r
if (sh && pal == 0x30)\r
- *(--hco) = code; /* save for later */\r
+ p[sh_cnt++] = offs / 2; // re-save for sh/hi pass\r
+\r
+ // parse remaining sprite data\r
+ sy=sprite[0];\r
+ sx=code>>16; // X\r
+ width=sy>>28;\r
+ height=(sy>>24)&7; // Width and height in tiles\r
+ sy=(sy<<16)>>16; // Y\r
+\r
+ row=DrawScanline-sy; // Row of the sprite we are on\r
+\r
+ if (code&0x1000) row=(height<<3)-1-row; // Flip Y\r
+\r
+ tile=code + (row>>3); // Tile number increases going down\r
+ delta=height; // Delta to increase tile by going right\r
+ if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X\r
+\r
+ tile &= 0x7ff; tile<<=4; tile+=(row&7)<<1; // Tile address\r
+ delta<<=4; // Delta of address\r
\r
pal |= 0x80;\r
for (; width; width--,sx+=8,tile+=delta)\r
}\r
}\r
\r
- /* nasty 2: loop once more and do operator colors */\r
- while ((code=*hco++))\r
- {\r
- pal=(code&0x30);\r
- if (pal != 0x30) continue;\r
- delta=code&0xf;\r
- width=delta>>2; delta&=3;\r
- width++; delta++;\r
- if (code&0x10000) delta=-delta; // Flip X\r
- delta<<=4;\r
- tile=((unsigned int)code>>17)<<1;\r
- sx=(code<<16)>>22;\r
-\r
- if (code & 0x80000000)\r
- {\r
- if(code&0x10000) fTileFunc=TileFlipSH;\r
- else fTileFunc=TileNormSH;\r
- } else {\r
- if(code&0x10000) fTileFunc=TileFlipSH_onlyop_lp;\r
- else fTileFunc=TileNormSH_onlyop_lp;\r
- }\r
-\r
- pal |= 0x80;\r
- for (; width; width--,sx+=8,tile+=delta)\r
- {\r
- if(sx<=0) continue;\r
- if(sx>=328) break; // Offscreen\r
-\r
- tile&=0x7fff; // Clip tile address\r
- fTileFunc(sx,tile,pal);\r
- }\r
- }\r
+ /* nasty 2: sh operator pass */\r
+ HighLnSpr[DrawScanline][0] = sh_cnt;\r
+ DrawSpritesSHi(1, 1);\r
}\r
\r
\r
-\r
// Index + 0 : ----hhvv -lllllll -------y yyyyyyyy\r
// Index + 4 : -------x xxxxxxxx pccvhnnn nnnnnnnn\r
// v\r
(sx > -24 || sx < max_width)) // onscreen x\r
{\r
int y = (sy >= DrawScanline) ? sy : DrawScanline;\r
- int offs = (pd - HighPreSpr) / 2;\r
+ int entry = ((pd - HighPreSpr) / 2) | ((code2>>8)&0x80);\r
for (; y < sy + (height<<3) && y < max_lines; y++)\r
{\r
int i, cnt;\r
if (cnt >= max_line_sprites) continue; // sprite limit?\r
\r
for (i = 0; i < cnt; i++)\r
- if (HighLnSpr[y][2+i] == offs) goto found;\r
+ if (((HighLnSpr[y][2+i] ^ entry) & 0x7f) == 0) goto found;\r
\r
// this sprite was previously missing\r
- HighLnSpr[y][2+cnt] = offs;\r
+ HighLnSpr[y][2+cnt] = entry;\r
HighLnSpr[y][0] = cnt + 1;\r
found:;\r
}\r
if (sy < max_lines && sy + (height<<3) > DrawScanline) // sprite onscreen (y)?\r
{\r
int y = (sy >= DrawScanline) ? sy : DrawScanline;\r
+ int entry = ((pd - HighPreSpr) / 2) | ((code2>>8)&0x80);\r
for (; y < sy + (height<<3) && y < max_lines; y++)\r
{\r
int cnt = HighLnSpr[y][0];\r
// must keep the first sprite even if it's offscreen, for masking\r
if (cnt > 0 && (sx <= sx_min || sx >= max_width)) continue; // offscreen x\r
\r
- HighLnSpr[y][2+cnt] = ((pd - HighPreSpr) / 2); // | prio;\r
+ HighLnSpr[y][2+cnt] = entry;\r
HighLnSpr[y][0] = cnt + 1;\r
+ if (entry & 0x80)\r
+ rendstatus |= PDRAW_HAVE_HI_SPR;\r
+ else rendstatus |= PDRAW_HAVE_LO_SPR;\r
}\r
}\r
\r
}\r
\r
#ifndef _ASM_DRAW_C\r
-static void DrawAllSprites(int *hcache, int prio, int sh)\r
+static void DrawAllSprites(int prio, int sh)\r
{\r
int rs = rendstatus, scan = DrawScanline;\r
unsigned char *p;\r
rendstatus = rs & ~(PDRAW_SPRITES_MOVED|PDRAW_DIRTY_SPRITES);\r
}\r
\r
- HighCacheS_ptr = hcache;\r
cnt = HighLnSpr[scan][0] & 0x7f;\r
+ if (cnt == 0) return;\r
\r
- if (cnt != 0)\r
- {\r
- p = &HighLnSpr[scan][2];\r
- as = (rs & PDRAW_ACC_SPRITES) ? 1 : 0;\r
+ p = &HighLnSpr[scan][2];\r
+ as = (rs & PDRAW_ACC_SPRITES) ? 1 : 0;\r
\r
- // Go through sprites backwards:\r
- for (cnt--; cnt >= 0; cnt--)\r
- {\r
- int offs = p[cnt] * 2;\r
- //if ((p[cnt] & 0x80) && !as) continue;\r
- DrawSprite(HighPreSpr + offs, sh, as);\r
- }\r
+ // Go through sprites backwards:\r
+ for (cnt--; cnt >= 0; cnt--)\r
+ {\r
+ int offs;\r
+ if ((p[cnt] >> 7) != prio && !as) continue;\r
+ offs = (p[cnt]&0x7f) * 2;\r
+ DrawSprite(HighPreSpr + offs, sh, as);\r
}\r
-\r
- *HighCacheS_ptr = 0;\r
}\r
\r
\r
DrawWindow( (win&0x80) ? edge : 0, (win&0x80) ? maxcells>>1 : edge, 0, sh|as);\r
} else\r
DrawLayer(0|((sh|as)<<1), HighCacheA, 0, maxcells);\r
- DrawAllSpritesLoPri(HighCacheS, 0, sh);\r
+ if ((rendstatus & PDRAW_HAVE_LO_SPR) || as)\r
+ DrawAllSpritesLoPri(0, sh);\r
\r
if (HighCacheB[0]) DrawTilesFromCache(HighCacheB, sh, maxw);\r
if (hvwind == 1)\r
DrawWindow((win&0x80) ? edge : 0, (win&0x80) ? maxcells>>1 : edge, 1, sh);\r
} else\r
if (HighCacheA[0]) DrawTilesFromCache(HighCacheA, sh, maxw);\r
- if (HighCacheS[0]) DrawAllSpritesHiPri(HighCacheS, 1, sh);\r
+ if ((rendstatus & PDRAW_HAVE_HI_SPR) || sh)\r
+ DrawAllSpritesHiPri(1, sh);\r
\r
#if 0\r
{\r
PICO_INTERNAL void PicoFrameStart(void)\r
{\r
// prepare to do this frame\r
- rendstatus = (PicoOpt&0x80)>>5; // accurate sprites, clear everything else\r
+ int sh = Pico.video.reg[0xC] & 8; // shadow/hilight?\r
+ rendstatus = 0;\r
+ if (PicoOpt & POPT_ACC_SPRITES)\r
+ rendstatus |= PDRAW_ACC_SPRITES;\r
+\r
if ((Pico.video.reg[12]&6) == 6) {\r
rendstatus |= PDRAW_INTERLACE; // interlace mode\r
- DrawAllSpritesLoPri = DrawAllSpritesInterlace;\r
+ DrawAllSpritesLoPri =\r
DrawAllSpritesHiPri = DrawAllSpritesInterlace;\r
}\r
- else\r
+ else if (sh)\r
{\r
DrawAllSpritesLoPri = DrawAllSprites;\r
- DrawAllSpritesHiPri = rendstatus ? DrawSpritesFromCacheAS : DrawSpritesFromCache;\r
+ DrawAllSpritesHiPri = DrawSpritesSHi;\r
+ }\r
+ else\r
+ {\r
+ DrawAllSpritesLoPri =\r
+ DrawAllSpritesHiPri = DrawAllSprites;\r
}\r
+ if (rendstatus & PDRAW_ACC_SPRITES)\r
+ DrawAllSpritesHiPri = DrawSpritesHiAS;\r
\r
if (Pico.m.dirtyPal) Pico.m.dirtyPal = 2; // reset dirty if needed\r
\r