pitch-dark/src/glue.onbeyond.a

173 lines
6.0 KiB
Plaintext
Raw Normal View History

2018-03-27 00:05:34 +00:00
;license:MIT
;(c) 2018 by 4am
;
2018-04-15 16:29:24 +00:00
; glue code to load, set up, and launch the On Beyond Z-Machine! interpreter
2018-03-27 00:05:34 +00:00
;
; Public functions
2018-04-18 00:32:31 +00:00
; - LaunchInterpreterWithNewGame
2018-03-31 14:59:02 +00:00
; - LaunchInterpreterWithGame
; - LaunchInterpreterWithHints
2018-03-27 00:05:34 +00:00
;
2018-04-02 19:43:11 +00:00
kHintsRootDirectory ; length-prefixed pathname of hint files
!byte 6
2018-07-20 19:52:02 +00:00
!raw "HINTS/"
2018-04-02 19:43:11 +00:00
2018-03-31 14:59:02 +00:00
kOnBeyondOptionsStruct = $0300
kOnBeyondColumns = $0300
kOnBeyondCase = $0301
kOnBeyondAutoRestore = $0302
kOnBeyondScriptToFile = $0303
kOnBeyondAutoScript = $0304
kOnBeyondWarnMissing = $0305
kOnBeyondChecksum = $0306
;------------------------------------------------------------------------------
2018-04-19 02:01:24 +00:00
; LaunchInterpreterWithNewGame/LaunchInterpreterWithGame
; load interpreter and launch it with a game based on global preferences store,
2018-04-19 02:01:24 +00:00
; and optionally tell it to restore from a specific saved game slot
; in: A = saved game slot, or #$FF for none
2018-04-17 18:06:41 +00:00
; 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
2018-04-17 18:06:41 +00:00
LaunchInterpreterWithGame
sta kOnBeyondAutoRestore
jsr SaveGlobalPreferences
jsr LoadInterpreter
2018-04-19 02:01:24 +00:00
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
2018-04-17 18:06:41 +00:00
sta kOnBeyondAutoRestore ; no saved game to restore
jsr SaveGlobalPreferences
jsr LoadInterpreter
2018-04-19 02:01:24 +00:00
bcc +
jmp SoftBell
+ jsr ResetPath
+LDADDR kHintsRootDirectory
jsr AddToPath
jsr okvs_get
!word gGlobalPrefsStore
!word kLastPlayed
2018-04-18 02:35:13 +00:00
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
2018-03-31 14:59:02 +00:00
;------------------------------------------------------------------------------
; SetInterpreterOptions
; set options struct based on global preferences store
;
2018-04-17 18:06:41 +00:00
; in: kOnBeyondAutoRestore already set (save slot 0-7, or #$FF if none)
2018-03-31 14:59:02 +00:00
; out: all registers and flags clobbered
;------------------------------------------------------------------------------
SetInterpreterOptions
2018-03-27 00:05:34 +00:00
jsr okvs_get
!word gGlobalPrefsStore
2018-03-27 00:05:34 +00:00
!word kForce40
jsr okvs_as_boolean
2018-03-31 14:59:02 +00:00
beq SetInterpreterOptionsExceptForce40
lda #$CE
2018-04-18 02:28:22 +00:00
+HIDE_NEXT_2_BYTES
2018-04-18 00:32:31 +00:00
; execution falls through here
2018-03-31 14:59:02 +00:00
;------------------------------------------------------------------------------
; SetInterpreterOptionsExceptForce40
; set options struct based on global preferences store, except always specify
2018-07-20 19:52:02 +00:00
; 80-column mode (used to launch hint files)
2018-03-31 14:59:02 +00:00
;
; in: none
; out: all registers and flags clobbered
;------------------------------------------------------------------------------
SetInterpreterOptionsExceptForce40
lda #$D9
2018-03-31 14:59:02 +00:00
sta kOnBeyondColumns
2018-03-27 00:05:34 +00:00
jsr okvs_get
!word gGlobalPrefsStore
2018-03-27 00:05:34 +00:00
!word kForceUpper
jsr okvs_as_boolean
beq +
lda #0
2018-04-18 02:28:22 +00:00
+HIDE_NEXT_2_BYTES
+ lda #1
2018-03-31 14:59:02 +00:00
sta kOnBeyondCase
2018-03-27 00:05:34 +00:00
jsr okvs_get
!word gGlobalPrefsStore
2018-03-27 00:05:34 +00:00
!word kScriptToFile
jsr okvs_as_boolean
beq +
lda #1
2018-04-18 02:28:22 +00:00
+HIDE_NEXT_2_BYTES
+ lda #0
2018-03-31 14:59:02 +00:00
sta kOnBeyondScriptToFile
2018-03-27 00:05:34 +00:00
jsr okvs_get
!word gGlobalPrefsStore
2018-03-27 00:05:34 +00:00
!word kAutoScript
jsr okvs_as_boolean
beq +
lda #1
2018-04-18 02:28:22 +00:00
+HIDE_NEXT_2_BYTES
+ lda #0
2018-03-31 14:59:02 +00:00
sta kOnBeyondAutoScript
2018-03-27 00:05:34 +00:00
2018-03-31 14:59:02 +00:00
lda #0 ; never warn, YOLO
sta kOnBeyondWarnMissing
2018-03-27 00:05:34 +00:00
lda #$A5
2018-03-31 14:59:02 +00:00
eor kOnBeyondColumns
eor kOnBeyondCase
2018-04-17 18:06:41 +00:00
eor kOnBeyondAutoRestore ; caller must have set this already
2018-03-31 14:59:02 +00:00
eor kOnBeyondScriptToFile
eor kOnBeyondAutoScript
eor kOnBeyondWarnMissing
sta kOnBeyondChecksum
rts
2018-03-31 14:59:02 +00:00
;------------------------------------------------------------------------------
; 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
;------------------------------------------------------------------------------
2018-03-27 00:05:34 +00:00
LoadInterpreter
jsr LoadFile
!word kInterpreterFilename
2018-03-27 00:05:34 +00:00
!word kSystemAddress
!word kProDOSFileBuffer
rts
2018-03-31 14:59:02 +00:00
kInterpreterFilename
2018-03-27 00:05:34 +00:00
!byte 15
!raw "ONBEYOND.SYSTEM"