2018-08-31 04:31:54 +00:00
|
|
|
;license:MIT
|
2019-06-19 02:40:17 +00:00
|
|
|
;(c) 2018-9 by 4am & qkumba
|
2018-08-31 04:31:54 +00:00
|
|
|
;
|
|
|
|
; ProRWTS2 glue functions
|
|
|
|
;
|
|
|
|
; Public functions
|
|
|
|
; - LoadFile
|
2018-09-01 01:04:00 +00:00
|
|
|
; - LoadDHRFile
|
2018-11-10 15:08:14 +00:00
|
|
|
; - SaveSmallFile
|
2019-09-09 21:28:13 +00:00
|
|
|
; - SaveOrRestoreScreenHoles
|
2018-08-31 04:31:54 +00:00
|
|
|
;
|
2018-11-10 15:08:14 +00:00
|
|
|
; A general note about paths:
|
2018-11-07 23:56:39 +00:00
|
|
|
;
|
2019-09-10 02:38:17 +00:00
|
|
|
; LoadFile, LoadDHRFile, and SaveSmallFile support subdirectories.
|
2018-11-12 15:06:15 +00:00
|
|
|
; Directories are delimited by '/' like ProDOS. At program startup, we get the
|
|
|
|
; current directory and save it; that is the PROGRAM ROOT DIRECTORY. All
|
|
|
|
; pathnames are relative to the PROGRAM ROOT DIRECTORY. There is no concept of
|
|
|
|
; setting or changing the 'current' directory.
|
2018-11-10 15:08:14 +00:00
|
|
|
;
|
|
|
|
; The PROGRAM ROOT DIRECTORY is not guaranteed to be the root directory of the
|
2018-11-12 15:06:15 +00:00
|
|
|
; underlying ProDOS disk (although it can be). But it doesn't matter, because
|
|
|
|
; these functions provide no access to any directory above the PROGRAM ROOT
|
|
|
|
; DIRECTORY. You can't use '..' to access the parent directory, and you can't
|
|
|
|
; start a pathname with '/' to access the root directory of the underlying
|
|
|
|
; ProDOS disk.
|
2018-11-10 15:08:14 +00:00
|
|
|
;
|
|
|
|
; Examples:
|
2018-11-12 15:06:15 +00:00
|
|
|
; 'PREFS.CONF' points to a file named 'PREFS.CONF' in the PROGRAM ROOT
|
2018-11-10 15:08:14 +00:00
|
|
|
; DIRECTORY.
|
|
|
|
;
|
2018-11-12 15:06:15 +00:00
|
|
|
; 'FX/RIPPLE' points to a file named 'RIPPLE' in a directory named 'FX' in the
|
2018-11-10 15:08:14 +00:00
|
|
|
; PROGRAM ROOT DIRECTORY.
|
2018-08-31 04:31:54 +00:00
|
|
|
|
2018-10-28 15:44:26 +00:00
|
|
|
gRootDirectory
|
|
|
|
!word $FDFD
|
|
|
|
|
2018-08-31 04:31:54 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; LoadFile
|
2019-09-10 02:38:17 +00:00
|
|
|
; Load a file into memory all at once, using ProRWTS2
|
2018-11-12 15:06:15 +00:00
|
|
|
;
|
2018-11-10 15:08:14 +00:00
|
|
|
; supports paths, see note
|
2018-08-31 04:31:54 +00:00
|
|
|
;
|
2019-09-10 02:38:17 +00:00
|
|
|
; in: stack contains 6 bytes of parameters:
|
|
|
|
; +1 [word] address of length-prefixed pathname
|
|
|
|
; +3 [word] address of length-prefixed filename
|
|
|
|
; +5 [word] address to load file, or 0 to use file's default address
|
2018-08-31 04:31:54 +00:00
|
|
|
; out: all flags clobbered
|
|
|
|
; all registers clobbered
|
2019-06-19 02:40:17 +00:00
|
|
|
; gPathname clobbered
|
2018-08-31 04:31:54 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
LoadFile
|
2019-09-10 02:38:17 +00:00
|
|
|
+PARAMS_ON_STACK 6
|
2019-06-18 03:05:19 +00:00
|
|
|
+LDPARAM 1
|
2019-09-10 02:38:17 +00:00
|
|
|
jsr SetPath
|
|
|
|
+LDPARAM 3
|
|
|
|
jsr AddToPath
|
|
|
|
+LDPARAM 5
|
2019-06-18 03:05:19 +00:00
|
|
|
+STAY ldrlo ; set load address
|
2019-06-19 02:40:17 +00:00
|
|
|
+LDADDR gPathname
|
|
|
|
+STAY namlo ; set filename
|
2019-06-20 01:10:56 +00:00
|
|
|
+READ_RAM2_WRITE_RAM2
|
2019-06-18 03:05:19 +00:00
|
|
|
jsr traverse ; go to subdirectory, set up filename for read
|
|
|
|
lda #cmdread ; read (instead of write)
|
|
|
|
sta reqcmd
|
|
|
|
lda #0 ; 0 = read into main memory
|
|
|
|
sta auxreq
|
2019-09-10 02:38:17 +00:00
|
|
|
lda ldrlo+1
|
|
|
|
bne + ; if caller provided a load address, use it
|
|
|
|
sta sizelo ; otherwise query the load address from file metadata
|
|
|
|
sta sizehi ; 0 = query load address
|
|
|
|
jsr hddopendir ; call ProRWTS2
|
|
|
|
+LDAY ldrlo2
|
|
|
|
+STAY ldrlo
|
|
|
|
+ lda #$FF ; read entire file (ProRWTS2 will figure out exact size)
|
2018-10-28 18:04:52 +00:00
|
|
|
sta sizehi
|
2019-06-20 01:10:56 +00:00
|
|
|
jsr hddopendir ; exit via ProRWTS2
|
|
|
|
+READ_RAM1_WRITE_RAM1
|
|
|
|
rts
|
2018-10-28 18:04:52 +00:00
|
|
|
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; LoadDHRFile
|
|
|
|
; load .A2FC file (uncompressed double hi-res graphics) into memory
|
|
|
|
; all at once, using ProRWTS2
|
2019-09-10 02:38:17 +00:00
|
|
|
; first $2000 bytes of file are loaded into auxiliary memory $4000..$5FFF
|
|
|
|
; second $2000 bytes of file are loaded into main memory $4000..$4FFF
|
2018-11-12 15:06:15 +00:00
|
|
|
;
|
2018-11-10 15:08:14 +00:00
|
|
|
; supports paths, see note
|
2018-10-28 18:04:52 +00:00
|
|
|
;
|
2019-09-10 02:38:17 +00:00
|
|
|
; in: stack contains 6 bytes of parameters:
|
|
|
|
; +1 [word] address of length-prefixed pathname
|
|
|
|
; +3 [word] address of length-prefixed filename
|
2018-10-28 18:04:52 +00:00
|
|
|
; out: all flags clobbered
|
|
|
|
; all registers clobbered
|
|
|
|
; stack set to next instruction after parameters
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
LoadDHRFile
|
2019-09-10 02:38:17 +00:00
|
|
|
+PARAMS_ON_STACK 4
|
|
|
|
+LDPARAM 1
|
|
|
|
jsr SetPath
|
|
|
|
+LDPARAM 3
|
|
|
|
jsr AddToPath
|
2019-06-19 02:40:17 +00:00
|
|
|
+LDADDR gPathname
|
2018-10-28 18:04:52 +00:00
|
|
|
+STAY namlo ; set filename
|
2019-06-20 01:10:56 +00:00
|
|
|
+READ_RAM2_WRITE_RAM2
|
2018-10-28 18:04:52 +00:00
|
|
|
jsr traverse ; go to subdirectory, set up filename for read
|
|
|
|
lda #$00 ; read first $2000 bytes
|
|
|
|
sta sizelo
|
2019-06-18 03:05:19 +00:00
|
|
|
sta ldrlo
|
2018-10-28 18:04:52 +00:00
|
|
|
lda #$20
|
|
|
|
sta sizehi
|
2019-06-18 03:05:19 +00:00
|
|
|
asl
|
2019-09-10 02:38:17 +00:00
|
|
|
sta ldrhi ; into $4000
|
2018-10-28 18:04:52 +00:00
|
|
|
lda #1 ; 1 = read into aux memory
|
|
|
|
sta auxreq
|
|
|
|
lda #cmdread ; read (instead of write)
|
|
|
|
sta reqcmd
|
|
|
|
jsr hddopendir ; call ProRWTS2
|
|
|
|
lda #$20 ; read next $2000 bytes
|
|
|
|
sta sizehi
|
2019-06-18 03:05:19 +00:00
|
|
|
asl
|
2019-09-10 02:38:17 +00:00
|
|
|
sta ldrhi ; into $4000
|
2018-10-28 18:04:52 +00:00
|
|
|
dec auxreq ; 0 = read into main memory
|
2018-11-01 05:48:35 +00:00
|
|
|
clc ; not a subdirectory
|
2019-06-20 01:10:56 +00:00
|
|
|
jsr hddrdwrpart ; call ProRWTS2
|
|
|
|
+READ_RAM1_WRITE_RAM1
|
|
|
|
rts
|
2018-10-28 18:04:52 +00:00
|
|
|
|
2018-11-10 15:08:14 +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. /!\
|
2018-11-12 15:06:15 +00:00
|
|
|
;
|
2018-11-10 15:08:14 +00:00
|
|
|
; supports paths, see note
|
|
|
|
;
|
2019-06-19 02:40:17 +00:00
|
|
|
; in: stack contains 2 bytes of parameters:
|
|
|
|
; +1 address of data buffer
|
2018-11-10 15:08:14 +00:00
|
|
|
; out: all flags clobbered
|
|
|
|
; all registers clobbered
|
|
|
|
; stack set to next instruction after parameters
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
SaveSmallFile
|
2019-06-19 02:40:17 +00:00
|
|
|
+PARAMS_ON_STACK 2
|
2018-11-10 15:08:14 +00:00
|
|
|
+LDPARAM 1
|
|
|
|
+STAY ldrlo ; set data buffer address for ProRWTS2
|
2019-06-19 02:40:17 +00:00
|
|
|
+LDADDR gPathname
|
|
|
|
+STAY namlo ; set filename for ProRWTS2
|
2019-06-20 01:10:56 +00:00
|
|
|
+READ_RAM2_WRITE_RAM2
|
2018-11-10 15:08:14 +00:00
|
|
|
jsr traverse ; go to subdirectory, set up filename for read
|
2019-06-18 03:05:19 +00:00
|
|
|
;;if the write address is always a fixed value then we can discard the query
|
|
|
|
lda #cmdread ; read (instead of write)
|
|
|
|
sta reqcmd
|
|
|
|
lda #0 ; 0 = read into main memory
|
|
|
|
sta sizelo
|
|
|
|
sta sizehi ; 0 = query load address
|
|
|
|
jsr hddopendir ; call ProRWTS2
|
|
|
|
lda ldrlo2
|
|
|
|
sta ldrlo
|
|
|
|
lda ldrhi2
|
|
|
|
sta ldrhi
|
2018-11-10 15:08:14 +00:00
|
|
|
lda #cmdwrite ; write (instead of read)
|
|
|
|
sta reqcmd
|
2019-06-18 03:05:19 +00:00
|
|
|
sta sizelo ; non-zero
|
2019-06-20 01:10:56 +00:00
|
|
|
jsr hddopendir ; exit via ProRWTS2 (must re-open the file after query)
|
|
|
|
+READ_RAM1_WRITE_RAM1
|
|
|
|
rts
|
2018-11-10 15:08:14 +00:00
|
|
|
|
2018-11-26 19:43:39 +00:00
|
|
|
;------------------------------------------------------------------------------
|
2019-06-23 18:24:09 +00:00
|
|
|
; SaveOrRestoreScreenHoles
|
2018-11-26 19:43:39 +00:00
|
|
|
; preserve screen hole contents across demo execution
|
|
|
|
; to avoid crashing later on disk access
|
|
|
|
;
|
|
|
|
; in: nothing
|
|
|
|
; out: all flags clobbered
|
|
|
|
; all registers clobbered
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
|
2019-06-23 18:24:09 +00:00
|
|
|
SaveOrRestoreScreenHoles
|
2018-11-26 19:43:39 +00:00
|
|
|
lda #4
|
|
|
|
sta namhi
|
|
|
|
ldx #0
|
|
|
|
stx namlo
|
|
|
|
sta bloklo
|
|
|
|
-- ldy #$78
|
|
|
|
- lda (namlo),y
|
|
|
|
pha
|
|
|
|
lda holey_stuff,x
|
|
|
|
holepatch ;sta->lda
|
|
|
|
lda (namlo),y
|
|
|
|
pla
|
|
|
|
sta holey_stuff,x
|
|
|
|
inx
|
|
|
|
tya
|
|
|
|
eor #$80
|
|
|
|
tay
|
|
|
|
bmi -
|
|
|
|
iny
|
|
|
|
bpl -
|
|
|
|
inc namhi
|
|
|
|
dec bloklo
|
|
|
|
bne --
|
|
|
|
rts
|
|
|
|
holey_stuff
|
|
|
|
!fill 64
|