From 9470c99c424ffeadb3f7071204e2e570fec954c9 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Fri, 4 Oct 2024 17:22:57 +0200 Subject: [PATCH] WIP: ui drawing code for hp/mp --- src/ui.s | 51 +++++++++++++++++++++++++++++++++++++++++++++------ src/video.s | 2 ++ src/wram.s | 10 ++++++++++ 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/ui.s b/src/ui.s index 4a36d2d..00c4030 100644 --- a/src/ui.s +++ b/src/ui.s @@ -1,10 +1,10 @@ #define THP_ICON 0x33 #define TMP_ICON 0x37 - ; update the UI - ; this should only be called - ; during blanking -ui_draw: + ; sets up static parts of the UI + ; all other parts are drawin by ui_draw + ; only call during blanking +ui_init: ; draw hp string ld hl, STR_HP ld de, SCRN0_UI @@ -14,10 +14,21 @@ ui_draw: ld hl, STR_MP ld de, SCRN0_UI+10 call puts + + ; darw mp and hp on first frame + ld a, UI_REDRAW_HP | UI_REDRAW_MP + ld [ui_flags], a + + ret + + ; draws a UI bar + ; inputs: + ; hl: screen location + ; [de]: amount of bars to draw +ui_draw_bar: - ; draw hp UI + ld a, THP_ICON - ld hl, SCRN0_UI+SCRN_W ld [hl+], a inc a ld [hl+], a @@ -25,6 +36,29 @@ ui_draw: ld [hl+], a inc a ld [hl+], a + ret + + ; update the UI + ; this should only be called + ; during blanking +ui_draw: + ; check if we should darw hp bar + ld a, [ui_flags] + cp a, 0 + jr z, @skip REL + + ; draw hp UI + ld hl, SCRN0_UI+SCRN_W + ; player hp ptr + ld de, player + player_hp + ; check redraw hp flag + and a, UI_REDRAW_HP + call nz, ui_draw_bar + + ; check if we should draw mp bar + ld a, [ui_flags] + and a, UI_REDRAW_HP + jr z, @no_mp_draw REL ; draw mp UI ld a, TMP_ICON @@ -38,5 +72,10 @@ ui_draw: ld [hl+], a inc a ld [hl+], a +@no_mp_draw: + ; set flags to 0 + xor a, a + ld [ui_flags], a +@skip: ret diff --git a/src/video.s b/src/video.s index e315321..92a6f47 100644 --- a/src/video.s +++ b/src/video.s @@ -64,6 +64,8 @@ video_init: ld a, 0b11011000 ld [ROBP1], a + + call ui_init ret diff --git a/src/wram.s b/src/wram.s index acae72c..1989595 100644 --- a/src/wram.s +++ b/src/wram.s @@ -69,3 +69,13 @@ player: .adv player_size ; pointer to current room struct curr_room: .adv 2 + + ; drawing related flags + + ; UI flags +.se 1 +.de UI_REDRAW_HP, 1 +.de UI_REDRAW_MP, 2 + +ui_flags: .adv 1 +draw_flags: .adv 1 -- 2.30.2