From 0eda19bd2bb551bf9186b0fbe1a806a28d5a3597 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Thu, 3 Jun 2021 11:24:31 +0200 Subject: Add initial text background drawing functions --- src/renderer.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'src/renderer.c') 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 @@ // the remaining two available for other background layers. There are 14KB of // sprite memory available, since the backbuffer is located at the end of the // VRAM, but if more space is needed it can be moved to the end of the BG -// charblocks instead. +// charblocks instead as described below. // -#include "bd-font.c" +#include "text.h" // The frontbuffer is located at the beginning of the VRAM, and requires 20KB of // video memory for 32 * 20 tiles at 4bpp. @@ -40,6 +40,7 @@ #define FONT_DATA ((u32*)(MEM_VRAM + KB(22))) #define FONT_TILEMAP ((u16*)(MEM_VRAM + KB(30))) #define FONT_SB 15 +#define FONT_OFFSET 192 // Keep track of which tiles need to be copied to the frontbuffer. static u32 dirty_tiles[21] = {0}; @@ -86,8 +87,6 @@ flip_buffer(void) { } } -static u16 font_map[256] = {0}; - void renderer_init(void) { // Initialize display mode and bg palette. @@ -100,9 +99,9 @@ renderer_init(void) { // Use DMA to clear front and back buffers as well as the font memory map. dma_fill(FRONTBUF, 0, KB(20), 3); dma_fill(FRONTBUF_TILEMAP, 0, KB(2), 3); - dma_fill(FONT_DATA, 0, KB(8), 3); - dma_fill(FONT_TILEMAP, 0, KB(2), 3); dma_fill(BACKBUF, 0, KB(20), 3); + dma_fill(FONT_DATA, 0, KB(8), 3); + dma_fill(FONT_TILEMAP, FONT_OFFSET, KB(2), 3); // Initialize default palette. PAL_BUFFER_BG[0] = COLOR_BLACK; @@ -117,13 +116,6 @@ renderer_init(void) { FRONTBUF_TILEMAP[i] = i; } - // Load font data into VRAM. - unpack_tiles(&bd_font, FONT_DATA, 256); - - // Initialize the font map translation table. That way we can write - // a character on the text background layer with: - // FONT_TILEMAP[tile_x + 32 * tile_y] = font_map['A']; - for (size_t i = 0; i < 256; ++i) { - font_map[i] = 192 + i; - } + // Initialize text engine. + txt_init(FONT_DATA, FONT_TILEMAP, FONT_OFFSET); } -- cgit v1.2.1