aboutsummaryrefslogtreecommitdiffstats
path: root/src/ppu.c
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2023-04-20 11:37:34 +0200
committerBad Diode <bd@badd10de.dev>2023-04-20 11:37:34 +0200
commit773cd197a323d2f9b701addd63e30d54e43c74f5 (patch)
treea50a76dfd6111af296cddab1c407f1c4f1ae6128 /src/ppu.c
parent1d1e1123f8b76c40ba57427367f34b6f5c61de85 (diff)
downloaduxngba-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.
Diffstat (limited to 'src/ppu.c')
-rw-r--r--src/ppu.c54
1 files changed, 28 insertions, 26 deletions
diff --git a/src/ppu.c b/src/ppu.c
index d68ab8f..bc6f503 100644
--- a/src/ppu.c
+++ b/src/ppu.c
@@ -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) {
722IWRAM_CODE 723IWRAM_CODE
723void 724void
724flipbuf() { 725flipbuf() {
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
753typedef struct KeyboardChar { 755typedef struct KeyboardChar {