385 lines
		
	
	
		
			9.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			385 lines
		
	
	
		
			9.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| ; screen variables shared with screencardread
 | |
| PUSHS UNION "Screen Variables", WRAM0[SCREEN_VARS_START]
 | |
| ds 32 ; why are we putting this so far in? i don't remember but whatever
 | |
| vPrintJobState: db ; start, wait til ready, top row, row a, wait, printing, bottom row
 | |
| vPrintingRow: db
 | |
| vExposureSetting: db
 | |
| POPS
 | |
| 
 | |
| ScreenCardBrowse:
 | |
|   dw CardBrowseSetup
 | |
|   dw CardBrowseUpdate
 | |
|   dw CardBrowseDraw
 | |
|   dw CardBrowseTeardown
 | |
| 
 | |
| CardBrowseSetup:
 | |
|   ld a, 1 
 | |
|   ld [vBlocked], a 
 | |
|   ld [vTooBusyForPrinter], a 
 | |
|   
 | |
|   call CardPreload
 | |
|   
 | |
|   ld hl, .asyncTask
 | |
|   call Async_Spawn_HL
 | |
|   
 | |
|   call CheckForPrinter
 | |
|   ret
 | |
|   
 | |
| .asyncTask:
 | |
|   ld hl, CardBrowse.UITilemap ; origin
 | |
|   ld de, _SCRN0 ; destination
 | |
|   ld b, 18 ; height
 | |
|   ld c, 20 ; width
 | |
|   call CopyTilesToMap
 | |
|   
 | |
|   ld hl, CardBrowse.PrinterTiles
 | |
|   ld de, _VRAM + $1000 - $10*16
 | |
|   ld bc, CardBrowse.PrinterTilesEnd - CardBrowse.PrinterTiles
 | |
|   call CopyRange
 | |
|   
 | |
|   ld a, 0 
 | |
|   ld [vBlocked], a 
 | |
|   
 | |
|   call RefreshCardTask
 | |
|   
 | |
|   ret
 | |
| 
 | |
| CardBrowseUpdate:
 | |
|   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, CardBrowse.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, ScreenMainMenu
 | |
|     call ChangeScene
 | |
|     ret
 | |
|   .doneWithB
 | |
|   
 | |
|   ld hl, rMYBTNP
 | |
|   bit 4, [hl]
 | |
|   jp z, .doneWithA
 | |
|     ld a, [vSelectedCardIndex]
 | |
|     ld b, 0 
 | |
|     ld c, a 
 | |
|     ld hl, DECK_FLIPS+1
 | |
|     add hl, bc 
 | |
|     ld a, [hl]
 | |
|     xor a, %10000000
 | |
|     ld [hl], a 
 | |
| 
 | |
|     jr .attemptCardChange
 | |
|   .doneWithA
 | |
|   
 | |
|   ld a, [vSelectedCardIndex]
 | |
|   ld hl, rMYBTNP
 | |
|   bit 0, [hl]
 | |
|   jp z, :+ ; skip the following code if left is not pressed
 | |
|     inc a 
 | |
|   :
 | |
|   bit 1, [hl]
 | |
|   jp z, :+ ; skip the following code if right is not pressed
 | |
|     dec a 
 | |
|   :
 | |
|   ld [vSelectedCardIndex], a 
 | |
|   ld hl, Cards 
 | |
|   call ArrayClampLooping
 | |
|   ld [vSelectedCardIndex], a 
 | |
|   
 | |
|   ld hl, rMYBTNP
 | |
|   bit 2, [hl] ; up
 | |
|   jp z, :+
 | |
|     ld hl, AdjacentCards.Ups+1
 | |
|     ld b, 0
 | |
|     ld c, a 
 | |
|     add hl, bc
 | |
|     ld a, [hl] 
 | |
|   :
 | |
|   
 | |
|   ld hl, rMYBTNP
 | |
|   bit 3, [hl] ; up
 | |
|   jp z, :+
 | |
|     ld hl, AdjacentCards.Downs+1
 | |
|     ld b, 0
 | |
|     ld c, a 
 | |
|     add hl, bc
 | |
|     ld a, [hl] 
 | |
|   :
 | |
|   
 | |
|   ld [vSelectedCardIndex], a 
 | |
|   ld hl, Cards 
 | |
|   call ArrayClampLooping
 | |
|   ld [vSelectedCardIndex], a 
 | |
|   
 | |
|   .doneWithButtons
 | |
|   
 | |
|   ld a, [vSelectedCardIndex]
 | |
|   ld hl, vPreviousCardIndex
 | |
|   cp a, [hl]
 | |
|   ret z ; if the selected card didn't change, nothing to do
 | |
|   
 | |
|   .attemptCardChange
 | |
|   
 | |
|   ld a, [vBlocked]
 | |
|   cp a, 0 
 | |
|   ret nz
 | |
|   
 | |
|   ld a, 1
 | |
|   ld [vTooBusyForPrinter], a
 | |
|   
 | |
