;license:MIT ;(c) 2018 by 4am ; ; Parser for global preferences file ; ; Public functions ; - SaveGlobalPreferences ; ; Public variables ; - gGlobalPrefsStore word address of prefs okvs (set in LoadGameList) ; - gGlobalPrefsDirty byte 0=false, nonzero=true ; set to 1 if prefs have changed. SaveGlobalPreferences won't write to disk if this is 0. ; ; Public constants (all length-prefixed strings) ; - kGlobalPrefsFilename ; - kForce40 ; - kForceUpper ; - kScriptToFile ; - kAutoScript ; - kLastPlayed ; gGlobalPrefsStore !word 0 gGlobalPrefsDirty !byte 0 kGlobalPrefsFilename !byte 15 !raw "PITCH.DARK.CONF" 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" ;------------------------------------------------------------------------------ ; 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 @kFluff1 jsr @addString jsr @addBooleanFromStore !word kForce40 jsr @addBooleanFromStore !word kForceUpper jsr @addBooleanFromStore !word kScriptToFile jsr @addBooleanFromStore !word kAutoScript +LDADDR @kFluff2 jsr @addString jsr @addStringFromStore !word kLastPlayed +LDADDR @kFluff3 jsr @addString jsr okvs_iter !word gGamesListStore !word @addGameToPrefs +LDADDR @kEOF jsr @addString lda $FE sta @filelen lda $FF sec sbc #>kGlobalPrefsBuffer sta @filelen+1 jsr SaveFile !word kGlobalPrefsFilename !byte 4 ; filetype=TXT !word 0 ; auxtype=0000 !word kGlobalPrefsBuffer @filelen !word $FDFD ; SMC !word kProDOSFileBuffer stz gGlobalPrefsDirty @exit rts @addGameToPrefs +STAY + jsr @addStringFromStore + !word $FDFD ; SMC rts @addBooleanFromStore lda #$24 ; BIT opcode +HIDE_NEXT_2_BYTES @addStringFromStore lda #$80 ; BRA opcode sta @skipOverBooleanLogic +PARAMS_ON_STACK 2 +LDPARAM 1 +STAY @key jsr @addString +LDADDR @kEquals 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 @kLF 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 @kEquals !byte 1 !raw "=" @kLF !byte 1 !byte $0D @kFluff1 !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 @kFluff2 !byte 24 !byte $0D !raw "# value=game directory",$0D @kFluff3 !byte 58 !byte $0D !raw "# key=game directory, value=filename of selected version",$0D @kEOF !byte 7 !byte $0D !raw "[eof]",$0D