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_update(address, key, value) update key/value pair
; - okvs_get(address, key) get value by key lookup ; - okvs_get(address, key) get value by key lookup
; - okvs_nth(address, n) get key by numeric index ; - 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(address, callback) iterate through keys
; - okvs_iter_values(address, callback) iterate through values ; - okvs_iter_values(address, callback) iterate through values
; ;
@ -288,6 +289,7 @@ okvs_get
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; okvs_nth ; okvs_nth
; get (N)th key
; ;
; in: stack contains 3 bytes of parameters: ; in: stack contains 3 bytes of parameters:
; +1 [word] handle to storage space ; +1 [word] handle to storage space
@ -315,6 +317,37 @@ okvs_nth
+LDAY PTR +LDAY PTR
rts 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 ; okvs_update
; ;

View File

@ -4,11 +4,10 @@
; Parser for global preferences file ; Parser for global preferences file
; ;
; Public functions ; Public functions
; - SaveGlobalPreferences ; - pref_get
; - pref_set
; ;
; Public constants (all length-prefixed strings) ; Public constants (all length-prefixed strings)
; - kGlobalPrefsFilename
; - kLastPlayed
; - kNextAttract ; - kNextAttract
; - kNextFX ; - kNextFX
; - kNextDFX ; - kNextDFX
@ -20,9 +19,7 @@ kGlobalPrefsFilename
!byte 10 !byte 10
!raw "PREFS.CONF" !raw "PREFS.CONF"
kLastPlayed ; valid pref keys
!byte 10
!raw "LASTPLAYED"
kNextAttract kNextAttract
!byte 11 !byte 11
!raw "NEXTATTRACT" !raw "NEXTATTRACT"
@ -34,33 +31,111 @@ kNextDFX
!raw "NEXTDFX" !raw "NEXTDFX"
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; SaveGlobalPreferences ; pref_get
; save global options and state to file ; get pref value by pref key, and validate that the pref value exists as a key
; in another OKVS
; ;
; in: none ; example usage:
; out: all registers and flags clobbered ; jsr pref_get
; $00/$01/$FE/$FF clobbered ; !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 pref_get
+LDADDR kGlobalPrefsBuffer +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 +STAY $FE
ldx #$02
ldy #$00
tya
- sta ($FE),y
iny
bne -
inc $FF
dex
bne -
dec $FF
dec $FF
+LDADDR @kFluff1 +LDADDR @kFluff1 ; serialize prefs into prefs buffer
jsr @addString
+LDADDR kLastPlayed
jsr @addStringFromStore
+LDADDR @kFluff2
jsr @addString jsr @addString
+LDADDR kNextAttract +LDADDR kNextAttract
jsr @addStringFromStore jsr @addStringFromStore
+LDADDR @kFluff3 +LDADDR @kFluff2
jsr @addString jsr @addString
+LDADDR kNextFX +LDADDR kNextFX
jsr @addStringFromStore jsr @addStringFromStore
+LDADDR @kFluff4 +LDADDR @kFluff3
jsr @addString jsr @addString
+LDADDR kNextDFX +LDADDR kNextDFX
jsr @addStringFromStore jsr @addStringFromStore
@ -68,7 +143,7 @@ SaveGlobalPreferences
+LDADDR @kEOF +LDADDR @kEOF
jsr @addString jsr @addString
+LDADDR kGlobalPrefsFilename +LDADDR kGlobalPrefsFilename ; write prefs buffer to file on disk
jsr SetPath jsr SetPath
jsr SaveSmallFile jsr SaveSmallFile
!word kGlobalPrefsBuffer !word kGlobalPrefsBuffer
@ -115,14 +190,11 @@ SaveGlobalPreferences
!raw "# Do not edit by hand.",$0D !raw "# Do not edit by hand.",$0D
!raw "# Or do. I'm a comment, not a cop.",$0D !raw "# Or do. I'm a comment, not a cop.",$0D
!byte $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 @kFluff2 !byte @kFluff3-*-1
!byte $0D
!raw "# value=attract mode module listed in ATTRACT.CONF, or empty",$0D
@kFluff3 !byte @kFluff4-*-1
!byte $0D !byte $0D
!raw "# value=transition effect listed in FX.CONF, or empty",$0D !raw "# value=transition effect listed in FX.CONF, or empty",$0D
@kFluff4 !byte @kEOF-*-1 @kFluff3 !byte @kEOF-*-1
!byte $0D !byte $0D
!raw "# value=transition effect listed in DFX.CONF, or empty",$0D !raw "# value=transition effect listed in DFX.CONF, or empty",$0D
@kEOF !byte @_-*-1 @kEOF !byte @_-*-1

View File

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

View File

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

View File

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