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.
 
 
 
 

56 lines
1.0 KiB

SECTION "Utilities", ROM0
; Busy-wait until vertical blank occurs
wait_for_vblank::
ld a, [$ff41]
and 3
cp 1
jr nz, wait_for_vblank
ret
; Copy data between two regions (takes 40*N+12 cycles)
; @param bc Pointer to the destination region
; @param hl Pointer to the source region
; @param d Size (in bytes) to copy. Must be >0
; @destroy a, b, c, d, h, l
memcpy::
ld a, [hli] ; 8
ld [bc], a ; 8
inc bc ; 8
dec d ; 4
jr nz, memcpy ; 12/8
ret ; 16
; Fill a memory region with a value
; @param hl Pointer to the destination region
; @param a Byte to fill with
; @param c Number of bytes to fill. Must be >0
; @destroy a, c, hl
memset::
ld [hli], a
dec c
jr nz, memset
ret
; Divide a value by 10 (http://homepage.divms.uiowa.edu/~jones/bcd/decimal.html#division)
; @param b Dividend
; @return a Quotient
; @destroy b
div10::
ld a, b
srl a
srl a
add b
srl a
add b
srl a
srl a
srl a
add b
srl a
add b
srl a
srl a
srl a
srl a
ret