pitch-dark/src/parse.prefs.a

207 lines
5.0 KiB
Plaintext
Raw Normal View History

;license:MIT
;(c) 2018 by 4am
;
2018-03-27 20:55:31 +00:00
; Global preferences
;
; Public functions
; - LoadGlobalPreferences
; - SaveGlobalPreferences
2018-03-16 18:17:45 +00:00
;
; Public variables
2018-04-01 22:26:54 +00:00
; - gGlobalPrefsDirty byte 0=false, 1=true
2018-03-27 21:17:47 +00:00
; set to 1 if prefs have changed. SaveGlobalPreferences won't write to disk if this is 0.
;
2018-03-27 21:17:47 +00:00
; Public constants (all length-prefixed strings)
; - kForce40
; - kForceUpper
2018-03-26 18:57:06 +00:00
; - kScriptToFile
; - kAutoScript
; - kLastPlayed
2018-03-26 18:57:06 +00:00
;
!zone {
2018-03-28 15:48:47 +00:00
gGlobalPrefsStore
!word 0
2018-04-01 22:26:54 +00:00
gGlobalPrefsDirty
2018-03-27 20:31:01 +00:00
!byte 0
kForce40
!byte 14
!raw "FORCE40COLUMNS"
kForceUpper
!byte 14
!raw "FORCEUPPERCASE"
2018-03-26 17:17:35 +00:00
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
;
2018-03-27 19:19:48 +00:00
; in: current ProDOS prefix is the same as the PITCH.DARK.CONF file
; out: all registers and flags clobbered
;------------------------------------------------------------------------------
LoadGlobalPreferences
2018-04-01 22:26:54 +00:00
stz gGlobalPrefsDirty
2018-03-27 20:31:01 +00:00
2018-03-27 19:19:48 +00:00
jsr LoadFile ; load prefs file at $2000
!word .globalPrefsFilename
.handle !word kGlobalPrefsBuffer
2018-03-27 19:19:48 +00:00
!word kProDOSFileBuffer
jsr ParseKeyValueText ; parse contents into global prefs store
!word gGlobalPrefsStore
2018-03-29 02:49:51 +00:00
!word .handle
!byte 16
2018-03-27 19:19:48 +00:00
2018-03-29 02:49:51 +00:00
+LDAY SRC
+STAY gVersionsStore ; save pointer to free space for next store
.exit rts
2018-03-27 19:19:48 +00:00
2018-03-27 21:17:47 +00:00
;------------------------------------------------------------------------------
; 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
2018-03-27 21:17:47 +00:00
;
; in: current ProDOS prefix is the same as the PITCH.DARK.CONF file
; out: all registers and flags clobbered
;------------------------------------------------------------------------------
2018-03-27 19:19:48 +00:00
SaveGlobalPreferences
2018-04-01 22:26:54 +00:00
lda gGlobalPrefsDirty
2018-03-29 02:49:51 +00:00
beq .exit
+LDADDR kGlobalPrefsBuffer
+STAY $FE
2018-03-27 19:19:48 +00:00
2018-03-29 02:49:51 +00:00
+LDADDR .fluff1
2018-03-27 19:19:48 +00:00
jsr addString
jsr addBooleanFromStore
!word kForce40
2018-03-24 16:04:09 +00:00
2018-03-27 19:19:48 +00:00
jsr addBooleanFromStore
!word kForceUpper
2018-03-24 16:04:09 +00:00
2018-03-27 19:19:48 +00:00
jsr addBooleanFromStore
2018-03-26 17:17:35 +00:00
!word kScriptToFile
2018-03-24 16:04:09 +00:00
2018-03-27 19:19:48 +00:00
jsr addBooleanFromStore
2018-03-26 17:17:35 +00:00
!word kAutoScript
2018-03-24 19:28:55 +00:00
2018-03-29 02:49:51 +00:00
+LDADDR .fluff2
2018-03-27 19:19:48 +00:00
jsr addString
jsr addStringFromStore
!word kLastPlayed
2018-03-29 02:49:51 +00:00
+LDADDR .fluff3
2018-03-27 19:19:48 +00:00
jsr addString
jsr okvs_iter
!word gGamesListStore
!word addGameToPrefs
2018-03-27 19:19:48 +00:00
2018-03-29 02:49:51 +00:00
+LDADDR .eof
2018-03-27 19:19:48 +00:00
jsr addString
lda $FE
2018-03-29 02:49:51 +00:00
sta .filelen
2018-03-27 19:19:48 +00:00
lda $FF
sec
sbc #>kGlobalPrefsBuffer
2018-03-29 02:49:51 +00:00
sta .filelen+1
2018-03-27 20:31:01 +00:00
2018-03-27 19:19:48 +00:00
jsr SaveFile
!word .globalPrefsFilename
2018-03-27 19:19:48 +00:00
!byte 4 ; filetype=TXT
!word 0 ; auxtype=0000
!word kGlobalPrefsBuffer
2018-03-29 02:49:51 +00:00
.filelen !word $FDFD ; SMC
!word kProDOSFileBuffer
2018-03-27 20:31:01 +00:00
2018-04-01 22:26:54 +00:00
stz gGlobalPrefsDirty
2018-03-16 18:17:45 +00:00
rts
addGameToPrefs
+STAY +
jsr addStringFromStore
+ !word $FDFD ; SMC
rts
2018-03-27 19:19:48 +00:00
addBooleanFromStore
lda #$24 ; BIT opcode
!byte $2C
addStringFromStore
lda #$80 ; BRA opcode
sta .skipOverBooleanLogic
+PARAMS_ON_STACK 2
+LDPARAM 1
+STAY .key
2018-03-27 19:19:48 +00:00
jsr addString
2018-03-29 02:49:51 +00:00
+LDADDR .equals
2018-03-27 19:19:48 +00:00
jsr addString
jsr okvs_get
!word gGlobalPrefsStore
2018-03-29 02:49:51 +00:00
.key !word $FDFD ; SMC
2018-03-27 19:19:48 +00:00
.skipOverBooleanLogic
2018-03-28 15:48:47 +00:00
bra + ; SMC (opcode may become BIT)
2018-03-29 02:49:51 +00:00
+STAY PTR
2018-03-27 19:19:48 +00:00
ldy #1
lda (PTR),y
ora #$30
sta (PTR),y
2018-03-29 02:49:51 +00:00
+LDAY PTR
2018-03-27 19:19:48 +00:00
+ jsr addString
2018-03-29 02:49:51 +00:00
+LDADDR .lf
2018-03-27 19:19:48 +00:00
jmp addString
addString
2018-03-29 02:49:51 +00:00
+STAY $00
2018-03-27 19:19:48 +00:00
lda ($00)
inc
sta .len
ldy #1
- lda ($00),y
sta ($FE)
+ iny
inc $FE
bne +
inc $FF
.len=*+1
2018-03-28 15:48:47 +00:00
+ cpy #$FD ; SMC
2018-03-27 19:19:48 +00:00
bne -
rts
.globalPrefsFilename
!byte 15
!raw "PITCH.DARK.CONF"
2018-03-16 18:17:45 +00:00
2018-03-27 19:19:48 +00:00
.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
2018-03-27 19:19:48 +00:00
!byte $0D
!raw "[eof]",$0D
}