gb-tarot/ScreenCardRead.inc

289 lines
7.4 KiB
PHP

PUSHS UNION "Screen Variables", WRAM0[SCREEN_VARS_START]
ds 16 ; why are we putting this so far in? i don't remember but whatever
vPreviousCardIndex: db
POPS
ScreenCardRead:
dw CardReadSetup
dw CardReadUpdate
dw CardReadDraw
dw CardReadTeardown
CardReadSetup:
ld a, 1
ld [vBlocked], a
ld [vTooBusyForPrinter], a
ld hl, .asyncTask
call Async_Spawn_HL
ld hl, ZEROES
ld de, MY_OAM
ld bc, $100
call CopyRange
call CheckForPrinter
ret
.asyncTask:
ld hl, CardRead.UITilemap ; origin
ld de, _SCRN0 ; destination
ld b, 18 ; height
ld c, 20 ; width
call CopyTilesToMap
ld hl, CardRead.PrinterTiles
ld de, _VRAM + $1000 - $10*16
ld bc, CardRead.PrinterTilesEnd - CardRead.PrinterTiles
call CopyRange
ld a, 0
ld [vBlocked], a
call ChangedCardTask
ret
CardReadUpdate:
ld a, [vPrinterStart]
cp a, 0
call z, CardUpdate
call ScrollBackgroundTile
ld a, [vTooBusyForPrinter]
cp a, 0
jp nz, .donePrinter
.checkForPrinter
ld a, [vPrinterStart]
cp a, 0
call z, CheckForPrinter
.updatePrintUI
ld a, [vPrinterStart]
cp a, 0
call z, CardRead.UpdatePrintUI
.runPrintJob
ld a, [vPrinterStart]
cp a, 0
call nz, RunPrintJob
.printButton
ld hl, rMYBTNP
bit 6, [hl] ; check select?
jp z, .donePrinter
ld a, [vPrinterState]
cp a, PS_READY
jp nz, .donePrinter
call KickOffPrintJob
ret
.donePrinter
ld hl, rMYBTNP
bit 5, [hl]
jp z, .doneWithB
ld hl, ScreenSpreadSelect
call ChangeScene
ret
.doneWithB
ld 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
:
ld [vSelectedSpreadCard], a
ld a, [vCurrentSpread]
ld l, a
ld a, [vCurrentSpread+1]
ld h, a
ld a, [vSelectedSpreadCard]
call ArrayClampLooping
ld [vSelectedSpreadCard], a
ld hl, vPreviousSpreadCard
cp a, [hl]
ret z ; if the selected card diddn't change, nothing to do
ld a, [vBlocked]
cp a, 0
ret nz
ld a, 1
ld [vTooBusyForPrinter], a
ld hl, ChangedCardTask
call Async_Spawn_HL
ret
CardReadDraw:
ld a, [vCurrentBackgroundTile]
ld l, a
ld a, [vCurrentBackgroundTile+1]
ld h, a
ld de, _VRAM + $1000 + 1*16
call CopyOneTileData
call CardDraw
ld de, SAFE_DMA_LOCATION
ld a, HIGH(MY_OAM)
call RunDMA
ret
CardReadTeardown:
ret
ChangedCardTask:
ld a, [vSelectedSpreadCard]
ld [vPreviousSpreadCard], a
ld a, [vCurrentSpread]
ld c, a
ld a, [vCurrentSpread+1]
ld b, a ; gett bc as cuurrent spread address
ld hl, _SCRN0 + (32*1)+11
ld a, [vSelectedSpreadCard]
call DrawSpreadMinimap
ld a, [vCurrentSpread]
ld l, a
ld a, [vCurrentSpread+1]
ld h, a
call PassList ; skip spread layout
ld a, [vSelectedSpreadCard]
or a, a
.loopThroughSpreadPositions
jp z, .foundSpreadPositionDescription
call PassList
call PassList
dec a
jp .loopThroughSpreadPositions
.foundSpreadPositionDescription
ld de, _SCRN0 + 32*5 + 11
call PrintString
ld de, _SCRN0 + 32*6 + 11
call PrintString
ld hl, SHUFFLED_DECK+1
ld a, [vSelectedSpreadCard]
ld c, a
ld b, 0
add hl, bc
ld a, [hl]
ld [vSelectedCardIndex], a
ld [vPreviousCardIndex], a
call LoadCardData
call CardRead.UpdatePrintUIImmediate
ld a, 0
ld [vTooBusyForPrinter], a
ret
CardRead.UpdatePrintUI:
ld a, [vPrinterState]
ld hl, vPreviousPrinterState
cp a, [hl]
ret z ; if the printer state has not changed, return.
; otherwise updae previous printer state and we're good
ld [hl], a
ld hl, CardRead.UpdatePrintUIImmediate
call Async_Spawn_HL
ret
CardRead.UpdatePrintUIImmediate:
ld a, [vPrinterState]
ld hl, CardRead.PrinterNotDetected
cp a, PS_NONE
jp z, .setIt
ld hl, CardRead.PrinterAvailable
cp a, PS_READY
jp z, .setIt
ld hl, CardRead.PrinterFull
cp a, PS_FULL
jp z, .setIt
ld hl, CardRead.PrinterPrinting
cp a, PS_PRINTING
jp z, .setIt
ld hl, CardRead.PrinterError
cp a, PS_ERROR
jp z, .setIt
.setIt
ld de, _SCRN0 + 32*7 + 10
ld b, 2
ld c, 9
call CopyTilesToMap
ret
CardRead.PrinterNotDetected:
db $06, $05, $05, $05, $05, $05, $05, $05, $07
db $01, $01, $01, $01, $01, $01, $01, $01, $01
CardRead.PrinterAvailable:
db $03, $00, $f1, $f2, $00, $f3, $f4, $00, $04
db $06, $05, $05, $05, $05, $05, $05, $05, $07
CardRead.PrinterFull:
db $03, $00, $f1, $f2, $00, $f9, $fa, $00, $04
db $06, $05, $05, $05, $05, $05, $05, $05, $07
CardRead.PrinterPrinting:
db $03, $00, $f1, $f2, $00, $f7, $f8, $00, $04
db $06, $05, $05, $05, $05, $05, $05, $05, $07
CardRead.PrinterError:
db $03, $00, $f1, $f2, $00, $f5, $f6, $00, $04
db $06, $05, $05, $05, $05, $05, $05, $05, $07
CardRead.PrinterTiles:
db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
db $00,$1c,$00,$0e,$38,$3f,$64,$7f,$7f,$7f,$7f,$40,$7f,$40,$3f,$3f
db $00,$00,$00,$00,$00,$00,$06,$b6,$ff,$ff,$ff,$11,$ff,$11,$fe,$fe
db $00,$00,$00,$00,$0e,$0e,$12,$1e,$24,$3c,$38,$38,$00,$00,$00,$00
db $00,$00,$00,$00,$5a,$5a,$92,$92,$5a,$5a,$52,$52,$9b,$9b,$00,$00
db $00,$00,$18,$18,$18,$18,$18,$18,$18,$18,$00,$00,$18,$18,$00,$00
db $00,$00,$00,$00,$d8,$d8,$94,$94,$d8,$d8,$94,$94,$d2,$d2,$00,$00
db $00,$00,$00,$00,$19,$19,$15,$15,$19,$19,$11,$11,$11,$11,$00,$00
db $00,$00,$00,$00,$92,$92,$5a,$5a,$96,$96,$52,$52,$52,$52,$00,$00
db $00,$00,$00,$00,$1d,$1d,$11,$11,$19,$19,$11,$11,$11,$11,$00,$00
db $00,$00,$00,$00,$52,$52,$52,$52,$52,$52,$52,$52,$db,$db,$00,$00
CardRead.PrinterTilesEnd:
CardRead.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
CardRead.UITilemapEnd: