add SaveSmallFile, untested, YOLO

This commit is contained in:
4am 2018-11-10 10:08:14 -05:00
parent 852b7093f4
commit afcec48d1d
8 changed files with 128 additions and 86 deletions

View File

@ -28,7 +28,7 @@ Main
!source "src/wait.a"
!source "src/parse.common.a"
!source "src/parse.games.a"
gGamesListStore
gGlobalPrefsStore
!word *+2 ; address of first okvs store
}
LastMover

View File

@ -55,11 +55,21 @@ OneTimeSetup
ldy hddopendir+3
+STAY gRootDirectory
jsr LoadFile ; load preferences file
!word kGlobalPrefsFilename
jsr ParseKeyValueText ; parse contents into global prefs store
!word gGlobalPrefsStore
!word ldrlo2 ; (ldrlo2) points to last load address
!byte 16
+LDAY SRC
+STAY gGamesListStore ; save pointer to free space for next store
jsr LoadFile ; load games list
!word kGameListConfFile
jsr ParseGamesList ; parse games list
!word gGamesListStore
!word ldrlo2 ; (ldrlo2) points to load address
!word ldrlo2 ; (ldrlo2) points to last load address
+LDAY SRC
+STAY gFXStore ; save pointer to free space for next store
@ -67,7 +77,7 @@ OneTimeSetup
!word kFXConfFile
jsr ParseKeyValueList ; parse HGR transition effects list
!word gFXStore
!word ldrlo2 ; (ldrlo2) points to load address
!word ldrlo2 ; (ldrlo2) points to last load address
+LDAY SRC
+STAY gDFXStore ; save pointer to free space for next store
@ -75,7 +85,7 @@ OneTimeSetup
!word kDFXConfFile
jsr ParseKeyValueList ; parse DHGR transition effects list
!word gDFXStore
!word ldrlo2 ; (ldrlo2) points to load address
!word ldrlo2 ; (ldrlo2) points to last load address
+LDAY SRC
+STAY gAttractModeStore ; save pointer to free space for next store
@ -83,7 +93,7 @@ OneTimeSetup
!word kAttractModeConfFile
jsr ParseKeyValueList ; parse attract-mode configuration
!word gAttractModeStore
!word ldrlo2 ; (ldrlo2) points to load address
!word ldrlo2 ; (ldrlo2) points to last load address
+LDAY SRC
+STAY gSlideshowStore ; save pointer to free space for next store

View File

