diff options
author | Bad Diode <bd@badd10de.dev> | 2023-04-14 21:26:37 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2023-04-15 18:29:26 +0200 |
commit | d63f3d01326e84bfd026690c0d03ed002b466332 (patch) | |
tree | a65412844d32293939d8875689fbac916829b0f9 | |
parent | e9297dc5ee36ee053dc350422cc772eaa2c8504a (diff) | |
download | gba-renderers-d63f3d01326e84bfd026690c0d03ed002b466332.tar.gz gba-renderers-d63f3d01326e84bfd026690c0d03ed002b466332.zip |
Update documentation and colors
-rw-r--r-- | src/gba/gba.h | 18 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/renderer.c | 26 | ||||
-rw-r--r-- | src/renderer.h | 34 | ||||
-rw-r--r-- | src/renderer_m4.c | 23 |
5 files changed, 49 insertions, 54 deletions
diff --git a/src/gba/gba.h b/src/gba/gba.h index 37b8a4c..d607eee 100644 --- a/src/gba/gba.h +++ b/src/gba/gba.h | |||
@@ -101,15 +101,15 @@ typedef Color Palette[16]; | |||
101 | #define RGB15(R,G,B) (u16)(((B) << 10) | ((G) << 5) | (R)) | 101 | #define RGB15(R,G,B) (u16)(((B) << 10) | ((G) << 5) | (R)) |
102 | 102 | ||
103 | // Some nice default colors. | 103 | // Some nice default colors. |
104 | #define COLOR_BLACK RGB15(0, 0, 0) | 104 | #define COLOR_BLACK RGB15( 0, 0, 0) |
105 | #define COLOR_RED RGB15(31, 0,10) | 105 | #define COLOR_RED RGB15(31, 0, 10) |
106 | #define COLOR_GREEN RGB15(31, 0,10) | 106 | #define COLOR_GREEN RGB15( 0, 31, 18) |
107 | #define COLOR_YELLOW RGB15(31, 0,10) | 107 | #define COLOR_YELLOW RGB15(31, 31, 0) |
108 | #define COLOR_BLUE RGB15(2, 17,31) | 108 | #define COLOR_BLUE RGB15( 2, 17, 31) |
109 | #define COLOR_PURPLE RGB15(2, 17,31) | 109 | #define COLOR_PURPLE RGB15(15, 7, 31) |
110 | #define COLOR_CYAN RGB15(0, 27,30) | 110 | #define COLOR_CYAN RGB15( 0, 27, 30) |
111 | #define COLOR_GREY RGB15(16,17,19) | 111 | #define COLOR_GREY RGB15(16, 17, 19) |
112 | #define COLOR_WHITE RGB15(28,28,28) | 112 | #define COLOR_WHITE RGB15(28, 28, 28) |
113 | 113 | ||
114 | // | 114 | // |
115 | // Tile memory access. | 115 | // Tile memory access. |
@@ -92,7 +92,7 @@ test_icn(void) { | |||
92 | 92 | ||
93 | for (size_t y = 10; y < 20; y++) { | 93 | for (size_t y = 10; y < 20; y++) { |
94 | for (size_t x = 10; x < 20; x++) { | 94 | for (size_t x = 10; x < 20; x++) { |
95 | draw_icn(8 + x * 8, 2 + y * 8, tile, 5, 0, 1); | 95 | draw_icn(8 + x * 8, 2 + y * 8, tile, 7, 0, 1); |
96 | } | 96 | } |
97 | } | 97 | } |
98 | } | 98 | } |
diff --git a/src/renderer.c b/src/renderer.c index 172ea22..495585e 100644 --- a/src/renderer.c +++ b/src/renderer.c | |||
@@ -18,6 +18,32 @@ | |||
18 | #include "renderer.h" | 18 | #include "renderer.h" |
19 | #include "text.h" | 19 | #include "text.h" |
20 | 20 | ||
21 | // The frontbuffs,eer is located at the beginning of the VRAM, and requires 20KB of | ||
22 | // video memory for 32 * 20 tiles at 4bpp. | ||
23 | #define FRONTBUF ((u32*)(MEM_VRAM)) | ||
24 | |||
25 | // Adjust both of these if the location of the map changes. Each screnblock | ||
26 | // requires less than 2KB. | ||
27 | #define FRONTBUF_TILEMAP ((u16*)(MEM_VRAM + KB(20))) | ||
28 | #define FRONTBUF_SB 10 | ||
29 | |||
30 | // The backbuffer is located at the end of the VRAM. This can allow us to use | ||
31 | // more backgrounds but eats into the available memory for sprites. This should | ||
32 | // be fine for non sprite intensive applications. If more sprite memory is | ||
33 | // needed, the backbuffer can be located at the end of the background memory | ||
34 | // instead (64KB - 20KB). | ||
35 | #define BACKBUF ((u32*)(MEM_VRAM + KB(96) - KB(20))) | ||
36 | |||
37 | // The font data is located at the end of the frontbuffer memory, after the tile | ||
38 | // map and requires 8KB for 256 8x8 characters at 4bpp. This, along with the | ||
39 | // tilemap information allow us to store the frontbuffer and font for a text | ||
40 | // background in the first 2 charblocks (32KB). | ||
41 | #define FONT_DATA ((u32*)(MEM_VRAM + KB(96) - KB(8))) | ||
42 | #define FONT_TILEMAP ((u16*)(MEM_VRAM + KB(96) - KB(8) - KB(1))) | ||
43 | #define FONT_SB 15 | ||
44 | #define FONT_OFFSET 192 | ||
45 | |||
46 | |||
21 | // Keep track of which tiles need to be copied to the frontbuffer. | 47 | // Keep track of which tiles need to be copied to the frontbuffer. |
22 | static u32 dirty_tiles[21] = {0}; | 48 | static u32 dirty_tiles[21] = {0}; |
23 | 49 | ||
diff --git a/src/renderer.h b/src/renderer.h index f47b364..cf490d3 100644 --- a/src/renderer.h +++ b/src/renderer.h | |||
@@ -3,31 +3,6 @@ | |||
3 | 3 | ||
4 | #include "gba/gba.h" | 4 | #include "gba/gba.h" |
5 | 5 | ||
6 | // The frontbuffs,eer is located at the beginning of the VRAM, and requires 20KB of | ||
7 | // video memory for 32 * 20 tiles at 4bpp. | ||
8 | #define FRONTBUF ((u32*)(MEM_VRAM)) | ||
9 | |||
10 | // Adjust both of these if the location of the map changes. Each screnblock | ||
11 | // requires less than 2KB. | ||
12 | #define FRONTBUF_TILEMAP ((u16*)(MEM_VRAM + KB(20))) | ||
13 | #define FRONTBUF_SB 10 | ||
14 | |||
15 | // The backbuffer is located at the end of the VRAM. This can allow us to use | ||
16 | // more backgrounds but eats into the available memory for sprites. This should | ||
17 | // be fine for non sprite intensive applications. If more sprite memory is | ||
18 | // needed, the backbuffer can be located at the end of the background memory | ||
19 | // instead (64KB - 20KB). | ||
20 | #define BACKBUF ((u32*)(MEM_VRAM + KB(96) - KB(20))) | ||
21 | |||
22 | // The font data is located at the end of the frontbuffer memory, after the tile | ||
23 | // map and requires 8KB for 256 8x8 characters at 4bpp. This, along with the | ||
24 | // tilemap information allow us to store the frontbuffer and font for a text | ||
25 | // background in the first 2 charblocks (32KB). | ||
26 | #define FONT_DATA ((u32*)(MEM_VRAM + KB(96) - KB(8))) | ||
27 | #define FONT_TILEMAP ((u16*)(MEM_VRAM + KB(96) - KB(8) - KB(1))) | ||
28 | #define FONT_SB 15 | ||
29 | #define FONT_OFFSET 192 | ||
30 | |||
31 | // Draws a pixel to the given (x, y) position on the framebuffer. All drawing | 6 | // Draws a pixel to the given (x, y) position on the framebuffer. All drawing |
32 | // functions use paletted colors (clr: 0-15). | 7 | // functions use paletted colors (clr: 0-15). |
33 | void draw_pixel(size_t x, size_t y, u8 clr); | 8 | void draw_pixel(size_t x, size_t y, u8 clr); |
@@ -44,7 +19,14 @@ void draw_filled_rect(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr); | |||
44 | // Fills the framebuffer with the given color. | 19 | // Fills the framebuffer with the given color. |
45 | void screen_fill(u8 clr); | 20 | void screen_fill(u8 clr); |
46 | 21 | ||
47 | // Copies the content of dirty tiles from the backbuffer into the frontbuffer. | 22 | // Draws a chr sprite (16 * u8). The first 8 bytes correspond to ch0 and the |
23 | // last 8 to ch1. | ||
24 | void draw_chr(size_t x, size_t y, u8 *sprite, u8 flip_x, u8 flip_y); | ||
25 | |||
26 | // Draws a 1bpp icn sprite in the given color. | ||
27 | void draw_icn(size_t x, size_t y, u8 *sprite, u8 clr, u8 flip_x, u8 flip_y); | ||
28 | |||
29 | // Copies data and performs page flipping if needed. | ||
48 | // To be called exactly once at the beginning of the VBlank. | 30 | // To be called exactly once at the beginning of the VBlank. |
49 | void flip_buffer(void); | 31 | void flip_buffer(void); |
50 | 32 | ||
diff --git a/src/renderer_m4.c b/src/renderer_m4.c index 4cca97c..21dc192 100644 --- a/src/renderer_m4.c +++ b/src/renderer_m4.c | |||
@@ -186,22 +186,6 @@ draw_filled_rect(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr) { | |||
186 | screen_updated = true; | 186 | screen_updated = true; |
187 | } | 187 | } |
188 | 188 | ||
189 | IWRAM_CODE | ||
190 | static inline | ||
191 | u64 | ||
192 | decode_tile_u64(u32 *data) { | ||
193 | u64 mask = | ||
194 | (((u64)*data >> 0) * 0xF & 0xF) << 0 | | ||
195 | (((u64)*data >> 4) * 0xF & 0xF) << 8 | | ||
196 | (((u64)*data >> 8) * 0xF & 0xF) << 16 | | ||
197 | (((u64)*data >> 12) * 0xF & 0xF) << 24 | | ||
198 | (((u64)*data >> 16) * 0xF & 0xF) << 32 | | ||
199 | (((u64)*data >> 20) * 0xF & 0xF) << 40 | | ||
200 | (((u64)*data >> 24) * 0xF & 0xF) << 48 | | ||
201 | (((u64)*data >> 28) * 0xF & 0xF) << 56; | ||
202 | return mask; | ||
203 | } | ||
204 | |||
205 | static u32 dec_nibble[] = { | 189 | static u32 dec_nibble[] = { |
206 | 0x00000000, 0x01000000, 0x00010000, 0x01010000, | 190 | 0x00000000, 0x01000000, 0x00010000, 0x01010000, |
207 | 0x00000100, 0x01000100, 0x00010100, 0x01010100, | 191 | 0x00000100, 0x01000100, 0x00010100, 0x01010100, |
@@ -349,7 +333,7 @@ flip_buffer(void) { | |||
349 | 333 | ||
350 | #include "font.h" | 334 | #include "font.h" |
351 | 335 | ||
352 | // Font rendering function for the text engine.. | 336 | // Font rendering function for the text engine. |
353 | void | 337 | void |
354 | txt_drawc(char c, size_t x, size_t y, u8 clr) { | 338 | txt_drawc(char c, size_t x, size_t y, u8 clr) { |
355 | u8 *tile = font_icn; | 339 | u8 *tile = font_icn; |
@@ -370,7 +354,10 @@ renderer_init(void) { | |||
370 | PAL_BUFFER_BG[2] = COLOR_RED; | 354 | PAL_BUFFER_BG[2] = COLOR_RED; |
371 | PAL_BUFFER_BG[3] = COLOR_BLUE; | 355 | PAL_BUFFER_BG[3] = COLOR_BLUE; |
372 | PAL_BUFFER_BG[4] = COLOR_CYAN; | 356 | PAL_BUFFER_BG[4] = COLOR_CYAN; |
373 | PAL_BUFFER_BG[5] = COLOR_GREY; | 357 | PAL_BUFFER_BG[5] = COLOR_PURPLE; |
358 | PAL_BUFFER_BG[6] = COLOR_YELLOW; | ||
359 | PAL_BUFFER_BG[7] = COLOR_GREEN; | ||
360 | PAL_BUFFER_BG[8] = COLOR_GREY; | ||
374 | 361 | ||
375 | // Initialize text engine. | 362 | // Initialize text engine. |
376 | txt_init(txt_drawc); | 363 | txt_init(txt_drawc); |