diff options
author | Bad Diode <bd@badd10de.dev> | 2023-04-20 11:14:02 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2023-04-20 11:14:02 +0200 |
commit | 1d1e1123f8b76c40ba57427367f34b6f5c61de85 (patch) | |
tree | 6491d1e615a84284bb40feb89cce63cadfb0d184 | |
parent | d15d5599ab01ac1774f879d92dbec71e2654741e (diff) | |
download | uxngba-1d1e1123f8b76c40ba57427367f34b6f5c61de85.tar.gz uxngba-1d1e1123f8b76c40ba57427367f34b6f5c61de85.zip |
Clean up old ppu struct due to being unused
-rw-r--r-- | src/main.c | 76 | ||||
-rw-r--r-- | src/ppu.c | 102 |
2 files changed, 76 insertions, 102 deletions
@@ -28,9 +28,9 @@ | |||
28 | // | 28 | // |
29 | 29 | ||
30 | #if !defined(TEXT_MODE) || TEXT_MODE == 0 | 30 | #if !defined(TEXT_MODE) || TEXT_MODE == 0 |
31 | #define TEXT_LAYER ppu.fg | 31 | #define TEXT_LAYER FG_BACK |
32 | #else | 32 | #else |
33 | #define TEXT_LAYER ppu.bg | 33 | #define TEXT_LAYER BG_BACK |
34 | #endif | 34 | #endif |
35 | 35 | ||
36 | #ifndef CONTROL_METHODS | 36 | #ifndef CONTROL_METHODS |
@@ -46,6 +46,12 @@ | |||
46 | #elif PROF_ENABLE == 1 | 46 | #elif PROF_ENABLE == 1 |
47 | #define TEXT_ENABLE 1 | 47 | #define TEXT_ENABLE 1 |
48 | #define PROF(F,VAR) (profile_start(),(F),(VAR) = MAX(profile_stop(), (VAR))) | 48 | #define PROF(F,VAR) (profile_start(),(F),(VAR) = MAX(profile_stop(), (VAR))) |
49 | #elif PROF_ENABLE == 2 | ||
50 | #define TEXT_ENABLE 1 | ||
51 | // TODO: allow measuring inside a PROF function using profile_measure to store | ||
52 | // temporary values and calcualting the difference. | ||
53 | // TODO: allow per frame or per 60 second averaging of cycle measurement. | ||
54 | // TODO: calculate fps based on frame timing. | ||
49 | #endif | 55 | #endif |
50 | #ifndef PROF_SHOW_X | 56 | #ifndef PROF_SHOW_X |
51 | #define PROF_SHOW_X 0 | 57 | #define PROF_SHOW_X 0 |
@@ -53,45 +59,26 @@ | |||
53 | #ifndef PROF_SHOW_Y | 59 | #ifndef PROF_SHOW_Y |
54 | #define PROF_SHOW_Y 0 | 60 | #define PROF_SHOW_Y 0 |
55 | #endif | 61 | #endif |
56 | /* | ||
57 | // #define PROF_SHOW() \ | ||
58 | // do { \ | ||
59 | // txt_position((PROF_SHOW_X), (PROF_SHOW_Y));\ | ||
60 | // txt_printf("INPUT: %lu ", input_cycles);\ | ||
61 | // txt_position((PROF_SHOW_X), (PROF_SHOW_Y)+1);\ | ||
62 | // txt_printf("EVAL: %lu ", eval_cycles);\ | ||
63 | // txt_position((PROF_SHOW_X), (PROF_SHOW_Y)+2);\ | ||
64 | // txt_printf("FLIP: %lu ", flip_cycles);\ | ||
65 | // txt_position((PROF_SHOW_X), (PROF_SHOW_Y)+3);\ | ||
66 | // txt_printf("MIX: %lu ", mix_cycles);\ | ||
67 | // } while (0) | ||
68 | // #define PROF_SHOW() \ | ||
69 | // do { \ | ||
70 | // txt_position((PROF_SHOW_X), (PROF_SHOW_Y));\ | ||
71 | // txt_printf("PIX: %lu ", ppu_pixel_cycles);\ | ||
72 | // txt_position((PROF_SHOW_X), (PROF_SHOW_Y)+1);\ | ||
73 | // txt_printf("1BPP: %lu ", ppu_icn_cycles);\ | ||
74 | // txt_position((PROF_SHOW_X), (PROF_SHOW_Y)+2);\ | ||
75 | // txt_printf("2BPP: %lu ", ppu_chr_cycles);\ | ||
76 | // txt_position((PROF_SHOW_X), (PROF_SHOW_Y)+3);\ | ||
77 | // txt_printf("FLIP: %lu ", flip_cycles);\ | ||
78 | // } while (0) | ||
79 | // */ | ||
80 | #define PROF_SHOW() \ | 62 | #define PROF_SHOW() \ |
81 | do { \ | 63 | do { \ |
82 | txt_position((PROF_SHOW_X), (PROF_SHOW_Y));\ | 64 | txt_position((PROF_SHOW_X), (PROF_SHOW_Y));\ |
83 | txt_printf("1BPP: %.8lu\n2BPP: %.8lu\nFILL: %.8lu", ppu_icn_cycles, ppu_chr_cycles, ppu_fill_cycles);\ | 65 | txt_printf("FLIP: %.8lu\n", flip_cycles);\ |
66 | txt_printf("EVAL: %.8lu\n", eval_cycles);\ | ||
67 | screen_fill(BG_BACK, 0, 0, 15 * 8, 2 * 8, 0);\ | ||
68 | flipbuf();\ | ||
84 | } while (0) | 69 | } while (0) |
85 | 70 | ||
86 | static u32 ppu_pixel_cycles = 0; | 71 | |
87 | static u32 ppu_fill_cycles = 0; | 72 | // static u32 ppu_pixel_cycles = 0; |
88 | static u32 ppu_chr_cycles = 0; | 73 | // static u32 ppu_fill_cycles = 0; |
89 | static u32 ppu_icn_cycles = 0; | 74 | // static u32 ppu_chr_cycles = 0; |
75 | // static u32 ppu_icn_cycles = 0; | ||
90 | static u32 flip_cycles = 0; | 76 | static u32 flip_cycles = 0; |
91 | static u32 eval_cycles = 0; | 77 | static u32 eval_cycles = 0; |
92 | static u32 input_cycles = 0; | 78 | static u32 input_cycles = 0; |
93 | static u32 mix_cycles = 0; | 79 | static u32 mix_cycles = 0; |
94 | 80 | #define FRAME_START() ; // TODO | |
81 | #define FRAME_END() ; // TODO | ||
95 | #else | 82 | #else |
96 | #define PROF(F,VAR) (F) | 83 | #define PROF(F,VAR) (F) |
97 | #define PROF_SHOW() | 84 | #define PROF_SHOW() |
@@ -120,7 +107,6 @@ EWRAM_BSS | |||
120 | static u8 umem[0x10300]; | 107 | static u8 umem[0x10300]; |
121 | 108 | ||
122 | static Uxn u; | 109 | static Uxn u; |
123 | static Ppu ppu; | ||
124 | 110 | ||
125 | static Mouse mouse = {SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2}; | 111 | static Mouse mouse = {SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2}; |
126 | 112 | ||
@@ -155,17 +141,15 @@ screen_deo(u8 *ram, u8 *d, u8 port) { | |||
155 | u8 color = ctrl & 0x3; | 141 | u8 color = ctrl & 0x3; |
156 | u16 x0 = PEEK2(d + 0x8); | 142 | u16 x0 = PEEK2(d + 0x8); |
157 | u16 y0 = PEEK2(d + 0xa); | 143 | u16 y0 = PEEK2(d + 0xa); |
158 | u8 *layer = (ctrl & 0x40) ? ppu.fg : ppu.bg; | 144 | u8 *layer = (ctrl & 0x40) ? FG_BACK : BG_BACK; |
159 | if(ctrl & 0x80) { | 145 | if(ctrl & 0x80) { |
160 | u16 x1 = SCREEN_WIDTH - 1; | 146 | u16 x1 = SCREEN_WIDTH - 1; |
161 | u16 y1 = SCREEN_HEIGHT - 1; | 147 | u16 y1 = SCREEN_HEIGHT - 1; |
162 | if(ctrl & 0x10) x1 = x0, x0 = 0; | 148 | if(ctrl & 0x10) x1 = x0, x0 = 0; |
163 | if(ctrl & 0x20) y1 = y0, y0 = 0; | 149 | if(ctrl & 0x20) y1 = y0, y0 = 0; |
164 | PROF(screen_fill(layer, x0, y0, x1, y1, color), ppu_fill_cycles); | 150 | screen_fill(layer, x0, y0, x1, y1, color); |
165 | } else { | 151 | } else { |
166 | u16 width = SCREEN_WIDTH; | 152 | ppu_pixel(layer, x0, y0, color); |
167 | u16 height = SCREEN_HEIGHT; | ||
168 | PROF(ppu_pixel(layer, x0, y0, color), ppu_pixel_cycles); | ||
169 | if(d[0x6] & 0x1) POKE2(d + 0x8, x0 + 1); /* auto x+1 */ | 153 | if(d[0x6] & 0x1) POKE2(d + 0x8, x0 + 1); /* auto x+1 */ |
170 | if(d[0x6] & 0x2) POKE2(d + 0xa, y0 + 1); /* auto y+1 */ | 154 | if(d[0x6] & 0x2) POKE2(d + 0xa, y0 + 1); /* auto y+1 */ |
171 | } | 155 | } |
@@ -183,16 +167,16 @@ screen_deo(u8 *ram, u8 *d, u8 port) { | |||
183 | if(addr > 0x10000 - ((n + 1) << (3 + twobpp))) { | 167 | if(addr > 0x10000 - ((n + 1) << (3 + twobpp))) { |
184 | return; | 168 | return; |
185 | } | 169 | } |
186 | u8 *layer = (d[0xf] & 0x40) ? ppu.fg : ppu.bg; | 170 | u8 *layer = (d[0xf] & 0x40) ? FG_BACK : BG_BACK; |
187 | u8 color = d[0xf] & 0xf; | 171 | u8 color = d[0xf] & 0xf; |
188 | u8 flipx = d[0xf] & 0x10; | 172 | u8 flipx = d[0xf] & 0x10; |
189 | u8 flipy = d[0xf] & 0x20; | 173 | u8 flipy = d[0xf] & 0x20; |
190 | for(size_t i = 0; i <= n; i++) { | 174 | for(size_t i = 0; i <= n; i++) { |
191 | u8 *sprite = &ram[addr]; | 175 | u8 *sprite = &ram[addr]; |
192 | if (twobpp) { | 176 | if (twobpp) { |
193 | PROF(ppu_2bpp(layer, x + dy * i, y + dx * i, sprite, color, flipx, flipy), ppu_chr_cycles); | 177 | ppu_2bpp(layer, x + dy * i, y + dx * i, sprite, color, flipx, flipy); |
194 | } else { | 178 | } else { |
195 | PROF(ppu_1bpp(layer, x + dy * i, y + dx * i, sprite, color, flipx, flipy), ppu_icn_cycles); | 179 | ppu_1bpp(layer, x + dy * i, y + dx * i, sprite, color, flipx, flipy); |
196 | } | 180 | } |
197 | addr += (d[0x6] & 0x04) << (1 + twobpp); | 181 | addr += (d[0x6] & 0x04) << (1 + twobpp); |
198 | } | 182 | } |
@@ -614,7 +598,7 @@ main(void) { | |||
614 | irs_set(IRQ_VBLANK, sound_vsync); | 598 | irs_set(IRQ_VBLANK, sound_vsync); |
615 | 599 | ||
616 | // Initialize PPU. | 600 | // Initialize PPU. |
617 | initppu(&ppu, 30, 20); | 601 | video_init(); |
618 | 602 | ||
619 | // Initialize text engine. | 603 | // Initialize text engine. |
620 | #ifdef TEXT_ENABLE | 604 | #ifdef TEXT_ENABLE |
@@ -632,17 +616,19 @@ main(void) { | |||
632 | uxn_eval(&u, PAGE_PROGRAM); | 616 | uxn_eval(&u, PAGE_PROGRAM); |
633 | u8 frame_counter = 0; | 617 | u8 frame_counter = 0; |
634 | while(true) { | 618 | while(true) { |
635 | bios_vblank_wait(); | 619 | FRAME_START(); |
636 | PROF(handle_input(&u), input_cycles); | 620 | PROF(handle_input(&u), input_cycles); |
637 | PROF(uxn_eval(&u, PEEK2(&u.dev[0x20])), eval_cycles); | 621 | PROF(uxn_eval(&u, PEEK2(&u.dev[0x20])), eval_cycles); |
638 | PROF(sound_mix(), mix_cycles); | 622 | PROF(sound_mix(), mix_cycles); |
639 | PROF_SHOW(); | 623 | bios_vblank_wait(); |
640 | PROF(flipbuf(&ppu), flip_cycles); | 624 | PROF(flipbuf(), flip_cycles); |
641 | frame_counter++; | 625 | frame_counter++; |
642 | if (frame_counter == 60) { | 626 | if (frame_counter == 60) { |
643 | seconds++; | 627 | seconds++; |
644 | frame_counter = 0; | 628 | frame_counter = 0; |
645 | } | 629 | } |
630 | PROF_SHOW(); | ||
631 | FRAME_END(); | ||
646 | } | 632 | } |
647 | 633 | ||
648 | return 0; | 634 | return 0; |
@@ -214,21 +214,17 @@ static u32 dirty_tiles[21] = {0}; | |||
214 | 214 | ||
215 | void | 215 | void |
216 | putcolors(u8 *addr) { | 216 | putcolors(u8 *addr) { |
217 | int i; | 217 | for(size_t i = 0; i < 4; ++i) { |
218 | for(i = 0; i < 4; ++i) { | 218 | u8 r = (*(addr + 0 + i / 2) >> (!(i % 2) << 2)) & 0x0f; |
219 | u8 | 219 | u8 g = (*(addr + 2 + i / 2) >> (!(i % 2) << 2)) & 0x0f; |
220 | r = (*(addr + i / 2) >> (!(i % 2) << 2)) & 0x0f, | 220 | u8 b = (*(addr + 4 + i / 2) >> (!(i % 2) << 2)) & 0x0f; |
221 | g = (*(addr + 2 + i / 2) >> (!(i % 2) << 2)) & 0x0f, | 221 | Color color = rgb15( |
222 | b = (*(addr + 4 + i / 2) >> (!(i % 2) << 2)) & 0x0f; | ||
223 | PAL_BUFFER_BG[i] = rgb15( | ||
224 | (r << 1) | (r >> 3), | 222 | (r << 1) | (r >> 3), |
225 | (g << 1) | (g >> 3), | 223 | (g << 1) | (g >> 3), |
226 | (b << 1) | (b >> 3)); | 224 | (b << 1) | (b >> 3)); |
225 | PAL_BUFFER_BG[i] = color; | ||
227 | for (size_t j = 0; j < 16; ++j) { | 226 | for (size_t j = 0; j < 16; ++j) { |
228 | PAL_BUFFER_SPRITES[i * 16 + j] = rgb15( | 227 | PAL_BUFFER_SPRITES[i * 16 + j] = color; |
229 | (r << 1) | (r >> 3), | ||
230 | (g << 1) | (g >> 3), | ||
231 | (b << 1) | (b >> 3)); | ||
232 | } | 228 | } |
233 | } | 229 | } |
234 | } | 230 | } |
@@ -241,9 +237,10 @@ ppu_pixel(u32 *layer, u16 x, u16 y, u8 clr) { | |||
241 | size_t tile_y = y / 8; | 237 | size_t tile_y = y / 8; |
242 | size_t start_col = x % 8; | 238 | size_t start_col = x % 8; |
243 | size_t start_row = y % 8; | 239 | size_t start_row = y % 8; |
244 | size_t pos = (start_row + ((tile_x + tile_y * 32) * 8)); | 240 | size_t shift_left = start_col * 4; |
245 | size_t shift = start_col * 4; | 241 | u32 *dst = &layer[start_row + (tile_x + tile_y * 32) * 8]; |
246 | layer[pos] = (layer[pos] & (~(0xF << shift))) | (clr << shift); | 242 | u32 mask = 0xF << shift_left; |
243 | *dst = (*dst & ~mask) | (clr << shift_left); | ||
247 | dirty_tiles[tile_y] |= 1 << tile_x; | 244 | dirty_tiles[tile_y] |= 1 << tile_x; |
248 | } | 245 | } |
249 | 246 | ||
@@ -318,7 +315,9 @@ screen_fill(u32 *layer, u16 x0, u16 y0, u16 x1, u16 y1, u8 clr) { | |||
318 | 315 | ||
319 | // Special condition. If the screen is to be completely filled, use the DMA | 316 | // Special condition. If the screen is to be completely filled, use the DMA |
320 | // instead. | 317 | // instead. |
321 | if (x0 == 0 && x1 >= (SCREEN_WIDTH - 1) && y0 == 0 && y1 >= (SCREEN_HEIGHT - 1)) { | 318 | u16 max_width = SCREEN_WIDTH - 1; |
319 | u16 max_height = SCREEN_HEIGHT - 1; | ||
320 | if (x0 == 0 && x1 >= max_width && y0 == 0 && y1 >= max_height) { | ||
322 | clear_screen(layer, clr); | 321 | clear_screen(layer, clr); |
323 | return; | 322 | return; |
324 | } | 323 | } |
@@ -722,25 +721,33 @@ putfontchar(u32 *layer, u16 tile_x, u16 tile_y, u8 ch, u8 color) { | |||
722 | 721 | ||
723 | IWRAM_CODE | 722 | IWRAM_CODE |
724 | void | 723 | void |
725 | flipbuf(Ppu *p) { | 724 | flipbuf() { |
726 | Tile *mem_fg = FG_FRONT; | 725 | // Copy the fg and bg layers fully with the DMA. |
727 | Tile *mem_bg = BG_FRONT; | 726 | dma_copy((u32*)FG_FRONT, (u32*)FG_BACK, KB(40), 3); |
728 | for (size_t j = 0; j < 20; ++j) { | 727 | // dma_sync_copy((u32*)FG_FRONT, (u32*)FG_BACK, KB(40)); |
729 | if (dirty_tiles[j] == 0) { | 728 | // |
730 | continue; | 729 | // TODO: dma the dirty lines instead of per tile copying. |
731 | } | 730 | // dma_copy((u32*)BG_FRONT, (u32*)BG_BACK, KB(20), 3); |
732 | 731 | // dma_sync_copy((u32*)FG_FRONT, (u32*)FG_BACK, KB(20)); | |
733 | size_t k = 1; | 732 | // dma_sync_copy((u32*)BG_FRONT, (u32*)BG_BACK, KB(20)); |
734 | for (size_t i = 0; i < 30; ++i, k <<= 1) { | 733 | // Tile *mem_fg = FG_FRONT; |
735 | if (dirty_tiles[j] & k) { | 734 | // Tile *mem_bg = BG_FRONT; |
736 | Tile *tile_fg = p->fg; | 735 | // for (size_t j = 0; j < 20; ++j) { |
737 | Tile *tile_bg = p->bg; | 736 | // if (dirty_tiles[j] == 0) { |
738 | mem_fg[i + j * 32] = tile_fg[i + j * 32]; | 737 | // continue; |
739 | mem_bg[i + j * 32] = tile_bg[i + j * 32]; | 738 | // } |
740 | } | 739 | |
741 | } | 740 | // // size_t k = 1; |
742 | dirty_tiles[j] = 0; | 741 | // // for (size_t i = 0; i < 30; ++i, k <<= 1) { |
743 | } | 742 | // // if (dirty_tiles[j] & k) { |
743 | // // Tile *tile_fg = FG_BACK; | ||
744 | // // Tile *tile_bg = BG_BACK; | ||
745 | // // mem_fg[i + j * 32] = tile_fg[i + j * 32]; | ||
746 | // // mem_bg[i + j * 32] = tile_bg[i + j * 32]; | ||
747 | // // } | ||
748 | // // } | ||
749 | // dirty_tiles[j] = 0; | ||
750 | // } | ||
744 | } | 751 | } |
745 | 752 | ||
746 | typedef struct KeyboardChar { | 753 | typedef struct KeyboardChar { |
@@ -781,12 +788,10 @@ update_cursor(u8 pos) { | |||
781 | | OBJ_X_COORD(keyboard[cursor_position].x); | 788 | | OBJ_X_COORD(keyboard[cursor_position].x); |
782 | } | 789 | } |
783 | 790 | ||
784 | int | 791 | void |
785 | initppu(Ppu *p, u8 hor, u8 ver) { | 792 | video_init() { |
786 | p->hor = hor; | 793 | // Clear VRAM. |
787 | p->ver = ver; | 794 | // dma_fill((u32*)MEM_VRAM, 0, KB(96), 3); |
788 | p->width = (8 * p->hor); | ||
789 | p->height = (8 * p->ver); | ||
790 | 795 | ||
791 | // Initialize display mode and bg palette. | 796 | // Initialize display mode and bg palette. |
792 | DISP_CTRL = DISP_MODE_0 | DISP_BG_0 | DISP_BG_1 | DISP_OBJ; | 797 | DISP_CTRL = DISP_MODE_0 | DISP_BG_0 | DISP_BG_1 | DISP_OBJ; |
@@ -799,21 +804,6 @@ initppu(Ppu *p, u8 hor, u8 ver) { | |||
799 | BG_CTRL(0) = BG_CHARBLOCK(cb_fg) | BG_SCREENBLOCK(sb_fg) | BG_PRIORITY(1); | 804 | BG_CTRL(0) = BG_CHARBLOCK(cb_fg) | BG_SCREENBLOCK(sb_fg) | BG_PRIORITY(1); |
800 | BG_CTRL(1) = BG_CHARBLOCK(cb_bg) | BG_SCREENBLOCK(sb_bg) | BG_PRIORITY(2); | 805 | BG_CTRL(1) = BG_CHARBLOCK(cb_bg) | BG_SCREENBLOCK(sb_bg) | BG_PRIORITY(2); |
801 | 806 | ||
802 | // Clear front buffer. | ||
803 | p->fg = FG_FRONT; | ||
804 | p->bg = BG_FRONT; | ||
805 | |||
806 | // Use DMA to clear VRAM. | ||
807 | u32 fill = 0; | ||
808 | dma_fill(p->fg, fill, KB(20), 3); | ||
809 | dma_fill(p->bg, fill, KB(20), 3); | ||
810 | |||
811 | // Clear back buffer. | ||
812 | p->fg = FG_BACK; | ||
813 | p->bg = BG_BACK; | ||
814 | dma_fill(p->fg, fill, KB(20), 3); | ||
815 | dma_fill(p->bg, fill, KB(20), 3); | ||
816 | |||
817 | // Initialize default palette. | 807 | // Initialize default palette. |
818 | PAL_BUFFER_BG[0] = COLOR_BLACK; | 808 | PAL_BUFFER_BG[0] = COLOR_BLACK; |
819 | PAL_BUFFER_BG[1] = COLOR_WHITE; | 809 | PAL_BUFFER_BG[1] = COLOR_WHITE; |
@@ -856,6 +846,4 @@ initppu(Ppu *p, u8 hor, u8 ver) { | |||
856 | OBJ_ATTR_0(127) = OBJ_SHAPE_SQUARE | OBJ_Y_COORD(keyboard[cursor_position].y) | OBJ_HIDDEN; | 846 | OBJ_ATTR_0(127) = OBJ_SHAPE_SQUARE | OBJ_Y_COORD(keyboard[cursor_position].y) | OBJ_HIDDEN; |
857 | OBJ_ATTR_1(127) = OBJ_SIZE_SMALL | OBJ_X_COORD(keyboard[cursor_position].x); | 847 | OBJ_ATTR_1(127) = OBJ_SIZE_SMALL | OBJ_X_COORD(keyboard[cursor_position].x); |
858 | OBJ_ATTR_2(127) = (SPRITE_START_IDX + 0xdb) | OBJ_PAL_BANK(3); | 848 | OBJ_ATTR_2(127) = (SPRITE_START_IDX + 0xdb) | OBJ_PAL_BANK(3); |
859 | |||
860 | return 1; | ||
861 | } | 849 | } |