summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-04-18 19:04:51 +0200
committerBad Diode <bd@badd10de.dev>2021-04-18 19:04:51 +0200
commiteefe1f5ff9f9e3b6fc94f57f98b8cfe47affd7fb (patch)
tree19436d883d18ff82664f5818469901bbdb177294
parent36706012b126bacc7c208108d9c328a810321bab (diff)
downloadgba-experiments-eefe1f5ff9f9e3b6fc94f57f98b8cfe47affd7fb.tar.gz
gba-experiments-eefe1f5ff9f9e3b6fc94f57f98b8cfe47affd7fb.zip
Test using fonts as sprites with a custom loader
-rw-r--r--src/main.c59
1 files 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() {
422 draw_line(x + height, y + 1, x + height + line, y + 1, COLOR_WHITE); 422 draw_line(x + height, y + 1, x + height + line, y + 1, COLOR_WHITE);
423} 423}
424 424
425void
426copy_font_to_tile_memory(Tile *tile) {
427 // Hex to bits translation table.
428 const u32 conversion_u32[16] = {
429 0x00000000, 0x00001000, 0x00000100, 0x00001100,
430 0x00000010, 0x00001010, 0x00000110, 0x00001110,
431 0x00000001, 0x00001001, 0x00000101, 0x00001101,
432 0x00000011, 0x00001011, 0x00000111, 0x00001111,
433 };
434 for (size_t i = 0; i < 250; ++i) {
435 for (size_t j = 0; j < 8; ++j) {
436 u8 row = font[i][j];
437 u32 tile_idx = 0x00000000;
438 tile_idx = conversion_u32[row & 0xF] << 16;
439 tile_idx |= conversion_u32[(row >> 4) & 0xF];
440 (tile + i)->data[j] = tile_idx;
441 }
442 }
443}
444
425int main(void) { 445int main(void) {
426 // Configure the display in mode 0 to show OBJs, where tile memory is 446 // Configure the display in mode 0 to show OBJs, where tile memory is
427 // sequential. 447 // sequential.
@@ -429,22 +449,23 @@ int main(void) {
429 449
430 // Create two 4bpp tiles, one filled with color 1 and another with color 2. 450 // Create two 4bpp tiles, one filled with color 1 and another with color 2.
431 Tile *tile_mem = &TILE_MEM[4][512]; 451 Tile *tile_mem = &TILE_MEM[4][512];
432 size_t n_tiles = 8; 452 // size_t n_tiles = 8;
433 u32 colors[] = { 453 // u32 colors[] = {
434 0x11111111, 454 // 0x11111111,
435 0x22222222, 455 // 0x22222222,
436 0x33333333, 456 // 0x33333333,
437 0x44444444, 457 // 0x44444444,
438 0x55555555, 458 // 0x55555555,
439 0x66666666, 459 // 0x66666666,
440 0x77777777, 460 // 0x77777777,
441 0x88888888, 461 // 0x88888888,
442 }; 462 // };
443 for (size_t j = 0; j < n_tiles; ++j) { 463 // for (size_t j = 0; j < n_tiles; ++j) {
444 for (size_t i = j * 8; i < 8 + 8 * j; ++i) { 464 // for (size_t i = j * 8; i < 8 + 8 * j; ++i) {
445 tile_mem->data[i] = colors[j]; 465 // tile_mem->data[i] = colors[j];
446 } 466 // }
447 } 467 // }
468 copy_font_to_tile_memory(tile_mem);
448 469
449 // Add colors to the sprite color palette. Tiles with color number 0 are 470 // Add colors to the sprite color palette. Tiles with color number 0 are
450 // treated as transparent. 471 // treated as transparent.
@@ -522,6 +543,12 @@ int main(void) {
522 active_sprite = 0; 543 active_sprite = 0;
523 } 544 }
524 } 545 }
546 if (key_pressed(KEY_L)) {
547 OBJ_ATTR_2(0) = OBJ_ATTR_2(0) - 1;
548 }
549 if (key_pressed(KEY_R)) {
550 OBJ_ATTR_2(0) = OBJ_ATTR_2(0) + 1;
551 }
525 552
526 OBJ_ATTR_0(0) = (OBJ_ATTR_0(0) & ~0xFF) | (y_a & 0xFF); 553 OBJ_ATTR_0(0) = (OBJ_ATTR_0(0) & ~0xFF) | (y_a & 0xFF);
527 OBJ_ATTR_1(0) = (OBJ_ATTR_1(0) & ~0x1FF) | (x_a & 0x1FF); 554 OBJ_ATTR_1(0) = (OBJ_ATTR_1(0) & ~0x1FF) | (x_a & 0x1FF);