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 /src/ppu.c | |
parent | d15d5599ab01ac1774f879d92dbec71e2654741e (diff) | |
download | uxngba-1d1e1123f8b76c40ba57427367f34b6f5c61de85.tar.gz uxngba-1d1e1123f8b76c40ba57427367f34b6f5c61de85.zip |
Clean up old ppu struct due to being unused
Diffstat (limited to 'src/ppu.c')
-rw-r--r-- | src/ppu.c | 102 |
1 files changed, 45 insertions, 57 deletions
@@ -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 | } |