aboutsummaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--src/common.h4
-rw-r--r--src/ppu.c54
-rw-r--r--src/ppu.h6
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
419inline void 419inline void
420dma_copy(void *dst, const void *src, u32 size, int channel) { 420dma_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.
425inline void 427inline void
426dma_fill(void *dst, vu32 src, u32 size, int channel) { 428dma_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//
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 {
diff --git a/src/ppu.h b/src/ppu.h
index f12e1a7..bd9120c 100644
--- a/src/ppu.h
+++ b/src/ppu.h
@@ -17,12 +17,6 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
17WITH REGARD TO THIS SOFTWARE. 17WITH REGARD TO THIS SOFTWARE.
18*/ 18*/
19 19
20typedef struct Ppu {
21 u32 *bg, *fg;
22 u16 hor, ver, width, height;
23} Ppu;
24
25int initppu(Ppu *p, u8 hor, u8 ver);
26void putcolors(u8 *addr); 20void putcolors(u8 *addr);
27void ppu_pixel(u32 *layer, u16 x, u16 y, u8 color); 21void ppu_pixel(u32 *layer, u16 x, u16 y, u8 color);
28void ppu_1bpp(u32 *layer, u16 x, u16 y, u8 *sprite, u8 color, u8 flipx, u8 flipy); 22void ppu_1bpp(u32 *layer, u16 x, u16 y, u8 *sprite, u8 color, u8 flipx, u8 flipy);