mirror of
https://github.com/a2-4am/4cade.git
synced 2024-09-27 12:57:21 +00:00
179 lines
5.6 KiB
Plaintext
179 lines
5.6 KiB
Plaintext
;license:MIT
|
|
;(c) 2018 by 4am
|
|
;
|
|
; Functions to launch games and self-running demos
|
|
;
|
|
; Public functions
|
|
; - 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)
|
|
|
|
Play
|
|
lda Mode
|
|
bmi @playFromAttract
|
|
@playFromSearch
|
|
lda SelectedIndex
|
|
sta @selectedIndex
|
|
jsr okvs_nth
|
|
!word gGamesListStore
|
|
@selectedIndex
|
|
!byte $FD ; SMC
|
|
jmp Go
|
|
|
|
@playFromAttract
|
|
+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_nth ; get filename of current attract-mode module
|
|
!word gAttractModeStore
|
|
gCurrentAttractIndex
|
|
!byte $FD ; set in AttractMode
|
|
+STAY @key
|
|
jsr okvs_get
|
|
!word gAttractModeStore
|
|
@key !word $FDFD ; SMC
|
|
+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
|
|
jsr okvs_nth
|
|
!word gSlideshowStore
|
|
gCurrentlyVisibleSlideshowIndex
|
|
!byte $FD ; set in HGRTitleCallback, HGRActionCallback, DHGRTitleCallback
|
|
+STAY @sskey
|
|
+STAY @sskey2
|
|
jsr okvs_get
|
|
!word gGamesListStore
|
|
@sskey !word $FDFD ; SMC
|
|
bcs +
|
|
+LDAY @sskey
|
|
jmp Go
|
|
+
|
|
; if the key is not found, try getting the value of the current record
|
|
; from gSlideshowStore and using that instead
|
|
; (some games have multiple action screenshots, value points to the key in gGamesListStore)
|
|
jsr okvs_get
|
|
!word gSlideshowStore
|
|
@sskey2 !word $FDFD ; SMC
|
|
bcc Go
|
|
rts
|
|
Go
|
|
+STAY PTR
|
|
bit $C010 ; forget the key that was pressed
|
|
ldx #1
|
|
sec
|
|
!byte $2c
|
|
-- pha
|
|
clc
|
|
php
|
|
ldy #0
|
|
lda (PTR), y
|
|
tay
|
|
iny
|
|
sty @runlength+1
|
|
ldy #0
|
|
lda #'X'
|
|
sta ProDOS_prefix+1
|
|
lda #'/'
|
|
- inx
|
|
sta ProDOS_prefix, x
|
|
iny
|
|
lda (PTR), y
|
|
@runlength
|
|
cpy #$D1 ; SMC
|
|
bne -
|
|
txa
|
|
plp
|
|
bcs --
|
|
stx ProDOS_prefix
|
|
|
|
+LDADDR ProDOS_prefix
|
|
jsr SetPath
|
|
jsr LoadFile
|
|
|
|
pla
|
|
sta ProDOS_prefix
|
|
|
|
copy_prelaunch
|
|
ldx #(End_Prelaunch-Prelaunch-1)
|
|
- lda Prelaunch,x ; copy pre-launch code to main memory
|
|
sta $100,x
|
|
dex
|
|
bpl -
|
|
ldx #(end_promote-promote-1)
|
|
- lda promote,x ; copy ProDOS shim to main memory
|
|
sta $bf00,x
|
|
dex
|
|
bpl -
|
|
jmp $106 ; jump to pre-launch code
|
|
|
|
;------------------------------------------------------------------------------
|
|
; Prelaunch
|
|
; code to set up machine for running a self-running, self-terminating game demo
|
|
; DO NOT CALL DIRECTLY
|
|
; must be run from main memory
|
|
; contains multiple entry points
|
|
;
|
|
; in: none
|
|
; out: exits via JMP (ldrlo2), which is expected to exit via JMP |Prelaunch|
|
|
; (not here, but wherever it was copied to in main memory) or by
|
|
; manually enabling LC RAM bank 1 then JMP |Reenter|
|
|
;------------------------------------------------------------------------------
|
|
Prelaunch ; this runs from main memory
|
|
; entry point used by some self-running demos
|
|
lda $C088
|
|
jmp Reenter
|
|
|
|
; entry point to launch game
|
|
+READ_ROM_NO_WRITE
|
|
lda ldrlo2 ; set up game entry point in stack page
|
|
ldy ldrhi2 ; (last load address - 1)
|
|
sec
|
|
sbc #$01
|
|
bcs +
|
|
dey
|
|
+
|
|
+STAY $1FE
|
|
ldx #0 ; wipe zero page
|
|
txa
|
|
- sta $00,x
|
|
inx
|
|
bne -
|
|
lda #$65 ; initialize random seed (some games like Pooyan
|
|
sta $4E ; require these to be non-zero)
|
|
lda #$02
|
|
sta $4F
|
|
jsr $FE89 ; initialize machine like a cold boot (many
|
|
jsr $FE93 ; games assume a 'clean slate' and rely on
|
|
jsr $FE84 ; zero page values set by these ROM routines,
|
|
sta $C000 ; e.g. Wavy Navy just prints out text via $FDED
|
|
sta $C002 ; and expects it to work)
|
|
sta $C004
|
|
sta $C00C
|
|
sta $C00E
|
|
jsr $FB2F
|
|
jsr $FC58
|
|
ldx #$FD ; jump to game entry point via stack pop
|
|
txs
|
|
rts
|
|
End_Prelaunch
|