From: Lukas Krickl Date: Tue, 11 Nov 2025 16:30:07 +0000 (+0100) Subject: tiles: Added adjacnet up getters X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=f916ef44286b8f82243f0877a5c609987c7d4ccc;p=gbrg%2F.git tiles: Added adjacnet up getters --- diff --git a/src/tiles.s b/src/tiles.s index a34b7a2..a1534bf 100644 --- a/src/tiles.s +++ b/src/tiles.s @@ -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 diff --git a/src/wram.s b/src/wram.s index e2c662f..2dd960e 100644 --- a/src/wram.s +++ b/src/wram.s @@ -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