mapgen: moved tile checker logic to a macro
authorLukas Krickl <lukas@krickl.dev>
Tue, 29 Jul 2025 17:15:29 +0000 (19:15 +0200)
committerLukas Krickl <lukas@krickl.dev>
Tue, 29 Jul 2025 17:15:29 +0000 (19:15 +0200)
src/mapgen.s

index bfe045decdcf59cf927ecac7f6dd258cbfcbb5ed..bc80bb8f274f3be0f1145574443f1c97d9574942 100644 (file)
@@ -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