pitch-dark/src/parse.prefs.a

261 lines
6.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
; - gCurrentGame byte 0..kNumberOfGames-1
2018-03-27 21:17:47 +00:00
; populated by LoadGlobalPreferences so other code can index into GAMES array for quick access to game shortnames
2018-03-27 20:31:01 +00:00
; - gNeedToSavePrefs 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-16 18:17:45 +00:00
gCurrentGame
!byte 0
2018-03-27 20:31:01 +00:00
gNeedToSavePrefs
!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
;
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-03-27 20:31:01 +00:00
stz gNeedToSavePrefs
2018-03-27 19:19:48 +00:00
jsr LoadFile ; load prefs file at $2000
!word .globalPrefsFilename
.prefsAddress
2018-03-27 19:19:48 +00:00
!word $2000
!word $2000
!word kProDOSFileBuffer
jsr ParseKeyValueText ; parse contents into global prefs store
!word gGlobalPrefsStore
!word .prefsAddress
!byte 16
2018-03-27 19:19:48 +00:00
lda SRC ; save pointer to free space for next store
sta gVersionsStore
lda SRC+1
sta gVersionsStore+1
jsr okvs_get ; set gCurrentGame
!word gGlobalPrefsStore
2018-03-27 19:19:48 +00:00
!word kLastPlayed
sta DEST
sty DEST+1
ldx #$FE
.findLastPlayed
inx
inx
lda GAMES,x
sta SRC
lda GAMES+1,x
sta SRC+1
lda (SRC)
tay
dey
- lda (SRC),y
cmp (DEST),y
bne .findLastPlayed
dey
bpl -
txa
lsr
sta gCurrentGame
rts
2018-03-27 21:17:47 +00:00
;------------------------------------------------------------------------------
; SaveGlobalPreferences
;
; 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-03-27 20:31:01 +00:00
lda gNeedToSavePrefs
bne +
rts
+
stz $FE
2018-03-27 19:19:48 +00:00
lda #$20
sta $FF
lda #<.fluff1
ldy #>.fluff1
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-27 19:19:48 +00:00
lda #<.fluff2
ldy #>.fluff2
jsr addString
jsr addStringFromStore
!word kLastPlayed
lda #<.fluff3
ldy #>.fluff3
jsr addString
ldx #0
.gameLoop
phx
txa
asl
tax
lda GAMES,x
ldy GAMES+1,x
sta .gameKey
sty .gameKey+1
jsr addStringFromStore
.gameKey !word $FDFD ; set at runtime
plx
inx
cpx #kNumberOfGames
bne .gameLoop
lda #<.eof
ldy #>.eof
jsr addString
lda $FE
sta .prefslen
lda $FF
sec
sbc #$20
sta .prefslen+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
2018-03-16 18:17:45 +00:00
!word $2000
2018-03-27 19:19:48 +00:00
.prefslen
!word $FDFD ; set at runtime
!word kProDOSFileBuffer
2018-03-27 20:31:01 +00:00
stz gNeedToSavePrefs
2018-03-16 18:17:45 +00:00
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
ldy #1
lda (PARAM),y
sta .storeKey
pha
iny
lda (PARAM),y
sta .storeKey+1
tay
pla
jsr addString
lda #<.equals
ldy #>.equals
jsr addString
jsr okvs_get
!word gGlobalPrefsStore
2018-03-27 19:19:48 +00:00
.storeKey
!word $FDFD ; set at runtime
.skipOverBooleanLogic
bra + ; set at runtime (opcode may become BIT)
sta PTR
sty PTR+1
ldy #1
lda (PTR),y
ora #$30
sta (PTR),y
lda PTR
ldy PTR+1
+ jsr addString
lda #<.lf
ldy #>.lf
jmp addString
addString
sta $00
sty $01
lda ($00)
inc
sta .len
ldy #1
- lda ($00),y
sta ($FE)
+ iny
inc $FE
bne +
inc $FF
.len=*+1
+ cpy #$FD ; set at runtime
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
}