From 431b35d85fa590d199acadbeaf638711eb10c6af Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Thu, 20 May 2021 23:02:34 +0200 Subject: Apply asie's patch 4 for performance modifications This patch removes the need for a backbuffer on EWRAM and instead store them on the VRAM. --- src/uxn/devices/ppu.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/uxn/devices/ppu.c b/src/uxn/devices/ppu.c index 97b5e4f..61e4d26 100644 --- a/src/uxn/devices/ppu.c +++ b/src/uxn/devices/ppu.c @@ -142,10 +142,6 @@ static Uint32 unpack_icon_lut_flipx[256] = { 0x11111111 }; -EWRAM_BSS -static u32 *backbuffer_bg0[32 * 20 * sizeof(Tile) / 4]; -EWRAM_BSS -static u32 *backbuffer_bg1[32 * 20 * sizeof(Tile) / 4]; static u32 dirty_tiles[20] = {0}; void @@ -194,13 +190,13 @@ puticn(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Ui if (flipy) flipy = 7; - if (x >= 240 || y >= 160) return; + if (x >= SCREEN_WIDTH || y >= SCREEN_HEIGHT) return; if (color != 0x05 && color != 0x0a && color != 0x0f) { u64 mask = ~((u64)0xFFFFFFFF << shift); for (v = 0; v < 8; v++, layerptr++) { - if ((y + v) >= 160) break; + if ((y + v) >= SCREEN_HEIGHT) break; sprline = sprite[v ^ flipy]; u64 data = (u64)(lut_expand[sprline] * (color & 3)) << shift; @@ -213,7 +209,7 @@ puticn(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Ui } } else { for (v = 0; v < 8; v++, layerptr++) { - if ((y + v) >= 160) break; + if ((y + v) >= SCREEN_HEIGHT) break; sprline = sprite[v ^ flipy]; u64 mask = ~((u64)(lut_expand[sprline] * 0xF) << shift); @@ -246,13 +242,13 @@ putchr(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, if (flipy) flipy = 7; - if (x >= 240 || y >= 160) return; + if (x >= SCREEN_WIDTH || y >= SCREEN_HEIGHT) return; u64 mask = ~((u64)0xFFFFFFFF << shift); u32 colconst = (color >> 2) * 0x11111111; for (v = 0; v < 8; v++, layerptr++) { - if ((y + v) >= 160) break; + if ((y + v) >= SCREEN_HEIGHT) break; sprline1 = sprite[v ^ flipy]; sprline2 = sprite[(v ^ flipy) | 8]; @@ -315,13 +311,27 @@ initppu(Ppu *p, Uint8 hor, Uint8 ver, Uint8 pad) { BG_CTRL(1) = BG_CHARBLOCK(cb_bg) | BG_SCREENBLOCK(sb_idx) | BG_PRIORITY(2); // Clear tile memory. - p->fg = backbuffer_bg0; - p->bg = backbuffer_bg1; for (size_t i = 0; i < 32 * 20 * 8; ++i) { p->fg[i] = 0; p->bg[i] = 0; } + // Use DMA to clear VRAM. + u32 fill = 0; + u32 tile_clear_ctrl = (32 * 20 * 8) | DMA_DST_INC | DMA_SRC_FIXED | DMA_NOW | DMA_CHUNK_32 | DMA_ENABLE; + DMA_SRC(3) = &fill; + DMA_DST(3) = p->fg; + DMA_CTRL(3) = tile_clear_ctrl; + DMA_DST(3) = p->bg; + DMA_CTRL(3) = tile_clear_ctrl; + + p->fg = (u32*) (MEM_VRAM + (56 * 1024)); + p->bg = (u32*) (MEM_VRAM + (76 * 1024)); + DMA_DST(3) = p->fg; + DMA_CTRL(3) = tile_clear_ctrl; + DMA_DST(3) = p->bg; + DMA_CTRL(3) = tile_clear_ctrl; + // Initialize default palette. PAL_BUFFER_BG[0] = COLOR_BLACK; PAL_BUFFER_BG[1] = COLOR_WHITE; -- cgit v1.2.1