gb-tarot/ScreenCardRead.inc

321 lines
10 KiB
PHP

; screen variables
DEF vPreviousCardIndex EQU VARIABLES_START
def vBlocked equ vPreviousCardIndex + 1
ScreenCardRead:
dw CardReadSetup
dw CardReadUpdate
dw CardReadDraw
dw CardReadTeardown
CardReadSetup:
ld a, 1
ldh [vBlocked], a
ld hl, UITilemap ; origin
ld de, $9800 ; destination
ld b, 18 ; height
ld c, 20 ; width
ld a, LOW(CopyTilesToMapThreadsafe)
ld [vAsyncNext], a
ld a, HIGH(CopyTilesToMapThreadsafe)
ld [vAsyncNext+1], a
ld a, LOW(LoadCardDataAsync)
ld [vAsyncAfter], a
ld a, HIGH(LoadCardDataAsync)
ld [vAsyncAfter+1], a
call DoInAsyncVBlank
ret
CardReadUpdate:
ld hl, rMYBTNP
bit 4, [hl]
jp z, .doneWithB
ld hl, ScreenSpreadSelect
call ChangeScene
ret
.doneWithB
ldh a, [vSelectedSpreadCard]
ld hl, rMYBTNP
bit 1, [hl]
jp z, :+ ; skip the following code if left is not pressed
dec a
:
bit 0, [hl]
jp z, :+ ; skip the following code if right is not pressed
inc a
:
ldh [vSelectedSpreadCard], a
ldh a, [vCurrentSpread]
ld l, a
ldh a, [vCurrentSpread+1]
ld h, a
ldh a, [vSelectedSpreadCard]
call ArrayClampLooping
ldh [vSelectedSpreadCard], a
ldh [vSelectedCardIndex], a
ldh a, [vSelectedCardIndex]
ld hl, vPreviousCardIndex
cp a, [hl]
ret z ; if the selected card diddn't change, nothing to do
ldh a, [vBlocked]
cp a, 0
ret nz
ld a, LOW(LoadCardDataAsync)
ld [vAsyncAfter], a
ld a, HIGH(LoadCardDataAsync)
ld [vAsyncAfter+1], a
call DoInAsyncVBlank
ret
CardReadDraw:
; first draw the spread minimap
ldh a, [vCurrentSpread]
ld c, a
ldh a, [vCurrentSpread+1]
ld b, a
ld hl, $9800 + (32*1)+11
ldh a, [vSelectedSpreadCard]
call DrawSpreadMinimap
; the card data is loaded asynchronously, initiated in CardReadUpdate
ret
CardReadTeardown:
ret
LoadCardDataAsync:
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 this twice to double the offset because it's two bytes per address
; 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
; 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*9 + 10
call PrintString
ld de, $9800 + 32*10 + 10
call PrintString
ld de, $9800 + 32*12 + 10
call PrintString
ld de, $9800 + 32*13 + 10
call PrintString
ld de, $9800 + 32*14 + 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
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 this twice to double the offset because it's two bytes per address
; 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, $91b0 ; 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
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
BigLetterTiles:
db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
db $ee,$ee,$44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$44
db $7c,$7c,$44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$ee,$ee
db $10,$10,$10,$10,$10,$10,$10,$10,$10,$10,$10,$10,$10,$10,$38,$38
db $38,$38,$10,$10,$10,$10,$10,$10,$10,$10,$10,$10,$10,$10,$10,$10
db $70,$70,$40,$40,$40,$40,$40,$40,$40,$40,$40,$40,$42,$42,$fe,$fe
db $fe,$fe,$42,$42,$40,$40,$40,$40,$40,$40,$40,$40,$40,$40,$40,$40
db $48,$48,$44,$44,$44,$44,$44,$44,$44,$44,$42,$42,$42,$42,$e3,$e3
db $fc,$fc,$42,$42,$42,$42,$42,$42,$42,$42,$7c,$7c,$48,$48,$48,$48
db $42,$42,$42,$42,$42,$42,$42,$42,$42,$42,$42,$42,$42,$42,$3c,$3c
db $3c,$3c,$42,$42,$42,$42,$42,$42,$42,$42,$42,$42,$42,$42,$42,$42
db $20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$70,$70
db $7c,$7c,$22,$22,$22,$22,$22,$22,$22,$22,$3c,$3c,$20,$20,$20,$20
db $38,$38,$44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$ee,$ee
db $10,$10,$28,$28,$28,$28,$28,$28,$28,$28,$28,$28,$28,$28,$28,$28
db $ce,$ce,$44,$44,$64,$64,$54,$54,$54,$54,$54,$54,$54,$54,$54,$54
db $54,$54,$54,$54,$54,$54,$54,$54,$54,$54,$4c,$4c,$44,$44,$e6,$e6
db $fe,$fe,$92,$92,$10,$10,$10,$10,$10,$10,$10,$10,$10,$10,$10,$10
db $7e,$7e,$22,$22,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20
db $38,$38,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$70,$70
db $70,$70,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20
db $20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$22,$22,$7e,$7e
db $42,$42,$42,$42,$42,$42,$42,$42,$42,$42,$42,$42,$42,$42,$fc,$fc
db $f8,$f8,$44,$44,$42,$42,$42,$42,$44,$44,$78,$78,$44,$44,$42,$42
db $ee,$ee,$44,$44,$44,$44,$44,$44,$44,$44,$7c,$7c,$44,$44,$44,$44
db $44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$ee,$ee
db $7e,$7e,$22,$22,$20,$20,$20,$20,$20,$20,$38,$38,$20,$20,$20,$20
db $fe,$fe,$42,$42,$40,$40,$40,$40,$40,$40,$70,$70,$40,$40,$40,$40
db $40,$40,$40,$40,$40,$40,$40,$40,$40,$40,$40,$40,$42,$42,$fe,$fe
db $3c,$3c,$42,$42,$42,$42,$42,$42,$40,$40,$40,$40,$40,$40,$40,$40
db $40,$40,$40,$40,$40,$40,$40,$40,$42,$42,$42,$42,$42,$42,$3c,$3c
db $42,$42,$42,$42,$42,$42,$42,$42,$42,$42,$42,$42,$44,$44,$f8,$f8
db $f8,$f8,$44,$44,$42,$42,$42,$42,$42,$42,$42,$42,$42,$42,$42,$42
db $80,$80,$80,$80,$8f,$8f,$8a,$8a,$82,$82,$82,$82,$44,$44,$38,$38
db $38,$38,$44,$44,$82,$82,$82,$82,$82,$82,$80,$80,$80,$80,$80,$80
db $04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$44,$44,$44,$44,$38,$38
db $0e,$0e,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04,$04
db $ee,$ee,$44,$44,$44,$44,$48,$48,$50,$50,$60,$60,$50,$50,$48,$48
db $54,$54,$54,$54,$54,$54,$54,$54,$44,$44,$44,$44,$44,$44,$ee,$ee
db $c6,$c6,$6c,$6c,$54,$54,$54,$54,$54,$54,$54,$54,$54,$54,$54,$54
db $42,$42,$42,$42,$42,$42,$42,$42,$4a,$4a,$4c,$4c,$4c,$4c,$36,$36
db $3c,$3c,$42,$42,$42,$42,$40,$40,$40,$40,$3c,$3c,$02,$02,$02,$02
db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$42,$42,$42,$42,$3c,$3c
db $44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$28,$28,$10,$10
db $44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$44,$38,$38
db $44,$44,$54,$54,$54,$54,$54,$54,$54,$54,$54,$54,$54,$54,$28,$28
db $10,$10,$10,$10,$28,$28,$28,$28,$28,$28,$44,$44,$44,$44,$ee,$ee
db $ee,$ee,$44,$44,$44,$44,$28,$28,$28,$28,$28,$28,$10,$10,$10,$10
db $ee,$ee,$44,$44,$44,$44,$28,$28,$10,$10,$10,$10,$10,$10,$10,$10
db $fe,$fe,$82,$82,$04,$04,$04,$04,$08,$08,$08,$08,$08,$08,$10,$10
db $10,$10,$20,$20,$20,$20,$20,$20,$40,$40,$40,$40,$82,$82,$fe,$fe
BigLetterTilesEnd:
UITilemap:
db $0e, $0a, $0a, $0a, $0a, $0a, $0a, $0a, $0a, $0f, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01
db $11, $0d, $0d, $0d, $0d, $0d, $0d, $0d, $0d, $10, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01
UITilemapEnd: