2018-02-09 01:38:26 +00:00
|
|
|
;license:MIT
|
|
|
|
;(c) 2018 by 4am
|
|
|
|
;
|
2018-03-27 20:55:31 +00:00
|
|
|
; Global preferences
|
2018-02-09 01:38:26 +00:00
|
|
|
;
|
|
|
|
; Public functions
|
|
|
|
; - LoadGlobalPreferences
|
2018-03-24 23:03:00 +00:00
|
|
|
; - 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-24 23:03:00 +00:00
|
|
|
;
|
2018-03-27 21:17:47 +00:00
|
|
|
; Public constants (all length-prefixed strings)
|
2018-03-24 23:03:00 +00:00
|
|
|
; - kForce40
|
|
|
|
; - kForceUpper
|
2018-03-26 18:57:06 +00:00
|
|
|
; - kScriptToFile
|
|
|
|
; - kAutoScript
|
2018-03-24 23:03:00 +00:00
|
|
|
; - kLastPlayed
|
2018-03-26 18:57:06 +00:00
|
|
|
;
|
2018-02-09 01:38:26 +00:00
|
|
|
|
|
|
|
!zone {
|
2018-03-16 18:17:45 +00:00
|
|
|
gCurrentGame
|
|
|
|
!byte 0
|
2018-03-24 23:03:00 +00:00
|
|
|
|
2018-03-27 20:31:01 +00:00
|
|
|
gNeedToSavePrefs
|
|
|
|
!byte 0
|
|
|
|
|
2018-03-24 23:03:00 +00:00
|
|
|
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"
|
2018-03-24 23:03:00 +00:00
|
|
|
kLastPlayed
|
|
|
|
!byte 10
|
|
|
|
!raw "LASTPLAYED"
|
2018-02-09 01:38:26 +00:00
|
|
|
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; LoadGlobalPreferences
|
|
|
|
;
|
2018-03-27 19:19:48 +00:00
|
|
|
; in: current ProDOS prefix is the same as the PITCH.DARK.CONF file
|
2018-02-09 01:38:26 +00:00
|
|
|
; out: all registers and flags clobbered
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
LoadGlobalPreferences
|
2018-03-27 20:31:01 +00:00
|
|
|
stz gNeedToSavePrefs
|
|
|
|
|
2018-03-24 16:04:09 +00:00
|
|
|
jsr okvs_init
|
2018-03-28 02:40:09 +00:00
|
|
|
!word gGlobalPrefsStore
|
2018-03-24 16:04:09 +00:00
|
|
|
|
2018-03-27 19:19:48 +00:00
|
|
|
jsr LoadFile ; load prefs file at $2000
|
|
|
|
!word .globalPrefsFilename
|
|
|
|
!word $2000
|
|
|
|
!word $2000
|
|
|
|
!word kProDOSFileBuffer
|
|
|
|
|
|
|
|
lda #$FF
|
|
|
|
sta $FE
|
|
|
|
lda #$1F
|
|
|
|
sta $FF ; ($FE) points to start of data buffer
|
|
|
|
ldy #$00 ; index into ($FE) pointing to current character
|
|
|
|
.newKey ldx #$00 ; X = index into current key
|
|
|
|
.gatherKey
|
2018-03-28 02:40:09 +00:00
|
|
|
stx gKeyLen
|
2018-03-27 19:19:48 +00:00
|
|
|
jsr IncAndGetChar
|
|
|
|
cmp #$23 ; '#' is starts a comment (until CR)
|
|
|
|
beq .skipComment
|
|
|
|
cmp #$3D ; '=' ends the key
|
|
|
|
beq .endKey
|
|
|
|
cmp #$0D ; found CR before '=', ignore key and start over
|
|
|
|
beq .newKey
|
2018-03-28 02:40:09 +00:00
|
|
|
sta gKey,x
|
2018-03-27 19:19:48 +00:00
|
|
|
inx
|
|
|
|
bra .gatherKey
|
2018-03-28 02:40:09 +00:00
|
|
|
.endKey stx gKeyLen
|
2018-03-27 19:19:48 +00:00
|
|
|
txa ; to set Z flag
|
|
|
|
beq .doneParsing ; empty key ends the parsing
|
|
|
|
ldx #$00 ; X = index into the current value
|
|
|
|
.gatherValue
|
2018-03-28 02:40:09 +00:00
|
|
|
stx gValLen
|
2018-03-27 19:19:48 +00:00
|
|
|
jsr IncAndGetChar
|
|
|
|
cmp #$0D ; CR ends the value
|
|
|
|
beq .endValue
|
2018-03-28 02:40:09 +00:00
|
|
|
sta gVal,x
|
2018-03-27 19:19:48 +00:00
|
|
|
inx
|
|
|
|
bra .gatherValue
|
|
|
|
.endValue
|
2018-03-28 02:40:09 +00:00
|
|
|
stx gValLen
|
|
|
|
lda gValLen
|
2018-03-27 19:19:48 +00:00
|
|
|
cmp #1
|
|
|
|
bne .use16
|
2018-03-28 02:40:09 +00:00
|
|
|
lda gVal
|
2018-03-27 19:19:48 +00:00
|
|
|
and #1
|
2018-03-28 02:40:09 +00:00
|
|
|
sta gVal ; single-character values get converted to #$00 or #$01 in prefs store
|
2018-03-27 19:19:48 +00:00
|
|
|
lda #0
|
|
|
|
!byte $2C
|
|
|
|
.use16 lda #16
|
|
|
|
sta .okvslen ; all other values get upgraded to 16 bytes so we can update them in place
|
|
|
|
phy ; okvs functions clobber everything but we need Y
|
2018-03-26 17:17:35 +00:00
|
|
|
jsr okvs_append
|
2018-03-28 02:40:09 +00:00
|
|
|
!word gGlobalPrefsStore
|
|
|
|
!word gKeyLen
|
|
|
|
!word gValLen
|
2018-03-27 19:19:48 +00:00
|
|
|
.okvslen !byte $FD ; set at runtime
|
|
|
|
ply
|
|
|
|
bra .newKey
|
2018-03-26 17:17:35 +00:00
|
|
|
|
2018-03-27 19:19:48 +00:00
|
|
|
.skipComment ; skip to CR
|
|
|
|
jsr IncAndGetChar
|
|
|
|
cmp #$0D ; CR
|
|
|
|
bne .skipComment
|
|
|
|
bra .newKey
|
|
|
|
|
|
|
|
.doneParsing
|
2018-03-28 02:40:09 +00:00
|
|
|
lda SRC
|
|
|
|
sta gVersionsStore
|
|
|
|
lda SRC+1
|
|
|
|
sta gVersionsStore+1
|
2018-03-27 19:19:48 +00:00
|
|
|
jsr okvs_get
|
2018-03-28 02:40:09 +00:00
|
|
|
!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
|
2018-03-24 23:03:00 +00:00
|
|
|
!word kForce40
|
2018-03-24 16:04:09 +00:00
|
|
|
|
2018-03-27 19:19:48 +00:00
|
|
|
jsr addBooleanFromStore
|
2018-03-24 23:03:00 +00:00
|
|
|
!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
|
2018-02-09 01:38:26 +00:00
|
|
|
!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
|
2018-02-09 01:38:26 +00:00
|
|
|
!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
|
2018-03-28 02:40:09 +00:00
|
|
|
!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 -
|
2018-02-09 01:38:26 +00:00
|
|
|
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 6
|
|
|
|
!byte $0D
|
|
|
|
!raw "=EOF",$0D
|
2018-02-09 01:38:26 +00:00
|
|
|
}
|