gameboy/tools.asm

20 lines
913 B
NASM

SECTION "Tools", ROM0
; Memory copier
; @param de - Address source to start of data to be copied
; @param hl - Address destomatopm where to copy the data to
; @param bc - The total amount of bytes to copy
; @return a = Zero
; @return bc = Zero
; @return de = Address Source to the byte after the last byte from source (garbage)
; @return hl = Address Target to the byte after the last byte on the target (garbage)
Memcpy:
ld a, [de] ; Load the value at [de] to accumilator
ld [hli], a ; Load the value from accumilator to the destination address and increment it by one
inc de ; Increment de to point to next byte to copy
dec bc ; Decrement bc the total amount of bytes to copy
ld a, b ; Load the first half of total amount of bytes to write to accumilator
or c ; OR together the second half of total amount with the first half
jr nz, Memcpy ; Loop back to Memcpy if not zero
ret