X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fdraw.c;h=5094e5cda9c9c5fd756f8f4694d77879971d3a4f;hb=a2b8c5a54568093b247ced39f0754cbb30324830;hp=c432bd57fc1a5ef0fa4aa88d9ac8e833b986b516;hpb=ae87bffa0696eeb18ffb8d283992bc3881e8f241;p=picodrive.git diff --git a/pico/draw.c b/pico/draw.c index c432bd5..5094e5c 100644 --- a/pico/draw.c +++ b/pico/draw.c @@ -34,14 +34,15 @@ 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 char *HighCol = DefHighCol; +static unsigned char *HighColBase = DefHighCol; +static int HighColIncrement; + static unsigned int DefOutBuff[320*2/2]; -void *DrawLineDest=DefOutBuff; // pointer to dest buffer where to draw this line to +void *DrawLineDest = DefOutBuff; // pointer to dest buffer where to draw this line to +void *DrawLineDestBase = DefOutBuff; +int DrawLineDestIncrement; static int HighCacheA[41+1]; // caches for high layers static int HighCacheB[41+1]; @@ -1193,6 +1194,7 @@ void PicoDoHighPal555(int sh) } } +#if 0 static void FinalizeLineBGR444(int sh, int line) { unsigned short *pd=DrawLineDest; @@ -1229,9 +1231,10 @@ static void FinalizeLineBGR444(int sh, int line) for(i = 0; i < len; i++) pd[i] = pal[ps[i] & mask]; } +#endif -void FinalizeLineRGB555(int sh, int line) +void FinalizeLine555(int sh, int line) { unsigned short *pd=DrawLineDest; unsigned char *ps=HighCol+8; @@ -1405,7 +1408,7 @@ static int DrawDisplay(int sh) // MUST be called every frame PICO_INTERNAL void PicoFrameStart(void) { - int lines = 224; + int offs = 8, lines = 224; // prepare to do this frame rendstatus = 0; @@ -1413,17 +1416,22 @@ PICO_INTERNAL void PicoFrameStart(void) rendstatus |= PDRAW_INTERLACE; // interlace mode if (!(Pico.video.reg[12] & 1)) rendstatus |= PDRAW_32_COLS; - if (Pico.video.reg[1] & 8) + if (Pico.video.reg[1] & 8) { + offs = 0; lines = 240; + } + HighCol = HighColBase + offs * HighColIncrement; + DrawLineDest = (char *)DrawLineDestBase + offs * DrawLineDestIncrement; DrawScanline = 0; skip_next_line = 0; if (rendstatus != rendstatus_old || lines != rendlines) { rendlines = lines; - rendstatus_old = rendstatus; + // 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 = rendstatus; } if (PicoOpt & POPT_ALT_RENDERER) @@ -1476,6 +1484,9 @@ static void PicoLine(int line, int offs, int sh, int bgc) if (PicoScanEnd != NULL) skip_next_line = PicoScanEnd(line + offs); + + HighCol += HighColIncrement; + DrawLineDest = (char *)DrawLineDest + DrawLineDestIncrement; } void PicoDrawSync(int to, int blank_last_line) @@ -1484,13 +1495,11 @@ void PicoDrawSync(int to, int blank_last_line) int sh = (Pico.video.reg[0xC] & 8) >> 3; // shadow/hilight? int bgc = Pico.video.reg[7]; + pprof_start(draw); + if (rendlines != 240) offs = 8; - // need to know which pixels are bg for 32x - if (PicoAHW & PAHW_32X) - bgc = 0; - for (line = DrawScanline; line < to; line++) { #if !CAN_HANDLE_240_LINES @@ -1515,21 +1524,66 @@ void PicoDrawSync(int to, int blank_last_line) line++; } DrawScanline = line; + + pprof_end(draw); +} + +// also works for fast renderer +void PicoDrawUpdateHighPal(void) +{ + int sh = (Pico.video.reg[0xC] & 8) >> 3; // shadow/hilight? + if (PicoOpt & POPT_ALT_RENDERER) + sh = 0; // no s/h support + + PicoDoHighPal555(sh); + if (rendstatus & PDRAW_SONIC_MODE) { + // FIXME? + memcpy(HighPal + 0x40, HighPal, 0x40*2); + memcpy(HighPal + 0x80, HighPal, 0x40*2); + } } -void PicoDrawSetColorFormat(int which) +void PicoDrawSetOutFormat(pdso_t which, int allow_32x) { switch (which) { - case 2: FinalizeLine = FinalizeLine8bit; break; - case 1: FinalizeLine = (PicoAHW & PAHW_32X) ? FinalizeLine32xRGB555 : FinalizeLineRGB555; break; - case 0: FinalizeLine = FinalizeLineBGR444; break; - default:FinalizeLine = NULL; break; + case PDF_8BIT: + FinalizeLine = FinalizeLine8bit; + break; + + case PDF_RGB555: + if ((PicoAHW & PAHW_32X) && allow_32x) + FinalizeLine = FinalizeLine32xRGB555; + else + FinalizeLine = FinalizeLine555; + break; + + default: + FinalizeLine = NULL; + break; + } + PicoDrawSetOutputMode4(which); + rendstatus_old = -1; +} + +// note: may be called on the middle of frame +void PicoDrawSetOutBuf(void *dest, int increment) +{ + DrawLineDestBase = dest; + DrawLineDestIncrement = increment; + DrawLineDest = DrawLineDestBase + DrawScanline * increment; +} + +void PicoDrawSetInternalBuf(void *dest, int increment) +{ + if (dest != NULL) { + HighColBase = dest; + HighColIncrement = increment; + HighCol = HighColBase + DrawScanline * increment; + } + else { + HighColBase = DefHighCol; + HighColIncrement = 0; } - PicoDrawSetColorFormatMode4(which); -#if OVERRIDE_HIGHCOL - if (which) - HighCol=DefHighCol; -#endif }