4cade/src/glue.launch.a

171 lines
5.6 KiB
Plaintext
Raw Normal View History

2019-01-15 00:06:58 +00:00
;license:MIT
;(c) 2018-9 by 4am
2019-01-15 00:06:58 +00:00
;
; Functions to launch games and self-running demos
;
; Public functions
; - GetGameDisplayName
2019-09-22 02:25:34 +00:00
; - GetGameDisplayNameInActionSlideshow
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
;
GetGameDisplayName
; in: A/Y points to game filename
; out: C clear if game exists in gGamesListStore, and
; A/Y points to game display name (but see hack notes below)
2019-09-21 03:26:32 +00:00
; X = game index, or #$FF if the game doesn't really exist but
; we want to return a successful result anyway (really, read the
; hack notes, they're important)
; C set if game does not exist (this can happen because slideshows
; list games that require a joystick, but the games list parser
; filters out joystick-only games if the machine doesn't have a
; joystick)
2019-09-22 02:25:34 +00:00
ldx #$60
+HIDE_NEXT_2_BYTES
GetGameDisplayNameInActionSlideshow
ldx #$EA
stx @maybeExit
+STAY @key
+STAY @slideshowKey
jsr okvs_get
!word gGamesListStore
@key !word $FDFD ; SMC
bcc @exit
; Hack to allow self-running demos that don't correspond to a game
; filename. If the name ends in a '.', accept it unconditionally.
; The filename is its own display name. Launching this fake game
; will of course fail, so don't do that.
+LDAY @key
+STAY PARAM
ldy #0
lda (PARAM),y
tay
lda (PARAM),y
cmp #"."
beq @forceGoodResult
sec
@maybeExit
!byte $00 ; SMC
; if the key is still not found, AND the caller said to try this, then try
; getting the value of the current record from gSlideshowStore
; (some games have multiple action screenshots, in which case the filename of
; the action screenshot is not the game name, but the value is)
jsr okvs_get
!word gSlideshowStore
@slideshowKey
!word $FDFD ; SMC
+STAY @key3
jsr okvs_get
!word gGamesListStore
@key3 !word $FDFD ; SMC
; note that the game might still not be found (C will be set by okvs_get),
; which can happen if the game can't be played due to memory or joystick
; requirements
rts
@forceGoodResult
+LDAY @key
2019-09-21 03:26:32 +00:00
ldx #$FF
clc
@exit rts
2019-09-21 03:26:32 +00:00
PlayGame
gGameToLaunch=*+1
ldx #$FF ; SMC
2019-09-20 23:27:16 +00:00
+LDADDR gGamesListStore
2019-06-20 18:18:23 +00:00
jsr okvs_nth
2019-09-16 01:35:34 +00:00
; A/Y = address of game filename
2019-09-15 02:57:52 +00:00
+STAY SAVE
2019-09-24 20:01:03 +00:00
+STAY @pfile ; assume we're loading a game-specific prelaunch file
jsr Home ; clear screen (clobbers $106, must do now before loading prelaunch code)
lda #$20 ; clear both hi-res pages
sta @clear+2 ; (in case game loader shows them, we don't want
ldx #$40 ; to flash previous bits of the launcher UI)
ldy #$00
tya
2019-09-21 03:26:32 +00:00
@clear sta $FD00,y ; SMC
iny
bne @clear
inc @clear+2
dex
bne @clear
2019-09-15 02:57:52 +00:00
bit gCheatsEnabled ; are cheats enabled?
bpl @noCheats
2019-09-16 01:35:34 +00:00
2019-09-21 03:43:31 +00:00
ldx gGameToLaunch
ldy gCheatsAvailable,x ; are there any cheats for this game?
2019-09-24 00:01:42 +00:00
bne @Cheats
@noCheats
2019-09-24 19:57:43 +00:00
+LDADDR kStandardPrelaunch ; no game-specific prelaunch file, so
+STAY @pfile ; load standard prelaunch file instead
2019-09-24 00:01:42 +00:00
@Cheats
2019-09-24 20:01:03 +00:00
jsr LoadFile ; if cheats are enabled and this game has a prelaunch
!word kPrelaunchDirectory ; file that will set up the cheats, load that, otherwise
@pfile !word $FDFD ; load the standard prelaunch file
!word $0106
2019-09-15 02:57:52 +00:00
2019-06-26 02:44:39 +00:00
ldx #1 ; construct path to game's startup file
sec ; which is always /X/game/game
2019-06-21 23:47:05 +00:00
!byte $2c
-- pha
clc
2019-01-15 00:06:58 +00:00
php
ldy #0
2019-09-15 02:57:52 +00:00
lda (SAVE), y
2019-01-15 00:06:58 +00:00
tay
iny
sty MAX
2019-01-15 00:06:58 +00:00
ldy #0
lda #'X'
sta ProDOS_prefix+1
lda #'/'
- inx
sta ProDOS_prefix, x
iny
2019-09-15 02:57:52 +00:00
lda (SAVE), y
cpy MAX
2019-01-15 00:06:58 +00:00
bne -
2019-06-21 23:47:05 +00:00
txa
2019-01-15 00:06:58 +00:00
plp
bcs --
stx ProDOS_prefix
2019-06-26 02:44:39 +00:00
jsr LoadFile ; load the game startup file
2019-09-10 02:38:17 +00:00
!word kRootDirectory
!word ProDOS_prefix
!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
jsr SwitchToBank2
2019-09-10 16:51:04 +00:00
jsr SaveOrRestoreScreenHoles ; save screen hole contents
2019-09-20 19:42:02 +00:00
ldy #$F1
- lda $100,y
sta $DF00,y ; back up stack
iny
bne -
2019-06-26 02:44:39 +00:00
tsx ; back up stack pointer
2019-09-10 17:50:36 +00:00
stx $DFF0
2019-06-26 02:44:39 +00:00
lda #$38 ; 'sec' opcode to tell |Reenter| to
sta RestoreStackNextTime ; restore the stack and stack pointer
2019-01-15 00:06:58 +00:00
ldx #(end_promote-promote-1)
- lda promote,x ; copy ProDOS shim to main memory
sta $bf00,x
dex
bpl -
2019-09-20 19:42:02 +00:00
tya
ldy #$18
- sta $bf57,y
dey
bne -
2019-01-15 00:06:58 +00:00
jmp $106 ; jump to pre-launch code