X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fdraw.c;h=0939f3fe8f7a3269993693716a39d26707ae1a2a;hb=93f9619ed819dee07948416c98ca2f1c70a22666;hp=a649e8c136081817ae7b79f41ae6b21c1c926835;hpb=1a08dec0e0d3667556ce61307d055b8d19a02034;p=picodrive.git diff --git a/pico/draw.c b/pico/draw.c index a649e8c..0939f3f 100644 --- a/pico/draw.c +++ b/pico/draw.c @@ -46,6 +46,10 @@ static int HighCacheA[41+1]; // caches for high layers static int HighCacheB[41+1]; static int HighPreSpr[80*2+1]; // slightly preprocessed sprites +#define LF_PLANE_1 (1 << 0) +#define LF_SH (1 << 1) // must be = 2 +#define LF_FORCE (1 << 2) + #define SPRL_HAVE_HI 0x80 // have hi priority sprites #define SPRL_HAVE_LO 0x40 // *lo* #define SPRL_MAY_HAVE_OP 0x20 // may have operator sprites on the line @@ -54,12 +58,9 @@ unsigned char HighLnSpr[240][3 + MAX_LINE_SPRITES]; // sprite_count, ^flags, til int rendstatus_old; int rendlines; -int PicoDrawMask = -1; static int skip_next_line=0; -//unsigned short ppt[] = { 0x0f11, 0x0ff1, 0x01f1, 0x011f, 0x01ff, 0x0f1f, 0x0f0e, 0x0e7c }; - struct TileStrip { int nametab; // Position in VRAM of name table (for this tile line) @@ -128,19 +129,12 @@ static void funcname(int sx, unsigned int pack, int pal) \ } -#ifdef _ASM_DRAW_C_AMIPS -int TileNorm(int sx, unsigned int pack, int pal); -int TileFlip(int sx, unsigned int pack, int pal); -#else - #define pix_just_write(x) \ if (t) pd[x]=pal|t TileNormMaker(TileNorm,pix_just_write) TileFlipMaker(TileFlip,pix_just_write) -#endif - #ifndef _ASM_DRAW_C // draw a sprite pixel, process operator colors @@ -192,18 +186,24 @@ TileFlipMaker(TileFlipAS_noop, pix_sh_as_noop) TileNormMaker(TileNormAS_onlymark, pix_sh_as_onlymark) TileFlipMaker(TileFlipAS_onlymark, pix_sh_as_onlymark) +// mark pixel as sprite pixel (AS) +#define pix_and(x) \ + pd[x] = (pd[x] & 0xc0) | (pd[x] & (pal | t)) + +TileNormMaker(TileNorm_and, pix_and) +TileFlipMaker(TileFlip_and, pix_and) // -------------------------------------------- #ifndef _ASM_DRAW_C -static void DrawStrip(struct TileStrip *ts, int plane_sh, int cellskip) +static void DrawStrip(struct TileStrip *ts, int lflags, int cellskip) { int tilex,dx,ty,code=0,addr=0,cells; int oldcode=-1,blank=-1; // The tile we know is blank int pal=0,sh; // Draw tiles across screen: - sh=(plane_sh<<5)&0x40; + sh = (lflags & LF_SH) << 5; // 0x40 tilex=((-ts->hscroll)>>3)+cellskip; ty=(ts->line&7)<<1; // Y-Offset into tile dx=((ts->hscroll-1)&7)+1; @@ -211,13 +211,14 @@ static void DrawStrip(struct TileStrip *ts, int plane_sh, int cellskip) if(dx != 8) cells++; // have hscroll, need to draw 1 cell more dx+=cellskip<<3; - for (; cells > 0; dx+=8,tilex++,cells--) + for (; cells > 0; dx+=8, tilex++, cells--) { unsigned int pack; - code=Pico.vram[ts->nametab+(tilex&ts->xmask)]; - if (code==blank) continue; - if (code>>15) { // high priority tile + code = PicoMem.vram[ts->nametab + (tilex & ts->xmask)]; + if (code == blank) + continue; + if ((code >> 15) | (lflags & LF_FORCE)) { // high priority tile int cval = code | (dx<<16) | (ty<<25); if(code&0x1000) cval^=7<<26; *ts->hc++ = cval; // cache it @@ -234,7 +235,7 @@ static void DrawStrip(struct TileStrip *ts, int plane_sh, int cellskip) pal=((code>>9)&0x30)|sh; } - pack = *(unsigned int *)(Pico.vram + addr); + pack = *(unsigned int *)(PicoMem.vram + addr); if (!pack) { blank = code; continue; @@ -260,7 +261,11 @@ static void DrawStripVSRam(struct TileStrip *ts, int plane_sh, int cellskip) // Draw tiles across screen: tilex=(-ts->hscroll)>>3; dx=((ts->hscroll-1)&7)+1; - if(dx != 8) cell--; // have hscroll, start with negative cell + if (ts->hscroll & 0x0f) { + int adj = ((ts->hscroll ^ dx) >> 3) & 1; + cell -= adj + 1; + ts->cells -= adj; + } cell+=cellskip; tilex+=cellskip; dx+=cellskip<<3; @@ -273,7 +278,7 @@ static void DrawStripVSRam(struct TileStrip *ts, int plane_sh, int cellskip) //if((cell&1)==0) { int line,vscroll; - vscroll=Pico.vsram[(plane_sh&1)+(cell&~1)]; + vscroll=PicoMem.vsram[(plane_sh&1)+(cell&~1)]; // Find the line in the name table line=(vscroll+scan)&ts->line&0xffff; // ts->line is really ymask .. @@ -281,7 +286,7 @@ static void DrawStripVSRam(struct TileStrip *ts, int plane_sh, int cellskip) ty=(line&7)<<1; // Y-Offset into tile } - code=Pico.vram[ts->nametab+nametabadd+(tilex&ts->xmask)]; + code=PicoMem.vram[ts->nametab+nametabadd+(tilex&ts->xmask)]; if (code==blank) continue; if (code>>15) { // high priority tile int cval = code | (dx<<16) | (ty<<25); @@ -299,7 +304,7 @@ static void DrawStripVSRam(struct TileStrip *ts, int plane_sh, int cellskip) pal=((code>>9)&0x30)|((plane_sh<<5)&0x40); } - pack = *(unsigned int *)(Pico.vram + addr); + pack = *(unsigned int *)(PicoMem.vram + addr); if (!pack) { blank = code; continue; @@ -335,7 +340,7 @@ void DrawStripInterlace(struct TileStrip *ts) { unsigned int pack; - code=Pico.vram[ts->nametab+(tilex&ts->xmask)]; + code = PicoMem.vram[ts->nametab + (tilex & ts->xmask)]; if (code==blank) continue; if (code>>15) { // high priority tile int cval = (code&0xfc00) | (dx<<16) | (ty<<25); @@ -355,7 +360,7 @@ void DrawStripInterlace(struct TileStrip *ts) pal=((code>>9)&0x30); } - pack = *(unsigned int *)(Pico.vram + addr); + pack = *(unsigned int *)(PicoMem.vram + addr); if (!pack) { blank = code; continue; @@ -408,11 +413,11 @@ static void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells, htab+=plane_sh&1; // A or B // Get horizontal scroll value, will be masked later - ts.hscroll=Pico.vram[htab&0x7fff]; + ts.hscroll = PicoMem.vram[htab & 0x7fff]; if((pvid->reg[12]&6) == 6) { // interlace mode 2 - vscroll=Pico.vsram[plane_sh&1]; // Get vertical scroll value + vscroll = PicoMem.vsram[plane_sh & 1]; // Get vertical scroll value // Find the line in the name table ts.line=(vscroll+(est->DrawScanline<<1))&((ymask<<1)|1); @@ -425,7 +430,7 @@ static void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells, ts.line=ymask|(shift[width]<<24); // save some stuff instead of line DrawStripVSRam(&ts, plane_sh, cellskip); } else { - vscroll=Pico.vsram[plane_sh&1]; // Get vertical scroll value + vscroll = PicoMem.vsram[plane_sh & 1]; // Get vertical scroll value // Find the line in the name table ts.line=(vscroll+est->DrawScanline)&ymask; @@ -462,7 +467,7 @@ static void DrawWindow(int tstart, int tend, int prio, int sh, if (!(est->rendstatus & PDRAW_WND_DIFF_PRIO)) { // check the first tile code - code=Pico.vram[nametab+tilex]; + code = PicoMem.vram[nametab + tilex]; // if the whole window uses same priority (what is often the case), we may be able to skip this field if ((code>>15) != prio) return; } @@ -479,7 +484,7 @@ static void DrawWindow(int tstart, int tend, int prio, int sh, int dx, addr; int pal; - code=Pico.vram[nametab+tilex]; + code = PicoMem.vram[nametab + tilex]; if (code==blank) continue; if ((code>>15) != prio) { est->rendstatus |= PDRAW_WND_DIFF_PRIO; @@ -490,7 +495,7 @@ static void DrawWindow(int tstart, int tend, int prio, int sh, addr=(code&0x7ff)<<4; if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip - pack = *(unsigned int *)(Pico.vram + addr); + pack = *(unsigned int *)(PicoMem.vram + addr); if (!pack) { blank = code; continue; @@ -511,7 +516,7 @@ static void DrawWindow(int tstart, int tend, int prio, int sh, int dx, addr; int pal; - code=Pico.vram[nametab+tilex]; + code = PicoMem.vram[nametab + tilex]; if(code==blank) continue; if((code>>15) != prio) { est->rendstatus |= PDRAW_WND_DIFF_PRIO; @@ -532,7 +537,7 @@ static void DrawWindow(int tstart, int tend, int prio, int sh, addr=(code&0x7ff)<<4; if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip - pack = *(unsigned int *)(Pico.vram + addr); + pack = *(unsigned int *)(PicoMem.vram + addr); if (!pack) { blank = code; continue; @@ -580,12 +585,13 @@ static void DrawTilesFromCache(int *hc, int sh, int rlim, struct PicoEState *est { short blank=-1; // The tile we know is blank while ((code=*hc++)) { - if((short)code == blank) continue; + if (!(code & 0x8000) || (short)code == blank) + continue; // Get tile address/2: - addr=(code&0x7ff)<<4; - addr+=(unsigned int)code>>25; // y offset into tile + addr = (code & 0x7ff) << 4; + addr += code >> 25; // y offset into tile - pack = *(unsigned int *)(Pico.vram + addr); + pack = *(unsigned int *)(PicoMem.vram + addr); if (!pack) { blank = (short)code; continue; @@ -613,7 +619,7 @@ static void DrawTilesFromCache(int *hc, int sh, int rlim, struct PicoEState *est *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; - pack = *(unsigned int *)(Pico.vram + addr); + pack = *(unsigned int *)(PicoMem.vram + addr); if (!pack) continue; @@ -715,12 +721,33 @@ static void DrawSprite(int *sprite, int sh) if(sx<=0) continue; if(sx>=328) break; // Offscreen - pack = *(unsigned int *)(Pico.vram + (tile & 0x7fff)); + pack = *(unsigned int *)(PicoMem.vram + (tile & 0x7fff)); fTileFunc(sx, pack, pal); } } #endif +static NOINLINE void DrawTilesFromCacheForced(const int *hc) +{ + int code, addr, dx; + unsigned int pack; + int pal; + + // *ts->hc++ = code | (dx<<16) | (ty<<25); + while ((code = *hc++)) { + // Get tile address/2: + addr = (code & 0x7ff) << 4; + addr += (code >> 25) & 0x0e; // y offset into tile + + dx = (code >> 16) & 0x1ff; + pal = ((code >> 9) & 0x30); + pack = *(unsigned int *)(PicoMem.vram + addr); + + if (code & 0x0800) TileFlip_and(dx, pack, pal); + else TileNorm_and(dx, pack, pal); + } +} + static void DrawSpriteInterlace(unsigned int *sprite) { int width=0,height=0; @@ -760,14 +787,14 @@ static void DrawSpriteInterlace(unsigned int *sprite) if(sx<=0) continue; if(sx>=328) break; // Offscreen - pack = *(unsigned int *)(Pico.vram + (tile & 0x7fff)); + pack = *(unsigned int *)(PicoMem.vram + (tile & 0x7fff)); if (code & 0x0800) TileFlip(sx, pack, pal); else TileNorm(sx, pack, pal); } } -static void DrawAllSpritesInterlace(int pri, int sh) +static NOINLINE void DrawAllSpritesInterlace(int pri, int sh) { struct PicoVideo *pvid=&Pico.video; int i,u,table,link=0,sline=Pico.est.DrawScanline<<1; @@ -782,7 +809,7 @@ static void DrawAllSpritesInterlace(int pri, int sh) unsigned int *sprite; int code, sx, sy, height; - sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite + sprite=(unsigned int *)(PicoMem.vram+((table+(link<<2))&0x7ffc)); // Find sprite // get sprite info code = sprite[0]; @@ -885,7 +912,7 @@ static void DrawSpritesSHi(unsigned char *sprited, const struct PicoEState *est) if(sx<=0) continue; if(sx>=328) break; // Offscreen - pack = *(unsigned int *)(Pico.vram + (tile & 0x7fff)); + pack = *(unsigned int *)(PicoMem.vram + (tile & 0x7fff)); fTileFunc(sx, pack, pal); } } @@ -959,7 +986,7 @@ static void DrawSpritesHiAS(unsigned char *sprited, int sh) if(sx<=0) continue; if(sx>=328) break; // Offscreen - pack = *(unsigned int *)(Pico.vram + (tile & 0x7fff)); + pack = *(unsigned int *)(PicoMem.vram + (tile & 0x7fff)); fTileFunc(sx, pack, pal); } } @@ -1000,7 +1027,7 @@ static NOINLINE void PrepareSprites(int full) if (!(Pico.video.reg[12]&1)) max_sprites = 64, max_line_sprites = 16, max_width = 264; - if (PicoOpt & POPT_DIS_SPRITE_LIM) + if (PicoIn.opt & POPT_DIS_SPRITE_LIM) max_line_sprites = MAX_LINE_SPRITES; if (pvid->reg[1]&8) max_lines = 240; @@ -1019,7 +1046,7 @@ static NOINLINE void PrepareSprites(int full) unsigned int *sprite; int code2, sx, sy, height; - sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite + sprite=(unsigned int *)(PicoMem.vram+((table+(link<<2))&0x7ffc)); // Find sprite // parse sprite info code2 = sprite[1]; @@ -1072,7 +1099,7 @@ found:; unsigned int *sprite; int code, code2, sx, sy, hv, height, width; - sprite=(unsigned int *)(Pico.vram+((table+(link<<2))&0x7ffc)); // Find sprite + sprite=(unsigned int *)(PicoMem.vram+((table+(link<<2))&0x7ffc)); // Find sprite // parse sprite info code = sprite[0]; @@ -1196,7 +1223,7 @@ void PicoDoHighPal555(int sh, int line, struct PicoEState *est) Pico.m.dirtyPal = 0; - spal = (void *)Pico.cram; + spal = (void *)PicoMem.cram; dpal = (void *)est->HighPal; for (i = 0; i < 0x40 / 2; i++) { @@ -1240,7 +1267,7 @@ void FinalizeLine555(int sh, int line, struct PicoEState *est) if (Pico.video.reg[12]&1) { len = 320; } else { - if (!(PicoOpt&POPT_DIS_32C_BORDER)) pd+=32; + if (!(PicoIn.opt&POPT_DIS_32C_BORDER)) pd+=32; len = 256; } @@ -1278,16 +1305,16 @@ static void FinalizeLine8bit(int sh, int line, struct PicoEState *est) rs |= PDRAW_SONIC_MODE; est->rendstatus = rs; if (dirty_count == 3) { - blockcpy(est->HighPal, Pico.cram, 0x40*2); + blockcpy(est->HighPal, PicoMem.cram, 0x40*2); } else if (dirty_count == 11) { - blockcpy(est->HighPal+0x40, Pico.cram, 0x40*2); + blockcpy(est->HighPal+0x40, PicoMem.cram, 0x40*2); } } if (Pico.video.reg[12]&1) { len = 320; } else { - if (!(PicoOpt & POPT_DIS_32C_BORDER)) + if (!(PicoIn.opt & POPT_DIS_32C_BORDER)) pd += 32; len = 256; } @@ -1312,8 +1339,8 @@ static int DrawDisplay(int sh) struct PicoEState *est=&Pico.est; unsigned char *sprited = &HighLnSpr[est->DrawScanline][0]; struct PicoVideo *pvid=&Pico.video; - int win=0,edge=0,hvwind=0; - int maxw,maxcells; + int win=0, edge=0, hvwind=0, lflags; + int maxw, maxcells; if (est->rendstatus & (PDRAW_SPRITES_MOVED|PDRAW_DIRTY_SPRITES)) { // elprintf(EL_STATUS, "PrepareSprites(%i)", (est->rendstatus>>4)&1); @@ -1351,29 +1378,40 @@ static int DrawDisplay(int sh) } /* - layer B low - */ - if (PicoDrawMask & PDRAW_LAYERB_ON) - DrawLayer(1|(sh<<1), HighCacheB, 0, maxcells, est); + if (!(pvid->debug_p & PVD_KILL_B)) { + lflags = LF_PLANE_1 | (sh << 1); + if (pvid->debug_p & PVD_FORCE_B) + lflags |= LF_FORCE; + DrawLayer(lflags, HighCacheB, 0, maxcells, est); + } /* - layer A low - */ - if (!(PicoDrawMask & PDRAW_LAYERA_ON)); + lflags = 0 | (sh << 1); + if (pvid->debug_p & PVD_FORCE_A) + lflags |= LF_FORCE; + if (pvid->debug_p & PVD_KILL_A) + ; else if (hvwind == 1) DrawWindow(0, maxcells>>1, 0, sh, est); else if (hvwind == 2) { - DrawLayer(0|(sh<<1), HighCacheA, (win&0x80) ? 0 : edge<<1, (win&0x80) ? edge<<1 : maxcells, est); - DrawWindow( (win&0x80) ? edge : 0, (win&0x80) ? maxcells>>1 : edge, 0, sh, est); - } else - DrawLayer(0|(sh<<1), HighCacheA, 0, maxcells, est); + DrawLayer(lflags, HighCacheA, (win&0x80) ? 0 : edge<<1, (win&0x80) ? edge<<1 : maxcells, est); + DrawWindow( (win&0x80) ? edge : 0, (win&0x80) ? maxcells>>1 : edge, 0, sh, est); + } + else + DrawLayer(lflags, HighCacheA, 0, maxcells, est); /* - sprites low - */ - if (!(PicoDrawMask & PDRAW_SPRITES_LOW_ON)); + if (pvid->debug_p & PVD_KILL_S_LO) + ; else if (est->rendstatus & PDRAW_INTERLACE) DrawAllSpritesInterlace(0, sh); else if (sprited[1] & SPRL_HAVE_LO) DrawAllSprites(sprited, 0, sh, est); /* - layer B hi - */ - if ((PicoDrawMask & PDRAW_LAYERB_ON) && HighCacheB[0]) + if (!(pvid->debug_p & PVD_KILL_B) && HighCacheB[0]) DrawTilesFromCache(HighCacheB, sh, maxw, est); /* - layer A hi - */ - if (!(PicoDrawMask & PDRAW_LAYERA_ON)); + if (pvid->debug_p & PVD_KILL_A) + ; else if (hvwind == 1) DrawWindow(0, maxcells>>1, 1, sh, est); else if (hvwind == 2) { @@ -1384,17 +1422,23 @@ static int DrawDisplay(int sh) if (HighCacheA[0]) DrawTilesFromCache(HighCacheA, sh, maxw, est); /* - sprites hi - */ - if (!(PicoDrawMask & PDRAW_SPRITES_HI_ON)); + if (pvid->debug_p & PVD_KILL_S_HI) + ; else if (est->rendstatus & PDRAW_INTERLACE) DrawAllSpritesInterlace(1, sh); // have sprites without layer pri bit ontop of sprites with that bit - else if ((sprited[1] & 0xd0) == 0xd0 && (PicoOpt & POPT_ACC_SPRITES)) + else if ((sprited[1] & 0xd0) == 0xd0 && (PicoIn.opt & POPT_ACC_SPRITES)) DrawSpritesHiAS(sprited, sh); else if (sh && (sprited[1] & SPRL_MAY_HAVE_OP)) DrawSpritesSHi(sprited, est); else if (sprited[1] & SPRL_HAVE_HI) DrawAllSprites(sprited, 1, 0, est); + if (pvid->debug_p & PVD_FORCE_B) + DrawTilesFromCacheForced(HighCacheB); + else if (pvid->debug_p & PVD_FORCE_A) + DrawTilesFromCacheForced(HighCacheA); + #if 0 { int *c, a, b; @@ -1437,7 +1481,7 @@ PICO_INTERNAL void PicoFrameStart(void) Pico.est.DrawScanline = 0; skip_next_line = 0; - if (PicoOpt & POPT_ALT_RENDERER) + if (PicoIn.opt & POPT_ALT_RENDERER) return; if (Pico.m.dirtyPal) @@ -1480,6 +1524,9 @@ static void PicoLine(int line, int offs, int sh, int bgc) return; } + if (Pico.video.debug_p & (PVD_FORCE_A | PVD_FORCE_B)) + bgc = 0x3f; + // Draw screen: BackFill(bgc, sh, &Pico.est); if (Pico.video.reg[1]&0x40) @@ -1503,13 +1550,14 @@ void PicoDrawSync(int to, int blank_last_line) pprof_start(draw); - if (rendlines != 240) + if (rendlines != 240) { offs = 8; + if (to > 223) + to = 223; + } for (line = Pico.est.DrawScanline; line < to; line++) - { PicoLine(line, offs, sh, bgc); - } // last line if (line <= to) @@ -1529,7 +1577,7 @@ void PicoDrawUpdateHighPal(void) { struct PicoEState *est = &Pico.est; int sh = (Pico.video.reg[0xC] & 8) >> 3; // shadow/hilight? - if (PicoOpt & POPT_ALT_RENDERER) + if (PicoIn.opt & POPT_ALT_RENDERER) sh = 0; // no s/h support PicoDoHighPal555(sh, 0, &Pico.est); @@ -1549,7 +1597,7 @@ void PicoDrawSetOutFormat(pdso_t which, int use_32x_line_mode) break; case PDF_RGB555: - if ((PicoAHW & PAHW_32X) && use_32x_line_mode) + if ((PicoIn.AHW & PAHW_32X) && use_32x_line_mode) FinalizeLine = FinalizeLine32xRGB555; else FinalizeLine = FinalizeLine555; @@ -1569,7 +1617,7 @@ void PicoDrawSetOutBuf(void *dest, int increment) { DrawLineDestBase = dest; DrawLineDestIncrement = increment; - Pico.est.DrawLineDest = DrawLineDestBase + Pico.est.DrawScanline * increment; + Pico.est.DrawLineDest = (char *)DrawLineDestBase + Pico.est.DrawScanline * increment; } void PicoDrawSetInternalBuf(void *dest, int increment) @@ -1592,7 +1640,7 @@ void PicoDrawSetCallbacks(int (*begin)(unsigned int num), int (*end)(unsigned in PicoScan32xBegin = NULL; PicoScan32xEnd = NULL; - if ((PicoAHW & PAHW_32X) && FinalizeLine != FinalizeLine32xRGB555) { + if ((PicoIn.AHW & PAHW_32X) && FinalizeLine != FinalizeLine32xRGB555) { PicoScan32xBegin = begin; PicoScan32xEnd = end; }