fix keyboard handling across search and browse modes

This commit is contained in:
4am 2019-07-03 22:27:46 -04:00
parent a37dd59b4f
commit 3fdc6256a3
3 changed files with 118 additions and 127 deletions

View File

@ -18,30 +18,13 @@
; out: never returns to caller (may JMP to other major modes) ; out: never returns to caller (may JMP to other major modes)
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
BrowseMode BrowseMode
+READ_RAM1_WRITE_RAM1
ldx #$FF ldx #$FF
txs txs
ldx SelectedIndex ldx SelectedIndex
stx BrowseSelectedIndex stx BrowseSelectedIndex
.BrowseModeInputLoop .BrowseModeInputLoop
lda KBD jsr WaitForKeyFor30Seconds
bmi @gotKey
inc RNDSEED+1 ; these are only ever incremented, never
bne + ; reset (may be used as a pseudorandom
inc RNDSEED ; seed)
+
dec Timeout ; these are a 3-byte timeout counter
bne .BrowseModeInputLoop ; that counts down from a number set
dec Timeout+1 ; in .ResetInputTimeout and reset
bne .BrowseModeInputLoop ; on every keypress (whether or not
dec Timeout+2 ; the key leads to an action)
bne .BrowseModeInputLoop
; jsr .CoverFade ; no input for ~30 seconds, switch to
jmp MegaAttractMode ; mega-attract mode
@gotKey
bit CLEARKBD bit CLEARKBD
jsr ResetInputTimeout jsr ResetInputTimeout
@ -61,7 +44,7 @@ BrowseMode
cmp #$9B ; Esc switches to search mode cmp #$9B ; Esc switches to search mode
bne + bne +
ldx #kBrowseExitMode ldx #kBrowseExitToSearch
bne @BrowseDispatch ; always branches bne @BrowseDispatch ; always branches
+ +
cmp #$8D ; ENTER launches the current game cmp #$8D ; ENTER launches the current game
@ -75,26 +58,11 @@ BrowseMode
bne @BrowseDispatch ; always branches bne @BrowseDispatch ; always branches
+ +
and #$7F ; strip high bit for search characters and #$7F ; strip high bit for search characters
cmp #$30 ; control keys and punctuation ignored jsr IsSearchKey
bcc @badkey beq +
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
jsr SoftBell ; beep on invalid input jsr SoftBell ; beep on invalid input
jmp .BrowseModeInputLoop ; and start over jmp .BrowseModeInputLoop ; and start over
+
@goodkey
ldx #kBrowseSearch ldx #kBrowseSearch
; execution falls through here ; execution falls through here
@BrowseDispatch @BrowseDispatch
@ -108,10 +76,7 @@ BrowseMode
sta @j+2 sta @j+2
pla ; restore key pressed pla ; restore key pressed
@j jsr $FDFD ; SMC @j jsr $FDFD ; SMC
bcs + jmp .BrowseModeInputLoop
jmp .BrowseModeInputLoop ; if carry is clear, we're done
; TODO
+ jmp BrowseMode ; if carry is set, force full redraw
.OnSearch .OnSearch
sta InputBuffer sta InputBuffer
@ -138,18 +103,20 @@ BrowseMode
@done stx BrowseSelectedIndex @done stx BrowseSelectedIndex
jmp .OnBrowseChanged jmp .OnBrowseChanged
.OnLaunch
ldx BrowseSelectedIndex
jsr PlayGameFromBrowse
jsr BlankHGR
jmp +
.OnTab .OnTab
ldx BrowseSelectedIndex ldx BrowseSelectedIndex
jsr MiniAttractMode jsr MiniAttractMode
cmp #$8D cmp #$8D
beq .OnLaunch beq .OnLaunch
; TODO redraw + bit CLEARKBD
rts
.OnLaunch
ldx BrowseSelectedIndex ldx BrowseSelectedIndex
jsr PlayGameFromBrowse ; execution falls through here
jmp BrowseMode
.OnBrowseChanged .OnBrowseChanged
stx @index stx @index
@ -199,7 +166,7 @@ BrowseMode
kBrowseSearch = 0 kBrowseSearch = 0
kBrowsePrevious = 1 kBrowsePrevious = 1
kBrowseNext = 2 kBrowseNext = 2
kBrowseExitMode = 3 kBrowseExitToSearch = 3
kBrowseTab = 4 kBrowseTab = 4
kBrowseLaunch = 5 kBrowseLaunch = 5

