2018-12-23 16:13:47 +00:00
|
|
|
;license:MIT
|
2019-06-24 02:32:18 +00:00
|
|
|
;(c) 2018-9 by 4am
|
2018-12-23 16:13:47 +00:00
|
|
|
;
|
2019-06-24 02:32:18 +00:00
|
|
|
; Search Mode - main UI
|
2018-12-23 16:13:47 +00:00
|
|
|
;
|
|
|
|
; Public functions
|
|
|
|
; - SearchMode
|
|
|
|
;
|
2019-06-27 15:37:23 +00:00
|
|
|
|
|
|
|
!zone {
|
2018-12-23 16:13:47 +00:00
|
|
|
|
2019-06-24 02:32:18 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; 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
|
2019-06-24 02:32:18 +00:00
|
|
|
ldx #$FF
|
2019-06-23 18:24:09 +00:00
|
|
|
txs
|
2019-09-21 03:26:32 +00:00
|
|
|
stx gGameToLaunch ; $FF = no game selected
|
2019-06-24 02:32:18 +00:00
|
|
|
inx
|
2019-09-06 19:21:38 +00:00
|
|
|
stx OffscreenPage ; $00 = currently showing HGR page 2
|
2019-09-10 04:04:16 +00:00
|
|
|
jsr Home ; clear screen (switches to text mode)
|
2019-06-27 15:37:23 +00:00
|
|
|
jsr .OnInputChanged ; draw UI on HGR page 1
|
2019-09-10 04:04:16 +00:00
|
|
|
jsr HGRMode ; show HGR screen
|
2019-06-27 14:55:07 +00:00
|
|
|
bit CLEARKBD
|
2019-06-21 17:10:29 +00:00
|
|
|
|
2019-06-27 15:37:23 +00:00
|
|
|
.SearchModeInputLoop
|
2019-07-04 02:27:46 +00:00
|
|
|
jsr WaitForKeyFor30Seconds
|
2019-06-21 17:10:29 +00:00
|
|
|
|
2019-07-04 02:27:46 +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-09-10 03:04:17 +00:00
|
|
|
cmp #$8B ; up arrow switches to browse mode
|
2019-07-03 22:31:50 +00:00
|
|
|
beq @arrow
|
2019-09-10 03:04:17 +00:00
|
|
|
cmp #$95 ; also right arrow
|
2019-07-03 22:31:50 +00:00
|
|
|
beq @arrow
|
|
|
|
cmp #$8A ; also down arrow
|
|
|
|
bne @notArrow
|
|
|
|
@arrow ldx #kInputBrowse
|
|
|
|
bne @InputDispatch ; always branches
|
|
|
|
@notArrow
|
2019-09-10 04:04:16 +00:00
|
|
|
bit CLEARKBD
|
2019-06-20 18:18:23 +00:00
|
|
|
|
2019-09-06 19:21:38 +00:00
|
|
|
ldy #kNumBrowseKeys
|
|
|
|
- dey
|
|
|
|
bmi @noKeyMatch
|
|
|
|
cmp .InputKeys,y
|
|
|
|
bne -
|
|
|
|
ldx .InputKeyDispatch,y
|
2019-07-10 17:37:59 +00:00
|
|
|
bne @InputDispatch ; always branches
|
|
|
|
|
2019-09-06 19:21:38 +00:00
|
|
|
@noKeyMatch
|
2019-07-04 02:27:46 +00:00
|
|
|
jsr IsSearchKey
|
2019-09-06 19:21:38 +00:00
|
|
|
beq @foundSearchKey
|
|
|
|
ldx #kInputError
|
|
|
|
+HIDE_NEXT_2_BYTES
|
|
|
|
@foundSearchKey
|
2019-06-20 02:13:49 +00:00
|
|
|
ldx #kInputSearch
|
2019-06-18 18:56:05 +00:00
|
|
|
; execution falls through here
|
2019-06-27 15:37:23 +00:00
|
|
|
@InputDispatch
|
2019-09-06 19:21:38 +00:00
|
|
|
ldy .InputDispatchTableLo,x
|
|
|
|
sty @j+1
|
|
|
|
ldy .InputDispatchTableHi,x
|
|
|
|
sty @j+2
|
2019-06-18 18:56:05 +00:00
|
|
|
@j jsr $FDFD ; SMC
|
2019-09-06 19:21:38 +00:00
|
|
|
bcc .SearchModeInputLoop ; if carry is clear, we're done
|
|
|
|
bcs SearchMode ; if carry is set, force full redraw
|
2018-12-23 16:13:47 +00:00
|
|
|
|
2019-09-07 18:15:53 +00:00
|
|
|
.OnError
|
|
|
|
jmp SoftBell ; Beep on invalid input and start over.
|
|
|
|
|
2019-06-27 15:37:23 +00:00
|
|
|
.OnClear
|
2019-06-20 02:13:49 +00:00
|
|
|
ldx InputLength
|
|
|
|
bne +
|
2019-07-04 02:27:46 +00:00
|
|
|
jsr CoverFade ; Esc with no input switches to
|
2019-06-23 18:24:09 +00:00
|
|
|
jmp MegaAttractMode ; mega-attract mode
|
|
|
|
+ ldx #0 ; Esc with input clears the input
|
2019-06-20 02:13:49 +00:00
|
|
|
stx InputLength
|
2019-09-07 18:15:53 +00:00
|
|
|
beq .OnInputChanged ; always branches
|
2019-06-20 02:13:49 +00:00
|
|
|
|
2019-06-27 15:37:23 +00:00
|
|
|
.OnBack
|
2018-12-23 16:13:47 +00:00
|
|
|
ldx InputLength
|
2019-09-07 18:15:53 +00:00
|
|
|
beq .OnError
|
|
|
|
dec InputLength
|
2019-06-27 15:37:23 +00:00
|
|
|
jmp .OnInputChanged
|
2018-12-23 16:13:47 +00:00
|
|
|
|
2019-06-27 15:37:23 +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-07 18:15:53 +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
|
|
|
|
beq .OnLaunch ; by pressing Enter, launch the game
|
2019-06-27 02:51:34 +00:00
|
|
|
sec ; tell caller to redraw UI
|
|
|
|
rts
|
|
|
|
|
2019-06-27 15:37:23 +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-07 18:15:53 +00:00
|
|
|
beq .OnError
|
2019-09-21 03:26:32 +00:00
|
|
|
jsr PlayGame
|
2019-06-23 18:24:09 +00:00
|
|
|
sec ; tell caller to redraw UI
|
|
|
|
rts
|
2018-12-23 16:13:47 +00:00
|
|
|
|
2019-09-16 17:36:48 +00:00
|
|
|
.OnCheat
|
2019-09-21 03:26:32 +00:00
|
|
|
dec gGameToLaunch ; force reload (will be reset to correct value in .OnInputChanged)
|
2019-09-16 17:36:48 +00:00
|
|
|
jsr ToggleCheat
|
|
|
|
beq .OnInputChanged ; always branches because Z=1 on exit from ToggleCheat
|
|
|
|
|
2019-06-27 15:37:23 +00:00
|
|
|
.OnSearch
|
2019-06-18 18:56:05 +00:00
|
|
|
ldx InputLength
|
|
|
|
cpx #MaxInputLength
|
2019-09-07 18:15:53 +00:00
|
|
|
beq .OnError
|
|
|
|
sta InputBuffer,x
|
2019-06-18 18:56:05 +00:00
|
|
|
inc InputLength
|
|
|
|
; execution falls through here
|
2019-06-27 15:37:23 +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
|
2019-07-04 02:27:46 +00:00
|
|
|
jsr LoadTitleOffscreen
|
2019-09-21 16:59:56 +00:00
|
|
|
clc
|
|
|
|
jsr DrawSearchBarOffscreen
|
|
|
|
jsr ShowOtherPage
|
2019-06-23 18:24:09 +00:00
|
|
|
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
|
|
|
|
2019-06-20 02:13:49 +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
|
|
|
|
jmp .OnError ; beep and return
|
2019-06-20 02:13:49 +00:00
|
|
|
+
|
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
|
2019-06-20 02:13:49 +00:00
|
|
|
php ; (we'll use this later to skip reloading)
|
2019-09-21 03:26:32 +00:00
|
|
|
stx gGameToLaunch
|
2019-09-20 23:27:16 +00:00
|
|
|
+LDADDR gGamesListStore
|
2019-09-21 16:59:56 +00:00
|
|
|
jsr okvs_nth ; get the filename of the new best match
|
2018-12-23 16:13:47 +00:00
|
|
|
+STAY @key
|
2019-06-20 02:13:49 +00:00
|
|
|
plp
|
|
|
|
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-06-27 15:37:23 +00:00
|
|
|
bpl @skipload ; always branches
|
|
|
|
+
|
2019-07-03 22:31:50 +00:00
|
|
|
jsr GetOffscreenAddress ; we have a new best match, so load the
|
2019-06-27 15:37:23 +00:00
|
|
|
sta + ; new title screenshot (offscreen)
|
2019-09-10 02:38:17 +00:00
|
|
|
jsr LoadFile
|
|
|
|
!word kHGRTitleDirectory
|
|
|
|
@key !word $FDFD ; SMC
|
2019-06-27 15:37:23 +00:00
|
|
|
!byte $00
|
|
|
|
+ !byte $FD ; SMC
|
2018-12-23 16:13:47 +00:00
|
|
|
|
2019-06-20 02:13:49 +00:00
|
|
|
@skipload
|
2019-09-21 16:59:56 +00:00
|
|
|
sec
|
|
|
|
jsr DrawSearchBarOffscreen
|
|
|
|
jmp ShowOtherPage
|
2018-12-23 16:13:47 +00:00
|
|
|
|
2019-07-04 02:27:46 +00:00
|
|
|
;------------------------------------------------------------------------------
|
2018-12-23 16:13:47 +00:00
|
|
|
|
2019-06-24 02:32:18 +00:00
|
|
|
; indices into InputDispatchTable
|
|
|
|
kInputSearch = 0
|
|
|
|
kInputClear = 1
|
|
|
|
kInputBack = 2
|
2019-07-03 22:31:50 +00:00
|
|
|
kInputBrowse = 3
|
|
|
|
kInputTab = 4
|
|
|
|
kInputLaunch = 5
|
2019-07-10 17:37:59 +00:00
|
|
|
kInputCredits = 6
|
2019-09-16 17:36:48 +00:00
|
|
|
kInputCheat = 7
|
|
|
|
kInputError = 8
|
2019-06-24 02:32:18 +00:00
|
|
|
|
2019-09-06 19:21:38 +00:00
|
|
|
.InputDispatchTableLo
|
|
|
|
!byte <.OnSearch
|
|
|
|
!byte <.OnClear
|
|
|
|
!byte <.OnBack
|
|
|
|
!byte <BrowseMode
|
|
|
|
!byte <.OnTab
|
|
|
|
!byte <.OnLaunch
|
|
|
|
!byte <Credits
|
2019-09-16 17:36:48 +00:00
|
|
|
!byte <.OnCheat
|
2019-09-06 19:21:38 +00:00
|
|
|
!byte <.OnError
|
|
|
|
.InputDispatchTableHi
|
|
|
|
!byte >.OnSearch
|
|
|
|
!byte >.OnClear
|
|
|
|
!byte >.OnBack
|
|
|
|
!byte >BrowseMode
|
|
|
|
!byte >.OnTab
|
|
|
|
!byte >.OnLaunch
|
|
|
|
!byte >Credits
|
2019-09-16 17:36:48 +00:00
|
|
|
!byte >.OnCheat
|
2019-09-06 19:21:38 +00:00
|
|
|
!byte >.OnError
|
2019-06-27 15:37:23 +00:00
|
|
|
|
2019-09-16 17:36:48 +00:00
|
|
|
kNumInputKeys = 9 ; number of entries in next 2 tables (each)
|
2019-09-06 19:21:38 +00:00
|
|
|
.InputKeys
|
2019-09-16 17:36:48 +00:00
|
|
|
!byte $83 ; Ctrl-C = toggle cheat mode
|
2019-09-06 19:21:38 +00:00
|
|
|
!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
|
2019-09-16 17:36:48 +00:00
|
|
|
!byte kInputCheat
|
2019-09-06 19:21:38 +00:00
|
|
|
!byte kInputCredits
|
|
|
|
!byte kInputCredits
|
|
|
|
!byte kInputTab
|
|
|
|
!byte kInputTab
|
|
|
|
!byte kInputBack
|
|
|
|
!byte kInputBack
|
|
|
|
!byte kInputLaunch
|
|
|
|
!byte kInputClear
|
2019-06-27 15:37:23 +00:00
|
|
|
}
|