From 9911609e8fff312c406e3407a519b39db79bdb97 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Wed, 19 May 2021 16:29:20 +0200 Subject: Implement double buffering drawing --- src/text.h | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'src/text.h') diff --git a/src/text.h b/src/text.h index b3bb601..b90c160 100644 --- a/src/text.h +++ b/src/text.h @@ -131,9 +131,9 @@ txt_putc_hybrid(char c) { unpack_tiles(packed_char, &tile, 1); int x = text_engine.cursor_x; int y = text_engine.cursor_y; - // DEBUG: should be on the text struct. - Tile *buf = &TILE_MEM[0]; + Tile *buf = text_engine.memory; buf[x + y * 30] = tile; + dirty_tiles[y][x] = 1; text_engine.cursor_x += 1; if (text_engine.cursor_x >= 30) { text_engine.cursor_x = 0; @@ -222,6 +222,33 @@ txt_init_bitmap(TextMode mode, Font font) { text_engine.mode = mode; } +void +txt_init_hybrid(TextMode mode, Font font, u32 *buf) { + // If font_map is NULL, initialize the standard 0-255 character map. + if (font.char_map == NULL) { + for (size_t i = 0; i < 256; ++i) { + default_char_map[i] = i; + } + font.char_map = &default_char_map; + } + + // Initialize default values if set to zero. + if (font.char_width == 0) { + font.char_width = 8; + } + if (font.char_height == 0) { + font.char_height = 8; + } + if (font.color == 0) { + font.color = COLOR_WHITE; + } + + // Prepare text engine. + text_engine.font = font; + text_engine.mode = mode; + text_engine.memory = *buf; +} + // Print text to the screen with formatting. void txt_printf(char *msg, ...) { -- cgit v1.2.1