-
Notifications
You must be signed in to change notification settings - Fork 2
/
ui.search.mode.a
271 lines (249 loc) · 8.44 KB
/
ui.search.mode.a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
;license:MIT
;(c) 2018-2020 by 4am
;
; Search Mode - main UI
;
; Public functions
; - SearchMode
; - SoftBell
;
; 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
kInputQuit = 11
kInputSHR = 12
InputDispatchTableLo
!byte <OnSearch
!byte <OnClear
!byte <OnBack
!byte <BrowseMode
!byte <OnTab
!byte <OnLaunch
!byte <Help
!byte <Credits
!byte <OnCheat
!byte <OnError
!byte <Joystick
!byte <OnQuit
!byte <AllSHRSlideshow
InputDispatchTableHi
!byte >OnSearch
!byte >OnClear
!byte >OnBack
!byte >BrowseMode
!byte >OnTab
!byte >OnLaunch
!byte >Help
!byte >Credits
!byte >OnCheat
!byte >OnError
!byte >Joystick
!byte >OnQuit
!byte >AllSHRSlideshow
kNumInputKeys = 13
; number of entries in next 2 tables (each)
InputKeys
!byte $83 ; Ctrl-C = toggle cheat mode
!byte $81 ; Ctrl-A = about
!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
!byte $91 ; Ctrl-Q = quit
!byte $80 ; Ctrl-@ = SHR-only slideshow
InputKeyDispatch
!byte kInputCheat
!byte kInputCredits
!byte kInputHelp
!byte kInputHelp
!byte kInputTab
!byte kInputTab
!byte kInputBack
!byte kInputBack
!byte kInputLaunch
!byte kInputClear
!byte kInputJoystick
!byte kInputQuit
!byte kInputSHR
.noKeyMatch
jsr IsSearchKey
!if kInputSearch > 0 {
+HIDE_NEXT_2_BYTES
.foundSearchKey
ldx #kInputSearch
} else {
.foundSearchKey
}
; execution falls through here to .InputDispatch
.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)
;------------------------------------------------------------------------------
SearchMode
ldx #$FF
txs
stx gGameToLaunch ; $FFFF = no game selected
stx gGameToLaunch+1
stx gMegaAttractModeFilter ; $FF = all module types
jsr ReloadSearchIndex
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
lda KBD
jsr IsSearchKey
lda CLEARKBD - kInputError,X
; clear strobe if key was bad
.SearchModeInputLoop
jsr WaitForKeyFor30Seconds
; Don't clear keyboard strobe yet. Certain keys switch to Browse Mode
; with the keyboard still hot so that mode dispatches it
ldx #kInputBrowse
jsr IsKeyThatSwitchesToBrowseMode
beq .InputDispatch
bit CLEARKBD
ldy #kNumBrowseKeys
- dey
bmi .noKeyMatch
cmp InputKeys,y
bne -
ldx InputKeyDispatch,y
bne .InputDispatch ; always branches
OnClear
ldx #1 ; Esc with input clears the input
ldy InputLength
bne +
jmp CoverFade ; Esc with no input transitions to
; mega attract mode
OnBack
ldx InputLength
beq OnError
+ dex
stx InputLength
bpl OnInputChanged ; always branches
OnTab
jsr AnyGameSelected
bcs OnError
jsr MiniAttractMode
cmp #$8D ; if we exited mini attract mode
bne .req_redraw ; by pressing Enter, launch the game
jsr ReloadSearchIndex ; must reload search index before calling PlayGame
; /!\ execution falls through here
OnLaunch
ldx gGameToLaunch+1
inx
beq OnError
jsr PlayGame
.req_redraw
sec ; tell caller to reload search index and redraw UI from scratch
rts
OnCheat
dec gGameToLaunch ; force reload (will be reset to correct value in OnInputChanged)
jsr ToggleCheat
beq OnInputChanged ; always branches because Z=1 on exit from ToggleCheat
OnSearch
ldx InputLength
cpx #MaxInputLength
beq OnError
sta InputBuffer,x
inc InputLength
; execution falls through here to OnInputChanged
OnInputChanged
ldx InputLength
bne FindMatchingTitle
; no input, reset params and UI
dex
stx gGameToLaunch ; $FFFF = no game selected
stx gGameToLaunch+1
jsr LoadTitleOffscreen
jmp DrawUIWithoutDots
FindMatchingTitle
jsr SwitchToBank2
jsr EnableAcceleratorAndSwitchToBank1
jsr FindTitleInCache
bcc + ; sets BestMatchIndex on success
jsr ResetTextRank
jsr okvs_iter_values ; iterate through all game display names
!word gSearchStore ; and rank them for the best match
!word TextRankCallback ; to the current input buffer
lda MatchCount ; any matches at all?
bne +
; no matches for this input buffer
dec InputLength ; ignore the last key typed
OnError
jsr SwitchToBank2
jsr DisableAcceleratorAndSwitchToBank1
; /!\ 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
jsr WaitForKeyWithTimeout
bit SPEAKER
lda #33
jsr WaitForKeyWithTimeout
bit SPEAKER
dex
bne -
clc
rts
+
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
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
+LD16 BestMatchIndex
+ST16 gGameToLaunch
jsr LoadGameTitleOffscreen
lda #0
@noload
sta gDrawingOnscreen ; will minimize flicker in case we're
jsr DrawUI ; drawing directly onscreen
; /!\ execution falls through to ui.animation/MaybeAnimateTitle