diff --git a/CardReadScreen.inc b/CardReadScreen.inc index 848b210..b34b76d 100644 --- a/CardReadScreen.inc +++ b/CardReadScreen.inc @@ -1,5 +1,5 @@ ; screen variables -DEF vSelectedCardIndex EQU rMYBTNP + 1 +DEF vSelectedCardIndex EQU VARIABLES_START DEF vPreviousCardIndex EQU vSelectedCardIndex + 1 DEF vSelectedCardInSpread EQU vPreviousCardIndex + 1 DEF vSelectedSpreadAddress EQU vSelectedCardInSpread + 1 @@ -7,11 +7,18 @@ DEF vSelectedSpreadAddress EQU vSelectedCardInSpread + 1 ;; CARD READ PAGE STARTS HERE CardReadSetup: ; Turn the LCD off - ld a, 0 - ld [rLCDC], a + ld hl, rLCDC + bit 7, [hl] + jp z, CardReadSetup_ScreenOff +CardReadSetup_BusyWait: + ld a, [rLY] + cp a, 143 + jp c, CardReadSetup_BusyWait + ld [hl], 0 +CardReadSetup_ScreenOff: ld hl, UITiles ; source - ld de, $8800 ; destination of copy + ld de, $8000 + $80*16; destination of copy ld bc, UITilesEnd - UITiles ; length to copy call CopyRangeUnsafe @@ -26,14 +33,14 @@ CardReadSetup: ld c, 10 ; width call CopyTilesToMapUnsafe - ; Turn the LCD on - ld a, LCDCF_BLK01 | LCDCF_ON | LCDCF_BGON - ld [rLCDC], a - - ; During the first (blank) frame, initialize display registers + ; set LCD and display registers ld a, %11100100 ld [rBGP], a + ld a, LCDCF_BLK01 | LCDCF_ON | LCDCF_BGON + ld [rLCDC], a + + ; arguments for the screen ld a, 0 ldh [vSelectedCardInSpread], a ld hl, Spreads @@ -50,15 +57,14 @@ CardReadSetup: ret ; return from cardreadsetup CardReadUpdate: - ldh a, [rMYBTNP] - and a, %0000_1000 ; select the down key + ld hl, rMYBTNP + bit 3, [hl] ; select the down key jp z, :+ ; skip the following code if down is not pressed ldh a, [vSelectedCardIndex] inc a ; increment when they press down because the deck has card 0 at the top ldh [vSelectedCardIndex], a : - ldh a, [rMYBTNP] - and a, %0000_0100 ; select the up key + bit 2, [hl] ; select up key %0000_0100 jp z, :+ ; skip the following code if up is not pressed ldh a, [vSelectedCardIndex] dec a ; decrement when they press up because the deck has card 0 at the top @@ -78,15 +84,14 @@ CardReadUpdate: ldh [vSelectedCardIndex], a : - ldh a, [rMYBTNP] - and a, %0000_0010 ; select the left key + ld hl, rMYBTNP + bit 1, [hl] jp z, :+ ; skip the following code if left is not pressed ldh a, [vSelectedCardInSpread] dec a ldh [vSelectedCardInSpread], a : - ldh a, [rMYBTNP] - and a, %0000_0001 ; select the right key + bit 0, [hl] jp z, :+ ; skip the following code if right is not pressed ldh a, [vSelectedCardInSpread] inc a diff --git a/CopyRangeSafe.inc b/CopyRangeSafe.inc index 5f7015c..2632d2b 100644 --- a/CopyRangeSafe.inc +++ b/CopyRangeSafe.inc @@ -56,7 +56,7 @@ CopyRangeSafe: ld [INTERRUPT_LCD], a ld a, h ld [INTERRUPT_LCD + 1], a; set interrupt handler to "ENTER SAFE MODE" - ld a, 148 ; CHANGE ME TO ADJUST SAFE TRANSFER TIMING + ld a, 143 ; CHANGE ME TO ADJUST SAFE TRANSFER TIMING ld [$ff45], a ld hl, $ffff set 1, [hl] @@ -110,7 +110,6 @@ CopyRangeSafe_EnterSafeMode: CopyRangeSafe_TransferLoop: ei nop ; ei only sets the flag one instruction later apparently. safety nop! - nop di ; process interrupts jp z, CopyRangeSafe_CleanUp ; zero flag will only be set if the exitsafemode handler fired ld a, [hl+] @@ -146,7 +145,7 @@ CopyRangeSafe_CleanUp: ld [INTERRUPT_LCD], a ld a, h ld [INTERRUPT_LCD+1], a - ld a, 148 ; CHANGE ME TO ADJUST SAFE TRANSFER TIMING + ld a, 143 ; CHANGE ME TO ADJUST SAFE TRANSFER TIMING ld [$ff45], a ; set lcd interrupt handler to ENTER SAFE MODE on line 148 pop af pop de @@ -175,7 +174,7 @@ CopyRangeSafe_Done: ; called when the complete transfer is finished, ld [INTERRUPT_LCD], a ld a, h ld [INTERRUPT_LCD+1], a - ld a, 148 ; CHANGE ME TO ADJUST SAFE TRANSFER TIMING + ld a, 143 ; CHANGE ME TO ADJUST SAFE TRANSFER TIMING ld [$ff45], a ; set lcd interrupt handler to ENTER SAFE MODE on line 148 pop af pop de @@ -210,7 +209,7 @@ CopyRangeUnsafe: ; hl is source ; de is destination ; bc is length to copy - ld a, [hli] + ld a, [hl+] ld [de], a inc de dec bc diff --git a/KeyArtTiles.asm b/KeyArtTiles.asm new file mode 100644 index 0000000..4c3d9fa --- /dev/null +++ b/KeyArtTiles.asm @@ -0,0 +1,25 @@ + ; original export script by gabriel reis, modified by shoofle + + +KeyArtTiles: + + 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,$fe,$ff,$fe,$ff,$06,$ff,$f6,$ff,$56,$bf,$b6,$5f,$56,$bf + db $b6,$5f,$56,$bf,$b6,$5f,$56,$bf,$b6,$5f,$56,$bf,$b6,$5f,$56,$bf + db $6a,$fd,$6d,$fa,$6a,$fd,$6f,$ff,$60,$ff,$7f,$ff,$7f,$ff,$00,$ff + db $b6,$5f,$56,$bf,$b6,$5f,$f6,$ff,$06,$ff,$fe,$ff,$fe,$ff,$00,$ff + 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 $aa,$55,$55,$aa,$aa,$55,$ff,$ff,$00,$ff,$ff,$ff,$ff,$ff,$00,$ff + + + +BackgroundCopy: + db $01, $07, $03 + db $02, $08, $04 + db $02, $08, $04 + db $02, $08, $04 + db $02, $08, $04 + db $05, $09, $06 diff --git a/ShuffleDeckScreen.inc b/ShuffleDeckScreen.inc new file mode 100644 index 0000000..0438520 --- /dev/null +++ b/ShuffleDeckScreen.inc @@ -0,0 +1,441 @@ +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,$fe,$ff,$fe,$ff,$06,$ff,$f6,$ff,$56,$bf,$b6,$5f,$56,$bf + db $b6,$5f,$56,$bf,$b6,$5f,$56,$bf,$b6,$5f,$56,$bf,$b6,$5f,$56,$bf + + db $6a,$fd,$6d,$fa,$6a,$fd,$6d,$fa,$6a,$fd,$6d,$fa,$6a,$fd,$6d,$fa + db $6a,$fd,$6d,$fa,$6a,$fd,$6d,$fa,$6a,$fd,$6d,$fa,$6a,$fd,$6d,$fa + + db $aa,$55,$55,$aa,$aa,$55,$55,$aa,$aa,$55,$55,$aa,$aa,$55,$55,$aa + db $aa,$55,$55,$aa,$aa,$55,$55,$aa,$aa,$55,$55,$aa,$aa,$55,$55,$aa + + db $b6,$5f,$56,$bf,$b6,$5f,$56,$bf,$b6,$5f,$56,$bf,$b6,$5f,$56,$bf + db $b6,$5f,$56,$bf,$b6,$5f,$56,$bf,$b6,$5f,$56,$bf,$b6,$5f,$56,$bf + + db $6a,$fd,$6d,$fa,$6a,$fd,$6d,$fa,$6a,$fd,$6d,$fa,$6a,$fd,$6d,$fa + db $6a,$fd,$6d,$fa,$6a,$fd,$6f,$ff,$60,$ff,$7f,$ff,$7f,$ff,$00,$ff + + db $aa,$55,$55,$aa,$aa,$55,$55,$aa,$aa,$55,$55,$aa,$aa,$55,$55,$aa + db $aa,$55,$55,$aa,$aa,$55,$ff,$ff,$00,$ff,$ff,$ff,$ff,$ff,$00,$ff + + db $b6,$5f,$56,$bf,$b6,$5f,$56,$bf,$b6,$5f,$56,$bf,$b6,$5f,$56,$bf + db $b6,$5f,$56,$bf,$b6,$5f,$f6,$ff,$06,$ff,$fe,$ff,$fe,$ff,$00,$ff + +CardBackSpritesEnd: diff --git a/generate_animation_circling.py b/generate_animation_circling.py new file mode 100644 index 0000000..916741d --- /dev/null +++ b/generate_animation_circling.py @@ -0,0 +1,23 @@ +#!python3 +from math import * + +tile_size = 8 +frames = [] +center = (100, 64) + +spread_max = 8 +spread_min = 4 +frame_count = 160 + +for t in range(frame_count): + e = ((spread_min + spread_max)/2) + (spread_max - spread_min)*0.5*sin(2*pi*t/frame_count) + x = center[0] - 60*cos(2*pi*t/frame_count) - (e*1.5) - (tile_size*1.5) + y = center[1] - (e * 1.5) - (tile_size*3) + frames.append( (x, y, e) ) + +def h(flt): + return f'${int(floor(flt+0.5)):x}' + +frame_strings = [f"{h(t[1])}, {h(t[0])}, {h(t[2])}" for t in frames] + +print("db {}, {}".format(frame_count, ", ".join(frame_strings))) \ No newline at end of file diff --git a/main.asm b/main.asm index 7c7be12..90c0204 100644 --- a/main.asm +++ b/main.asm @@ -12,6 +12,8 @@ DEF INTERRUPT_LCD EQU $FF91 DEF rMYBTN EQU $FFA8 DEF rMYBTNP EQU rMYBTN + 1 +DEF rDELTAT EQU rMYBTNP + 1 +DEF VARIABLES_START EQU rDELTAT+1 INCLUDE "hardware.inc" SECTION "Interrupts", ROM0[$0] @@ -28,7 +30,8 @@ SECTION "Header", ROM0[$100] EntryPoint: ; Shut down audio circuitry ld a, 0 - ld [rNR52], a + ld [rNR52], a ; shut down audio + ldh [rDIV], a ; reset timer just in case?? ld a, [Instructions] ; get the value of a call instruction so we can shove it into our handles ld hl, SCENE_SETUP - 1 @@ -56,25 +59,25 @@ EntryPoint: ; set up our scene vectors ld hl, SCENE_SETUP - ld de, CardReadSetup + ld de, ShuffleDeckSetup ld a, e ld [hl+], a ld a, d ld [hl+], a ld hl, SCENE_UPDATE - ld de, CardReadUpdate + ld de, ShuffleDeckUpdate ld a, e ld [hl+], a ld a, d ld [hl+], a ld hl, SCENE_DRAW - ld de, CardReadDraw + ld de, ShuffleDeckDraw ld a, e ld [hl+], a ld a, d ld [hl+], a ld hl, SCENE_TEARDOWN - ld de, CardReadTeardown + ld de, ShuffleDeckTeardown ld a, e ld [hl+], a ld a, d @@ -88,16 +91,34 @@ EntryPoint: ld a, d ld [hl+], a - ; Do not turn the LCD off outside of VBlank -WaitVBlank: - ld a, [rLY] - cp 144 - jp c, WaitVBlank + ld b, 144 + call AwaitLine call SCENE_SETUP - 1 Loop: di + ; okay this is kinda sketchy. we want a delta time variable. + ; we've got two eight-bit counters, one at 4096hz and one at 16384hz + ; we can definitely reset the faster counter. + ; but! that's gonna overflow every frame. + ; however! it should always overflow the same amount + ; because we're basically running once per frame (AwaitLine call later) + ; if we assume it overflows once per frame, then the total value should be + ; 256 + [rDIV]. so if we divide by two (or more!) the total value will be + ; 256/2 + [rDIV]/2. so we just have to right shift and add 128. + ; or right shift twice and add 64. this loses us precision but we didn't need + ; it anyway. + ldh a, [rDIV] + ldh [rDIV], a ; this will reset the timer + sra a + sra a + add a, 64 + ldh [rDELTAT], a + xor a, a ; zero a out in one cycle + + + ; store dpad and btn state in the rMYBTN register ld hl, rP1 ld [hl], P1F_GET_DPAD ld a, [hl] @@ -116,20 +137,21 @@ Loop: and a, %00001111 swap a or a, b - ld b, a - ld a, [rMYBTN] - cpl - and a, b - ld [rMYBTNP], a - ld a, b - ld [rMYBTN], a + ld b, a ; put new input state in b + ldh a, [rMYBTN] ; previous input state in a + cpl ; a holds buttons which weren't pressed last frame + and a, b ; select buttons which were pressed this frame, but not last frame + ldh [rMYBTNP], a ; save that as btnp state + ld a, b ; select buttons which were pressed this frame + ldh [rMYBTN], a ; save that as btn state - call SCENE_UPDATE - 1 + call SCENE_UPDATE - 1 ; hope this takes not too many scanlines! ld b, 144 call AwaitLine - call SCENE_DRAW - 1 + call SCENE_DRAW - 1 ; hope this takes fewer than 9 scanlines! + ; either way it's going to eat into the update timing jp Loop AwaitLine: ; put the line you want to reach in b @@ -138,6 +160,18 @@ AwaitLine: ; put the line you want to reach in b jp nz, AwaitLine ret +ArrayClampLooping: ; loops a to be in the array, assuming hl points to the length + cp a, [hl] ; if a == length... + jp nz, :+ + ld a, 0 ; set it to 0 +: + cp a, $FF ; otherwise if a == $FF... + jp nz, :+ + ld a, [hl] + dec a ; then set it to length-1 +: + ret ; a is return value + PrintString: ; write ascii string which has been prefixed by its length. ld b, [hl] inc hl @@ -154,7 +188,7 @@ PrintBChars: ;write ascii characters. will not respect newlines or anything like ret INCLUDE "CardReadScreen.inc" - +INCLUDE "ShuffleDeckScreen.inc" Instructions: call Instructions + 2 ret diff --git a/screendesigns.aseprite b/screendesigns.aseprite new file mode 100644 index 0000000..db91f0c Binary files /dev/null and b/screendesigns.aseprite differ