pitch-dark/src/parse.prefs.a

207 lines
5.0 KiB
Plaintext

;license:MIT
;(c) 2018 by 4am
;
; Global preferences
;
; Public functions
; - LoadGlobalPreferences
; - SaveGlobalPreferences
;
; Public variables
; - gGlobalPrefsDirty byte 0=false, 1=true
; set to 1 if prefs have changed. SaveGlobalPreferences won't write to disk if this is 0.
;
; Public constants (all length-prefixed strings)
; - kForce40
; - kForceUpper
; - kScriptToFile
; - kAutoScript
; - kLastPlayed
;
!zone {
gGlobalPrefsStore
!word 0
gGlobalPrefsDirty
!byte 0
kForce40
!byte 14
!raw "FORCE40COLUMNS"
kForceUpper
!byte 14
!raw "FORCEUPPERCASE"
kScriptToFile
!byte 12
!raw "SCRIPTTOFILE"
kAutoScript
!byte 10
!raw "AUTOSCRIPT"
kLastPlayed
!byte 10
!raw "LASTPLAYED"
;------------------------------------------------------------------------------
; LoadGlobalPreferences
; load global options and state (including current game) from file and populate
; global prefs store
;
; in: current ProDOS prefix is the same as the PITCH.DARK.CONF file
; out: all registers and flags clobbered
;------------------------------------------------------------------------------
LoadGlobalPreferences
stz gGlobalPrefsDirty
jsr LoadFile ; load prefs file at $2000
!word .globalPrefsFilename
.handle !word kGlobalPrefsBuffer
!word kProDOSFileBuffer
jsr ParseKeyValueText ; parse contents into global prefs store
!word gGlobalPrefsStore
!word .handle
!byte 16
+LDAY SRC
+STAY gVersionsStore ; save pointer to free space for next store
.exit rts
;------------------------------------------------------------------------------
; SaveGlobalPreferences
; save global options and state to file
; note: this function is inefficient because I want the preferences file to
; look a certain way at all times
;
; in: current ProDOS prefix is the same as the PITCH.DARK.CONF file
; out: all registers and flags clobbered
;------------------------------------------------------------------------------
SaveGlobalPreferences
lda gGlobalPrefsDirty
beq .exit
+LDADDR kGlobalPrefsBuffer
+STAY $FE
+LDADDR .fluff1
jsr addString
jsr addBooleanFromStore
!word kForce40
jsr addBooleanFromStore
!word kForceUpper
jsr addBooleanFromStore
!word kScriptToFile
jsr addBooleanFromStore
!word kAutoScript
+LDADDR .fluff2
jsr addString
jsr addStringFromStore
!word kLastPlayed
+LDADDR .fluff3
jsr addString
jsr okvs_iter
!word gGamesListStore
!word addGameToPrefs
+LDADDR .eof
jsr addString
lda $FE
sta .filelen
lda $FF
sec
sbc #>kGlobalPrefsBuffer
sta .filelen+1
jsr SaveFile
!word .globalPrefsFilename
!byte 4 ; filetype=TXT
!word 0 ; auxtype=0000
!word kGlobalPrefsBuffer
.filelen !word $FDFD ; SMC
!word kProDOSFileBuffer
stz gGlobalPrefsDirty
rts
addGameToPrefs
+STAY +
jsr addStringFromStore
+ !word $FDFD ; SMC
rts
addBooleanFromStore
lda #$24 ; BIT opcode
!byte $2C
addStringFromStore
lda #$80 ; BRA opcode
sta .skipOverBooleanLogic
+PARAMS_ON_STACK 2
+LDPARAM 1
+STAY .key
jsr addString
+LDADDR .equals
jsr addString
jsr okvs_get
!word gGlobalPrefsStore
.key !word $FDFD ; SMC
.skipOverBooleanLogic
bra + ; SMC (opcode may become BIT)
+STAY PTR
ldy #1
lda (PTR),y
ora #$30
sta (PTR),y
+LDAY PTR
+ jsr addString
+LDADDR .lf
jmp addString
addString
+STAY $00
lda ($00)
inc
sta .len
ldy #1
- lda ($00),y
sta ($FE)
+ iny
inc $FE
bne +
inc $FF
.len=*+1
+ cpy #$FD ; SMC
bne -
rts
.globalPrefsFilename
!byte 15
!raw "PITCH.DARK.CONF"
.equals !byte 1
!raw "="
.lf !byte 1
!byte $0D
.fluff1 !byte 101
!raw "# Pitch Dark preferences file",$0D
!raw "# Do not edit by hand.",$0D
!raw "# Or do. I'm a comment, not a cop.",$0D,$0D
!raw "# value=0|1",$0D
.fluff2 !byte 24
!byte $0D
!raw "# value=game directory",$0D
.fluff3 !byte 58
!byte $0D
!raw "# key=game directory, value=filename of selected version",$0D
.eof !byte 7
!byte $0D
!raw "[eof]",$0D
}