From 975961d9cbaf238d3b33cd6e8757824d79275f3e Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Mon, 2 Feb 2026 14:28:59 +0100 Subject: [PATCH] attr: added sub16 call for attacking --- src/actor.s | 4 ++-- src/attributes.s | 43 +++++++++++++++++++++++++++++++++++++++++++ src/defs.s | 2 +- src/math.s | 6 +++--- src/player.s | 4 ++-- 5 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/actor.s b/src/actor.s index f347edf..ab27f0f 100644 --- a/src/actor.s +++ b/src/actor.s @@ -268,9 +268,9 @@ act_init_set_tact: ld hl, act_hp add hl, de ; set default hp - ld a, b - ld [hl+], a ld a, c + ld [hl+], a + ld a, b ld [hl], a diff --git a/src/attributes.s b/src/attributes.s index 4266598..f70e9d3 100644 --- a/src/attributes.s +++ b/src/attributes.s @@ -105,10 +105,53 @@ act_attr_get_weapon_damage: ; bc = damage ret + ; gets actor's current hp + ; inputs: + ; de: actor + ; returns: + ; bc: current hp +act_attr_get_hp: + ld hl, act_hp + add hl, de + ld a, [hl+] + ld c, a + ld a, [hl] + ld b, a + ret + + ; writes hp + ; inputs: + ; de: actor + ; bc: new hp value +act_attr_write_hp: + ld hl, act_hp + add hl, de + ld a, c + ld [hl+], a + ld a, b + ld [hl], a + ret + ; takes weapon type damage ; inputs: ; de: actor to take damage ; bc: damage value act_attr_take_weapon_damage: + push de + + ; TODO: apply resistances to bc + + m16_write_bc m16_b + call act_attr_get_hp + m16_write_bc m16_a + call m16_sub + ; a - b + + ; read result back + m16_read_bc m16_a + + pop de + call act_attr_write_hp + call act_die ret diff --git a/src/defs.s b/src/defs.s index 61c72b7..9e8e307 100644 --- a/src/defs.s +++ b/src/defs.s @@ -68,7 +68,7 @@ .de act_p0, 1 ; state parameter .de act_state, 1 - ; hp/mp stored in BE + ; hp/mp stored in LE .de act_hp, 2 .de act_mp, 2 ; currently active buff id diff --git a/src/math.s b/src/math.s index 3517e1e..c83aed8 100644 --- a/src/math.s +++ b/src/math.s @@ -7,19 +7,19 @@ ld a, c ld [$1], a ld a, b - ld [$1+1], c + ld [$1+1], a #endmacro #macro m16_write_de ld a, e ld [$1], a ld a, d - ld [$1+1], c + ld [$1+1], a #endmacro #macro m16_write_hl ld a, l ld [$1], a ld a, h - ld [$1+1], c + ld [$1+1], a #endmacro diff --git a/src/player.s b/src/player.s index 9914d53..b61f052 100644 --- a/src/player.s +++ b/src/player.s @@ -66,9 +66,9 @@ player_init: ; set current hp ld de, player call act_attr_get_max_hp - ld a, b - ld [player+act_hp], a ld a, c + ld [player+act_hp], a + ld a, b ld [player+act_hp+1], a _player_set_target -1, 0 -- 2.30.2