From: Lukas Krickl Date: Wed, 24 Sep 2025 04:27:29 +0000 (+0200) Subject: rectangle: fixed collision breaking during scroll due to rectangle positions overflow... X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=ef497e241d48e1bf4f90ee534a52eb9744d8106b;p=gbrg%2F.git rectangle: fixed collision breaking during scroll due to rectangle positions overflowing or underflowing --- diff --git a/src/macros.inc b/src/macros.inc index c0f36f3..3aa5bba 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -218,4 +218,28 @@ $1: ; $6: w #macro recdef .db $1, $2, $3, $4, $5, $6 +#endmacro + + ; caps an underflow when carry is set + ; caps value to 0x00 + ; inputs: + ; af: value and carry flag +#macro capunderflow +.beginscope + jr nc, @no_underflow REL + xor a, a +@no_underflow: +.endscope +#endmacro + + ; caps an overflow when carry is set + ; caps value to 0xFF + ; inputs: + ; af: value and carry flag +#macro capoverflow +.beginscope +jr nc, @no_overflow REL + ld a, 0xFF +@no_overflow: +.endscope #endmacro diff --git a/src/rectangle.s b/src/rectangle.s index 3a3e012..c14086f 100644 --- a/src/rectangle.s +++ b/src/rectangle.s @@ -97,6 +97,7 @@ rect_tl: ld l, a ld a, d sub a, l ; y-height + capunderflow ld d, a ; d = top left y ret @@ -122,6 +123,7 @@ rect_tr: ld a, [hl] add a, e ; e = x + width + capoverflow ld e, a dec hl ; go back to height @@ -129,6 +131,7 @@ rect_tr: ld l, a ld a, d sub a, l ; y-height + capunderflow ld d, a ; d = top right y ret @@ -144,6 +147,7 @@ rect_br: ld a, [hl] add a, e ; e = x + width + capoverflow ld e, a ret