From 5e28e432f13ae2ee74b09c54bbda2cae91c6c175 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 2 Nov 2025 13:21:23 +0100 Subject: [PATCH] ui: wip tile rendering --- src/tiles.s | 18 +++++++++++ src/ui.s | 86 ++++++++++++++++++++++++++++++++++++++++++----------- src/video.s | 2 ++ src/wram.s | 15 ++++++++-- 4 files changed, 101 insertions(+), 20 deletions(-) diff --git a/src/tiles.s b/src/tiles.s index 6327de7..74ae07e 100644 --- a/src/tiles.s +++ b/src/tiles.s @@ -22,6 +22,24 @@ tile_update_table: dw tile_update_enemy_hive dw tile_update_food +strz str_empty, "EMPTY" +strz str_player_hive, "YOUR HIVE" +strz str_enemy_hive, "HIVE" +strz str_player, "PLAYER" +strz str_enemy, "ENEMY" +strz str_food, "FOOD" + + ; mapping of tile ids to + ; the tile names +tile_str_table: + dw str_empty + dw str_player + dw str_player_hive + dw str_enemy + dw str_enemy_hive + dw str_food + + ; updates empty tile ; inputs: ; de: tile diff --git a/src/ui.s b/src/ui.s index b7ab11d..870e936 100644 --- a/src/ui.s +++ b/src/ui.s @@ -1,10 +1,4 @@ -; draw one TILE_MOVE tile -; in top row for each move remaining -#define UI_TILE_MOVE 0xC0 -#define UI_TILE_MOVE_USED 0xC1 - -#define UI_PLAYER_HP SCRN1+33 -#define UI_ENEMY_HP SCRN1+65 +#define UI_TILE_NAME SCRN1+33 ; one tile after 'Z' #define UI_WINDOW_BACKGROUND 0xF4 @@ -14,51 +8,107 @@ #define UI_TILE_HP_2 0xCA #define UI_TILE_HP_1 0xCB - -strz str_player, "PLAYER" -strz str_enemy, "ENEMY" - ; inits UI ui_init: - call ui_draw_all + ld hl, ui_draw_nop + call ui_request_draw ret ; updates UI ; checks if a UI draw is required ; usually this occurs when ; the player cursor enters a new tile + ; sets current tile y/x and ptr ui_update: ; check y - ld a, [ui_prev_tile_y] + ld a, [current_tile_y] ld b, a ld a, [player+act_pos_y] add a, PLAYER_TILE_OFFSET div16 a - ld [ui_prev_tile_y], a + ld [current_tile_y], a cp a, b ; are they differnet? jr nz, @draw_new REL ; check x - ld a, [ui_prev_tile_x] + ld a, [current_tile_x] ld b, a ld a, [player+act_pos_x] add a, PLAYER_TILE_OFFSET div16 a - ld [ui_prev_tile_x], a + ld [current_tile_x], a cp a, b ; ar they dfifernet? ret z ; no need to proceed @draw_new: + + ; save current tile + ; this can be used in various places + ld a, [current_tile_y] + ld b, a + ld a, [current_tile_x] + ld c, a + call map_get_tile + ld a, h + ld [current_tile], a + ld a, l + ld [current_tile+1], a + ld hl, ui_draw_tile_name call ui_request_draw ret ; requests a draw ; for UI information about the current tile + ; inputs: + ; hl: routine ptr to draw ui_request_draw: + ld a, h + ld [ui_draw_routine], a + ld a, l + ld [ui_draw_routine+1], a + ret + + ; no draw +ui_draw_nop: + ret + + ; ui draw tile name +ui_draw_tile_name: + ld a, [current_tile] + ld h, a + ld a, [current_tile+1] + + ld a, [hl] ; load type + add a, a ; * 2 for offset + + ld d, 0 + ld e, a + ld hl, tile_str_table + add hl, de + + ld a, [hl+] + ld b, a + ld a, [hl] + ld h, a + ld a, b + ld l, a + + ld de, UI_TILE_NAME + call puts + + ld hl, ui_draw_nop + call ui_request_draw ret ; draws the entire UI ; only call during blank -ui_draw_all: - ret +ui_draw: + ld a, [ui_draw_routine] + ld h, a + ld a, [ui_draw_routine+1] + ld l, a + xor a, h + ret z + jp hl + diff --git a/src/video.s b/src/video.s index 4902877..9c3a37b 100644 --- a/src/video.s +++ b/src/video.s @@ -19,6 +19,8 @@ vblank: ; get inputs call poll_inputs + + call ui_draw ; dma previous frame's oam call OAMDMAFN diff --git a/src/wram.s b/src/wram.s index 0d07427..8445324 100644 --- a/src/wram.s +++ b/src/wram.s @@ -79,5 +79,16 @@ 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 + +ui_draw_routine: .adv 1 + + ; the following valuess are set by ui_update + ; coordinates of current tile +current_tile_y: .adv 1 +current_tile_x: .adv 1 + ; ptr to current tile + ; selected by the player cursor +current_tile: .adv 2 + + ; the next tile to be updated +next_update_tile: .adv 2 -- 2.30.2