mirror of
https://github.com/a2-4am/pitch-dark.git
synced 2024-09-27 04:54:48 +00:00
173 lines
6.0 KiB
Plaintext
173 lines
6.0 KiB
Plaintext
;license:MIT
|
|
;(c) 2018 by 4am
|
|
;
|
|
; glue code to load, set up, and launch the On Beyond Z-Machine! interpreter
|
|
;
|
|
; Public functions
|
|
; - LaunchInterpreterWithNewGame
|
|
; - LaunchInterpreterWithGame
|
|
; - LaunchInterpreterWithHints
|
|
;
|
|
|
|
kHintsRootDirectory ; length-prefixed pathname of hint files
|
|
!byte 6
|
|
!raw "HINTS/"
|
|
|
|
kOnBeyondOptionsStruct = $0300
|
|
kOnBeyondColumns = $0300
|
|
kOnBeyondCase = $0301
|
|
kOnBeyondAutoRestore = $0302
|
|
kOnBeyondScriptToFile = $0303
|
|
kOnBeyondAutoScript = $0304
|
|
kOnBeyondWarnMissing = $0305
|
|
kOnBeyondChecksum = $0306
|
|
|
|
;------------------------------------------------------------------------------
|
|
; LaunchInterpreterWithNewGame/LaunchInterpreterWithGame
|
|
; load interpreter and launch it with a game based on global preferences store,
|
|
; and optionally tell it to restore from a specific saved game slot
|
|
; in: A = saved game slot, or #$FF for none
|
|
; in: current ProDOS prefix is the same as the PITCH.DARK file
|
|
; out: returns with C set if interpreter could not be loaded or game
|
|
; directory could not be found
|
|
; otherwise does not return (calls ExitWeeGUI and jumps to interpreter)
|
|
; gPathname clobbered
|
|
;------------------------------------------------------------------------------
|
|
LaunchInterpreterWithNewGame
|
|
lda #$FF
|
|
; execution falls through here
|
|
LaunchInterpreterWithGame
|
|
sta kOnBeyondAutoRestore
|
|
jsr SaveGlobalPreferences
|
|
jsr LoadInterpreter
|
|
bcc +
|
|
jmp SoftBell
|
|
+ jsr SetStartupPathToCurrentVersionOfCurrentGame
|
|
jsr ExitWeeGUI ; shut down WeeGUI
|
|
jsr SetInterpreterOptions ; set options struct at $300
|
|
jmp kSystemAddress ; exit via interpreter
|
|
|
|
;------------------------------------------------------------------------------
|
|
; LaunchInterpreterWithHints
|
|
; load interpreter and launch it with the hints file for the current game
|
|
;
|
|
; in: current ProDOS prefix is the same as the PITCH.DARK file
|
|
; out: returns with C set if interpreter could not be loaded or hints
|
|
; directory could not be found
|
|
; otherwise does not return (calls ExitWeeGUI and jumps to interpreter)
|
|
; gPathname clobbered
|
|
;------------------------------------------------------------------------------
|
|
LaunchInterpreterWithHints
|
|
lda #$FF
|
|
sta kOnBeyondAutoRestore ; no saved game to restore
|
|
jsr SaveGlobalPreferences
|
|
jsr LoadInterpreter
|
|
bcc +
|
|
jmp SoftBell
|
|
+ jsr ResetPath
|
|
+LDADDR kHintsRootDirectory
|
|
jsr AddToPath
|
|
jsr okvs_get
|
|
!word gGlobalPrefsStore
|
|
!word kLastPlayed
|
|
jsr AddToPath
|
|
+LDADDR gPathname
|
|
jsr SetStartupPath ; store hints path+filename at $2006
|
|
jsr ExitWeeGUI ; shut down WeeGUI
|
|
jsr SetInterpreterOptionsExceptForce40 ; set options struct at $300, but force 80 columns
|
|
jmp kSystemAddress ; exit via interpreter
|
|
|
|
;------------------------------------------------------------------------------
|
|
; internal functions
|
|
|
|
;------------------------------------------------------------------------------
|
|
; SetInterpreterOptions
|
|
; set options struct based on global preferences store
|
|
;
|
|
; in: kOnBeyondAutoRestore already set (save slot 0-7, or #$FF if none)
|
|
; out: all registers and flags clobbered
|
|
;------------------------------------------------------------------------------
|
|
SetInterpreterOptions
|
|
jsr okvs_get
|
|
!word gGlobalPrefsStore
|
|
!word kForce40
|
|
jsr okvs_as_boolean
|
|
beq SetInterpreterOptionsExceptForce40
|
|
lda #$CE
|
|
+HIDE_NEXT_2_BYTES
|
|
; execution falls through here
|
|
;------------------------------------------------------------------------------
|
|
; SetInterpreterOptionsExceptForce40
|
|
; set options struct based on global preferences store, except always specify
|
|
; 80-column mode (used to launch hint files)
|
|
;
|
|
; in: none
|
|
; out: all registers and flags clobbered
|
|
;------------------------------------------------------------------------------
|
|
SetInterpreterOptionsExceptForce40
|
|
lda #$D9
|
|
sta kOnBeyondColumns
|
|
|
|
jsr okvs_get
|
|
!word gGlobalPrefsStore
|
|
!word kForceUpper
|
|
jsr okvs_as_boolean
|
|
beq +
|
|
lda #0
|
|
+HIDE_NEXT_2_BYTES
|
|
+ lda #1
|
|
sta kOnBeyondCase
|
|
|
|
jsr okvs_get
|
|
!word gGlobalPrefsStore
|
|
!word kScriptToFile
|
|
jsr okvs_as_boolean
|
|
beq +
|
|
lda #1
|
|
+HIDE_NEXT_2_BYTES
|
|
+ lda #0
|
|
sta kOnBeyondScriptToFile
|
|
|
|
jsr okvs_get
|
|
!word gGlobalPrefsStore
|
|
!word kAutoScript
|
|
jsr okvs_as_boolean
|
|
beq +
|
|
lda #1
|
|
+HIDE_NEXT_2_BYTES
|
|
+ lda #0
|
|
sta kOnBeyondAutoScript
|
|
|
|
lda #0 ; never warn, YOLO
|
|
sta kOnBeyondWarnMissing
|
|
|
|
lda #$A5
|
|
eor kOnBeyondColumns
|
|
eor kOnBeyondCase
|
|
eor kOnBeyondAutoRestore ; caller must have set this already
|
|
eor kOnBeyondScriptToFile
|
|
eor kOnBeyondAutoScript
|
|
eor kOnBeyondWarnMissing
|
|
sta kOnBeyondChecksum
|
|
rts
|
|
|
|
;------------------------------------------------------------------------------
|
|
; LoadInterpreter
|
|
; load interpreter and launch it with the hints file for the current game
|
|
;
|
|
; in: current ProDOS prefix is the same as the ONBEYOND.SYSTEM file
|
|
; out: C clear if success
|
|
; C set if interpreter could not be loaded
|
|
; all other registers and flags clobbered
|
|
;------------------------------------------------------------------------------
|
|
LoadInterpreter
|
|
jsr LoadFile
|
|
!word kInterpreterFilename
|
|
!word kSystemAddress
|
|
!word kProDOSFileBuffer
|
|
rts
|
|
|
|
kInterpreterFilename
|
|
!byte 15
|
|
!raw "ONBEYOND.SYSTEM"
|