gameboy/tools.asm

46 lines
1.6 KiB
NASM
Raw Normal View History

2019-06-14 08:36:52 +00:00
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
2019-06-18 09:08:14 +00:00
2019-06-19 15:07:02 +00:00
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
2019-06-18 09:08:14 +00:00
;;
; 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