X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=picodrive.git;a=blobdiff_plain;f=pico%2Fdraw.c;h=5e8d86b48c90424eb5438375c886c3d8bb9a7d6d;hp=9b9ce91c81f9b403c2549e2e4aefaf68afe3842a;hb=e0bcb7a90d06b295b1ca989b6ad70412912cca5b;hpb=bfa124288c633b7631a37bb0e6be0aca1e2363ea diff --git a/pico/draw.c b/pico/draw.c index 9b9ce91..5e8d86b 100644 --- a/pico/draw.c +++ b/pico/draw.c @@ -1,11 +1,11 @@ -// This is part of Pico Library - -// (c) Copyright 2004 Dave, All rights reserved. -// (c) Copyright 2006-2008 notaz, All rights reserved. -// Free for non-commercial use. - -// For commercial use, separate licencing terms must be obtained. - +/* + * line renderer + * (c) Copyright Dave, 2004 + * (C) notaz, 2006-2010 + * + * This work is licensed under the terms of MAME license. + * See COPYING file in the top-level directory. + */ /* * The renderer has 4 modes now: * - normal @@ -19,7 +19,7 @@ * * since renderer always draws line in 8bit mode, there are 2 spare bits: * b \ mode: s/h as sonic - * 00 normal - - + * 00 normal - pal index * 01 shadow - pal index * 10 hilight+op spr spr pal index * 11 shadow +op spr - pal index @@ -34,18 +34,21 @@ int (*PicoScanBegin)(unsigned int num) = NULL; int (*PicoScanEnd) (unsigned int num) = NULL; -#if OVERRIDE_HIGHCOL static unsigned char DefHighCol[8+320+8]; -unsigned char *HighCol=DefHighCol; -#else -unsigned char HighCol[8+320+8]; -#endif -unsigned short DefOutBuff[320*2]; -void *DrawLineDest=DefOutBuff; // pointer to dest buffer where to draw this line to +static unsigned char *HighColBase = DefHighCol; +static int HighColIncrement; + +static unsigned int DefOutBuff[320*2/2]; +void *DrawLineDestBase = DefOutBuff; +int DrawLineDestIncrement; static int HighCacheA[41+1]; // caches for high layers static int HighCacheB[41+1]; -int HighPreSpr[80*2+1]; // slightly preprocessed sprites +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* @@ -53,14 +56,11 @@ int HighPreSpr[80*2+1]; // slightly preprocessed sprites #define SPRL_LO_ABOVE_HI 0x10 // low priority sprites may be on top of hi unsigned char HighLnSpr[240][3 + MAX_LINE_SPRITES]; // sprite_count, ^flags, tile_count, [spritep]... -int rendstatus = 0; -int DrawScanline = 0; -int PicoDrawMask = -1; +int rendstatus_old; +int rendlines; 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) @@ -73,14 +73,15 @@ struct TileStrip // stuff available in asm: #ifdef _ASM_DRAW_C -void DrawWindow(int tstart, int tend, int prio, int sh); -void BackFill(int reg7, int sh); -void DrawAllSprites(unsigned char *sprited, int prio, int sh); -void DrawTilesFromCache(int *hc, int sh, int rlim); -void DrawSpritesSHi(unsigned char *sprited); -void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells); -void FinalizeLineBGR444(int sh); -void FinalizeLineRGB555(int sh); +void DrawWindow(int tstart, int tend, int prio, int sh, + struct PicoEState *est); +void DrawAllSprites(unsigned char *sprited, int prio, int sh, + struct PicoEState *est); +void DrawTilesFromCache(int *hc, int sh, int rlim, + struct PicoEState *est); +void DrawSpritesSHi(unsigned char *sprited, struct PicoEState *est); +void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells, + struct PicoEState *est); void *blockcpy(void *dst, const void *src, size_t n); void blockcpy_or(void *dst, void *src, size_t n, int pat); #else @@ -96,56 +97,41 @@ void blockcpy_or(void *dst, void *src, size_t n, int pat) #define TileNormMaker(funcname,pix_func) \ -static int funcname(int sx,int addr,int pal) \ +static void funcname(int sx, unsigned int pack, int pal) \ { \ - unsigned char *pd = HighCol+sx; \ - unsigned int pack=0; unsigned int t=0; \ - \ - pack=*(unsigned int *)(Pico.vram+addr); /* Get 8 pixels */ \ - if (pack) \ - { \ - t=(pack&0x0000f000)>>12; pix_func(0); \ - t=(pack&0x00000f00)>> 8; pix_func(1); \ - t=(pack&0x000000f0)>> 4; pix_func(2); \ - t=(pack&0x0000000f) ; pix_func(3); \ - t=(pack&0xf0000000)>>28; pix_func(4); \ - t=(pack&0x0f000000)>>24; pix_func(5); \ - t=(pack&0x00f00000)>>20; pix_func(6); \ - t=(pack&0x000f0000)>>16; pix_func(7); \ - return 0; \ - } \ + unsigned char *pd = Pico.est.HighCol + sx; \ + unsigned int t; \ \ - return 1; /* Tile blank */ \ + t = (pack&0x0000f000)>>12; pix_func(0); \ + t = (pack&0x00000f00)>> 8; pix_func(1); \ + t = (pack&0x000000f0)>> 4; pix_func(2); \ + t = (pack&0x0000000f) ; pix_func(3); \ + t = (pack&0xf0000000)>>28; pix_func(4); \ + t = (pack&0x0f000000)>>24; pix_func(5); \ + t = (pack&0x00f00000)>>20; pix_func(6); \ + t = (pack&0x000f0000)>>16; pix_func(7); \ } - #define TileFlipMaker(funcname,pix_func) \ -static int funcname(int sx,int addr,int pal) \ +static void funcname(int sx, unsigned int pack, int pal) \ { \ - unsigned char *pd = HighCol+sx; \ - unsigned int pack=0; unsigned int t=0; \ + unsigned char *pd = Pico.est.HighCol + sx; \ + unsigned int t; \ \ - pack=*(unsigned int *)(Pico.vram+addr); /* Get 8 pixels */ \ - if (pack) \ - { \ - t=(pack&0x000f0000)>>16; pix_func(0); \ - t=(pack&0x00f00000)>>20; pix_func(1); \ - t=(pack&0x0f000000)>>24; pix_func(2); \ - t=(pack&0xf0000000)>>28; pix_func(3); \ - t=(pack&0x0000000f) ; pix_func(4); \ - t=(pack&0x000000f0)>> 4; pix_func(5); \ - t=(pack&0x00000f00)>> 8; pix_func(6); \ - t=(pack&0x0000f000)>>12; pix_func(7); \ - return 0; \ - } \ - \ - return 1; /* Tile blank */ \ + t = (pack&0x000f0000)>>16; pix_func(0); \ + t = (pack&0x00f00000)>>20; pix_func(1); \ + t = (pack&0x0f000000)>>24; pix_func(2); \ + t = (pack&0xf0000000)>>28; pix_func(3); \ + t = (pack&0x0000000f) ; pix_func(4); \ + t = (pack&0x000000f0)>> 4; pix_func(5); \ + t = (pack&0x00000f00)>> 8; pix_func(6); \ + t = (pack&0x0000f000)>>12; pix_func(7); \ } #ifdef _ASM_DRAW_C_AMIPS -int TileNorm(int sx,int addr,int pal); -int TileFlip(int sx,int addr,int pal); +int TileNorm(int sx, unsigned int pack, int pal); +int TileFlip(int sx, unsigned int pack, int pal); #else #define pix_just_write(x) \ @@ -207,18 +193,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; @@ -226,13 +218,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--) { - int zero=0; + unsigned int pack; - code=Pico.vram[ts->nametab+(tilex&ts->xmask)]; - if (code==blank) continue; - if (code>>15) { // high priority tile + code = Pico.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 @@ -249,24 +242,28 @@ static void DrawStrip(struct TileStrip *ts, int plane_sh, int cellskip) pal=((code>>9)&0x30)|sh; } - if (code&0x0800) zero=TileFlip(dx,addr,pal); - else zero=TileNorm(dx,addr,pal); + pack = *(unsigned int *)(Pico.vram + addr); + if (!pack) { + blank = code; + continue; + } - if (zero) blank=code; // We know this tile is blank now + if (code & 0x0800) TileFlip(dx, pack, pal); + else TileNorm(dx, pack, pal); } // terminate the cache list *ts->hc = 0; // if oldcode wasn't changed, it means all layer is hi priority - if (oldcode == -1) rendstatus |= PDRAW_PLANE_HI_PRIO; + if (oldcode == -1) Pico.est.rendstatus |= PDRAW_PLANE_HI_PRIO; } // this is messy -void DrawStripVSRam(struct TileStrip *ts, int plane_sh, int cellskip) +static void DrawStripVSRam(struct TileStrip *ts, int plane_sh, int cellskip) { int tilex,dx,code=0,addr=0,cell=0; int oldcode=-1,blank=-1; // The tile we know is blank - int pal=0,scan=DrawScanline; + int pal=0,scan=Pico.est.DrawScanline; // Draw tiles across screen: tilex=(-ts->hscroll)>>3; @@ -278,7 +275,8 @@ void DrawStripVSRam(struct TileStrip *ts, int plane_sh, int cellskip) for (; cell < ts->cells; dx+=8,tilex++,cell++) { - int zero=0,nametabadd,ty; + int nametabadd, ty; + unsigned int pack; //if((cell&1)==0) { @@ -309,15 +307,19 @@ void DrawStripVSRam(struct TileStrip *ts, int plane_sh, int cellskip) pal=((code>>9)&0x30)|((plane_sh<<5)&0x40); } - if (code&0x0800) zero=TileFlip(dx,addr,pal); - else zero=TileNorm(dx,addr,pal); + pack = *(unsigned int *)(Pico.vram + addr); + if (!pack) { + blank = code; + continue; + } - if (zero) blank=code; // We know this tile is blank now + if (code & 0x0800) TileFlip(dx, pack, pal); + else TileNorm(dx, pack, pal); } // terminate the cache list *ts->hc = 0; - if (oldcode == -1) rendstatus |= PDRAW_PLANE_HI_PRIO; + if (oldcode == -1) Pico.est.rendstatus |= PDRAW_PLANE_HI_PRIO; } #endif @@ -339,7 +341,7 @@ void DrawStripInterlace(struct TileStrip *ts) for (; cells; dx+=8,tilex++,cells--) { - int zero=0; + unsigned int pack; code=Pico.vram[ts->nametab+(tilex&ts->xmask)]; if (code==blank) continue; @@ -361,10 +363,14 @@ void DrawStripInterlace(struct TileStrip *ts) pal=((code>>9)&0x30); } - if (code&0x0800) zero=TileFlip(dx,addr,pal); - else zero=TileNorm(dx,addr,pal); + pack = *(unsigned int *)(Pico.vram + addr); + if (!pack) { + blank = code; + continue; + } - if (zero) blank=code; // We know this tile is blank now + if (code & 0x0800) TileFlip(dx, pack, pal); + else TileNorm(dx, pack, pal); } // terminate the cache list @@ -374,7 +380,8 @@ void DrawStripInterlace(struct TileStrip *ts) // -------------------------------------------- #ifndef _ASM_DRAW_C -static void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells) +static void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells, + struct PicoEState *est) { struct PicoVideo *pvid=&Pico.video; const char shift[4]={5,6,5,7}; // 32,64 or 128 sized tilemaps (2 is invalid) @@ -393,15 +400,18 @@ static void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells) ts.xmask=(1<1) ymask =0x0ff; + switch (width) { + case 1: ymask &= 0x1ff; break; + case 2: ymask = 0x007; break; + case 3: ymask = 0x0ff; break; + } // Find name table: if (plane_sh&1) ts.nametab=(pvid->reg[4]&0x07)<<12; // B else ts.nametab=(pvid->reg[2]&0x38)<< 9; // A htab=pvid->reg[13]<<9; // Horizontal scroll table address - if ( pvid->reg[11]&2) htab+=DrawScanline<<1; // Offset by line + if ( pvid->reg[11]&2) htab+=est->DrawScanline<<1; // Offset by line if ((pvid->reg[11]&1)==0) htab&=~0xf; // Offset by tile htab+=plane_sh&1; // A or B @@ -413,7 +423,7 @@ static void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells) vscroll=Pico.vsram[plane_sh&1]; // Get vertical scroll value // Find the line in the name table - ts.line=(vscroll+(DrawScanline<<1))&((ymask<<1)|1); + ts.line=(vscroll+(est->DrawScanline<<1))&((ymask<<1)|1); ts.nametab+=(ts.line>>4)<DrawScanline)&ymask; ts.nametab+=(ts.line>>3)<reg[12]&1) { nametab=(pvid->reg[3]&0x3c)<<9; // 40-cell mode - nametab+=(DrawScanline>>3)<<6; + nametab+=(est->DrawScanline>>3)<<6; } else { nametab=(pvid->reg[3]&0x3e)<<9; // 32-cell mode - nametab+=(DrawScanline>>3)<<5; + nametab+=(est->DrawScanline>>3)<<5; } tilex=tstart<<1; - if (!(rendstatus & PDRAW_WND_DIFF_PRIO)) { + if (!(est->rendstatus & PDRAW_WND_DIFF_PRIO)) { // check the first tile code code=Pico.vram[nametab+tilex]; // if the whole window uses same priority (what is often the case), we may be able to skip this field @@ -465,53 +476,60 @@ static void DrawWindow(int tstart, int tend, int prio, int sh) // int *hcache } tend<<=1; - ty=(DrawScanline&7)<<1; // Y-Offset into tile + ty=(est->DrawScanline&7)<<1; // Y-Offset into tile // Draw tiles across screen: if (!sh) { for (; tilex < tend; tilex++) { - int addr=0,zero=0; + unsigned int pack; + int dx, addr; int pal; code=Pico.vram[nametab+tilex]; if (code==blank) continue; if ((code>>15) != prio) { - rendstatus |= PDRAW_WND_DIFF_PRIO; + est->rendstatus |= PDRAW_WND_DIFF_PRIO; continue; } - pal=((code>>9)&0x30); - // Get tile address/2: addr=(code&0x7ff)<<4; if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip - if (code&0x0800) zero=TileFlip(8+(tilex<<3),addr,pal); - else zero=TileNorm(8+(tilex<<3),addr,pal); + pack = *(unsigned int *)(Pico.vram + addr); + if (!pack) { + blank = code; + continue; + } + + pal = ((code >> 9) & 0x30); + dx = 8 + (tilex << 3); - if (zero) blank=code; // We know this tile is blank now + if (code & 0x0800) TileFlip(dx, pack, pal); + else TileNorm(dx, pack, pal); } } else { for (; tilex < tend; tilex++) { - int addr=0,zero=0; + unsigned int pack; + int dx, addr; int pal; code=Pico.vram[nametab+tilex]; if(code==blank) continue; if((code>>15) != prio) { - rendstatus |= PDRAW_WND_DIFF_PRIO; + est->rendstatus |= PDRAW_WND_DIFF_PRIO; continue; } pal=((code>>9)&0x30); if (prio) { - int *zb = (int *)(HighCol+8+(tilex<<3)); + int *zb = (int *)(est->HighCol+8+(tilex<<3)); *zb++ &= 0xbfbfbfbf; *zb &= 0xbfbfbfbf; } else { @@ -522,10 +540,16 @@ static void DrawWindow(int tstart, int tend, int prio, int sh) // int *hcache addr=(code&0x7ff)<<4; if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip - if (code&0x0800) zero=TileFlip(8+(tilex<<3),addr,pal); - else zero=TileNorm(8+(tilex<<3),addr,pal); + pack = *(unsigned int *)(Pico.vram + addr); + if (!pack) { + blank = code; + continue; + } - if (zero) blank=code; // We know this tile is blank now + dx = 8 + (tilex << 3); + + if (code & 0x0800) TileFlip(dx, pack, pal); + else TileNorm(dx, pack, pal); } } } @@ -537,24 +561,25 @@ static void DrawTilesFromCacheShPrep(void) // as some layer has covered whole line with hi priority tiles, // we can process whole line and then act as if sh/hi mode was off, // but leave lo pri op sprite markers alone - int c = 320/4, *zb = (int *)(HighCol+8); - rendstatus |= PDRAW_SHHI_DONE; + int c = 320/4, *zb = (int *)(Pico.est.HighCol+8); + Pico.est.rendstatus |= PDRAW_SHHI_DONE; while (c--) { *zb++ &= 0xbfbfbfbf; } } -static void DrawTilesFromCache(int *hc, int sh, int rlim) +static void DrawTilesFromCache(int *hc, int sh, int rlim, struct PicoEState *est) { int code, addr, dx; + unsigned int pack; int pal; // *ts->hc++ = code | (dx<<16) | (ty<<25); // cache it - if (sh && (rendstatus & (PDRAW_SHHI_DONE|PDRAW_PLANE_HI_PRIO))) + if (sh && (est->rendstatus & (PDRAW_SHHI_DONE|PDRAW_PLANE_HI_PRIO))) { - if (!(rendstatus & PDRAW_SHHI_DONE)) + if (!(est->rendstatus & PDRAW_SHHI_DONE)) DrawTilesFromCacheShPrep(); sh = 0; } @@ -563,48 +588,60 @@ static void DrawTilesFromCache(int *hc, int sh, int rlim) { short blank=-1; // The tile we know is blank while ((code=*hc++)) { - int zero; - 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 - dx=(code>>16)&0x1ff; + addr = (code & 0x7ff) << 4; + addr += code >> 25; // y offset into tile - pal=((code>>9)&0x30); - if (rlim-dx < 0) goto last_cut_tile; + pack = *(unsigned int *)(Pico.vram + addr); + if (!pack) { + blank = (short)code; + continue; + } - if (code&0x0800) zero=TileFlip(dx,addr,pal); - else zero=TileNorm(dx,addr,pal); + dx = (code >> 16) & 0x1ff; + pal = ((code >> 9) & 0x30); + if (rlim-dx < 0) + goto last_cut_tile; - if (zero) blank=(short)code; + if (code & 0x0800) TileFlip(dx, pack, pal); + else TileNorm(dx, pack, pal); } } else { while ((code=*hc++)) { unsigned char *zb; + // Get tile address/2: addr=(code&0x7ff)<<4; addr+=(unsigned int)code>>25; // y offset into tile dx=(code>>16)&0x1ff; - zb = HighCol+dx; + zb = est->HighCol+dx; *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; *zb++ &= 0xbf; - pal=((code>>9)&0x30); - if (rlim-dx < 0) goto last_cut_tile; + pack = *(unsigned int *)(Pico.vram + addr); + if (!pack) + continue; + + pal = ((code >> 9) & 0x30); + if (rlim - dx < 0) + goto last_cut_tile; - if (code&0x0800) TileFlip(dx,addr,pal); - else TileNorm(dx,addr,pal); + if (code & 0x0800) TileFlip(dx, pack, pal); + else TileNorm(dx, pack, pal); } } return; last_cut_tile: + // for vertical window cutoff { - unsigned int t, pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels - unsigned char *pd = HighCol+dx; - if (!pack) return; + unsigned char *pd = est->HighCol + dx; + unsigned int t; + if (code&0x0800) { switch (rlim-dx+8) @@ -648,7 +685,7 @@ static void DrawSprite(int *sprite, int sh) int pal; int tile=0,delta=0; int sx, sy; - int (*fTileFunc)(int sx,int addr,int pal); + void (*fTileFunc)(int sx, unsigned int pack, int pal); // parse the sprite data sy=sprite[0]; @@ -658,7 +695,7 @@ static void DrawSprite(int *sprite, int sh) height=(sy>>24)&7; // Width and height in tiles sy=(sy<<16)>>16; // Y - row=DrawScanline-sy; // Row of the sprite we are on + row=Pico.est.DrawScanline-sy; // Row of the sprite we are on if (code&0x1000) row=(height<<3)-1-row; // Flip Y @@ -682,15 +719,38 @@ static void DrawSprite(int *sprite, int sh) for (; width; width--,sx+=8,tile+=delta) { + unsigned int pack; + if(sx<=0) continue; if(sx>=328) break; // Offscreen - tile&=0x7fff; // Clip tile address - fTileFunc(sx,tile,pal); + pack = *(unsigned int *)(Pico.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 *)(Pico.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; @@ -706,7 +766,7 @@ static void DrawSpriteInterlace(unsigned int *sprite) width=(height>>2)&3; height&=3; width++; height++; // Width and height in tiles - row=(DrawScanline<<1)-sy; // Row of the sprite we are on + row=(Pico.est.DrawScanline<<1)-sy; // Row of the sprite we are on code=sprite[1]; sx=((code>>16)&0x1ff)-0x78; // X @@ -725,20 +785,22 @@ static void DrawSpriteInterlace(unsigned int *sprite) for (; width; width--,sx+=8,tile+=delta) { + unsigned int pack; + if(sx<=0) continue; if(sx>=328) break; // Offscreen - tile&=0x7fff; // Clip tile address - if (code&0x0800) TileFlip(sx,tile,pal); - else TileNorm(sx,tile,pal); + pack = *(unsigned int *)(Pico.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=DrawScanline<<1; + int i,u,table,link=0,sline=Pico.est.DrawScanline<<1; unsigned int *sprites[80]; // Sprite index table=pvid->reg[5]&0x7f; @@ -790,9 +852,9 @@ static void DrawAllSpritesInterlace(int pri, 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(unsigned char *sprited) +static void DrawSpritesSHi(unsigned char *sprited, const struct PicoEState *est) { - int (*fTileFunc)(int sx,int addr,int pal); + void (*fTileFunc)(int sx, unsigned int pack, int pal); unsigned char *p; int cnt; @@ -808,7 +870,7 @@ static void DrawSpritesSHi(unsigned char *sprited) int offs, delta, width, height, row; offs = (p[cnt] & 0x7f) * 2; - sprite = HighPreSpr + offs; + sprite = est->HighPreSpr + offs; code = sprite[1]; pal = (code>>9)&0x30; @@ -835,7 +897,7 @@ static void DrawSpritesSHi(unsigned char *sprited) height=(sy>>24)&7; // Width and height in tiles sy=(sy<<16)>>16; // Y - row=DrawScanline-sy; // Row of the sprite we are on + row=est->DrawScanline-sy; // Row of the sprite we are on if (code&0x1000) row=(height<<3)-1-row; // Flip Y @@ -848,11 +910,13 @@ static void DrawSpritesSHi(unsigned char *sprited) for (; width; width--,sx+=8,tile+=delta) { + unsigned int pack; + if(sx<=0) continue; if(sx>=328) break; // Offscreen - tile&=0x7fff; // Clip tile address - fTileFunc(sx,tile,pal); + pack = *(unsigned int *)(Pico.vram + (tile & 0x7fff)); + fTileFunc(sx, pack, pal); } } } @@ -860,14 +924,14 @@ static void DrawSpritesSHi(unsigned char *sprited) static void DrawSpritesHiAS(unsigned char *sprited, int sh) { - int (*fTileFunc)(int sx,int addr,int pal); + void (*fTileFunc)(int sx, unsigned int pack, int pal); unsigned char *p; int entry, cnt, sh_cnt = 0; cnt = sprited[0] & 0x7f; if (cnt == 0) return; - rendstatus |= PDRAW_SPR_LO_ON_HI; + Pico.est.rendstatus |= PDRAW_SPR_LO_ON_HI; p = &sprited[3]; @@ -906,7 +970,7 @@ static void DrawSpritesHiAS(unsigned char *sprited, int sh) height=(sy>>24)&7; // Width and height in tiles sy=(sy<<16)>>16; // Y - row=DrawScanline-sy; // Row of the sprite we are on + row=Pico.est.DrawScanline-sy; // Row of the sprite we are on if (code&0x1000) row=(height<<3)-1-row; // Flip Y @@ -920,11 +984,13 @@ static void DrawSpritesHiAS(unsigned char *sprited, int sh) pal |= 0x80; for (; width; width--,sx+=8,tile+=delta) { + unsigned int pack; + if(sx<=0) continue; if(sx>=328) break; // Offscreen - tile&=0x7fff; // Clip tile address - fTileFunc(sx,tile,pal); + pack = *(unsigned int *)(Pico.vram + (tile & 0x7fff)); + fTileFunc(sx, pack, pal); } } @@ -932,7 +998,7 @@ static void DrawSpritesHiAS(unsigned char *sprited, int sh) /* nasty 1: remove 'sprite' flags */ { - int c = 320/4/4, *zb = (int *)(HighCol+8); + int c = 320/4/4, *zb = (int *)(Pico.est.HighCol+8); while (c--) { *zb++ &= 0x7f7f7f7f; *zb++ &= 0x7f7f7f7f; @@ -942,7 +1008,7 @@ static void DrawSpritesHiAS(unsigned char *sprited, int sh) /* nasty 2: sh operator pass */ sprited[0] = sh_cnt; - DrawSpritesSHi(sprited); + DrawSpritesSHi(sprited, &Pico.est); } @@ -952,9 +1018,10 @@ static void DrawSpritesHiAS(unsigned char *sprited, int sh) // Index + 0 : hhhhvvvv ----hhvv yyyyyyyy yyyyyyyy // v, h: vert./horiz. size // Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8 -void PrepareSprites(int full) +static NOINLINE void PrepareSprites(int full) { - struct PicoVideo *pvid=&Pico.video; + const struct PicoVideo *pvid=&Pico.video; + const struct PicoEState *est=&Pico.est; int u,link=0,sh; int table=0; int *pd = HighPreSpr; @@ -991,10 +1058,11 @@ void PrepareSprites(int full) sy = (pack << 16) >> 16; height = (pack >> 24) & 0xf; - if (sy < max_lines && sy + (height<<3) > DrawScanline && // sprite onscreen (y)? + if (sy < max_lines && + sy + (height<<3) > est->DrawScanline && // sprite onscreen (y)? (sx > -24 || sx < max_width)) // onscreen x { - int y = (sy >= DrawScanline) ? sy : DrawScanline; + int y = (sy >= est->DrawScanline) ? sy : est->DrawScanline; int entry = ((pd - HighPreSpr) / 2) | ((code2>>8)&0x80); for (; y < sy + (height<<3) && y < max_lines; y++) { @@ -1047,7 +1115,7 @@ found:; sx = (code2>>16)&0x1ff; sx -= 0x78; // Get X coordinate + 8 - if (sy < max_lines && sy + (height<<3) > DrawScanline) // sprite onscreen (y)? + if (sy < max_lines && sy + (height<<3) > est->DrawScanline) // sprite onscreen (y)? { int entry, y, sx_min, onscr_x, maybe_op = 0; @@ -1057,7 +1125,7 @@ found:; maybe_op = SPRL_MAY_HAVE_OP; entry = ((pd - HighPreSpr) / 2) | ((code2>>8)&0x80); - y = (sy >= DrawScanline) ? sy : DrawScanline; + y = (sy >= est->DrawScanline) ? sy : est->DrawScanline; for (; y < sy + (height<<3) && y < max_lines; y++) { unsigned char *p = &HighLnSpr[y][0]; @@ -1110,18 +1178,12 @@ found:; } #ifndef _ASM_DRAW_C -static void DrawAllSprites(unsigned char *sprited, int prio, int sh) +static void DrawAllSprites(unsigned char *sprited, int prio, int sh, + struct PicoEState *est) { - int rs = rendstatus; unsigned char *p; int cnt; - if (rs & (PDRAW_SPRITES_MOVED|PDRAW_DIRTY_SPRITES)) { - //elprintf(EL_STATUS, "PrepareSprites(%i)", (rs>>4)&1); - PrepareSprites(rs & PDRAW_DIRTY_SPRITES); - rendstatus = rs & ~(PDRAW_SPRITES_MOVED|PDRAW_DIRTY_SPRITES); - } - cnt = sprited[0] & 0x7f; if (cnt == 0) return; @@ -1140,7 +1202,7 @@ static void DrawAllSprites(unsigned char *sprited, int prio, int sh) // -------------------------------------------- -static void BackFill(int reg7, int sh) +void BackFill(int reg7, int sh, struct PicoEState *est) { unsigned int back; @@ -1150,93 +1212,60 @@ static void BackFill(int reg7, int sh) back|=back<<8; back|=back<<16; - memset32((int *)(HighCol+8), back, 320/4); + memset32((int *)(est->HighCol+8), back, 320/4); } #endif // -------------------------------------------- -unsigned short HighPal[0x100]; - #ifndef _ASM_DRAW_C -void PicoDoHighPal555(int sh) +void PicoDoHighPal555(int sh, int line, struct PicoEState *est) { - unsigned short *pal=HighPal; - int i, t; + unsigned int *spal, *dpal; + unsigned int t, i; Pico.m.dirtyPal = 0; - { - unsigned int *spal=(void *)Pico.cram; - unsigned int *dpal=(void *)HighPal; - for (i = 0x3f/2; i >= 0; i--) + spal = (void *)Pico.cram; + dpal = (void *)est->HighPal; + + for (i = 0; i < 0x40 / 2; i++) { + t = spal[i]; #ifdef USE_BGR555 - dpal[i] = ((spal[i]&0x000f000f)<< 1)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)<<4); + t = ((t & 0x000e000e)<< 1) | ((t & 0x00e000e0)<<3) | ((t & 0x0e000e00)<<4); #else - dpal[i] = ((spal[i]&0x000f000f)<<12)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)>>7); + t = ((t & 0x000e000e)<<12) | ((t & 0x00e000e0)<<3) | ((t & 0x0e000e00)>>7); #endif + // treat it like it was 4-bit per channel, since in s/h mode it somewhat is that. + // otherwise intensity difference between this and s/h will be wrong + t |= (t >> 4) & 0x08610861; // 0x18e318e3 + dpal[i] = t; } + // norm: xxx0, sh: 0xxx, hi: 0xxx + 7 if (sh) { // shadowed pixels - for (i = 0x3f; i >= 0; i--) - pal[0x40|i] = pal[0xc0|i] = (unsigned short)((pal[i]>>1)&0x738e); + for (i = 0; i < 0x40 / 2; i++) + dpal[0x40/2 | i] = dpal[0xc0/2 | i] = (dpal[i] >> 1) & 0x738e738e; // hilighted pixels - for (i = 0x3f; i >= 0; i--) { - t=pal[i]&0xe71c;t+=0x4208;if(t&0x20)t|=0x1c;if(t&0x800)t|=0x700;if(t&0x10000)t|=0xe000;t&=0xe71c; - pal[0x80|i]=(unsigned short)t; - } - } -} - -static void FinalizeLineBGR444(int sh) -{ - unsigned short *pd=DrawLineDest; - unsigned char *ps=HighCol+8; - unsigned short *pal=Pico.cram; - int len, i, t, mask=0xff; - - if (Pico.video.reg[12]&1) { - len = 320; - } else { - if(!(PicoOpt&POPT_DIS_32C_BORDER)) pd+=32; - len = 256; - } - - if(sh) { - pal=HighPal; - if(Pico.m.dirtyPal) { - blockcpy(pal, Pico.cram, 0x40*2); - // shadowed pixels - for(i = 0x3f; i >= 0; i--) - pal[0x40|i] = pal[0xc0|i] = (unsigned short)((pal[i]>>1)&0x0777); - // hilighted pixels - for(i = 0x3f; i >= 0; i--) { - t=pal[i]&0xeee;t+=0x444;if(t&0x10)t|=0xe;if(t&0x100)t|=0xe0;if(t&0x1000)t|=0xe00;t&=0xeee; - pal[0x80|i]=(unsigned short)t; - } - Pico.m.dirtyPal = 0; + for (i = 0; i < 0x40 / 2; i++) { + t = ((dpal[i] >> 1) & 0x738e738e) + 0x738e738e; // 0x7bef7bef; + t |= (t >> 4) & 0x08610861; + dpal[0x80/2 | i] = t; } } - - if (!sh && (rendstatus & PDRAW_SPR_LO_ON_HI)) - mask=0x3f; // accurate sprites - - for(i = 0; i < len; i++) - pd[i] = pal[ps[i] & mask]; } - -static void FinalizeLineRGB555(int sh) +void FinalizeLine555(int sh, int line, struct PicoEState *est) { - unsigned short *pd=DrawLineDest; - unsigned char *ps=HighCol+8; - unsigned short *pal=HighPal; + unsigned short *pd=est->DrawLineDest; + unsigned char *ps=est->HighCol+8; + unsigned short *pal=est->HighPal; int len; if (Pico.m.dirtyPal) - PicoDoHighPal555(sh); + PicoDoHighPal555(sh, line, est); if (Pico.video.reg[12]&1) { len = 320; @@ -1248,7 +1277,7 @@ static void FinalizeLineRGB555(int sh) { #ifndef PSP int i, mask=0xff; - if (!sh && (rendstatus & PDRAW_SPR_LO_ON_HI)) + if (!sh && (est->rendstatus & PDRAW_SPR_LO_ON_HI)) mask=0x3f; // accurate sprites, upper bits are priority stuff for (i = 0; i < len; i++) @@ -1256,7 +1285,7 @@ static void FinalizeLineRGB555(int sh) #else extern void amips_clut(unsigned short *dst, unsigned char *src, unsigned short *pal, int count); extern void amips_clut_6bit(unsigned short *dst, unsigned char *src, unsigned short *pal, int count); - if (!sh && (rendstatus & PDRAW_SPR_LO_ON_HI)) + if (!sh && (est->rendstatus & PDRAW_SPR_LO_ON_HI)) amips_clut_6bit(pd, ps, pal, len); else amips_clut(pd, ps, pal, len); #endif @@ -1264,73 +1293,65 @@ static void FinalizeLineRGB555(int sh) } #endif -static void FinalizeLine8bit(int sh) +static void FinalizeLine8bit(int sh, int line, struct PicoEState *est) { - unsigned char *pd=DrawLineDest; - int len, rs = rendstatus; + unsigned char *pd = est->DrawLineDest; + int len, rs = est->rendstatus; static int dirty_count; - if (!sh && Pico.m.dirtyPal == 1 && DrawScanline < 222) + if (!sh && Pico.m.dirtyPal == 1) { // a hack for mid-frame palette changes if (!(rs & PDRAW_SONIC_MODE)) dirty_count = 1; else dirty_count++; rs |= PDRAW_SONIC_MODE; - rendstatus = rs; + est->rendstatus = rs; if (dirty_count == 3) { - blockcpy(HighPal, Pico.cram, 0x40*2); + blockcpy(est->HighPal, Pico.cram, 0x40*2); } else if (dirty_count == 11) { - blockcpy(HighPal+0x40, Pico.cram, 0x40*2); + blockcpy(est->HighPal+0x40, Pico.cram, 0x40*2); } } if (Pico.video.reg[12]&1) { len = 320; } else { - if (!(PicoOpt&POPT_DIS_32C_BORDER)) pd+=32; + if (!(PicoOpt & POPT_DIS_32C_BORDER)) + pd += 32; len = 256; } if (!sh && (rs & PDRAW_SONIC_MODE)) { if (dirty_count >= 11) { - blockcpy_or(pd, HighCol+8, len, 0x80); + blockcpy_or(pd, est->HighCol+8, len, 0x80); } else { - blockcpy_or(pd, HighCol+8, len, 0x40); + blockcpy_or(pd, est->HighCol+8, len, 0x40); } } else { - blockcpy(pd, HighCol+8, len); + blockcpy(pd, est->HighCol+8, len); } } -static void (*FinalizeLine)(int sh) = FinalizeLineBGR444; +static void (*FinalizeLine)(int sh, int line, struct PicoEState *est); // -------------------------------------------- -static void DrawBlankedLine(void) -{ - int sh=(Pico.video.reg[0xC]&8)>>3; // shadow/hilight? - - if (PicoScanBegin != NULL) - PicoScanBegin(DrawScanline); - - BackFill(Pico.video.reg[7], sh); - - if (FinalizeLine != NULL) - FinalizeLine(sh); - - if (PicoScanEnd != NULL) - PicoScanEnd(DrawScanline); -} - static int DrawDisplay(int sh) { - unsigned char *sprited = &HighLnSpr[DrawScanline][0]; + 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; - rendstatus &= ~(PDRAW_SHHI_DONE|PDRAW_PLANE_HI_PRIO); + if (est->rendstatus & (PDRAW_SPRITES_MOVED|PDRAW_DIRTY_SPRITES)) { + // elprintf(EL_STATUS, "PrepareSprites(%i)", (est->rendstatus>>4)&1); + PrepareSprites(est->rendstatus & PDRAW_DIRTY_SPRITES); + est->rendstatus &= ~(PDRAW_SPRITES_MOVED|PDRAW_DIRTY_SPRITES); + } + + est->rendstatus &= ~(PDRAW_SHHI_DONE|PDRAW_PLANE_HI_PRIO); if (pvid->reg[12]&1) { maxw = 328; maxcells = 40; @@ -1342,8 +1363,8 @@ static int DrawDisplay(int sh) win=pvid->reg[0x12]; edge=(win&0x1f)<<3; - if (win&0x80) { if (DrawScanline>=edge) hvwind=1; } - else { if (DrawScanline< edge) hvwind=1; } + if (win&0x80) { if (est->DrawScanline>=edge) hvwind=1; } + else { if (est->DrawScanline< edge) hvwind=1; } if (!hvwind) // we might have a vertical window here { @@ -1360,54 +1381,74 @@ static int DrawDisplay(int sh) } /* - layer B low - */ - if (PicoDrawMask & PDRAW_LAYERB_ON) - DrawLayer(1|(sh<<1), HighCacheB, 0, maxcells); + 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); + 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); - DrawWindow( (win&0x80) ? edge : 0, (win&0x80) ? maxcells>>1 : edge, 0, sh); - } else - DrawLayer(0|(sh<<1), HighCacheA, 0, maxcells); + 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)); - else if (rendstatus & PDRAW_INTERLACE) + 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); + DrawAllSprites(sprited, 0, sh, est); /* - layer B hi - */ - if ((PicoDrawMask & PDRAW_LAYERB_ON) && HighCacheB[0]) - DrawTilesFromCache(HighCacheB, sh, maxw); + 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); + DrawWindow(0, maxcells>>1, 1, sh, est); else if (hvwind == 2) { - if (HighCacheA[0]) DrawTilesFromCache(HighCacheA, sh, (win&0x80) ? edge<<4 : maxw); - DrawWindow((win&0x80) ? edge : 0, (win&0x80) ? maxcells>>1 : edge, 1, sh); + if (HighCacheA[0]) + DrawTilesFromCache(HighCacheA, sh, (win&0x80) ? edge<<4 : maxw, est); + DrawWindow((win&0x80) ? edge : 0, (win&0x80) ? maxcells>>1 : edge, 1, sh, est); } else - if (HighCacheA[0]) DrawTilesFromCache(HighCacheA, sh, maxw); + if (HighCacheA[0]) + DrawTilesFromCache(HighCacheA, sh, maxw, est); /* - sprites hi - */ - if (!(PicoDrawMask & PDRAW_SPRITES_HI_ON)); - else if (rendstatus & PDRAW_INTERLACE) + 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)) DrawSpritesHiAS(sprited, sh); else if (sh && (sprited[1] & SPRL_MAY_HAVE_OP)) - DrawSpritesSHi(sprited); + DrawSpritesSHi(sprited, est); else if (sprited[1] & SPRL_HAVE_HI) - DrawAllSprites(sprited, 1, 0); + 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; for (a = 0, c = HighCacheA; *c; c++, a++); for (b = 0, c = HighCacheB; *c; c++, b++); - printf("%i:%03i: a=%i, b=%i\n", Pico.m.frame_count, DrawScanline, a, b); + printf("%i:%03i: a=%i, b=%i\n", Pico.m.frame_count, + Pico.est.DrawScanline, a, b); } #endif @@ -1417,75 +1458,206 @@ static int DrawDisplay(int sh) // MUST be called every frame PICO_INTERNAL void PicoFrameStart(void) { + int offs = 8, lines = 224; + // prepare to do this frame - rendstatus = 0; - if ((Pico.video.reg[12]&6) == 6) - rendstatus |= PDRAW_INTERLACE; // interlace mode + Pico.est.rendstatus = 0; + if ((Pico.video.reg[12] & 6) == 6) + Pico.est.rendstatus |= PDRAW_INTERLACE; // interlace mode + if (!(Pico.video.reg[12] & 1)) + Pico.est.rendstatus |= PDRAW_32_COLS; + if (Pico.video.reg[1] & 8) { + offs = 0; + lines = 240; + } - if (Pico.m.dirtyPal) Pico.m.dirtyPal = 2; // reset dirty if needed + if (Pico.est.rendstatus != rendstatus_old || lines != rendlines) { + rendlines = lines; + // mode_change() might reset rendstatus_old by calling SetColorFormat + emu_video_mode_change((lines == 240) ? 0 : 8, + lines, (Pico.video.reg[12] & 1) ? 0 : 1); + rendstatus_old = Pico.est.rendstatus; + } - DrawScanline=0; + Pico.est.HighCol = HighColBase + offs * HighColIncrement; + Pico.est.DrawLineDest = (char *)DrawLineDestBase + offs * DrawLineDestIncrement; + Pico.est.DrawScanline = 0; + skip_next_line = 0; + + if (PicoOpt & POPT_ALT_RENDERER) + return; + + if (Pico.m.dirtyPal) + Pico.m.dirtyPal = 2; // reset dirty if needed PrepareSprites(1); - skip_next_line=0; } -static void PicoLine(void) +static void DrawBlankedLine(int line, int offs, int sh, int bgc) { - int sh; - if (skip_next_line>0) { skip_next_line--; return; } // skip rendering lines + if (PicoScanBegin != NULL) + PicoScanBegin(line + offs); - sh=(Pico.video.reg[0xC]&8)>>3; // shadow/hilight? + BackFill(bgc, sh, &Pico.est); + if (FinalizeLine != NULL) + FinalizeLine(sh, line, &Pico.est); + + if (PicoScanEnd != NULL) + PicoScanEnd(line + offs); + + Pico.est.HighCol += HighColIncrement; + Pico.est.DrawLineDest = (char *)Pico.est.DrawLineDest + DrawLineDestIncrement; +} + +static void PicoLine(int line, int offs, int sh, int bgc) +{ + int skip = 0; + + if (skip_next_line > 0) { + skip_next_line--; + return; + } + + Pico.est.DrawScanline = line; if (PicoScanBegin != NULL) - skip_next_line = PicoScanBegin(DrawScanline); + skip = PicoScanBegin(line + offs); + + if (skip) { + skip_next_line = skip - 1; + return; + } + + if (Pico.video.debug_p & (PVD_FORCE_A | PVD_FORCE_B)) + bgc = 0x3f; // Draw screen: - BackFill(Pico.video.reg[7], sh); + BackFill(bgc, sh, &Pico.est); if (Pico.video.reg[1]&0x40) DrawDisplay(sh); if (FinalizeLine != NULL) - FinalizeLine(sh); + FinalizeLine(sh, line, &Pico.est); if (PicoScanEnd != NULL) - skip_next_line = PicoScanEnd(DrawScanline); + skip_next_line = PicoScanEnd(line + offs); + + Pico.est.HighCol += HighColIncrement; + Pico.est.DrawLineDest = (char *)Pico.est.DrawLineDest + DrawLineDestIncrement; } void PicoDrawSync(int to, int blank_last_line) { - for (; DrawScanline < to; DrawScanline++) + int line, offs = 0; + int sh = (Pico.video.reg[0xC] & 8) >> 3; // shadow/hilight? + int bgc = Pico.video.reg[7]; + + pprof_start(draw); + + if (rendlines != 240) + offs = 8; + + for (line = Pico.est.DrawScanline; line < to; line++) { -#if !CAN_HANDLE_240_LINES - if (DrawScanline >= 224) break; -#endif - PicoLine(); + PicoLine(line, offs, sh, bgc); } -#if !CAN_HANDLE_240_LINES - if (DrawScanline >= 224) { DrawScanline = 240; return; } -#endif - // last line - if (DrawScanline <= to) + if (line <= to) { if (blank_last_line) - DrawBlankedLine(); - else PicoLine(); - DrawScanline++; + DrawBlankedLine(line, offs, sh, bgc); + else PicoLine(line, offs, sh, bgc); + line++; } + Pico.est.DrawScanline = line; + + pprof_end(draw); } -void PicoDrawSetColorFormat(int which) +// also works for fast renderer +void PicoDrawUpdateHighPal(void) +{ + struct PicoEState *est = &Pico.est; + int sh = (Pico.video.reg[0xC] & 8) >> 3; // shadow/hilight? + if (PicoOpt & POPT_ALT_RENDERER) + sh = 0; // no s/h support + + PicoDoHighPal555(sh, 0, &Pico.est); + if (est->rendstatus & PDRAW_SONIC_MODE) { + // FIXME? + memcpy(est->HighPal + 0x40, est->HighPal, 0x40*2); + memcpy(est->HighPal + 0x80, est->HighPal, 0x40*2); + } +} + +void PicoDrawSetOutFormat(pdso_t which, int use_32x_line_mode) { switch (which) { - case 2: FinalizeLine = FinalizeLine8bit; break; - case 1: FinalizeLine = FinalizeLineRGB555; break; - case 0: FinalizeLine = FinalizeLineBGR444; break; - default:FinalizeLine = NULL; break; + case PDF_8BIT: + FinalizeLine = FinalizeLine8bit; + break; + + case PDF_RGB555: + if ((PicoAHW & PAHW_32X) && use_32x_line_mode) + FinalizeLine = FinalizeLine32xRGB555; + else + FinalizeLine = FinalizeLine555; + break; + + default: + FinalizeLine = NULL; + break; } -#if OVERRIDE_HIGHCOL - if (which) HighCol=DefHighCol; -#endif + PicoDrawSetOutFormat32x(which, use_32x_line_mode); + PicoDrawSetOutputMode4(which); + rendstatus_old = -1; +} + +// note: may be called on the middle of frame +void PicoDrawSetOutBuf(void *dest, int increment) +{ + DrawLineDestBase = dest; + DrawLineDestIncrement = increment; + Pico.est.DrawLineDest = DrawLineDestBase + Pico.est.DrawScanline * increment; +} + +void PicoDrawSetInternalBuf(void *dest, int increment) +{ + if (dest != NULL) { + HighColBase = dest; + HighColIncrement = increment; + Pico.est.HighCol = HighColBase + Pico.est.DrawScanline * increment; + } + else { + HighColBase = DefHighCol; + HighColIncrement = 0; + } +} + +void PicoDrawSetCallbacks(int (*begin)(unsigned int num), int (*end)(unsigned int num)) +{ + PicoScanBegin = NULL; + PicoScanEnd = NULL; + PicoScan32xBegin = NULL; + PicoScan32xEnd = NULL; + + if ((PicoAHW & PAHW_32X) && FinalizeLine != FinalizeLine32xRGB555) { + PicoScan32xBegin = begin; + PicoScan32xEnd = end; + } + else { + PicoScanBegin = begin; + PicoScanEnd = end; + } +} + +void PicoDrawInit(void) +{ + Pico.est.DrawLineDest = DefOutBuff; + Pico.est.HighCol = HighColBase; + Pico.est.HighPreSpr = HighPreSpr; + rendstatus_old = -1; } +// vim:ts=2:sw=2:expandtab