4sports/src/glue.launch.a

240 lines
8.0 KiB
Plaintext
Raw Permalink Normal View History

2021-02-16 06:01:22 +00:00
;license:MIT
;(c) 2018-9 by 4am
;
; Functions to launch games and self-running demos
;
; Public functions
2022-08-23 02:04:55 +00:00
; - AnyGameSelected
2021-02-16 06:01:22 +00:00
; - GetGameToLaunch
; - FindGame
; - PlayGame
; - Launch
2022-10-13 03:43:44 +00:00
; - Joystick
; - LoadXSingle
; - LoadStandardPrelaunch
2021-02-16 06:01:22 +00:00
;
; Public variables:
2022-08-23 02:04:55 +00:00
; - gGameToLaunch - 0-based index into gSearchStore (word)
2021-02-16 06:01:22 +00:00
;
gGameToLaunch
!word $FFFF
2022-08-23 02:04:55 +00:00
gLastMegaAttractGame
!word $FFFF
2021-02-16 06:01:22 +00:00
;------------------------------------------------------------------------------
; AnyGameSelected
; get index of game that is currently selected in the UI (if any)
;
; in: none
; out: A/Y = gGameToLaunch (word)
; C clear if gGameToLaunch is not #$FFFF
; C set if gGameToLaunch is #$FFFF
; X preserved
;------------------------------------------------------------------------------
AnyGameSelected
+LD16 gGameToLaunch
2022-08-23 02:04:55 +00:00
+CMP16_NE $FFFF, ForceGoodResult
2021-02-16 06:01:22 +00:00
rts ; CMP sets carry when equal
;------------------------------------------------------------------------------
; GetGameToLaunch
; get filename of game that is currently selected in the UI (if any)
;
2022-08-23 02:04:55 +00:00
; in: gGameToLaunch = index into gSearchStore (word) or #$FFFF if no game selected
; gSearchStore populated
2021-02-16 06:01:22 +00:00
; out: C clear if a game is selected, and
; A/Y points to game filename
; C set if no game is selected
;------------------------------------------------------------------------------
GetGameToLaunch
jsr AnyGameSelected
bcs _gameToLaunchExit
+ST16 WINDEX
2022-08-23 02:04:55 +00:00
+LDADDR gSearchStore
2021-02-16 06:01:22 +00:00
jsr okvs_nth
ForceGoodResult
clc
_gameToLaunchExit
rts
;------------------------------------------------------------------------------
; FindGame
; check if an arbitrary game exists, for some definition of 'exists', while
; in the middle of a slideshow
;
2022-08-23 02:04:55 +00:00
; in: A/Y points to a key in gSlideshowStore
; out: C clear if game exists and is playable on current machine, and
; (SAVE) -> game display name, and
; (gLastMegaAttractGame) -> game filename
; C set otherwise
; clobbers $FF, PTR
; all registers clobbered
2021-02-16 06:01:22 +00:00
;------------------------------------------------------------------------------
2022-08-23 02:04:55 +00:00
FindGame
+ST16 gLastMegaAttractGame
jsr okvs_next_field ; (PTR) -> OKVS value (filename or empty string)
; Y=0
lda (PTR), y
2021-02-16 06:01:22 +00:00
beq +
+LD16 PTR
2022-08-23 02:04:55 +00:00
+ST16 gLastMegaAttractGame
+ jsr okvs_next_field_PTR_is_already_set ; (PTR) -> game display name
+LD16 PTR ; A/Y -> game display name
+ST16 SAVE ; (SAVE) -> game display name
jsr okvs_next_field ; (PTR) -> game requirements bitfield
; Y=0
; check if game requires joystick
lda (PTR), y
sta $FF
bpl @check128K
lda MachineStatus
and #HAS_JOYSTICK
beq @failedCheck ; machine doesn't have joystick but game requires it
@check128K
; check if game requires 128K
bit $FF
bvc @passedAllChecks
lda MachineStatus
and #HAS_128K
beq @failedCheck ; machine doesn't have 128K but game requires it
@passedAllChecks
2021-02-16 06:01:22 +00:00
clc
rts
2022-08-23 02:04:55 +00:00
@failedCheck
sec
2021-02-16 06:01:22 +00:00
rts
;------------------------------------------------------------------------------
; PlayGame
;
; in: gGameToLaunch != #$FFFF
; out: exits via the game, but also backs up the stack, which may get
; restored in |Reenter|... what I'm saying is that we might actually
; 'return' from this after the user is done playing the game, which is
; a neat trick
;------------------------------------------------------------------------------
PlayGame
jsr GetGameToLaunch
2022-10-13 03:43:44 +00:00
; A/Y = address of game filename in gSearchIndex
2022-08-23 02:04:55 +00:00
PlayGameInAY
2021-02-16 06:01:22 +00:00
+ST16 SAVE
+ST16 @pfile
2022-10-13 03:43:44 +00:00
+ST16 xfile
jsr okvs_next_field
jsr okvs_next_field_PTR_is_already_set
; (PTR) -> length-prefixed game info bitfield
; Y = 0
iny ; Y = 1
lda (PTR), y ; A = game info bitfield
and #IS_SINGLE_LOAD
php
2021-02-16 06:01:22 +00:00
jsr ClearScreens ; avoid seeing code load into the HGR page
; (clobbers $106, must do now before loading prelaunch code)
2022-08-23 02:04:55 +00:00
jsr LoadIndexedFile ; load prelaunch index file
2022-10-13 03:43:44 +00:00
- !word gSearchCache ; clobber gSearchCache which we no longer need
2022-08-23 02:04:55 +00:00
!word kPrelaunchIndexRecord
2022-10-13 03:43:44 +00:00
jsr okvs_find ; find this game's prelaunch index record
2022-08-23 02:04:55 +00:00
!word -
@pfile !word $FDFD ; SMC
2022-10-13 03:43:44 +00:00
+ST16 @prelaunchIndexRecordPtr
2022-08-23 02:04:55 +00:00
2022-10-13 03:43:44 +00:00
jsr LoadIndexedFile ; load this game's prelaunch code into $0106
2021-02-16 06:01:22 +00:00
!word $0106
2022-10-13 03:43:44 +00:00
@prelaunchIndexRecordPtr
2022-08-23 02:04:55 +00:00
!word $FDFD ; SMC
2021-02-16 06:01:22 +00:00
2022-10-13 03:43:44 +00:00
plp
beq @loadFromSubdirectory
jsr LoadXSingle_NameIsAlreadySet
jmp Launch
@loadFromSubdirectory
2021-02-16 06:01:22 +00:00
+LD16 SAVE
2024-05-04 03:58:02 +00:00
+ST16 @p
2021-02-16 06:01:22 +00:00
jsr LoadFile ; load the game startup file
!word kGameDirectory
2024-05-04 03:58:02 +00:00
@p !word $FDFD
2021-02-16 06:01:22 +00:00
!word 0 ; use file's default address
2024-05-04 03:58:02 +00:00
lda #1
2021-02-16 06:01:22 +00:00
sta ProDOS_prefix ; set 'root' directory to the path part
; of the game startup file we just loaded
; so games can load other files without
; knowing which directory they're in
; execution falls through here
Launch
jsr SwitchToBank2
lda #$BD
sta launchpatch
jsr saveslot ; set proper slot information
lda #$9D
sta launchpatch
jmp LaunchInternal
2022-10-13 03:43:44 +00:00
;------------------------------------------------------------------------------
; LoadXSingle/LoadXSingle_NameIsAlreadySet/LoadXFile
; load an indexed file via an extended index record that also contains starting
; address information
;
; in: A/Y points to game filename (must be listed in xsingle OKVS)
; out: all flags & registers clobbered
;------------------------------------------------------------------------------
LoadXSingle ; entry point used by demos to load additional resources
+ST16 xfile
LoadXSingle_NameIsAlreadySet ; entry point used by PlayGame
jsr LoadIndexedFile ; load xsingle index file (contains pointers to game binaries)
- !word gSearchCache ; clobber search cache which we no longer need
!word kXSingleRecord
LoadXFile ; entry point used by attract mode to load self-running demo
jsr okvs_find ; find this game's extended index record
!word -
xfile !word $FDFD ; SMC
+ST16 @xsingleIndexRecordPtr
jsr okvs_next_field
ldy #5
lda (PTR), y ; get game load address (stored immediately after index record)
sta @xsingleAddr
iny
lda (PTR), y
sta @xsingleAddr+1
jsr LoadIndexedFile ; load this game binary
@xsingleAddr
!word $FDFD ; SMC
@xsingleIndexRecordPtr
!word $FDFD ; SMC
rts
;------------------------------------------------------------------------------
; Joystick
; launch joystick calibration program
;
; in: none
; out: exits via Launch
;------------------------------------------------------------------------------
2021-02-16 06:01:22 +00:00
Joystick
2022-08-23 02:04:55 +00:00
jsr LoadStandardPrelaunch
2021-02-16 06:01:22 +00:00
2022-08-23 02:04:55 +00:00
jsr LoadIndexedFile
!word $800
!word kJoystickRecord
2021-02-16 06:01:22 +00:00
jmp Launch
2022-08-23 02:04:55 +00:00
LoadStandardPrelaunch
jsr LoadIndexedFile ; load standard prelaunch code at $0106
!word $0106
!word kStandardPrelaunchRecord
rts