2018-06-24 07:09:41 -07:00
|
|
|
_Multiply::
|
2015-11-28 12:13:40 -08:00
|
|
|
; hMultiplier is one byte.
|
|
|
|
ld a, 8
|
|
|
|
ld b, a
|
|
|
|
|
|
|
|
xor a
|
2018-09-09 12:10:38 -07:00
|
|
|
ldh [hMultiplicand - 1], a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMathBuffer + 1], a
|
|
|
|
ldh [hMathBuffer + 2], a
|
|
|
|
ldh [hMathBuffer + 3], a
|
|
|
|
ldh [hMathBuffer + 4], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
|
|
|
.loop
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMultiplier]
|
2015-11-28 12:13:40 -08:00
|
|
|
srl a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplier], a
|
2015-11-28 12:13:40 -08:00
|
|
|
jr nc, .next
|
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMathBuffer + 4]
|
2015-11-28 12:13:40 -08:00
|
|
|
ld c, a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMultiplicand + 2]
|
2015-11-28 12:13:40 -08:00
|
|
|
add c
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMathBuffer + 4], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMathBuffer + 3]
|
2015-11-28 12:13:40 -08:00
|
|
|
ld c, a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMultiplicand + 1]
|
2015-11-28 12:13:40 -08:00
|
|
|
adc c
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMathBuffer + 3], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMathBuffer + 2]
|
2015-11-28 12:13:40 -08:00
|
|
|
ld c, a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMultiplicand + 0]
|
2015-11-28 12:13:40 -08:00
|
|
|
adc c
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMathBuffer + 2], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMathBuffer + 1]
|
2015-11-28 12:13:40 -08:00
|
|
|
ld c, a
|
2018-09-09 12:10:38 -07:00
|
|
|
ldh a, [hMultiplicand - 1]
|
2015-11-28 12:13:40 -08:00
|
|
|
adc c
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMathBuffer + 1], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
|
|
|
.next
|
|
|
|
dec b
|
|
|
|
jr z, .done
|
|
|
|
|
|
|
|
; hMultiplicand <<= 1
|
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMultiplicand + 2]
|
2015-11-28 12:13:40 -08:00
|
|
|
add a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplicand + 2], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMultiplicand + 1]
|
2015-11-28 12:13:40 -08:00
|
|
|
rla
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplicand + 1], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMultiplicand + 0]
|
2015-11-28 12:13:40 -08:00
|
|
|
rla
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMultiplicand + 0], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2018-09-09 12:10:38 -07:00
|
|
|
ldh a, [hMultiplicand - 1]
|
2015-11-28 12:13:40 -08:00
|
|
|
rla
|
2018-09-09 12:10:38 -07:00
|
|
|
ldh [hMultiplicand - 1], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
|
|
|
jr .loop
|
|
|
|
|
|
|
|
.done
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMathBuffer + 4]
|
|
|
|
ldh [hProduct + 3], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMathBuffer + 3]
|
|
|
|
ldh [hProduct + 2], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMathBuffer + 2]
|
|
|
|
ldh [hProduct + 1], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMathBuffer + 1]
|
|
|
|
ldh [hProduct + 0], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
_Divide::
|
2015-11-28 12:13:40 -08:00
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMathBuffer + 0], a
|
|
|
|
ldh [hMathBuffer + 1], a
|
|
|
|
ldh [hMathBuffer + 2], a
|
|
|
|
ldh [hMathBuffer + 3], a
|
|
|
|
ldh [hMathBuffer + 4], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
|
|
|
ld a, 9
|
|
|
|
ld e, a
|
|
|
|
|
|
|
|
.loop
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMathBuffer + 0]
|
2015-11-28 12:13:40 -08:00
|
|
|
ld c, a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hDividend + 1]
|
2015-11-28 12:13:40 -08:00
|
|
|
sub c
|
|
|
|
ld d, a
|
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hDivisor]
|
2015-11-28 12:13:40 -08:00
|
|
|
ld c, a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hDividend + 0]
|
2015-11-28 12:13:40 -08:00
|
|
|
sbc c
|
|
|
|
jr c, .next
|
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hDividend + 0], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
|
|
|
ld a, d
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hDividend + 1], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMathBuffer + 4]
|
2015-11-28 12:13:40 -08:00
|
|
|
inc a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMathBuffer + 4], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
|
|
|
jr .loop
|
|
|
|
|
|
|
|
.next
|
|
|
|
ld a, b
|
|
|
|
cp 1
|
|
|
|
jr z, .done
|
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMathBuffer + 4]
|
2015-11-28 12:13:40 -08:00
|
|
|
add a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMathBuffer + 4], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMathBuffer + 3]
|
2015-11-28 12:13:40 -08:00
|
|
|
rla
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMathBuffer + 3], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMathBuffer + 2]
|
2015-11-28 12:13:40 -08:00
|
|
|
rla
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMathBuffer + 2], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMathBuffer + 1]
|
2015-11-28 12:13:40 -08:00
|
|
|
rla
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMathBuffer + 1], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
|
|
|
dec e
|
|
|
|
jr nz, .next2
|
|
|
|
|
|
|
|
ld e, 8
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMathBuffer + 0]
|
|
|
|
ldh [hDivisor], a
|
2015-11-28 12:13:40 -08:00
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMathBuffer + 0], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hDividend + 1]
|
|
|
|
ldh [hDividend + 0], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hDividend + 2]
|
|
|
|
ldh [hDividend + 1], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hDividend + 3]
|
|
|
|
ldh [hDividend + 2], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
|
|
|
.next2
|
|
|
|
ld a, e
|
|
|
|
cp 1
|
|
|
|
jr nz, .okay
|
|
|
|
dec b
|
|
|
|
|
|
|
|
.okay
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hDivisor]
|
2015-11-28 12:13:40 -08:00
|
|
|
srl a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hDivisor], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMathBuffer + 0]
|
2015-11-28 12:13:40 -08:00
|
|
|
rr a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMathBuffer + 0], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
|
|
|
jr .loop
|
|
|
|
|
|
|
|
.done
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hDividend + 1]
|
2018-08-25 19:58:26 -07:00
|
|
|
ldh [hRemainder], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMathBuffer + 4]
|
2018-08-26 10:49:38 -07:00
|
|
|
ldh [hQuotient + 3], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMathBuffer + 3]
|
2018-08-26 10:49:38 -07:00
|
|
|
ldh [hQuotient + 2], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMathBuffer + 2]
|
2018-08-26 10:49:38 -07:00
|
|
|
ldh [hQuotient + 1], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMathBuffer + 1]
|
2018-08-26 10:49:38 -07:00
|
|
|
ldh [hQuotient + 0], a
|
2015-11-28 12:13:40 -08:00
|
|
|
|
|
|
|
ret
|