diff options
author | Bad Diode <bd@badd10de.dev> | 2023-04-22 13:41:10 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2023-04-22 13:41:10 +0200 |
commit | ef8570cd346e7ff5efccf360bcbe80c7b5e65b46 (patch) | |
tree | 569ca60823933ffbaaeb0090bf8c0756e013ae2d | |
parent | f40e5520fbe9726b26daf04d95c567ed3afdc28b (diff) | |
download | gba-renderers-ef8570cd346e7ff5efccf360bcbe80c7b5e65b46.tar.gz gba-renderers-ef8570cd346e7ff5efccf360bcbe80c7b5e65b46.zip |
Add dma dirty lines mode for double buffering
-rw-r--r-- | src/profiling.c | 2 | ||||
-rw-r--r-- | src/renderer_m0.c | 37 |
2 files changed, 36 insertions, 3 deletions
diff --git a/src/profiling.c b/src/profiling.c index 7477dca..6a4d448 100644 --- a/src/profiling.c +++ b/src/profiling.c | |||
@@ -86,7 +86,7 @@ static bool profile_bg_show = true; | |||
86 | 2) * 60;\ | 86 | 2) * 60;\ |
87 | draw_filled_rect(8 * 18, 0, 239, 16, 0);\ | 87 | draw_filled_rect(8 * 18, 0, 239, 16, 0);\ |
88 | txt_drawf("TIME: %.6d", 8 * 18, 0, 1, frame_time >> 2);\ | 88 | txt_drawf("TIME: %.6d", 8 * 18, 0, 1, frame_time >> 2);\ |
89 | txt_drawf("MAX FPS:%.4d", 8 * 18, 8, 1, fps >> 2);\ | 89 | txt_drawf("MAX FPS:%.4d", 8 * 18, 8, 1, (fps >> 2) + 1);\ |
90 | }\ | 90 | }\ |
91 | } while (0) | 91 | } while (0) |
92 | 92 | ||
diff --git a/src/renderer_m0.c b/src/renderer_m0.c index 6c509f9..5655e1d 100644 --- a/src/renderer_m0.c +++ b/src/renderer_m0.c | |||
@@ -673,8 +673,8 @@ flip_buffer(void) { | |||
673 | dirty_tiles[j] = 0; | 673 | dirty_tiles[j] = 0; |
674 | } | 674 | } |
675 | 675 | ||
676 | // Mode 3: Double buffering with dirty tiles, copying the dirty tiles if needed | 676 | // Mode 3: Double buffering with dirty line, copying the dirty lines if needed |
677 | // after flipping buffers. | 677 | // after flipping buffers with the DMA. |
678 | #elif FLIP_TYPE == 3 | 678 | #elif FLIP_TYPE == 3 |
679 | bool should_flip = false; | 679 | bool should_flip = false; |
680 | for (size_t j = 0; j < 20; ++j) { | 680 | for (size_t j = 0; j < 20; ++j) { |
@@ -701,6 +701,39 @@ flip_buffer(void) { | |||
701 | if (dirty_tiles[j] == 0) { | 701 | if (dirty_tiles[j] == 0) { |
702 | continue; | 702 | continue; |
703 | } | 703 | } |
704 | u32 offset = j * 32 * 8; | ||
705 | dma_copy(backbuf + offset, frontbuf + offset, (30 * 8 * 4), 3); | ||
706 | dirty_tiles[j] = 0; | ||
707 | } | ||
708 | |||
709 | // Mode 4: Double buffering with dirty tiles, copying the dirty tiles if needed | ||
710 | // after flipping buffers. | ||
711 | #elif FLIP_TYPE == 4 | ||
712 | bool should_flip = false; | ||
713 | for (size_t j = 0; j < 20; ++j) { | ||
714 | if (dirty_tiles[j] == 0) { | ||
715 | continue; | ||
716 | } | ||
717 | should_flip = true; | ||
718 | break; | ||
719 | } | ||
720 | if (!should_flip) { | ||
721 | return; | ||
722 | } | ||
723 | u32 *frontbuf = backbuf; | ||
724 | if (backbuf == BUF_0) { | ||
725 | backbuf = BUF_1; | ||
726 | BG_H_SCROLL_0 = 0; | ||
727 | BG_H_SCROLL_1 = -240; | ||
728 | } else { | ||
729 | backbuf = BUF_0; | ||
730 | BG_H_SCROLL_0 = -240; | ||
731 | BG_H_SCROLL_1 = 0; | ||
732 | } | ||
733 | for (size_t j = 0; j < 20; ++j) { | ||
734 | if (dirty_tiles[j] == 0) { | ||
735 | continue; | ||
736 | } | ||
704 | size_t k = 1; | 737 | size_t k = 1; |
705 | for (size_t i = 0; i < 30; ++i, k <<= 1) { | 738 | for (size_t i = 0; i < 30; ++i, k <<= 1) { |
706 | if (dirty_tiles[j] & k) { | 739 | if (dirty_tiles[j] & k) { |