shave some bytes

This commit is contained in:
4am 2019-09-06 15:21:38 -04:00
parent 5faffbd825
commit 99b1de5380
4 changed files with 166 additions and 170 deletions

View File

@ -25,50 +25,17 @@ BrowseMode
.BrowseModeInputLoop .BrowseModeInputLoop
jsr WaitForKeyFor30Seconds jsr WaitForKeyFor30Seconds
bit CLEARKBD
jsr ResetInputTimeout jsr ResetInputTimeout
cmp #$88 ; left arrow = previous ldy #kNumBrowseKeys
bne + - dey
- ldx #kBrowsePrevious bmi @noKeyMatch
cmp .BrowseKeys,y
bne -
ldx .BrowseKeyDispatch,y
bne @BrowseDispatch ; always branches bne @BrowseDispatch ; always branches
+ cmp #$8B ; up arrow is same as left arrow
beq -
cmp #$95 ; right arrow = next @noKeyMatch
bne +
- ldx #kBrowseNext
bne @BrowseDispatch ; always branches
+ cmp #$8A ; down arrow is same as right arrow
beq -
cmp #$9B ; Esc switches to search mode
bne +
ldx #kBrowseExitToSearch
bne @BrowseDispatch ; always branches
+
cmp #$8D ; ENTER launches the current game
bne +
ldx #kBrowseLaunch
bne @BrowseDispatch ; always branches
+
cmp #$89 ; TAB switches to mini attract mode
bne + ; temporarily
- ldx #kBrowseTab
bne @BrowseDispatch ; always branches
+
cmp #$A0 ; SPACE = TAB because ][+ doesn't have TAB
beq -
cmp #$BF ; '?' display scredits
bne +
- ldx #kBrowseCredits
bne @BrowseDispatch ; always branches
+
cmp #$AF ; '/' also displays credits
beq -
and #$7F ; strip high bit for search characters
jsr IsSearchKey jsr IsSearchKey
beq + beq +
jsr SoftBell ; beep on invalid input jsr SoftBell ; beep on invalid input
@ -77,15 +44,10 @@ BrowseMode
ldx #kBrowseSearch ldx #kBrowseSearch
; execution falls through here ; execution falls through here
@BrowseDispatch @BrowseDispatch
pha ; save key pressed ldy .BrowseDispatchTableLo,x
txa sty @j+1
asl ldy .BrowseDispatchTableHi,x
tax sty @j+2
lda .BrowseDispatchTable,x
sta @j+1
lda .BrowseDispatchTable+1,x
sta @j+2
pla ; restore key pressed
@j jsr $FDFD ; SMC @j jsr $FDFD ; SMC
jmp .BrowseModeInputLoop jmp .BrowseModeInputLoop
@ -187,14 +149,46 @@ kBrowseTab = 4
kBrowseLaunch = 5 kBrowseLaunch = 5
kBrowseCredits = 6 kBrowseCredits = 6
.BrowseDispatchTable .BrowseDispatchTableLo
!word .OnSearch !byte <.OnSearch
!word .OnPrevious !byte <.OnPrevious
!word .OnNext !byte <.OnNext
!word SearchMode !byte <SearchMode
!word .OnTab !byte <.OnTab
!word .OnLaunch !byte <.OnLaunch
!word Credits !byte <Credits
.BrowseDispatchTableHi
!byte >.OnSearch
!byte >.OnPrevious
!byte >.OnNext
!byte >SearchMode
!byte >.OnTab
!byte >.OnLaunch
!byte >Credits
kNumBrowseKeys = 10 ; number of entries in next 2 tables (each)
.BrowseKeys
!byte $AF ; '/' = credits
!byte $BF ; '?' = credits
!byte $A0 ; Space = mini attract mode
!byte $89 ; TAB = mini attract mode
!byte $8D ; ENTER = launch current game
!byte $9B ; Esc = switch to search mode
!byte $8A ; down arrow = next
!byte $95 ; right arrow = next
!byte $8B ; up arrow = previous
!byte $88 ; left arrow = previous
.BrowseKeyDispatch
!byte kBrowseCredits
!byte kBrowseCredits
!byte kBrowseTab
!byte kBrowseTab
!byte kBrowseLaunch
!byte kBrowseExitToSearch
!byte kBrowseNext
!byte kBrowseNext
!byte kBrowsePrevious
!byte kBrowsePrevious
BrowseSelectedIndex BrowseSelectedIndex
!byte $FF !byte $FF

