diff options
author | Bad Diode <bd@badd10de.dev> | 2021-05-23 14:21:57 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2021-05-23 14:21:57 +0200 |
commit | b6878ffcd291a64bd1ab463e3da017a195bc2d0f (patch) | |
tree | a9004bda711ce8a8eca932a52037a5d2cc796cbb /src | |
parent | e73d10d09e10f2002122ea8d2cd878951b7eda0e (diff) | |
download | uxngba-b6878ffcd291a64bd1ab463e3da017a195bc2d0f.tar.gz uxngba-b6878ffcd291a64bd1ab463e3da017a195bc2d0f.zip |
Update VRAM map to free space for sprite data
Diffstat (limited to 'src')
-rw-r--r-- | src/common.h | 4 | ||||
-rw-r--r-- | src/main.c | 5 | ||||
-rw-r--r-- | src/text.h | 4 | ||||
-rw-r--r-- | src/uxn/devices/ppu.c | 76 | ||||
-rw-r--r-- | src/uxn/uxn.c | 1 |
5 files changed, 41 insertions, 49 deletions
diff --git a/src/common.h b/src/common.h index 5d3f497..049533e 100644 --- a/src/common.h +++ b/src/common.h | |||
@@ -417,8 +417,8 @@ dma_copy(void *dst, const void *src, u32 size, int channel) { | |||
417 | 417 | ||
418 | // Fill the dst location with the word set at src. | 418 | // Fill the dst location with the word set at src. |
419 | inline void | 419 | inline void |
420 | dma_fill(void *dst, const void *src, u32 size, int channel) { | 420 | dma_fill(void *dst, vu32 src, u32 size, int channel) { |
421 | dma_transfer_fill(dst, (volatile u32)src, size / 4, channel, DMA_CHUNK_32 | DMA_ENABLE); | 421 | dma_transfer_fill(dst, src, size / 4, channel, DMA_CHUNK_32 | DMA_ENABLE); |
422 | } | 422 | } |
423 | 423 | ||
424 | // | 424 | // |
@@ -5,11 +5,12 @@ | |||
5 | #include "bd-font.c" | 5 | #include "bd-font.c" |
6 | #include "filesystem.c" | 6 | #include "filesystem.c" |
7 | 7 | ||
8 | #include "rom.c" | ||
8 | #include "uxn/uxn.h" | 9 | #include "uxn/uxn.h" |
9 | #include "uxn/uxn.c" | 10 | #include "uxn/uxn.c" |
10 | #include "uxn/devices/ppu.h" | 11 | #include "uxn/devices/ppu.h" |
11 | #include "uxn/devices/ppu.c" | 12 | #include "uxn/devices/ppu.c" |
12 | #include "uxn/roms/boot.c" | 13 | |
13 | #include "text.h" | 14 | #include "text.h" |
14 | 15 | ||
15 | /* | 16 | /* |
@@ -286,7 +287,7 @@ int main(void) { | |||
286 | .data = bd_font, | 287 | .data = bd_font, |
287 | .char_height = 8, | 288 | .char_height = 8, |
288 | .char_width = 8, | 289 | .char_width = 8, |
289 | }, &ppu.fg); | 290 | }, ppu.fg); |
290 | txt_position(0,0); | 291 | txt_position(0,0); |
291 | 292 | ||
292 | // Main loop. | 293 | // Main loop. |
@@ -6,6 +6,8 @@ | |||
6 | 6 | ||
7 | #include "common.h" | 7 | #include "common.h" |
8 | #include "bitmap.h" | 8 | #include "bitmap.h" |
9 | #include "posprintf.h" | ||
10 | |||
9 | 11 | ||
10 | typedef enum { | 12 | typedef enum { |
11 | TXT_MODE_TILED_BG, | 13 | TXT_MODE_TILED_BG, |
@@ -246,7 +248,7 @@ txt_init_hybrid(TextMode mode, Font font, u32 *buf) { | |||
246 | // Prepare text engine. | 248 | // Prepare text engine. |
247 | text_engine.font = font; | 249 | text_engine.font = font; |
248 | text_engine.mode = mode; | 250 | text_engine.mode = mode; |
249 | text_engine.memory = *buf; | 251 | text_engine.memory = buf; |
250 | } | 252 | } |
251 | 253 | ||
252 | // Print text to the screen with formatting. | 254 | // Print text to the screen with formatting. |
diff --git a/src/uxn/devices/ppu.c b/src/uxn/devices/ppu.c index 726b510..4db8c77 100644 --- a/src/uxn/devices/ppu.c +++ b/src/uxn/devices/ppu.c | |||
@@ -14,23 +14,11 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |||
14 | WITH REGARD TO THIS SOFTWARE. | 14 | WITH REGARD TO THIS SOFTWARE. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | static Uint8 font[][8] = { | 17 | #define FG_FRONT ((u32*)(MEM_VRAM)) |
18 | {0x00, 0x7c, 0x82, 0x82, 0x82, 0x82, 0x82, 0x7c}, | 18 | #define BG_FRONT ((u32*)(MEM_VRAM + KB(20))) |
19 | {0x00, 0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10}, | 19 | #define FG_BACK ((u32*)(MEM_VRAM + KB(44))) |
20 | {0x00, 0x7c, 0x82, 0x02, 0x7c, 0x80, 0x80, 0xfe}, | 20 | #define BG_BACK ((u32*)(MEM_VRAM + KB(64))) |
21 | {0x00, 0x7c, 0x82, 0x02, 0x1c, 0x02, 0x82, 0x7c}, | 21 | #define TILE_MAP ((u32*)(MEM_VRAM + KB(40))) |
22 | {0x00, 0x0c, 0x14, 0x24, 0x44, 0x84, 0xfe, 0x04}, | ||
23 | {0x00, 0xfe, 0x80, 0x80, 0x7c, 0x02, 0x82, 0x7c}, | ||
24 | {0x00, 0x7c, 0x82, 0x80, 0xfc, 0x82, 0x82, 0x7c}, | ||
25 | {0x00, 0x7c, 0x82, 0x02, 0x1e, 0x02, 0x02, 0x02}, | ||
26 | {0x00, 0x7c, 0x82, 0x82, 0x7c, 0x82, 0x82, 0x7c}, | ||
27 | {0x00, 0x7c, 0x82, 0x82, 0x7e, 0x02, 0x82, 0x7c}, | ||
28 | {0x00, 0x7c, 0x82, 0x02, 0x7e, 0x82, 0x82, 0x7e}, | ||
29 | {0x00, 0xfc, 0x82, 0x82, 0xfc, 0x82, 0x82, 0xfc}, | ||
30 | {0x00, 0x7c, 0x82, 0x80, 0x80, 0x80, 0x82, 0x7c}, | ||
31 | {0x00, 0xfc, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfc}, | ||
32 | {0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x82, 0x7c}, | ||
33 | {0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80}}; | ||
34 | 22 | ||
35 | static Uint32 unpack_icon_lut[256] = { | 23 | static Uint32 unpack_icon_lut[256] = { |
36 | 0x00000000, 0x00000001, 0x00000010, 0x00000011, 0x00000100, | 24 | 0x00000000, 0x00000001, 0x00000010, 0x00000011, 0x00000100, |
@@ -157,6 +145,7 @@ putcolors(Ppu *p, Uint8 *addr) { | |||
157 | (g << 1) | (g >> 3), | 145 | (g << 1) | (g >> 3), |
158 | (b << 1) | (b >> 3)); | 146 | (b << 1) | (b >> 3)); |
159 | } | 147 | } |
148 | (void)p; | ||
160 | } | 149 | } |
161 | 150 | ||
162 | IWRAM_CODE | 151 | IWRAM_CODE |
@@ -171,6 +160,7 @@ putpixel(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 color) { | |||
171 | size_t shift = start_col * 4; | 160 | size_t shift = start_col * 4; |
172 | layer[pos] = (layer[pos] & (~(0xF << shift))) | (color << shift); | 161 | layer[pos] = (layer[pos] & (~(0xF << shift))) | (color << shift); |
173 | dirty_tiles[tile_y] |= 1 << tile_x; | 162 | dirty_tiles[tile_y] |= 1 << tile_x; |
163 | (void)p; | ||
174 | } | 164 | } |
175 | 165 | ||
176 | IWRAM_CODE | 166 | IWRAM_CODE |
@@ -221,6 +211,7 @@ puticn(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Ui | |||
221 | 211 | ||
222 | dirty_tiles[y >> 3] |= dirtyflag; | 212 | dirty_tiles[y >> 3] |= dirtyflag; |
223 | dirty_tiles[(y + 7) >> 3] |= dirtyflag; | 213 | dirty_tiles[(y + 7) >> 3] |= dirtyflag; |
214 | (void)p; | ||
224 | } | 215 | } |
225 | 216 | ||
226 | IWRAM_CODE | 217 | IWRAM_CODE |
@@ -263,13 +254,14 @@ putchr(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, | |||
263 | 254 | ||
264 | dirty_tiles[y >> 3] |= dirtyflag; | 255 | dirty_tiles[y >> 3] |= dirtyflag; |
265 | dirty_tiles[(y + 7) >> 3] |= dirtyflag; | 256 | dirty_tiles[(y + 7) >> 3] |= dirtyflag; |
257 | (void)p; | ||
266 | } | 258 | } |
267 | 259 | ||
268 | IWRAM_CODE | 260 | IWRAM_CODE |
269 | void | 261 | void |
270 | flipbuf(Ppu *p) { | 262 | flipbuf(Ppu *p) { |
271 | Tile *mem_fg = &TILE_MEM[0]; | 263 | Tile *mem_fg = FG_FRONT; |
272 | Tile *mem_bg = &TILE_MEM[2]; | 264 | Tile *mem_bg = BG_FRONT; |
273 | for (size_t j = 0; j < 20; ++j) { | 265 | for (size_t j = 0; j < 20; ++j) { |
274 | if (dirty_tiles[j] == 0) { | 266 | if (dirty_tiles[j] == 0) { |
275 | continue; | 267 | continue; |
@@ -301,32 +293,26 @@ initppu(Ppu *p, Uint8 hor, Uint8 ver, Uint8 pad) { | |||
301 | 293 | ||
302 | // Initialize backgrounds. | 294 | // Initialize backgrounds. |
303 | u8 cb_fg = 0; | 295 | u8 cb_fg = 0; |
304 | u8 cb_bg = 2; | 296 | u8 cb_bg = 1; |
305 | u8 sb_idx = 10; | 297 | u8 sb_fg = 20; |
306 | BG_CTRL(0) = BG_CHARBLOCK(cb_fg) | BG_SCREENBLOCK(sb_idx) | BG_PRIORITY(1); | 298 | u8 sb_bg = 21; |
307 | BG_CTRL(1) = BG_CHARBLOCK(cb_bg) | BG_SCREENBLOCK(sb_idx) | BG_PRIORITY(2); | 299 | BG_CTRL(0) = BG_CHARBLOCK(cb_fg) | BG_SCREENBLOCK(sb_fg) | BG_PRIORITY(1); |
308 | 300 | BG_CTRL(1) = BG_CHARBLOCK(cb_bg) | BG_SCREENBLOCK(sb_bg) | BG_PRIORITY(2); | |
309 | // Clear tile memory. | 301 | |
310 | for (size_t i = 0; i < 32 * 20 * 8; ++i) { | 302 | // Clear front buffer. |
311 | p->fg[i] = 0; | 303 | p->fg = FG_FRONT; |
312 | p->bg[i] = 0; | 304 | p->bg = BG_FRONT; |
313 | } | ||
314 | 305 | ||
315 | // Use DMA to clear VRAM. | 306 | // Use DMA to clear VRAM. |
316 | u32 fill = 0; | 307 | u32 fill = 0; |
317 | u32 tile_clear_ctrl = (32 * 20 * 8) | DMA_DST_INC | DMA_SRC_FIXED | DMA_NOW | DMA_CHUNK_32 | DMA_ENABLE; | 308 | dma_fill(p->fg, fill, KB(20), 3); |
318 | DMA_SRC(3) = &fill; | 309 | dma_fill(p->bg, fill, KB(20), 3); |
319 | DMA_DST(3) = p->fg; | 310 | |
320 | DMA_CTRL(3) = tile_clear_ctrl; | 311 | // Clear back buffer. |
321 | DMA_DST(3) = p->bg; | 312 | p->fg = FG_BACK; |
322 | DMA_CTRL(3) = tile_clear_ctrl; | 313 | p->bg = BG_BACK; |
323 | 314 | dma_fill(p->fg, fill, KB(20), 3); | |
324 | p->fg = (u32*) (MEM_VRAM + (56 * 1024)); // 0-20K front, 32K-52K back | 315 | dma_fill(p->bg, fill, KB(20), 3); |
325 | p->bg = (u32*) (MEM_VRAM + (76 * 1024)); // 56K-76K front, 76K-96K back | ||
326 | DMA_DST(3) = p->fg; | ||
327 | DMA_CTRL(3) = tile_clear_ctrl; | ||
328 | DMA_DST(3) = p->bg; | ||
329 | DMA_CTRL(3) = tile_clear_ctrl; | ||
330 | 316 | ||
331 | // Initialize default palette. | 317 | // Initialize default palette. |
332 | PAL_BUFFER_BG[0] = COLOR_BLACK; | 318 | PAL_BUFFER_BG[0] = COLOR_BLACK; |
@@ -335,10 +321,12 @@ initppu(Ppu *p, Uint8 hor, Uint8 ver, Uint8 pad) { | |||
335 | PAL_BUFFER_BG[3] = COLOR_BLUE; | 321 | PAL_BUFFER_BG[3] = COLOR_BLUE; |
336 | 322 | ||
337 | // Initialize memory map. | 323 | // Initialize memory map. |
338 | u16 *mem_map = SCREENBLOCK_MEM[sb_idx]; | 324 | u16 *mem_map_fg = SCREENBLOCK_MEM[sb_fg]; |
325 | u16 *mem_map_bg = SCREENBLOCK_MEM[sb_bg]; | ||
339 | size_t k = 0; | 326 | size_t k = 0; |
340 | for (size_t i = 0; i < 32 * 20; ++i, ++k) { | 327 | for (size_t i = 0; i < 32 * 20; ++i, ++k) { |
341 | mem_map[i] = k; | 328 | mem_map_fg[i] = k; |
329 | mem_map_bg[i] = k + 32 * 4; | ||
342 | } | 330 | } |
343 | 331 | ||
344 | return 1; | 332 | return 1; |
diff --git a/src/uxn/uxn.c b/src/uxn/uxn.c index 8ae5586..e8ae9f7 100644 --- a/src/uxn/uxn.c +++ b/src/uxn/uxn.c | |||
@@ -3763,5 +3763,6 @@ portuxn(Uxn *u, Uint8 id, char *name, void (*talkfn)(Device *d, Uint8 b0, Uint8 | |||
3763 | d->u = u; | 3763 | d->u = u; |
3764 | d->mem = u->ram.dat; | 3764 | d->mem = u->ram.dat; |
3765 | d->talk = talkfn; | 3765 | d->talk = talkfn; |
3766 | (void)name; | ||
3766 | return d; | 3767 | return d; |
3767 | } | 3768 | } |