ui: wip tile rendering
authorLukas Krickl <lukas@krickl.dev>
Sun, 2 Nov 2025 12:21:23 +0000 (13:21 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sun, 2 Nov 2025 12:21:23 +0000 (13:21 +0100)
src/tiles.s
src/ui.s
src/video.s
src/wram.s

index 6327de74a117cd9f65bb0683bc17b00a3ef5d078..74ae07ef21ec98e6d567fcd8de12a2e1ed23a628 100644 (file)
@@ -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
index b7ab11dd689bdc1609873147c912922c1c30a1eb..870e93623f698e465bbb8b25795b56518ade64d7 100644 (file)
--- 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  
 #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
+
index 490287724c82e354a5155f7ca6e0ec5ae7af8a1e..9c3a37b45210db2d45df834e61c3a8234f106347 100644 (file)
@@ -19,6 +19,8 @@ vblank:
 
   ; get inputs 
   call poll_inputs
+       
+       call ui_draw
   
   ; dma previous frame's oam
   call OAMDMAFN
index 0d07427c9227a41b97710d7e8a7c77717982bbfa..8445324e088f31e17eedb69b2903c2d617dcfc72 100644 (file)
@@ -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