diff options
author | Bad Diode <bd@badd10de.dev> | 2021-06-03 11:24:31 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2021-06-03 11:24:31 +0200 |
commit | 0eda19bd2bb551bf9186b0fbe1a806a28d5a3597 (patch) | |
tree | 859aad06f65f2502a13d26c372c4978147fa1864 /src/renderer.c | |
parent | 6b68cbd8a25dc2e554cf6741ff61ef87c030d841 (diff) | |
download | stepper-0eda19bd2bb551bf9186b0fbe1a806a28d5a3597.tar.gz stepper-0eda19bd2bb551bf9186b0fbe1a806a28d5a3597.zip |
Add initial text background drawing functions
Diffstat (limited to 'src/renderer.c')
-rw-r--r-- | src/renderer.c | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/src/renderer.c b/src/renderer.c index bddaacd..bd2c023 100644 --- a/src/renderer.c +++ b/src/renderer.c | |||
@@ -12,10 +12,10 @@ | |||
12 | // the remaining two available for other background layers. There are 14KB of | 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 | 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 | 14 | // VRAM, but if more space is needed it can be moved to the end of the BG |
15 | // charblocks instead. | 15 | // charblocks instead as described below. |
16 | // | 16 | // |
17 | 17 | ||
18 | #include "bd-font.c" | 18 | #include "text.h" |
19 | 19 | ||
20 | // The frontbuffer is located at the beginning of the VRAM, and requires 20KB of | 20 | // The frontbuffer is located at the beginning of the VRAM, and requires 20KB of |
21 | // video memory for 32 * 20 tiles at 4bpp. | 21 | // video memory for 32 * 20 tiles at 4bpp. |
@@ -40,6 +40,7 @@ | |||
40 | #define FONT_DATA ((u32*)(MEM_VRAM + KB(22))) | 40 | #define FONT_DATA ((u32*)(MEM_VRAM + KB(22))) |
41 | #define FONT_TILEMAP ((u16*)(MEM_VRAM + KB(30))) | 41 | #define FONT_TILEMAP ((u16*)(MEM_VRAM + KB(30))) |
42 | #define FONT_SB 15 | 42 | #define FONT_SB 15 |
43 | #define FONT_OFFSET 192 | ||
43 | 44 | ||
44 | // Keep track of which tiles need to be copied to the frontbuffer. | 45 | // Keep track of which tiles need to be copied to the frontbuffer. |
45 | static u32 dirty_tiles[21] = {0}; | 46 | static u32 dirty_tiles[21] = {0}; |
@@ -86,8 +87,6 @@ flip_buffer(void) { | |||
86 | } | 87 | } |
87 | } | 88 | } |
88 | 89 | ||
89 | static u16 font_map[256] = {0}; | ||
90 | |||
91 | void | 90 | void |
92 | renderer_init(void) { | 91 | renderer_init(void) { |
93 | // Initialize display mode and bg palette. | 92 | // Initialize display mode and bg palette. |
@@ -100,9 +99,9 @@ renderer_init(void) { | |||
100 | // Use DMA to clear front and back buffers as well as the font memory map. | 99 | // Use DMA to clear front and back buffers as well as the font memory map. |
101 | dma_fill(FRONTBUF, 0, KB(20), 3); | 100 | dma_fill(FRONTBUF, 0, KB(20), 3); |
102 | dma_fill(FRONTBUF_TILEMAP, 0, KB(2), 3); | 101 | dma_fill(FRONTBUF_TILEMAP, 0, KB(2), 3); |
103 | dma_fill(FONT_DATA, 0, KB(8), 3); | ||
104 | dma_fill(FONT_TILEMAP, 0, KB(2), 3); | ||
105 | dma_fill(BACKBUF, 0, KB(20), 3); | 102 | dma_fill(BACKBUF, 0, KB(20), 3); |
103 | dma_fill(FONT_DATA, 0, KB(8), 3); | ||
104 | dma_fill(FONT_TILEMAP, FONT_OFFSET, KB(2), 3); | ||
106 | 105 | ||
107 | // Initialize default palette. | 106 | // Initialize default palette. |
108 | PAL_BUFFER_BG[0] = COLOR_BLACK; | 107 | PAL_BUFFER_BG[0] = COLOR_BLACK; |
@@ -117,13 +116,6 @@ renderer_init(void) { | |||
117 | FRONTBUF_TILEMAP[i] = i; | 116 | FRONTBUF_TILEMAP[i] = i; |
118 | } | 117 | } |
119 | 118 | ||
120 | // Load font data into VRAM. | 119 | // Initialize text engine. |
121 | unpack_tiles(&bd_font, FONT_DATA, 256); | 120 | txt_init(FONT_DATA, FONT_TILEMAP, FONT_OFFSET); |
122 | |||
123 | // Initialize the font map translation table. That way we can write | ||
124 | // a character on the text background layer with: | ||
125 | // FONT_TILEMAP[tile_x + 32 * tile_y] = font_map['A']; | ||
126 | for (size_t i = 0; i < 256; ++i) { | ||
127 | font_map[i] = 192 + i; | ||
128 | } | ||
129 | } | 121 | } |