View File

@ -4,10 +4,14 @@
; common UI functions ; common UI functions
; ;
; Public functions ; Public functions
; - WaitForKeyFor30Seconds
; - GetOffscreenAddress ; - GetOffscreenAddress
; - LoadTitleOffscreen
; - LoadCoverOffscreen
; - DrawSearchBarOffscreen ; - DrawSearchBarOffscreen
; - ShowOtherPage ; - ShowOtherPage
; - ToggleOffscreenPage ; - ToggleOffscreenPage
; - CoverFade
; - ResetInputTimeout ; - ResetInputTimeout
; - SoftBell ; - SoftBell
; - Home ; - Home
@ -22,6 +26,7 @@
; ;
!zone { !zone {
OffscreenPage OffscreenPage
!byte 1 ; 0 = currently showing HGR page 2 !byte 1 ; 0 = currently showing HGR page 2
; (so offscreen is page 1 @ $2000) ; (so offscreen is page 1 @ $2000)
@ -54,6 +59,50 @@ GetOffscreenAddress
+ lda #$20 + lda #$20
rts rts
LoadTitleOffscreen
; clobbers all
+LDADDR .TitleFile
bne + ; Always branches, because Y is loaded
; last with the high byte of the address,
; which is never 0. I miss my 65c02.
LoadCoverOffscreen
; clobbers all
+LDADDR .CoverFile
+
jsr SetPath
jsr GetOffscreenAddress
sta +
jsr LoadFileAt
!byte $00
+ !byte $FD ; SMC
rts
.TitleFile
!byte 5
!text "TITLE"
.CoverFile
!byte 5
!text "COVER"
CoverFade
; clobbers all
jsr LoadCoverOffscreen
jsr ShowOtherPage
lda OffscreenPage
bne +
jsr LoadCoverOffscreen
jsr ShowOtherPage
+
; load transition effect code at $6000
+LDADDR kFXDirectory
jsr SetPath
+LDADDR @CoverFadeFile
jsr AddToPath
jsr LoadFile
jmp $6000 ; exit via loaded code
@CoverFadeFile
!byte 9
!text "COVERFADE"
DrawSearchBarOffscreen DrawSearchBarOffscreen
; clobbers all ; clobbers all
LDA #22 ; draw visible search bar LDA #22 ; draw visible search bar
@ -95,6 +144,24 @@ ResetInputTimeout
stx Timeout+2 stx Timeout+2
rts rts
WaitForKeyFor30Seconds
lda KBD
bmi @gotKey
inc RNDSEED+1 ; these are only ever incremented, never
bne + ; reset (may be used as a pseudorandom
inc RNDSEED ; seed)
+
dec Timeout ; these are a 3-byte timeout counter
bne WaitForKeyFor30Seconds; that counts down from a number set
dec Timeout+1 ; in .ResetInputTimeout and reset
bne WaitForKeyFor30Seconds; on every keypress (whether or not
dec Timeout+2 ; the key leads to an action)
bne WaitForKeyFor30Seconds
jsr CoverFade ; no input for ~30 seconds, switch to
jmp MegaAttractMode ; mega-attract mode
@gotKey rts
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; SoftBell ; SoftBell
; yell at the user, but, like, gently ; yell at the user, but, like, gently

View File

@ -5,6 +5,7 @@
; ;
; Public functions ; Public functions
; - SearchMode ; - SearchMode
; - IsSearchKey
; ;
!zone { !zone {
@ -31,23 +32,12 @@ SearchMode
jsr ResetInputTimeout jsr ResetInputTimeout
.SearchModeInputLoop .SearchModeInputLoop
lda KBD jsr WaitForKeyFor30Seconds
bmi @gotKey
inc RNDSEED+1 ; these are only ever incremented, never ; Don't clear keyboard strobe yet. If the user pressed an arrow key,
bne + ; reset (may be used as a pseudorandom ; we want to switch to Browse Mode with the keyboard still hot so
inc RNDSEED ; seed) ; that mode finds and dispatches the arrow key.
+
dec Timeout ; these are a 3-byte timeout counter
bne .SearchModeInputLoop ; that counts down from a number set
dec Timeout+1 ; in ResetInputTimeout and reset
bne .SearchModeInputLoop ; on every keypress (whether or not
dec Timeout+2 ; the key leads to an action)
bne .SearchModeInputLoop
jsr .CoverFade ; no input for ~30 seconds, switch to
jmp MegaAttractMode ; mega-attract mode
@gotKey
cmp #$88 ; left arrow switches to browse mode cmp #$88 ; left arrow switches to browse mode
beq @arrow beq @arrow
cmp #$8B ; also right arrow cmp #$8B ; also right arrow
@ -83,26 +73,13 @@ SearchMode
bne @InputDispatch ; always branches bne @InputDispatch ; always branches
+ +
and #$7F ; strip high bit for search characters and #$7F ; strip high bit for search characters
cmp #$30 ; control keys and punctuation ignored jsr IsSearchKey
bcc @badkey beq +
cmp #$3A ; numbers are good input jsr SoftBell ; Beep on invalid input and start over.
bcc @goodkey bne .SearchModeInputLoop ; This always branches because SoftBell
cmp #$41 ; more punctuation (also ignored) ; preserves all flags and we got here
bcc @badkey ; because the BEQ didn't branch.
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
jsr SoftBell ; beep on invalid input
jmp .SearchModeInputLoop ; and start over
@goodkey
ldx #kInputSearch ldx #kInputSearch
; execution falls through here ; execution falls through here
@InputDispatch @InputDispatch
@ -123,7 +100,7 @@ SearchMode
.OnClear .OnClear
ldx InputLength ldx InputLength
bne + bne +
jsr .CoverFade ; Esc with no input switches to jsr CoverFade ; Esc with no input switches to
jmp MegaAttractMode ; mega-attract mode jmp MegaAttractMode ; mega-attract mode
+ ldx #0 ; Esc with input clears the input + ldx #0 ; Esc with input clears the input
stx InputLength stx InputLength
@ -169,6 +146,7 @@ SearchMode
+ 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
@ -187,7 +165,7 @@ SearchMode
bne - bne -
lda #$7F lda #$7F
sta UILine2+1 sta UILine2+1
jsr .LoadTitleOffscreen jsr LoadTitleOffscreen
jsr DrawSearchBarOffscreen jsr DrawSearchBarOffscreen
jsr ShowOtherPage jsr ShowOtherPage
clc clc
@ -278,51 +256,30 @@ 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
.LoadTitleOffscreen + cmp #$61 ; more punctuation (also ignored)
; [private] clobbers all bcc @badkey
+LDADDR @TitleFile cmp #$7B ; lowercase letters are good input
bne + ; Always branches, because Y is loaded bcc @goodkey
; last with the high byte of the address, @badkey
; which is never 0. I miss my 65c02. ldx #1
.LoadCoverOffscreen rts
; [private] clobbers all @goodkey
+LDADDR @CoverFile ldx #0
+
jsr SetPath
jsr GetOffscreenAddress
sta +
jsr LoadFileAt
!byte $00
+ !byte $FD ; SMC
rts rts
@TitleFile
!byte 5
!text "TITLE"
@CoverFile
!byte 5
!text "COVER"
.CoverFade ;------------------------------------------------------------------------------
; [private] clobbers all
jsr .LoadCoverOffscreen
jsr ShowOtherPage
lda OffscreenPage
bne +
jsr .LoadCoverOffscreen
jsr ShowOtherPage
+
; load transition effect code at $6000
+LDADDR kFXDirectory
jsr SetPath
+LDADDR @CoverFadeFile
jsr AddToPath
jsr LoadFile
jmp $6000 ; exit via loaded code
@CoverFadeFile
!byte 9
!text "COVERFADE"
; indices into InputDispatchTable ; indices into InputDispatchTable
kInputSearch = 0 kInputSearch = 0