shave some bytes

This commit is contained in:
Peter Ferrie 2019-10-09 18:02:46 -07:00
parent c4ac4883dd
commit 89869a2d3d
14 changed files with 112 additions and 112 deletions

View File

@ -9,7 +9,7 @@
; D000..E611 - persistent data structures (per-game cheat categories, ; D000..E611 - persistent data structures (per-game cheat categories,
; gGlobalPrefsStore, gGamesListStore) ; gGlobalPrefsStore, gGamesListStore)
; ...unused... ; ...unused...
; EC5F..FFF9 - main program code ; ECA6..FFF9 - main program code
; FFFA..FFFF - NMI, reset, IRQ vectors ; FFFA..FFFF - NMI, reset, IRQ vectors
; ;
; LC RAM BANK 2 ; LC RAM BANK 2
@ -71,9 +71,6 @@ PTR = $02 ; word
SRC = $04 ; word SRC = $04 ; word
DEST = $06 ; word DEST = $06 ; word
SAVE = $08 ; word SAVE = $08 ; word
KEYLEN = $0A ; byte
VALUELEN = $0B ; byte
MAX = $0C ; byte
HTAB = $24 ; byte HTAB = $24 ; byte
VTAB = $25 ; byte VTAB = $25 ; byte
RNDSEED = $4E ; word RNDSEED = $4E ; word

View File

@ -87,18 +87,8 @@ PlayGame
+STAY SAVE +STAY SAVE
+STAY @pfile ; assume we're loading a game-specific prelaunch file +STAY @pfile ; assume we're loading a game-specific prelaunch file
jsr Home ; clear screen (clobbers $106, must do now before loading prelaunch code) jsr ClearScreens ; avoid seeing code load into the HGR page
lda #$20 ; clear both hi-res pages ; (clobbers $106, must do now before loading prelaunch code)
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 LoadFile ; load this game's prelaunch file at $106 jsr LoadFile ; load this game's prelaunch file at $106
!word kPrelaunchDirectory !word kPrelaunchDirectory

View File

@ -149,17 +149,16 @@ okvs_append
ldy #0 ldy #0
lda (SRC),y lda (SRC),y
tay tay
iny tax
sty KEYLEN - lda (SRC),y ; copy new key
- dey ; copy new key
lda (SRC),y
sta (PTR),y sta (PTR),y
dey
cpy #$FF cpy #$FF
bne - bne -
lda PTR ; update PTR to byte after copied key sec
clc txa
adc KEYLEN adc PTR ; update PTR to byte after copied key
sta PTR sta PTR
bcc + bcc +
inc PTR+1 inc PTR+1
@ -168,21 +167,22 @@ okvs_append
+STAY SRC ; SRC -> new value to copy +STAY SRC ; SRC -> new value to copy
ldy #7 ldy #7
lda (PARAM),y ; get max length of value lda (PARAM),y ; get max length of value
tay tax
bne + bne +
lda (SRC),y ; no max, use actual length instead
tay tay
iny lda (SRC),y ; no max, use actual length instead
+ sty VALUELEN tax
- dey inx
lda (SRC),y + tay
- lda (SRC),y
sta (PTR),y sta (PTR),y
dey
cpy #$FF cpy #$FF
bne - bne -
lda PTR txa
clc clc
adc VALUELEN adc PTR
sta SRC sta SRC
bcc + bcc +
inc PTR+1 inc PTR+1
@ -229,7 +229,7 @@ okvs_get
; Y = 0 ; Y = 0
lda (PTR),y ; A = number of keys in store lda (PTR),y ; A = number of keys in store
beq @fail ; no keys, fail immediately beq @fail ; no keys, fail immediately
sta MAX sta @max
jsr incptr3 jsr incptr3
; PTR -> first record ; PTR -> first record
ldx #0 ldx #0
@ -255,7 +255,8 @@ okvs_get
cmp (DEST),y cmp (DEST),y
bne @next bne @next
iny iny
cpy KEYLEN KEYLEN = *+1
cpy #$D1 ; SMC
bne @matchKeyLoop bne @matchKeyLoop
+LDAY PTR +LDAY PTR
clc clc
@ -271,7 +272,8 @@ okvs_get
+ rts + rts
@next jsr derefptr ; PTR -> next record @next jsr derefptr ; PTR -> next record
inx inx
cpx MAX @max = *+1
cpx #$D1 ; SMC
bne @matchRecordLoop bne @matchRecordLoop
@fail sec @fail sec
rts rts

