;license:MIT ;(c) 2018 by 4am ; ; Mega Attract Mode - cycle through slideshows and self-running demos ; ; Public functions ; - AttractMode ; ; 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 ;------------------------------------------------------------------------------ ; AttractMode ; 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: exits to caller (note that some attract mode modules never return but ; instead call |Reenter|, in which case this routine technically never ; returns) ; if this routine returns, everything is clobbered (zero page, main ; memory, unused portions of the stack page, all registers, all flags) ;------------------------------------------------------------------------------ AttractMode jsr LoadFile ; load attract-mode configuration file at $8000 !word kAttractModeConfFile 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 AttractMode rts @RunNextAttractModule ldy #1 lda (PTR),y and #$0F bne @Slideshow ; 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 SaveScreenHoles ; save screen hole contents in case game changes them jmp copy_prelaunch @Slideshow ; HGR or DHGR slideshow pha ; save module type (1=HGR title, 2=HGR action, 3=DHGR title) ; 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 SHRArtworkSlideshow 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 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 lda MachineStatus and #SUPPORTS_SHR beq @noSHR lda $C029 and #$7F sta $C029 ; get out of SHR mode @noSHR rts @end