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

228 lines
8.0 KiB
Plaintext

;license:MIT
;(c) 2018-9 by 4am
;
; Attract Mode - cycle through slideshows and self-running demos
;
; Public functions
; - MegaAttractMode
; - MiniAttractMode
; - RunAttractModule
;------------------------------------------------------------------------------
; MegaAttractMode
; main entry point for Mega Attract Mode, which endlessly cycles through
; modules listed in ATTRACT.CONF to display title pages, action screenshots,
; super hi-res box art (on supporting platforms), and self-running game demos
;
; in: gGlobalPrefsStore must be initialized
; out: never returns to caller (may JMP to other major modes)
;------------------------------------------------------------------------------
MegaAttractMode
jsr SwitchToBank1
ldx #$FF
txs
jsr BlankHGR ; switch to HGR page 1 (once cleared)
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
!word gAttractModeStore
+ST16 @mname ; A/Y = module name
; $WINDEX = index of module in attract store
+LDADDR gAttractModeStore
jsr okvs_next ; get module after this one
+ST16 +
jsr pref_set ; update prefs store and save to disk
!word kNextAttract
+ !word $FDFD ; SMC
jsr okvs_get
!word gAttractModeStore
@mname !word $FDFD ; SMC
+ST16 PTR
ldy #1
lda (PTR),y
tax ; X = module type
+LD16 @mname ; A/Y = address of module name
jsr RunAttractModule
lda KBD
bpl MegaAttractMode
cmp #$8D ; Enter plays the game shown on screen.
bne + ; Any other key switches to Search Mode.
jsr PlayGame ; (might return if user hits Ctrl-Reset)
+ jmp SearchMode
;------------------------------------------------------------------------------
; MiniAttractMode
; run attract modules related to one game
;
; in: gGameToLaunch = index in gGamesListStore (word)
; out: all flags and registers clobbered
; assume all of main memory has been clobbered
;------------------------------------------------------------------------------
MiniAttractMode
jsr GetGameToLaunch
+ST16 +
jsr BlankHGR
; X = 0
stx MiniAttractIndex
stx MiniAttractIndex+1
@loop
jsr LoadFile ; load mini attract mode configuration file into $8000
!word kMiniAttractDirectory
+ !word $FDFD ; SMC
- !word $8000
jsr ParseKeyValueList ; parse configuration into OKVS data structure at $6000
!word gAttractModeStore
!word -
!byte 0
+LDADDR gAttractModeStore
jsr okvs_len
lda WCOUNT
cmp MiniAttractIndex
bne +
lda WCOUNT+1
cmp MiniAttractIndex+1
beq ATTRTS ; we've run through all modules, so exit to caller
+
+LD16 MiniAttractIndex
+ST16 WINDEX
+LDADDR gAttractModeStore
jsr okvs_nth ; get the next module on the list
+ST16 SAVE
jsr okvs_get_current ; get module type
ldy #1
lda (PTR),y
tax ; X = module type
+LD16 SAVE ; A/Y = address of module name
jsr RunAttractModule ; execute the module
inc MiniAttractIndex
bne +
inc MiniAttractIndex+1
+
lda KBD
bpl @loop
ATTRTS rts
MiniAttractIndex
!word 0 ; SMC
;------------------------------------------------------------------------------
; RunAttractModule
; run a single attract module of any type and return to caller
;
; in: X = module type as ASCII char (1-6,A-C, see attract.conf)
; A/Y = address of module name
; for demos, this is the filename of an executable in /demo/
; for slideshows, this is the filename of a .conf file in /ss/
; for singles, this is a pathname of the graphic to load
; gGlobalPrefsStore must be initialized (if we load a transition effect
; of any kind, we will update the global prefs with the next one)
; out: all flags and registers clobbered
; assume all of main memory has been clobbered
;------------------------------------------------------------------------------
RunAttractModule
+ST16 @key
+ST16 @key2
cpx #$30
bne @NotDemo
; Self-running demos are loaded into main memory and executed.
; Each binary has been patched to quit on any key and jump back
; to the |Reenter| entry point.
; All demos are strictly 48K / main memory. No demo uses the
; language card or auxiliary memory.
+LD16 @key
jsr FindGame
bcs ATTRTS ; if game doesn't exist, skip the demo
+LD16 WINDEX
+CMP16 $FFFF
beq +
+ST16 gGameToLaunch ; if this demo corresponds to a game, save its index
; in case user presses RETURN during the demo (we will launch the game)
+
jsr ClearScreens ; avoid seeing code load into the HGR page
; (clobbers $106, must do now before loading prelaunch code)
jsr LoadFile ; load standard prelaunch code (|Launch| will call it)
!word kPrelaunchDirectory
!word kStandardPrelaunch
!word $0106
jsr LoadFile ; load self-running demo into its default address (varies)
!word kDemoDirectory
@key !word $FDFD
!word 0
jmp Launch ; will return to caller via |Reenter|
; not a demo, so maybe a slideshow or single screenshot
@NotDemo
txa
cmp #$41 ; numbers are slideshow modules,
bcs @dispatchSingle ; letters are single files
; it's a slideshow, so load and parse slideshow configuration file
pha ; save module type
jsr LoadFile ; load slideshow configuration file into $4000
!word kAttractModeSlideshowDirectory
@key2 !word $FDFD ; SMC
- !word $4000
jsr ParseKeyValueList ; parse into an OKVS data structure at $0800
!word gSlideshowStore
!word -
!byte 0
pla ; restore module type
- and #$0F ; convert ASCII digit to int
tax
lda @slideshowslo-1,x
sta @jmp+1
lda @slideshowshi-1,x
sta @jmp+2
+LD16 @key ; pass in module name
@jmp jmp $FDFD ; SMC
@dispatchSingle
adc #(@singleslo-@slideshowslo)-1
bne - ; always branches
@slideshowslo
!byte <HGRTitleSlideshow
!byte <HGRActionSlideshow
!byte <DHGRTitleSlideshow
!byte <DHGRActionSlideshow
!byte <SHRSlideshow
!byte <GRActionSlideshow
@singleslo
!byte <HGRSingle
!byte <DHGRSingle
!byte <SHRSingle
!byte <GRSingle
@slideshowshi
!byte >HGRTitleSlideshow
!byte >HGRActionSlideshow
!byte >DHGRTitleSlideshow
!byte >DHGRActionSlideshow
!byte >SHRSlideshow
!byte >GRActionSlideshow
@singleshi
!byte >HGRSingle
!byte >DHGRSingle
!byte >SHRSingle
!byte >GRSingle