View File

@ -18,6 +18,7 @@
; - Home ; - Home
; - BlankHGR ; - BlankHGR
; - BlankDHGR ; - BlankDHGR
; - IsSearchKey
; Public variables ; Public variables
; - OffscreenPage ; - OffscreenPage
@ -151,6 +152,7 @@ ResetInputTimeout
stx Timeout stx Timeout
stx Timeout+1 stx Timeout+1
stx Timeout+2 stx Timeout+2
bit CLEARKBD
rts rts
WaitForKeyFor30Seconds WaitForKeyFor30Seconds
@ -291,12 +293,13 @@ ExecuteTransitionAndWait
+ rts + rts
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; .ClearHGR1 [private] ; ClearOffscreen
; clear $2000..$3FFF in current memory bank (main or auxmem) ; clear $2000..$3FFF or $4000..$5FFF, depending on which HGR page is not
; visible right now
; does not change HGR mode ; does not change HGR mode
; ;
; in: none ; in: none
; out: $2000..$3FFF cleared ; out: $2000..$3FFF or $4000..$5FFF cleared
; A = 0 ; A = 0
; X = 0 ; X = 0
; Y = 0 ; Y = 0
@ -318,4 +321,41 @@ ClearOffscreen
dex dex
bne @a bne @a
rts rts
;------------------------------------------------------------------------------
; IsSearchKey
; test whether accumulator contains a key that might trigger a new textrank
; search
;
; in: A = key
; out: A &= 0x7F
; Y preserved
; X clobbered
; Z = 1 if this is a search key
; Z = 0 if this is not a search key
;------------------------------------------------------------------------------
IsSearchKey
and #$7F ; strip high bit for search characters
cmp #$30 ; control keys and punctuation ignored
bcc @badkey
cmp #$3A ; numbers are good input
bcc @goodkey
cmp #$41 ; more punctuation (also ignored)
bcc @badkey
cmp #$5B ; uppercase letters are good input
bcs +
ora #$20 ; convert uppercase letters to lowercase
bne @goodkey ; always branches
+ cmp #$61 ; more punctuation (also ignored)
bcc @badkey
cmp #$7B ; lowercase letters are good input
bcc @goodkey
@badkey
ldx #1
rts
@goodkey
ldx #0
rts
} }

View File

@ -10,7 +10,9 @@
Credits Credits
; clobbers all ; clobbers all
jsr .LoadCredits +LDADDR .CreditsFile
jsr SetPath
jsr LoadFile ; loads at $8000
jsr ClearOffscreen jsr ClearOffscreen
lda OffscreenPage lda OffscreenPage
ror ; draw on offscreen page ror ; draw on offscreen page
@ -22,14 +24,6 @@ Credits
bit CLEARKBD bit CLEARKBD
clc clc
rts rts
.LoadCredits
; [private] clobbers all
+LDADDR .CreditsFile
+
jsr SetPath
jsr LoadFile ; loads at $8000
rts
.CreditsFile .CreditsFile
!byte 7 !byte 7
!text "CREDITS" !text "CREDITS"

View File

