; variables for safe transfer async function DEF vSafeCopySource EQU $ff80 DEF vSafeCopyDest EQU vSafeCopySource + 2 DEF vSafeCopyCount EQU vSafeCopyDest + 2 ; check this for safe transfer being complete DEF vSafeCopyOriginalCount EQU vSafeCopyCount + 2 ; stash previous interrupt state before using the interrupts DEF vSafeCopyLYC EQU vSafeCopyOriginalCount + 2 ; stashes $FF45, the LYC register DEF vSafeCopySTAT EQU vSafeCopyLYC + 1 ; stashes $FF41, the STAT register DEF vSafeCopyInterrupt EQU vSafeCopySTAT + 1 ; stashes the previous LCD interrupt DEF vSafeCopyInterruptEnable EQU vSafeCopyInterrupt + 2 ; stashes $FFFF, which interrupts are enabled DEF SAFE_TRANSFER_START EQU 145 DEF SAFE_TRANSFER_END EQU 153 CopyRange: CopyRangeUnsafe: ; hl is source ; de is destination ; bc is length to copy ld a, b or a, c ret z .loop ld a, [hl+] ld [de], a inc de dec bc ld a, b or a, c ; check if bc is zero jp nz, .loop ret CopyRangeBy8s: CopyRangeUnsafeBy8s: ; hl is source ; de is destination ; bc is 1/8 of length to copy!!! ; so like this will copy 8*bc bytes! ld a, b or a, c ret z .loop ld a, [hl+] ld [de], a inc de ld a, [hl+] ld [de], a inc de ld a, [hl+] ld [de], a inc de ld a, [hl+] ld [de], a inc de ld a, [hl+] ld [de], a inc de ld a, [hl+] ld [de], a inc de ld a, [hl+] ld [de], a inc de ld a, [hl+] ld [de], a inc de dec bc ld a, b or a, c ; check if bc is zero jp nz, .loop ret