2018-02-07 14:05:24 +00:00
|
|
|
;license:MIT
|
|
|
|
;(c) 2018 by 4am
|
|
|
|
;
|
2018-03-27 21:00:02 +00:00
|
|
|
; Parser for per-game configuration files
|
2018-02-07 14:05:24 +00:00
|
|
|
;
|
|
|
|
; Public functions
|
|
|
|
; - LoadGameInfo
|
2018-04-11 19:12:36 +00:00
|
|
|
; - CheckForSavedGames
|
2018-02-07 14:05:24 +00:00
|
|
|
;
|
2018-04-01 16:21:48 +00:00
|
|
|
; Public variables
|
2018-04-18 19:28:55 +00:00
|
|
|
; - gHasSavedGames byte 0=false, nonzero=true (set in CheckForSavedGames)
|
|
|
|
; - gLastSavedGameSlot byte 0-7 (only valid if gHasSavedGames=1)
|
2018-04-01 16:21:48 +00:00
|
|
|
;
|
|
|
|
; Public constants (keys in gOptionsStore)
|
|
|
|
; - kHasArtwork
|
|
|
|
; - kHasHints
|
|
|
|
; - kHasVersions
|
2018-02-07 14:05:24 +00:00
|
|
|
|
2018-02-08 17:00:20 +00:00
|
|
|
kTextRootDirectory
|
2018-02-03 17:01:34 +00:00
|
|
|
!byte 5
|
2018-02-08 17:00:20 +00:00
|
|
|
!raw "TEXT/"
|
2018-04-01 16:21:48 +00:00
|
|
|
kHasArtwork
|
|
|
|
!byte 7
|
|
|
|
!raw "ARTWORK"
|
|
|
|
kHasHints
|
|
|
|
!byte 5
|
|
|
|
!raw "CLUES"
|
|
|
|
kHasVersions
|
|
|
|
!byte 8
|
|
|
|
!raw "VERSIONS"
|
2018-03-28 02:40:09 +00:00
|
|
|
|
2018-04-19 02:41:02 +00:00
|
|
|
gVersionsStore
|
|
|
|
!word $FDFD ; set in LoadGlobalPreferences
|
|
|
|
gOptionsStore
|
|
|
|
!word $FDFD ; set in LoadGameInfo
|
|
|
|
gHasSavedGames
|
|
|
|
!byte $FD ; set in CheckForSavedGames
|
|
|
|
gLastSavedGameSlot
|
|
|
|
!byte $FD ; set in CheckForSavedGames
|
|
|
|
|
2018-03-03 22:45:39 +00:00
|
|
|
sectionPointers ; array of pointers to start of each section
|
2018-03-03 23:07:13 +00:00
|
|
|
addrEOF
|
2018-04-19 02:41:02 +00:00
|
|
|
!word $FDFD
|
2018-03-03 23:07:13 +00:00
|
|
|
addrOptions
|
2018-04-19 02:41:02 +00:00
|
|
|
!word $FDFD
|
2018-03-03 22:45:39 +00:00
|
|
|
addrVersions
|
2018-04-19 02:41:02 +00:00
|
|
|
!word $FDFD
|
2018-02-07 14:05:24 +00:00
|
|
|
addrDescription
|
2018-04-19 02:41:02 +00:00
|
|
|
!word $FDFD
|
2018-03-03 22:45:39 +00:00
|
|
|
addrInfo
|
2018-04-19 02:41:02 +00:00
|
|
|
!word $FDFD
|
2018-02-07 14:05:24 +00:00
|
|
|
|
2018-06-18 23:10:53 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; FlushSaveInfo
|
|
|
|
; update aux data for the current game save-slot if needed
|
|
|
|
;
|
|
|
|
; in: current ProDOS prefix is the same as the PITCH.DARK binary
|
|
|
|
; out: all registers and flags clobbered
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
FlushSaveInfo
|
|
|
|
lda $50
|
|
|
|
cmp #$50
|
|
|
|
bne +
|
|
|
|
lda $51
|
|
|
|
cmp #$44
|
|
|
|
bne +
|
|
|
|
dec $50 ; prevent re-check in future
|
|
|
|
lda $52
|
|
|
|
sta @slot
|
|
|
|
jsr SetStartupPathToCurrentVersionOfCurrentGame
|
|
|
|
ldx gPathname
|
|
|
|
lda #'S'
|
|
|
|
sta gPathname-1,x
|
|
|
|
lda #'A'
|
|
|
|
sta gPathname,x
|
|
|
|
lda #'V'
|
|
|
|
sta gPathname+1,x
|
|
|
|
inc gPathname
|
|
|
|
jsr SetAuxFileType ; best-effort
|
|
|
|
!word gPathname
|
|
|
|
@slot !word 0
|
|
|
|
+ rts
|
|
|
|
|
2018-02-07 14:05:24 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; LoadGameInfo
|
|
|
|
; load file with information about the current game
|
|
|
|
;
|
2018-03-28 18:09:39 +00:00
|
|
|
; in: current ProDOS prefix is the same as the PITCH.DARK binary
|
2018-03-03 23:07:13 +00:00
|
|
|
; out: addrInfo, addrDescription, addrVersions, addrOptions populated
|
2018-03-28 15:48:47 +00:00
|
|
|
; gVersionsStore populated with keys/values in [versions] section
|
|
|
|
; gOptionsStore populated with keys/values in [options] section
|
2018-03-03 22:45:39 +00:00
|
|
|
; all registers and flags clobbered
|
2018-03-28 15:48:47 +00:00
|
|
|
; $00..$05 clobbered
|
|
|
|
; $0800..$1FFF clobbered
|
2018-02-07 14:05:24 +00:00
|
|
|
;------------------------------------------------------------------------------
|
2018-02-03 17:01:34 +00:00
|
|
|
LoadGameInfo
|
2018-02-07 21:02:14 +00:00
|
|
|
jsr ResetPath
|
2018-03-29 02:49:51 +00:00
|
|
|
+LDADDR kTextRootDirectory
|
2018-02-07 21:02:14 +00:00
|
|
|
jsr AddToPath
|
2018-03-28 15:48:47 +00:00
|
|
|
jsr okvs_get
|
|
|
|
!word gGlobalPrefsStore
|
|
|
|
!word kLastPlayed
|
2018-02-07 21:02:14 +00:00
|
|
|
jsr AddToPath
|
2018-02-05 15:04:35 +00:00
|
|
|
|
|
|
|
jsr LoadFile
|
2018-02-07 21:02:14 +00:00
|
|
|
!word gPathname
|
2018-03-30 17:43:48 +00:00
|
|
|
!word kGameInfoBuffer
|
2018-02-09 01:38:26 +00:00
|
|
|
!word kProDOSFileBuffer
|
2018-02-05 17:17:06 +00:00
|
|
|
|
2018-03-30 17:43:48 +00:00
|
|
|
+LDADDR (kGameInfoBuffer-1)
|
|
|
|
+STAY $FE ; ($FE) points to start of data buffer
|
|
|
|
ldy #$00 ; index into ($FE) pointing to current character
|
2018-03-03 23:07:13 +00:00
|
|
|
ldx #$08 ; index into sectionPointers array, stores pointer to start of each section
|
2018-03-03 22:45:39 +00:00
|
|
|
|
2018-04-19 14:05:48 +00:00
|
|
|
@convertSectionLoop
|
2018-03-03 22:45:39 +00:00
|
|
|
jsr IncAndGetChar
|
2018-04-19 14:05:48 +00:00
|
|
|
@convertSectionNoInc
|
2018-03-03 22:53:50 +00:00
|
|
|
cmp #$5B ; '[' is the start of a new section
|
2018-04-19 14:05:48 +00:00
|
|
|
beq @skipSectionName
|
2018-03-27 19:19:48 +00:00
|
|
|
cmp #$0D ; CR -> 0x00 (WeeGUI wants null-terminated strings)
|
2018-04-19 14:05:48 +00:00
|
|
|
beq @null
|
2018-02-08 21:28:49 +00:00
|
|
|
cmp #$5E ; '^' -> closed-apple mousetext
|
2018-04-19 14:05:48 +00:00
|
|
|
beq @ca
|
2018-03-03 22:45:39 +00:00
|
|
|
cmp #$26 ; '&' -> open-apple mousetext
|
2018-04-19 14:05:48 +00:00
|
|
|
beq @oa
|
2018-03-03 22:53:50 +00:00
|
|
|
ora #$80 ; all other characters -> set high bit
|
2018-04-18 02:28:22 +00:00
|
|
|
+HIDE_NEXT_2_BYTES
|
2018-04-19 14:05:48 +00:00
|
|
|
@null lda #$00
|
2018-04-18 02:28:22 +00:00
|
|
|
+HIDE_NEXT_2_BYTES
|
2018-04-19 14:05:48 +00:00
|
|
|
@ca lda #$40
|
2018-04-18 02:28:22 +00:00
|
|
|
+HIDE_NEXT_2_BYTES
|
2018-04-19 14:05:48 +00:00
|
|
|
@oa lda #$41
|
2018-03-27 19:19:48 +00:00
|
|
|
sta ($FE),y
|
2018-04-19 14:05:48 +00:00
|
|
|
bra @convertSectionLoop
|
2018-03-03 22:45:39 +00:00
|
|
|
|
|
|
|
; We found the start of a new section, so skip to the first character on the next line
|
2018-04-19 14:05:48 +00:00
|
|
|
@skipSectionName
|
2018-03-03 22:45:39 +00:00
|
|
|
jsr IncAndGetChar
|
2018-03-27 19:19:48 +00:00
|
|
|
cmp #$0D ; CR
|
2018-04-19 14:05:48 +00:00
|
|
|
bne @skipSectionName
|
2018-03-03 22:45:39 +00:00
|
|
|
jsr IncAndGetChar
|
|
|
|
|
|
|
|
; We are at the start of a section, so save this address in the sectionPointers array
|
|
|
|
pha
|
2018-03-03 16:41:09 +00:00
|
|
|
tya
|
|
|
|
clc
|
2018-03-27 19:19:48 +00:00
|
|
|
adc $FE
|
2018-03-03 22:45:39 +00:00
|
|
|
sta sectionPointers,x
|
2018-03-27 19:19:48 +00:00
|
|
|
lda $FF
|
2018-03-03 16:41:09 +00:00
|
|
|
bcc +
|
|
|
|
inc
|
2018-03-03 22:45:39 +00:00
|
|
|
+ sta sectionPointers+1,x
|
2018-02-05 17:17:06 +00:00
|
|
|
pla
|
2018-03-03 22:45:39 +00:00
|
|
|
dex
|
|
|
|
dex
|
2018-04-19 14:05:48 +00:00
|
|
|
bpl @convertSectionNoInc
|
2018-03-03 22:45:39 +00:00
|
|
|
|
2018-03-28 14:44:47 +00:00
|
|
|
; 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)
|
2018-03-28 14:42:37 +00:00
|
|
|
!word addrVersions
|
|
|
|
!byte 0
|
2018-03-28 02:40:09 +00:00
|
|
|
|
2018-03-29 02:49:51 +00:00
|
|
|
+LDAY SRC
|
|
|
|
+STAY gOptionsStore ; save pointer to free space for next store
|
2018-03-28 14:42:37 +00:00
|
|
|
|
2018-03-28 14:44:47 +00:00
|
|
|
jsr ParseKeyValueText ; parse [options] section into gOptionsStore
|
2018-03-28 14:42:37 +00:00
|
|
|
!word gOptionsStore
|
|
|
|
!word addrOptions
|
2018-03-28 02:40:09 +00:00
|
|
|
!byte 0
|
2018-04-17 03:48:30 +00:00
|
|
|
|
|
|
|
+LDAY SRC
|
|
|
|
+STAY gSavedGamesStore ; save pointer to free space for next store
|
|
|
|
|
2018-04-11 19:12:36 +00:00
|
|
|
; execution falls through here
|
|
|
|
CheckForSavedGames
|
2018-03-31 14:59:02 +00:00
|
|
|
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
|
2018-03-31 16:38:51 +00:00
|
|
|
+STAY SRC ; A/Y contains address
|
|
|
|
|
|
|
|
lda (SRC)
|
|
|
|
dec
|
|
|
|
tay
|
|
|
|
phy
|
|
|
|
- lda (SRC),y
|
|
|
|
sta gVal,y
|
|
|
|
dey
|
|
|
|
bpl -
|
|
|
|
ply
|
2018-04-01 16:21:48 +00:00
|
|
|
lda #$53 ; add new suffix ('SAV')
|
2018-03-31 16:38:51 +00:00
|
|
|
sta gVal,y
|
|
|
|
iny
|
2018-04-01 16:21:48 +00:00
|
|
|
lda #$41
|
2018-03-31 16:38:51 +00:00
|
|
|
sta gVal,y
|
|
|
|
iny
|
2018-04-01 16:21:48 +00:00
|
|
|
lda #$56
|
2018-03-31 16:38:51 +00:00
|
|
|
sta gVal,y
|
|
|
|
inc gVal ; fix string length
|
2018-04-01 16:21:48 +00:00
|
|
|
|
2018-03-31 16:38:51 +00:00
|
|
|
jsr ResetPath
|
2018-04-01 16:21:48 +00:00
|
|
|
+LDADDR kGameRootDirectory
|
|
|
|
jsr AddToPath
|
|
|
|
jsr okvs_get
|
|
|
|
!word gGlobalPrefsStore
|
|
|
|
!word kLastPlayed
|
|
|
|
jsr AddToPath
|
|
|
|
+LDADDR kPathSeparator
|
|
|
|
jsr AddToPath
|
2018-03-31 16:38:51 +00:00
|
|
|
+LDADDR gVal
|
|
|
|
jsr AddToPath
|
2018-04-01 16:21:48 +00:00
|
|
|
jsr GetFileInfo
|
|
|
|
!word gPathname
|
2018-04-19 14:05:48 +00:00
|
|
|
bcs @no ; no file -> no saved games
|
2018-06-19 02:27:53 +00:00
|
|
|
lda auxtype ; if low byte of auxtype is $3x, then saved and x is the last save slot
|
2018-04-18 01:49:48 +00:00
|
|
|
and #$F0
|
|
|
|
cmp #$30
|
2018-06-19 02:27:53 +00:00
|
|
|
bne @no
|
|
|
|
@yes lda auxtype
|
2018-04-18 01:49:48 +00:00
|
|
|
and #$0F
|
|
|
|
sta gLastSavedGameSlot
|
|
|
|
lda #1
|
2018-04-18 02:28:22 +00:00
|
|
|
+HIDE_NEXT_2_BYTES
|
2018-04-19 14:05:48 +00:00
|
|
|
@no lda #0
|
2018-04-01 16:21:48 +00:00
|
|
|
sta gHasSavedGames
|
2018-02-03 17:01:34 +00:00
|
|
|
rts
|