From db1ee7a2df5570b900a57bb3438eabf9c80eddff Mon Sep 17 00:00:00 2001 From: kub Date: Sun, 28 Jan 2024 19:23:25 +0000 Subject: [PATCH] core, handle background color DMA (arm asm) --- pico/draw.c | 66 +++++++++++++++++++++++++------------------------ pico/draw_arm.S | 10 ++++++-- pico/pico.h | 1 + 3 files changed, 43 insertions(+), 34 deletions(-) diff --git a/pico/draw.c b/pico/draw.c index 40903e74f..3584b6a20 100644 --- a/pico/draw.c +++ b/pico/draw.c @@ -1607,46 +1607,46 @@ static int BgcDMAlen, BgcDMAoffs; static #endif // handle DMA to background color -int BgcDMA(u16 *pd, int len, struct PicoEState *est) +void BgcDMA(struct PicoEState *est) { + u16 *pd=est->DrawLineDest; + int len = (est->Pico->video.reg[12]&1) ? 320 : 256; + // TODO for now handles the line as all background. int xl = (len == 320 ? 38 : 33); // DMA slots during HSYNC int upscale = (est->rendstatus & PDRAW_SOFTSCALE) && len < 320; + u16 *q = upscale ? DefOutBuff : pd; + int i, l = len; + u16 t; - if (BgcDMAlen > 0) { - // BG color DMA under way. TODO for now handles the line as all background. - int i, l = len; - u16 *q = upscale ? DefOutBuff : pd; - u16 t; - - if ((est->rendstatus & PDRAW_BORDER_32) && !upscale) - q += (320-len) / 2; + if ((est->rendstatus & PDRAW_BORDER_32) && !upscale) + q += (320-len) / 2; - BgcDMAlen -= (l>>1)+xl; - if (BgcDMAlen < 0) - // partial line - l += 2*BgcDMAlen; + BgcDMAlen -= ((l-BgcDMAoffs)>>1)+xl; + if (BgcDMAlen <= 0) { + // partial line + l += 2*BgcDMAlen; + est->rendstatus &= ~PDRAW_BGC_DMA; + } - for (i = 0; i < l; i += 2) { - // TODO use ps to overwrite only real bg pixels - t = BgcDMAbase[BgcDMAsrc++ & BgcDMAmask]; - q[i] = q[i+1] = PXCONV(t); - } - BgcDMAsrc += xl; // HSYNC DMA + for (i = BgcDMAoffs; i < l; i += 2) { + // TODO use ps to overwrite only real bg pixels + t = BgcDMAbase[BgcDMAsrc++ & BgcDMAmask]; + q[i] = q[i+1] = PXCONV(t); + } + BgcDMAsrc += xl; // HSYNC DMA + BgcDMAoffs = 0; - t = est->HighPal[Pico.video.reg[7] & 0x3f]; - while (i < len) q[i++] = t; // fill partial line with BG + t = est->HighPal[Pico.video.reg[7] & 0x3f]; + while (i < len) q[i++] = t; // fill partial line with BG - if (upscale) { - switch (PicoIn.filter) { - case 3: h_upscale_bl4_4_5(pd, 320, q, 256, len, f_nop); break; - case 2: h_upscale_bl2_4_5(pd, 320, q, 256, len, f_nop); break; - case 1: h_upscale_snn_4_5(pd, 320, q, 256, len, f_nop); break; - default: h_upscale_nn_4_5(pd, 320, q, 256, len, f_nop); break; - } + if (upscale) { + switch (PicoIn.filter) { + case 3: h_upscale_bl4_4_5(pd, 320, q, 256, len, f_nop); break; + case 2: h_upscale_bl2_4_5(pd, 320, q, 256, len, f_nop); break; + case 1: h_upscale_snn_4_5(pd, 320, q, 256, len, f_nop); break; + default: h_upscale_nn_4_5(pd, 320, q, 256, len, f_nop); break; } - return 1; } - return 0; } // -------------------------------------------- @@ -1747,8 +1747,8 @@ void FinalizeLine555(int sh, int line, struct PicoEState *est) else if ((PicoIn.AHW & PAHW_SMS) && (est->Pico->video.reg[0] & 0x20)) len -= 8, ps += 8; - if (BgcDMA(pd, len, est)) - return; + if (est->rendstatus & PDRAW_BGC_DMA) + return BgcDMA(est); if ((est->rendstatus & PDRAW_SOFTSCALE) && len < 320) { if (len >= 240 && len <= 256) { @@ -2193,6 +2193,8 @@ void PicoDrawBgcDMA(u16 *base, u32 source, u32 mask, int dlen, int sl) BgcDMAlen -= (len>>1)+xl; BgcDMAoffs = 0; } + if (BgcDMAlen > 0) + est->rendstatus |= PDRAW_BGC_DMA; } // also works for fast renderer diff --git a/pico/draw_arm.S b/pico/draw_arm.S index e3ef3e281..05f8ba3de 100644 --- a/pico/draw_arm.S +++ b/pico/draw_arm.S @@ -20,6 +20,7 @@ .equ PDRAW_SHHI_DONE, (1<<7) .equ PDRAW_BORDER_32, (1<<9) .equ PDRAW_32X_SCALE, (1<<12) +.equ PDRAW_BGC_DMA, (1<<14) .equ PDRAW_SOFTSCALE, (1<<15) @ helpers @@ -1632,10 +1633,16 @@ PicoDoHighPal555_end: FinalizeLine555: stmfd sp!, {r4-r11,lr} mov r11,r2 @ est - ldr r8, [r11, #OFS_EST_Pico] + ldr r4, [r11, #OFS_EST_rendstatus] bl PicoDrawUpdateHighPal + tst r4, #PDRAW_BGC_DMA + movne r0, r11 + ldmnefd sp!, {r4-r11,lr} + bne BgcDMA + + ldr r8, [r11, #OFS_EST_Pico] add r3, r11, #OFS_EST_HighPal mov lr, #0xff @@ -1644,7 +1651,6 @@ FinalizeLine555: ldr r5, [r11, #OFS_EST_PicoOpt] ldr r1, [r11, #OFS_EST_HighCol] ldr r0, [r11, #OFS_EST_DrawLineDest] - ldr r4, [r11, #OFS_EST_rendstatus] ldr r7, [r5, #OFS_PicoIn_AHW-OFS_PicoIn_opt] ldrb r12,[r8, #OFS_Pico_video_reg+12] ldrb r6, [r8, #OFS_Pico_video_reg+0] diff --git a/pico/pico.h b/pico/pico.h index 2db502d5b..6759f73d6 100644 --- a/pico/pico.h +++ b/pico/pico.h @@ -235,6 +235,7 @@ void PicoDoHighPal555(int sh, int line, struct PicoEState *est); #define PDRAW_30_ROWS (1<<11) // 30 rows mode (240 lines) #define PDRAW_32X_SCALE (1<<12) // scale CLUT layer for 32X #define PDRAW_SMS_BLANK_1 (1<<13) // 1st column blanked +#define PDRAW_BGC_DMA (1<<14) // in background color DMA #define PDRAW_SOFTSCALE (1<<15) // H32 upscaling #define PDRAW_SYNC_NEEDED (1<<16) // redraw needed #define PDRAW_SYNC_NEXT (1<<17) // redraw next frame