mirror of
https://github.com/a2-4am/4cade.git
synced 2024-12-26 04:33:10 +00:00
refactor PlayGame
This commit is contained in:
parent
10e3d05f07
commit
8e19fc9c5b
@ -9,7 +9,7 @@
|
||||
; D000..E5F4 - persistent data structures (per-game cheat categories,
|
||||
; gGlobalPrefsStore, gGamesListStore)
|
||||
; ...unused...
|
||||
; EAE5..FFF9 - main program code
|
||||
; EB42..FFF9 - main program code
|
||||
; FFFA..FFFF - NMI, reset, IRQ vectors
|
||||
;
|
||||
; LC RAM BANK 2
|
||||
|
@ -5,15 +5,9 @@
|
||||
;
|
||||
; Public functions
|
||||
; - GetGameDisplayName
|
||||
; - PlayGameFromSearch
|
||||
; - PlayGameFromBrowse
|
||||
; - PlayGameFromAttract
|
||||
; - PlayGame
|
||||
; - Launch
|
||||
;
|
||||
; Public variables
|
||||
; - gCurrentAttractIndex ; [byte] numeric index in gAttractModeStore of current Mega-Attract Module
|
||||
; - gCurrentlyVisibleSlideshowIndex ; [byte] numeric index in gSlideshowStore of currently visible slideshow picture
|
||||
; (only valid during slideshows, not updated once a key is pressed)
|
||||
|
||||
!zone {
|
||||
|
||||
@ -23,6 +17,9 @@ GetGameDisplayName
|
||||
; X = #$EA if we should also look in gSlideshowStore
|
||||
; out: C clear if game exists in gGamesListStore, and
|
||||
; A/Y points to game display name (but see hack notes below)
|
||||
; X = game index, or #$FF if the game doesn't really exist but
|
||||
; we want to return a successful result anyway (really, read the
|
||||
; hack notes, they're important)
|
||||
; C set if game does not exist (this can happen because slideshows
|
||||
; list games that require a joystick, but the games list parser
|
||||
; filters out joystick-only games if the machine doesn't have a
|
||||
@ -67,70 +64,16 @@ GetGameDisplayName
|
||||
rts
|
||||
@forceGoodResult
|
||||
+LDAY @key
|
||||
ldx #$FF
|
||||
clc
|
||||
@exit rts
|
||||
|
||||
PlayGameFromSearch
|
||||
PlayGameFromBrowse
|
||||
; in: X = game index
|
||||
PlayGame
|
||||
gGameToLaunch=*+1
|
||||
ldx #$FF ; SMC
|
||||
+LDADDR gGamesListStore
|
||||
jsr okvs_nth
|
||||
; A/Y = address of game filename
|
||||
bne .Go ; always branches
|
||||
|
||||
PlayGameFromAttract
|
||||
; in: none
|
||||
jsr LoadAndParseAttractModeConf
|
||||
|
||||
+LDADDR gAttractModeStore
|
||||
gCurrentAttractIndex=*+1
|
||||
ldx #$FD ; set in MegaAttractMode
|
||||
jsr okvs_nth ; get filename of current attract-mode module
|
||||
+STAY @key
|
||||
jsr okvs_get
|
||||
!word gAttractModeStore
|
||||
@key !word $FDFD ; SMC
|
||||
; A/Y = address of attract mode value (module type)
|
||||
+STAY PTR
|
||||
ldy #1
|
||||
lda (PTR),y
|
||||
and #$0F
|
||||
bne @playFromSlideshow
|
||||
|
||||
; we reached here by pressing <RETURN> during a self-running demo,
|
||||
; which means that @key points to the filename of the game we want to play,
|
||||
+LDAY @key
|
||||
jmp .Go
|
||||
|
||||
@playFromSlideshow
|
||||
; we reached here by pressing <RETURN> during a slideshow
|
||||
; gSlideshowStore is still in memory, and gCurrentlyVisibleSlideshowIndex
|
||||
; is the index into gSlideshowStore of the picture that is being displayed
|
||||
+LDADDR gSlideshowStore
|
||||
gCurrentlyVisibleSlideshowIndex=*+1
|
||||
ldx #$FD ; set in HGRTitleCallback, HGRActionCallback, DHGRTitleCallback
|
||||
jsr okvs_nth
|
||||
!word gSlideshowStore
|
||||
+STAY @sskey
|
||||
+STAY @sskey2
|
||||
jsr okvs_get
|
||||
!word gGamesListStore
|
||||
@sskey !word $FDFD ; SMC
|
||||
bcs +
|
||||
+LDAY @sskey ; the slideshow key was a game filename, so use that
|
||||
jmp .Go
|
||||
+
|
||||
; if the key is not found, get the value of the current record
|
||||
; from gSlideshowStore instead (some games have multiple action screenshots, so
|
||||
; the key is just a unique filename for that screenshot and the value is the
|
||||
; actual game filename)
|
||||
jsr okvs_get
|
||||
!word gSlideshowStore
|
||||
@sskey2 !word $FDFD ; SMC
|
||||
; execution falls through here
|
||||
|
||||
.Go
|
||||
; in: A/Y = lo/hi address of filename
|
||||
+STAY SAVE
|
||||
+STAY +
|
||||
+STAY @pfile
|
||||
@ -141,7 +84,7 @@ gCurrentlyVisibleSlideshowIndex=*+1
|
||||
ldx #$40 ; to flash previous bits of the launcher UI)
|
||||
ldy #$00
|
||||
tya
|
||||
@clear sta $FD00,y
|
||||
@clear sta $FD00,y ; SMC
|
||||
iny
|
||||
bne @clear
|
||||
inc @clear+2
|
||||
|
@ -29,8 +29,6 @@ InputLength
|
||||
!byte 0
|
||||
InputBuffer
|
||||
!text " "
|
||||
SelectedIndex
|
||||
!byte $FF
|
||||
MatchCount
|
||||
!byte 0
|
||||
BestMatchScore
|
||||
|
@ -108,17 +108,15 @@ kDFXConfFile
|
||||
@exit rts
|
||||
+
|
||||
+STAY @tfname
|
||||
stx gCurrentlyVisibleSlideshowIndex
|
||||
|
||||
; try to get the human-readable name of this game from gGamesListStore
|
||||
; find this game in gGamesListStore
|
||||
ldx #$60
|
||||
jsr GetGameDisplayName
|
||||
; if game is not found (C will be set here), it means it can't be played on
|
||||
; this machine due to memory or joystick requirements, so we don't display
|
||||
; it in slideshows
|
||||
bcs @exit
|
||||
; (we don't actually use the display name in the title slideshow, we just
|
||||
; reuse the function for convenience)
|
||||
stx gGameToLaunch
|
||||
|
||||
; load DHGR screenshot at $4000/main and $4000/aux
|
||||
jsr LoadDHRFile
|
||||
@ -147,18 +145,15 @@ kDFXConfFile
|
||||
rts
|
||||
+
|
||||
+STAY @afname
|
||||
stx gCurrentlyVisibleSlideshowIndex
|
||||
|
||||
; try to get the human-readable name of this game from gGamesListStore
|
||||
; or gSlideshowStore
|
||||
; find this game in gGamesListStore or gSlideshowStore
|
||||
ldx #$EA
|
||||
jsr GetGameDisplayName
|
||||
; if game is not found (C will be set here), it means it can't be played on
|
||||
; this machine due to memory or joystick requirements, so we don't display
|
||||
; it in slideshows
|
||||
; if game name is not found (C will be set here), it means the game
|
||||
; can't be played due to memory or joystick requirements, so we hide
|
||||
; it from slideshows
|
||||
bcs @actionExit
|
||||
; (we don't actually use the display name in the DHGR action slideshow, we
|
||||
; just reuse the function for convenience)
|
||||
stx gGameToLaunch
|
||||
|
||||
; load DHGR screenshot at $4000/main and $4000/aux
|
||||
jsr LoadDHRFile
|
||||
|
@ -91,18 +91,15 @@ kGRFizzleFile
|
||||
rts
|
||||
+
|
||||
+STAY @fname
|
||||
stx gCurrentlyVisibleSlideshowIndex
|
||||
|
||||
; try to get the human-readable name of this game from gGamesListStore
|
||||
; or gSlideshowStore
|
||||
; find this game in gGamesListStore or gSlideshowStore
|
||||
ldx #$EA
|
||||
jsr GetGameDisplayName
|
||||
; if game is not found (C will be set here), it means it can't be played on
|
||||
; this machine due to memory or joystick requirements, so we don't display
|
||||
; it in slideshows
|
||||
; if game name is not found (C will be set here), it means the game
|
||||
; can't be played due to memory or joystick requirements, so we hide
|
||||
; it from slideshows
|
||||
bcs @actionExit
|
||||
; (we don't actually use the display name in the GR action slideshow, we
|
||||
; just reuse the function for convenience)
|
||||
stx gGameToLaunch
|
||||
|
||||
jsr LoadFile ; load GR screenshot into $6000
|
||||
!word kGRActionDirectory
|
||||
|
@ -52,17 +52,15 @@ HGRSingle
|
||||
@exit rts
|
||||
+
|
||||
+STAY @tfname
|
||||
stx gCurrentlyVisibleSlideshowIndex
|
||||
|
||||
; try to get the human-readable name of this game from gGamesListStore
|
||||
; find this game in gGamesListStore
|
||||
ldx #$60
|
||||
jsr GetGameDisplayName
|
||||
; if game is not found (C will be set here), it means it can't be played on
|
||||
; this machine due to memory or joystick requirements, so we don't display
|
||||
; it in slideshows
|
||||
bcs @exit
|
||||
; (we don't actually use the display name in the title slideshow, we just
|
||||
; reuse the function for convenience)
|
||||
stx gGameToLaunch
|
||||
|
||||
jsr LoadFile ; load HGR screenshot at $4000
|
||||
!word kHGRTitleDirectory
|
||||
@ -91,10 +89,8 @@ HGRSingle
|
||||
rts
|
||||
+
|
||||
+STAY @afname
|
||||
stx gCurrentlyVisibleSlideshowIndex
|
||||
|
||||
; try to get the human-readable name of this game from gGamesListStore
|
||||
; or gSlideshowStore
|
||||
; find this game in gGamesListStore or gSlideshowStore
|
||||
ldx #$EA
|
||||
jsr GetGameDisplayName
|
||||
; if game name is not found (C will be set here), it means the game
|
||||
@ -104,6 +100,7 @@ HGRSingle
|
||||
|
||||
; found the game
|
||||
+STAY SAVE
|
||||
stx gGameToLaunch
|
||||
|
||||
jsr LoadFile ; load HGR screenshot at $4000
|
||||
!word kHGRActionDirectory
|
||||
|
@ -1,12 +1,12 @@
|
||||
;license:MIT
|
||||
;(c) 2018-9 by 4am
|
||||
;
|
||||
; Mega Attract Mode - cycle through slideshows and self-running demos
|
||||
; Attract Mode - cycle through slideshows and self-running demos
|
||||
;
|
||||
; Public functions
|
||||
; - MegaAttractMode
|
||||
; - MiniAttractMode
|
||||
; - RunAttractModule
|
||||
; - LoadAndParseAttractModeConf
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; MegaAttractMode
|
||||
@ -24,7 +24,14 @@ MegaAttractMode
|
||||
|
||||
jsr BlankHGR ; switch to HGR page 1 (once cleared)
|
||||
|
||||
jsr LoadAndParseAttractModeConf
|
||||
jsr LoadFile ; load attract-mode configuration file into $8000
|
||||
!word kRootDirectory
|
||||
!word kAttractModeConfFile
|
||||
- !word $8000
|
||||
jsr ParseKeyValueList ; parse attract-mode configuration into OKVS data structure at $6000
|
||||
!word gAttractModeStore
|
||||
!word -
|
||||
!byte 0
|
||||
|
||||
jsr pref_get ; get attract mode module from prefs
|
||||
!word kNextAttract
|
||||
@ -52,7 +59,7 @@ MegaAttractMode
|
||||
bpl @jmpattract
|
||||
cmp #$8D ; Enter plays the game shown on screen.
|
||||
bne @jmpsearch ; Any other key switches to Search Mode.
|
||||
jsr PlayGameFromAttract ; Might return if user hits Ctrl-Reset.
|
||||
jsr PlayGame ; (might return if user hits Ctrl-Reset)
|
||||
@jmpattract
|
||||
jmp MegaAttractMode
|
||||
@jmpsearch
|
||||
@ -146,6 +153,10 @@ RunAttractModule
|
||||
jsr GetGameDisplayName
|
||||
bcc + ; if game doesn't exist, skip the demo
|
||||
rts
|
||||
+
|
||||
cpx #$FF
|
||||
beq +
|
||||
stx gGameToLaunch
|
||||
+
|
||||
jsr Home ; avoid seeing code load into the HGR page
|
||||
|
||||
@ -223,17 +234,6 @@ RunAttractModule
|
||||
!byte >SHRSingle
|
||||
!byte >GRSingle
|
||||
|
||||
LoadAndParseAttractModeConf
|
||||
; TODO refactor launch code then make this private
|
||||
jsr LoadFile ; load attract-mode configuration file into $8000
|
||||
!word kRootDirectory
|
||||
!word @AttractModeConfFile
|
||||
- !word $8000
|
||||
jsr ParseKeyValueList ; parse attract-mode configuration into OKVS data structure at $6000
|
||||
!word gAttractModeStore
|
||||
!word -
|
||||
!byte 0
|
||||
rts
|
||||
@AttractModeConfFile
|
||||
kAttractModeConfFile
|
||||
!byte 12
|
||||
!text "ATTRACT.CONF"
|
||||
|
@ -69,10 +69,18 @@ kSFXFizzleFile
|
||||
.SHRArtworkCallback
|
||||
bit KBD
|
||||
bpl +
|
||||
rts
|
||||
@exit rts
|
||||
+
|
||||
+STAY @sfname
|
||||
stx gCurrentlyVisibleSlideshowIndex
|
||||
|
||||
; find this game in gGamesListStore
|
||||
ldx #$60
|
||||
jsr GetGameDisplayName
|
||||
; if game is not found (C will be set here), it means it can't be played on
|
||||
; this machine due to memory or joystick requirements, so we don't display
|
||||
; it in slideshows
|
||||
bcs @exit
|
||||
stx gGameToLaunch
|
||||
|
||||
jsr .BlankSHR
|
||||
|
||||
|
@ -20,8 +20,6 @@
|
||||
BrowseMode
|
||||
ldx #$FF
|
||||
txs
|
||||
ldx SelectedIndex
|
||||
stx BrowseSelectedIndex
|
||||
|
||||
.BrowseModeInputLoop
|
||||
jsr WaitForKeyFor30Seconds
|
||||
@ -58,12 +56,12 @@ BrowseMode
|
||||
jmp SearchMode
|
||||
|
||||
.OnPrevious
|
||||
dec BrowseSelectedIndex
|
||||
dec gGameToLaunch
|
||||
jmp +
|
||||
.OnNext
|
||||
inc BrowseSelectedIndex
|
||||
inc gGameToLaunch
|
||||
+
|
||||
ldx BrowseSelectedIndex
|
||||
ldx gGameToLaunch
|
||||
cpx #$FF
|
||||
bne @notTooSmall
|
||||
GameCount = *+1
|
||||
@ -74,12 +72,11 @@ GameCount = *+1
|
||||
cpx GameCount
|
||||
bcc @done
|
||||
ldx #0
|
||||
@done stx BrowseSelectedIndex
|
||||
@done stx gGameToLaunch
|
||||
jmp .OnBrowseChanged
|
||||
|
||||
.OnLaunch
|
||||
ldx BrowseSelectedIndex
|
||||
jsr PlayGameFromBrowse
|
||||
jsr PlayGame
|
||||
jsr BlankHGR
|
||||
jmp .ForceBrowseChanged
|
||||
|
||||
@ -88,13 +85,13 @@ GameCount = *+1
|
||||
beq .ForceBrowseChanged ; always branches because Z=1 on exit from ToggleCheat
|
||||
|
||||
.OnTab
|
||||
ldx BrowseSelectedIndex
|
||||
ldx gGameToLaunch
|
||||
jsr MiniAttractMode
|
||||
cmp #$8D
|
||||
beq .OnLaunch
|
||||
.ForceBrowseChanged
|
||||
bit CLEARKBD
|
||||
ldx BrowseSelectedIndex
|
||||
ldx gGameToLaunch
|
||||
; execution falls through here
|
||||
.OnBrowseChanged
|
||||
+LDADDR gGamesListStore
|
||||
@ -132,9 +129,9 @@ GameCount = *+1
|
||||
sta UI_ToPlay,x
|
||||
dex
|
||||
bpl -
|
||||
ldx BrowseSelectedIndex
|
||||
ldx gGameToLaunch
|
||||
jsr BuildUILine1WithNoDots; build UI line 1 with bars and other shapes
|
||||
ldx BrowseSelectedIndex
|
||||
ldx gGameToLaunch
|
||||
jsr DrawSearchBarOffscreen; actually draw the UI (offscreen)
|
||||
jmp ShowOtherPage ; now show everything at once
|
||||
|
||||
@ -194,8 +191,4 @@ kNumBrowseKeys = 11 ; number of entries in next 2 tables (each)
|
||||
!byte kBrowseNext
|
||||
!byte kBrowsePrevious
|
||||
!byte kBrowsePrevious
|
||||
|
||||
BrowseSelectedIndex
|
||||
!byte $FF
|
||||
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
SearchMode
|
||||
ldx #$FF
|
||||
txs
|
||||
stx SelectedIndex ; $FF = no game selected
|
||||
stx gGameToLaunch ; $FF = no game selected
|
||||
inx
|
||||
stx OffscreenPage ; $00 = currently showing HGR page 2
|
||||
jsr Home ; clear screen (switches to text mode)
|
||||
@ -90,7 +90,7 @@ SearchMode
|
||||
jmp .OnInputChanged
|
||||
|
||||
.OnTab
|
||||
ldx SelectedIndex
|
||||
ldx gGameToLaunch
|
||||
cpx #$FF
|
||||
beq .OnError
|
||||
jsr MiniAttractMode
|
||||
@ -100,15 +100,15 @@ SearchMode
|
||||
rts
|
||||
|
||||
.OnLaunch
|
||||
ldx SelectedIndex
|
||||
ldx gGameToLaunch
|
||||
cpx #$FF
|
||||
beq .OnError
|
||||
jsr PlayGameFromSearch
|
||||
jsr PlayGame
|
||||
sec ; tell caller to redraw UI
|
||||
rts
|
||||
|
||||
.OnCheat
|
||||
dec SelectedIndex ; force reload (will be reset to correct value in .OnInputChanged)
|
||||
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
|
||||
|
||||
@ -124,7 +124,7 @@ SearchMode
|
||||
bne @findMatchingTitle
|
||||
; no input, reset params and UI
|
||||
lda #$FF
|
||||
sta SelectedIndex ; no game selected
|
||||
sta gGameToLaunch ; no game selected
|
||||
ldx #39 ; copy instructions to line 2
|
||||
- lda Instructions,x
|
||||
sta UILine2,x
|
||||
@ -153,9 +153,9 @@ SearchMode
|
||||
jmp .OnError ; beep and return
|
||||
+
|
||||
ldx BestMatchIndex ; check if the new best match is the same
|
||||
cpx SelectedIndex ; as the current best match
|
||||
cpx gGameToLaunch ; as the current best match
|
||||
php ; (we'll use this later to skip reloading)
|
||||
stx SelectedIndex
|
||||
stx gGameToLaunch
|
||||
+LDADDR gGamesListStore
|
||||
jsr okvs_nth ; get the name of the new best match
|
||||
+STAY @key
|
||||
@ -204,7 +204,7 @@ SearchMode
|
||||
dex
|
||||
bpl -
|
||||
|
||||
ldx SelectedIndex
|
||||
ldx gGameToLaunch
|
||||
jsr BuildUILine1WithNoDots; build UI line 1 with bars and other shapes
|
||||
|
||||
; now add dots to UI line 1 to highlight matched characters
|
||||
@ -225,7 +225,7 @@ SearchMode
|
||||
cpy SAVE ; if game name is exhausted, we're done
|
||||
bne @dotloop
|
||||
@doneHighlight
|
||||
ldx SelectedIndex
|
||||
ldx gGameToLaunch
|
||||
jsr DrawSearchBarOffscreen; actually draw the search UI (offscreen)
|
||||
jmp ShowOtherPage ; now show everything at once
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user