You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
514 B
43 lines
514 B
section "home/math.asm", rom0
|
|
|
|
bits_swap::
|
|
ld c, $80
|
|
ld b, a
|
|
xor a
|
|
.loop
|
|
rrc b
|
|
jr nc, .skip
|
|
or c
|
|
.skip
|
|
rrc c
|
|
jr nc, .loop
|
|
ret
|
|
|
|
; TODO: There was a more optimal way to do this with max 16 iterations
|
|
array_index::
|
|
; hl: array base
|
|
; c: entry size
|
|
; a: index
|
|
and a
|
|
ret z
|
|
ld b, 0
|
|
.loop
|
|
add hl, bc
|
|
dec a
|
|
jr nz, .loop
|
|
ret
|
|
|
|
divide::
|
|
; a: value
|
|
; c: divisor
|
|
; Returns:
|
|
; b: result
|
|
; a: remainder
|
|
ld b, 0
|
|
.loop
|
|
inc b
|
|
sub c
|
|
jr nc, .loop
|
|
dec b
|
|
add c
|
|
ret
|
|
|