diff options
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | src/bd-font.c | 141 | ||||
-rw-r--r-- | src/filesystem.h | 2 | ||||
-rw-r--r-- | src/gba/bios_calls.s (renamed from src/bios_calls.s) | 0 | ||||
-rw-r--r-- | src/gba/gba.h (renamed from src/common.h) | 6 | ||||
-rw-r--r-- | src/gba/interrupts.c (renamed from src/interrupts.c) | 2 | ||||
-rw-r--r-- | src/gba/interrupts.s (renamed from src/interrupts.s) | 0 | ||||
-rw-r--r-- | src/main.c | 9 | ||||
-rw-r--r-- | src/renderer.c | 71 |
9 files changed, 203 insertions, 33 deletions
@@ -15,7 +15,8 @@ LIBGBA += $(LIBGBA_DIR)/lib/libmm.a | |||
15 | SRC_DIR := src | 15 | SRC_DIR := src |
16 | BUILD_DIR := build | 16 | BUILD_DIR := build |
17 | SRC_MAIN := $(SRC_DIR)/main.c | 17 | SRC_MAIN := $(SRC_DIR)/main.c |
18 | ASM_FILES := $(wildcard $(SRC_DIR)/*.s) | 18 | SRC_BDGBA := $(wildcard $(SRC_DIR)/gba/*.s) |
19 | SRC_BDGBA += $(wildcard $(SRC_DIR)/gba/*.c) | ||
19 | WATCH_SRC := $(shell find $(SRC_DIR) -name *.c -or -name *.s -or -name *.h) | 20 | WATCH_SRC := $(shell find $(SRC_DIR) -name *.c -or -name *.s -or -name *.h) |
20 | INC_DIRS := $(shell find $(SRC_DIR) -type d) | 21 | INC_DIRS := $(shell find $(SRC_DIR) -type d) |
21 | INC_DIRS += $(BUILD_DIR) | 22 | INC_DIRS += $(BUILD_DIR) |
@@ -64,7 +65,7 @@ $(BIN): $(ELF) | |||
64 | 65 | ||
65 | # Link files. | 66 | # Link files. |
66 | $(ELF): $(SRC_MAIN) $(WATCH_SRC) | 67 | $(ELF): $(SRC_MAIN) $(WATCH_SRC) |
67 | $(CC) $(CFLAGS) $(LDFLAGS) -o $(ELF) $(SRC_MAIN) $(ASM_FILES) $(LDLIBS) | 68 | $(CC) $(CFLAGS) $(LDFLAGS) -o $(ELF) $(SRC_MAIN) $(SRC_BDGBA) $(LDLIBS) |
68 | 69 | ||
69 | # Create build directory if needed. | 70 | # Create build directory if needed. |
70 | $(BUILD_DIR): | 71 | $(BUILD_DIR): |
diff --git a/src/bd-font.c b/src/bd-font.c new file mode 100644 index 0000000..5276735 --- /dev/null +++ b/src/bd-font.c | |||
@@ -0,0 +1,141 @@ | |||
1 | /* | ||
2 | Copyright (c) 2021 Bad Diode | ||
3 | |||
4 | Permission to use, copy, modify, and distribute this software for any | ||
5 | purpose with or without fee is hereby granted, provided that the above | ||
6 | copyright notice and this permission notice appear in all copies. | ||
7 | |||
8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | WITH REGARD TO THIS SOFTWARE. | ||
10 | */ | ||
11 | |||
12 | static const u32 bd_font[] = { | ||
13 | 0x00000000, 0x00000000, 0x00002400, 0x423c0000, | ||
14 | 0x00002400, 0x3c420000, 0x0000363e, 0x3e1c0800, | ||
15 | 0x00081c3e, 0x3e1c0800, 0x001c1c3e, 0x363e081c, | ||
16 | 0x00081c3e, 0x3e3e081c, 0x00000018, 0x18000000, | ||
17 | 0x7e7e7e66, 0x667e7e7e, 0x00001824, 0x24180000, | ||
18 | 0x7e7e665a, 0x5a667e7e, 0x00081c3e, 0x081c221c, | ||
19 | 0x001c221c, 0x08083e08, 0x00183828, 0x08080c0c, | ||
20 | 0x003c2424, 0x24343606, 0x00082208, 0x1c082208, | ||
21 | 0x040c1c3c, 0x1c0c0400, 0x2030383c, 0x38302000, | ||
22 | 0x081c3e08, 0x083e1c08, 0x00141414, 0x14140014, | ||
23 | 0x003c2a2a, 0x2c282828, 0x0038043c, 0x423c201e, | ||
24 | 0x00000000, 0x7e000000, 0x081c3e08, 0x3e1c083e, | ||
25 | 0x081c3e08, 0x08080800, 0x00080808, 0x083e1c08, | ||
26 | 0x00001030, 0x7e301000, 0x0000080c, 0x7e0c0800, | ||
27 | 0x00000000, 0x0002023e, 0x00002466, 0xff662400, | ||
28 | 0x0008081c, 0x1c3e3e00, 0x003e3e1c, 0x1c080800, | ||
29 | 0x00000000, 0x00000000, 0x00080808, 0x08080008, | ||
30 | 0x14141400, 0x00000000, 0x0000143e, 0x143e1400, | ||
31 | 0x00081c02, 0x1c201e08, 0x00002616, 0x08343200, | ||
32 | 0x00081408, 0x34122c00, 0x08080800, 0x00000000, | ||
33 | 0x08040404, 0x04040408, 0x08101010, 0x10101008, | ||
34 | 0x00001408, 0x3e081400, 0x00000808, 0x3e080800, | ||
35 | 0x00000000, 0x000c0804, 0x00000000, 0x3e000000, | ||
36 | 0x00000000, 0x000c0c00, 0x00203018, 0x0c060200, | ||
37 | 0x00001c22, 0x2a221c00, 0x00000c0a, 0x08083e00, | ||
38 | 0x00001c20, 0x1c023e00, 0x00001c22, 0x18221c00, | ||
39 | 0x00001018, 0x143e1000, 0x00003e02, 0x1e201e00, | ||
40 | 0x00001c02, 0x1e221c00, 0x00003e20, 0x10080400, | ||
41 | 0x00001c22, 0x1c221c00, 0x00001c22, 0x3c201c00, | ||
42 | 0x00000c0c, 0x000c0c00, 0x00000c0c, 0x000c0804, | ||
43 | 0x00100804, 0x04081000, 0x0000003e, 0x003e0000, | ||
44 | 0x00040810, 0x10080400, 0x001c2220, 0x10080008, | ||
45 | 0x001c322a, 0x1a021c00, 0x001c2222, 0x3e222200, | ||
46 | 0x001e221e, 0x22221e00, 0x001c2202, 0x02221c00, | ||
47 | 0x000e1222, 0x22120e00, 0x003e021e, 0x02023e00, | ||
48 | 0x003e021e, 0x02020200, 0x001c2202, 0x32221c00, | ||
49 | 0x00222222, 0x3e222200, 0x003e0808, 0x08083e00, | ||
50 | 0x00202020, 0x22221c00, 0x0022120a, 0x0e122200, | ||
51 | 0x00020202, 0x02023e00, 0x0022362a, 0x22222200, | ||
52 | 0x0022262a, 0x32222200, 0x001c2222, 0x22221c00, | ||
53 | 0x001e2222, 0x1e020200, 0x001c2222, 0x2a122c00, | ||
54 | 0x001e2222, 0x1e122200, 0x001c021c, 0x20221c00, | ||
55 | 0x003e0808, 0x08080800, 0x00222222, 0x22221c00, | ||
56 | 0x00222222, 0x22140800, 0x0022222a, 0x2a2a1400, | ||
57 | 0x00221408, 0x08142200, 0x00222214, 0x08080800, | ||
58 | 0x003e1008, 0x04023e00, 0x1c040404, 0x0404041c, | ||
59 | 0x0002060c, 0x18302000, 0x1c101010, 0x1010101c, | ||
60 | 0x08142200, 0x00000000, 0x00000000, 0x00003e00, | ||
61 | 0x00040810, 0x00000000, 0x00001c20, 0x3c223c00, | ||
62 | 0x0002021e, 0x22221e00, 0x00001c22, 0x02221c00, | ||
63 | 0x0020203c, 0x22223c00, 0x00001c22, 0x1e023c00, | ||
64 | 0x00003c02, 0x021e0202, 0x00003c22, 0x223c201c, | ||
65 | 0x0002021e, 0x22222200, 0x0008000c, 0x08083e00, | ||
66 | 0x00200020, 0x2020221c, 0x0002120a, 0x060a3200, | ||
67 | 0x000c0808, 0x08083e00, 0x0000162a, 0x2a2a2a00, | ||
68 | 0x00000e32, 0x22222200, 0x00001c22, 0x22221c00, | ||
69 | 0x00001e22, 0x221e0202, 0x00003c22, 0x223c2070, | ||
70 | 0x00001a26, 0x02020200, 0x00001c02, 0x1c201e00, | ||
71 | 0x00043e04, 0x04041800, 0x00002222, 0x22221c00, | ||
72 | 0x00002222, 0x22140800, 0x00002222, 0x2a2a1400, | ||
73 | 0x00002214, 0x08142200, 0x00002222, 0x223c201c, | ||
74 | 0x00003e10, 0x08043e00, 0x18040402, 0x02040418, | ||
75 | 0x00080808, 0x08080808, 0x0c101020, 0x2010100c, | ||
76 | 0x00002c1a, 0x00000000, 0x00000814, 0x22223e00, | ||
77 | 0x001c2202, 0x221c080e, 0x00140022, 0x2222221c, | ||
78 | 0x1008001c, 0x221e023c, 0x0814001c, 0x203c223c, | ||
79 | 0x0014001c, 0x203c223c, 0x0408001c, 0x203c223c, | ||
80 | 0x0814081c, 0x203c223c, 0x00001c02, 0x221c080e, | ||
81 | 0x0814001c, 0x221e023c, 0x0014001c, 0x221e023c, | ||
82 | 0x0408001c, 0x221e023c, 0x0014000c, 0x0808083e, | ||
83 | 0x0014000c, 0x0808083e, 0x0408000c, 0x0808083e, | ||
84 | 0x0014001c, 0x223e2222, 0x0814081c, 0x223e2222, | ||
85 | 0x1008003e, 0x021e023e, 0x00001628, 0x1c0a3400, | ||
86 | 0x003c0a1a, 0x0e0a3a00, 0x0814001c, 0x2222221c, | ||
87 | 0x0014001c, 0x2222221c, 0x0408001c, 0x2222221c, | ||
88 | 0x08140022, 0x2222221c, 0x04080022, 0x2222221c, | ||
89 | 0x00140022, 0x223c201c, 0x14001c22, 0x2222221c, | ||
90 | 0x14002222, 0x2222221c, 0x00081c22, 0x02221c08, | ||
91 | 0x0018240e, 0x04043e00, 0x00221408, 0x1c081c08, | ||
92 | 0x0038041e, 0x041e0438, 0x0030081c, 0x08080806, | ||
93 | 0x1008001c, 0x203c223c, 0x1008000c, 0x0808083e, | ||
94 | 0x1008001c, 0x2222221c, 0x10080022, 0x2222221c, | ||
95 | 0x2c1a000e, 0x32222222, 0x2c1a0022, 0x262a3222, | ||
96 | 0x001c122c, 0x001e0000, 0x000c120c, 0x001e0000, | ||
97 | 0x08000804, 0x02221c00, 0x0000003e, 0x02020000, | ||
98 | 0x0000003e, 0x20200000, 0x06241468, 0x4422f000, | ||
99 | 0x06241468, 0x54f24000, 0x08000808, 0x08080800, | ||
100 | 0x00482412, 0x24480000, 0x00122448, 0x24120000, | ||
101 | 0x00880022, 0x00880022, 0x55885522, 0x55885522, | ||
102 | 0x55aa55aa, 0x55aa55aa, 0x08080808, 0x08080808, | ||
103 | 0x0808080f, 0x08080808, 0x08080f08, 0x0f080808, | ||
104 | 0x14141417, 0x14141414, 0x0000001f, 0x14141414, | ||
105 | 0x00000f08, 0x0f080808, 0x14141710, 0x17141414, | ||
106 | 0x14141414, 0x14141414, 0x00001f10, 0x17141414, | ||
107 | 0x14141710, 0x1f000000, 0x1414141f, 0x00000000, | ||
108 | 0x08080f08, 0x0f000000, 0x0000000f, 0x08080808, | ||
109 | 0x080808f8, 0x00000000, 0x080808ff, 0x00000000, | ||
110 | 0x000000ff, 0x08080808, 0x080808f8, 0x08080808, | ||
111 | 0x000000ff, 0x00000000, 0x080808ff, 0x08080808, | ||
112 | 0x0808f808, 0xf8080808, 0x141414f4, 0x14141414, | ||
113 | 0x1414f404, 0xfc000000, 0x0000fc04, 0xf4141414, | ||
114 | 0x1414f700, 0xff000000, 0x0000ff00, 0xf7141414, | ||
115 | 0x1414f404, 0xf4141414, 0x0000ff00, 0xff000000, | ||
116 | 0x1414f700, 0xf7141414, 0x0808ff00, 0xff000000, | ||
117 | 0x141414ff, 0x00000000, 0x0000ff00, 0xff080808, | ||
118 | 0x000000ff, 0x14141414, 0x141414fc, 0x00000000, | ||
119 | 0x0808f808, 0xf8000000, 0x0000f808, 0xf8080808, | ||
120 | 0x000000fc, 0x14141414, 0x141414ff, 0x14141414, | ||
121 | 0x0808ff08, 0xff080808, 0x0808080f, 0x00000000, | ||
122 | 0x000000f8, 0x08080808, 0xffffffff, 0xffffffff, | ||
123 | 0x00000000, 0xffffffff, 0x0f0f0f0f, 0x0f0f0f0f, | ||
124 | 0xf0f0f0f0, 0xf0f0f0f0, 0xffffffff, 0x00000000, | ||
125 | 0x00002c12, 0x12122c00, 0x000c120a, 0x12223a02, | ||
126 | 0x003e2202, 0x02020200, 0x00003e14, 0x14141400, | ||
127 | 0x3e220408, 0x04223e00, 0x00003c12, 0x12120c00, | ||
128 | 0x00002222, 0x221e0202, 0x002c1a08, 0x08281000, | ||
129 | 0x1c081c22, 0x221c081c, 0x1c22223e, 0x22221c00, | ||
130 | 0x1c222222, 0x22143600, 0x1e041824, 0x22221c00, | ||
131 | 0x0000142a, 0x2a140000, 0x0020142a, 0x2a140200, | ||
132 | 0x00003c02, 0x1c023c00, 0x001c2222, 0x22222202, | ||
133 | 0x00003e00, 0x3e003e00, 0x0000081c, 0x08001c00, | ||
134 | 0x04081008, 0x04001c00, 0x10080408, 0x10001c00, | ||
135 | 0x30480808, 0x08080808, 0x08080808, 0x08080906, | ||
136 | 0x00000800, 0x3e000800, 0x00004c32, 0x004c3200, | ||
137 | 0x00182418, 0x00000000, 0x00001c1c, 0x1c000000, | ||
138 | 0x00000018, 0x18000000, 0x00f01010, 0x10121418, | ||
139 | 0x0c342424, 0x00000000, 0x1810083c, 0x00000000, | ||
140 | 0x00003c3c, 0x3c3c0000, 0x00000000, 0x00000000, | ||
141 | }; | ||
diff --git a/src/filesystem.h b/src/filesystem.h index d50e5e7..6439f83 100644 --- a/src/filesystem.h +++ b/src/filesystem.h | |||
@@ -1,7 +1,7 @@ | |||
1 | #ifndef FILESYSTEM_H | 1 | #ifndef FILESYSTEM_H |
2 | #define FILESYSTEM_H | 2 | #define FILESYSTEM_H |
3 | 3 | ||
4 | #include "common.h" | 4 | #include "gba/gba.h" |
5 | 5 | ||
6 | typedef enum { | 6 | typedef enum { |
7 | FS_OPEN_READ = (1 << 0), | 7 | FS_OPEN_READ = (1 << 0), |
diff --git a/src/bios_calls.s b/src/gba/bios_calls.s index 740fa02..740fa02 100644 --- a/src/bios_calls.s +++ b/src/gba/bios_calls.s | |||
diff --git a/src/common.h b/src/gba/gba.h index fbe01a4..56c4876 100644 --- a/src/common.h +++ b/src/gba/gba.h | |||
@@ -1,5 +1,5 @@ | |||
1 | #ifndef COMMON_H | 1 | #ifndef GBA_H |
2 | #define COMMON_H | 2 | #define GBA_H |
3 | 3 | ||
4 | #include "shorthand.h" | 4 | #include "shorthand.h" |
5 | 5 | ||
@@ -664,4 +664,4 @@ wait_vsync(void) { | |||
664 | #define EWRAM_CODE __attribute__((section(".ewram"), long_call)) | 664 | #define EWRAM_CODE __attribute__((section(".ewram"), long_call)) |
665 | #define EWRAM_BSS __attribute__((section(".sbss"))) | 665 | #define EWRAM_BSS __attribute__((section(".sbss"))) |
666 | 666 | ||
667 | #endif // COMMON_H | 667 | #endif // GBA_H |
diff --git a/src/interrupts.c b/src/gba/interrupts.c index 8e560dc..3b11335 100644 --- a/src/interrupts.c +++ b/src/gba/interrupts.c | |||
@@ -1,4 +1,4 @@ | |||
1 | #include "common.h" | 1 | #include "gba.h" |
2 | 2 | ||
3 | IrsFunc irs_table[] = { | 3 | IrsFunc irs_table[] = { |
4 | [IRQ_VBLANK ] = NULL, | 4 | [IRQ_VBLANK ] = NULL, |
diff --git a/src/interrupts.s b/src/gba/interrupts.s index 67b9fe9..67b9fe9 100644 --- a/src/interrupts.s +++ b/src/gba/interrupts.s | |||
@@ -9,12 +9,11 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |||
9 | WITH REGARD TO THIS SOFTWARE. | 9 | WITH REGARD TO THIS SOFTWARE. |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include "common.h" | 12 | #include "gba/gba.h" |
13 | // #include "text.h" | ||
14 | 13 | ||
15 | #include "interrupts.c" | ||
16 | #include "filesystem.c" | 14 | #include "filesystem.c" |
17 | #include "renderer.c" | 15 | #include "renderer.c" |
16 | // #include "text.h" | ||
18 | 17 | ||
19 | // | 18 | // |
20 | // Config parameters. | 19 | // Config parameters. |
@@ -62,6 +61,10 @@ int main(void) { | |||
62 | irq_init(); | 61 | irq_init(); |
63 | irs_set(IRQ_VBLANK, irs_stub); | 62 | irs_set(IRQ_VBLANK, irs_stub); |
64 | 63 | ||
64 | draw_pixel(10, 0, 1); | ||
65 | draw_pixel(10, 1, 2); | ||
66 | draw_pixel(10, 2, 3); | ||
67 | draw_pixel(10, 3, 4); | ||
65 | draw_pixel(0, 0, 1); | 68 | draw_pixel(0, 0, 1); |
66 | draw_pixel(0, 1, 2); | 69 | draw_pixel(0, 1, 2); |
67 | draw_pixel(0, 2, 3); | 70 | draw_pixel(0, 2, 3); |
diff --git a/src/renderer.c b/src/renderer.c index 9fe55b2..ec54411 100644 --- a/src/renderer.c +++ b/src/renderer.c | |||
@@ -1,14 +1,28 @@ | |||
1 | // TODO: For now we pack front/backbuffers together but this make it so that we | 1 | #include "bd-font.c" |
2 | // can only use 2 backgrounds. Instead we can move the backbuffer to the end of | 2 | |
3 | // the VRAM. This will give us 3 backgrounds but eats into the available memory | 3 | // The frontbuffer is located at the beginning of the VRAM, and requires 20KB of |
4 | // for sprites but should be fine for non sprite intensive applications. | 4 | // video memory for 32 * 20 tiles at 4bpp. |
5 | #define FRONTBUFFER ((u32*)(MEM_VRAM)) | 5 | #define FRONTBUF ((u32*)(MEM_VRAM)) |
6 | #define BACKBUFFER ((u32*)(MEM_VRAM + KB(96) - KB(20))) | ||
7 | 6 | ||
8 | // Adjust both of these if the location of the map changes. Each screnblock | 7 | // Adjust both of these if the location of the map changes. Each screnblock |
9 | // requires 2K. | 8 | // requires less than 2KB. |
10 | #define FRONTBUFFER_TILEMAP ((u16*)(MEM_VRAM + KB(20))) | 9 | #define FRONTBUF_TILEMAP ((u16*)(MEM_VRAM + KB(20))) |
11 | #define FRONTBUFFER_SCREENBLOCK 10 | 10 | #define FRONTBUF_SB 10 |
11 | |||
12 | // The backbuffer is located at the end of the VRAM. This can allow us to use | ||
13 | // more backgrounds but eats into the available memory for sprites. This should | ||
14 | // be fine for non sprite intensive applications. If more sprite memory is | ||
15 | // needed, the backbuffer can be located at the end of the background memory | ||
16 | // instead (64KB - 20KB). | ||
17 | #define BACKBUF ((u32*)(MEM_VRAM + KB(96) - KB(20))) | ||
18 | |||
19 | // The font data is located at the end of the frontbuffer memory, after the tile | ||
20 | // map and requires 8KB for 256 8x8 characters at 4bpp. This, along with the | ||
21 | // tilemap information allow us to store the frontbuffer and font for a text | ||
22 | // background in the first 2 charblocks (32KB). | ||
23 | #define FONT_DATA ((u32*)(MEM_VRAM + KB(22))) | ||
24 | #define FONT_TILEMAP ((u16*)(MEM_VRAM + KB(30))) | ||
25 | #define FONT_SB 15 | ||
12 | 26 | ||
13 | static u32 dirty_tiles[21] = {0}; | 27 | static u32 dirty_tiles[21] = {0}; |
14 | 28 | ||
@@ -29,7 +43,7 @@ draw_pixel(u16 x, u16 y, u8 color) { | |||
29 | 43 | ||
30 | // Update backbuffer. | 44 | // Update backbuffer. |
31 | size_t shift = start_col * sizeof(u32); | 45 | size_t shift = start_col * sizeof(u32); |
32 | BACKBUFFER[pos] = (BACKBUFFER[pos] & ~(0xF << shift)) | color << shift; | 46 | BACKBUF[pos] = (BACKBUF[pos] & ~(0xF << shift)) | color << shift; |
33 | 47 | ||
34 | // Mark tile as dirty. | 48 | // Mark tile as dirty. |
35 | dirty_tiles[tile_y] |= 1 << tile_x; | 49 | dirty_tiles[tile_y] |= 1 << tile_x; |
@@ -39,8 +53,8 @@ IWRAM_CODE | |||
39 | void | 53 | void |
40 | flip_buffer(void) { | 54 | flip_buffer(void) { |
41 | // Copy dirty tiles from the backbuffer to the frontbuffer. | 55 | // Copy dirty tiles from the backbuffer to the frontbuffer. |
42 | Tile *dst = FRONTBUFFER; | 56 | Tile *dst = FRONTBUF; |
43 | Tile *src = BACKBUFFER; | 57 | Tile *src = BACKBUF; |
44 | for (size_t j = 0; j < 20; ++j) { | 58 | for (size_t j = 0; j < 20; ++j) { |
45 | if (dirty_tiles[j] == 0) { | 59 | if (dirty_tiles[j] == 0) { |
46 | continue; | 60 | continue; |
@@ -54,19 +68,23 @@ flip_buffer(void) { | |||
54 | } | 68 | } |
55 | } | 69 | } |
56 | 70 | ||
71 | static u16 font_map[256] = {0}; | ||
72 | |||
57 | void | 73 | void |
58 | renderer_init(void) { | 74 | renderer_init(void) { |
59 | // Initialize display mode and bg palette. | 75 | // Initialize display mode and bg palette. |
60 | DISP_CTRL = DISP_MODE_0 | DISP_BG_0 | DISP_OBJ; | 76 | DISP_CTRL = DISP_MODE_0 | DISP_BG_0 | DISP_BG_1 | DISP_OBJ; |
61 | 77 | ||
62 | // Initialize backgrounds. | 78 | // Initialize backgrounds. |
63 | BG_CTRL(0) = BG_CHARBLOCK(0) | BG_SCREENBLOCK(FRONTBUFFER_SCREENBLOCK); | 79 | BG_CTRL(0) = BG_CHARBLOCK(0) | BG_SCREENBLOCK(FRONTBUF_SB) | BG_PRIORITY(1); |
80 | BG_CTRL(1) = BG_CHARBLOCK(1) | BG_SCREENBLOCK(FONT_SB) | BG_PRIORITY(0); | ||
64 | 81 | ||
65 | // TODO: Initialize other backgrounds if needed. | 82 | // Use DMA to clear front and back buffers as well as the font memory map. |
66 | 83 | dma_fill(FRONTBUF, 0, KB(20), 3); | |
67 | // Use DMA to clear front and back buffers. | 84 | dma_fill(FRONTBUF_TILEMAP, 0, KB(2), 3); |
68 | dma_fill(FRONTBUFFER, 0, KB(20), 3); | 85 | dma_fill(FONT_DATA, 0, KB(8), 3); |
69 | dma_fill(BACKBUFFER, 0, KB(20), 3); | 86 | dma_fill(FONT_TILEMAP, 0, KB(2), 3); |
87 | dma_fill(BACKBUF, 0, KB(20), 3); | ||
70 | 88 | ||
71 | // Initialize default palette. | 89 | // Initialize default palette. |
72 | PAL_BUFFER_BG[0] = COLOR_BLACK; | 90 | PAL_BUFFER_BG[0] = COLOR_BLACK; |
@@ -76,11 +94,18 @@ renderer_init(void) { | |||
76 | PAL_BUFFER_BG[4] = COLOR_CYAN; | 94 | PAL_BUFFER_BG[4] = COLOR_CYAN; |
77 | PAL_BUFFER_BG[5] = COLOR_GREY; | 95 | PAL_BUFFER_BG[5] = COLOR_GREY; |
78 | 96 | ||
79 | // Initialize background memory map. | 97 | // Initialize background memory map for frontbuffer and font backgorund. |
80 | for (size_t i = 0; i < 32 * 20; ++i) { | 98 | for (size_t i = 0; i < 32 * 20; ++i) { |
81 | FRONTBUFFER_TILEMAP[i] = i; | 99 | FRONTBUF_TILEMAP[i] = i; |
82 | } | 100 | } |
83 | 101 | ||
84 | // // Load font data into VRAM. | 102 | // Load font data into VRAM. |
85 | // unpack_tiles(&bd_font, FONT_DATA, 256); | 103 | unpack_tiles(&bd_font, FONT_DATA, 256); |
104 | |||
105 | // Initialize the font map translation table. That way we can write | ||
106 | // a character on the text background layer with: | ||
107 | // FONT_TILEMAP[tile_x + 32 * tile_y] = font_map['A']; | ||
108 | for (size_t i = 0; i < 256; ++i) { | ||
109 | font_map[i] = 192 + i; | ||
110 | } | ||
86 | } | 111 | } |