View File

@ -118,7 +118,6 @@ kSFXFizzleFile
; Y contains high byte of address of length-prefixed string to append ; Y contains high byte of address of length-prefixed string to append
; out: all registers and flags clobbered ; out: all registers and flags clobbered
; $02/$03 (PTR/PTR+1) clobbered ; $02/$03 (PTR/PTR+1) clobbered
; MAX clobbered
; gPathname updated with concatenated length-prefixed string ; gPathname updated with concatenated length-prefixed string
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
SetPath SetPath
@ -133,14 +132,15 @@ AddToPath
beq @done beq @done
tay tay
iny iny
sty MAX sty @max
ldx gPathname ; current pathname length ldx gPathname ; current pathname length
ldy #$01 ldy #$01
- lda (PTR),y - lda (PTR),y
sta gPathname+1,x sta gPathname+1,x
inx inx
iny iny
cpy MAX @max = *+1
cpy #$D1 ; SMC
bcc - bcc -
stx gPathname stx gPathname
@done @done

View File

@ -8,6 +8,9 @@
; /!\ execution falls through from ui.search.mode/FindMatchingTitle ; /!\ execution falls through from ui.search.mode/FindMatchingTitle
MaybeAnimateTitle MaybeAnimateTitle
jsr SwitchToBank2
jsr DisableAcceleratorAndSwitchToBank1
; out: C clear ; out: C clear
lda #$3F lda #$3F
ldy OffscreenPage ldy OffscreenPage

View File

@ -30,8 +30,7 @@ HGRSingle
@fname !word $FDFD ; SMC @fname !word $FDFD ; SMC
!word $4000 !word $4000
jsr LoadHGRTransition ; load transition effect code at $6000 jsr LoadHGRTransition ; load transition effect code at $6000
+LDADDR $6000 jmp .transition
jmp ExecuteTransitionAndWait
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; LoadHGRTransition [private] ; LoadHGRTransition [private]
@ -100,8 +99,7 @@ HGRTitleCallback
+ !word $FDFD ; SMC + !word $FDFD ; SMC
!word $4000 !word $4000
+LDADDR $6000 jmp .transition
jmp ExecuteTransitionAndWait
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; HGRActionCallback [private] ; HGRActionCallback [private]
@ -160,6 +158,7 @@ HGRActionCallback
lda #3 ; solid vertical bar character lda #3 ; solid vertical bar character
jsr @drawline jsr @drawline
.transition
+LDADDR $6000 +LDADDR $6000
jmp ExecuteTransitionAndWait jmp ExecuteTransitionAndWait
@resetline @resetline

View File

@ -143,7 +143,8 @@ RunAttractModule
beq + beq +
stx gGameToLaunch 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) jsr LoadFile ; load standard prelaunch code (|Launch| will call it)
!word kPrelaunchDirectory !word kPrelaunchDirectory

View File

@ -110,16 +110,8 @@ BlankSHR
sta SHADOW sta SHADOW
lda #$20 ; clear $2000..$9FFF in auxmem lda #$20 ; clear $2000..$9FFF in auxmem
sta @a+2
ldx #$80 ldx #$80
lda #0 jsr ClearMem
tay
@a sta $2000,y
iny
bne @a
inc @a+2
dex
bne @a
sta WRITEMAINMEM ; writes go to main memory sta WRITEMAINMEM ; writes go to main memory

View File

@ -70,25 +70,26 @@ OnBrowseSearch
jmp SearchMode jmp SearchMode
OnBrowsePrevious OnBrowsePrevious
dec gGameToLaunch
jmp +
OnBrowseNext
inc gGameToLaunch
+
ldx gGameToLaunch ldx gGameToLaunch
cpx #$FF bne .decindex
bne @notTooSmall ldx GameCount
GameCount = *+1
ldx #$D1 ; SMC .decindex
dex dex
bne @done ; always branches
@notTooSmall .setindex
cpx GameCount stx gGameToLaunch
bcc @done
ldx #0
@done stx gGameToLaunch
jmp OnBrowseChanged jmp OnBrowseChanged
OnBrowseNext
ldx gGameToLaunch
inx
GameCount = *+1
cpx #$D1 ; SMC
bne .setindex
ldx #0
beq .setindex ; branch always
OnBrowseLaunch OnBrowseLaunch
jsr PlayGame jsr PlayGame
jsr BlankHGR jsr BlankHGR
@ -112,8 +113,6 @@ OnBrowseChanged
jsr EnableAcceleratorAndSwitchToBank1 jsr EnableAcceleratorAndSwitchToBank1
jsr LoadGameTitleOffscreen jsr LoadGameTitleOffscreen
jsr DrawUIWithoutDots jsr DrawUIWithoutDots
jsr SwitchToBank2
jsr DisableAcceleratorAndSwitchToBank1
jmp MaybeAnimateTitle jmp MaybeAnimateTitle
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------

