From 89869a2d3d1fd9b4daa9c46c819ac812e177d0a3 Mon Sep 17 00:00:00 2001 From: Peter Ferrie Date: Wed, 9 Oct 2019 18:02:46 -0700 Subject: [PATCH] shave some bytes --- src/constants.a | 5 +---- src/glue.launch.a | 14 ++---------- src/okvs.a | 38 +++++++++++++++++--------------- src/prodos.path.a | 6 ++--- src/ui.animation.a | 3 +++ src/ui.attract.hgr.a | 7 +++--- src/ui.attract.mode.a | 3 ++- src/ui.attract.shr.a | 10 +-------- src/ui.browse.mode.a | 33 ++++++++++++++-------------- src/ui.common.a | 26 +++++++++++++++++++++- src/ui.credits.a | 2 +- src/ui.offscreen.a | 12 +++++----- src/ui.overlay.a | 51 +++++++++++++++++++------------------------ src/ui.search.mode.a | 14 +++++------- 14 files changed, 112 insertions(+), 112 deletions(-) diff --git a/src/constants.a b/src/constants.a index 1d6aa0579..ea36a3430 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... -; EC5F..FFF9 - main program code +; ECA6..FFF9 - main program code ; FFFA..FFFF - NMI, reset, IRQ vectors ; ; LC RAM BANK 2 @@ -71,9 +71,6 @@ PTR = $02 ; word SRC = $04 ; word DEST = $06 ; word SAVE = $08 ; word -KEYLEN = $0A ; byte -VALUELEN = $0B ; byte -MAX = $0C ; byte HTAB = $24 ; byte VTAB = $25 ; byte RNDSEED = $4E ; word diff --git a/src/glue.launch.a b/src/glue.launch.a index 5aeb100c5..1b47b1e61 100644 --- a/src/glue.launch.a +++ b/src/glue.launch.a @@ -87,18 +87,8 @@ PlayGame +STAY SAVE +STAY @pfile ; assume we're loading a game-specific prelaunch file - jsr Home ; clear screen (clobbers $106, must do now before loading prelaunch code) - lda #$20 ; clear both hi-res pages - sta @clear+2 ; (in case game loader shows them, we don't want - ldx #$40 ; to flash previous bits of the launcher UI) - ldy #$00 - tya -@clear sta $FD00,y ; SMC - iny - bne @clear - inc @clear+2 - dex - bne @clear + jsr ClearScreens ; avoid seeing code load into the HGR page + ; (clobbers $106, must do now before loading prelaunch code) jsr LoadFile ; load this game's prelaunch file at $106 !word kPrelaunchDirectory diff --git a/src/okvs.a b/src/okvs.a index 89f3ba65a..61903aa23 100644 --- a/src/okvs.a +++ b/src/okvs.a @@ -149,17 +149,16 @@ okvs_append ldy #0 lda (SRC),y tay - iny - sty KEYLEN -- dey ; copy new key - lda (SRC),y + tax +- lda (SRC),y ; copy new key sta (PTR),y + dey cpy #$FF bne - - lda PTR ; update PTR to byte after copied key - clc - adc KEYLEN + sec + txa + adc PTR ; update PTR to byte after copied key sta PTR bcc + inc PTR+1 @@ -168,21 +167,22 @@ okvs_append +STAY SRC ; SRC -> new value to copy ldy #7 lda (PARAM),y ; get max length of value - tay + tax bne + - lda (SRC),y ; no max, use actual length instead tay - iny -+ sty VALUELEN -- dey - lda (SRC),y + lda (SRC),y ; no max, use actual length instead + tax + inx ++ tay +- lda (SRC),y sta (PTR),y + dey cpy #$FF bne - - lda PTR + txa clc - adc VALUELEN + adc PTR sta SRC bcc + inc PTR+1 @@ -229,7 +229,7 @@ okvs_get ; Y = 0 lda (PTR),y ; A = number of keys in store beq @fail ; no keys, fail immediately - sta MAX + sta @max jsr incptr3 ; PTR -> first record ldx #0 @@ -255,7 +255,8 @@ okvs_get cmp (DEST),y bne @next iny - cpy KEYLEN +KEYLEN = *+1 + cpy #$D1 ; SMC bne @matchKeyLoop +LDAY PTR clc @@ -271,7 +272,8 @@ okvs_get + rts @next jsr derefptr ; PTR -> next record inx - cpx MAX +@max = *+1 + cpx #$D1 ; SMC bne @matchRecordLoop @fail sec rts diff --git a/src/prodos.path.a b/src/prodos.path.a index 090134b14..3026db67c 100644 --- a/src/prodos.path.a +++ b/src/prodos.path.a @@ -118,7 +118,6 @@ kSFXFizzleFile ; Y contains high byte of address of length-prefixed string to append ; out: all registers and flags clobbered ; $02/$03 (PTR/PTR+1) clobbered -; MAX clobbered ; gPathname updated with concatenated length-prefixed string ;------------------------------------------------------------------------------ SetPath @@ -133,14 +132,15 @@ AddToPath beq @done tay iny - sty MAX + sty @max ldx gPathname ; current pathname length ldy #$01 - lda (PTR),y sta gPathname+1,x inx iny - cpy MAX +@max = *+1 + cpy #$D1 ; SMC bcc - stx gPathname @done diff --git a/src/ui.animation.a b/src/ui.animation.a index c065ae174..95e2f40a8 100644 --- a/src/ui.animation.a +++ b/src/ui.animation.a @@ -8,6 +8,9 @@ ; /!\ execution falls through from ui.search.mode/FindMatchingTitle MaybeAnimateTitle + jsr SwitchToBank2 + jsr DisableAcceleratorAndSwitchToBank1 + ; out: C clear lda #$3F ldy OffscreenPage diff --git a/src/ui.attract.hgr.a b/src/ui.attract.hgr.a index 23ecc32a6..8cb5b4b95 100644 --- a/src/ui.attract.hgr.a +++ b/src/ui.attract.hgr.a @@ -30,8 +30,7 @@ HGRSingle @fname !word $FDFD ; SMC !word $4000 jsr LoadHGRTransition ; load transition effect code at $6000 - +LDADDR $6000 - jmp ExecuteTransitionAndWait + jmp .transition ;------------------------------------------------------------------------------ ; LoadHGRTransition [private] @@ -100,8 +99,7 @@ HGRTitleCallback + !word $FDFD ; SMC !word $4000 - +LDADDR $6000 - jmp ExecuteTransitionAndWait + jmp .transition ;------------------------------------------------------------------------------ ; HGRActionCallback [private] @@ -160,6 +158,7 @@ HGRActionCallback lda #3 ; solid vertical bar character jsr @drawline +.transition +LDADDR $6000 jmp ExecuteTransitionAndWait @resetline diff --git a/src/ui.attract.mode.a b/src/ui.attract.mode.a index 61c8e7975..3c695cbec 100644 --- a/src/ui.attract.mode.a +++ b/src/ui.attract.mode.a @@ -143,7 +143,8 @@ RunAttractModule beq + stx gGameToLaunch + - jsr Home ; avoid seeing code load into the HGR page + jsr ClearScreens ; avoid seeing code load into the HGR page + ; (clobbers $106, must do now before loading prelaunch code) jsr LoadFile ; load standard prelaunch code (|Launch| will call it) !word kPrelaunchDirectory diff --git a/src/ui.attract.shr.a b/src/ui.attract.shr.a index 0f38207e0..d62d968d8 100644 --- a/src/ui.attract.shr.a +++ b/src/ui.attract.shr.a @@ -110,16 +110,8 @@ BlankSHR sta SHADOW lda #$20 ; clear $2000..$9FFF in auxmem - sta @a+2 ldx #$80 - lda #0 - tay -@a sta $2000,y - iny - bne @a - inc @a+2 - dex - bne @a + jsr ClearMem sta WRITEMAINMEM ; writes go to main memory diff --git a/src/ui.browse.mode.a b/src/ui.browse.mode.a index d0dfe5169..4655343d6 100644 --- a/src/ui.browse.mode.a +++ b/src/ui.browse.mode.a @@ -70,25 +70,26 @@ OnBrowseSearch jmp SearchMode OnBrowsePrevious - dec gGameToLaunch - jmp + -OnBrowseNext - inc gGameToLaunch -+ ldx gGameToLaunch - cpx #$FF - bne @notTooSmall -GameCount = *+1 - ldx #$D1 ; SMC + bne .decindex + ldx GameCount + +.decindex dex - bne @done ; always branches -@notTooSmall - cpx GameCount - bcc @done - ldx #0 -@done stx gGameToLaunch + +.setindex + stx gGameToLaunch jmp OnBrowseChanged +OnBrowseNext + ldx gGameToLaunch + inx +GameCount = *+1 + cpx #$D1 ; SMC + bne .setindex + ldx #0 + beq .setindex ; branch always + OnBrowseLaunch jsr PlayGame jsr BlankHGR @@ -112,8 +113,6 @@ OnBrowseChanged jsr EnableAcceleratorAndSwitchToBank1 jsr LoadGameTitleOffscreen jsr DrawUIWithoutDots - jsr SwitchToBank2 - jsr DisableAcceleratorAndSwitchToBank1 jmp MaybeAnimateTitle ;------------------------------------------------------------------------------ diff --git a/src/ui.common.a b/src/ui.common.a index dd2bb52d0..56b06357b 100644 --- a/src/ui.common.a +++ b/src/ui.common.a @@ -4,12 +4,36 @@ ; miscellaneous UI functions ; ; Public functions +; - ClearScreens ; - Home ; - BlankDHGR ; - IsSearchKey ; - IsUpDownOrRightArrow ; +;------------------------------------------------------------------------------ +; ClearScreens +; clear and display text screen and then clear both hires screens +; (in this order so that the erasing isn't visible) +; +; in: none +; out: $0106..$011F clobbered +;------------------------------------------------------------------------------ +ClearScreens + jsr Home + lda #$20 ; clear both hi-res pages + sta @clear+2 ; (in case game loader shows them, we don't want + ldx #$40 ; to flash previous bits of the launcher UI) + ldy #$00 + tya +@clear sta $FD00,y ; SMC + iny + bne @clear + inc @clear+2 + dex + bne @clear + rts + ;------------------------------------------------------------------------------ ; Home ; clear and display text screen (HARDER THAN IT SOUNDS) @@ -75,7 +99,7 @@ BlankDHGR ; out: A &= 0x7F ; Y preserved ; X clobbered -; Z = 1 if this is a search key +; Z = 1 and C = 0 if this is a search key ; Z = 0 if this is not a search key ;------------------------------------------------------------------------------ IsSearchKey diff --git a/src/ui.credits.a b/src/ui.credits.a index 14341c714..9eb938090 100644 --- a/src/ui.credits.a +++ b/src/ui.credits.a @@ -38,5 +38,5 @@ Help jsr IsUpDownOrRightArrow beq - jsr IsSearchKey - beq - bne -- + rts diff --git a/src/ui.offscreen.a b/src/ui.offscreen.a index 67fff16f0..8cf28d5f4 100644 --- a/src/ui.offscreen.a +++ b/src/ui.offscreen.a @@ -13,6 +13,7 @@ ; - ToggleOffscreenPage ; - ClearOffscreen ; - ClearHGR1 +; - ClearMem ; ; Public variables ; - OffscreenPage @@ -27,16 +28,14 @@ ; preserves X/Y ;------------------------------------------------------------------------------ GetOffscreenAddress + lda #$40 OffscreenPage = * + 1 - lda #$00 ; SMC + bne + ; SMC ; 0 = currently showing HGR page 2 ; (so offscreen is page 1 @ $2000) ; 1 = currently showing HGR page 1 ; (so offscreen is page 2 @ $4000) - beq + - lda #$40 - rts -+ lda #$20 ++ lsr rts ;------------------------------------------------------------------------------ @@ -113,8 +112,9 @@ ClearOffscreen +HIDE_NEXT_2_BYTES ClearHGR1 lda #$20 ; note to self: LDX #$20 can't move here - sta @a+2 ldx #$20 +ClearMem + sta @a+2 lda #$80 ldy #0 @a sta $2000,y diff --git a/src/ui.overlay.a b/src/ui.overlay.a index 29332b8aa..62022b91f 100644 --- a/src/ui.overlay.a +++ b/src/ui.overlay.a @@ -91,27 +91,26 @@ DrawUI bpl - ldx gGameToLaunch - cpx #$FF ; if no game, nothing more to do on UI line 2 + inx ; if no game, nothing more to do on UI line 2 beq @doneWithLine2 jsr GetGameToLaunch jsr okvs_get_current ; (PTR) -> game title - ldy #0 ; copy game title into UI line 2 - lda (PTR),y + lda (PTR),y ; copy game title into UI line 2 sta SAVE ; title length inc SAVE - iny - cpy SAVE - bcc @printTitleChar - beq @printCursor - lda #" " - +HIDE_NEXT_2_BYTES @printCursor lda #$FD ; SMC + cpy SAVE + bcc @printTitleChar + beq @printChar + lda #" " +HIDE_NEXT_2_BYTES @printTitleChar lda (PTR),y +@printChar sta UILine2,y cpy #MaxInputLength+1 bcc - @@ -127,16 +126,7 @@ DrawUI and #CHEATS_ENABLED beq @maybeDrawDots ; if cheat mode is disabled, we don't need ; any curves or spaces on UI line 1 - ldx gGameToLaunch - ldy gCheatsAvailable,x - cpx #$FF - bne + - ldy #kCheatsEnabled -+ - lda kCheatDescriptionLo,y - sta SAVE - lda kCheatDescriptionHi,y - sta SAVE+1 + jsr CheckCheats ; (SAVE) -> length-prefixed string ; (game-specific description or 'cheats enabled' message) ldy #0 @@ -171,7 +161,7 @@ DrawUI @dotloop iny lda (PTR),y ; (PTR) still points to game title - +LOW_ASCII_TO_LOWER + ora #$20 ; force lower-case always cmp InputBuffer,x bne + lda #$11 ; dot character @@ -218,15 +208,7 @@ DrawUI +LDADDR gPathname jsr DrawCenteredString ; draw cheat UI line 1 - ldx gGameToLaunch - ldy gCheatsAvailable,x - cpx #$FF - bne + - ldy #kCheatsEnabled -+ lda kCheatDescriptionLo,y - sta SAVE - lda kCheatDescriptionHi,y - sta SAVE+1 + jsr CheckCheats ; (SAVE) -> length-prefixed cheat description +LDADDR sCheatDescriptionPrefix jsr SetPath @@ -240,3 +222,16 @@ DrawUI jsr DrawCenteredString ; draw cheat UI line 2 @uidone jmp ShowOtherPage + +CheckCheats + ldy #kCheatsEnabled + ldx gGameToLaunch + inx + beq + + ldy gCheatsAvailable,x ++ + lda kCheatDescriptionLo,y + sta SAVE + lda kCheatDescriptionHi,y + sta SAVE+1 + rts diff --git a/src/ui.search.mode.a b/src/ui.search.mode.a index b747cd193..8106c3e8d 100644 --- a/src/ui.search.mode.a +++ b/src/ui.search.mode.a @@ -149,7 +149,7 @@ OnBack OnTab ldx gGameToLaunch - cpx #$FF + inx beq OnError jsr MiniAttractMode cmp #$8D ; if we exited mini attract mode @@ -157,7 +157,7 @@ OnTab OnLaunch ldx gGameToLaunch - cpx #$FF + inx beq OnError jsr PlayGame @@ -178,10 +178,10 @@ OnSearch inc InputLength ; execution falls through here to OnInputChanged OnInputChanged - lda InputLength + ldx InputLength bne FindMatchingTitle ; no input, reset params and UI - ldx #$FF + dex stx gGameToLaunch ; no game selected jsr LoadTitleOffscreen jsr DrawUIWithoutDots @@ -243,14 +243,12 @@ SoftBell + ldx BestMatchIndex ; check if the new best match is the same cpx gGameToLaunch ; as the current best match - stx gGameToLaunch bne + jsr ToggleOffscreenPage ; Since we're not loading a new screenshot ; we fake switching the 'offscreen' page ; in order to draw on the visible page. bpl @noload ; (always branches) -+ jsr LoadGameTitleOffscreen ++ stx gGameToLaunch + jsr LoadGameTitleOffscreen @noload jsr DrawUI - jsr SwitchToBank2 - jsr DisableAcceleratorAndSwitchToBank1 ; /!\ execution falls through to ui.animation/MaybeAnimateTitle