diff options
author | Bad Diode <bd@badd10de.dev> | 2023-04-16 16:22:59 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2023-04-16 16:22:59 +0200 |
commit | 4b73363bbb3507641165db4c0283a5acf5ff44e3 (patch) | |
tree | a2355bf0e5bf0e2b411e285e1efa4b9cb8a35e21 | |
parent | 6c0e7e0f470ec5617f01d57cf23145d581764a5b (diff) | |
download | gba-link-cable-tester-4b73363bbb3507641165db4c0283a5acf5ff44e3.tar.gz gba-link-cable-tester-4b73363bbb3507641165db4c0283a5acf5ff44e3.zip |
Remove outdated comments
-rw-r--r-- | src/renderer_m0.c | 124 |
1 files changed, 9 insertions, 115 deletions
diff --git a/src/renderer_m0.c b/src/renderer_m0.c index 97899aa..5c57278 100644 --- a/src/renderer_m0.c +++ b/src/renderer_m0.c | |||
@@ -4,16 +4,6 @@ | |||
4 | // backgrounds if needed. It also performs double buffering to avoid tearing | 4 | // backgrounds if needed. It also performs double buffering to avoid tearing |
5 | // artifacts and tries to only draw tiles that changed on each frame. | 5 | // artifacts and tries to only draw tiles that changed on each frame. |
6 | // | 6 | // |
7 | // In addition to the frontbuffer (displayed on background 0), a tiled text | ||
8 | // layer is displayed on background 1, which can be used for application | ||
9 | // development or for debug information. | ||
10 | // | ||
11 | // These two layers occupy the first and second background charblocks, leaving | ||
12 | // the remaining two available for other background layers. There are 14KB of | ||
13 | // sprite memory available, since the backbuffer is located at the end of the | ||
14 | // VRAM, but if more space is needed it can be moved to the end of the BG | ||
15 | // charblocks instead. | ||
16 | // | ||
17 | 7 | ||
18 | #include "renderer.h" | 8 | #include "renderer.h" |
19 | #include "text.h" | 9 | #include "text.h" |
@@ -21,42 +11,24 @@ | |||
21 | // Front/back buffers for double buffering. | 11 | // Front/back buffers for double buffering. |
22 | #define BUF_0 ((u32*)(MEM_VRAM)) | 12 | #define BUF_0 ((u32*)(MEM_VRAM)) |
23 | #define BUF_1 ((u32*)(MEM_VRAM + KB(20))) | 13 | #define BUF_1 ((u32*)(MEM_VRAM + KB(20))) |
14 | |||
24 | // Position of the tilemap. | 15 | // Position of the tilemap. |
25 | #define TILE_MAP ((u32*)(MEM_VRAM + KB(40))) | 16 | #define TILE_MAP ((u32*)(MEM_VRAM + KB(40))) |
26 | 17 | ||
27 | // Charblock and screenblock for both render buffers. | 18 | // Charblock and screenblock for both render buffers. |
28 | #define CB_0 0 | 19 | #define CB_0 0 |
29 | #define CB_1 1 | 20 | #define CB_1 1 |
30 | // NOTE: CB_2 could be at the end of 2 (0x0600:8000) since we only need a clear | ||
31 | // color tile. Testing at 3 for now. | ||
32 | // #define CB_2 3 | ||
33 | #define SB_0 20 | 21 | #define SB_0 20 |
34 | #define SB_1 22 | 22 | #define SB_1 22 |
35 | // #define SB_2 23 | ||
36 | 23 | ||
37 | // Available storage for other memory. | 24 | // Available storage for other memory. |
38 | // #define FG_PIXELS ((u32*)(MEM_VRAM + KB(44))) | 25 | // #define FG_PIXELS ((u32*)(MEM_VRAM + KB(44))) |
39 | // #define BG_PIXELS ((u32*)(MEM_VRAM + KB(64))) | 26 | // #define BG_PIXELS ((u32*)(MEM_VRAM + KB(64))) |
40 | 27 | ||
41 | // // The frontbuffs,eer is located at the beginning of the VRAM, and requires 20KB of | ||
42 | // // video memory for 32 * 20 tiles at 4bpp. | ||
43 | // #define FRONTBUF ((u32*)(MEM_VRAM)) | ||
44 | |||
45 | // // Adjust both of these if the location of the map changes. Each screnblock | ||
46 | // // requires less than 2KB. | ||
47 | // #define FRONTBUF_TILEMAP ((u16*)(MEM_VRAM + KB(20))) | ||
48 | // #define FRONTBUF_SB 10 | ||
49 | |||
50 | // The backbuffer is located at the end of the VRAM. This can allow us to use | ||
51 | // more backgrounds but eats into the available memory for sprites. This should | ||
52 | // be fine for non sprite intensive applications. If more sprite memory is | ||
53 | // needed, the backbuffer can be located at the end of the background memory | ||
54 | // instead (64KB - 20KB). | ||
55 | // #define BACKBUF ((u32*)(MEM_VRAM + KB(96) - KB(20))) | ||
56 | |||
57 | // Keep track of which tiles need to be copied to the frontbuffer. | 28 | // Keep track of which tiles need to be copied to the frontbuffer. |
58 | static u32 dirty_tiles[21] = {0}; | 29 | static u32 dirty_tiles[21] = {0}; |
59 | static u32 *backbuf = BUF_0; | 30 | |
31 | static u32 *backbuf = BUF_1; | ||
60 | 32 | ||
61 | // Boundchecks can be disable at compile time but this will not always improve | 33 | // Boundchecks can be disable at compile time but this will not always improve |
62 | // the performance and can in fact make it worse. It is possible that this is | 34 | // the performance and can in fact make it worse. It is possible that this is |
@@ -146,7 +118,7 @@ draw_line(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr) { | |||
146 | MAYBE_SWAP(y0, y1); | 118 | MAYBE_SWAP(y0, y1); |
147 | draw_vline(x0, y0, y1, clr); | 119 | draw_vline(x0, y0, y1, clr); |
148 | } else { | 120 | } else { |
149 | // ... | 121 | // TODO |
150 | // // Diagonal line. | 122 | // // Diagonal line. |
151 | // int dx = x0 > x1 ? x0 - x1 : x1 - x0; | 123 | // int dx = x0 > x1 ? x0 - x1 : x1 - x0; |
152 | // int dy = y0 > y1 ? y0 - y1 : y1 - y0; | 124 | // int dy = y0 > y1 ? y0 - y1 : y1 - y0; |
@@ -309,7 +281,6 @@ draw_filled_rect(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr) { | |||
309 | 281 | ||
310 | // Drawline implementation. | 282 | // Drawline implementation. |
311 | for (size_t y = y0; y <= y1; y++) { | 283 | for (size_t y = y0; y <= y1; y++) { |
312 | // NOTE: Unclear why here draw_hline is faster than draw_line. | ||
313 | draw_hline(x0, x1, y, clr); | 284 | draw_hline(x0, x1, y, clr); |
314 | } | 285 | } |
315 | 286 | ||
@@ -365,84 +336,6 @@ draw_filled_rect(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr) { | |||
365 | // } | 336 | // } |
366 | } | 337 | } |
367 | 338 | ||
368 | // IWRAM_CODE | ||
369 | // void | ||
370 | // draw_tile(size_t x, size_t y, Tile *tile, u8 clr) { | ||
371 | // BOUNDCHECK_SCREEN(x, y); | ||
372 | |||
373 | // // Find row position for the given x/y coordinates. | ||
374 | // size_t tile_x = x / 8; | ||
375 | // size_t tile_y = y / 8; | ||
376 | // size_t start_col = x % 8; | ||
377 | // size_t start_row = y % 8; | ||
378 | |||
379 | // // Get a pointer to the backbuffer and the tile row. | ||
380 | // size_t pos = start_row + (tile_x + tile_y * 32) * 8; | ||
381 | // u32 *backbuffer = &backbuf[pos]; | ||
382 | // u32 *row = tile; | ||
383 | |||
384 | // // This will blend all colors weirdly if using tiles that contain colors | ||
385 | // // higher than 1. | ||
386 | // size_t shift_left = start_col * 4; | ||
387 | // size_t shift_right = (8 - start_col) * 4; | ||
388 | // // u32 row_mask_left = merge ? 0 : 0xFFFFFFFF << shift_left; | ||
389 | // // u32 row_mask_right = merge ? 0 : 0xFFFFFFFF >> shift_right; | ||
390 | |||
391 | // // Draw the tiles. There are 4 possible cases: | ||
392 | // // 1. The tile is exactly at the tile boundary. | ||
393 | // // 2. The tile spans 2 tiles horizontally. | ||
394 | // // 3. The tile spans 2 tiles vertically. | ||
395 | // // 4. The tile spans 4 tiles. | ||
396 | // if (start_col == 0 && start_row == 0) { | ||
397 | // for (size_t i = 0; i < (8 - start_row); i++, backbuffer++) { | ||
398 | // BOUNDCHECK_SCREEN(x, y + i); | ||
399 | // backbuffer[0] = (backbuffer[0] & ~row_mask_left) | row[i] * clr; | ||
400 | // } | ||
401 | // dirty_tiles[tile_y] |= 1 << tile_x; | ||
402 | // } else if (start_row == 0) { | ||
403 | // for (size_t i = 0; i < 8; i++, backbuffer++) { | ||
404 | // BOUNDCHECK_SCREEN(x, y + i); | ||
405 | // backbuffer[0] = (backbuffer[0] & ~row_mask_left) | (row[i] * clr << shift_left); | ||
406 | // backbuffer[8] = (backbuffer[8] & ~row_mask_right) | (row[i] * clr >> shift_right); | ||
407 | // } | ||
408 | // dirty_tiles[tile_y] |= 1 << tile_x; | ||
409 | // dirty_tiles[tile_y] |= 1 << (tile_x + 1); | ||
410 | // } else if (start_col == 0) { | ||
411 | // for (size_t i = 0; i < (8 - start_row); i++, backbuffer++) { | ||
412 | // BOUNDCHECK_SCREEN(x, y + i); | ||
413 | // backbuffer[0] = (backbuffer[0] & ~row_mask_left) | row[i] * clr; | ||
414 | // } | ||
415 | // backbuffer += 8 * 31; | ||
416 | // for (size_t i = (8 - start_row); i < 8; i++, backbuffer++) { | ||
417 | // BOUNDCHECK_SCREEN(x, y + i); | ||
418 | // backbuffer[0] = (backbuffer[0] & ~row_mask_left) | row[i] * clr; | ||
419 | // } | ||
420 | // dirty_tiles[tile_y] |= 1 << tile_x; | ||
421 | // dirty_tiles[tile_y + 1] |= 1 << tile_x; | ||
422 | // } else { | ||
423 | // for (size_t i = 0; i < (8 - start_row); i++, backbuffer++) { | ||
424 | // BOUNDCHECK_SCREEN(x, y + i); | ||
425 | // backbuffer[0] = (backbuffer[0] & ~row_mask_left) | (row[i] * clr << shift_left); | ||
426 | // backbuffer[8] = (backbuffer[8] & ~row_mask_right) | (row[i] * clr >> shift_right); | ||
427 | // } | ||
428 | // backbuffer += 8 * 31; | ||
429 | // for (size_t i = (8 - start_row); i < 8; i++, backbuffer++) { | ||
430 | // BOUNDCHECK_SCREEN(x, y + i); | ||
431 | // backbuffer[0] = (backbuffer[0] & ~row_mask_left) | (row[i] * clr << shift_left); | ||
432 | // backbuffer[8] = (backbuffer[8] & ~row_mask_right) | (row[i] * clr >> shift_right); | ||
433 | // } | ||
434 | // dirty_tiles[tile_y] |= 1 << tile_x; | ||
435 | // dirty_tiles[tile_y] |= 1 << (tile_x + 1); | ||
436 | // dirty_tiles[tile_y + 1] |= 1 << tile_x; | ||
437 | // dirty_tiles[tile_y + 1] |= 1 << (tile_x + 1); | ||
438 | // } | ||
439 | // } | ||
440 | |||
441 | // void | ||
442 | // clear_screen(void) { | ||
443 | // dma_fill(FRONTBUF, 0, KB(20), 3); | ||
444 | // } | ||
445 | |||
446 | IWRAM_CODE | 339 | IWRAM_CODE |
447 | void | 340 | void |
448 | flip_buffer(void) { | 341 | flip_buffer(void) { |
@@ -632,10 +525,11 @@ renderer_init(void) { | |||
632 | BG_CTRL(0) = BG_CHARBLOCK(CB_0) | BG_SCREENBLOCK(SB_0) | BG_PRIORITY(0) | BG_SIZE(1); | 525 | BG_CTRL(0) = BG_CHARBLOCK(CB_0) | BG_SCREENBLOCK(SB_0) | BG_PRIORITY(0) | BG_SIZE(1); |
633 | BG_CTRL(1) = BG_CHARBLOCK(CB_1) | BG_SCREENBLOCK(SB_1) | BG_PRIORITY(1) | BG_SIZE(1); | 526 | BG_CTRL(1) = BG_CHARBLOCK(CB_1) | BG_SCREENBLOCK(SB_1) | BG_PRIORITY(1) | BG_SIZE(1); |
634 | 527 | ||
635 | // Initialize background memory map for frontbuffer. | 528 | // Initialize background memory map for the render buffers. The backgrounds |
636 | // for (size_t i = 0; i < 32 * 20; ++i) { | 529 | // are 64x32 each, with the second screenblock pointing to a zeroed tile. |
637 | // TILE_MAP[i] = i; | 530 | // This makes it so while scrolling the backgrounds to the second screen we |
638 | // } | 531 | // effectively disabling them. Thanks to this we can perform double |
532 | // buffering with mode 0 rendering. | ||
639 | u16 *mem_map_fg = SCREENBLOCK_MEM[SB_0]; | 533 | u16 *mem_map_fg = SCREENBLOCK_MEM[SB_0]; |
640 | u16 *mem_map_fg_blank = SCREENBLOCK_MEM[SB_0 + 1]; | 534 | u16 *mem_map_fg_blank = SCREENBLOCK_MEM[SB_0 + 1]; |
641 | u16 *mem_map_bg = SCREENBLOCK_MEM[SB_1]; | 535 | u16 *mem_map_bg = SCREENBLOCK_MEM[SB_1]; |