gb-tarot/ScreenCardRead.inc

180 lines
4.9 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 [vAsyncAfter+1], 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, vTime
ldh a, [rDELTAT]
ld b, a
ldh a, [vTime]
add a, b
ldh [vTime], a
ldh a, [vTime+1]
adc a, 0
ldh [vTime+1], a ; increment time. when the 16bit time register is greater
; than 4096 ($10_00) then one second has passed. so that's satisfied when
; vTime+1 is equal to or greater than $10
ldh a, [vTime+1]
cp a, $01
jp c, .doneTimer ; if the timer is less than $0100, skip to end
;otherwise reset the timer
ld a, 0
ldh [vTime], a
ldh [vTime+1], a
ld hl, SquaresTiles
ldh a, [vFrameCountSquares]
inc a
call ArrayClampLooping
ldh [vFrameCountSquares], a
.doneTimer
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:
ld hl, SquaresTiles
inc hl
ld b, 0
ldh a, [vFrameCountSquares]
ld c, a
add hl, bc
add hl, bc
ld c, [hl]
inc hl
ld b, [hl]
ld h, b
ld l, c
ld de, $8000+$100*16 + 1*16
ld bc, (SquaresTileset8 - SquaresTileset7) / 8
call CopyRangeUnsafeBy8s
; then 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
ldh a, [vCurrentSpread]
ld l, a
ldh a, [vCurrentSpread+1]
ld h, a
call PassList ; skip spread layout
ldh a, [vSelectedSpreadCard]
or a, a
.loopThroughSpreadPositions
jp z, .foundSpreadPositionDescription
call PassList
call PassList
dec a
jp .loopThroughSpreadPositions
.foundSpreadPositionDescription
ld de, $9800 + 32*5 + 11
call PrintString
ld de, $9800 + 32*6 + 11
call PrintString
; the card data is loaded asynchronously, initiated in CardReadUpdate
ret
CardReadTeardown:
ret
UITilemap:
db $0e, $0a, $0a, $0a, $0a, $0a, $0a, $0a, $0a, $0f, $09, $02, $02, $02, $02, $02, $02, $02, $08, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $03, $00, $00, $00, $00, $00, $00, $00, $04, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $03, $00, $00, $00, $00, $00, $00, $00, $04, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $03, $00, $00, $00, $00, $00, $00, $00, $04, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $03, $00, $00, $00, $00, $00, $00, $00, $04, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $03, $00, $00, $00, $00, $00, $00, $00, $04, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $03, $00, $00, $00, $00, $00, $00, $00, $04, $01
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $06, $05, $05, $05, $05, $05, $05, $05, $07, $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, $02, $02, $02, $02, $02, $02, $02, $02, $02, $02
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
db $11, $0d, $0d, $0d, $0d, $0d, $0d, $0d, $0d, $10, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
UITilemapEnd: