prefs refactor

This commit is contained in:
4am 2019-09-16 12:36:10 -04:00
parent bb335602cc
commit 03a90947de
6 changed files with 164 additions and 144 deletions

View File

@ -1 +1 @@
# 4cade preferences file # Do not edit by hand. # Or do. I'm a comment, not a cop. # value=game directory listed in GAMES.CONF, or empty LASTPLAYED= # value=attract mode module listed in ATTRACT.CONF, or empty NEXTATTRACT= # value=transition effect listed in FX.CONF, or empty NEXTFX= # value=transition effect listed in DFX.CONF, or empty NEXTDFX= [eof]
# Total Replay preferences file # Do not edit by hand. # Or do. I'm a comment, not a cop. # value=attract mode module listed in ATTRACT.CONF, or empty NEXTATTRACT= # value=transition effect listed in FX.CONF, or empty NEXTFX= # value=transition effect listed in DFX.CONF, or empty NEXTDFX= [eof]

View File

@ -10,6 +10,7 @@
; - okvs_update(address, key, value) update key/value pair
; - okvs_get(address, key) get value by key lookup
; - okvs_nth(address, n) get key by numeric index
; - okvs_next(address, n) get next key by numeric index
; - okvs_iter(address, callback) iterate through keys
; - okvs_iter_values(address, callback) iterate through values
;
@ -288,6 +289,7 @@ okvs_get
;------------------------------------------------------------------------------
; okvs_nth
; get (N)th key
;
; in: stack contains 3 bytes of parameters:
; +1 [word] handle to storage space
@ -315,6 +317,37 @@ okvs_nth
+LDAY PTR
rts
;------------------------------------------------------------------------------
; okvs_next
; get (N+1)th key, with wraparound
;
; in: A/Y = handle to storage space
; X = record index
; out: A/Y = lo/hi address of (X+1)th key, or first key if X was the last record
; all other registers and flags clobbered
; PARAM clobbered
; PTR clobbered
; SRC clobbered
; SAVE clobbered
;------------------------------------------------------------------------------
okvs_next
+STAY @store1
+STAY @store2
inx
stx SAVE
jsr okvs_len
@store1 !word $FDFD ; SMC
cmp SAVE
beq +
lda SAVE
+HIDE_NEXT_2_BYTES
+ lda #0
sta @n
jsr okvs_nth
@store2 !word $FDFD ; SMC
@n !byte $FD ; SMC
rts
;------------------------------------------------------------------------------
; okvs_update
;

View File

