X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FDraw.c;h=15d09927f088451ef15a56aa3a30fa68f391b131;hb=6a13ef3f56a80ac698d463f5d00235ea2a090f52;hp=f20af59fe7ec2c0780d6a808a6b3edef96b5e815;hpb=fbc65db75502192750f19f5cc8c5543aef625cb1;p=picodrive.git diff --git a/Pico/Draw.c b/Pico/Draw.c index f20af59..15d0992 100644 --- a/Pico/Draw.c +++ b/Pico/Draw.c @@ -36,7 +36,6 @@ static int HighCacheA[41+1]; // caches for high layers static int HighCacheB[41+1]; int HighPreSpr[80*2+1]; // slightly preprocessed sprites -#define MAX_LINE_SPRITES 29 #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 @@ -65,9 +64,9 @@ struct TileStrip #ifdef _ASM_DRAW_C void DrawWindow(int tstart, int tend, int prio, int sh); void BackFill(int reg7, int sh); -void DrawAllSprites(int prio, int sh); +void DrawAllSprites(unsigned char *sprited, int prio, int sh); void DrawTilesFromCache(int *hc, int sh, int rlim); -void DrawSpritesSHi(unsigned short *sprited); +void DrawSpritesSHi(unsigned char *sprited); void DrawLayer(int plane_sh, int *hcache, int cellskip, int maxcells); void FinalizeLineBGR444(int sh); void FinalizeLineRGB555(int sh); @@ -840,7 +839,7 @@ static void DrawSpritesSHi(unsigned char *sprited) } } } -#endif +#endif // !_ASM_DRAW_C static void DrawSpritesHiAS(unsigned char *sprited, int sh) { @@ -851,6 +850,8 @@ static void DrawSpritesHiAS(unsigned char *sprited, int sh) cnt = sprited[0] & 0x7f; if (cnt == 0) return; + rendstatus |= PDRAW_SPR_LO_ON_HI; + p = &sprited[3]; // Go through sprites: @@ -958,7 +959,7 @@ void PrepareSprites(int full) { int pack; // updates: tilecode, sx - for (u=0; u < max_lines && (pack = *pd); u++, pd+=2) + for (u=0; u < max_sprites && (pack = *pd); u++, pd+=2) { unsigned int *sprite; int code2, sx, sy, height; @@ -1007,12 +1008,10 @@ found:; } else { - int old_prio = 0x8000, lo_above_hi = 0; - for (u = 0; u < max_lines; u++) *((int *)&HighLnSpr[u][0]) = 0; - for (u = 0; u < max_lines; u++) + for (u = 0; u < max_sprites; u++) { unsigned int *sprite; int code, code2, sx, sy, hv, height, width; @@ -1039,37 +1038,34 @@ found:; if (sh && (code2 & 0x6000) == 0x6000) maybe_op = SPRL_MAY_HAVE_OP; - if (onscr_x && !old_prio && (code2 & 0x8000)) - lo_above_hi = SPRL_LO_ABOVE_HI; - old_prio = code2 & 0x8000; - entry = ((pd - HighPreSpr) / 2) | ((code2>>8)&0x80); y = (sy >= DrawScanline) ? sy : DrawScanline; for (; y < sy + (height<<3) && y < max_lines; y++) { - int cnt = HighLnSpr[y][0]; + unsigned char *p = &HighLnSpr[y][0]; + int cnt = p[0]; if (cnt >= max_line_sprites) continue; // sprite limit? - if (HighLnSpr[y][2] >= max_line_sprites*2) { // tile limit? - HighLnSpr[y][0] |= 0x80; + if (p[2] >= max_line_sprites*2) { // tile limit? + p[0] |= 0x80; continue; } - HighLnSpr[y][2] += width; + p[2] += width; if (sx == -0x78) { if (cnt > 0) - HighLnSpr[y][0] |= 0x80; // masked, no more sprites for this line + p[0] |= 0x80; // masked, no more sprites for this line continue; } // must keep the first sprite even if it's offscreen, for masking if (cnt > 0 && !onscr_x) continue; // offscreen x - HighLnSpr[y][3+cnt] = entry; - HighLnSpr[y][0] = cnt + 1; - if (entry & 0x80) - HighLnSpr[y][1] |= SPRL_HAVE_HI; - else HighLnSpr[y][1] |= SPRL_HAVE_LO; - HighLnSpr[y][1] |= maybe_op|lo_above_hi; // there might be op sprites or priority mess on this line + p[3+cnt] = entry; + p[0] = cnt + 1; + p[1] |= (entry & 0x80) ? SPRL_HAVE_HI : SPRL_HAVE_LO; + p[1] |= maybe_op; // there might be op sprites on this line + if (cnt > 0 && (code2 & 0x8000) && !(p[3+cnt-1]&0x80)) + p[1] |= SPRL_LO_ABOVE_HI; } } @@ -1145,6 +1141,37 @@ static void BackFill(int reg7, int sh) unsigned short HighPal[0x100]; #ifndef _ASM_DRAW_C +void PicoDoHighPal555(int sh) +{ + unsigned short *pal=HighPal; + int i, t; + + Pico.m.dirtyPal = 0; + + { + unsigned int *spal=(void *)Pico.cram; + unsigned int *dpal=(void *)HighPal; + for (i = 0x3f/2; i >= 0; i--) +#ifdef USE_BGR555 + dpal[i] = ((spal[i]&0x000f000f)<< 1)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)<<4); +#else + dpal[i] = ((spal[i]&0x000f000f)<<12)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)>>7); +#endif + } + + if (sh) + { + // shadowed pixels + for (i = 0x3f; i >= 0; i--) + pal[0x40|i] = pal[0xc0|i] = (unsigned short)((pal[i]>>1)&0x738e); + // 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; @@ -1175,7 +1202,7 @@ static void FinalizeLineBGR444(int sh) } } - if (!sh && (rendstatus & PDRAW_ACC_SPRITES)) + if (!sh && (rendstatus & PDRAW_SPR_LO_ON_HI)) mask=0x3f; // accurate sprites for(i = 0; i < len; i++) @@ -1188,34 +1215,10 @@ static void FinalizeLineRGB555(int sh) unsigned short *pd=DrawLineDest; unsigned char *ps=HighCol+8; unsigned short *pal=HighPal; - int len, i, t, dirtyPal = Pico.m.dirtyPal; - - if (dirtyPal) - { - unsigned int *spal=(void *)Pico.cram; - unsigned int *dpal=(void *)HighPal; - for (i = 0x3f/2; i >= 0; i--) -#ifdef USE_BGR555 - dpal[i] = ((spal[i]&0x000f000f)<< 1)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)<<4); -#else - dpal[i] = ((spal[i]&0x000f000f)<<12)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)>>7); -#endif - Pico.m.dirtyPal = 0; - } + int len; - if (sh) - { - if (dirtyPal) { - // shadowed pixels - for (i = 0x3f; i >= 0; i--) - pal[0x40|i] = pal[0xc0|i] = (unsigned short)((pal[i]>>1)&0x738e); - // 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; - } - } - } + if (Pico.m.dirtyPal) + PicoDoHighPal555(sh); if (Pico.video.reg[12]&1) { len = 320; @@ -1226,8 +1229,8 @@ static void FinalizeLineRGB555(int sh) { #ifndef PSP - int mask=0xff; - if (!sh && (rendstatus & PDRAW_ACC_SPRITES)) + int i, mask=0xff; + if (!sh && (rendstatus & PDRAW_SPR_LO_ON_HI)) mask=0x3f; // accurate sprites, upper bits are priority stuff for (i = 0; i < len; i++) @@ -1235,7 +1238,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_ACC_SPRITES)) + if (!sh && (rendstatus & PDRAW_SPR_LO_ON_HI)) amips_clut_6bit(pd, ps, pal, len); else amips_clut(pd, ps, pal, len); #endif @@ -1249,7 +1252,7 @@ static void FinalizeLine8bit(int sh) int len, rs = rendstatus; static int dirty_count; - if (!sh && !(rs & PDRAW_ACC_SPRITES) && Pico.m.dirtyPal == 1 && DrawScanline < 222) + if (!sh && Pico.m.dirtyPal == 1 && DrawScanline < 222) { // a hack for mid-frame palette changes if (!(rs & PDRAW_SONIC_MODE)) @@ -1302,7 +1305,7 @@ static void DrawBlankedLine(void) PicoScanEnd(DrawScanline); } -static int DrawDisplay(int sh, int as) +static int DrawDisplay(int sh) { unsigned char *sprited = &HighLnSpr[DrawScanline][0]; struct PicoVideo *pvid=&Pico.video; @@ -1373,8 +1376,8 @@ static int DrawDisplay(int sh, int as) if (!(PicoDrawMask & PDRAW_SPRITES_HI_ON)); else if (rendstatus & PDRAW_INTERLACE) DrawAllSpritesInterlace(1, sh); - // AS on and have both lo/hi sprites and lo before hi sprites? - else if (as && (sprited[1] & 0xd0) == 0xd0) + // 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); @@ -1393,13 +1396,11 @@ static int DrawDisplay(int sh, int as) return 0; } - +// MUST be called every frame PICO_INTERNAL void PicoFrameStart(void) { // prepare to do this frame rendstatus = 0; - if (PicoOpt & POPT_ACC_SPRITES) - rendstatus |= PDRAW_ACC_SPRITES; if ((Pico.video.reg[12]&6) == 6) rendstatus |= PDRAW_INTERLACE; // interlace mode @@ -1412,25 +1413,24 @@ PICO_INTERNAL void PicoFrameStart(void) static void PicoLine(void) { - int sh, as = 0; + int sh; if (skip_next_line>0) { skip_next_line--; return; } // skip rendering lines sh=(Pico.video.reg[0xC]&8)>>3; // shadow/hilight? - if (rendstatus & PDRAW_ACC_SPRITES) as|=1; // accurate sprites if (PicoScanBegin != NULL) skip_next_line = PicoScanBegin(DrawScanline); // Draw screen: - BackFill(Pico.video.reg[7], sh|as); + BackFill(Pico.video.reg[7], sh); if (Pico.video.reg[1]&0x40) - DrawDisplay(sh, as); + DrawDisplay(sh); if (FinalizeLine != NULL) FinalizeLine(sh); if (PicoScanEnd != NULL) - PicoScanEnd(DrawScanline); + skip_next_line = PicoScanEnd(DrawScanline); } void PicoDrawSync(int to, int blank_last_line) @@ -1444,7 +1444,7 @@ void PicoDrawSync(int to, int blank_last_line) } #if !CAN_HANDLE_240_LINES - if (DrawScanline >= 224) DrawScanline = 240, return; + if (DrawScanline >= 224) { DrawScanline = 240; return; } #endif // last line @@ -1471,87 +1471,3 @@ void PicoDrawSetColorFormat(int which) #endif } -/* debug and fun */ -static void set16(unsigned short *p, unsigned short d, int cnt) -{ - while (cnt-- > 0) - *p++ = d; -} - -void PicoDrawShowSpriteStats(unsigned short *screen) -{ - int lines, i, u, step; - unsigned short *dest; - unsigned char *p; - - memset(screen, 0, 320*240*2); - step = (320-4*4-1) / MAX_LINE_SPRITES; - lines = 240; - if (!Pico.m.pal || !(Pico.video.reg[1]&8)) - lines = 224, screen += 320*8; - - for (i = 0; i < lines; i++) - { - dest = screen + 320*i; - p = &HighLnSpr[i][0]; - - // sprite graphs - for (u = 0; u < (p[0] & 0x7f); u++) { - set16(dest, (p[3+u] & 0x80) ? 0xe700 : 0x0700, step); - dest += step; - } - - // flags - dest = screen + 320*i + 320-4*4; - if (p[1] & SPRL_HAVE_LO) set16(dest+4*0, 0x0700, 4); - if (p[1] & SPRL_HAVE_HI) set16(dest+4*1, 0xe700, 4); - if (p[1] & SPRL_MAY_HAVE_OP) set16(dest+4*2, 0x001e, 4); - if (p[1] & SPRL_LO_ABOVE_HI) set16(dest+4*3, 0xf000, 4); - } - - // draw grid - for (i = step*5; i <= 320-4*4-1; i += step*5) { - for (u = 0; u < lines; u++) - screen[i + u*320] = 0x182; - } -} - -void PicoDrawShowPalette(unsigned short *screen) -{ - unsigned int *spal=(void *)Pico.cram; - unsigned int *dpal=(void *)HighPal; - int x, y, i; - - memset(screen, 0, 320*240*2); - - for (i = 0x3f/2; i >= 0; i--) -#ifdef USE_BGR555 - dpal[i] = ((spal[i]&0x000f000f)<< 1)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)<<4); -#else - dpal[i] = ((spal[i]&0x000f000f)<<12)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)>>7); -#endif - for (i = 0x3f; i >= 0; i--) - HighPal[0x40|i] = (unsigned short)((HighPal[i]>>1)&0x738e); - for (i = 0x3f; i >= 0; i--) { - int t=HighPal[i]&0xe71c;t+=0x4208;if(t&0x20)t|=0x1c;if(t&0x800)t|=0x700;if(t&0x10000)t|=0xe000;t&=0xe71c; - HighPal[0x80|i]=(unsigned short)t; - } - - screen += 16*320+8; - for (y = 0; y < 8*4; y++) - for (x = 0; x < 8*16; x++) - screen[x + y*320] = HighPal[x/8 + (y/8)*16]; - - screen += 160; - for (y = 0; y < 8*4; y++) - for (x = 0; x < 8*16; x++) - screen[x + y*320] = HighPal[(x/8 + (y/8)*16) | 0x40]; - - screen += 320*48; - for (y = 0; y < 8*4; y++) - for (x = 0; x < 8*16; x++) - screen[x + y*320] = HighPal[(x/8 + (y/8)*16) | 0x80]; - - Pico.m.dirtyPal = 1; -} -