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

213 lines
6.8 KiB
Plaintext

;license:MIT
;(c) 2018-9 by 4am
;
; Mega Attract Mode - cycle through slideshows and self-running demos
;
; Public functions
; - MegaAttractMode
;;;;;; - RunAttractModule
;
; Public variables
; - gAttractIndex ; [byte] numeric index in gAttractModeStore of next Mega-Attract Module
; - gFXIndex ; [byte] numeric index in gFXStore of next HGR transition effect
; - gDFXIndex ; [byte] numeric index in gDFXStore of next DHGR transition effect
;------------------------------------------------------------------------------
; 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)
+LDADDR kAttractModeConfFile
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
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 gAttractIndex
jsr okvs_nth ; get filename of next attract-mode module
!word gAttractModeStore
gAttractIndex
!byte 0
+STAY @key
lda gAttractIndex
sta gCurrentAttractIndex
inc gAttractIndex ; increment module index for next time
jsr okvs_len
!word gAttractModeStore
cmp gAttractIndex
bne +
lda #0
sta gAttractIndex
+
lda gAttractIndex
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
jsr @RunNextAttractModule
lda $C000
bpl @jmpattract
cmp #$8D
bne @jmpsearch
jsr PlayGameFromAttract
@jmpattract
jmp MegaAttractMode
@jmpsearch
jmp SearchMode
@RunNextAttractModule
ldy #1
lda (PTR),y
and #$0F
; jsr RunAttractModule
;------------------------------------------------------------------------------
; RunAttractModule
; run a single attract module of any type and return to caller
;
; in: A = module type (#$01..#$09, see attract.conf)
; gGlobalPrefsStore must be initialized
; out: all flags and registers clobbered
; assume all of main memory has been clobbered
;------------------------------------------------------------------------------
;RunAttractModule
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 ; clear text screen and switch to it during loading
; to avoid seeing executable code load into the HGR page
+LOAD_PATH kDemoDirectory
ldy gPathname
sty ProDOS_prefix
- lda gPathname, y
sta ProDOS_prefix, y
dey
bne -
+LOAD_FILE_IMM @key
jsr SaveOrRestoreScreenHoles ; save screen hole contents in case game changes them
jmp copy_prelaunch
@NotDemo ; slideshow module or screenshot
; cmp #$06 ; 1-5 are slideshow modules
; bcs @Single ; higher values are screenshot modules
pha ; save module type
; load slideshow configuration file at $4000
+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
asl
tax
lda @slideshows-2,x
sta @jmp+1
lda @slideshows-1,x
sta @jmp+2
@jmp jmp $FDFD ; SMC
@slideshows
!word HGRTitleSlideshow
!word HGRActionSlideshow
!word DHGRTitleSlideshow
!word DHGRActionSlideshow
!word SHRArtworkSlideshow
!word 0
; !word HGRSingle
; !word DHGRSingle
; !word SHRSingle
kAttractModeConfFile
!byte @kAttractModeConfFile_e-*-1
!text "ATTRACT.CONF"
@kAttractModeConfFile_e
;------------------------------------------------------------------------------
; internal functions
;------------------------------------------------------------------------------
; Home
; clear and display text screen
;
; in: none
; out: $0106..$011F clobbered
;------------------------------------------------------------------------------
Home
lda MachineStatus
and #SUPPORTS_SHR
beq @noSHR
lda $C035
ora #$08
sta $C035 ; turn off auxmem-to-bank-E1 shadowing
lda $C029
and #$7F
sta $C029 ; get out of SHR mode
@noSHR
ldx #(@end-@start-1)
- lda @start,x
sta $106,x
dex
bpl -
jmp $106
@start
; this will be run from main memory
+READ_ROM_NO_WRITE
sta $C00C ; get out of DHGR mode
sta $C05F ; get out of DHGR mode
jsr $FB2F ; TEXT
jsr $FC58 ; HOME
+READ_RAM1_WRITE_RAM1
rts
@end