@ -4,11 +4,10 @@
; Parser for global preferences file
;
; Public functions
; - SaveGlobalPreferences
; - pref_get
; - pref_set
;
; Public constants (all length-prefixed strings)
; - kGlobalPrefsFilename
; - kLastPlayed
; - kNextAttract
; - kNextFX
; - kNextDFX
@ -20,9 +19,7 @@ kGlobalPrefsFilename
!byte 10
!raw "PREFS.CONF"
kLastPlayed
!byte 10
!raw "LASTPLAYED"
; valid pref keys
kNextAttract
!byte 11
!raw "NEXTATTRACT"
@ -34,33 +31,111 @@ kNextDFX
!raw "NEXTDFX"
;------------------------------------------------------------------------------
; SaveGlobalPreferences
; save global options and state to file
; pref_get
; get pref value by pref key, and validate that the pref value exists as a key
; in another OKVS
;
; in: none
; out: all registers and flags clobbered
; $00/$01/$FE/$FF clobbered
; example usage:
; jsr pref_get
; !word kNextFX
; !word gFXStore
;
; See above for list of valid pref keys.
;
; The OKVS you pass in as the second parameter must have at least 1 record.
; This is not checked.
;
; in: stack contains 4 bytes of parameters:
; +1 [word] address of length-prefixed pref key
; +3 [word] address of OKVS
; gGlobalPrefsStore must be initialized (this is done in 4cade.init)
; out: A/Y = address of pref value
; X = index of pref value in passed store
; PARAM clobbered
; PTR clobbered
; SRC clobbered
; SAVE clobbered
;------------------------------------------------------------------------------
SaveGlobalPreferences
+LDADDR kGlobalPrefsBuffer
pref_get
+PARAMS_ON_STACK 4
+LDPARAM 1
+STAY @prefkey
+LDPARAM 3
+STAY @store1
+STAY @store2
jsr okvs_get ; look up pref key in prefs store
!word gGlobalPrefsStore
@prefkey !word $FDFD ; SMC
bcs .useDefaultValue ; if pref key is not found, use default value
+STAY +
+STAY PTR
ldy #0
lda (PTR),y
beq .useDefaultValue ; if pref value is empty, use default value
jsr okvs_get ; check whether the pref value exists as a key in the passed-in store
@store1 !word $FDFD ; SMC
+ !word $FDFD ; SMC
bcc +
.useDefaultValue ; find first key in passed store and use that as a default value
ldx #0
+ stx @n
jsr okvs_nth
@store2 !word $FDFD ; SMC
@n !byte $FD ; SMC
ldx @n
rts
;------------------------------------------------------------------------------
; pref_set
; set pref value by pref key, serialize prefs, and write them to disk
;
; in: stack contains 4 bytes of parameters:
; +1 [word] address of length-prefixed pref key
; +3 [word] address of length-prefixed pref value
; out: all registers and flags clobbered
; PARAM clobbered
; PTR clobbered
; SRC clobbered
; $FE/$FF clobbered
;------------------------------------------------------------------------------
pref_set
+PARAMS_ON_STACK 4
+LDPARAM 1
+STAY @prefkey
+LDPARAM 3
+STAY @prefval
jsr okvs_update ; save that in prefs store
!word gGlobalPrefsStore
@prefkey !word $FDFD ; SMC
@prefval !word $FDFD ; SMC
+LDADDR kGlobalPrefsBuffer ; clear prefs buffer
+STAY $FE
ldx #$02
ldy #$00
tya
- sta ($FE),y
iny
bne -
inc $FF
dex
bne -
dec $FF
dec $FF
+LDADDR @kFluff1
jsr @addString
+LDADDR kLastPlayed
jsr @addStringFromStore
+LDADDR @kFluff2
+LDADDR @kFluff1 ; serialize prefs into prefs buffer
jsr @addString
+LDADDR kNextAttract
jsr @addStringFromStore
+LDADDR @kFluff3
+LDADDR @kFluff2
jsr @addString
+LDADDR kNextFX
jsr @addStringFromStore
+LDADDR @kFluff4
+LDADDR @kFluff3
jsr @addString
+LDADDR kNextDFX
jsr @addStringFromStore
@ -68,7 +143,7 @@ SaveGlobalPreferences
+LDADDR @kEOF
jsr @addString
+LDADDR kGlobalPrefsFilename
+LDADDR kGlobalPrefsFilename ; write prefs buffer to file on disk
jsr SetPath
jsr SaveSmallFile
!word kGlobalPrefsBuffer
@ -115,14 +190,11 @@ SaveGlobalPreferences
!raw "# Do not edit by hand.",$0D
!raw "# Or do. I'm a comment, not a cop.",$0D
!byte $0D
!raw "# value=game directory listed in GAMES.CONF, or empty",$0D
!raw "# value=attract mode module listed in ATTRACT.CONF, or empty",$0D
@kFluff2 !byte @kFluff3-*-1
!byte $0D
!raw "# value=attract mode module listed in ATTRACT.CONF, or empty",$0D
@kFluff3 !byte @kFluff4-*-1
!byte $0D
!raw "# value=transition effect listed in FX.CONF, or empty",$0D
@kFluff4 !byte @kEOF-*-1
@kFluff3 !byte @kEOF-*-1
!byte $0D
!raw "# value=transition effect listed in DFX.CONF, or empty",$0D
@kEOF !byte @_-*-1

View File

