gb-tarot/CardHelpers.inc

110 lines
2.4 KiB
PHP

LoadCardData:
LoadCardDataAsync:
ei
ld a, [vSelectedCardIndex]
ld [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.
.duringDraw
; 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
; 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
call CopyTilesToMapUnsafe
ld a, [vSelectedCardIndex]
ld [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.
call PassList
call PassList
call PassList
call PassList
call PassList ; skip the strings
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
call CopyRangeUnsafe
di
nop
ret