pitch-dark/src/parse.gameinfo.a
2018-04-11 15:12:36 -04:00

196 lines
5.6 KiB
Plaintext

;license:MIT
;(c) 2018 by 4am
;
; Parser for per-game configuration files
;
; Public functions
; - LoadGameInfo
; - CheckForSavedGames
;
; Public variables
; - gHasSavedGames 0=false, 1=true (set in CheckForSavedGames)
;
; Public constants (keys in gOptionsStore)
; - kHasArtwork
; - kHasHints
; - kHasVersions
kTextRootDirectory
!byte 5
!raw "TEXT/"
gVersionsStore
!word $FDFD ; set in LoadGlobalPreferences
gOptionsStore
!word $FDFD ; set in LoadGameInfo
gHasSavedGames
!byte 0
kHasArtwork
!byte 7
!raw "ARTWORK"
kHasHints
!byte 5
!raw "CLUES"
kHasVersions
!byte 8
!raw "VERSIONS"
sectionPointers ; array of pointers to start of each section
addrEOF
!word 0
addrOptions
!word 0
addrVersions
!word 0
addrDescription
!word 0
addrInfo
!word 0
;------------------------------------------------------------------------------
; LoadGameInfo
; load file with information about the current game
;
; in: current ProDOS prefix is the same as the PITCH.DARK binary
; out: addrInfo, addrDescription, addrVersions, addrOptions populated
; gVersionsStore populated with keys/values in [versions] section
; gOptionsStore populated with keys/values in [options] section
; all registers and flags clobbered
; $00..$05 clobbered
; $0800..$1FFF clobbered
;------------------------------------------------------------------------------
!zone {
LoadGameInfo
jsr ResetPath
+LDADDR kTextRootDirectory
jsr AddToPath
jsr okvs_get
!word gGlobalPrefsStore
!word kLastPlayed
jsr AddToPath
jsr LoadFile
!word gPathname
!word kGameInfoBuffer
!word kProDOSFileBuffer
+LDADDR (kGameInfoBuffer-1)
+STAY $FE ; ($FE) points to start of data buffer
ldy #$00 ; index into ($FE) pointing to current character
ldx #$08 ; index into sectionPointers array, stores pointer to start of each section
.convertSectionLoop
jsr IncAndGetChar
.convertSectionNoInc
cmp #$5B ; '[' is the start of a new section
beq .skipSectionName
cmp #$0D ; CR -> 0x00 (WeeGUI wants null-terminated strings)
beq .null
cmp #$5E ; '^' -> closed-apple mousetext
beq .ca
cmp #$26 ; '&' -> open-apple mousetext
beq .oa
ora #$80 ; all other characters -> set high bit
!byte $2C
.null lda #$00
!byte $2C
.ca lda #$40
!byte $2C
.oa lda #$41
sta ($FE),y
bra .convertSectionLoop
; We found the start of a new section, so skip to the first character on the next line
.skipSectionName
jsr IncAndGetChar
cmp #$0D ; CR
bne .skipSectionName
jsr IncAndGetChar
; We are at the start of a section, so save this address in the sectionPointers array
pha
tya
clc
adc $FE
sta sectionPointers,x
lda $FF
bcc +
inc
+ sta sectionPointers+1,x
pla
dex
dex
bpl .convertSectionNoInc
; We are done converting the game info file.
; Now handle the individual sections that require further parsing.
jsr ParseKeyValueText ; parse [versions] section into gVersionsStore
!word gVersionsStore ; (this handle was initialized in LoadGlobalPreferences)
!word addrVersions
!byte 0
+LDAY SRC
+STAY gOptionsStore ; save pointer to free space for next store
jsr ParseKeyValueText ; parse [options] section into gOptionsStore
!word gOptionsStore
!word addrOptions
!byte 0
; execution falls through here
CheckForSavedGames
jsr okvs_get ; get shortname of current game
!word gGlobalPrefsStore
!word kLastPlayed
+STAY + ; A/Y contains address
jsr okvs_get ; get selected version of this game
!word gGlobalPrefsStore
+ !word $FDFD ; SMC
+STAY SRC ; A/Y contains address
lda (SRC)
dec
tay
phy
- lda (SRC),y
sta gVal,y
dey
bpl -
ply
lda #$53 ; add new suffix ('SAV')
sta gVal,y
iny
lda #$41
sta gVal,y
iny
lda #$56
sta gVal,y
inc gVal ; fix string length
jsr ResetPath
+LDADDR kGameRootDirectory
jsr AddToPath
jsr okvs_get
!word gGlobalPrefsStore
!word kLastPlayed
jsr AddToPath
+LDADDR kPathSeparator
jsr AddToPath
+LDADDR gVal
jsr AddToPath
jsr GetFileInfo
!word gPathname
bcs .no ; no file -> no saved games
lda blocks+1
bne .yes ; file exists and is quite large -> assume saved games
lda blocks
cmp #$06 ; file exists but is small -> no saved games (.Z4/.Z5 files have a 5 block 'empty' .sav file)
bcc .no
.yes lda #1
!byte $2C
.no lda #0
sta gHasSavedGames
rts
}