@ -68,55 +68,28 @@ DHGRSingle
!word -
!byte 0
jsr okvs_get ; get next DHGR transition effect from prefs
!word gGlobalPrefsStore
jsr pref_get ; get DHGR transition effect from prefs
!word kNextDFX
bcs @nodfx
+STAY @dfx
jsr okvs_get
!word gDFXStore
@dfx !word $FDFD ; SMC
bcc +
@nodfx ldx #0
+ stx gDFXIndex
+STAY @filename ; A/Y = filename (don't load file yet)
; X = index of the transition in DFX store
jsr okvs_nth ; get filename of DHGR transition effect code
!word gDFXStore
gDFXIndex
!byte 0
+STAY @dfxkey
+LDADDR gDFXStore
jsr okvs_next ; get transition after this one
+STAY +
inc gDFXIndex ; increment transition effect index for next time
jsr okvs_len
!word gDFXStore
cmp gDFXIndex
bne +
lda #0
sta gDFXIndex
+
lda gDFXIndex
sta @nexti
jsr okvs_nth ; get name of next DHGR transition
!word gDFXStore
@nexti !byte $FD ; SMC
+STAY @nextdfx
jsr okvs_update ; save name of next DHGR transition in prefs store
!word gGlobalPrefsStore
jsr pref_set ; update prefs store and save to disk
!word kNextDFX
@nextdfx !word $FDFD ; SMC
+ !word $FDFD ; SMC
jsr SaveGlobalPreferences ; write prefs store to disk
jsr LoadFile ; load transition effect code into $6000
jsr LoadFile ; now load transition effect code into $6000
!word kFXDirectory
@dfxkey !word $FDFD ; SMC
@filename !word $FDFD ; SMC
!word $6000
rts
kDFXConfFile
!byte @kDFXConfFile_e-*-1
!byte 8
!text "DFX.CONF"
@kDFXConfFile_e
;------------------------------------------------------------------------------
; .DHGRTitleCallback [private]

View File

@ -172,49 +172,23 @@ HGRSingle
!word -
!byte 0
jsr okvs_get ; get next HGR transition effect from prefs
!word gGlobalPrefsStore
jsr pref_get ; get HGR transition effect from prefs
!word kNextFX
bcs @nofx
+STAY @fx
jsr okvs_get
!word gFXStore
@fx !word $FDFD ; SMC
bcc +
@nofx ldx #0
+ stx gFXIndex
+STAY @filename ; A/Y = filename (don't load file yet)
; X = index of the transition in FX store
jsr okvs_nth ; get filename of transition effect code
!word gFXStore
gFXIndex
!byte 0
+STAY @fxkey
+LDADDR gFXStore
jsr okvs_next ; get transition after this one
+STAY +
inc gFXIndex ; increment transition effect index
jsr okvs_len
!word gFXStore
cmp gFXIndex
bne +
lda #0
sta gFXIndex
+
lda gFXIndex
sta @nexti
jsr okvs_nth ; get name of next HGR transition
!word gFXStore
@nexti !byte $FD ; SMC
+STAY @nextfx
jsr okvs_update ; save name of next HGR transition in prefs store
!word gGlobalPrefsStore
jsr pref_set ; update prefs store and save to disk
!word kNextFX
@nextfx !word $FDFD ; SMC
+ !word $FDFD ; SMC
jsr SaveGlobalPreferences ; write prefs store to disk
jsr LoadFile ; load transition effect code into $6000
jsr LoadFile ; now load transition effect code into $6000
!word kFXDirectory
@fxkey !word $FDFD ; SMC
@filename !word $FDFD ; SMC
!word $6000
rts
kFXConfFile

View File

@ -26,59 +26,27 @@ MegaAttractMode
jsr LoadAndParseAttractModeConf
jsr okvs_get ; get next attract-mode module from prefs
!word gGlobalPrefsStore
jsr pref_get ; get attract mode module from prefs
!word kNextAttract
bcs @noattract
+STAY @attract
jsr okvs_get
!word gAttractModeStore
@attract !word $FDFD ; SMC
bcc +
@noattract
ldx #0
+ stx @attractIndex
+STAY @mname ; A/Y = module name
; X = index of module in attract store
+LDADDR gAttractModeStore
jsr okvs_next ; get module after this one
+STAY +
jsr okvs_nth ; get filename of next attract-mode module
!word gAttractModeStore
@attractIndex
!byte 0
+STAY @key
lda @attractIndex
sta gCurrentAttractIndex
inc @attractIndex ; increment module index for next time
jsr okvs_len
!word gAttractModeStore
cmp @attractIndex
bne +
lda #0
sta @attractIndex
+
lda @attractIndex
sta @nexti
jsr okvs_nth ; get name of next attract-mode module
!word gAttractModeStore
@nexti !byte $FD ; SMC
+STAY @nextattract
jsr okvs_update ; save name of next attract-mode module in prefs store
!word gGlobalPrefsStore
jsr pref_set ; update prefs store and save to disk
!word kNextAttract
@nextattract
!word $FDFD ; SMC
jsr SaveGlobalPreferences ; write prefs store to disk
+ !word $FDFD ; SMC
jsr okvs_get
!word gAttractModeStore
@key !word $FDFD ; SMC
@mname !word $FDFD ; SMC
+STAY PTR
ldy #1
lda (PTR),y
tax ; X = module type
+LDAY @key ; A/Y = address of module name
+LDAY @mname ; A/Y = address of module name
jsr RunAttractModule
lda KBD
bpl @jmpattract