gb-tarot/CardHelpers.inc

162 lines
3.4 KiB
PHP

LoadCardDataAsync: ; to be called as async
ei
ld a, 1
ldh [vBlocked], a
ldh a, [vSelectedCardIndex]
ldh [vPreviousCardIndex], a
ld b, 0
ld c, a ; load bc from a, the number of the card in the cards list
ld hl, Cards + 1 ; skip the length prefix
add hl, bc
add hl, bc
add hl, bc ; triple add bc entries are bank, addr, addr
ld a, [hl+]
ld [rROMB0], a ; select the specified bank
; follow the pointer we're looking at
ld a, [hl+]
ld c, a
ld a, [hl+]
ld b, a
ld h, b
ld l, c ; hl now contains the address of the card data.
ld a, LOW(.duringDraw)
ld [vAsyncNext], a
ld a, HIGH(.duringDraw)
ld [vAsyncNext+1], a
ld a, 0
ld [vAsyncAfter], a
ld [vAsyncAfter+1], a
di
nop
nop
ret
.duringDraw
di ; these function calls should be fast so we'll disable interrupts and do them
nop
; synchronously
; hl points to a card struct.
; card struct starts with a sequence of length-prefixed strings in memory
; so when we're done writing one, hl will be correctly placed to read the next
; length-prefixed print doesn't require passing a length
; so all we have to set is the destination for each
ld de, $9800 + 32*11 + 10
call PrintString
ld de, $9800 + 32*12 + 10
call PrintString
ld de, $9800 + 32*14 + 10
call PrintString
ld de, $9800 + 32*15 + 10
call PrintString
ld de, $9800 + 32*16 + 10
call PrintString
ei
; hl now contains the address after all the strings.
; [hl+] and [hl+] read the length first, into bc
ld a, [hl+]
ld c, a
ld a, [hl+]
ld b, a ; bc has length
ld a, [hl+]
ld e, a
ld a, [hl+]
ld d, a ; de has source of tile range copy
ld h, d
ld l, e ; source
ld de, $9800 + 32 + 1 ; destination
ld b, 16 ; height
ld c, 8 ; width
ld a, LOW(CopyTilesToMapThreadsafe)
ld [vAsyncNext], a
ld a, HIGH(CopyTilesToMapThreadsafe)
ld [vAsyncNext+1], a
ld a, LOW(.afterCopyTiles)
ld [vAsyncAfter], a
ld a, HIGH(.afterCopyTiles)
ld [vAsyncAfter+1], a
di
nop
nop
ret
.afterCopyTiles
ei
ldh a, [vSelectedCardIndex]
ldh [vPreviousCardIndex], a
ld b, 0
ld c, a ; load bc from a, the number of the card in the cards list
ld hl, Cards + 1 ; skip the length prefix
add hl, bc
add hl, bc
add hl, bc ; triple add bc entries are bank, addr, addr
ld a, [hl+]
ld [rROMB0], a ; select the specified bank
; follow the pointer we're looking at
ld a, [hl+]
ld c, a
ld a, [hl+]
ld b, a
ld h, b
ld l, c ; hl now contains the address of the card data.
di
call PassList
call PassList
call PassList
call PassList
call PassList ; skip the strings
ei
inc hl
inc hl ; skip tile map width
inc hl
inc hl ; skip tile map pointer
ld a, [hl+]
ld c, a
ld a, [hl+]
ld b, a ; bc has length of tile data
ld a, [hl+]
ld e, a
ld a, [hl+]
ld d, a ; de has source of tile range copy
ld h, d
ld l, e ; hl takes the source
ld de, $9000 + VARIABLE_TILES_START*$10 ; always load tile data into the same spot in vram
ld a, LOW(CopyRangeUnsafe)
ld [vAsyncNext], a
ld a, HIGH(CopyRangeUnsafe)
ld [vAsyncNext+1], a
ld a, LOW(.afterLoadingTiles)
ld [vAsyncAfter], a
ld a, HIGH(.afterLoadingTiles)
ld [vAsyncAfter+1], a
di
nop
nop
ret
.afterLoadingTiles
ei
ld a, 0
ldh [vBlocked], a
ld a, 0
ld [vAsyncNext], a
ld [vAsyncNext+1], a
ld [vAsyncAfter], a
ld [vAsyncAfter+1], a
di
nop
nop
ret