@ -6,9 +6,27 @@
; Public functions
; - LoadFile
; - LoadDHRFile
; - SaveSmallFile
;
; - promote
; A general note about paths:
;
; LoadFile, LoadDHRFile, and SaveSmallFile support files in subdirectories.
; Paths are delimited by '/' like ProDOS. HOWEVER, you should never include a
; disk volume name. At program startup, we get the current directory and save
; it; that is the PROGRAM ROOT DIRECTORY. The first '/' always points to the
; PROGRAM ROOT DIRECTORY. All pathnames are relative to the PROGRAM ROOT
; DIRECTORY.
;
; The PROGRAM ROOT DIRECTORY is not guaranteed to be the root directory of the
; underlying ProDOS disk (although it can be). These functions provide no
; access to any directory outside the PROGRAM ROOT DIRECTORY.
;
; Examples:
; '/PREFS.CONF' points to a file named 'PREFS.CONF' in the PROGRAM ROOT
; DIRECTORY.
;
; '/FX/RIPPLE' points to a file named 'RIPPLE' in a directory named 'FX' in the
; PROGRAM ROOT DIRECTORY.
gRootDirectory
!word $FDFD
@ -18,7 +36,7 @@ gPrefix
;------------------------------------------------------------------------------
; LoadFile
; load a file into memory all at once, using ProRWTS2
; supports files in subdirectories, delimited by '/' like ProDOS
; supports paths, see note
; uses file's load address
;
; in: stack contains 2 bytes of parameters:
@ -49,6 +67,7 @@ LoadFile
; all at once, using ProRWTS2
; first $2000 bytes of file are loaded into auxiliary memory $2000..$3FFF
; second $2000 bytes of file are loaded into main memory $2000..$3FFF
; supports paths, see note
;
; in: stack contains 2 bytes of parameters:
; +1 address of filename
@ -78,6 +97,44 @@ LoadDHRFile
clc ; not a subdirectory
jmp hddrdwrpart ; call ProRWTS2
;------------------------------------------------------------------------------
; 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: stack contains 4 bytes of parameters:
; +1 address of filename
; +3 address of data buffer
; out: all flags clobbered
; all registers clobbered
; stack set to next instruction after parameters
;------------------------------------------------------------------------------
SaveSmallFile
+PARAMS_ON_STACK 4
+LDPARAM 1
+STAY namlo ; set filename for ProRWTS2
+STAY gPrefix ; remember path
+LDPARAM 3
+STAY ldrlo ; set data buffer address for ProRWTS2
jsr traverse ; go to subdirectory, set up filename for read
lda #cmdwrite ; write (instead of read)
sta reqcmd
lda #0 ; 0 = data buffer is in main memory (instead of auxmem)
sta auxreq
jmp hddopendir ; exit via ProRWTS2
;------------------------------------------------------------------------------
; traverse [private]
;
; in: (namlo) points to length-prefixed pathname+filename
; out: all flags clobbered
; all registers clobbered
;------------------------------------------------------------------------------
traverse
+LDAY gRootDirectory
sta @myreadblock+1

View File

@ -1,7 +1,7 @@
;license:MIT
;(c) 2018 by 4am
;
; common assembler macros
; common assembler macros (6502 compatible)
;
; for functions that take parameters on the stack
@ -108,4 +108,3 @@
jsr LoadFile
!word gPathname
}

View File

@ -1,7 +1,7 @@
;license:MIT
;(c) 2018 by 4am
;
; Ordered key/value store (6502 version)
; Ordered key/value store (6502 compatible)
;
; Public functions
; - okvs_init(address) reset (required)

View File

@ -28,6 +28,7 @@ gSlideshowStore
; in: stack contains 4 bytes of parameters:
; +1 [word] handle to storage space for okvs
; +3 [word] handle to buffer containing contents of text file
; +5 [byte] max length for okvs records (or 0)
; out: all registers and flags clobbered
; $1F00..$1FFF clobbered
; $00/$01 clobbered
@ -36,7 +37,7 @@ gSlideshowStore
; $FE/$FF clobbered
;------------------------------------------------------------------------------
ParseKeyValueList
+PARAMS_ON_STACK 4
+PARAMS_ON_STACK 5
+LDPARAM 1
+STAY @store1
@ -45,6 +46,10 @@ ParseKeyValueList
+LDPARAM 3
+STAY $FE
ldy #5
lda (PARAM),y
sta @maxLength
ldy #0
lda ($FE),y
pha
@ -103,7 +108,8 @@ ParseKeyValueList
@store2 !word $FDFD ; SMC
!word gKeyLen
!word gValLen
!byte 0
@maxLength
!byte $FD ; SMC
pla
tay
clc

View File

@ -7,6 +7,9 @@
; - ParseGamesList
;
gGamesListStore
!word $FDFD ; SMC
;------------------------------------------------------------------------------
; ParseGamesList
; parse buffer with AB,KEY=VALUE lines of text into an okvs

View File

