From c4786065e811bbd1548a84f5f066bed81259acd8 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sat, 1 Nov 2025 18:41:10 +0100 Subject: [PATCH] ui: added stub for UI draw request --- src/defs.s | 4 +++- src/ui.s | 35 +++++++++++++++++++++++++++++++++++ src/update.s | 2 ++ src/wram.s | 3 ++- 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/defs.s b/src/defs.s index a36c2f0..d9ff0c4 100644 --- a/src/defs.s +++ b/src/defs.s @@ -23,7 +23,9 @@ #define UI_TILE_WIDTH 32 #define UI_TILE_HEIGHT 4 - + + ; player position offset to get center of tile +#define PLAYER_TILE_OFFSET 8 #define MAP_W 16 #define MAP_H 16 #define MAP_TILES (MAP_W * MAP_H) diff --git a/src/ui.s b/src/ui.s index 79ed476..b7ab11d 100644 --- a/src/ui.s +++ b/src/ui.s @@ -23,6 +23,41 @@ ui_init: call ui_draw_all ret + ; updates UI + ; checks if a UI draw is required + ; usually this occurs when + ; the player cursor enters a new tile +ui_update: + ; check y + ld a, [ui_prev_tile_y] + ld b, a + ld a, [player+act_pos_y] + add a, PLAYER_TILE_OFFSET + div16 a + ld [ui_prev_tile_y], a + cp a, b ; are they differnet? + jr nz, @draw_new REL + + ; check x + ld a, [ui_prev_tile_x] + ld b, a + ld a, [player+act_pos_x] + add a, PLAYER_TILE_OFFSET + div16 a + ld [ui_prev_tile_x], a + cp a, b ; ar they dfifernet? + ret z ; no need to proceed + +@draw_new: + + call ui_request_draw + ret + + ; requests a draw + ; for UI information about the current tile +ui_request_draw: + ret + ; draws the entire UI ; only call during blank ui_draw_all: diff --git a/src/update.s b/src/update.s index 824249e..a5cf3d1 100644 --- a/src/update.s +++ b/src/update.s @@ -14,6 +14,8 @@ update_game: call player_draw call enemy_update + + call ui_update ; TODO: update map routine diff --git a/src/wram.s b/src/wram.s index d099a18..0d07427 100644 --- a/src/wram.s +++ b/src/wram.s @@ -79,4 +79,5 @@ map: .adv 2 tile_curr: .adv 2 tiles: .adv t_size * MAP_TILES - +ui_prev_tile_y: .adv 1 +ui_prev_tile_x: .adv 1 -- 2.30.2