X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FDraw.c;h=aea679f612ce13a6ea5b212f29246de292a23327;hb=ee4f03ae8612ca281935871c897ef3a7f4d499ca;hp=d9f4a8acc808655d54ee854bf27e114ca7e085bd;hpb=d9fc2fe1ac69169861cb60b62ccc9fbc6e4fd4c6;p=picodrive.git diff --git a/Pico/Draw.c b/Pico/Draw.c index d9f4a8a..aea679f 100644 --- a/Pico/Draw.c +++ b/Pico/Draw.c @@ -34,12 +34,10 @@ void *DrawLineDest=DefOutBuff; // pointer to dest buffer where to draw this line static int HighCacheA[41+1]; // caches for high layers static int HighCacheB[41+1]; -static int HighCacheS[80+1]; // and sprites -static int HighPreSpr[80*2+1]; // slightly preprocessed sprites -int *HighCacheS_ptr; +int HighPreSpr[80*2+1]; // slightly preprocessed sprites #define MAX_LINE_SPRITES 30 -static unsigned char HighLnSpr[240][2 + MAX_LINE_SPRITES]; // sprite_count, tile_count, [spritep]... +unsigned char HighLnSpr[240][2 + MAX_LINE_SPRITES]; // sprite_count, tile_count, [spritep]... int rendstatus = 0; int DrawScanline = 0; @@ -48,8 +46,8 @@ static int skip_next_line=0; //unsigned short ppt[] = { 0x0f11, 0x0ff1, 0x01f1, 0x011f, 0x01ff, 0x0f1f, 0x0f0e, 0x0e7c }; -static void (*DrawAllSpritesLoPri)(int *hcache, int maxwidth, int prio, int sh) = NULL; -static void (*DrawAllSpritesHiPri)(int *hcache, int maxwidth, int prio, int sh) = NULL; +static void (*DrawAllSpritesLoPri)(int prio, int sh) = NULL; +static void (*DrawAllSpritesHiPri)(int prio, int sh) = NULL; struct TileStrip { @@ -65,9 +63,9 @@ struct TileStrip #ifdef _ASM_DRAW_C void DrawWindow(int tstart, int tend, int prio, int sh); void BackFill(int reg7, int sh); -void DrawSprite(int *sprite, int sh, int as); +void DrawAllSprites(int prio, int sh); void DrawTilesFromCache(int *hc, int sh, int rlim); -void DrawSpritesFromCache(int *hc, int maxwidth, int prio, int sh); +void DrawSpritesSHi(int prio, int sh); void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells); void FinalizeLineBGR444(int sh); void FinalizeLineRGB555(int sh); @@ -611,13 +609,13 @@ last_cut_tile: switch (rlim-dx+8) { case 7: t=pack&0x00f00000; if (t) pd[6]=(unsigned char)(pal|(t>>20)); - case 6: t=pack&0x0f000000; if (t) pd[5]=(unsigned char)(pal|(t>>24)); - case 5: t=pack&0xf0000000; if (t) pd[4]=(unsigned char)(pal|(t>>28)); - case 4: t=pack&0x0000000f; if (t) pd[3]=(unsigned char)(pal|(t )); - case 3: t=pack&0x000000f0; if (t) pd[2]=(unsigned char)(pal|(t>> 4)); - case 2: t=pack&0x00000f00; if (t) pd[1]=(unsigned char)(pal|(t>> 8)); - case 1: t=pack&0x0000f000; if (t) pd[0]=(unsigned char)(pal|(t>>12)); - default: break; + case 6: t=pack&0x0f000000; if (t) pd[5]=(unsigned char)(pal|(t>>24)); + case 5: t=pack&0xf0000000; if (t) pd[4]=(unsigned char)(pal|(t>>28)); + case 4: t=pack&0x0000000f; if (t) pd[3]=(unsigned char)(pal|(t )); + case 3: t=pack&0x000000f0; if (t) pd[2]=(unsigned char)(pal|(t>> 4)); + case 2: t=pack&0x00000f00; if (t) pd[1]=(unsigned char)(pal|(t>> 8)); + case 1: t=pack&0x0000f000; if (t) pd[0]=(unsigned char)(pal|(t>>12)); + default: break; } } } @@ -654,17 +652,9 @@ static void DrawSprite(int *sprite, int sh, int as) if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X tile &= 0x7ff; tile<<=4; tile+=(row&7)<<1; // Tile address + delta<<=4; // Delta of address pal=(code>>9)&0x30; - - // assume there will be no sprites with both normal and operator pixels.. - if ((code&0x8000) || (sh && pal == 0x30) || as) { - *HighCacheS_ptr++ = ((code&0x8000)<<16)|(tile<<16)|((code&0x0800)<<5)|((sx<<6)&0x0000ffc0)|pal|((sprite[0]>>16)&0xf); - // we need all for accurate sprites, cached will be used to do proper priorities - if (!as && (code&0x8000)) return; - } - - delta<<=4; // Delta of address pal|=((sh|as)<<6); if (sh && (code&0x6000) == 0x6000) { @@ -730,7 +720,7 @@ static void DrawSpriteInterlace(unsigned int *sprite) } -static void DrawAllSpritesInterlace(int *hcache, int maxwidth, int pri, int sh) +static void DrawAllSpritesInterlace(int pri, int sh) { struct PicoVideo *pvid=&Pico.video; int i,u,table,link=0,sline=DrawScanline<<1; @@ -760,7 +750,7 @@ static void DrawAllSpritesInterlace(int *hcache, int maxwidth, int pri, int sh) // check if sprite is not hidden offscreen sx = (sx>>16)&0x1ff; sx -= 0x78; // Get X coordinate + 8 - if(sx <= -8*3 || sx >= maxwidth) goto nextsprite; + if(sx <= -8*3 || sx >= 328) goto nextsprite; // sprite is good, save it's pointer sprites[i++]=sprite; @@ -774,46 +764,68 @@ static void DrawAllSpritesInterlace(int *hcache, int maxwidth, int pri, int sh) // Go through sprites backwards: for (i-- ;i>=0; i--) DrawSpriteInterlace(sprites[i]); - - HighCacheS[0] = 1; // just to fool main code } #ifndef _ASM_DRAW_C -static void DrawSpritesFromCache(int *hc, int maxwidth, int prio, int sh) +// Index + 0 : hhhhvvvv ----hhvv yyyyyyyy yyyyyyyy // v, h: vert./horiz. size +// Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8 +static void DrawSpritesSHi(int prio, int sh) { - int code, tile, sx, delta, width; - int pal; int (*fTileFunc)(int sx,int addr,int pal); + unsigned char *p; + int cnt; + + cnt = HighLnSpr[DrawScanline][0] & 0x7f; + if (cnt == 0) return; - // prio[31]:tile[30:17]:flipx[16]:sx[15:6]:pal[5:4]:delta_width[3:0] + p = &HighLnSpr[DrawScanline][2]; - while ((code=*hc++)) + // Go through sprites backwards: + for (cnt--; cnt >= 0; cnt--) { - pal=(code&0x30); - delta=code&0xf; - width=delta>>2; delta&=3; - width++; delta++; // Width and height in tiles - if (code&0x10000) delta=-delta; // Flip X - delta<<=4; - tile=((unsigned int)code>>17)<<1; // also has prio - sx=(code<<16)>>22; // sx can be negative (start offscreen), so sign extend + int *sprite, code, pal, tile, sx, sy; + int offs, delta, width, height, row; + + offs = (p[cnt] & 0x7f) * 2; + sprite = HighPreSpr + offs; + code = sprite[1]; + pal = (code>>9)&0x30; if (sh && pal == 0x30) { - if (code & 0x80000000) // hi priority + if (code & 0x8000) // hi priority { - if(code&0x10000) fTileFunc=TileFlipSH; - else fTileFunc=TileNormSH; + if (code&0x800) fTileFunc=TileFlipSH; + else fTileFunc=TileNormSH; } else { - if(code&0x10000) fTileFunc=TileFlipSH_onlyop_lp; - else fTileFunc=TileNormSH_onlyop_lp; + if (code&0x800) fTileFunc=TileFlipSH_onlyop_lp; + else fTileFunc=TileNormSH_onlyop_lp; } } else { - if(code&0x10000) fTileFunc=TileFlip; - else fTileFunc=TileNorm; + if (!(code & 0x8000)) continue; // non-operator low sprite, already drawn + if (code&0x800) fTileFunc=TileFlip; + else fTileFunc=TileNorm; } + // parse remaining sprite data + sy=sprite[0]; + sx=code>>16; // X + width=sy>>28; + height=(sy>>24)&7; // Width and height in tiles + sy=(sy<<16)>>16; // Y + + row=DrawScanline-sy; // Row of the sprite we are on + + if (code&0x1000) row=(height<<3)-1-row; // Flip Y + + tile=code + (row>>3); // Tile number increases going down + delta=height; // Delta to increase tile by going right + if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X + + tile &= 0x7ff; tile<<=4; tile+=(row&7)<<1; // Tile address + delta<<=4; // Delta of address + for (; width; width--,sx+=8,tile+=delta) { if(sx<=0) continue; @@ -826,44 +838,62 @@ static void DrawSpritesFromCache(int *hc, int maxwidth, int prio, int sh) } #endif -static void DrawSpritesFromCacheAS(int *hc, int maxwidth, int prio, int sh) +static void DrawSpritesHiAS(int prio, int sh) { - int code, tile, sx, delta, width; - int pal, *hce, *hco; int (*fTileFunc)(int sx,int addr,int pal); + unsigned char *p; + int entry, cnt, sh_cnt = 0; + + cnt = HighLnSpr[DrawScanline][0] & 0x7f; + if (cnt == 0) return; - // prio[31]:tile[30:17]:flipx[16]:sx[15:6]:pal[5:4]:delta_width[3:0] + p = &HighLnSpr[DrawScanline][2]; - /* walk the sprite cache backwards.. */ - hco = hce = HighCacheS_ptr; - while (hce > hc) + // Go through sprites: + for (entry = 0; entry < cnt; entry++) { - code=*(--hce); - pal=(code&0x30); - delta=code&0xf; - width=delta>>2; delta&=3; - width++; delta++; // Width and height in tiles - if (code&0x10000) delta=-delta; // Flip X - delta<<=4; - tile=((unsigned int)code>>17)<<1; - sx=(code<<16)>>22; // sx can be negative (start offscreen), so sign extend - - if (code & 0x80000000) // hi priority + int *sprite, code, pal, tile, sx, sy; + int offs, delta, width, height, row; + + offs = (p[entry] & 0x7f) * 2; + sprite = HighPreSpr + offs; + code = sprite[1]; + pal = (code>>9)&0x30; + + if (code & 0x8000) // hi priority { if (sh && pal == 0x30) { - if(code&0x10000) fTileFunc=TileFlipAS_noop; - else fTileFunc=TileNormAS_noop; + if (code&0x800) fTileFunc=TileFlipAS_noop; + else fTileFunc=TileNormAS_noop; } else { - if(code&0x10000) fTileFunc=TileFlipAS; - else fTileFunc=TileNormAS; + if (code&0x800) fTileFunc=TileFlipAS; + else fTileFunc=TileNormAS; } } else { - if(code&0x10000) fTileFunc=TileFlipAS_onlymark; - else fTileFunc=TileNormAS_onlymark; + if (code&0x800) fTileFunc=TileFlipAS_onlymark; + else fTileFunc=TileNormAS_onlymark; } if (sh && pal == 0x30) - *(--hco) = code; /* save for later */ + p[sh_cnt++] = offs / 2; // re-save for sh/hi pass + + // parse remaining sprite data + sy=sprite[0]; + sx=code>>16; // X + width=sy>>28; + height=(sy>>24)&7; // Width and height in tiles + sy=(sy<<16)>>16; // Y + + row=DrawScanline-sy; // Row of the sprite we are on + + if (code&0x1000) row=(height<<3)-1-row; // Flip Y + + tile=code + (row>>3); // Tile number increases going down + delta=height; // Delta to increase tile by going right + if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X + + tile &= 0x7ff; tile<<=4; tile+=(row&7)<<1; // Tile address + delta<<=4; // Delta of address pal |= 0x80; for (; width; width--,sx+=8,tile+=delta) @@ -887,59 +917,29 @@ static void DrawSpritesFromCacheAS(int *hc, int maxwidth, int prio, int sh) } } - /* nasty 2: loop once more and do operator colors */ - while ((code=*hco++)) - { - pal=(code&0x30); - if (pal != 0x30) continue; - delta=code&0xf; - width=delta>>2; delta&=3; - width++; delta++; - if (code&0x10000) delta=-delta; // Flip X - delta<<=4; - tile=((unsigned int)code>>17)<<1; - sx=(code<<16)>>22; - - if (code & 0x80000000) - { - if(code&0x10000) fTileFunc=TileFlipSH; - else fTileFunc=TileNormSH; - } else { - if(code&0x10000) fTileFunc=TileFlipSH_onlyop_lp; - else fTileFunc=TileNormSH_onlyop_lp; - } - - pal |= 0x80; - for (; width; width--,sx+=8,tile+=delta) - { - if(sx<=0) continue; - if(sx>=328) break; // Offscreen - - tile&=0x7fff; // Clip tile address - fTileFunc(sx,tile,pal); - } - } + /* nasty 2: sh operator pass */ + HighLnSpr[DrawScanline][0] = sh_cnt; + DrawSpritesSHi(1, 1); } - // Index + 0 : ----hhvv -lllllll -------y yyyyyyyy // Index + 4 : -------x xxxxxxxx pccvhnnn nnnnnnnn // v // Index + 0 : hhhhvvvv ----hhvv yyyyyyyy yyyyyyyy // v, h: vert./horiz. size // Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8 -static void PrepareSprites(int full) +void PrepareSprites(int full) { struct PicoVideo *pvid=&Pico.video; int u,link=0; int table=0; int *pd = HighPreSpr; - int max_lines = 224, max_sprites = 80; + int max_lines = 224, max_sprites = 80, max_width = 328; int max_line_sprites = 20; // 20 sprites, 40 tiles if (!(Pico.video.reg[12]&1)) - max_sprites = 64, max_line_sprites = 16; + max_sprites = 64, max_line_sprites = 16, max_width = 264; if (PicoOpt & POPT_DIS_SPRITE_LIM) max_line_sprites = MAX_LINE_SPRITES; @@ -965,24 +965,24 @@ static void PrepareSprites(int full) sx = (code2>>16)&0x1ff; sx -= 0x78; // Get X coordinate + 8 sy = (pack << 16) >> 16; - height = pack >> 28; + height = (pack >> 24) & 0xf; if (sy < max_lines && sy + (height<<3) > DrawScanline && // sprite onscreen (y)? - (sx > -24 || sx < 328)) // onscreen x + (sx > -24 || sx < max_width)) // onscreen x { int y = (sy >= DrawScanline) ? sy : DrawScanline; + int entry = ((pd - HighPreSpr) / 2) | ((code2>>8)&0x80); for (; y < sy + (height<<3) && y < max_lines; y++) { - int i, cnt, offs; + int i, cnt; cnt = HighLnSpr[y][0] & 0x7f; if (cnt >= max_line_sprites) continue; // sprite limit? - offs = (pd - HighPreSpr) / 2; for (i = 0; i < cnt; i++) - if (HighLnSpr[y][2+i] == offs) goto found; + if (((HighLnSpr[y][2+i] ^ entry) & 0x7f) == 0) goto found; // this sprite was previously missing - HighLnSpr[y][2+cnt] = offs; + HighLnSpr[y][2+cnt] = entry; HighLnSpr[y][0] = cnt + 1; found:; } @@ -1006,7 +1006,7 @@ found:; { unsigned int *sprite; int code, code2, sx, sy, hv, height, width; - int sx_min, offscr_x; + int sx_min; sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite @@ -1022,32 +1022,34 @@ found:; sx -= 0x78; // Get X coordinate + 8 sx_min = 8-(width<<3); - offscr_x = (sx <= sx_min) || sx >= 328; - if (sy < max_lines && sy + (height<<3) > DrawScanline) // sprite onscreen (y)? { int y = (sy >= DrawScanline) ? sy : DrawScanline; + int entry = ((pd - HighPreSpr) / 2) | ((code2>>8)&0x80); for (; y < sy + (height<<3) && y < max_lines; y++) { int cnt = HighLnSpr[y][0]; if (cnt >= max_line_sprites) continue; // sprite limit? - if (HighLnSpr[y][1] >= max_line_sprites*2) { // tile limit? + if (HighLnSpr[y][1] >= max_line_sprites*2) { // tile limit? HighLnSpr[y][0] |= 0x80; - continue; + continue; } HighLnSpr[y][1] += width; if (sx == -0x78) { if (cnt > 0) HighLnSpr[y][0] |= 0x80; // masked, no more sprites for this line - continue; + continue; } // must keep the first sprite even if it's offscreen, for masking - if (cnt > 0 && (sx <= sx_min || sx >= 328)) continue; // offscreen x + if (cnt > 0 && (sx <= sx_min || sx >= max_width)) continue; // offscreen x - HighLnSpr[y][2+cnt] = ((pd - HighPreSpr) / 2); // | prio; + HighLnSpr[y][2+cnt] = entry; HighLnSpr[y][0] = cnt + 1; + if (entry & 0x80) + rendstatus |= PDRAW_HAVE_HI_SPR; + else rendstatus |= PDRAW_HAVE_LO_SPR; } } @@ -1073,7 +1075,8 @@ found:; } } -static void DrawAllSprites(int *hcache, int maxwidth, int prio, int sh) +#ifndef _ASM_DRAW_C +static void DrawAllSprites(int prio, int sh) { int rs = rendstatus, scan = DrawScanline; unsigned char *p; @@ -1085,30 +1088,25 @@ static void DrawAllSprites(int *hcache, int maxwidth, int prio, int sh) rendstatus = rs & ~(PDRAW_SPRITES_MOVED|PDRAW_DIRTY_SPRITES); } - HighCacheS_ptr = hcache; cnt = HighLnSpr[scan][0] & 0x7f; + if (cnt == 0) return; - if (cnt != 0) - { - p = &HighLnSpr[scan][2]; - as = (rs & PDRAW_ACC_SPRITES) ? 1 : 0; + p = &HighLnSpr[scan][2]; + as = (rs & PDRAW_ACC_SPRITES) ? 1 : 0; - // Go through sprites backwards: - for (cnt--; cnt >= 0; cnt--) - { - int offs = p[cnt] * 2; - //if ((p[cnt] & 0x80) && !as) continue; - DrawSprite(HighPreSpr + offs, sh, as); - } + // Go through sprites backwards: + for (cnt--; cnt >= 0; cnt--) + { + int offs; + if ((p[cnt] >> 7) != prio && !as) continue; + offs = (p[cnt]&0x7f) * 2; + DrawSprite(HighPreSpr + offs, sh, as); } - - *HighCacheS_ptr = 0; } // -------------------------------------------- -#ifndef _ASM_DRAW_C static void BackFill(int reg7, int sh) { unsigned int back; @@ -1328,17 +1326,19 @@ static int DrawDisplay(int sh, int as) DrawWindow( (win&0x80) ? edge : 0, (win&0x80) ? maxcells>>1 : edge, 0, sh|as); } else DrawLayer(0|((sh|as)<<1), HighCacheA, 0, maxcells); - DrawAllSpritesLoPri(HighCacheS, maxw, 0, sh); + if ((rendstatus & PDRAW_HAVE_LO_SPR) || as) + DrawAllSpritesLoPri(0, sh); - if (HighCacheB[0]) DrawTilesFromCache(HighCacheB, sh, 328); + if (HighCacheB[0]) DrawTilesFromCache(HighCacheB, sh, maxw); if (hvwind == 1) DrawWindow(0, maxcells>>1, 1, sh); else if (hvwind == 2) { - if(HighCacheA[0]) DrawTilesFromCache(HighCacheA, sh, (win&0x80) ? edge<<4 : 328); + if(HighCacheA[0]) DrawTilesFromCache(HighCacheA, sh, (win&0x80) ? edge<<4 : maxw); DrawWindow((win&0x80) ? edge : 0, (win&0x80) ? maxcells>>1 : edge, 1, sh); } else - if (HighCacheA[0]) DrawTilesFromCache(HighCacheA, sh, 328); - if (HighCacheS[0]) DrawAllSpritesHiPri(HighCacheS, maxw, 1, sh); + if (HighCacheA[0]) DrawTilesFromCache(HighCacheA, sh, maxw); + if ((rendstatus & PDRAW_HAVE_HI_SPR) || sh) + DrawAllSpritesHiPri(1, sh); #if 0 { @@ -1356,17 +1356,28 @@ static int DrawDisplay(int sh, int as) PICO_INTERNAL void PicoFrameStart(void) { // prepare to do this frame - rendstatus = (PicoOpt&0x80)>>5; // accurate sprites, clear everything else + int sh = Pico.video.reg[0xC] & 8; // shadow/hilight? + rendstatus = 0; + if (PicoOpt & POPT_ACC_SPRITES) + rendstatus |= PDRAW_ACC_SPRITES; + if ((Pico.video.reg[12]&6) == 6) { rendstatus |= PDRAW_INTERLACE; // interlace mode - DrawAllSpritesLoPri = DrawAllSpritesInterlace; + DrawAllSpritesLoPri = DrawAllSpritesHiPri = DrawAllSpritesInterlace; } - else + else if (sh) { DrawAllSpritesLoPri = DrawAllSprites; - DrawAllSpritesHiPri = rendstatus ? DrawSpritesFromCacheAS : DrawSpritesFromCache; + DrawAllSpritesHiPri = DrawSpritesSHi; + } + else + { + DrawAllSpritesLoPri = + DrawAllSpritesHiPri = DrawAllSprites; } + if (rendstatus & PDRAW_ACC_SPRITES) + DrawAllSpritesHiPri = DrawSpritesHiAS; if (Pico.m.dirtyPal) Pico.m.dirtyPal = 2; // reset dirty if needed