4cade/src/ui.attract.mode.a
2019-06-25 22:44:39 -04:00

178 lines
6.2 KiB
Plaintext

;license:MIT
;(c) 2018-9 by 4am
;
; Mega Attract Mode - cycle through slideshows and self-running demos
;
; Public functions
; - MegaAttractMode
; - RunAttractModule
; - LoadAndParseAttractModeConf
;------------------------------------------------------------------------------
; MegaAttractMode
; main entry point for Mega Attract Mode, which cycles through modules listed
; in ATTRACT.CONF to provide pretty visual effects and snippets of self-running
; self-terminating game demos
;
; in: gGlobalPrefsStore must be initialized
; out: never returns to caller (may JMP to other major modes)
;------------------------------------------------------------------------------
MegaAttractMode
ldx #$FF
txs
jsr BlankHGR ; switch to HGR page 1 (once cleared)
jsr LoadAndParseAttractModeConf
jsr okvs_get ; get next attract-mode module from prefs
!word gGlobalPrefsStore
!word kNextAttract
bcs @noattract
+STAY @attract
jsr okvs_get
!word gAttractModeStore
@attract !word $FDFD ; SMC
bcc +
@noattract
ldx #0
+ stx @attractIndex
jsr okvs_nth ; get filename of next attract-mode module
!word gAttractModeStore
@attractIndex
!byte 0
+STAY @key
lda @attractIndex
sta gCurrentAttractIndex
inc @attractIndex ; increment module index for next time
jsr okvs_len
!word gAttractModeStore
cmp @attractIndex
bne +
lda #0
sta @attractIndex
+
lda @attractIndex
sta @nexti
jsr okvs_nth ; get name of next attract-mode module
!word gAttractModeStore
@nexti !byte $FD ; SMC
+STAY @nextattract
jsr okvs_update ; save name of next attract-mode module in prefs store
!word gGlobalPrefsStore
!word kNextAttract
@nextattract
!word $FDFD ; SMC
jsr SaveGlobalPreferences ; write prefs store to disk
jsr okvs_get
!word gAttractModeStore
@key !word $FDFD ; SMC
+STAY PTR
ldy #1
lda (PTR),y
and #$0F ; convert ASCII digit to integer
tax ; X = module type
+LDAY @key ; A/Y = address of module name
jsr RunAttractModule
lda $C000
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.
@jmpattract
jmp MegaAttractMode
@jmpsearch
jmp SearchMode
;------------------------------------------------------------------------------
; RunAttractModule
; run a single attract module of any type and return to caller
;
; in: X = module type (1-9, 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
+STAY @key
txa
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.
jsr Home ; avoid seeing code load into the HGR page
+LOAD_PATH kDemoDirectory
ldy gPathname
sty ProDOS_prefix ; temporarily set 'root' directory to
- lda gPathname, y ; /demos/ directory so demos can can load
sta ProDOS_prefix, y ; other resources in the same directory
dey
bne -
+LOAD_FILE_IMM @key ; load self-running demo (address varies)
jsr SaveOrRestoreScreenHoles ; save screen hole contents
jmp Launch ; will return to caller via |Reenter|
; not a demo, so maybe a slideshow or single screenshot
@NotDemo
cmp #$06 ; 1-5 are slideshow modules
bcs @startDispatch
; it's a slideshow, so load slideshow configuration file at $4000
pha ; save module type
+LOAD_FILE kAttractModeSlideshowDirectory, @key
jsr ParseKeyValueList ; parse slideshow configuration into an OKVS data structure at $0800
!word gSlideshowStore
!word ldrlo2 ; (ldrlo2) points to address of last loaded file, so $4000
!byte 0
pla ; restore module type
@startDispatch
asl
tax
lda @slideshows-2,x
sta @jmp+1
lda @slideshows-1,x
sta @jmp+2
+LDAY @key ; pass in module name
@jmp jmp $FDFD ; SMC
@key !word $FDFD ; SMC
@slideshows
!word HGRTitleSlideshow
!word HGRActionSlideshow
!word DHGRTitleSlideshow
!word DHGRActionSlideshow
!word SHRSlideshow
!word 0
!word HGRSingle
!word DHGRSingle
!word SHRSingle
LoadAndParseAttractModeConf
+LDADDR @AttractModeConfFile
jsr SetPath
jsr LoadFile ; load attract-mode configuration file at $8000
jsr ParseKeyValueList ; parse attract-mode configuration into OKVS data structure at $6000
!word gAttractModeStore
!word ldrlo2 ; (ldrlo2) points to last load address, so $8000
!byte 0
rts
@AttractModeConfFile
!byte 12
!text "ATTRACT.CONF"