2015-07-25 18:25:37 +00:00
|
|
|
AddNTimes:: ; 0x30fe
|
|
|
|
; Add bc * a to hl.
|
|
|
|
and a
|
|
|
|
ret z
|
|
|
|
.loop
|
|
|
|
add hl, bc
|
|
|
|
dec a
|
|
|
|
jr nz, .loop
|
|
|
|
ret
|
|
|
|
; 0x3105
|
|
|
|
|
2014-02-02 01:26:39 +00:00
|
|
|
SimpleMultiply:: ; 3105
|
2013-09-09 05:21:36 +00:00
|
|
|
; Return a * c.
|
|
|
|
and a
|
|
|
|
ret z
|
|
|
|
|
|
|
|
push bc
|
|
|
|
ld b, a
|
|
|
|
xor a
|
|
|
|
.loop
|
|
|
|
add c
|
|
|
|
dec b
|
|
|
|
jr nz, .loop
|
|
|
|
pop bc
|
|
|
|
ret
|
|
|
|
; 3110
|
|
|
|
|
|
|
|
|
2014-02-02 01:26:39 +00:00
|
|
|
SimpleDivide:: ; 3110
|
2013-09-09 05:21:36 +00:00
|
|
|
; Divide a by c. Return quotient b and remainder a.
|
|
|
|
ld b, 0
|
|
|
|
.loop
|
|
|
|
inc b
|
|
|
|
sub c
|
|
|
|
jr nc, .loop
|
|
|
|
dec b
|
|
|
|
add c
|
|
|
|
ret
|
|
|
|
; 3119
|
|
|
|
|
|
|
|
|
2014-02-02 01:26:39 +00:00
|
|
|
Multiply:: ; 3119
|
2013-09-09 05:21:36 +00:00
|
|
|
; Multiply hMultiplicand (3 bytes) by hMultiplier. Result in hProduct.
|
|
|
|
; All values are big endian.
|
|
|
|
push hl
|
|
|
|
push bc
|
|
|
|
|
|
|
|
callab _Multiply
|
|
|
|
|
|
|
|
pop bc
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
; 3124
|
|
|
|
|
|
|
|
|
2014-02-02 01:26:39 +00:00
|
|
|
Divide:: ; 3124
|
2013-09-09 05:21:36 +00:00
|
|
|
; Divide hDividend length b (max 4 bytes) by hDivisor. Result in hQuotient.
|
|
|
|
; All values are big endian.
|
|
|
|
push hl
|
|
|
|
push de
|
|
|
|
push bc
|
|
|
|
ld a, [hROMBank]
|
|
|
|
push af
|
|
|
|
ld a, BANK(_Divide)
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
call _Divide
|
|
|
|
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
pop bc
|
|
|
|
pop de
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
; 3136
|
|
|
|
|
|
|
|
|
2014-02-02 01:26:39 +00:00
|
|
|
SubtractSigned:: ; 3136
|
2013-09-09 05:21:36 +00:00
|
|
|
; Return a - b, sign in carry.
|
|
|
|
sub b
|
|
|
|
ret nc
|
|
|
|
cpl
|
|
|
|
add 1
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
; 313d
|