summaryrefslogtreecommitdiff
path: root/home/math.asm
diff options
context:
space:
mode:
authorentrpntr <12521136+entrpntr@users.noreply.github.com>2020-05-15 12:57:29 -0400
committerGitHub <noreply@github.com>2020-05-15 12:57:29 -0400
commit88d7e9a34a8b610b358cec1ccc6660634ca9ce80 (patch)
tree709f2f908d9e1c2f7a882d628ff09b80de3c9e8b /home/math.asm
parenta7e3a999ff21ecac0bfbe7f091f9ff901075a323 (diff)
parent6231351906960364a5ad2f34efefd809cceb0eb8 (diff)
Merge pull request #19 from libjet/home-cleanup
Home and HRAM cleanup
Diffstat (limited to 'home/math.asm')
-rw-r--r--home/math.asm49
1 files changed, 18 insertions, 31 deletions
diff --git a/home/math.asm b/home/math.asm
index ffa3c282..6daa2ed9 100644
--- a/home/math.asm
+++ b/home/math.asm
@@ -1,71 +1,58 @@
-SkipNames::
- ld bc, $b
- and a
- ret z
-.asm_319e
- add hl, bc
- dec a
- jr nz, .asm_319e
- ret
-
-AddNTimes:: ; 31a3 (0:31a3)
- and a
- ret z
-.asm_31a5
- add hl, bc
- dec a
- jr nz, .asm_31a5
- ret
-
SimpleMultiply::
+; Return a * c.
and a
ret z
+
push bc
ld b, a
xor a
-.asm_31af
+.loop
add c
dec b
- jr nz, .asm_31af
+ jr nz, .loop
pop bc
ret
-
-SimpleDivide:: ; 31b5 (0:31b5)
- ld b, $0
-.asm_31b7
+
+SimpleDivide::
+; Divide a by c. Return quotient b and remainder a.
+ ld b, 0
+.loop
inc b
sub c
- jr nc, .asm_31b7
+ jr nc, .loop
dec b
add c
ret
Multiply::
+; Multiply hMultiplicand (3 bytes) by hMultiplier. Result in hProduct.
+; All values are big endian.
push hl
push bc
- callfar Multiply_ ; 1:67bd
+ callfar _Multiply
pop bc
pop hl
ret
Divide::
+; Divide hDividend length b (max 4 bytes) by hDivisor. Result in hQuotient.
+; All values are big endian.
push hl
push de
push bc
-
- homecall Divide_ ; 1:681d
-
+ homecall _Divide
pop bc
pop de
pop hl
ret
SubtractSigned::
+; Return a - b, sign in carry.
sub b
ret nc
cpl
- add $1
+ add 1
scf
ret