static int HighPreSpr[80*2+1]; // slightly preprocessed sprites\r
int *HighCacheS_ptr;\r
\r
+#define MAX_LINE_SPRITES 30\r
+static unsigned char HighLnSpr[240][2 + MAX_LINE_SPRITES]; // sprite_count, tile_count, [spritep]...\r
+\r
int rendstatus = 0;\r
int DrawScanline = 0;\r
\r
-static int SpriteBlocks;\r
static int skip_next_line=0;\r
\r
//unsigned short ppt[] = { 0x0f11, 0x0ff1, 0x01f1, 0x011f, 0x01ff, 0x0f1f, 0x0f0e, 0x0e7c };\r
// Index + 0 : ----hhvv -lllllll -------y yyyyyyyy\r
// Index + 4 : -------x xxxxxxxx pccvhnnn nnnnnnnn\r
// v\r
-// Index + 0 : hhhhvvvv ab--hhvv yyyyyyyy yyyyyyyy // a: offscreen h, b: offs. v, h: horiz. size\r
+// Index + 0 : hhhhvvvv ----hhvv yyyyyyyy yyyyyyyy // v, h: vert./horiz. size\r
// Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8\r
\r
static void PrepareSprites(int full)\r
{\r
struct PicoVideo *pvid=&Pico.video;\r
- int u=0,link=0,sblocks=0;\r
+ int u,link=0;\r
int table=0;\r
int *pd = HighPreSpr;\r
+ int max_lines = 224, max_sprites = 80;\r
+ int max_line_sprites = 20; // 20 sprites, 40 tiles\r
+\r
+ if (!(Pico.video.reg[12]&1))\r
+ max_sprites = 64, max_line_sprites = 16;\r
+ if (PicoOpt & POPT_DIS_SPRITE_LIM)\r
+ max_line_sprites = MAX_LINE_SPRITES;\r
+\r
+ if (pvid->reg[1]&8) max_lines = 240;\r
\r
table=pvid->reg[5]&0x7f;\r
if (pvid->reg[12]&1) table&=0x7e; // Lowest bit 0 in 40-cell mode\r
{\r
int pack;\r
// updates: tilecode, sx\r
- for (u=0; u < 80 && (pack = *pd); u++, pd+=2)\r
+ for (u=0; u < max_lines && (pack = *pd); u++, pd+=2)\r
{\r
unsigned int *sprite;\r
- int code, code2, sx, sy, skip=0;\r
+ int code2, sx, sy, height;\r
\r
sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite\r
\r
// parse sprite info\r
- code = sprite[0];\r
code2 = sprite[1];\r
- code2 &= ~0xfe000000;\r
- code2 -= 0x00780000; // Get X coordinate + 8 in upper 16 bits\r
- sx = code2>>16;\r
+ sx = (code2>>16)&0x1ff;\r
+ sx -= 0x78; // Get X coordinate + 8\r
+ sy = (pack << 16) >> 16;\r
+ height = pack >> 28;\r
\r
- if((sx <= 8-((pack>>28)<<3) && sx >= -0x76) || sx >= 328) skip=1<<23;\r
- else if ((sy = (pack<<16)>>16) < 240 && sy > -32) {\r
- int sbl = (2<<(pack>>28))-1;\r
- sblocks |= sbl<<(sy>>3);\r
+ if (sy < max_lines && sy + (height<<3) > DrawScanline && // sprite onscreen (y)?\r
+ (sx > -24 || sx < 328)) // onscreen x\r
+ {\r
+ int y = (sy >= DrawScanline) ? sy : DrawScanline;\r
+ for (; y < sy + (height<<3) && y < max_lines; y++)\r
+ {\r
+ int i, cnt, offs;\r
+ cnt = HighLnSpr[y][0] & 0x7f;\r
+ if (cnt >= max_line_sprites) continue; // sprite limit?\r
+ offs = (pd - HighPreSpr) / 2;\r
+\r
+ for (i = 0; i < cnt; i++)\r
+ if (HighLnSpr[y][2+i] == offs) goto found;\r
+\r
+ // this sprite was previously missing\r
+ HighLnSpr[y][2+cnt] = offs;\r
+ HighLnSpr[y][0] = cnt + 1;\r
+found:;\r
+ }\r
}\r
\r
- *pd = (pack&~(1<<23))|skip;\r
- *(pd+1) = code2;\r
+ code2 &= ~0xfe000000;\r
+ code2 -= 0x00780000; // Get X coordinate + 8 in upper 16 bits\r
+ pd[1] = code2;\r
\r
// Find next sprite\r
- link=(code>>16)&0x7f;\r
- if(!link) break; // End of sprites\r
+ link=(sprite[0]>>16)&0x7f;\r
+ if (!link) break; // End of sprites\r
}\r
- SpriteBlocks |= sblocks;\r
}\r
else\r
{\r
- for (; u < 80; u++)\r
+ for (u = 0; u < max_lines; u++)\r
+ *((int *)&HighLnSpr[u][0]) = 0;\r
+\r
+ for (u = 0; u < max_lines; u++)\r
{\r
unsigned int *sprite;\r
- int code, code2, sx, sy, hv, height, width, skip=0, sx_min;\r
+ int code, code2, sx, sy, hv, height, width;\r
+ int sx_min, offscr_x;\r
\r
sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite\r
\r
hv = (code>>24)&0xf;\r
height = (hv&3)+1;\r
\r
- if (sy > 240 || sy + (height<<3) <= 0) skip|=1<<22; // sprite offscreen (completely, y)\r
-\r
width = (hv>>2)+1;\r
code2 = sprite[1];\r
sx = (code2>>16)&0x1ff;\r
sx -= 0x78; // Get X coordinate + 8\r
sx_min = 8-(width<<3);\r
\r
- if ((sx <= sx_min && sx >= -0x76) || sx >= 328) skip|=1<<23; // offscreen x\r
- else if (sx > sx_min && !skip) {\r
- int sbl = (2<<height)-1;\r
- int shi = sy>>3;\r
- if(shi < 0) shi=0; // negative sy\r
- sblocks |= sbl<<shi;\r
+ offscr_x = (sx <= sx_min) || sx >= 328;\r
+\r
+ if (sy < max_lines && sy + (height<<3) > DrawScanline) // sprite onscreen (y)?\r
+ {\r
+ int y = (sy >= DrawScanline) ? sy : DrawScanline;\r
+ for (; y < sy + (height<<3) && y < max_lines; y++)\r
+ {\r
+ int cnt = HighLnSpr[y][0];\r
+ if (cnt >= max_line_sprites) continue; // sprite limit?\r
+\r
+ if (HighLnSpr[y][1] >= max_line_sprites*2) { // tile limit?\r
+ HighLnSpr[y][0] |= 0x80;\r
+ continue;\r
+ }\r
+ HighLnSpr[y][1] += width;\r
+\r
+ if (sx == -0x78) {\r
+ if (cnt > 0)\r
+ HighLnSpr[y][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 && (sx <= sx_min || sx >= 328)) continue; // offscreen x\r
+\r
+ HighLnSpr[y][2+cnt] = ((pd - HighPreSpr) / 2); // | prio;\r
+ HighLnSpr[y][0] = cnt + 1;\r
+ }\r
}\r
\r
- *pd++ = (width<<28)|(height<<24)|skip|(hv<<16)|((unsigned short)sy);\r
+ *pd++ = (width<<28)|(height<<24)|(hv<<16)|((unsigned short)sy);\r
*pd++ = (sx<<16)|((unsigned short)code2);\r
\r
// Find next sprite\r
link=(code>>16)&0x7f;\r
- if(!link) break; // End of sprites\r
+ if (!link) break; // End of sprites\r
}\r
- SpriteBlocks = sblocks;\r
- *pd = 0; // terminate\r
+ *pd = 0;\r
+\r
+#if 0\r
+ for (u = 0; u < max_lines; u++)\r
+ {\r
+ int y;\r
+ printf("c%03i: %2i, %2i: ", u, HighLnSpr[u][0] & 0x7f, HighLnSpr[u][1]);\r
+ for (y = 0; y < HighLnSpr[u][0] & 0x7f; y++)\r
+ printf(" %i", HighLnSpr[u][y+2]);\r
+ printf("\n");\r
+ }\r
+#endif\r
}\r
}\r
\r
static void DrawAllSprites(int *hcache, int maxwidth, int prio, int sh)\r
{\r
- int i,u,n;\r
- int sx1seen = 0; // sprite with x coord 1 or 0 seen\r
- int ntiles = 0; // tile counter for sprite limit emulation\r
- int *sprites[40]; // Sprites to draw in fast mode\r
- int max_line_sprites = 20; // 20 sprites, 40 tiles\r
- int *ps, pack, rs = rendstatus, scan = DrawScanline;\r
+ int rs = rendstatus, scan = DrawScanline;\r
+ unsigned char *p;\r
+ int cnt, as;\r
\r
if (rs & (PDRAW_SPRITES_MOVED|PDRAW_DIRTY_SPRITES)) {\r
- //dprintf("PrepareSprites(%i) [%i]", (rs>>4)&1, scan);\r
+ //elprintf(EL_STATUS, "PrepareSprites(%i)", (rs>>4)&1);\r
PrepareSprites(rs & PDRAW_DIRTY_SPRITES);\r
rendstatus = rs & ~(PDRAW_SPRITES_MOVED|PDRAW_DIRTY_SPRITES);\r
}\r
- if (!(SpriteBlocks & (1<<(scan>>3)))) { *hcache = 0; return; }\r
-\r
- if (PicoOpt & POPT_DIS_SPRITE_LIM)\r
- max_line_sprites = 80;\r
\r
HighCacheS_ptr = hcache;\r
- ps = HighPreSpr;\r
+ cnt = HighLnSpr[scan][0] & 0x7f;\r
\r
- // Index + 0 : hhhhvvvv ab--hhvv yyyyyyyy yyyyyyyy // a: offscreen h, b: offs. v, h: horiz. size\r
- // Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8\r
-\r
- for (i=u=n=0; (pack = *ps) && n < max_line_sprites; ps+=2, u++)\r
+ if (cnt != 0)\r
{\r
- int sx, sy, row, pack2;\r
-\r
- if (pack & 0x00400000) continue;\r
-\r
- // get sprite info\r
- pack2 = *(ps+1);\r
- sx = pack2>>16;\r
- sy = (pack <<16)>>16;\r
- row = scan-sy;\r
-\r
- // elprintf(EL_ANOMALY, "x: %4i y: %4i p %i %ix%i", sx, sy, (pack2>>15)&1, (pack>>28)<<3, (pack>>21)&0x38);\r
-\r
- if (sx == -0x77) sx1seen|=1; // for masking mode 2\r
+ p = &HighLnSpr[scan][2];\r
+ as = (rs & PDRAW_ACC_SPRITES) ? 1 : 0;\r
\r
- // check if it is on this line\r
- if (row < 0 || row >= ((pack>>21)&0x38)) continue; // no\r
-\r
- // masking sprite?\r
- if (sx == -0x78) {\r
- if (n > 0) break; // masked\r
- continue;\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
-\r
- n++; // number of sprites on this line (both visible and hidden, except of x=0)\r
-\r
- // sprite limit\r
- ntiles += pack>>28;\r
- if (ntiles > max_line_sprites*2) break;\r
-\r
- if (pack & 0x00800000) continue;\r
-\r
- // sprite is good, save it's pointer\r
- sprites[i++]=ps;\r
}\r
\r
- n = (rs & PDRAW_ACC_SPRITES) ? 1 : 0;\r
-\r
- // Go through sprites backwards:\r
- for (i--; i>=0; i--)\r
- DrawSprite(sprites[i],sh,n);\r
-\r
- // terminate cache list\r
*HighCacheS_ptr = 0;\r
}\r
\r
\r
if (Pico.m.dirtyPal) Pico.m.dirtyPal = 2; // reset dirty if needed\r
\r
+ DrawScanline=0;\r
PrepareSprites(1);\r
skip_next_line=0;\r
- DrawScanline=0;\r
}\r
\r
static void PicoLine(void)\r