mirror of
https://gitlab.com/xCrystal/pokecrystal-board.git
synced 2025-04-09 05:44:44 -07:00
move multiplication/division functions into common/math.asm
This commit is contained in:
parent
ee04a2fcd9
commit
53b7926f5e
76
common/math.asm
Normal file
76
common/math.asm
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
SimpleMultiply: ; 3105
|
||||||
|
; 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
|
||||||
|
|
||||||
|
|
||||||
|
SimpleDivide: ; 3110
|
||||||
|
; 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
|
||||||
|
|
||||||
|
|
||||||
|
Multiply: ; 3119
|
||||||
|
; 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
|
||||||
|
|
||||||
|
|
||||||
|
Divide: ; 3124
|
||||||
|
; 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
|
||||||
|
|
||||||
|
|
||||||
|
SubtractSigned: ; 3136
|
||||||
|
; Return a - b, sign in carry.
|
||||||
|
sub b
|
||||||
|
ret nc
|
||||||
|
cpl
|
||||||
|
add 1
|
||||||
|
scf
|
||||||
|
ret
|
||||||
|
; 313d
|
||||||
|
|
76
main.asm
76
main.asm
@ -861,81 +861,7 @@ AddNTimes: ; 0x30fe
|
|||||||
; 0x3105
|
; 0x3105
|
||||||
|
|
||||||
|
|
||||||
SimpleMultiply: ; 3105
|
INCLUDE "common/math.asm"
|
||||||
; 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
|
|
||||||
|
|
||||||
|
|
||||||
SimpleDivide: ; 3110
|
|
||||||
; 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
|
|
||||||
|
|
||||||
|
|
||||||
Multiply: ; 3119
|
|
||||||
; 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
|
|
||||||
|
|
||||||
|
|
||||||
Divide: ; 3124
|
|
||||||
; 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
|
|
||||||
|
|
||||||
|
|
||||||
SubtractSigned: ; 3136
|
|
||||||
; Return a - b, sign in carry.
|
|
||||||
sub b
|
|
||||||
ret nc
|
|
||||||
cpl
|
|
||||||
add 1
|
|
||||||
scf
|
|
||||||
ret
|
|
||||||
; 313d
|
|
||||||
|
|
||||||
|
|
||||||
PrintLetterDelay: ; 313d
|
PrintLetterDelay: ; 313d
|
||||||
|
Loading…
x
Reference in New Issue
Block a user