View File

@ -4,12 +4,36 @@
; miscellaneous UI functions ; miscellaneous UI functions
; ;
; Public functions ; Public functions
; - ClearScreens
; - Home ; - Home
; - BlankDHGR ; - BlankDHGR
; - IsSearchKey ; - IsSearchKey
; - IsUpDownOrRightArrow ; - 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 ; Home
; clear and display text screen (HARDER THAN IT SOUNDS) ; clear and display text screen (HARDER THAN IT SOUNDS)
@ -75,7 +99,7 @@ BlankDHGR
; out: A &= 0x7F ; out: A &= 0x7F
; Y preserved ; Y preserved
; X clobbered ; 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 ; Z = 0 if this is not a search key
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
IsSearchKey IsSearchKey

View File

@ -38,5 +38,5 @@ Help
jsr IsUpDownOrRightArrow jsr IsUpDownOrRightArrow
beq - beq -
jsr IsSearchKey jsr IsSearchKey
beq -
bne -- bne --
rts

View File

@ -13,6 +13,7 @@
; - ToggleOffscreenPage ; - ToggleOffscreenPage
; - ClearOffscreen ; - ClearOffscreen
; - ClearHGR1 ; - ClearHGR1
; - ClearMem
; ;
; Public variables ; Public variables
; - OffscreenPage ; - OffscreenPage
@ -27,16 +28,14 @@
; preserves X/Y ; preserves X/Y
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
GetOffscreenAddress GetOffscreenAddress
lda #$40
OffscreenPage = * + 1 OffscreenPage = * + 1
lda #$00 ; SMC bne + ; SMC
; 0 = currently showing HGR page 2 ; 0 = currently showing HGR page 2
; (so offscreen is page 1 @ $2000) ; (so offscreen is page 1 @ $2000)
; 1 = currently showing HGR page 1 ; 1 = currently showing HGR page 1
; (so offscreen is page 2 @ $4000) ; (so offscreen is page 2 @ $4000)
beq + + lsr
lda #$40
rts
+ lda #$20
rts rts
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
@ -113,8 +112,9 @@ ClearOffscreen
+HIDE_NEXT_2_BYTES +HIDE_NEXT_2_BYTES
ClearHGR1 ClearHGR1
lda #$20 ; note to self: LDX #$20 can't move here lda #$20 ; note to self: LDX #$20 can't move here
sta @a+2
ldx #$20 ldx #$20
ClearMem
sta @a+2
lda #$80 lda #$80
ldy #0 ldy #0
@a sta $2000,y @a sta $2000,y

View File

