+ ; 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
+
+