mirror of
https://github.com/a2-4am/pitch-dark.git
synced 2024-06-26 15:29:31 +00:00
refactor key value parsers into parse.common, use for global prefs, versions, and options
This commit is contained in:
parent
e555e5b901
commit
5e15db31ae
|
@ -1 +1 @@
|
||||||
# Pitch Dark preferences file
# Do not edit by hand.
# Or do. I'm a comment, not a cop.
# value=0|1
FORCE40COLUMNS=0
FORCEUPPERCASE=0
SCRIPTTOFILE=0
AUTOSCRIPT=0
# value=game directory
LASTPLAYED=ZORK.I
# key=game directory, value=filename of selected version
ADVENTURE=R9.060321.Z5
AMFV=R79.DEPROT.Z4
BALLYHOO=R97.851218.Z3
BEYOND.ZORK=R57.871221.Z5
BORDER.ZONE=R9.871008.Z5
BUREAUCRACY=R116.DEPROT.Z4
CUTTHROATS=R23.840809.Z3
DEADLINE=R27.831005.Z3
ENCHANTER=R29.860820.Z3
HGTTG=R59.851108.Z3
HOLLYWOOD=R37.861215.Z3
INFIDEL=R22.830916.Z3
LGOP=R59.860730.Z3
LURKING.HORROR=R221.870918.Z3
MINI.ZORK=R34.871124.Z3
MOONMIST=R9.861022.Z3
NORD.AND.BERT=R19.870722.Z4
PLANETFALL=R37.851003.Z3
PLUNDERED=R26.870730.Z3
SEASTALKER=R16B.850603.Z3
SHERLOCK=R26.880127.Z5
SORCERER=R18.DEPROT.Z3
SPELLBREAKER=R87.DEPROT.Z3
STARCROSS=R17.821021.Z3
STATIONFALL=R107.DEPROT.Z3
SUSPECT=R14.841005.Z3
SUSPENDED=R8B.840521.Z3
TRINITY=R12.860926.Z4
WISHBRINGER=R69.850920.Z3
WITNESS=R22.840924.Z3
ZORK.I=R88.840726.Z3
ZORK.II=R48.840904.Z3
ZORK.III=R17.840727.Z3
ZTUU=R16.970828.Z5
=EOF
|
# Pitch Dark preferences file
# Do not edit by hand.
# Or do. I'm a comment, not a cop.
# value=0|1
FORCE40COLUMNS=0
FORCEUPPERCASE=0
SCRIPTTOFILE=0
AUTOSCRIPT=0
# value=game directory
LASTPLAYED=ZORK.I
# key=game directory, value=filename of selected version
ADVENTURE=R9.060321.Z5
AMFV=R79.DEPROT.Z4
BALLYHOO=R97.851218.Z3
BEYOND.ZORK=R57.871221.Z5
BORDER.ZONE=R9.871008.Z5
BUREAUCRACY=R116.DEPROT.Z4
CUTTHROATS=R23.840809.Z3
DEADLINE=R27.831005.Z3
ENCHANTER=R29.860820.Z3
HGTTG=R59.851108.Z3
HOLLYWOOD=R37.861215.Z3
INFIDEL=R22.830916.Z3
LGOP=R59.860730.Z3
LURKING.HORROR=R221.870918.Z3
MINI.ZORK=R34.871124.Z3
MOONMIST=R9.861022.Z3
NORD.AND.BERT=R19.870722.Z4
PLANETFALL=R37.851003.Z3
PLUNDERED=R26.870730.Z3
SEASTALKER=R16B.850603.Z3
SHERLOCK=R26.880127.Z5
SORCERER=R18.DEPROT.Z3
SPELLBREAKER=R87.DEPROT.Z3
STARCROSS=R17.821021.Z3
STATIONFALL=R107.DEPROT.Z3
SUSPECT=R14.841005.Z3
SUSPENDED=R8B.840521.Z3
TRINITY=R12.860926.Z4
WISHBRINGER=R69.850920.Z3
WITNESS=R22.840924.Z3
ZORK.I=R88.840726.Z3
ZORK.II=R48.840904.Z3
ZORK.III=R17.840727.Z3
ZTUU=R16.970828.Z5
[eof]
|
|
@ -1,11 +1,123 @@
|
||||||
gKeyLen = $3F00
|
gKeyLen = $3F00
|
||||||
gKey = $3F01
|
gKey = $3F01
|
||||||
gValLen = $3F10
|
gValLen = $3F80
|
||||||
gVal = $3F11
|
gVal = $3F81
|
||||||
|
|
||||||
|
;------------------------------------------------------------------------------
|
||||||
|
; ParseKeyValueText
|
||||||
|
; parse buffer with KEY=VALUE lines of text into an okvs
|
||||||
|
; keys and values limited to 127 characters, which should be enough for anyone
|
||||||
|
;
|
||||||
|
; in: stack contains 5 bytes of parameters:
|
||||||
|
; +1 [word] handle to storage space
|
||||||
|
; +3 [word] handle to data buffer
|
||||||
|
; +5 [byte] max length for okvs records (or 0)
|
||||||
|
; out: all registers and flags clobbered
|
||||||
|
; $3F00..$3FFF clobbered
|
||||||
|
; $00/$01 clobbered
|
||||||
|
; $02/$03 clobbered
|
||||||
|
; $04/$05 has the address of the next available byte after the okvs
|
||||||
|
;------------------------------------------------------------------------------
|
||||||
|
!zone {
|
||||||
|
ParseKeyValueText
|
||||||
|
+PARAMS_ON_STACK 5
|
||||||
|
|
||||||
|
ldy #1
|
||||||
|
lda (PARAM),y
|
||||||
|
sta .initStore
|
||||||
|
sta .appendStore
|
||||||
|
iny
|
||||||
|
lda (PARAM),y
|
||||||
|
sta .initStore+1
|
||||||
|
sta .appendStore+1
|
||||||
|
iny
|
||||||
|
lda (PARAM),y
|
||||||
|
sta $FE
|
||||||
|
iny
|
||||||
|
lda (PARAM),y
|
||||||
|
sta $FF
|
||||||
|
iny
|
||||||
|
lda (PARAM),y
|
||||||
|
sta .useMaxLength+1
|
||||||
|
|
||||||
|
lda ($FE)
|
||||||
|
pha
|
||||||
|
ldy #1
|
||||||
|
lda ($FE),y
|
||||||
|
tay
|
||||||
|
pla
|
||||||
|
sec
|
||||||
|
sbc #$01
|
||||||
|
sta $FE
|
||||||
|
bcs +
|
||||||
|
dey
|
||||||
|
+ sty $FF
|
||||||
|
jsr okvs_init ; reset key/value store
|
||||||
|
.initStore
|
||||||
|
!word $FDFD ; set at runtime
|
||||||
|
|
||||||
|
ldy #$00 ; index into ($FE) pointing to current character
|
||||||
|
.newKey
|
||||||
|
ldx #$00 ; X = index into current key
|
||||||
|
.gatherKey
|
||||||
|
jsr IncAndGetChar
|
||||||
|
and #$7F ; keys get their high bit stripped
|
||||||
|
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 (also handles blank lines)
|
||||||
|
beq .newKey
|
||||||
|
cmp #$5B ; '[' ends the parsing
|
||||||
|
beq .exit
|
||||||
|
sta gKey,x
|
||||||
|
inx
|
||||||
|
bpl .gatherKey
|
||||||
|
.endKey
|
||||||
|
stx gKeyLen
|
||||||
|
ldx #$00 ; now X = index into the current value
|
||||||
|
.gatherValue
|
||||||
|
jsr IncAndGetChar ; note: values do NOT get their high bit stripped
|
||||||
|
cmp #$0D ; CR ends the value
|
||||||
|
beq .endValue
|
||||||
|
cmp #$00 ; null also ends the value
|
||||||
|
beq .endValue
|
||||||
|
sta gVal,x
|
||||||
|
inx
|
||||||
|
bpl .gatherValue
|
||||||
|
.endValue
|
||||||
|
stx gValLen
|
||||||
|
cpx #1
|
||||||
|
bne .useMaxLength
|
||||||
|
lda gVal
|
||||||
|
and #1
|
||||||
|
sta gVal ; single-character values get converted to #$00 or #$01 in prefs store
|
||||||
|
lda #0
|
||||||
|
!byte $2C
|
||||||
|
.useMaxLength
|
||||||
|
lda #$FD ; set at runtime
|
||||||
|
sta .appendMaxLength ; all other values get upgraded to max_length so we can update them in place
|
||||||
|
phy ; okvs functions clobber everything but we need Y
|
||||||
|
jsr okvs_append
|
||||||
|
.appendStore
|
||||||
|
!word $FDFD ; set at runtime
|
||||||
|
!word gKeyLen
|
||||||
|
!word gValLen
|
||||||
|
.appendMaxLength
|
||||||
|
!byte $FD ; set at runtime
|
||||||
|
ply
|
||||||
|
bra .newKey
|
||||||
|
|
||||||
|
.skipComment ; skip to CR
|
||||||
|
jsr IncAndGetChar
|
||||||
|
cmp #$0D ; CR
|
||||||
|
bne .skipComment
|
||||||
|
bra .newKey
|
||||||
|
|
||||||
IncAndGetChar
|
IncAndGetChar
|
||||||
iny
|
iny
|
||||||
bne +
|
bne +
|
||||||
inc $FF
|
inc $FF
|
||||||
+ lda ($FE),y
|
+ lda ($FE),y
|
||||||
rts
|
.exit rts
|
||||||
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ kTextRootDirectory
|
||||||
|
|
||||||
gVersionsStore
|
gVersionsStore
|
||||||
!word $FDFD ; set at runtime in LoadGlobalPreferences
|
!word $FDFD ; set at runtime in LoadGlobalPreferences
|
||||||
|
gOptionsStore
|
||||||
|
!word $FDFD ; set at runtime in LoadGameInfo
|
||||||
|
|
||||||
sectionPointers ; array of pointers to start of each section
|
sectionPointers ; array of pointers to start of each section
|
||||||
addrEOF
|
addrEOF
|
||||||
|
@ -103,57 +105,20 @@ LoadGameInfo
|
||||||
dex
|
dex
|
||||||
bpl .convertSectionNoInc
|
bpl .convertSectionNoInc
|
||||||
|
|
||||||
jmp LoadVersions
|
jsr ParseKeyValueText ; parse [versions] section into versions store
|
||||||
;jmp LoadGamePreferences
|
|
||||||
}
|
|
||||||
|
|
||||||
!zone {
|
|
||||||
LoadVersions
|
|
||||||
jsr okvs_init
|
|
||||||
!word gVersionsStore
|
!word gVersionsStore
|
||||||
|
!word addrVersions
|
||||||
lda addrVersions+1
|
|
||||||
sta $FF
|
|
||||||
lda addrVersions
|
|
||||||
sec
|
|
||||||
sbc #$01
|
|
||||||
sta $FE
|
|
||||||
bcs +
|
|
||||||
dec $FF
|
|
||||||
+ ldy #$00 ; index into ($FE) pointing to current character
|
|
||||||
.newKey ldx #$00 ; X = index into current key
|
|
||||||
.gatherKey
|
|
||||||
stx gKeyLen
|
|
||||||
jsr IncAndGetChar
|
|
||||||
and #$7F
|
|
||||||
cmp #$3D ; '=' ends the key
|
|
||||||
beq .endKey
|
|
||||||
cmp #$5B ; '[' ends the parsing
|
|
||||||
beq .doneParsing
|
|
||||||
sta gKey,x
|
|
||||||
inx
|
|
||||||
bra .gatherKey
|
|
||||||
.endKey stx gKeyLen
|
|
||||||
ldx #$00 ; X = index into the current value
|
|
||||||
.gatherValue
|
|
||||||
stx gValLen
|
|
||||||
jsr IncAndGetChar
|
|
||||||
cmp #$00 ; null ends the value
|
|
||||||
beq .endValue
|
|
||||||
and #$7F
|
|
||||||
sta gVal,x
|
|
||||||
inx
|
|
||||||
bra .gatherValue
|
|
||||||
.endValue
|
|
||||||
stx gValLen
|
|
||||||
phy ; okvs functions clobber everything but we need Y
|
|
||||||
jsr okvs_append
|
|
||||||
!word gVersionsStore
|
|
||||||
!word gKeyLen
|
|
||||||
!word gValLen
|
|
||||||
!byte 0
|
!byte 0
|
||||||
ply
|
|
||||||
bra .newKey
|
lda SRC ; save pointer to free space for next store
|
||||||
.doneParsing
|
sta gOptionsStore
|
||||||
|
lda SRC+1
|
||||||
|
sta gOptionsStore+1
|
||||||
|
|
||||||
|
jsr ParseKeyValueText ; parse [options] section into options store
|
||||||
|
!word gOptionsStore
|
||||||
|
!word addrOptions
|
||||||
|
!byte 0
|
||||||
|
|
||||||
rts
|
rts
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,78 +53,24 @@ kLastPlayed
|
||||||
LoadGlobalPreferences
|
LoadGlobalPreferences
|
||||||
stz gNeedToSavePrefs
|
stz gNeedToSavePrefs
|
||||||
|
|
||||||
jsr okvs_init
|
|
||||||
!word gGlobalPrefsStore
|
|
||||||
|
|
||||||
jsr LoadFile ; load prefs file at $2000
|
jsr LoadFile ; load prefs file at $2000
|
||||||
!word .globalPrefsFilename
|
!word .globalPrefsFilename
|
||||||
|
.prefsAddress
|
||||||
!word $2000
|
!word $2000
|
||||||
!word $2000
|
!word $2000
|
||||||
!word kProDOSFileBuffer
|
!word kProDOSFileBuffer
|
||||||
|
|
||||||
lda #$FF
|
jsr ParseKeyValueText ; parse contents into global prefs store
|
||||||
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
|
|
||||||
stx gKeyLen
|
|
||||||
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
|
|
||||||
sta gKey,x
|
|
||||||
inx
|
|
||||||
bra .gatherKey
|
|
||||||
.endKey stx gKeyLen
|
|
||||||
txa ; to set Z flag
|
|
||||||
beq .doneParsing ; empty key ends the parsing
|
|
||||||
ldx #$00 ; X = index into the current value
|
|
||||||
.gatherValue
|
|
||||||
stx gValLen
|
|
||||||
jsr IncAndGetChar
|
|
||||||
cmp #$0D ; CR ends the value
|
|
||||||
beq .endValue
|
|
||||||
sta gVal,x
|
|
||||||
inx
|
|
||||||
bra .gatherValue
|
|
||||||
.endValue
|
|
||||||
stx gValLen
|
|
||||||
lda gValLen
|
|
||||||
cmp #1
|
|
||||||
bne .use16
|
|
||||||
lda gVal
|
|
||||||
and #1
|
|
||||||
sta gVal ; single-character values get converted to #$00 or #$01 in prefs store
|
|
||||||
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
|
|
||||||
jsr okvs_append
|
|
||||||
!word gGlobalPrefsStore
|
!word gGlobalPrefsStore
|
||||||
!word gKeyLen
|
!word .prefsAddress
|
||||||
!word gValLen
|
!byte 16
|
||||||
.okvslen !byte $FD ; set at runtime
|
|
||||||
ply
|
|
||||||
bra .newKey
|
|
||||||
|
|
||||||
.skipComment ; skip to CR
|
lda SRC ; save pointer to free space for next store
|
||||||
jsr IncAndGetChar
|
|
||||||
cmp #$0D ; CR
|
|
||||||
bne .skipComment
|
|
||||||
bra .newKey
|
|
||||||
|
|
||||||
.doneParsing
|
|
||||||
lda SRC
|
|
||||||
sta gVersionsStore
|
sta gVersionsStore
|
||||||
lda SRC+1
|
lda SRC+1
|
||||||
sta gVersionsStore+1
|
sta gVersionsStore+1
|
||||||
jsr okvs_get
|
|
||||||
|
jsr okvs_get ; set gCurrentGame
|
||||||
!word gGlobalPrefsStore
|
!word gGlobalPrefsStore
|
||||||
!word kLastPlayed
|
!word kLastPlayed
|
||||||
sta DEST
|
sta DEST
|
||||||
|
@ -308,7 +254,7 @@ addString
|
||||||
.fluff3 !byte 58
|
.fluff3 !byte 58
|
||||||
!byte $0D
|
!byte $0D
|
||||||
!raw "# key=game directory, value=filename of selected version",$0D
|
!raw "# key=game directory, value=filename of selected version",$0D
|
||||||
.eof !byte 6
|
.eof !byte 7
|
||||||
!byte $0D
|
!byte $0D
|
||||||
!raw "=EOF",$0D
|
!raw "[eof]",$0D
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,7 +185,6 @@ paintInfoView
|
||||||
lda (SRC)
|
lda (SRC)
|
||||||
tay
|
tay
|
||||||
- lda (SRC),y
|
- lda (SRC),y
|
||||||
ora #$80
|
|
||||||
sta $3F00,y
|
sta $3F00,y
|
||||||
dey
|
dey
|
||||||
bne -
|
bne -
|
||||||
|
|
Loading…
Reference in New Issue
Block a user