4cade/src/ui.search.mode.a

255 lines
7.9 KiB
Plaintext
Raw Normal View History

2018-12-23 16:13:47 +00:00
;license:MIT
;(c) 2018-9 by 4am
2018-12-23 16:13:47 +00:00
;
; Search Mode - main UI
2018-12-23 16:13:47 +00:00
;
; Public functions
; - SearchMode
2019-09-24 19:50:40 +00:00
; - IsSearchKey
2018-12-23 16:13:47 +00:00
;
2019-06-27 15:37:23 +00:00
2019-09-26 03:01:59 +00:00
.noKeyMatch
jsr IsSearchKey
beq .foundSearchKey
ldx #kInputError
+HIDE_NEXT_2_BYTES
.foundSearchKey
ldx #kInputSearch
; execution falls through here
.InputDispatch
ldy InputDispatchTableLo,x
sty .j+1
ldy InputDispatchTableHi,x
sty .j+2
.j jsr $FDFD ; SMC
bcc .SearchModeInputLoop ; if carry is clear, we're done
; fall through to force full redraw
;------------------------------------------------------------------------------
; SearchMode
; main entry point for Search Mode, which allows the user to search the game
; catalog and launch games
;
; in: none
; out: never returns to caller (may JMP to other major modes)
;------------------------------------------------------------------------------
2018-12-23 16:13:47 +00:00
SearchMode
ldx #$FF
txs
2019-09-21 03:26:32 +00:00
stx gGameToLaunch ; $FF = no game selected
jsr Home ; clear screen (switches to text mode)
jsr OnInputChanged ; draw UI offscreen
jsr HGRMode ; show HGR screen
jsr ResyncPage
2019-06-21 17:10:29 +00:00
2019-09-26 03:01:59 +00:00
.SearchModeInputLoop
jsr WaitForKeyFor30Seconds
2019-06-21 17:10:29 +00:00
; Don't clear keyboard strobe yet. If the user pressed an arrow key,
; we want to switch to Browse Mode with the keyboard still hot so
; that mode finds and dispatches the arrow key.
2019-06-21 17:17:57 +00:00
jsr IsUpDownOrRightArrow
2019-07-03 22:31:50 +00:00
bne @notArrow
ldx #kInputBrowse
2019-09-26 03:01:59 +00:00
bne .InputDispatch ; always branches
2019-07-03 22:31:50 +00:00
@notArrow
bit CLEARKBD
2019-06-20 18:18:23 +00:00
2019-09-06 19:21:38 +00:00
ldy #kNumBrowseKeys
- dey
2019-09-26 03:01:59 +00:00
bmi .noKeyMatch
2019-09-21 22:04:38 +00:00
cmp InputKeys,y
2019-09-06 19:21:38 +00:00
bne -
2019-09-21 22:04:38 +00:00
ldx InputKeyDispatch,y
2019-09-26 03:01:59 +00:00
bne .InputDispatch ; always branches
2019-09-07 18:15:53 +00:00
2019-09-21 22:04:38 +00:00
OnClear
ldx InputLength
bne +
2019-09-21 22:04:38 +00:00
jmp CoverFade ; Esc with no input transitions to
; mega attract mode
OnBack
2018-12-23 16:13:47 +00:00
ldx InputLength
2019-09-21 22:04:38 +00:00
beq OnError
2019-09-26 03:01:59 +00:00
+HIDE_NEXT_2_BYTES
+ ldx #1 ; Esc with input clears the input
dex
stx InputLength
bpl OnInputChanged ; always branches
2018-12-23 16:13:47 +00:00
2019-09-21 22:04:38 +00:00
OnTab
2019-09-21 03:26:32 +00:00
ldx gGameToLaunch
2019-06-27 02:51:34 +00:00
cpx #$FF
2019-09-21 22:04:38 +00:00
beq OnError
2019-06-27 02:51:34 +00:00
jsr MiniAttractMode
2019-06-27 15:37:23 +00:00
cmp #$8D ; if we exited mini attract mode
2019-09-26 03:01:59 +00:00
bne .req_redraw ; by pressing Enter, launch the game
2019-06-27 02:51:34 +00:00
2019-09-21 22:04:38 +00:00
OnLaunch
2019-09-21 03:26:32 +00:00
ldx gGameToLaunch
2019-06-20 18:18:23 +00:00
cpx #$FF
2019-09-21 22:04:38 +00:00
beq OnError
2019-09-21 03:26:32 +00:00
jsr PlayGame
2019-09-26 03:01:59 +00:00
.req_redraw
sec ; tell caller to redraw UI
rts
2018-12-23 16:13:47 +00:00
2019-09-21 22:04:38 +00:00
OnCheat
dec gGameToLaunch ; force reload (will be reset to correct value in OnInputChanged)
jsr ToggleCheat
2019-09-21 22:04:38 +00:00
beq OnInputChanged ; always branches because Z=1 on exit from ToggleCheat
2019-09-21 22:04:38 +00:00
OnSearch
2019-06-18 18:56:05 +00:00
ldx InputLength
cpx #MaxInputLength
2019-09-21 22:04:38 +00:00
beq OnError
2019-09-07 18:15:53 +00:00
sta InputBuffer,x
2019-06-18 18:56:05 +00:00
inc InputLength
; execution falls through here
2019-09-21 22:04:38 +00:00
OnInputChanged
2019-06-18 18:56:05 +00:00
lda InputLength
bne @findMatchingTitle
; no input, reset params and UI
2019-09-21 16:59:56 +00:00
ldx #$FF
stx gGameToLaunch ; no game selected
jsr LoadTitleOffscreen
2019-09-21 21:35:49 +00:00
jsr DrawUIWithoutDots
clc
rts
2019-09-06 19:21:38 +00:00
2019-06-18 18:56:05 +00:00
@findMatchingTitle
2019-06-18 21:07:14 +00:00
jsr ResetTextRank
2018-12-23 16:13:47 +00:00
2019-06-18 21:07:14 +00:00
jsr okvs_iter_values ; iterate through all game titles
!word gGamesListStore ; and rank them for the best match
!word TextRankCallback ; to the current input buffer
2018-12-23 16:13:47 +00:00
lda MatchCount ; any matches at all?
bne +
2019-09-06 19:21:38 +00:00
; no matches for this input buffer
dec InputLength ; ignore the last key typed
2019-09-26 03:01:59 +00:00
OnError
jmp SoftBell ; Beep on invalid input and start over.
+
2019-09-20 23:27:16 +00:00
ldx BestMatchIndex ; check if the new best match is the same
2019-09-21 03:26:32 +00:00
cpx gGameToLaunch ; as the current best match
stx gGameToLaunch
bne +
2019-07-03 22:31:50 +00:00
jsr ToggleOffscreenPage ; Since we're not loading a new screenshot
; we fake switching the 'offscreen' page
; in order to draw on the visible page.
2019-09-21 21:35:49 +00:00
bpl @noload ; (always branches)
+ jsr LoadGameTitleOffscreen
2019-09-28 12:35:48 +00:00
@noload jsr DrawUI
2019-10-02 23:13:42 +00:00
jsr MaybeAnimateTitle
clc
rts
2018-12-23 16:13:47 +00:00
;------------------------------------------------------------------------------
2019-09-24 19:50:40 +00:00
; 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
2019-09-26 03:01:59 +00:00
@goodkey
ldx #0
rts
2019-09-24 19:50:40 +00:00
+ cmp #$61 ; more punctuation (also ignored)
bcc @badkey
cmp #$7B ; lowercase letters are good input
bcc @goodkey
@badkey
ldx #1
rts
2018-12-23 16:13:47 +00:00
IsUpDownOrRightArrow
cmp #$8B ; up arrow
beq @done
cmp #$95 ; right arrow
beq @done
cmp #$8A ; down arrow
@done rts
; indices into InputDispatchTable
kInputSearch = 0
kInputClear = 1
kInputBack = 2
2019-07-03 22:31:50 +00:00
kInputBrowse = 3
kInputTab = 4
kInputLaunch = 5
kInputHelp = 6
kInputCredits = 7
kInputCheat = 8
kInputError = 9
2019-09-21 22:04:38 +00:00
InputDispatchTableLo
!byte <OnSearch
!byte <OnClear
!byte <OnBack
2019-09-06 19:21:38 +00:00
!byte <BrowseMode
2019-09-21 22:04:38 +00:00
!byte <OnTab
!byte <OnLaunch
!byte <Help
2019-09-06 19:21:38 +00:00
!byte <Credits
2019-09-21 22:04:38 +00:00
!byte <OnCheat
!byte <OnError
InputDispatchTableHi
!byte >OnSearch
!byte >OnClear
!byte >OnBack
2019-09-06 19:21:38 +00:00
!byte >BrowseMode
2019-09-21 22:04:38 +00:00
!byte >OnTab
!byte >OnLaunch
!byte >Help
2019-09-06 19:21:38 +00:00
!byte >Credits
2019-09-21 22:04:38 +00:00
!byte >OnCheat
!byte >OnError
2019-06-27 15:37:23 +00:00
kNumInputKeys = 10 ; number of entries in next 2 tables (each)
2019-09-21 22:04:38 +00:00
InputKeys
!byte $83 ; Ctrl-C = toggle cheat mode
!byte $A6 ; '&' = credits
!byte $AF ; '/' = help
!byte $BF ; '?' = help
2019-09-06 19:21:38 +00:00
!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
2019-09-21 22:04:38 +00:00
InputKeyDispatch
!byte kInputCheat
2019-09-06 19:21:38 +00:00
!byte kInputCredits
!byte kInputHelp
!byte kInputHelp
2019-09-06 19:21:38 +00:00
!byte kInputTab
!byte kInputTab
!byte kInputBack
!byte kInputBack
!byte kInputLaunch
!byte kInputClear