From f10597b4bd79619b127e7c9d7392f7b9d232ea66 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Wed, 4 Dec 2024 10:49:17 +0100 Subject: [PATCH] Moved flag reading to map --- src/collision.s | 9 +-------- src/map.s | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/collision.s b/src/collision.s index 4ecd53c..6c8abec 100644 --- a/src/collision.s +++ b/src/collision.s @@ -106,13 +106,6 @@ collision_tile_table_check: ; a = 0 -> no collision ; a = 1 -> collision collision_tile: - call room_get_flag_ptr - ; hl = current tile flags - - ld a, [hl] ; load flags - ld d, a ld a, [ct_mask] - and a, d - - ret + jp room_get_flag_masked diff --git a/src/map.s b/src/map.s index d6e4409..ce43c69 100644 --- a/src/map.s +++ b/src/map.s @@ -247,6 +247,12 @@ room_get_flag_ptr: ; a: the flag to set (flags | a) ; de: y/x room_set_flag: + ld b, a + call room_get_flag_ptr + ld a, [hl] + or a, b + ld [hl], a + ret ; unsets a tile position flag @@ -256,7 +262,33 @@ room_set_flag: ; a: the flag to set (flags ^ a) ; de: y/x room_unset_flag: - ret + ld b, a + call room_get_flag_ptr + ld a, [hl] + xor a, b + ld [hl], a + ret + + ; gets flags at a certain position + ; applies a mask + ; inputs: + ; d : y pos + ; e : x pos + ; a: mask + ; ct_mask: bit mask for flag to check (tile & mask) + ; returns: + ; a: masked flag +room_get_flag_masked: + ld b, a ; b = mask + call room_get_flag_ptr + ; hl = current tile flags + + ld a, [hl] ; load flags + ld d, a + ld a, b ; a= mask + ; ld a, [ct_mask] + and a, d + ret ; base room ; this can be copied and modified -- 2.30.2