map: added tile update call test
authorLukas Krickl <lukas@krickl.dev>
Sat, 8 Nov 2025 05:30:41 +0000 (06:30 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sat, 8 Nov 2025 05:30:41 +0000 (06:30 +0100)
src/map.s
src/tiles.s
src/update.s
src/video.s
src/wram.s

index d77bc243ad005fdecb7aab7819af2d113c8395ce..28259b9762ed4af73e59980e8d21d15aae9092b0 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -33,8 +33,7 @@ map_load:
        call player_init
        call ui_init
 
-       ld de, tiles
-       call tile_next_set
+       call tile_update_reset
 
        ret
        
index 3a2436c8f471640c34c0215970bd99dcbd62b86d..c206aafab0ea3e99df0c2cde76202df7ab0e6876 100644 (file)
@@ -6,14 +6,48 @@
 #define GFX_FOOD 0x03
 
        
+       ; resets update tile to 0/0
+tile_update_reset:
+       xor a, a
+       ld [update_tile_y], a
+       ld [update_tile_x], a
+
+       call tile_update_get
+
+       ret
+
        ; inits the next tile
-       ; inputs:
-       ;               de: next tile
-tile_next_set:
-       ld a, d
-       ld [next_update_tile], a
-       ld a, e
-       ld [next_update_tile+1], a
+       ;       increments update_tile_y/x
+       ; resets when out of bounds
+tile_update_get_next:  
+       ld a, [update_tile_x]
+       inc a
+       cp a, MAP_W
+       jr nz, @not_y REL
+               ld a, [update_tile_y]
+               inc a
+               and a, MAP_H-1
+               ld [update_tile_y], a
+               xor a, a ; reset x
+@not_y:
+       ld [update_tile_x], a
+
+       call tile_update_get
+       ret
+       
+       ; sets update_tile to the current selected tile
+       ; bsed on y/x position
+tile_update_get:
+       ld a, [update_tile_y]
+       ld b, a
+       ld a, [update_tile_x]
+       ld c, a
+       call map_get_tile
+
+       ld a, h
+       ld [update_tile], a
+       ld a, l
+       ld [update_tile+1], a
        ret
        
        ; updates the next tile
@@ -22,31 +56,39 @@ tile_next_set:
        ;               next_update_tile
        ;       sets next_update_tile to next tile 
        ;               wraps to first tile if end is reached
-tile_next_update:
-       ld a, [next_update_tile]
+tile_update_selected:
+       call tile_update_get_next
+
+       ld a, [update_tile]
        ld d, a
-       ld a, [next_update_tile+1]
+       ld a, [update_tile+1]
        ld e, a
        
-       push de
        call tile_update
-       pop de
-
-       ; next tile
-       ld hl, t_size
-       add hl, de
-       push hl
-       pop de
-       ; TODO: wrap back to start
-       call tile_next_set
 
        ret
+       
+       ; draws the recently updated tile
+       ; bsed on update_tile y and x
+tile_update_draw:
+       ld a, [update_tile_y]
+       ld b, a
+       ld a, [update_tile_x]
+       ld c, a
+       jp map_draw_tile
+
 
        ; updates a tile with its 
        ; routine
        ; inputs:
        ;               de: tile
 tile_update:
+       ; TODO: for now just inc t_tile
+       ld hl, t_tile
+       add hl, de
+       ld a, [hl]
+       inc a
+       ld [hl], a
        ret
 
        ; table of update routines
index 7e399f7f091df205be82747a1b6e7344eb9480c4..d411928482c5c9bd80a0e0ed902a06ba51b0885b 100644 (file)
@@ -15,7 +15,7 @@ update_game:
 
        call enemy_update
 
-       call tile_next_update
+       call tile_update_selected
 
        call ui_update
        
index 9c3a37b45210db2d45df834e61c3a8234f106347..dcd0b366824e4dd4d270430790b9fb1966c648e8 100644 (file)
@@ -21,6 +21,8 @@ vblank:
   call poll_inputs
        
        call ui_draw
+
+       call tile_update_draw
   
   ; dma previous frame's oam
   call OAMDMAFN
index 9222cf90c0eb0f101865dd5763d264bb3afbc3ea..2551010f148dffbbb0d07bea9f7260dd78aef437 100644 (file)
@@ -90,6 +90,12 @@ 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
+
+       ; the following values are set by tile_next_update
+update_tile_y: .adv 1
+update_tile_x: .adv 1
+update_tile: .adv 2    
+       ; previpus frame's update tile
+       ; used for drawing the recently updated tile
+update_tile_prev_y: .adv 1
+update_tile_prev_x: .adv 1