From 93deb35f86a71a55fe8f4c5b9e9c7f8bd9534b13 Mon Sep 17 00:00:00 2001 From: enne2 Date: Tue, 23 Jun 2026 20:10:27 +0200 Subject: [PATCH] Fix GameBoy VRAM shared memory overlap bug between background tiles and stamina UI sprites --- src/engine.c | 3 ++- src/render.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/engine.c b/src/engine.c index 0b1ce33..49451d7 100644 --- a/src/engine.c +++ b/src/engine.c @@ -95,7 +95,8 @@ void engine_init(void) { set_sprite_data(player_TILE_COUNT, enemy_TILE_COUNT, enemy_tiles); set_sprite_data(player_TILE_COUNT + enemy_TILE_COUNT, gameover_TILE_COUNT, gameover_tiles); set_sprite_data(player_TILE_COUNT + enemy_TILE_COUNT + gameover_TILE_COUNT, victory_TILE_COUNT, victory_tiles); - set_sprite_data(player_TILE_COUNT + enemy_TILE_COUNT + gameover_TILE_COUNT + victory_TILE_COUNT, stamina_TILE_COUNT * 2, stamina_tiles); + // Load stamina_tiles AFTER the background tiles to prevent VRAM overlap in the shared block (indices > 127) + set_sprite_data(tiles_TILE_COUNT, stamina_TILE_COUNT * 2, stamina_tiles); // SPAWN DEL GIOCATORE player_lx = 1; diff --git a/src/render.c b/src/render.c index e0b66f6..3e9f20a 100644 --- a/src/render.c +++ b/src/render.c @@ -57,7 +57,8 @@ void update_stamina_display(void) { uint8_t num_pixels = temp / 100; // Offset di base nella VRAM dove sono caricati i tile della stamina - uint8_t base_tile = player_TILE_COUNT + enemy_TILE_COUNT + gameover_TILE_COUNT + victory_TILE_COUNT; // 44 + // Caricato a partire da tiles_TILE_COUNT per non sovrascrivere la VRAM condivisa (>=128) + uint8_t base_tile = tiles_TILE_COUNT; for (uint8_t i = 0; i < 5; i++) { uint8_t tile_idx;