65 lines
1.4 KiB
PHP
65 lines
1.4 KiB
PHP
; 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
|
|
|
|
|
|
CopyRangeUnsafe: ; this is threadsafe but not vblank safe
|
|
; hl is source
|
|
; de is destination
|
|
; bc is length to copy
|
|
ld a, [hl+]
|
|
ld [de], a
|
|
inc de
|
|
dec bc
|
|
ld a, b
|
|
or a, c ; check if bc is zero
|
|
jp nz, CopyRangeUnsafe
|
|
|
|
ret
|
|
|
|
CopyRangeUnsafeBy8s:
|
|
; hl is source
|
|
; de is destination
|
|
; bc is length to copy
|
|
|
|
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, CopyRangeUnsafeBy8s
|
|
nop
|
|
nop
|
|
ret |