4cade/src/ui.browse.mode.a
2020-03-24 16:30:14 -04:00

173 lines
4.7 KiB
Plaintext

;license:MIT
;(c) 2018-2020 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 ; must match kInputError
ldy #kNumBrowseKeys
- dey
bmi @noKeyMatch
cmp BrowseKeys,y
bne -
ldx BrowseKeyDispatch,y
bne @BrowseDispatch ; always branches
@noKeyMatch
jsr IsSearchKey
bne @BrowseDispatch
ldx #kBrowseSearch
; 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
+LD16 gGameToLaunch
+CMP16 0
bne @notFirstGame
+LD16 GameCount
@notFirstGame
+DEC16
+ST16 gGameToLaunch
jmp OnBrowseChanged
OnBrowseNext
+LD16 gGameToLaunch
+INC16
+CMP16ADDR GameCount
bne @notLastGame
lda #0
tay
@notLastGame
+ST16 gGameToLaunch
jmp OnBrowseChanged
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 (word)
jsr SwitchToBank2
jsr EnableAcceleratorAndSwitchToBank1
jsr LoadGameTitleOffscreen
jsr DrawUIWithoutDots
jmp MaybeAnimateTitle
BrowseCreditsWrapper
jsr Credits
jmp ForceBrowseChanged
BrowseHelpWrapper
jsr Help
jmp ForceBrowseChanged
;------------------------------------------------------------------------------
BrowseDispatchTableLo
!byte <OnBrowseSearch
!byte <OnBrowsePrevious
!byte <OnBrowseNext
!byte <SearchMode
!byte <OnBrowseTab
!byte <OnBrowseLaunch
!byte <BrowseHelpWrapper
!byte <BrowseCreditsWrapper
!byte <OnBrowseCheat
!byte <SoftBell
BrowseDispatchTableHi
!byte >OnBrowseSearch
!byte >OnBrowsePrevious
!byte >OnBrowseNext
!byte >SearchMode
!byte >OnBrowseTab
!byte >OnBrowseLaunch
!byte >BrowseHelpWrapper
!byte >BrowseCreditsWrapper
!byte >OnBrowseCheat
!byte >SoftBell
kNumBrowseKeys = 12 ; number of entries in next 2 tables (each)
BrowseKeys
!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 $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
GameCount
!word 0