@ -5,7 +5,6 @@
; ;
; Public functions ; Public functions
; - SearchMode ; - SearchMode
; - IsSearchKey
; ;
!zone { !zone {
@ -22,9 +21,9 @@ SearchMode
+READ_RAM1_WRITE_RAM1 +READ_RAM1_WRITE_RAM1
ldx #$FF ldx #$FF
txs txs
stx SelectedIndex ; no game selected stx SelectedIndex ; $FF = no game selected
inx inx
stx OffscreenPage stx OffscreenPage ; $00 = currently showing HGR page 2
jsr Home ; clear screen jsr Home ; clear screen
jsr .OnInputChanged ; draw UI on HGR page 1 jsr .OnInputChanged ; draw UI on HGR page 1
+HGR_MODE ; show HGR +HGR_MODE ; show HGR
@ -47,68 +46,32 @@ SearchMode
@arrow ldx #kInputBrowse @arrow ldx #kInputBrowse
bne @InputDispatch ; always branches bne @InputDispatch ; always branches
@notArrow @notArrow
bit CLEARKBD
jsr ResetInputTimeout jsr ResetInputTimeout
cmp #$9B ; Esc clears the input buffer (if any) ldy #kNumBrowseKeys
bne + ; or switches to mega attract mode - dey
ldx #kInputClear bmi @noKeyMatch
cmp .InputKeys,y
bne -
ldx .InputKeyDispatch,y
bne @InputDispatch ; always branches bne @InputDispatch ; always branches
+
cmp #$8D ; ENTER launches the current game (if any)
bne +
ldx #kInputLaunch
bne @InputDispatch ; always branches
+
cmp #$FF ; delete key
bne +
- ldx #kInputBack
bne @InputDispatch ; always branches
+
cmp #$88 ; left arrow = delete (may as well, since
; popular emulators remap this anyway)
beq -
cmp #$89 ; TAB switches to mini attract mode @noKeyMatch
bne + ; if there is a game selected
- ldx #kInputTab
bne @InputDispatch ; always branches
+
cmp #$A0 ; SPACE = TAB because ][+ doesn't have TAB
beq -
cmp #$BF ; '?' display scredits
bne +
- ldx #kInputCredits
bne @InputDispatch ; always branches
+
cmp #$AF ; '/' also displays credits
beq -
and #$7F ; strip high bit for search characters
jsr IsSearchKey jsr IsSearchKey
beq + beq @foundSearchKey
jsr SoftBell ; Beep on invalid input and start over. ldx #kInputError
bne .SearchModeInputLoop ; This always branches because SoftBell +HIDE_NEXT_2_BYTES
; preserves all flags and we got here @foundSearchKey
; because the BEQ didn't branch.
+
ldx #kInputSearch ldx #kInputSearch
; execution falls through here ; execution falls through here
@InputDispatch @InputDispatch
pha ; save key pressed ldy .InputDispatchTableLo,x
txa sty @j+1
asl ldy .InputDispatchTableHi,x
tax sty @j+2
lda .InputDispatchTable,x
sta @j+1
lda .InputDispatchTable+1,x
sta @j+2
pla ; restore key pressed
@j jsr $FDFD ; SMC @j jsr $FDFD ; SMC
bcs + bcc .SearchModeInputLoop ; if carry is clear, we're done
jmp .SearchModeInputLoop ; if carry is clear, we're done bcs SearchMode ; if carry is set, force full redraw
+ jmp SearchMode ; if carry is set, force full redraw
.OnClear .OnClear
ldx InputLength ldx InputLength
@ -122,44 +85,40 @@ SearchMode
.OnBack .OnBack
ldx InputLength ldx InputLength
bne + bne +
jsr SoftBell jmp SoftBell
rts
+ dec InputLength + dec InputLength
jmp .OnInputChanged jmp .OnInputChanged
.OnTab .OnTab
ldx SelectedIndex ldx SelectedIndex
cpx #$FF cpx #$FF
beq + beq .ClearAndReturn
jsr MiniAttractMode jsr MiniAttractMode
cmp #$8D ; if we exited mini attract mode cmp #$8D ; if we exited mini attract mode
beq .OnLaunch ; by pressing Enter, launch the game beq .OnLaunch ; by pressing Enter, launch the game
sec ; tell caller to redraw UI sec ; tell caller to redraw UI
rts rts
+ clc
rts
.OnLaunch .OnLaunch
ldx SelectedIndex ldx SelectedIndex
cpx #$FF cpx #$FF
beq + beq .ClearAndReturn
jsr PlayGameFromSearch jsr PlayGameFromSearch
sec ; tell caller to redraw UI sec ; tell caller to redraw UI
rts rts
+ clc
rts
.OnSearch .OnSearch
ldx InputLength ldx InputLength
cpx #MaxInputLength cpx #MaxInputLength
bne + bne +
jsr SoftBell .OnError
jsr SoftBell ; Beep on invalid input and start over.
.ClearAndReturn
clc clc
rts rts
+ sta InputBuffer,x + sta InputBuffer,x
inc InputLength inc InputLength
; execution falls through here ; execution falls through here
.OnInputChanged .OnInputChanged
lda InputLength lda InputLength
bne @findMatchingTitle bne @findMatchingTitle
@ -178,6 +137,7 @@ SearchMode
jsr ShowOtherPage jsr ShowOtherPage
clc clc
rts rts
@findMatchingTitle @findMatchingTitle
jsr ResetTextRank jsr ResetTextRank
@ -187,10 +147,9 @@ SearchMode
lda MatchCount ; any matches at all? lda MatchCount ; any matches at all?
bne + bne +
jsr SoftBell ; no matches for this input buffer, beep ; no matches for this input buffer
dec InputLength ; and ignore the last key typed dec InputLength ; ignore the last key typed
clc jmp .OnError ; beep and return
rts
+ +
lda BestMatchIndex ; check if the new best match is the same lda BestMatchIndex ; check if the new best match is the same
cmp SelectedIndex ; as the current best match cmp SelectedIndex ; as the current best match
@ -270,29 +229,6 @@ SearchMode
jsr DrawSearchBarOffscreen; actually draw the search UI (offscreen) jsr DrawSearchBarOffscreen; actually draw the search UI (offscreen)
jmp ShowOtherPage ; now show everything at once jmp ShowOtherPage ; now show everything at once
IsSearchKey
cmp #$30 ; control keys and punctuation ignored
bcc @badkey
cmp #$3A ; numbers are good input
bcc @goodkey
cmp #$41 ; more punctuation (also ignored)
bcc @badkey
cmp #$5B ; uppercase letters are good input
bcs +
ora #$20 ; convert uppercase letters to lowercase
bne @goodkey ; always branches
+ cmp #$61 ; more punctuation (also ignored)
bcc @badkey
cmp #$7B ; lowercase letters are good input
bcc @goodkey
@badkey
ldx #1
rts
@goodkey
ldx #0
rts
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; indices into InputDispatchTable ; indices into InputDispatchTable
@ -303,14 +239,46 @@ kInputBrowse = 3
kInputTab = 4 kInputTab = 4
kInputLaunch = 5 kInputLaunch = 5
kInputCredits = 6 kInputCredits = 6
kInputError = 7
.InputDispatchTable .InputDispatchTableLo
!word .OnSearch !byte <.OnSearch
!word .OnClear !byte <.OnClear
!word .OnBack !byte <.OnBack
!word BrowseMode !byte <BrowseMode
!word .OnTab !byte <.OnTab
!word .OnLaunch !byte <.OnLaunch
!word Credits !byte <Credits
!byte <.OnError
.InputDispatchTableHi
!byte >.OnSearch
!byte >.OnClear
!byte >.OnBack
!byte >BrowseMode
!byte >.OnTab
!byte >.OnLaunch
!byte >Credits
!byte >.OnError
kNumInputKeys = 8 ; number of entries in next 2 tables (each)
.InputKeys
!byte $AF ; '/' = credits
!byte $BF ; '?' = credits
!byte $A0 ; Space = mini attract mode
!byte $89 ; TAB = mini attract mode
!byte $88 ; left arrow = delete (may as well, since
; popular emulators remap this anyway)
!byte $FF ; backspace = delete
!byte $8D ; ENTER = launch current game (if any)
!byte $9B ; Esc = clear input buffer (if any)
; or switch to mega attract mode
.InputKeyDispatch
!byte kInputCredits
!byte kInputCredits
!byte kInputTab
!byte kInputTab
!byte kInputBack
!byte kInputBack
!byte kInputLaunch
!byte kInputClear
} }