diff options
author | Bad Diode <bd@badd10de.dev> | 2023-04-20 11:37:34 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2023-04-20 11:37:34 +0200 |
commit | 773cd197a323d2f9b701addd63e30d54e43c74f5 (patch) | |
tree | a50a76dfd6111af296cddab1c407f1c4f1ae6128 | |
parent | 1d1e1123f8b76c40ba57427367f34b6f5c61de85 (diff) | |
download | uxngba-773cd197a323d2f9b701addd63e30d54e43c74f5.tar.gz uxngba-773cd197a323d2f9b701addd63e30d54e43c74f5.zip |
Add optional DMA usage on flipbuf
This will copy an entire row of tiles instead of per tile copy, but for
applications that clear the screen on each frame it will be more
efficient.
-rw-r--r-- | src/common.h | 4 | ||||
-rw-r--r-- | src/ppu.c | 54 | ||||
-rw-r--r-- | src/ppu.h | 6 |
3 files changed, 32 insertions, 32 deletions
diff --git a/src/common.h b/src/common.h index e62c78c..1fbfa4c 100644 --- a/src/common.h +++ b/src/common.h | |||
@@ -419,12 +419,16 @@ dma_transfer_fill(void *dst, volatile u32 src, u32 count, int channel, u32 optio | |||
419 | inline void | 419 | inline void |
420 | dma_copy(void *dst, const void *src, u32 size, int channel) { | 420 | dma_copy(void *dst, const void *src, u32 size, int channel) { |
421 | dma_transfer_copy(dst, src, size / 4, channel, DMA_CHUNK_32 | DMA_ENABLE); | 421 | dma_transfer_copy(dst, src, size / 4, channel, DMA_CHUNK_32 | DMA_ENABLE); |
422 | // Stall for 2 cycles in case we call this function more than once. | ||
423 | asm("nop"); asm("nop"); | ||
422 | } | 424 | } |
423 | 425 | ||
424 | // Fill the dst location with the word set at src. | 426 | // Fill the dst location with the word set at src. |
425 | inline void | 427 | inline void |
426 | dma_fill(void *dst, vu32 src, u32 size, int channel) { | 428 | dma_fill(void *dst, vu32 src, u32 size, int channel) { |
427 | dma_transfer_fill(dst, src, size / 4, channel, DMA_CHUNK_32 | DMA_ENABLE); | 429 | dma_transfer_fill(dst, src, size / 4, channel, DMA_CHUNK_32 | DMA_ENABLE); |
430 | // Stall for 2 cycles in case we call this function more than once. | ||
431 | asm("nop"); asm("nop"); | ||
428 | } | 432 | } |
429 | 433 | ||
430 | // | 434 | // |
@@ -16,6 +16,7 @@ WITH REGARD TO THIS SOFTWARE. | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | #define NEW_PPU 1 | 18 | #define NEW_PPU 1 |
19 | #define FLIPBUF_DMA 1 | ||
19 | 20 | ||
20 | #define FG_FRONT ((u32*)(MEM_VRAM)) | 21 | #define FG_FRONT ((u32*)(MEM_VRAM)) |
21 | #define BG_FRONT ((u32*)(MEM_VRAM + KB(20))) | 22 | #define BG_FRONT ((u32*)(MEM_VRAM + KB(20))) |
@@ -722,32 +723,33 @@ putfontchar(u32 *layer, u16 tile_x, u16 tile_y, u8 ch, u8 color) { | |||
722 | IWRAM_CODE | 723 | IWRAM_CODE |
723 | void | 724 | void |
724 | flipbuf() { | 725 | flipbuf() { |
725 | // Copy the fg and bg layers fully with the DMA. | 726 | u32 *fg_back = FG_BACK; |
726 | dma_copy((u32*)FG_FRONT, (u32*)FG_BACK, KB(40), 3); | 727 | u32 *bg_back = BG_BACK; |
727 | // dma_sync_copy((u32*)FG_FRONT, (u32*)FG_BACK, KB(40)); | 728 | u32 *bg_front = BG_FRONT; |
728 | // | 729 | u32 *fg_front = FG_FRONT; |
729 | // TODO: dma the dirty lines instead of per tile copying. | 730 | for (size_t j = 0; j < 20; ++j) { |
730 | // dma_copy((u32*)BG_FRONT, (u32*)BG_BACK, KB(20), 3); | 731 | if (dirty_tiles[j] == 0) { |
731 | // dma_sync_copy((u32*)FG_FRONT, (u32*)FG_BACK, KB(20)); | 732 | continue; |
732 | // dma_sync_copy((u32*)BG_FRONT, (u32*)BG_BACK, KB(20)); | 733 | } |
733 | // Tile *mem_fg = FG_FRONT; | 734 | #if FLIPBUF_DMA == 1 |
734 | // Tile *mem_bg = BG_FRONT; | 735 | u32 offset = j * 32 * 8; |
735 | // for (size_t j = 0; j < 20; ++j) { | 736 | dma_copy(fg_front + offset, fg_back + offset, 32 * 8 * 4, 3); |
736 | // if (dirty_tiles[j] == 0) { | 737 | dma_copy(bg_front + offset, bg_back + offset, 32 * 8 * 4, 3); |
737 | // continue; | 738 | #else |
738 | // } | 739 | size_t k = 1; |
739 | 740 | for (size_t i = 0; i < 30; ++i, k <<= 1) { | |
740 | // // size_t k = 1; | 741 | if (dirty_tiles[j] & k) { |
741 | // // for (size_t i = 0; i < 30; ++i, k <<= 1) { | 742 | Tile *mem_fg = FG_FRONT; |
742 | // // if (dirty_tiles[j] & k) { | 743 | Tile *mem_bg = BG_FRONT; |
743 | // // Tile *tile_fg = FG_BACK; | 744 | Tile *tile_fg = FG_BACK; |
744 | // // Tile *tile_bg = BG_BACK; | 745 | Tile *tile_bg = BG_BACK; |
745 | // // mem_fg[i + j * 32] = tile_fg[i + j * 32]; | 746 | mem_fg[i + j * 32] = tile_fg[i + j * 32]; |
746 | // // mem_bg[i + j * 32] = tile_bg[i + j * 32]; | 747 | mem_bg[i + j * 32] = tile_bg[i + j * 32]; |
747 | // // } | 748 | } |
748 | // // } | 749 | } |
749 | // dirty_tiles[j] = 0; | 750 | #endif |
750 | // } | 751 | dirty_tiles[j] = 0; |
752 | } | ||
751 | } | 753 | } |
752 | 754 | ||
753 | typedef struct KeyboardChar { | 755 | typedef struct KeyboardChar { |
@@ -17,12 +17,6 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |||
17 | WITH REGARD TO THIS SOFTWARE. | 17 | WITH REGARD TO THIS SOFTWARE. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | typedef struct Ppu { | ||
21 | u32 *bg, *fg; | ||
22 | u16 hor, ver, width, height; | ||
23 | } Ppu; | ||
24 | |||
25 | int initppu(Ppu *p, u8 hor, u8 ver); | ||
26 | void putcolors(u8 *addr); | 20 | void putcolors(u8 *addr); |
27 | void ppu_pixel(u32 *layer, u16 x, u16 y, u8 color); | 21 | void ppu_pixel(u32 *layer, u16 x, u16 y, u8 color); |
28 | void ppu_1bpp(u32 *layer, u16 x, u16 y, u8 *sprite, u8 color, u8 flipx, u8 flipy); | 22 | void ppu_1bpp(u32 *layer, u16 x, u16 y, u8 *sprite, u8 color, u8 flipx, u8 flipy); |