From b6878ffcd291a64bd1ab463e3da017a195bc2d0f Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Sun, 23 May 2021 14:21:57 +0200 Subject: Update VRAM map to free space for sprite data --- src/common.h | 4 +-- src/main.c | 5 ++-- src/text.h | 4 ++- src/uxn/devices/ppu.c | 76 ++++++++++++++++++++++----------------------------- src/uxn/uxn.c | 1 + 5 files changed, 41 insertions(+), 49 deletions(-) (limited to 'src') 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) { // Fill the dst location with the word set at src. inline void -dma_fill(void *dst, const void *src, u32 size, int channel) { - dma_transfer_fill(dst, (volatile u32)src, size / 4, channel, DMA_CHUNK_32 | DMA_ENABLE); +dma_fill(void *dst, vu32 src, u32 size, int channel) { + dma_transfer_fill(dst, src, size / 4, channel, DMA_CHUNK_32 | DMA_ENABLE); } // diff --git a/src/main.c b/src/main.c index 40be7b9..5e0aad1 100644 --- a/src/main.c +++ b/src/main.c @@ -5,11 +5,12 @@ #include "bd-font.c" #include "filesystem.c" +#include "rom.c" #include "uxn/uxn.h" #include "uxn/uxn.c" #include "uxn/devices/ppu.h" #include "uxn/devices/ppu.c" -#include "uxn/roms/boot.c" + #include "text.h" /* @@ -286,7 +287,7 @@ int main(void) { .data = bd_font, .char_height = 8, .char_width = 8, - }, &ppu.fg); + }, ppu.fg); txt_position(0,0); // Main loop. diff --git a/src/text.h b/src/text.h index 06e3973..c27537f 100644 --- a/src/text.h +++ b/src/text.h @@ -6,6 +6,8 @@ #include "common.h" #include "bitmap.h" +#include "posprintf.h" + typedef enum { TXT_MODE_TILED_BG, @@ -246,7 +248,7 @@ txt_init_hybrid(TextMode mode, Font font, u32 *buf) { // Prepare text engine. text_engine.font = font; text_engine.mode = mode; - text_engine.memory = *buf; + text_engine.memory = buf; } // 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 WITH REGARD TO THIS SOFTWARE. */ -static Uint8 font[][8] = { - {0x00, 0x7c, 0x82, 0x82, 0x82, 0x82, 0x82, 0x7c}, - {0x00, 0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10}, - {0x00, 0x7c, 0x82, 0x02, 0x7c, 0x80, 0x80, 0xfe}, - {0x00, 0x7c, 0x82, 0x02, 0x1c, 0x02, 0x82, 0x7c}, - {0x00, 0x0c, 0x14, 0x24, 0x44, 0x84, 0xfe, 0x04}, - {0x00, 0xfe, 0x80, 0x80, 0x7c, 0x02, 0x82, 0x7c}, - {0x00, 0x7c, 0x82, 0x80, 0xfc, 0x82, 0x82, 0x7c}, - {0x00, 0x7c, 0x82, 0x02, 0x1e, 0x02, 0x02, 0x02}, - {0x00, 0x7c, 0x82, 0x82, 0x7c, 0x82, 0x82, 0x7c}, - {0x00, 0x7c, 0x82, 0x82, 0x7e, 0x02, 0x82, 0x7c}, - {0x00, 0x7c, 0x82, 0x02, 0x7e, 0x82, 0x82, 0x7e}, - {0x00, 0xfc, 0x82, 0x82, 0xfc, 0x82, 0x82, 0xfc}, - {0x00, 0x7c, 0x82, 0x80, 0x80, 0x80, 0x82, 0x7c}, - {0x00, 0xfc, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfc}, - {0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x82, 0x7c}, - {0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80}}; +#define FG_FRONT ((u32*)(MEM_VRAM)) +#define BG_FRONT ((u32*)(MEM_VRAM + KB(20))) +#define FG_BACK ((u32*)(MEM_VRAM + KB(44))) +#define BG_BACK ((u32*)(MEM_VRAM + KB(64))) +#define TILE_MAP ((u32*)(MEM_VRAM + KB(40))) static Uint32 unpack_icon_lut[256] = { 0x00000000, 0x00000001, 0x00000010, 0x00000011, 0x00000100, @@ -157,6 +145,7 @@ putcolors(Ppu *p, Uint8 *addr) { (g << 1) | (g >> 3), (b << 1) | (b >> 3)); } + (void)p; } IWRAM_CODE @@ -171,6 +160,7 @@ putpixel(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 color) { size_t shift = start_col * 4; layer[pos] = (layer[pos] & (~(0xF << shift))) | (color << shift); dirty_tiles[tile_y] |= 1 << tile_x; + (void)p; } IWRAM_CODE @@ -221,6 +211,7 @@ puticn(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Ui dirty_tiles[y >> 3] |= dirtyflag; dirty_tiles[(y + 7) >> 3] |= dirtyflag; + (void)p; } IWRAM_CODE @@ -263,13 +254,14 @@ putchr(Ppu *p, Uint32 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, dirty_tiles[y >> 3] |= dirtyflag; dirty_tiles[(y + 7) >> 3] |= dirtyflag; + (void)p; } IWRAM_CODE void flipbuf(Ppu *p) { - Tile *mem_fg = &TILE_MEM[0]; - Tile *mem_bg = &TILE_MEM[2]; + Tile *mem_fg = FG_FRONT; + Tile *mem_bg = BG_FRONT; for (size_t j = 0; j < 20; ++j) { if (dirty_tiles[j] == 0) { continue; @@ -301,32 +293,26 @@ initppu(Ppu *p, Uint8 hor, Uint8 ver, Uint8 pad) { // Initialize backgrounds. u8 cb_fg = 0; - u8 cb_bg = 2; - u8 sb_idx = 10; - BG_CTRL(0) = BG_CHARBLOCK(cb_fg) | BG_SCREENBLOCK(sb_idx) | BG_PRIORITY(1); - BG_CTRL(1) = BG_CHARBLOCK(cb_bg) | BG_SCREENBLOCK(sb_idx) | BG_PRIORITY(2); - - // Clear tile memory. - for (size_t i = 0; i < 32 * 20 * 8; ++i) { - p->fg[i] = 0; - p->bg[i] = 0; - } + u8 cb_bg = 1; + u8 sb_fg = 20; + u8 sb_bg = 21; + BG_CTRL(0) = BG_CHARBLOCK(cb_fg) | BG_SCREENBLOCK(sb_fg) | BG_PRIORITY(1); + BG_CTRL(1) = BG_CHARBLOCK(cb_bg) | BG_SCREENBLOCK(sb_bg) | BG_PRIORITY(2); + + // Clear front buffer. + p->fg = FG_FRONT; + p->bg = BG_FRONT; // Use DMA to clear VRAM. u32 fill = 0; - u32 tile_clear_ctrl = (32 * 20 * 8) | DMA_DST_INC | DMA_SRC_FIXED | DMA_NOW | DMA_CHUNK_32 | DMA_ENABLE; - DMA_SRC(3) = &fill; - DMA_DST(3) = p->fg; - DMA_CTRL(3) = tile_clear_ctrl; - DMA_DST(3) = p->bg; - DMA_CTRL(3) = tile_clear_ctrl; - - p->fg = (u32*) (MEM_VRAM + (56 * 1024)); // 0-20K front, 32K-52K back - p->bg = (u32*) (MEM_VRAM + (76 * 1024)); // 56K-76K front, 76K-96K back - DMA_DST(3) = p->fg; - DMA_CTRL(3) = tile_clear_ctrl; - DMA_DST(3) = p->bg; - DMA_CTRL(3) = tile_clear_ctrl; + dma_fill(p->fg, fill, KB(20), 3); + dma_fill(p->bg, fill, KB(20), 3); + + // Clear back buffer. + p->fg = FG_BACK; + p->bg = BG_BACK; + dma_fill(p->fg, fill, KB(20), 3); + dma_fill(p->bg, fill, KB(20), 3); // Initialize default palette. PAL_BUFFER_BG[0] = COLOR_BLACK; @@ -335,10 +321,12 @@ initppu(Ppu *p, Uint8 hor, Uint8 ver, Uint8 pad) { PAL_BUFFER_BG[3] = COLOR_BLUE; // Initialize memory map. - u16 *mem_map = SCREENBLOCK_MEM[sb_idx]; + u16 *mem_map_fg = SCREENBLOCK_MEM[sb_fg]; + u16 *mem_map_bg = SCREENBLOCK_MEM[sb_bg]; size_t k = 0; for (size_t i = 0; i < 32 * 20; ++i, ++k) { - mem_map[i] = k; + mem_map_fg[i] = k; + mem_map_bg[i] = k + 32 * 4; } 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 d->u = u; d->mem = u->ram.dat; d->talk = talkfn; + (void)name; return d; } -- cgit v1.2.1