2018-11-10 13:36:36 +00:00
|
|
|
;license:MIT
|
2020-03-17 01:58:05 +00:00
|
|
|
;(c) 2018-2020 by 4am
|
2018-11-10 13:36:36 +00:00
|
|
|
;
|
|
|
|
; Parser for global preferences file
|
|
|
|
;
|
|
|
|
; Public functions
|
2019-09-16 16:36:10 +00:00
|
|
|
; - pref_get
|
|
|
|
; - pref_set
|
2019-10-08 18:47:47 +00:00
|
|
|
; - SaveSmallFile
|
2018-11-10 13:36:36 +00:00
|
|
|
;
|
|
|
|
; Public constants (all length-prefixed strings)
|
|
|
|
; - kNextAttract
|
|
|
|
; - kNextFX
|
|
|
|
; - kNextDFX
|
2019-10-08 03:23:47 +00:00
|
|
|
; - kCheat
|
2018-11-10 13:36:36 +00:00
|
|
|
;
|
|
|
|
|
2019-01-04 17:23:27 +00:00
|
|
|
kGlobalPrefsBuffer = $8000
|
2018-11-10 15:08:14 +00:00
|
|
|
|
2019-09-16 16:36:10 +00:00
|
|
|
; valid pref keys
|
2018-11-10 13:36:36 +00:00
|
|
|
kNextAttract
|
|
|
|
!byte 11
|
|
|
|
!raw "NEXTATTRACT"
|
|
|
|
kNextFX
|
|
|
|
!byte 6
|
|
|
|
!raw "NEXTFX"
|
|
|
|
kNextDFX
|
|
|
|
!byte 7
|
|
|
|
!raw "NEXTDFX"
|
2019-09-16 17:36:48 +00:00
|
|
|
kCheat
|
|
|
|
!byte 5
|
|
|
|
!raw "CHEAT"
|
2018-11-10 13:36:36 +00:00
|
|
|
|
2019-10-08 17:19:20 +00:00
|
|
|
.kEquals !byte 1
|
|
|
|
!raw "="
|
2020-03-23 01:58:26 +00:00
|
|
|
.kLF !byte 1,$0A
|
2019-10-08 17:19:20 +00:00
|
|
|
.kFluff1 !byte .kFluff2-*-1
|
2020-03-23 01:58:26 +00:00
|
|
|
!raw "# Total Replay preferences file",$0A
|
|
|
|
!raw "# Do not edit by hand.",$0A
|
|
|
|
!raw "# Or do. I'm a comment, not a cop.",$0A
|
|
|
|
!byte $0A
|
|
|
|
!raw "# value=attract mode module listed in ATTRACT.CONF, or empty",$0A
|
2019-10-08 17:19:20 +00:00
|
|
|
.kFluff2 !byte .kFluff3-*-1
|
2020-03-23 01:58:26 +00:00
|
|
|
!byte $0A
|
|
|
|
!raw "# value=transition effect listed in FX.CONF, or empty",$0A
|
2019-10-08 17:19:20 +00:00
|
|
|
.kFluff3 !byte .kFluff4-*-1
|
2020-03-23 01:58:26 +00:00
|
|
|
!byte $0A
|
|
|
|
!raw "# value=transition effect listed in DFX.CONF, or empty",$0A
|
2019-10-08 17:19:20 +00:00
|
|
|
.kFluff4 !byte .kEOF-*-1
|
2020-03-23 01:58:26 +00:00
|
|
|
!byte $0A
|
|
|
|
!raw "# value=0 or 1",$0A
|
2019-10-08 17:19:20 +00:00
|
|
|
.kEOF !byte ._-*-1
|
2020-03-23 01:58:26 +00:00
|
|
|
!byte $0A
|
|
|
|
!raw "[eof]",$0A
|
2019-10-08 17:19:20 +00:00
|
|
|
._
|
|
|
|
|
|
|
|
.addStringFromStore
|
2020-03-24 20:30:14 +00:00
|
|
|
+ST16 .key
|
2019-10-08 17:19:20 +00:00
|
|
|
jsr .addString
|
|
|
|
+LDADDR .kEquals
|
|
|
|
jsr .addString
|
|
|
|
jsr okvs_get
|
|
|
|
!word gGlobalPrefsStore
|
|
|
|
.key !word $FDFD ; SMC
|
|
|
|
jsr .addString
|
|
|
|
+LDADDR .kLF
|
|
|
|
; execution falls through here
|
|
|
|
.addString
|
2020-03-24 20:30:14 +00:00
|
|
|
+ST16 $00
|
2019-10-08 17:19:20 +00:00
|
|
|
ldy #0
|
|
|
|
lda ($00),y
|
2019-10-08 18:53:27 +00:00
|
|
|
beq PREFRTS
|
2019-10-08 17:19:20 +00:00
|
|
|
tay
|
|
|
|
clc
|
|
|
|
adc $FE
|
|
|
|
tax
|
|
|
|
- lda ($00),y
|
|
|
|
dey
|
|
|
|
sta ($FE),y
|
|
|
|
bne -
|
|
|
|
stx $FE
|
2019-10-08 18:53:27 +00:00
|
|
|
bcc PREFRTS
|
2019-10-08 17:19:20 +00:00
|
|
|
inc $FF
|
2019-10-08 18:53:27 +00:00
|
|
|
PREFRTS rts
|
2019-10-08 17:19:20 +00:00
|
|
|
|
2018-11-10 13:36:36 +00:00
|
|
|
;------------------------------------------------------------------------------
|
2019-09-16 16:36:10 +00:00
|
|
|
; pref_get
|
2019-09-16 17:36:48 +00:00
|
|
|
; get pref value by pref key, and optionally validate that the pref value
|
|
|
|
; exists as a key in another OKVS
|
2019-09-16 16:36:10 +00:00
|
|
|
;
|
|
|
|
; 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
|
2019-09-16 17:36:48 +00:00
|
|
|
; +3 [word] address of OKVS, or 0
|
2019-09-16 16:36:10 +00:00
|
|
|
; gGlobalPrefsStore must be initialized (this is done in 4cade.init)
|
|
|
|
; out: A/Y = address of pref value
|
2020-03-24 20:30:14 +00:00
|
|
|
; $WINDEX = index of pref value in passed store
|
2019-09-16 17:36:48 +00:00
|
|
|
; (if OKVS parameter is 0, no validation occurs and X=0 and Z=1 on exit,
|
|
|
|
; some callers rely on this behavior, so don't change it!)
|
2019-09-16 16:36:10 +00:00
|
|
|
; PARAM clobbered
|
|
|
|
; PTR clobbered
|
|
|
|
; SRC clobbered
|
|
|
|
; SAVE clobbered
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
pref_get
|
|
|
|
+PARAMS_ON_STACK 4
|
2019-11-27 21:51:43 +00:00
|
|
|
+LDPARAMPTR 1, +
|
|
|
|
+LDPARAMPTR 3, .store1
|
2019-09-16 16:36:10 +00:00
|
|
|
|
|
|
|
jsr okvs_get ; look up pref key in prefs store
|
|
|
|
!word gGlobalPrefsStore
|
2019-10-08 17:19:20 +00:00
|
|
|
+ !word $FDFD ; SMC
|
2019-09-16 16:36:10 +00:00
|
|
|
bcs .useDefaultValue ; if pref key is not found, use default value
|
2019-10-08 17:19:20 +00:00
|
|
|
ldx .store1+1
|
2019-10-08 18:53:27 +00:00
|
|
|
beq PREFRTS ; if no OKVS to validate against, we're done
|
2020-03-24 20:30:14 +00:00
|
|
|
+ST16 +
|
|
|
|
+ST16 PTR
|
2019-09-16 16:36:10 +00:00
|
|
|
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
|
2019-10-08 17:19:20 +00:00
|
|
|
.store1 !word $FDFD ; SMC
|
2019-09-16 16:36:10 +00:00
|
|
|
+ !word $FDFD ; SMC
|
2019-09-20 23:27:16 +00:00
|
|
|
bcc + ; found key, continue
|
|
|
|
.useDefaultValue ; did not find key, use first key in passed store as a default value
|
2020-03-24 20:30:14 +00:00
|
|
|
lda #0
|
|
|
|
sta WINDEX
|
|
|
|
sta WINDEX+1
|
2019-09-20 23:27:16 +00:00
|
|
|
+
|
2020-03-24 20:30:14 +00:00
|
|
|
+LD16 .store1
|
2019-10-08 18:49:53 +00:00
|
|
|
jmp okvs_nth
|
2019-09-16 16:36:10 +00:00
|
|
|
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; pref_set
|
|
|
|
; set pref value by pref key, serialize prefs, and write them to disk
|
2018-11-10 13:36:36 +00:00
|
|
|
;
|
2019-09-16 16:36:10 +00:00
|
|
|
; in: stack contains 4 bytes of parameters:
|
|
|
|
; +1 [word] address of length-prefixed pref key
|
|
|
|
; +3 [word] address of length-prefixed pref value
|
2018-11-10 13:36:36 +00:00
|
|
|
; out: all registers and flags clobbered
|
2019-09-16 16:36:10 +00:00
|
|
|
; PARAM clobbered
|
|
|
|
; PTR clobbered
|
|
|
|
; SRC clobbered
|
|
|
|
; $FE/$FF clobbered
|
2018-11-10 13:36:36 +00:00
|
|
|
;------------------------------------------------------------------------------
|
2019-09-16 16:36:10 +00:00
|
|
|
pref_set
|
|
|
|
+PARAMS_ON_STACK 4
|
2019-11-27 21:51:43 +00:00
|
|
|
+LDPARAMPTR 1, +
|
|
|
|
+LDPARAMPTR 3, ++
|
2018-11-10 13:36:36 +00:00
|
|
|
|
2019-09-16 16:36:10 +00:00
|
|
|
jsr okvs_update ; save that in prefs store
|
|
|
|
!word gGlobalPrefsStore
|
2019-10-08 17:19:20 +00:00
|
|
|
+ !word $FDFD ; SMC
|
|
|
|
++ !word $FDFD ; SMC
|
2018-11-10 13:36:36 +00:00
|
|
|
|
2019-09-16 16:36:10 +00:00
|
|
|
+LDADDR kGlobalPrefsBuffer ; clear prefs buffer
|
2020-03-24 20:30:14 +00:00
|
|
|
+ST16 $FE
|
2019-09-16 16:36:10 +00:00
|
|
|
ldx #$02
|
|
|
|
ldy #$00
|
|
|
|
tya
|
|
|
|
- sta ($FE),y
|
|
|
|
iny
|
|
|
|
bne -
|
|
|
|
inc $FF
|
|
|
|
dex
|
|
|
|
bne -
|
|
|
|
dec $FF
|
|
|
|
dec $FF
|
|
|
|
|
2019-10-08 17:19:20 +00:00
|
|
|
+LDADDR .kFluff1 ; serialize prefs into prefs buffer
|
|
|
|
jsr .addString
|
2018-11-10 15:08:14 +00:00
|
|
|
+LDADDR kNextAttract
|
2019-10-08 17:19:20 +00:00
|
|
|
jsr .addStringFromStore
|
2018-11-10 13:36:36 +00:00
|
|
|
|
2019-10-08 17:19:20 +00:00
|
|
|
+LDADDR .kFluff2
|
|
|
|
jsr .addString
|
2018-11-10 15:08:14 +00:00
|
|
|
+LDADDR kNextFX
|
2019-10-08 17:19:20 +00:00
|
|
|
jsr .addStringFromStore
|
2018-11-10 13:36:36 +00:00
|
|
|
|
2019-10-08 17:19:20 +00:00
|
|
|
+LDADDR .kFluff3
|
|
|
|
jsr .addString
|
2018-11-10 15:08:14 +00:00
|
|
|
+LDADDR kNextDFX
|
2019-10-08 17:19:20 +00:00
|
|
|
jsr .addStringFromStore
|
2018-11-10 13:36:36 +00:00
|
|
|
|
2019-10-08 17:19:20 +00:00
|
|
|
+LDADDR .kFluff4
|
|
|
|
jsr .addString
|
2019-09-16 17:36:48 +00:00
|
|
|
+LDADDR kCheat
|
2019-10-08 17:19:20 +00:00
|
|
|
jsr .addStringFromStore
|
2019-09-16 17:36:48 +00:00
|
|
|
|
2019-10-08 17:19:20 +00:00
|
|
|
+LDADDR .kEOF
|
|
|
|
jsr .addString
|
2018-11-10 13:36:36 +00:00
|
|
|
|
2019-09-16 16:36:10 +00:00
|
|
|
+LDADDR kGlobalPrefsFilename ; write prefs buffer to file on disk
|
2019-06-20 17:56:31 +00:00
|
|
|
jsr SetPath
|
2020-03-24 20:30:14 +00:00
|
|
|
+LD16 kGlobalPrefsBuffer
|
2019-10-08 17:19:20 +00:00
|
|
|
; /!\ execution falls through here to glue.prorwts/SaveSmallFile
|
2019-10-08 18:47:47 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; SaveSmallFile
|
|
|
|
; Save a file into memory all at once, using ProRWTS2.
|
|
|
|
; /!\ Only first block (512 bytes) is written. Keep those files small. /!\
|
|
|
|
; /!\ All 512 bytes are written to disk. Clear buffer before calling. /!\
|
|
|
|
;
|
|
|
|
; supports paths, see note
|
|
|
|
;
|
|
|
|
; in: A/Y points to data buffer
|
|
|
|
; gPathname contains path+filename to write
|
|
|
|
; out: all flags clobbered
|
|
|
|
; all registers clobbered
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
SaveSmallFile
|
2020-03-24 20:30:14 +00:00
|
|
|
+ST16 ldrlo ; set data buffer address for ProRWTS2
|
2019-10-08 18:47:47 +00:00
|
|
|
jsr SwitchToBank2
|
|
|
|
jsr SaveSmallFileInternal
|
|
|
|
jmp SwitchToBank1
|