From: Lukas Krickl Date: Fri, 14 Nov 2025 08:41:56 +0000 (+0100) Subject: tiles: added test for food spread X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=gbrg%2F.git tiles: added test for food spread --- diff --git a/src/tiles.s b/src/tiles.s index 86c1d91..d61509f 100644 --- a/src/tiles.s +++ b/src/tiles.s @@ -243,17 +243,90 @@ tile_get_adjacent: 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