From d92654eef0f898a233812a02e31a812542df1d30 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Wed, 24 Sep 2025 06:33:33 +0200 Subject: [PATCH] player: Added underflow and overflow protection to movement --- src/player.s | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/player.s b/src/player.s index f7064a2..2a84024 100644 --- a/src/player.s +++ b/src/player.s @@ -112,7 +112,12 @@ player_stage_move_p: add a, b ld [player_sub_pixel_y], a ld a, [player+act_pos_y] - adc a, 0 + adc a, 0 + + jr nc, @no_overflow_y REL + ld a, 0xFF +@no_overflow_y: + ld b, a ld a, [player_sub_pixel_x] @@ -120,6 +125,10 @@ player_stage_move_p: ld [player_sub_pixel_x], a ld a, [player+act_pos_x] adc a, 0 + +jr nc, @no_overflow_x REL + ld a, 0xFF +@no_overflow_x: ld c, a ret @@ -135,6 +144,11 @@ player_stage_move_n: ld [player_sub_pixel_y], a ld a, [player+act_pos_y] sbc a, 0 + + jr nc, @no_underflow_y REL + xor a, a +@no_underflow_y: + ld b, a ld a, [player_sub_pixel_x] @@ -142,6 +156,11 @@ player_stage_move_n: ld [player_sub_pixel_x], a ld a, [player+act_pos_x] sbc a, 0 + + jr nc, @no_underflow_x REL + xor a, a +@no_underflow_x: + ld c, a ret -- 2.30.2