|   call CardPreload
 | |
|   
 | |
|   ld hl, RefreshCardTask
 | |
|   call Async_Spawn_HL
 | |
|   
 | |
|   ret
 | |
| 
 | |
| AdjacentCards: ; what card indices do down/up go to from each card?
 | |
| .Downs:
 | |
|   db 78
 | |
|   db 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
 | |
|   db 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33
 | |
|   db 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49
 | |
|   db 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63
 | |
|   db 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77
 | |
|   db  0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  9,  9,  9,  9
 | |
| .Ups:
 | |
|   db 78
 | |
|   db 64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
 | |
|   db  0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  9,  9
 | |
|   db 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 21, 21
 | |
|   db 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35
 | |
|   db 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49
 | |
|   db 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63
 | |
|       
 | |
|   
 | |
| CardBrowseDraw:
 | |
|   call CardDraw
 | |
|   
 | |
|   ld a, [vCurrentBackgroundTile]
 | |
|   ld l, a 
 | |
|   ld a, [vCurrentBackgroundTile+1]
 | |
|   ld h, a 
 | |
|   ld de, _VRAM + $1000 + 1*16
 | |
|   call CopyOneTileData
 | |
| 
 | |
|   ld de, SAFE_DMA_LOCATION
 | |
|   ld a, HIGH(MY_OAM)
 | |
|   call RunDMA
 | |
|   
 | |
|   ret
 | |
| 
 | |
| 
 | |
|   
 | |
| RefreshCardTask:
 | |
|   ld a, [vSelectedCardIndex]
 | |
|   ld [vPreviousCardIndex], a  
 | |
|   
 | |
|   call DrawDeckMinimap
 | |
|   call LoadCardData
 | |
|   call CardBrowse.UpdatePrintUIImmediate
 | |
|   
 | |
|   ld a, 0 
 | |
|   ld [vTooBusyForPrinter], a
 | |
|   ret
 | |
|   
 | |
| DrawDeckMinimap:
 | |
|   ld hl, Cards 
 | |
|   ld c, [hl] ; count of cards
 | |
|   srl c 
 | |
|   ;set 0, c
 | |
|   
 | |
|   ld hl, vSelectedCardIndex
 | |
|   ld d, [hl] ; selected card!
 | |
|   ld b, $ff ; start at -1 lol
 | |
|   ld hl, _SCRN0 + 32 + 10
 | |
|   
 | |
|   ; for this loop, c holds the total tile count
 | |
|   ; d holds the card which is currently selected
 | |
|   ; b holds the index of the TILE (two cards) we're currently drawing
 | |
|   ; hl points to the place we're drawing
 | |
|   .loop
 | |
|     inc hl 
 | |
|     inc b
 | |
|     ld a, b
 | |
|     cp a, 5 ; after we've drawn 5 tiles (10 cards), draw a newline
 | |
|     jp nz, :+
 | |
|       ld [hl], $13
 | |
|       ld hl, _SCRN0 + 32*2 + 11
 | |
|     :
 | |
|     cp a, 11 ; after we've drawn 11 tiles (5 + 6) draw a newline
 | |
|     jp nz, :+
 | |
|       ld [hl], $13
 | |
|       ld hl, _SCRN0 + 32*3 + 11
 | |
|     :
 | |
|     cp a, 18 ; after we've drawn 18 tiles (5 + 6 + 7) draw a newline
 | |
|     jp nz, :+
 | |
|       ld [hl], $13
 | |
|       ld hl, _SCRN0 + 32*4 + 11
 | |
|     :
 | |
|     cp a, 25 ; after we've drawn 25 tiles (5 + 6 + 7 + 7) draw a newline
 | |
|     jp nz, :+
 | |
|       ld [hl], $13
 | |
|       ld hl, _SCRN0 + 32*5 + 11
 | |
|     :
 | |
|     cp a, 32 ; after we've drawn 32 tiles (5 + 6 + 7 + 7 + 7) draw a newline
 | |
|     jp nz, :+
 | |
|       ld [hl], $13
 | |
|       ld hl, _SCRN0 + 32*6 + 11
 | |
|     :
 | |
|     ; add more conditions here to define newlines!
 | |
|   .noNewLine
 | |
|     ld a, b
 | |
|     cp a, c 
 | |
|     jp nc, .doneDrawing ; if b - c doesn't underflow, then we're done; jump to the end 
 | |
|     
 | |
|     ld a, d 
 | |
|     srl a ; divide current index by two
 | |
|     cp a, b ; check if the currently selected card is in current tile
 | |
|     jp z, .drawSelectedCard 
 | |
|     .drawUnselectedCards ; if it's not, then draw unselected cards
 | |
|       ld [hl], $12
 | |
|       jp .loop
 | |
|     .drawSelectedCard ; if it's in this tile, draw it
 | |
|       bit 0, d 
 | |
|       jp nz, .drawSelectedSecond ; if the 1 bit of the current selection is zero, draw the left-selected-tile
 | |
|         ld [hl], $14
 | |
|         jp .loop
 | |
|       .drawSelectedSecond ; if the 1 bit is nonzero draw the right-selected-tile
 | |
|         ld [hl], $15
 | |
|         jp .loop
 | |
|   .doneDrawing
 | |
|   ld [hl], $13 ; when we're done, draw a cap
 | |
|   ret
 | |
|   
 | |
| CardBrowse.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 continue to change ui
 | |
|   ld [hl], a 
 | |
|   
 | |
|   ld hl, CardBrowse.UpdatePrintUIImmediate
 | |
|   call Async_Spawn_HL
 | |
|   ret
 | |
|   
 | |
| CardBrowse.UpdatePrintUIImmediate:
 | |
|   ld a, [vPrinterState]
 | |
|   
 | |
|   ld hl, CardBrowse.PrinterNotDetected
 | |
|   cp a, PS_NONE
 | |
|   jp z, .setIt
 | |
| 
 | |
|   ld hl, CardBrowse.PrinterAvailable
 | |
|   cp a, PS_READY
 | |
|   jp z, .setIt
 | |
|   
 | |
|   ld hl, CardBrowse.PrinterFull
 | |
|   cp a, PS_FULL
 | |
|   jp z, .setIt
 | |
|   
 | |
|   ld hl, CardBrowse.PrinterPrinting
 | |
|   cp a, PS_PRINTING
 | |
|   jp z, .setIt
 | |
|   
 | |
|   ld hl, CardBrowse.PrinterError
 | |
|   cp a, PS_ERROR
 | |
|   jp z, .setIt
 | |
|   
 | |
|   .setIt
 | |
|   ld de, _SCRN0 + 32*1 + 17
 | |
|   ld b, 2
 | |
|   ld c, 2
 | |
|   call CopyTilesToMap
 | |
|   ret
 | |
| 
 | |
| CardBrowse.PrinterNotDetected:
 | |
|   db $00, $00
 | |
|   db $13, $00
 | |
| CardBrowse.PrinterAvailable:
 | |
|   db $f1, $f2
 | |
| 	db $f3, $f4
 | |
| CardBrowse.PrinterFull:
 | |
|   db $f1, $f2
 | |
|   db $f9, $fa
 | |
| CardBrowse.PrinterPrinting:
 | |
|   db $f1, $f2
 | |
|   db $f7, $f8
 | |
| CardBrowse.PrinterError:
 | |
|   db $f1, $f2
 | |
|   db $f5, $f6
 | |
| 
 | |
| CardBrowseTeardown:
 | |
|   ret
 | |
| 
 | |
| 
 | |
| CardBrowse.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,$80,$0e,$8e,$12,$9e,$24,$bc,$38,$b8,$00,$80,$00,$00
 | |
| 	db $00,$00,$00,$00,$5a,$5a,$92,$92,$5a,$5a,$52,$52,$9b,$9b,$00,$00
 | |
| 	db $00,$00,$18,$98,$18,$98,$18,$98,$18,$98,$00,$80,$18,$98,$00,$00
 | |
| 	db $00,$00,$00,$00,$d8,$d8,$94,$94,$d8,$d8,$94,$94,$d2,$d2,$00,$00
 | |
| 	db $00,$00,$00,$80,$19,$99,$15,$95,$19,$99,$11,$91,$11,$91,$00,$00
 | |
| 	db $00,$00,$00,$00,$92,$92,$5a,$5a,$96,$96,$52,$52,$52,$52,$00,$00
 | |
| 	db $00,$00,$00,$80,$1d,$9d,$11,$91,$19,$99,$11,$91,$11,$91,$00,$00
 | |
| 	db $00,$00,$00,$00,$52,$52,$52,$52,$52,$52,$52,$52,$db,$db,$00,$00
 | |
| CardBrowse.PrinterTilesEnd: ; $22
 | |
| 
 | |
| 
 | |
| CardBrowse.UITilemap:
 | |
| 	db $0e, $0a, $0a, $0a, $0a, $0a, $0a, $0a, $0a, $0f, $09, $02, $02, $02, $02, $02, $02, $02, $02, $08
 | |
| 	db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $03, $00, $00, $00, $00, $00, $00, $00, $00, $04
 | |
| 	db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $03, $00, $00, $00, $00, $00, $00, $00, $00, $04
 | |
| 	db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $03, $00, $00, $00, $00, $00, $00, $00, $00, $04
 | |
| 	db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $03, $00, $00, $00, $00, $00, $00, $00, $00, $04
 | |
| 	db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $03, $00, $00, $00, $00, $00, $00, $00, $00, $04
 | |
| 	db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $03, $00, $00, $00, $00, $00, $00, $00, $00, $04
 | |
| 	db $0b, $00, $00, $00, $00, $00, $00, $00, $00, $0c, $06, $05, $05, $05, $05, $05, $05, $05, $05, $07
 | |
| 	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
 | |
| CardBrowse.UITilemapEnd:
 |