tiles: Added adjacnet up getters
authorLukas Krickl <lukas@krickl.dev>
Tue, 11 Nov 2025 16:30:07 +0000 (17:30 +0100)
committerLukas Krickl <lukas@krickl.dev>
Tue, 11 Nov 2025 16:30:07 +0000 (17:30 +0100)
src/tiles.s
src/wram.s

index a34b7a2b0343124d43a8c5afca1ea5b495b2cb2c..a1534bf2bb881e9e48077a87578b19cd4cf0e0da 100644 (file)
@@ -136,6 +136,39 @@ tile_get_actor:
        ; TODO:
        ret
        
+       ; stores an adjacent tile
+       ; inputs:
+       ;                $1: skip if x position equal
+       ;                $2: tile offset based on bc
+       ;               bc: current tile ptr
+       ;   de: destination
+       ;       returns:
+       ;               de: next destination
+#macro tile_adjacent_store
+.beginscope
+               ; check if x is 0
+               ; if so skip left tile
+               ld a, [update_tile_x]
+               cp a, $1
+               jr z, @skip REL
+
+               ; store left tile
+               ld hl, $2 
+               add hl, bc
+               ; move to new position
+       
+               ; store tile
+               ld a, h
+               ld [de], a
+               inc de
+               ld a, l
+               ld [de], a
+               inc de
+
+@skip:
+.endscope
+#endmacro
+
        ; stores pointers to 
        ; all adjacent tiles
        ; stores NULL if adjacent tile is out 
@@ -155,11 +188,37 @@ tile_get_adjacent:
        ld b, a
        ld a, [update_tile_x]
        ld c, a
+       call map_get_tile
 
-       ld hl, tiles_adjacent
+       ; hl = current tile
+       push hl  
+       pop bc ; bc = current tile
+       
+       ; de = destination
+       ld de, tiles_adjacent
 
        ; now get all tiles adjacent
 
+       ; 1) get tiles above (up to 3 tiles)
+
+       ; check if y is already 0, if so skip
+       ld a, [update_tile_y]
+       cp a, 0
+       jp z, @skip_above 
+               ; up/center tile        
+               tile_adjacent_store 0xFF, (-1 * (t_size * MAP_W)) & 0xFFFF
+               ; up/left tile
+               tile_adjacent_store 0, (-1 * (t_size * (MAP_W+1))) & 0xFFFF
+               ; up/right tile
+               tile_adjacent_store (MAP_W-1), (-1 * (t_size * (MAP_W-1))) & 0xFFFF
+
+@skip_above:
+
+       ; 2) get tiles left and right (up to 2 tiles)
+
+       ; 3) get tiles below (up to 3 tiles)
+
+
        ret
 
        ; updates empty tile
index e2c662ffe66fa5e042d75a2d85a7a5a201507446..2dd960e3524f2d58ea28a1fab58def18e3099e07 100644 (file)
@@ -84,6 +84,7 @@ tiles_end: .adv 0
        ; list of pointers
        ; to all adjacent tiles
        ; set to NULL if no tile is adjacent
+       ; byte 0: h, byte 1: l
 tiles_adjacent: .adv 2 * TILES_ADJACENT_MAX
 
 ui_draw_routine: .adv 2