From: Lukas Krickl Date: Sat, 18 Jan 2025 05:58:24 +0000 (+0100) Subject: actor: moved rf flag setter to a macro X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=cfe3ca9e50b1c0bbe9deac87951f3a69ca91796e;p=gbrg%2F.git actor: moved rf flag setter to a macro This allows it to also be used as a copy-paste for palyer flag purposes. --- diff --git a/src/actor.s b/src/actor.s index 9d5e1e4..b65d377 100644 --- a/src/actor.s +++ b/src/actor.s @@ -162,7 +162,7 @@ actor_anim_verify: ld a, [anim_target_x] sub a, ANIM_MOVE_TILE_SIZE / 2 ; -8 to be in center ld e, a - ld a, RF_WALL | RF_DOOR | RF_ACTOR + ld a, RF_WALL | RF_DOOR | RF_ACTOR | RF_PLAYER call room_get_flag_masked pop bc @@ -181,33 +181,17 @@ actor_anim_verify: ; hl: trunacted y/x anim_truncate_pos: ret - - ; same as actor_tile_update_rf_flags - ; but decs hl before calling and - ; increments again after -player_tile_update_rf_flags: - dec hl - call actor_tile_update_rf_flags - inc hl - ret - - ; marks the current actor's tile - ; as occupied by an actor - ; also removes the flag from the actor's current tile - ; this only works for the default case of - ; an acotr needing a single tile. + + ; macro version of actor_tile_update_rf_flag ; inputs: - ; bc: (actor ptr) original y/x position ptr + ; $1: RF FLAG to set / unset + ; bc: original y/x position ptr ; anim_target_y/x: target position ; returns: - ; sets the RF_ACTOR flag at target_y/x - ; unsets RF_ACTOR at [bc] and [bc+1] + ; sets the $1 flag at target_y/x + ; unsets $1 at [bc] and [bc+1] ; preserves registers -actor_tile_update_rf_flags: - push_all - - inc bc ; bc = y pos - +#macro update_rf_flag ; first unset existing flags ; sub 8 to positions to center on tile @@ -222,7 +206,7 @@ actor_tile_update_rf_flags: ; unset flag ld a, [hl] - and a, 0xFF ^ RF_ACTOR + and a, 0xFF ^ $1 ld [hl], a @@ -237,10 +221,40 @@ actor_tile_update_rf_flags: ; set flag ld a, [hl] - or a, RF_ACTOR + or a, $1 ld [hl], a @skip: +#endmacro + + ; same as actor_tile_update_rf_flags + ; but decs hl before calling and + ; increments again after +player_tile_update_rf_flags: + push_all + update_rf_flag RF_PLAYER + pop_all + ret + + ; marks the current actor's tile + ; as occupied by an actor + ; also removes the flag from the actor's current tile + ; this only works for the default case of + ; an acotr needing a single tile. + ; inputs: + ; bc: (actor ptr) original y/x position ptr + ; anim_target_y/x: target position + ; returns: + ; sets the RF_ACTOR flag at target_y/x + ; unsets RF_ACTOR at [bc] and [bc+1] + ; preserves registers +actor_tile_update_rf_flags: + push_all + + inc bc ; bc = y pos + + update_rf_flag RF_ACTOR + pop_all ret diff --git a/src/player.s b/src/player.s index ab233d7..272ad92 100644 --- a/src/player.s +++ b/src/player.s @@ -270,9 +270,10 @@ player_update: jr z, @no_collision REL ; clear anim memory - call anim_clear + call anim_clear + jr @skip_input REL @no_collision: - + ; call z, player_tile_update_rf_flags @skip_input: ; hl should be player_y here diff --git a/src/wram.s b/src/wram.s index d259311..cc6c7af 100644 --- a/src/wram.s +++ b/src/wram.s @@ -130,6 +130,8 @@ damage_anim: .adv 1 ; note: if RF_ACTOR is set the highest 4 bits of RF flags will ; be set to the actor's id .de RF_ACTOR, 4 + ; same as RF_ACTOR, but for the player +.de RF_PLAYER, 8 ; current room struct ; same layout as room struct itself