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

178 lines
5.0 KiB
Plaintext

;license:MIT
;(c) 2018-9 by 4am
;
; Browse Mode - main UI
;
; Public functions
; - BrowseMode
;
;------------------------------------------------------------------------------
; BrowseMode
; main entry point for Browse Mode, which allows the user to browse the game
; catalog in alphabetical order and launch games
;
; in: none
; out: never returns to caller (may JMP to other major modes)
;------------------------------------------------------------------------------
BrowseMode
ldx #$FF
txs
@BrowseModeInputLoop
jsr WaitForKeyFor30Seconds
bit CLEARKBD
; indices into BrowseDispatchTable below
kBrowseSearch = 0
kBrowsePrevious = 1
kBrowseNext = 2
kBrowseExitToSearch = 3
kBrowseTab = 4
kBrowseLaunch = 5
kBrowseHelp = 6
kBrowseCredits = 7
kBrowseCheat = 8
kSoftBell = 9
ldy #kNumBrowseKeys
- dey
bmi @noKeyMatch
cmp BrowseKeys,y
bne -
ldx BrowseKeyDispatch,y
bne @BrowseDispatch ; always branches
@noKeyMatch
jsr IsSearchKey
beq +
ldx #kSoftBell ; beep on invalid input
!if kBrowseSearch > 0 {
+HIDE_NEXT_2_BYTES
+
ldx #kBrowseSearch
} else {
+
}
; execution falls through here
@BrowseDispatch
ldy BrowseDispatchTableLo,x
sty @j+1
ldy BrowseDispatchTableHi,x
sty @j+2
@j jsr $FDFD ; SMC
jmp @BrowseModeInputLoop
OnBrowseSearch
sta InputBuffer
lda #$01
sta InputLength
jmp SearchMode
OnBrowsePrevious
ldx gGameToLaunch
inx ; Slightly pathological case: there may be no
; current game by the time we get here, e.g.
; if we entered browse mode by pressing left
; or up arrow from the global help screen.
; In this case, pretend we were at game 0 and
; continue with the key handler logic.
beq +
dex
bne .decindex
+ ldx GameCount
.decindex
dex
.setindex
stx gGameToLaunch
jmp OnBrowseChanged
OnBrowseNext
ldx gGameToLaunch
inx
GameCount = *+1
cpx #$D1 ; SMC
bne .setindex
ldx #0
beq .setindex ; branch always
OnBrowseLaunch
jsr PlayGame
jsr BlankHGR
jmp ForceBrowseChanged
OnBrowseCheat
jsr ToggleCheat
beq ForceBrowseChanged ; always branches because Z=1 on exit from ToggleCheat
OnBrowseTab
jsr MiniAttractMode
cmp #$8D
beq OnBrowseLaunch
; execution falls through here
ForceBrowseChanged
bit CLEARKBD
; execution falls through here
OnBrowseChanged
; in: gGameToLaunch = game index
jsr SwitchToBank2
jsr EnableAcceleratorAndSwitchToBank1
jsr LoadGameTitleOffscreen
jsr DrawUIWithoutDots
jmp MaybeAnimateTitle
;------------------------------------------------------------------------------
BrowseDispatchTableLo
!byte <OnBrowseSearch
!byte <OnBrowsePrevious
!byte <OnBrowseNext
!byte <SearchMode
!byte <OnBrowseTab
!byte <OnBrowseLaunch
!byte <Help
!byte <Credits
!byte <OnBrowseCheat
!byte <SoftBell
BrowseDispatchTableHi
!byte >OnBrowseSearch
!byte >OnBrowsePrevious
!byte >OnBrowseNext
!byte >SearchMode
!byte >OnBrowseTab
!byte >OnBrowseLaunch
!byte >Help
!byte >Credits
!byte >OnBrowseCheat
!byte >SoftBell
kNumBrowseKeys = 12 ; number of entries in next 2 tables (each)
BrowseKeys
!byte $83 ; Ctrl-C = toggle cheat mode
!byte $A6 ; '&' = credits
!byte $AF ; '/' = help
!byte $BF ; '?' = help
!byte $A0 ; Space = mini attract mode
!byte $89 ; TAB = mini attract mode
!byte $8D ; ENTER = launch current game
!byte $9B ; Esc = switch to search mode
!byte $8A ; down arrow = next
!byte $95 ; right arrow = next
!byte $8B ; up arrow = previous
!byte $88 ; left arrow = previous
BrowseKeyDispatch
!byte kBrowseCheat
!byte kBrowseCredits
!byte kBrowseHelp
!byte kBrowseHelp
!byte kBrowseTab
!byte kBrowseTab
!byte kBrowseLaunch
!byte kBrowseExitToSearch
!byte kBrowseNext
!byte kBrowseNext
!byte kBrowsePrevious
!byte kBrowsePrevious