2019-01-15 00:06:58 +00:00
|
|
|
;license:MIT
|
2019-06-24 02:32:18 +00:00
|
|
|
;(c) 2018-9 by 4am
|
2019-01-15 00:06:58 +00:00
|
|
|
;
|
|
|
|
; Functions to launch games and self-running demos
|
|
|
|
;
|
|
|
|
; Public functions
|
2021-10-28 05:28:20 +00:00
|
|
|
; - AnyGameSelected
|
2019-10-08 18:43:41 +00:00
|
|
|
; - GetGameToLaunch
|
2020-03-18 16:08:39 +00:00
|
|
|
; - FindGame
|
|
|
|
; - FindGameInActionSlideshow
|
2019-09-21 03:26:32 +00:00
|
|
|
; - PlayGame
|
2019-06-26 02:44:39 +00:00
|
|
|
; - Launch
|
2019-01-15 00:06:58 +00:00
|
|
|
;
|
2019-09-24 22:40:43 +00:00
|
|
|
; Public variables:
|
2021-11-03 01:49:41 +00:00
|
|
|
; - gGameToLaunch - 0-based index into gSearchStore (word)
|
2019-09-24 22:40:43 +00:00
|
|
|
;
|
2019-01-15 00:06:58 +00:00
|
|
|
|
2020-03-24 20:30:14 +00:00
|
|
|
gGameToLaunch
|
2020-05-30 14:53:29 +00:00
|
|
|
!word $FFFF
|
2021-11-03 01:49:41 +00:00
|
|
|
gLastMegaAttractGame
|
|
|
|
!word $FFFF
|
2020-03-24 20:30:14 +00:00
|
|
|
|
2020-03-31 23:19:45 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; AnyGameSelected
|
|
|
|
; get index of game that is currently selected in the UI (if any)
|
|
|
|
;
|
2020-03-24 20:30:14 +00:00
|
|
|
; in: none
|
|
|
|
; out: A/Y = gGameToLaunch (word)
|
|
|
|
; C clear if gGameToLaunch is not #$FFFF
|
|
|
|
; C set if gGameToLaunch is #$FFFF
|
|
|
|
; X preserved
|
2020-03-31 23:19:45 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
AnyGameSelected
|
2020-03-24 20:30:14 +00:00
|
|
|
+LD16 gGameToLaunch
|
2021-10-13 22:58:26 +00:00
|
|
|
+CMP16_NE $FFFF, ForceGoodResult
|
2020-05-30 15:14:04 +00:00
|
|
|
rts ; CMP sets carry when equal
|
2020-03-24 20:30:14 +00:00
|
|
|
|
2020-03-31 23:19:45 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; GetGameToLaunch
|
|
|
|
; get filename of game that is currently selected in the UI (if any)
|
|
|
|
;
|
2021-10-28 05:28:20 +00:00
|
|
|
; in: gGameToLaunch = index into gSearchStore (word) or #$FFFF if no game selected
|
|
|
|
; gSearchStore populated
|
2020-03-24 20:30:14 +00:00
|
|
|
; out: C clear if a game is selected, and
|
|
|
|
; A/Y points to game filename
|
|
|
|
; C set if no game is selected
|
2020-03-31 23:19:45 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
GetGameToLaunch
|
2020-03-24 20:30:14 +00:00
|
|
|
jsr AnyGameSelected
|
2020-05-30 15:14:04 +00:00
|
|
|
bcs _gameToLaunchExit
|
2020-03-24 20:30:14 +00:00
|
|
|
+ST16 WINDEX
|
2021-10-28 05:28:20 +00:00
|
|
|
+LDADDR gSearchStore
|
2020-03-24 20:30:14 +00:00
|
|
|
jsr okvs_nth
|
2020-05-30 15:14:04 +00:00
|
|
|
ForceGoodResult
|
2020-03-24 20:30:14 +00:00
|
|
|
clc
|
2020-05-30 15:14:04 +00:00
|
|
|
_gameToLaunchExit
|
|
|
|
rts
|
2019-10-08 18:43:41 +00:00
|
|
|
|
2020-03-31 23:19:45 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; FindGameInActionSlideshow
|
|
|
|
; check if an arbitrary game exists, for some definition of 'exists', while
|
|
|
|
; in the middle of a slideshow
|
|
|
|
;
|
2021-10-27 17:06:04 +00:00
|
|
|
; in: A/Y points to a key in gSlideshowStore
|
2021-11-03 01:49:41 +00:00
|
|
|
; 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
|
2020-03-31 23:19:45 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
FindGameInActionSlideshow
|
2021-11-03 01:49:41 +00:00
|
|
|
+ST16 gLastMegaAttractGame
|
2021-11-09 17:41:15 +00:00
|
|
|
jsr okvs_next_field ; (PTR) -> OKVS value (filename or empty string)
|
2021-11-03 01:49:41 +00:00
|
|
|
; Y=0
|
|
|
|
lda (PTR), y
|
|
|
|
beq +
|
2020-03-24 20:30:14 +00:00
|
|
|
+LD16 PTR
|
2021-11-03 01:49:41 +00:00
|
|
|
+ST16 gLastMegaAttractGame
|
2021-11-09 17:41:15 +00:00
|
|
|
+ jsr okvs_next_field_PTR_is_already_set ; (PTR) -> game display name
|
2021-11-03 01:49:41 +00:00
|
|
|
+LD16 PTR ; A/Y -> game display name
|
|
|
|
+ST16 SAVE ; (SAVE) -> game display name
|
|
|
|
FindGame
|
2021-11-09 17:41:15 +00:00
|
|
|
jsr okvs_next_field ; (PTR) -> game requirements bitfield
|
2021-11-03 01:49:41 +00:00
|
|
|
; 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
|
|
|
|
clc
|
|
|
|
rts
|
|
|
|
|
|
|
|
@failedCheck
|
|
|
|
sec
|
2020-03-18 16:08:39 +00:00
|
|
|
rts
|
|
|
|
|
2020-03-31 23:19:45 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; 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
|
|
|
|
;------------------------------------------------------------------------------
|
2019-09-21 03:26:32 +00:00
|
|
|
PlayGame
|
2019-10-08 18:43:41 +00:00
|
|
|
jsr GetGameToLaunch
|
2019-09-16 01:35:34 +00:00
|
|
|
; A/Y = address of game filename
|
2021-11-03 01:49:41 +00:00
|
|
|
PlayGameInAY
|
2020-03-24 20:30:14 +00:00
|
|
|
+ST16 SAVE
|
|
|
|
+ST16 @pfile
|
2019-09-18 18:04:41 +00:00
|
|
|
|
2019-10-10 01:02:46 +00:00
|
|
|
jsr ClearScreens ; avoid seeing code load into the HGR page
|
|
|
|
; (clobbers $106, must do now before loading prelaunch code)
|
2019-09-15 02:57:52 +00:00
|
|
|
|
2021-10-13 22:58:45 +00:00
|
|
|
jsr LoadFile ; load prelaunch index file into $6000
|
|
|
|
!word kRootDirectory
|
|
|
|
!word kPrelaunchIndexFile
|
|
|
|
- !word $6000
|
|
|
|
|
|
|
|
jsr okvs_find
|
|
|
|
!word -
|
|
|
|
@pfile !word $FDFD ; SMC
|
|
|
|
+ST16 @indexRecordPtr
|
|
|
|
|
|
|
|
jsr LoadIndexedFile
|
|
|
|
!word kPrelaunchFulFile
|
2019-09-15 21:55:16 +00:00
|
|
|
!word $0106
|
2021-10-13 22:58:45 +00:00
|
|
|
@indexRecordPtr
|
|
|
|
!word $FDFD ; SMC
|
2019-09-15 02:57:52 +00:00
|
|
|
|
2019-10-09 04:25:10 +00:00
|
|
|
; we start by placing the subdirectory name at gPathname+kGameDirectoryLen
|
|
|
|
; to leave room for the GameDirectory name as the parent
|
|
|
|
|
|
|
|
lda #kGameDirectoryLen
|
|
|
|
sta gPathname
|
2020-03-24 20:30:14 +00:00
|
|
|
+LD16 SAVE
|
2019-10-09 04:25:10 +00:00
|
|
|
jsr AddToPath
|
|
|
|
|
|
|
|
; attach the separator
|
|
|
|
|
|
|
|
inc gPathname
|
|
|
|
lda #'/'
|
|
|
|
sta gPathname+1,x
|
2019-01-15 00:06:58 +00:00
|
|
|
|
2019-10-09 17:00:33 +00:00
|
|
|
; then we save the length of the resulting string without the count byte
|
|
|
|
|
|
|
|
dex
|
|
|
|
txa
|
|
|
|
pha
|
|
|
|
|
2019-10-09 04:25:10 +00:00
|
|
|
; then attach the game name
|
|
|
|
|
2020-03-24 20:30:14 +00:00
|
|
|
+LD16 SAVE
|
2019-10-09 04:25:10 +00:00
|
|
|
jsr AddToPath
|
|
|
|
|
|
|
|
; don't look while I do this
|
|
|
|
; we "place" a string at gPathname+kGameDirectoryLen
|
|
|
|
; whose length is the subdirectory name and game name
|
|
|
|
; then we load it
|
|
|
|
; the load sets the path to the GameDirectory
|
|
|
|
; and then finds the subdirectory name and game name right after it
|
|
|
|
; and attaches it to the path by overwriting the count byte
|
|
|
|
|
2019-11-27 21:51:43 +00:00
|
|
|
;;sec ; carry set by AddToPath
|
2019-10-09 04:25:10 +00:00
|
|
|
lda gPathname
|
|
|
|
sbc #kGameDirectoryLen
|
|
|
|
sta gPathname+kGameDirectoryLen
|
2019-06-26 02:44:39 +00:00
|
|
|
jsr LoadFile ; load the game startup file
|
2019-10-09 04:25:10 +00:00
|
|
|
!word kGameDirectory
|
|
|
|
!word gPathname+kGameDirectoryLen
|
2019-09-10 02:38:17 +00:00
|
|
|
!word 0 ; use file's default address
|
2019-01-15 00:06:58 +00:00
|
|
|
|
2019-06-21 23:47:05 +00:00
|
|
|
pla
|
2019-06-26 02:44:39 +00:00
|
|
|
sta ProDOS_prefix ; set 'root' directory to the path part
|
|
|
|
; of the game startup file we just loaded
|
2019-09-10 02:38:17 +00:00
|
|
|
; so games can load other files without
|
2019-06-26 02:44:39 +00:00
|
|
|
; knowing which directory they're in
|
2019-01-15 00:06:58 +00:00
|
|
|
|
2019-06-26 02:44:39 +00:00
|
|
|
; execution falls through here
|
|
|
|
Launch
|
2019-09-20 13:33:23 +00:00
|
|
|
jsr SwitchToBank2
|
2020-05-23 22:47:16 +00:00
|
|
|
lda #$BD
|
|
|
|
sta launchpatch
|
|
|
|
jsr saveslot ; set proper slot information
|
|
|
|
lda #$9D
|
|
|
|
sta launchpatch
|
2019-09-24 22:40:43 +00:00
|
|
|
jmp LaunchInternal
|
2020-06-15 16:44:46 +00:00
|
|
|
|
|
|
|
Joystick
|
2021-10-13 22:58:45 +00:00
|
|
|
jsr LoadStandardPrelaunch
|
2020-06-15 16:44:46 +00:00
|
|
|
|
|
|
|
jsr LoadFile
|
|
|
|
!word kRootDirectory
|
|
|
|
!word kJoystickFile
|
|
|
|
!word 0
|
|
|
|
|
|
|
|
jmp Launch
|
2021-10-13 22:58:45 +00:00
|
|
|
|
|
|
|
LoadStandardPrelaunch
|
|
|
|
jsr LoadIndexedFile ; load standard prelaunch code at $0106
|
|
|
|
!word kPrelaunchFulFile
|
|
|
|
!word $0106
|
|
|
|
!word +
|
|
|
|
rts
|
|
|
|
+ !byte 0
|
|
|
|
!be24 0
|
2021-10-29 19:59:35 +00:00
|
|
|
!le16 PRELAUNCH_STANDARD_SIZE
|