Skip to content

Commit

Permalink
core, handle background color DMA (arm asm)
Browse files Browse the repository at this point in the history
  • Loading branch information
irixxxx committed Jan 28, 2024
1 parent 492c47c commit 41fcf43
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 34 deletions.
66 changes: 34 additions & 32 deletions pico/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

// --------------------------------------------
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions pico/draw_arm.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1632,10 +1633,16 @@ PicoDoHighPal555_end:
FinalizeLine555:
stmfd sp!, {r4-r11,lr}
mov r11,r2 @ est
ldr r8, [r11, #OFS_EST_Pico]

bl PicoDrawUpdateHighPal

ldr r4, [r11, #OFS_EST_rendstatus]
mov r0, r11
tst r4, #PDRAW_BGC_DMA
ldmnefd sp!, {r4-r11,lr}
bne BgcDMA

ldr r8, [r11, #OFS_EST_Pico]
add r3, r11, #OFS_EST_HighPal

mov lr, #0xff
Expand All @@ -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]
Expand Down
1 change: 1 addition & 0 deletions pico/pico.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 41fcf43

Please sign in to comment.