From: Lukas Krickl Date: Sun, 1 Feb 2026 07:31:37 +0000 (+0100) Subject: math: Addd 16 bit add X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=abdc88d02a935c8b139399150e0552c1503519bd;p=gbrg%2F.git math: Addd 16 bit add Added macros for storing math registers --- diff --git a/src/math.s b/src/math.s index 8231515..22e0f64 100644 --- a/src/math.s +++ b/src/math.s @@ -1,10 +1,49 @@ + ; writes a 16 bit register + ; to an m16 regsiter + ; inputs: + ; $1: m16_a/b +#macro m16_write_bc + ld a, c + ld [$1], a + ld a, b + ld [$1+1], c +#endmacro +#macro m16_write_de + ld a, e + ld [$1], a + ld a, d + ld [$1+1], c +#endmacro +#macro m16_write_hl + ld a, l + ld [$1], a + ld a, h + ld [$1+1], c +#endmacro + ; 16 bit add ; inputs: ; m16_a/m16_b ; returns: ; m16_a: m16_a + m16_b m16_add: + ld a, [m16_b] + ld b, a + ld a, [m16_a] + + ; low is stored + add a, b + ld [m16_a], a + + ld a, [m16_b+1] + ld b, a + ld a, [m16_a+1] + + ; high + carry stored + adc a, b + ld [m16_a+1], a + ret ; 16 bit sub diff --git a/src/wram.s b/src/wram.s index 6678bab..b30b9a1 100644 --- a/src/wram.s +++ b/src/wram.s @@ -143,6 +143,7 @@ col_y: .adv 1 col_x: .adv 1 ; 16-bit math temporary registers + ; store in LE m16_a: .adv 2 m16_b: .adv 2