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

264 lines
8.0 KiB
Plaintext
Raw Normal View History

2018-12-23 16:13:47 +00:00
;license:MIT
2020-03-17 01:58:05 +00:00
;(c) 2018-2020 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-10-08 17:34:37 +00:00
; - SoftBell
2018-12-23 16:13:47 +00:00
;
2019-06-27 15:37:23 +00:00
2019-10-08 17:19:20 +00:00
; indices into InputDispatchTable
kInputSearch = 0
kInputClear = 1
kInputBack = 2
kInputBrowse = 3
kInputTab = 4
kInputLaunch = 5
kInputHelp = 6
kInputCredits = 7
kInputCheat = 8
kInputError = 9
kInputJoystick = 10
2020-07-29 16:15:22 +00:00
kInputQuit = 11
2019-10-08 17:19:20 +00:00
InputDispatchTableLo
!byte <OnSearch
!byte <OnClear
!byte <OnBack
!byte <BrowseMode
!byte <OnTab
!byte <OnLaunch
!byte <Help
!byte <Credits
!byte <OnCheat
!byte <OnError
!byte <Joystick
2020-07-29 16:15:22 +00:00
!byte <OnQuit
2019-10-08 17:19:20 +00:00
InputDispatchTableHi
!byte >OnSearch
!byte >OnClear
!byte >OnBack
!byte >BrowseMode
!byte >OnTab
!byte >OnLaunch
!byte >Help
!byte >Credits
!byte >OnCheat
!byte >OnError
!byte >Joystick
2020-07-29 16:15:22 +00:00
!byte >OnQuit
2019-10-08 17:19:20 +00:00
2020-07-29 01:06:36 +00:00
kNumInputKeys = 12
; number of entries in next 2 tables (each)
2019-10-08 17:19:20 +00:00
InputKeys
!byte $83 ; Ctrl-C = toggle cheat mode
!byte $81 ; Ctrl-A = about
2019-10-08 17:19:20 +00:00
!byte $AF ; '/' = help
!byte $BF ; '?' = help
!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
!byte $90 ; Ctrl-P = launch joystick calibration program
2020-07-29 16:15:22 +00:00
!byte $91 ; Ctrl-Q = quit
2019-10-08 17:19:20 +00:00
InputKeyDispatch
!byte kInputCheat
!byte kInputCredits
!byte kInputHelp
!byte kInputHelp
!byte kInputTab
!byte kInputTab
!byte kInputBack
!byte kInputBack
!byte kInputLaunch
!byte kInputClear
!byte kInputJoystick
2020-07-29 16:15:22 +00:00
!byte kInputQuit
2019-10-08 17:19:20 +00:00
2019-09-26 03:01:59 +00:00
.noKeyMatch
jsr IsSearchKey
2019-10-09 02:25:22 +00:00
!if kInputSearch > 0 {
+HIDE_NEXT_2_BYTES
2019-09-26 03:01:59 +00:00
.foundSearchKey
ldx #kInputSearch
2019-10-09 02:25:22 +00:00
} else {
.foundSearchKey
}
2019-10-08 17:19:20 +00:00
; execution falls through here to .InputDispatch
2019-09-26 03:01:59 +00:00
.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
2020-03-24 20:30:14 +00:00
stx gGameToLaunch ; $FFFF = no game selected
stx gGameToLaunch+1
jsr BuildSearchStore
jsr Home ; clear screen (switches to text mode)
stx OffscreenPage ; don't show text page 2 by accident
jsr OnInputChanged ; draw UI offscreen
jsr HGRMode ; show HGR screen
jsr ResyncPage
2019-10-03 20:20:18 +00:00
lda KBD
jsr IsSearchKey
2019-11-27 21:51:43 +00:00
lda CLEARKBD - kInputError,X
; clear strobe if key was bad
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
2019-10-10 04:26:18 +00:00
ldx #kInputBrowse
jsr IsUpDownOrRightArrow
2019-10-10 04:26:18 +00:00
beq .InputDispatch
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
2019-10-10 04:26:18 +00:00
ldx #1 ; Esc with input clears the input
ldy 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-10-10 04:26:18 +00:00
+ dex
2019-09-26 03:01:59 +00:00
stx InputLength
bpl OnInputChanged ; always branches
2018-12-23 16:13:47 +00:00
2019-09-21 22:04:38 +00:00
OnTab
2020-03-24 20:30:14 +00:00
jsr AnyGameSelected
bcs 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
2020-03-24 20:30:14 +00:00
ldx gGameToLaunch+1
2019-10-10 01:02:46 +00:00
inx
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
2019-10-08 17:19:20 +00:00
; execution falls through here to OnInputChanged
2019-09-21 22:04:38 +00:00
OnInputChanged
2019-10-10 01:02:46 +00:00
ldx InputLength
2019-10-08 17:19:20 +00:00
bne FindMatchingTitle
2019-06-18 18:56:05 +00:00
; no input, reset params and UI
2019-10-10 01:02:46 +00:00
dex
2020-03-24 20:30:14 +00:00
stx gGameToLaunch ; $FFFF = no game selected
stx gGameToLaunch+1
jsr LoadTitleOffscreen
2019-11-27 21:51:43 +00:00
jmp DrawUIWithoutDots
2019-09-06 19:21:38 +00:00
2019-10-08 17:19:20 +00:00
FindMatchingTitle
jsr SwitchToBank2
jsr EnableAcceleratorAndSwitchToBank1
2019-06-18 21:07:14 +00:00
jsr ResetTextRank
2018-12-23 16:13:47 +00:00
jsr okvs_iter_values ; iterate through all game display names
!word gSearchStore ; and rank them for the best match
2019-06-18 21:07:14 +00:00
!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
jsr SwitchToBank2
jsr DisableAcceleratorAndSwitchToBank1
2019-10-08 17:34:37 +00:00
; /!\ execution falls through to SoftBell
;------------------------------------------------------------------------------
; SoftBell
; yell at the user, but, like, gently
;
; in: none
; out: C clear
; Y preserved
; A=0
; X=0
; all flags preserved
;------------------------------------------------------------------------------
SoftBell
ldx #32
- lda #2
2020-03-14 00:11:59 +00:00
jsr WaitForKeyWithTimeout
2019-10-08 17:34:37 +00:00
bit SPEAKER
lda #33
2020-03-14 00:11:59 +00:00
jsr WaitForKeyWithTimeout
2019-10-08 17:34:37 +00:00
bit SPEAKER
dex
bne -
clc
rts
2019-09-26 03:01:59 +00:00
+
2020-03-24 20:30:14 +00:00
lda BestMatchIndex ; check if the new best match is the same
cmp gGameToLaunch ; as the current best match
bne @load
lda BestMatchIndex+1
cmp gGameToLaunch+1
bne @load
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.
lda #1
bne @noload ; always branches
@load
2020-03-24 20:30:14 +00:00
+LD16 BestMatchIndex
+ST16 gGameToLaunch
2019-10-10 01:02:46 +00:00
jsr LoadGameTitleOffscreen
lda #0
@noload
sta gDrawingOnscreen ; will minimize flicker in case we're
jsr DrawUI ; drawing directly onscreen
2019-10-08 17:19:20 +00:00
; /!\ execution falls through to ui.animation/MaybeAnimateTitle