ret
+ ; checks one tile for a type match
+ ; inputs:
+ ; hl: ptr to next tile
+ ; a: expected tile type
+ ; b: current tile match count
+ ; returns:
+ ; incremnets b if type matches
+ ; hl+=2 (next ptr)
+ ; preserves:
+ ; a
+#macro tile_count_adjacent_check
+.beginscope
+ push af
+ ld a, [hl+]
+ ld d, a
+ ld a, [hl+]
+ ld e, a
+ ; hl = next ptr
+
+ ; de = ptr to tile
+ push hl
+ ld hl, t_type
+ add hl, de
+ ; hl = tile type
+ ld a, [hl]
+ ld c, a ; c = tile type
+ pop hl
+
+ pop af
+ cp a, c
+ ; check if match
+ jr nz, @no_match REL
+ inc b ; result++
+@no_match:
+.endscope
+#endmacro
+
+ ; counts adjacent tiles of specific type
+ ; inputs:
+ ; a: expected type
+ ; returns:
+ ; a: count of type
+tile_count_adjacent:
+ ; b = result
+ ld b, 0
+
+ ; hl = ptrs to tiles
+ ld hl, tiles_adjacent
+
+ ; check 8 tiles
+ tile_count_adjacent_check
+ tile_count_adjacent_check
+ tile_count_adjacent_check
+ tile_count_adjacent_check
+
+ tile_count_adjacent_check
+ tile_count_adjacent_check
+ tile_count_adjacent_check
+ tile_count_adjacent_check
+
+ ; result is in a now
+ ld a, b
+ ret
+
+
; updates empty tile
; inputs:
; de: tile
tile_update_empty:
+ ld a, TT_FOOD
+ push de
+ call tile_count_adjacent
+ pop de
+
+ ; if 2 adjacnet food tiles
+ ; turn into food
+ cp a, 2
+ ret c
- ; TODO: for now just inc t_tile
- ld hl, t_tile
- add hl, de
- ld a, [hl]
- inc a
- ; ld [hl], a
+ push de
+ pop hl ; hl = dst
+ ld de, tile_food
+ ld bc, t_size
+ call memcpy
ret
; updates controlled tile