gameboy/tools.asm

63 lines
2.1 KiB
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
Memfill:
; Fill an area in memory at position hl with value a for b amount of times
;
; @param hl - Starting address in memory to fill
; @param a - The value to fill said address space with
; @param b - How many bytes we should fill starting from said address space
; @return a - garbage
; @return b - PosX on where to draw text
; @return c - PosY on where to draw text
; @return hl - Workram position for text pointer
; @return de - Memory address to source string
.repeatFill
ld [hli], a
dec b
jr nz, .repeatFill
ret
Memfill16:
; Fill an area in memory at position hl with value a for bc amount of times
;
; @param hl - Starting address in memory to fill
; @param a - The value to fill said address space with
; @param b - How many bytes we should fill starting from said address space
; @return a - garbage
; @return b - PosX on where to draw text
; @return c - PosY on where to draw text
; @return hl - Workram position for text pointer
; @return de - Memory address to source string
.repeatFill
ld [hli], a
dec bc
jr nz, .repeatFill
ret
;;
; Waits for the vblank ISR to increment the count of vertical blanks.
; Will lock up if DI, vblank IRQ off, or LCD off.
; Clobbers A, HL
WaitVBlank:
.wait
halt
ret