From e57eaaa3fafe1155cc159d3841f2f3d926050644 Mon Sep 17 00:00:00 2001 From: 4am Date: Tue, 8 Oct 2019 13:31:41 -0400 Subject: [PATCH] shave some bytes --- src/4cade.a | 7 ++-- src/constants.a | 2 +- src/ui.attract.dhgr.a | 2 +- src/ui.common.a | 71 --------------------------------------- src/ui.wait.a | 77 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+), 75 deletions(-) create mode 100644 src/ui.wait.a diff --git a/src/4cade.a b/src/4cade.a index 23cb2a5a3..deb338a53 100644 --- a/src/4cade.a +++ b/src/4cade.a @@ -92,7 +92,6 @@ ResetVector ; 6 bytes, copied to $100 !source "src/ui.overlay.a" !source "src/ui.offscreen.a" !source "src/ui.attract.mode.a" - !source "src/ui.attract.dhgr.a" !source "src/ui.attract.shr.a" !source "src/ui.attract.gr.a" @@ -109,8 +108,12 @@ ResetVector ; 6 bytes, copied to $100 !source "src/parse.prefs.a" ; \__ execution falls through !source "src/glue.prorwts2.a" ; / - ; add new files above here so ui.common stays last !source "src/ui.common.a" + + ; add new files above here so ui.wait stays last + + !source "src/ui.attract.dhgr.a" ; \-- execution falls through + !source "src/ui.wait.a" ; / gAttractModeStore gFXStore gDFXStore diff --git a/src/constants.a b/src/constants.a index a7a6842c5..460f3c40f 100644 --- a/src/constants.a +++ b/src/constants.a @@ -9,7 +9,7 @@ ; D000..E611 - persistent data structures (per-game cheat categories, ; gGlobalPrefsStore, gGamesListStore) ; ...unused... -; EC01..FFF9 - main program code +; EC04..FFF9 - main program code ; FFFA..FFFF - NMI, reset, IRQ vectors ; ; LC RAM BANK 2 diff --git a/src/ui.attract.dhgr.a b/src/ui.attract.dhgr.a index 75e1d5ed0..987101af2 100644 --- a/src/ui.attract.dhgr.a +++ b/src/ui.attract.dhgr.a @@ -146,4 +146,4 @@ DHGRActionCallback + !word $FDFD +LDADDR $6000 - jmp ExecuteTransitionAndWait + ; /!\ execution falls through to ui.wait/ExecuteTransitionAndWait diff --git a/src/ui.common.a b/src/ui.common.a index f6b7380e1..d6906c579 100644 --- a/src/ui.common.a +++ b/src/ui.common.a @@ -10,9 +10,6 @@ ; - BlankDHGR ; - IsSearchKey ; - IsUpDownOrRightArrow -; - ExecuteTransitionAndWait -; - WaitForKeyFor30Seconds -; - CoverFade ; ;------------------------------------------------------------------------------ @@ -172,71 +169,3 @@ IsUpDownOrRightArrow beq @done cmp #$8A ; down arrow @done rts - -;------------------------------------------------------------------------------ -; ExecuteTransitionAndWait -; call transition effect code (address passed in) and wait a period of time -; or until the user presses a key -; -; in: A/Y = address of transition effect code -; out: all flags and registers clobbered -;------------------------------------------------------------------------------ -ExecuteTransitionAndWait - +STAY @j+1 -@j jsr $FDFD ; SMC call transition effect code - ldx #$20 ; picture is showing so now we wait -- lda #0 - jsr WaitForKeyWithTimeout - bmi + - dex - bpl - -+ lda KBD - cmp #$95 - bne ConvenientlyPlacedRTS - bit CLEARKBD -ConvenientlyPlacedRTS - rts - -; /!\ keep this last in the file to ensure it doesn't cross a page boundary /!\ -;------------------------------------------------------------------------------ -; WaitForKeyFor30Seconds -; does what it says on the tin -; -; in: none -; out: if user presses a key before the timer runs out, exits with A = key -; and X/Y preserved -; otherwise exits via MegaAttractMode and everything is clobbered -;------------------------------------------------------------------------------ -WaitForKeyFor30Seconds - lda #$16 ; initialize timeout counters - sta Timeout - sta Timeout+1 - sta Timeout+2 -@loop - lda KBD - bmi ConvenientlyPlacedRTS - - inc RNDSEED+1 ; these are only ever incremented, never - bne + ; reset (may be used as a pseudorandom - inc RNDSEED ; seed) -+ - dec Timeout - bne @loop - dec Timeout+1 - bne @loop - dec Timeout+2 - bne @loop - ; /!\ execution falls through here to CoverFade -CoverFade - jsr LoadCoverOffscreen - jsr ShowOtherPage - lda OffscreenPage - bne + - jsr LoadCoverOffscreen - jsr ShowOtherPage -+ jsr LoadFile ; load transition effect code at $6000 - !word kFXDirectory - !word kCoverFadeFile - !word $6000 - jsr $6000 ; call transition effect - jmp MegaAttractMode ; exit via mega attract mode diff --git a/src/ui.wait.a b/src/ui.wait.a new file mode 100644 index 000000000..9cf842430 --- /dev/null +++ b/src/ui.wait.a @@ -0,0 +1,77 @@ +;License:MIT +;(c) 2018-9 by 4am +; +; UI functions for doing things then waiting, or waiting then doing things +; +; - ExecuteTransitionAndWait +; - WaitForKeyFor30Seconds +; - CoverFade + + ; /!\ execution falls through here from ui.attract.dhgr/DHGRActionCallback +;------------------------------------------------------------------------------ +; ExecuteTransitionAndWait +; call transition effect code (address passed in) and wait a period of time +; or until the user presses a key +; +; in: A/Y = address of transition effect code +; out: all flags and registers clobbered +;------------------------------------------------------------------------------ +ExecuteTransitionAndWait + +STAY @j+1 +@j jsr $FDFD ; SMC call transition effect code + ldx #$20 ; picture is showing so now we wait +- lda #0 + jsr WaitForKeyWithTimeout + bmi + + dex + bpl - ++ lda KBD + cmp #$95 + bne ConvenientlyPlacedRTS + bit CLEARKBD +ConvenientlyPlacedRTS + rts + +; /!\ keep this last in the file to ensure it doesn't cross a page boundary /!\ +;------------------------------------------------------------------------------ +; WaitForKeyFor30Seconds +; does what it says on the tin +; +; in: none +; out: if user presses a key before the timer runs out, exits with A = key +; and X/Y preserved +; otherwise exits via MegaAttractMode and everything is clobbered +;------------------------------------------------------------------------------ +WaitForKeyFor30Seconds + lda #$16 ; initialize timeout counters + sta Timeout + sta Timeout+1 + sta Timeout+2 +@loop + lda KBD + bmi ConvenientlyPlacedRTS + + inc RNDSEED+1 ; these are only ever incremented, never + bne + ; reset (may be used as a pseudorandom + inc RNDSEED ; seed) ++ + dec Timeout + bne @loop + dec Timeout+1 + bne @loop + dec Timeout+2 + bne @loop + ; /!\ execution falls through here to CoverFade +CoverFade + jsr LoadCoverOffscreen + jsr ShowOtherPage + lda OffscreenPage + bne + + jsr LoadCoverOffscreen + jsr ShowOtherPage ++ jsr LoadFile ; load transition effect code at $6000 + !word kFXDirectory + !word kCoverFadeFile + !word $6000 + jsr $6000 ; call transition effect + jmp MegaAttractMode ; exit via mega attract mode