@ -20,6 +20,9 @@
gGlobalPrefsStore
!word 0
kGlobalPrefsBuffer
!word $0800
kGlobalPrefsFilename
!byte 10
!raw "PREFS.CONF"
@ -43,74 +46,41 @@ kNextDFX
;
; in: none
; out: all registers and flags clobbered
; $00/$01/$FE/$FF clobbered
;------------------------------------------------------------------------------
SaveGlobalPreferences
+LDADDR kGlobalPrefsBuffer
+STAY $FE
+STAY $FE
+LDADDR @kFluff1
jsr @addString
jsr @addBooleanFromStore
!word kForce40
jsr @addBooleanFromStore
!word kForceUpper
jsr @addBooleanFromStore
!word kScriptToFile
jsr @addBooleanFromStore
!word kAutoScript
jsr @addString
+LDADDR kLastPlayed
jsr @addStringFromStore
+LDADDR @kFluff2
jsr @addString
jsr @addStringFromStore
!word kLastPlayed
jsr @addString
+LDADDR kNextAttract
jsr @addStringFromStore
+LDADDR @kFluff3
jsr @addString
jsr @addString
+LDADDR kNextFX
jsr @addStringFromStore
jsr okvs_iter
!word gGamesListStore
!word @addGameToPrefs
+LDADDR @kFluff4
jsr @addString
+LDADDR kNextDFX
jsr @addStringFromStore
+LDADDR @kEOF
jsr @addString
jsr @addString
lda $FE
sta @filelen
lda $FF
sec
sbc #>kGlobalPrefsBuffer
sta @filelen+1
jsr SaveFile
jsr SaveSmallFile
!word kGlobalPrefsFilename
!byte 4 ; filetype=TXT
!word 0 ; auxtype=0000
!word kGlobalPrefsBuffer
@filelen !word $FDFD ; SMC
!word kProDOSFileBuffer
stz gGlobalPrefsDirty
@exit rts
@addGameToPrefs
+STAY +
jsr @addStringFromStore
+ !word $FDFD ; SMC
rts
@addBooleanFromStore
lda #$24 ; BIT opcode
+HIDE_NEXT_2_BYTES
@addStringFromStore
lda #$80 ; BRA opcode
sta @skipOverBooleanLogic
+PARAMS_ON_STACK 2
+LDPARAM 1
+STAY @key
jsr @addString
+LDADDR @kEquals
@ -118,26 +88,21 @@ SaveGlobalPreferences
jsr okvs_get
!word gGlobalPrefsStore
@key !word $FDFD ; SMC
@skipOverBooleanLogic
bra + ; SMC (opcode may become BIT)
+STAY PTR
ldy #1
lda (PTR),y
ora #$30
sta (PTR),y
+LDAY PTR
+ jsr @addString
jsr @addString
+LDADDR @kLF
jmp @addString
@addString
+STAY $00
lda ($00)
inc
ldx #0
ldy #0
lda ($00),y
clc
adc #$01
sta @len
ldy #1
iny
- lda ($00),y
sta ($FE)
sta ($FE,x)
+ iny
inc $FE
bne +
@ -149,21 +114,23 @@ SaveGlobalPreferences
@kEquals !byte 1
!raw "="
@kLF !byte 1
!byte $0D
@kFluff1 !byte @kFluff1_e-@kFluff1_b
@kFluff1_b
@kLF !byte 1,$0D
@kFluff1 !byte @kFluff2-*-1
!raw "# 4cade preferences file",$0D
!raw "# Do not edit by hand.",$0D
!raw "# Or do. I'm a comment, not a cop.",$0D,$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
@kFluff1_e
@kFluff2 !byte 24
@kFluff2 !byte @kFluff3-*-1
!byte $0D
!raw "# value=game directory",$0D
@kFluff3 !byte 58
!raw "# value=attract mode module listed in ATTRACT.CONF, or empty",$0D
@kFluff3 !byte @kFluff4-*-1
!byte $0D
!raw "# key=game directory, value=filename of selected version",$0D
@kEOF !byte 7
!raw "# value=transition effect listed in FX.CONF, or empty",$0D
@kFluff4 !byte @kEOF-*-1
!byte $0D
!raw "# value=transition effect listed in DFX.CONF, or empty",$0D
@kEOF !byte @_-*-1
!byte $0D
!raw "[eof]",$0D
@_