From: Lukas Krickl Date: Tue, 29 Jul 2025 17:15:29 +0000 (+0200) Subject: mapgen: moved tile checker logic to a macro X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=5cd95052b3882624792735efd2cff90ae95bcf1e;p=gbrg%2F.git mapgen: moved tile checker logic to a macro --- diff --git a/src/mapgen.s b/src/mapgen.s index bfe045d..bc80bb8 100644 --- a/src/mapgen.s +++ b/src/mapgen.s @@ -309,6 +309,45 @@ mapgen_draw_room_pattern_row: pop de ret + + ; performs fix by checking if a tile + ; at a certain offset relative to a door + ; is a collider + ; inputs: + ; $1: the offset relative to the current map position + ; $2: the wall pattern to use if a collider is found + ; hl: map_ptr + ; a: pattern entry + ; + ; preserves: + ; hl, bc, de +#macro mapgen_fix_door_fixup + push hl + push de + + ; move left one tile + ; and check for colliders + ld de, ($1) & 0xFFFF + add hl, de + ; hl = tile to the left + + inc hl ; go to flags + ld d, a ; store a for later + ld a, [hl] + and a, CF_COLLISION + ld a, d ; restore a's value + + ; if not collider do not fix + jr z, @no_fix REL + ; otherwise load left wall into a + ld a, $2 + @no_fix: + + pop de + pop hl +#endmacro + + ; fixed door tile if it is adjacent to ; a collider tile ; inputs: @@ -343,31 +382,9 @@ mapgen_fix_door_adjacent_to_collider: @down_door: ret @left_door: - push hl - push de - - ; move left one tile - ; and check for colliders - ld de, (-c_size) & 0xFFFF - add hl, de - ; hl = tile to the left - - inc hl ; go to flags - ld d, a ; store a for later - ld a, [hl] - and a, CF_COLLISION - ld a, d ; restore a's value - - ; if not collider do not fix - jr z, @no_left_fix REL - ; otherwise load left wall into a - ld a, RPLW - -@no_left_fix: - - pop de - pop hl - + mapgen_fix_door_fixup -c_size, RPLW ret @right_door: + + ret