pitch-dark/src/glue.onbeyond.a
2018-04-15 12:29:24 -04:00

218 lines
6.6 KiB
Plaintext

;license:MIT
;(c) 2018 by 4am
;
; glue code to load, set up, and launch the On Beyond Z-Machine! interpreter
;
; Public functions
; - ClearInterpreterOptions
; - SetInterpreterOptions
; - SetInterpreterOptionsExceptForce40
; - LaunchInterpreterWithGame
; - LaunchInterpreterWithHints
;
kGameRootDirectory ; length-prefixed pathname of game subdirectories
!byte 2
!raw "Z/"
kHintsRootDirectory ; length-prefixed pathname of hint files
!byte 5
!raw "PRIZM/"
kOnBeyondOptionsStruct = $0300
kOnBeyondColumns = $0300
kOnBeyondCase = $0301
kOnBeyondAutoRestore = $0302
kOnBeyondScriptToFile = $0303
kOnBeyondAutoScript = $0304
kOnBeyondWarnMissing = $0305
kOnBeyondChecksum = $0306
;------------------------------------------------------------------------------
; ClearInterpreterOptions
; clear options script and make checksum invalid
;
; in: none
; out: A/Y clobbered
; X preserved
; all flags clobbered
;------------------------------------------------------------------------------
ClearInterpreterOptions
ldy #6
lda #0
- sta kOnBeyondOptionsStruct,y
dey
bpl -
rts
;------------------------------------------------------------------------------
; SetInterpreterOptions
; set options struct based on global preferences store
;
; in: none
; out: all registers and flags clobbered
;------------------------------------------------------------------------------
SetInterpreterOptions
jsr okvs_get
!word gGlobalPrefsStore
!word kForce40
jsr okvs_as_boolean
beq SetInterpreterOptionsExceptForce40
lda #$CE
!byte $2C
; execution falls through here
;------------------------------------------------------------------------------
; SetInterpreterOptionsExceptForce40
; set options struct based on global preferences store, except always specify
; 80-column mode (used to launch PRIZM 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
!byte $2C
+ lda #1
sta kOnBeyondCase
lda #$FF ; TODO this will eventually be set based on 'Resume Game' screen
sta kOnBeyondAutoRestore
jsr okvs_get
!word gGlobalPrefsStore
!word kScriptToFile
jsr okvs_as_boolean
beq +
lda #1
!byte $2C
+ lda #0
sta kOnBeyondScriptToFile
jsr okvs_get
!word gGlobalPrefsStore
!word kAutoScript
jsr okvs_as_boolean
beq +
lda #1
!byte $2C
+ lda #0
sta kOnBeyondAutoScript
lda #0 ; never warn, YOLO
sta kOnBeyondWarnMissing
lda #$A5
eor kOnBeyondColumns
eor kOnBeyondCase
eor kOnBeyondAutoRestore
eor kOnBeyondScriptToFile
eor kOnBeyondAutoScript
eor kOnBeyondWarnMissing
sta kOnBeyondChecksum
rts
;------------------------------------------------------------------------------
; LaunchInterpreterWithGame
; load interpreter and launch it with a game based on global preferences store
;
; 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
;------------------------------------------------------------------------------
LaunchInterpreterWithGame
jsr SaveGlobalPreferences
jsr LoadInterpreter
bcs .launchError
jsr ResetPath
+LDADDR kGameRootDirectory
jsr AddToPath
jsr okvs_get
!word gGlobalPrefsStore
!word kLastPlayed
+STAY + ; A/Y contains address
jsr AddToPath
jsr SetPrefix ; set ProDOS prefix to game directory
!word gPathname
bcs .launchError
jsr okvs_get
!word gGlobalPrefsStore
+ !word $FDFD ; SMC
jsr SetStartupPath ; store game filename at $2006
jsr ExitWeeGUI ; shut down WeeGUI
jsr SetInterpreterOptions ; set options struct at $300
jmp kSystemAddress ; exit via interpreter
.launchError
jmp SoftBell
;------------------------------------------------------------------------------
; 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
jsr SaveGlobalPreferences
jsr LoadInterpreter
bcs .launchError
jsr ResetPath
+LDADDR kHintsRootDirectory
jsr AddToPath
jsr SetPrefix
!word gPathname
bcs .launchError
jsr okvs_get
!word gGlobalPrefsStore
!word kLastPlayed
jsr SetStartupPath ; store hints filename at $2006
jsr ExitWeeGUI
jsr SetInterpreterOptionsExceptForce40
jmp kSystemAddress
;------------------------------------------------------------------------------
; 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
; gPathname clobbered
;------------------------------------------------------------------------------
LoadInterpreter
jsr ResetPath
+LDADDR .interpreterFilename
jsr AddToPath
jsr LoadFile
!word gPathname
!word kSystemAddress
!word kProDOSFileBuffer
rts
.interpreterFilename
!byte 15
!raw "ONBEYOND.SYSTEM"