pitch-dark/src/parse.prefs.a

182 lines
4.2 KiB
Plaintext
Raw Permalink Normal View History

;license:MIT
;(c) 2018 by 4am
;
2018-04-15 16:29:24 +00:00
; Parser for global preferences file
;
; Public functions
; - SaveGlobalPreferences
2018-03-16 18:17:45 +00:00
;
; Public variables
2018-04-18 19:28:55 +00:00
; - gGlobalPrefsStore word address of prefs okvs (set in LoadGameList)
; - gGlobalPrefsDirty byte 0=false, nonzero=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)
; - kGlobalPrefsFilename
; - kForce40
; - kForceUpper
2018-03-26 18:57:06 +00:00
; - kScriptToFile
; - kAutoScript
; - kLastPlayed
2018-03-26 18:57:06 +00:00
;
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
kGlobalPrefsFilename
!byte 15
!raw "PITCH.DARK.CONF"
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"
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
beq @exit
2018-04-19 02:01:24 +00:00
+LDADDR kGlobalPrefsBuffer
+STAY $FE
2018-03-27 19:19:48 +00:00
2018-04-19 19:15:49 +00:00
+LDADDR @kFluff1
2018-04-19 19:14:20 +00:00
jsr @addString
2018-03-27 19:19:48 +00:00
2018-04-19 19:14:20 +00:00
jsr @addBooleanFromStore
!word kForce40
2018-03-24 16:04:09 +00:00
2018-04-19 19:14:20 +00:00
jsr @addBooleanFromStore
!word kForceUpper
2018-03-24 16:04:09 +00:00
2018-04-19 19:14:20 +00:00
jsr @addBooleanFromStore
2018-03-26 17:17:35 +00:00
!word kScriptToFile
2018-03-24 16:04:09 +00:00
2018-04-19 19:14:20 +00:00
jsr @addBooleanFromStore
2018-03-26 17:17:35 +00:00
!word kAutoScript
2018-03-24 19:28:55 +00:00
2018-04-19 19:15:49 +00:00
+LDADDR @kFluff2
2018-04-19 19:14:20 +00:00
jsr @addString
2018-03-27 19:19:48 +00:00
2018-04-19 19:14:20 +00:00
jsr @addStringFromStore
2018-03-27 19:19:48 +00:00
!word kLastPlayed
2018-04-19 19:15:49 +00:00
+LDADDR @kFluff3
2018-04-19 19:14:20 +00:00
jsr @addString
2018-03-27 19:19:48 +00:00
jsr okvs_iter
!word gGamesListStore
2018-04-19 19:14:20 +00:00
!word @addGameToPrefs
2018-03-27 19:19:48 +00:00
2018-04-19 19:15:49 +00:00
+LDADDR @kEOF
2018-04-19 19:14:20 +00:00
jsr @addString
2018-03-27 19:19:48 +00:00
lda $FE
sta @filelen
2018-03-27 19:19:48 +00:00
lda $FF
sec
sbc #>kGlobalPrefsBuffer
sta @filelen+1
2018-03-27 20:31:01 +00:00
2018-03-27 19:19:48 +00:00
jsr SaveFile
!word kGlobalPrefsFilename
2018-03-27 19:19:48 +00:00
!byte 4 ; filetype=TXT
!word 0 ; auxtype=0000
!word kGlobalPrefsBuffer
@filelen !word $FDFD ; SMC
!word kProDOSFileBuffer
2018-03-27 20:31:01 +00:00
2018-04-01 22:26:54 +00:00
stz gGlobalPrefsDirty
@exit rts
2018-03-16 18:17:45 +00:00
2018-04-19 19:14:20 +00:00
@addGameToPrefs
+STAY +
2018-04-19 19:14:20 +00:00
jsr @addStringFromStore
+ !word $FDFD ; SMC
rts
2018-04-19 19:14:20 +00:00
@addBooleanFromStore
2018-03-27 19:19:48 +00:00
lda #$24 ; BIT opcode
2018-04-18 02:28:22 +00:00
+HIDE_NEXT_2_BYTES
2018-04-19 19:14:20 +00:00
@addStringFromStore
2018-03-27 19:19:48 +00:00
lda #$80 ; BRA opcode
sta @skipOverBooleanLogic
2018-03-27 19:19:48 +00:00
+PARAMS_ON_STACK 2
+LDPARAM 1
+STAY @key
2018-04-19 19:14:20 +00:00
jsr @addString
2018-04-19 19:15:49 +00:00
+LDADDR @kEquals
2018-04-19 19:14:20 +00:00
jsr @addString
2018-03-27 19:19:48 +00:00
jsr okvs_get
!word gGlobalPrefsStore
@key !word $FDFD ; SMC
@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-04-19 19:14:20 +00:00
+ jsr @addString
2018-04-19 19:15:49 +00:00
+LDADDR @kLF
2018-04-19 19:14:20 +00:00
jmp @addString
2018-03-27 19:19:48 +00:00
2018-04-19 19:14:20 +00:00
@addString
2018-03-29 02:49:51 +00:00
+STAY $00
2018-03-27 19:19:48 +00:00
lda ($00)
inc
sta @len
2018-03-27 19:19:48 +00:00
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
2018-04-19 19:15:49 +00:00
@kEquals !byte 1
2018-03-27 19:19:48 +00:00
!raw "="
2018-04-19 19:15:49 +00:00
@kLF !byte 1
2018-03-27 19:19:48 +00:00
!byte $0D
2018-04-19 19:15:49 +00:00
@kFluff1 !byte 101
2018-03-27 19:19:48 +00:00
!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
2018-04-19 19:15:49 +00:00
@kFluff2 !byte 24
2018-03-27 19:19:48 +00:00
!byte $0D
!raw "# value=game directory",$0D
2018-04-19 19:15:49 +00:00
@kFluff3 !byte 58
2018-03-27 19:19:48 +00:00
!byte $0D
!raw "# key=game directory, value=filename of selected version",$0D
2018-04-19 19:15:49 +00:00
@kEOF !byte 7
2018-03-27 19:19:48 +00:00
!byte $0D
!raw "[eof]",$0D