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/wait.a"
!source "src/parse.common.a" !source "src/parse.common.a"
!source "src/parse.games.a" !source "src/parse.games.a"
gGamesListStore gGlobalPrefsStore
!word *+2 ; address of first okvs store !word *+2 ; address of first okvs store
} }
LastMover LastMover

View File

@@ -55,11 +55,21 @@ OneTimeSetup
ldy hddopendir+3 ldy hddopendir+3
+STAY gRootDirectory +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 jsr LoadFile ; load games list
!word kGameListConfFile !word kGameListConfFile
jsr ParseGamesList ; parse games list jsr ParseGamesList ; parse games list
!word gGamesListStore !word gGamesListStore
!word ldrlo2 ; (ldrlo2) points to load address !word ldrlo2 ; (ldrlo2) points to last load address
+LDAY SRC +LDAY SRC
+STAY gFXStore ; save pointer to free space for next store +STAY gFXStore ; save pointer to free space for next store
@@ -67,7 +77,7 @@ OneTimeSetup
!word kFXConfFile !word kFXConfFile
jsr ParseKeyValueList ; parse HGR transition effects list jsr ParseKeyValueList ; parse HGR transition effects list
!word gFXStore !word gFXStore
!word ldrlo2 ; (ldrlo2) points to load address !word ldrlo2 ; (ldrlo2) points to last load address
+LDAY SRC +LDAY SRC
+STAY gDFXStore ; save pointer to free space for next store +STAY gDFXStore ; save pointer to free space for next store
@@ -75,7 +85,7 @@ OneTimeSetup
!word kDFXConfFile !word kDFXConfFile
jsr ParseKeyValueList ; parse DHGR transition effects list jsr ParseKeyValueList ; parse DHGR transition effects list
!word gDFXStore !word gDFXStore
!word ldrlo2 ; (ldrlo2) points to load address !word ldrlo2 ; (ldrlo2) points to last load address
+LDAY SRC +LDAY SRC
+STAY gAttractModeStore ; save pointer to free space for next store +STAY gAttractModeStore ; save pointer to free space for next store
@@ -83,7 +93,7 @@ OneTimeSetup
!word kAttractModeConfFile !word kAttractModeConfFile
jsr ParseKeyValueList ; parse attract-mode configuration jsr ParseKeyValueList ; parse attract-mode configuration
!word gAttractModeStore !word gAttractModeStore
!word ldrlo2 ; (ldrlo2) points to load address !word ldrlo2 ; (ldrlo2) points to last load address
+LDAY SRC +LDAY SRC
+STAY gSlideshowStore ; save pointer to free space for next store +STAY gSlideshowStore ; save pointer to free space for next store

View File

@@ -6,9 +6,27 @@
; Public functions ; Public functions
; - LoadFile ; - LoadFile
; - LoadDHRFile ; - 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 gRootDirectory
!word $FDFD !word $FDFD
@@ -18,7 +36,7 @@ gPrefix
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; LoadFile ; LoadFile
; load a file into memory all at once, using ProRWTS2 ; 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 ; uses file's load address
; ;
; in: stack contains 2 bytes of parameters: ; in: stack contains 2 bytes of parameters:
@@ -49,6 +67,7 @@ LoadFile
; all at once, using ProRWTS2 ; all at once, using ProRWTS2
; first $2000 bytes of file are loaded into auxiliary memory $2000..$3FFF ; first $2000 bytes of file are loaded into auxiliary memory $2000..$3FFF
; second $2000 bytes of file are loaded into main 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: ; in: stack contains 2 bytes of parameters:
; +1 address of filename ; +1 address of filename
@@ -78,6 +97,44 @@ LoadDHRFile
clc ; not a subdirectory clc ; not a subdirectory
jmp hddrdwrpart ; call ProRWTS2 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 traverse
+LDAY gRootDirectory +LDAY gRootDirectory
sta @myreadblock+1 sta @myreadblock+1

View File

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

View File

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

View File

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

View File

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

View File

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