@ -91,27 +91,26 @@ DrawUI
bpl - bpl -
ldx gGameToLaunch 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 beq @doneWithLine2
jsr GetGameToLaunch jsr GetGameToLaunch
jsr okvs_get_current jsr okvs_get_current
; (PTR) -> game title ; (PTR) -> game title
ldy #0 ; copy game title into UI line 2 lda (PTR),y ; copy game title into UI line 2
lda (PTR),y
sta SAVE ; title length sta SAVE ; title length
inc SAVE inc SAVE
- iny - iny
cpy SAVE
bcc @printTitleChar
beq @printCursor
lda #" "
+HIDE_NEXT_2_BYTES
@printCursor @printCursor
lda #$FD ; SMC lda #$FD ; SMC
cpy SAVE
bcc @printTitleChar
beq @printChar
lda #" "
+HIDE_NEXT_2_BYTES +HIDE_NEXT_2_BYTES
@printTitleChar @printTitleChar
lda (PTR),y lda (PTR),y
@printChar
sta UILine2,y sta UILine2,y
cpy #MaxInputLength+1 cpy #MaxInputLength+1
bcc - bcc -
@ -127,16 +126,7 @@ DrawUI
and #CHEATS_ENABLED and #CHEATS_ENABLED
beq @maybeDrawDots ; if cheat mode is disabled, we don't need beq @maybeDrawDots ; if cheat mode is disabled, we don't need
; any curves or spaces on UI line 1 ; any curves or spaces on UI line 1
ldx gGameToLaunch jsr CheckCheats
ldy gCheatsAvailable,x
cpx #$FF
bne +
ldy #kCheatsEnabled
+
lda kCheatDescriptionLo,y
sta SAVE
lda kCheatDescriptionHi,y
sta SAVE+1
; (SAVE) -> length-prefixed string ; (SAVE) -> length-prefixed string
; (game-specific description or 'cheats enabled' message) ; (game-specific description or 'cheats enabled' message)
ldy #0 ldy #0
@ -171,7 +161,7 @@ DrawUI
@dotloop @dotloop
iny iny
lda (PTR),y ; (PTR) still points to game title lda (PTR),y ; (PTR) still points to game title
+LOW_ASCII_TO_LOWER ora #$20 ; force lower-case always
cmp InputBuffer,x cmp InputBuffer,x
bne + bne +
lda #$11 ; dot character lda #$11 ; dot character
@ -218,15 +208,7 @@ DrawUI
+LDADDR gPathname +LDADDR gPathname
jsr DrawCenteredString ; draw cheat UI line 1 jsr DrawCenteredString ; draw cheat UI line 1
ldx gGameToLaunch jsr CheckCheats
ldy gCheatsAvailable,x
cpx #$FF
bne +
ldy #kCheatsEnabled
+ lda kCheatDescriptionLo,y
sta SAVE
lda kCheatDescriptionHi,y
sta SAVE+1
; (SAVE) -> length-prefixed cheat description ; (SAVE) -> length-prefixed cheat description
+LDADDR sCheatDescriptionPrefix +LDADDR sCheatDescriptionPrefix
jsr SetPath jsr SetPath
@ -240,3 +222,16 @@ DrawUI
jsr DrawCenteredString ; draw cheat UI line 2 jsr DrawCenteredString ; draw cheat UI line 2
@uidone jmp ShowOtherPage @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

View File

@ -149,7 +149,7 @@ OnBack
OnTab OnTab
ldx gGameToLaunch ldx gGameToLaunch
cpx #$FF inx
beq OnError beq OnError
jsr MiniAttractMode jsr MiniAttractMode
cmp #$8D ; if we exited mini attract mode cmp #$8D ; if we exited mini attract mode
@ -157,7 +157,7 @@ OnTab
OnLaunch OnLaunch
ldx gGameToLaunch ldx gGameToLaunch
cpx #$FF inx
beq OnError beq OnError
jsr PlayGame jsr PlayGame
@ -178,10 +178,10 @@ OnSearch
inc InputLength inc InputLength
; execution falls through here to OnInputChanged ; execution falls through here to OnInputChanged
OnInputChanged OnInputChanged
lda InputLength ldx InputLength
bne FindMatchingTitle bne FindMatchingTitle
; no input, reset params and UI ; no input, reset params and UI
ldx #$FF dex
stx gGameToLaunch ; no game selected stx gGameToLaunch ; no game selected
jsr LoadTitleOffscreen jsr LoadTitleOffscreen
jsr DrawUIWithoutDots jsr DrawUIWithoutDots
@ -243,14 +243,12 @@ SoftBell
+ +
ldx BestMatchIndex ; check if the new best match is the same ldx BestMatchIndex ; check if the new best match is the same
cpx gGameToLaunch ; as the current best match cpx gGameToLaunch ; as the current best match
stx gGameToLaunch
bne + bne +
jsr ToggleOffscreenPage ; Since we're not loading a new screenshot jsr ToggleOffscreenPage ; Since we're not loading a new screenshot
; we fake switching the 'offscreen' page ; we fake switching the 'offscreen' page
; in order to draw on the visible page. ; in order to draw on the visible page.
bpl @noload ; (always branches) bpl @noload ; (always branches)
+ jsr LoadGameTitleOffscreen + stx gGameToLaunch
jsr LoadGameTitleOffscreen
@noload jsr DrawUI @noload jsr DrawUI
jsr SwitchToBank2
jsr DisableAcceleratorAndSwitchToBank1
; /!\ execution falls through to ui.animation/MaybeAnimateTitle ; /!\ execution falls through to ui.animation/MaybeAnimateTitle