Created
December 20, 2018 17:05
-
-
Save ISSOtm/dd25b25523f7d44bbccc20cb4f809d73 to your computer and use it in GitHub Desktop.
Fast VRAM copy queue code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Perform fast VRAM copy if asked to | |
ldh a, [hFastCopyNbReq] | |
and a | |
jp z, .dontDoFastTransfer | |
push de | |
push hl | |
; Save sp and set it to source | |
ld [wSPBuffer], sp | |
; Get ready to read params | |
ldh a, [hFastCopyCurLowByte] | |
ld c, a | |
.serveOneCopyReq | |
ld b, HIGH(wFastCopyQueue) | |
ld a, [bc] ; Read bank | |
ld [rROMB0], a | |
inc c ; inc bc | |
; Read src | |
ld a, [bc] | |
ld l, a | |
inc c ; inc bc | |
ld a, [bc] | |
ld h, a | |
inc c ; inc bc | |
ld sp, hl | |
; Read dest | |
ld a, [bc] | |
ld l, a | |
inc c ; inc bc | |
ld a, [bc] | |
ld h, a | |
inc c ; inc bc | |
ld a, [bc] ; Read completion flags ptr (low) | |
ld e, a | |
inc c ; inc bc | |
ld a, [bc] ; Read len | |
ld d, a | |
rra ; Carry should be clear | |
ld b, a | |
; Check if the copy is still going to be in our budget | |
ldh a, [rLY] | |
and a | |
jr z, .abort | |
add a, b | |
cp SCRN_Y + 10 | |
jr nc, .abort | |
inc c ; inc bc | |
; And begin the fun | |
inc b ; Compensate for half cycle | |
rr d ; Get shifted bit again | |
; Write ACK for systems dependent on the transfer | |
ld d, HIGH(wFastCopyACKs) | |
ld a, 1 | |
ld [de], a | |
jr c, .oneTile ; Do a light Duff's Device | |
dec b ; Actually, there won't be any half cycle | |
.twoTiles | |
REPT 8 | |
pop de | |
ld a, e | |
ld [hli], a | |
ld a, d | |
ld [hli], a | |
ENDR | |
.oneTile | |
REPT 8 | |
pop de | |
ld a, e | |
ld [hli], a | |
ld a, d | |
ld [hli], a | |
ENDR | |
dec b | |
jr nz, .twoTiles | |
ld a, c | |
cp LOW(wFastCopyQueueEnd) | |
jr c, .noWrap | |
sub LOW(wFastCopyQueueEnd) - LOw(wFastCopyQueue) | |
ld c, a | |
.noWrap | |
ldh a, [hFastCopyNbReq] | |
dec a | |
ldh [hFastCopyNbReq], a | |
jp nz, .serveOneCopyReq | |
; Update low byte | |
ld a, c | |
ldh [hFastCopyCurLowByte], a | |
.abort | |
; Restore regs | |
ldh a, [hCurROMBank] | |
ld [rROMB0], a | |
ld sp, wSPBuffer | |
pop hl | |
ld sp, hl | |
pop hl | |
pop de | |
.dontDoFastTransfer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SECTION "General-purpose vars", WRAM0,ALIGN[7] | |
; Queue of fast VRAM copy requests | |
; Format: | |
; Byte - bank | |
; Ptr - source | |
; Ptr - dest | |
; Byte - low byte of ptr to which 1 is written upon transfer | |
; Byte - len | |
wFastCopyQueue:: | |
ds NB_FAST_COPY_REQS * 7 | |
wFastCopyQueueEnd:: | |
; ACK flags for fast copy completions | |
wFastCopyACKs:: | |
wDummyFastCopyACK:: | |
db | |
wPlayerFastCopyACK:: | |
db | |
ds 3 ; Alignment, I guess | |
wPlayerReqPtrLow:: | |
db | |
; Temporary storage for SP while doing a VBlank fast VRAM transfer | |
wSPBuffer:: | |
dw |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment