442 lines
10 KiB
PHP
442 lines
10 KiB
PHP
DEF vFrameCount1 EQU VARIABLES_START
|
|
DEF vFrameCount2 equ vFrameCount1+1
|
|
DEF vFrameCount3 EQU vFrameCount2+1
|
|
PRINTLN "vframecount is ", vFrameCount1
|
|
DEF vTime EQU vFrameCount3+1 ; 16bit
|
|
|
|
|
|
ShuffleDeckSetup:
|
|
; Turn the LCD off
|
|
ld hl, rLCDC
|
|
bit 7, [hl]
|
|
jp z, CardReadSetup_ScreenOff
|
|
ShuffleDeckSetup_BusyWait:
|
|
ld a, [rLY]
|
|
cp a, 143
|
|
jp c, CardReadSetup_BusyWait
|
|
ld [hl], 0
|
|
|
|
ShuffleDeckSetup_ScreenOff:
|
|
ld a, 0
|
|
ldh [rLCDC], a
|
|
|
|
ld hl, CardBackSprites ; source
|
|
ld de, $8000; destination of copy
|
|
ld bc, CardBackSpritesEnd - CardBackSprites ; length to copy
|
|
call CopyRangeUnsafe
|
|
|
|
; set LCD and display registers
|
|
ld a, %11100100
|
|
ld [rBGP], a
|
|
ld [rOBP0], a
|
|
|
|
ld a, LCDCF_BLK01 | LCDCF_ON | LCDCF_BGON | LCDCF_OBJON | LCDCF_OBJ16
|
|
ldh [rLCDC], a
|
|
|
|
ld a, 0
|
|
ldh [vFrameCount1], a ; first starts at 0
|
|
ldh [vTime], a
|
|
ldh [vTime+1], a
|
|
|
|
; second starts at 1/3 length which is approximately L/2 - L/4 - L/8 + L/16 ?
|
|
ld hl, Coords
|
|
ld a, [hl]
|
|
ld b, a
|
|
srl b
|
|
sub a, b ; L - L/2
|
|
srl b
|
|
sub a, b ; L - L/2 - L/4
|
|
srl b
|
|
add a, b ; L - L/2 - L/4 + L/8
|
|
srl b
|
|
sub a, b ; L - L/2 - L/4 + L/8 - L/16
|
|
srl b
|
|
add a, b ; L - L/2 - L/4 + L/8 - L/16 + L/32
|
|
srl b
|
|
sub a, b ; L - L/2 - L/4 + L/8 - L/16 + L/32 - L/64
|
|
srl b
|
|
add a, b ; L - L/2 - L/4 + L/8 - L/16 + L/32 - L/64 + L/128
|
|
; that should be approx 1/3 of L !
|
|
ldh [vFrameCount2], a
|
|
|
|
; third starts at 2/3 length which is approximately L/2 - L/4 + L/8 - L/16 ?
|
|
ld hl, Coords
|
|
ld a, [hl]
|
|
ld b, a
|
|
srl b
|
|
sub a, b ; L - L/2
|
|
srl b
|
|
add a, b ; L - L/2 + L/4
|
|
srl b
|
|
sub a, b ; L - L/2 + L/4 - L/8
|
|
srl b
|
|
add a, b ; L - L/2 + L/4 - L/8 + L/16
|
|
srl b
|
|
sub a, b ; L - L/2 + L/4 - L/8 + L/16 - L/32
|
|
srl b
|
|
add a, b ; L - L/2 + L/4 - L/8 + L/16 - L/32 + L/64
|
|
srl b
|
|
sub a, b ; L - L/2 + L/4 - L/8 + L/16 - L/32 + L/64 - L/128
|
|
; that should be just about 2/3 of L !
|
|
ldh [vFrameCount3], a
|
|
|
|
|
|
; load graphics into vram for deck face
|
|
; set up variables: LFSR stuff
|
|
ret ; return from cardreadsetup
|
|
|
|
ShuffleDeckUpdate:
|
|
; if pressing a key and unblocked:
|
|
; signal an animation to start
|
|
; turn on block
|
|
; if in animation state:
|
|
; increment timer
|
|
; if timer is max, turn off animation state and unblock?
|
|
|
|
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
|
|
|
|
cp a, $01
|
|
jp c, ShuffleDeckUpdate_Done ; if the timer is less than $1000, skip to end
|
|
|
|
;otherwise reset the timer
|
|
ld a, 0
|
|
ldh [vTime], a
|
|
ldh [vTime+1], a
|
|
|
|
|
|
ld hl, Coords
|
|
|
|
; and advance the frame counts
|
|
ldh a, [vFrameCount1]
|
|
inc a
|
|
call ArrayClampLooping
|
|
ldh [vFrameCount1], a
|
|
|
|
ldh a, [vFrameCount2]
|
|
inc a
|
|
call ArrayClampLooping
|
|
ldh [vFrameCount2], a
|
|
|
|
ldh a, [vFrameCount3]
|
|
inc a
|
|
call ArrayClampLooping
|
|
ldh [vFrameCount3], a
|
|
|
|
ShuffleDeckUpdate_Done:
|
|
ret
|
|
|
|
ShuffleDeckDraw:
|
|
ld hl, Coords
|
|
inc hl
|
|
ld b, 0
|
|
ld a, [vFrameCount1]
|
|
ld c, a
|
|
add hl, bc
|
|
add hl, bc
|
|
add hl, bc
|
|
ld a, [hl+]
|
|
ld b, a ; y coordinate
|
|
ld a, [hl+]
|
|
ld c, a ; x coordinate
|
|
ld a, [hl+]
|
|
ld e, a ; spread value
|
|
ld hl, $fe00
|
|
call DrawWholeCard
|
|
|
|
ld hl, Coords
|
|
inc hl
|
|
ld b, 0
|
|
ld a, [vFrameCount2]
|
|
ld c, a
|
|
add hl, bc
|
|
add hl, bc
|
|
add hl, bc
|
|
ld a, [hl+]
|
|
ld b, a ; y coordinate
|
|
ld a, [hl+]
|
|
ld c, a ; x coordinate
|
|
ld a, [hl+]
|
|
ld e, a ; spread value
|
|
ld hl, $fe00 + 3*4
|
|
call DrawWholeCard
|
|
|
|
ld hl, Coords
|
|
inc hl
|
|
ld b, 0
|
|
ld a, [vFrameCount3]
|
|
ld c, a
|
|
add hl, bc
|
|
add hl, bc
|
|
add hl, bc
|
|
ld a, [hl+]
|
|
ld b, a ; y coordinate
|
|
ld a, [hl+]
|
|
ld c, a ; x coordinate
|
|
ld a, [hl+]
|
|
ld e, a ; spread value
|
|
ld hl, $fe00 + 6*4
|
|
call DrawWholeCard
|
|
|
|
|
|
ret
|
|
|
|
ShuffleDeckTeardown:
|
|
ret
|
|
|
|
DrawWholeCard: ; hl memory location, b y, c x, e step
|
|
jp Draw3x3Card
|
|
Draw2x2Card:
|
|
; hl memory location, b y coord, c x coord, e step
|
|
; top-left
|
|
ld d, $02
|
|
call DrawTile
|
|
|
|
ld a, c
|
|
add a, e ; addd stride to x
|
|
ld c, a
|
|
ld a, e
|
|
cp a, 5
|
|
ld d, $04
|
|
call DrawTile
|
|
|
|
ld d, $06
|
|
ld a, c
|
|
add a, e ; add stride to x
|
|
;sub a, 8
|
|
ld c, a
|
|
call DrawTile
|
|
|
|
push bc
|
|
ld b, 0
|
|
ld c, 6*4
|
|
add hl, bc ; advance by 6 oam slots?
|
|
pop bc
|
|
|
|
ld d, $08
|
|
ld a, b
|
|
add a, 8
|
|
add a, 8
|
|
ld b, a ; add 16 to y coord
|
|
ld a, c
|
|
sub a, e
|
|
sub a, e
|
|
ld c, a ; subtract stridex2 from x
|
|
call DrawTile
|
|
|
|
|
|
ld d, $0a
|
|
ld a, c
|
|
add a, e
|
|
ld c, a
|
|
call DrawTile
|
|
|
|
ld d, $0c
|
|
ld a, c
|
|
add a, e
|
|
ld c, a
|
|
call DrawTile
|
|
|
|
push bc
|
|
ld b, 0
|
|
ld c, 6*4
|
|
add hl, bc ; advance by 6 oam slots so the other two cards have room
|
|
pop bc
|
|
|
|
ld d, $0e
|
|
ld a, b
|
|
sub a, 8
|
|
sub a, 8
|
|
add a, e
|
|
add a, e
|
|
add a, e
|
|
add a, e
|
|
ld b, a ; add stridex2 to y coord
|
|
ld a, c
|
|
sub a, e
|
|
sub a, e
|
|
ld c, a ; subtract stridex2 from x
|
|
call DrawTile
|
|
|
|
ld d, $10
|
|
ld a, c
|
|
add a, e
|
|
ld c, a
|
|
call DrawTile
|
|
|
|
ld d, $12
|
|
ld a, c
|
|
add a, e
|
|
ld c, a
|
|
call DrawTile
|
|
ret
|
|
|
|
Draw3x3Card:
|
|
; hl memory location, b y coord, c x coord, e step
|
|
; top-left
|
|
ld d, $02
|
|
call DrawTile
|
|
|
|
ld a, c
|
|
add a, e ; addd stride to x
|
|
ld c, a
|
|
ld a, e
|
|
cp a, 5
|
|
ld d, $04
|
|
call DrawTile
|
|
|
|
ld d, $06
|
|
ld a, c
|
|
add a, e ; add stride to x
|
|
;sub a, 8
|
|
ld c, a
|
|
call DrawTile
|
|
|
|
push bc
|
|
ld b, 0
|
|
ld c, 6*4
|
|
add hl, bc ; advance by 6 oam slots?
|
|
pop bc
|
|
|
|
ld d, $08
|
|
ld a, b
|
|
add a, 8
|
|
add a, 8
|
|
ld b, a ; add 16 to y coord
|
|
ld a, c
|
|
sub a, e
|
|
sub a, e
|
|
ld c, a ; subtract stridex2 from x
|
|
call DrawTile
|
|
|
|
|
|
ld d, $0a
|
|
ld a, c
|
|
add a, e
|
|
ld c, a
|
|
call DrawTile
|
|
|
|
ld d, $0c
|
|
ld a, c
|
|
add a, e
|
|
ld c, a
|
|
call DrawTile
|
|
|
|
push bc
|
|
ld b, 0
|
|
ld c, 6*4
|
|
add hl, bc ; advance by 6 oam slots so the other two cards have room
|
|
pop bc
|
|
|
|
ld d, $0e
|
|
ld a, b
|
|
sub a, 8
|
|
sub a, 8
|
|
add a, e
|
|
add a, e
|
|
add a, e
|
|
add a, e
|
|
ld b, a ; add stridex2 to y coord
|
|
ld a, c
|
|
sub a, e
|
|
sub a, e
|
|
ld c, a ; subtract stridex2 from x
|
|
call DrawTile
|
|
|
|
ld d, $10
|
|
ld a, c
|
|
add a, e
|
|
ld c, a
|
|
call DrawTile
|
|
|
|
ld d, $12
|
|
ld a, c
|
|
add a, e
|
|
ld c, a
|
|
call DrawTile
|
|
ret
|
|
|
|
DrawTile: ; b: y. a: x. d: sprite. hl: location of sprite in OAM
|
|
ld a, b
|
|
ld [hl+], a ; y byte
|
|
|
|
ld a, c
|
|
ld [hl+], a ; x byte
|
|
|
|
ld a, d
|
|
ld [hl+], a ; tile index
|
|
ld a, $00
|
|
ld [hl+], a ; attributes
|
|
ret
|
|
Coords: ; y, x, spread
|
|
db 160, $1f, $13, $6, $1f, $13, $6, $1f, $13, $6, $1f, $13, $6, $1f, $13, $6,
|
|
db $1e, $14, $6, $1e, $14, $6, $1e, $14, $7, $1e, $15, $7, $1e, $16, $7, $1e, $16,
|
|
db $7, $1e, $17, $7, $1e, $18, $7, $1e, $19, $7, $1d, $1a, $7, $1d, $1b, $7, $1d, $1d,
|
|
db $7, $1d, $1e, $7, $1d, $1f, $7, $1d, $21, $7, $1d, $22, $7, $1d, $24, $7, $1d, $26,
|
|
db $8, $1d, $27, $8, $1d, $29, $8, $1d, $2b, $8, $1c, $2d, $8, $1c, $2f, $8, $1c, $31,
|
|
db $8, $1c, $33, $8, $1c, $35, $8, $1c, $37, $8, $1c, $3a, $8, $1c, $3c, $8, $1c, $3e,
|
|
db $8, $1c, $40, $8, $1c, $43, $8, $1c, $45, $8, $1c, $47, $8, $1c, $4a, $8, $1c, $4c,
|
|
db $8, $1c, $4e, $8, $1c, $51, $8, $1c, $53, $8, $1c, $55, $8, $1c, $58, $8, $1c, $5a,
|
|
db $8, $1c, $5c, $8, $1c, $5f, $8, $1c, $61, $8, $1c, $63, $8, $1c, $65, $8, $1c, $68,
|
|
db $8, $1c, $6a, $8, $1c, $6c, $8, $1d, $6e, $8, $1d, $70, $8, $1d, $72, $8, $1d, $74,
|
|
db $8, $1d, $76, $7, $1d, $77, $7, $1d, $79, $7, $1d, $7b, $7, $1d, $7c, $7, $1d, $7e,
|
|
db $7, $1d, $7f, $7, $1d, $81, $7, $1e, $82, $7, $1e, $83, $7, $1e, $84, $7, $1e, $85,
|
|
db $7, $1e, $86, $7, $1e, $87, $7, $1e, $88, $7, $1e, $89, $6, $1e, $89, $6, $1f, $8a,
|
|
db $6, $1f, $8a, $6, $1f, $8b, $6, $1f, $8b, $6, $1f, $8b, $6, $1f, $8b, $6, $1f, $8b,
|
|
db $6, $1f, $8b, $6, $1f, $8b, $6, $20, $8a, $6, $20, $8a, $6, $20, $8a, $5, $20, $89,
|
|
db $5, $20, $88, $5, $20, $88, $5, $20, $87, $5, $20, $86, $5, $20, $85, $5, $21, $84,
|
|
db $5, $21, $83, $5, $21, $81, $5, $21, $80, $5, $21, $7f, $5, $21, $7d, $5, $21, $7c,
|
|
db $5, $21, $7a, $5, $21, $78, $4, $21, $77, $4, $21, $75, $4, $21, $73, $4, $22, $71,
|
|
db $4, $22, $6f, $4, $22, $6d, $4, $22, $6b, $4, $22, $69, $4, $22, $67, $4, $22, $64,
|
|
db $4, $22, $62, $4, $22, $60, $4, $22, $5e, $4, $22, $5b, $4, $22, $59, $4, $22, $57,
|
|
db $4, $22, $54, $4, $22, $52, $4, $22, $50, $4, $22, $4d, $4, $22, $4b, $4, $22, $49,
|
|
db $4, $22, $46, $4, $22, $44, $4, $22, $42, $4, $22, $3f, $4, $22, $3d, $4, $22, $3b,
|
|
db $4, $22, $39, $4, $22, $36, $4, $22, $34, $4, $22, $32, $4, $21, $30, $4, $21, $2e,
|
|
db $4, $21, $2c, $4, $21, $2a, $4, $21, $28, $5, $21, $27, $5, $21, $25, $5, $21, $23,
|
|
db $5, $21, $22, $5, $21, $20, $5, $21, $1f, $5, $21, $1d, $5, $20, $1c, $5, $20, $1b,
|
|
db $5, $20, $1a, $5, $20, $19, $5, $20, $18, $5, $20, $17, $5, $20, $16, $5, $20, $15,
|
|
db $6, $20, $15, $6, $1f, $14, $6, $1f, $14, $6, $1f, $13, $6, $1f, $13, $6
|
|
|
|
|
|
CardBackSprites:
|
|
db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
|
|
db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
|
|
|
|
db $00,$ff,$7f,$ff,$7f,$ff,$60,$ff,$6f,$ff,$6d,$fa,$6a,$fd,$6d,$fa
|
|
db $6a,$fd,$6d,$fa,$6a,$fd,$6d,$fa,$6a,$fd,$6d,$fa,$6a,$fd,$6d,$fa
|
|
|
|
db $00,$ff,$ff,$ff,$ff,$ff,$00,$ff,$ff,$ff,$55,$aa,$aa,$55,$55,$aa
|
|
db $aa,$55,$55,$aa,$aa,$55,$55,$aa,$aa,$55,$55,$aa,$aa,$55,$55,$aa
|
|
|
|
db $00,$ff,$f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