From eefe1f5ff9f9e3b6fc94f57f98b8cfe47affd7fb Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Sun, 18 Apr 2021 19:04:51 +0200 Subject: Test using fonts as sprites with a custom loader --- src/main.c | 59 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/src/main.c b/src/main.c index 7dd8dcd..17c6654 100644 --- a/src/main.c +++ b/src/main.c @@ -422,6 +422,26 @@ draw_logo() { draw_line(x + height, y + 1, x + height + line, y + 1, COLOR_WHITE); } +void +copy_font_to_tile_memory(Tile *tile) { + // Hex to bits translation table. + const u32 conversion_u32[16] = { + 0x00000000, 0x00001000, 0x00000100, 0x00001100, + 0x00000010, 0x00001010, 0x00000110, 0x00001110, + 0x00000001, 0x00001001, 0x00000101, 0x00001101, + 0x00000011, 0x00001011, 0x00000111, 0x00001111, + }; + for (size_t i = 0; i < 250; ++i) { + for (size_t j = 0; j < 8; ++j) { + u8 row = font[i][j]; + u32 tile_idx = 0x00000000; + tile_idx = conversion_u32[row & 0xF] << 16; + tile_idx |= conversion_u32[(row >> 4) & 0xF]; + (tile + i)->data[j] = tile_idx; + } + } +} + int main(void) { // Configure the display in mode 0 to show OBJs, where tile memory is // sequential. @@ -429,22 +449,23 @@ int main(void) { // Create two 4bpp tiles, one filled with color 1 and another with color 2. Tile *tile_mem = &TILE_MEM[4][512]; - size_t n_tiles = 8; - u32 colors[] = { - 0x11111111, - 0x22222222, - 0x33333333, - 0x44444444, - 0x55555555, - 0x66666666, - 0x77777777, - 0x88888888, - }; - for (size_t j = 0; j < n_tiles; ++j) { - for (size_t i = j * 8; i < 8 + 8 * j; ++i) { - tile_mem->data[i] = colors[j]; - } - } + // size_t n_tiles = 8; + // u32 colors[] = { + // 0x11111111, + // 0x22222222, + // 0x33333333, + // 0x44444444, + // 0x55555555, + // 0x66666666, + // 0x77777777, + // 0x88888888, + // }; + // for (size_t j = 0; j < n_tiles; ++j) { + // for (size_t i = j * 8; i < 8 + 8 * j; ++i) { + // tile_mem->data[i] = colors[j]; + // } + // } + copy_font_to_tile_memory(tile_mem); // Add colors to the sprite color palette. Tiles with color number 0 are // treated as transparent. @@ -522,6 +543,12 @@ int main(void) { active_sprite = 0; } } + if (key_pressed(KEY_L)) { + OBJ_ATTR_2(0) = OBJ_ATTR_2(0) - 1; + } + if (key_pressed(KEY_R)) { + OBJ_ATTR_2(0) = OBJ_ATTR_2(0) + 1; + } OBJ_ATTR_0(0) = (OBJ_ATTR_0(0) & ~0xFF) | (y_a & 0xFF); OBJ_ATTR_1(0) = (OBJ_ATTR_1(0) & ~0x1FF) | (x_a & 0x1FF); -- cgit v1.2.1