2018-08-31 04:31:54 +00:00
|
|
|
;license:MIT
|
2021-10-13 22:04:56 +00:00
|
|
|
;(c) 2018-2021 by 4am & qkumba
|
2018-08-31 04:31:54 +00:00
|
|
|
;
|
|
|
|
; ProRWTS2 glue functions
|
|
|
|
;
|
|
|
|
; Public functions
|
|
|
|
; - LoadFile
|
2021-10-13 22:04:56 +00:00
|
|
|
; - LoadAuxFile
|
2018-09-01 01:04:00 +00:00
|
|
|
; - LoadDHRFile
|
2021-10-13 22:04:56 +00:00
|
|
|
; - LoadIndexedFile
|
2019-10-08 17:19:20 +00:00
|
|
|
;
|
|
|
|
; Public variables
|
|
|
|
; - gRootDirectory
|
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
|
|
|
;
|
2021-10-13 22:04:56 +00:00
|
|
|
; Load[*]File routines support subdirectories. 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
|
|
|
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; 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
|
2021-10-13 22:58:26 +00:00
|
|
|
ldx #7
|
|
|
|
bne .loadcommon
|
2018-10-28 18:04:52 +00:00
|
|
|
|
2020-03-12 19:36:28 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; LoadAuxFile
|
|
|
|
; Load a file into aux memory all at once, using ProRWTS2
|
|
|
|
;
|
|
|
|
; supports paths, see note
|
|
|
|
;
|
|
|
|
; 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
|
|
|
|
; out: all flags clobbered
|
|
|
|
; all registers clobbered
|
|
|
|
; gPathname clobbered
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
LoadAuxFile
|
2021-10-13 22:58:26 +00:00
|
|
|
ldx #6
|
|
|
|
bne .loadcommon
|
2020-03-12 19:36:28 +00:00
|
|
|
|
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:45:18 +00:00
|
|
|
; in: stack contains 4 bytes of parameters:
|
2019-09-10 02:38:17 +00:00
|
|
|
; +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
|
2021-10-13 22:58:26 +00:00
|
|
|
ldx #$84
|
|
|
|
.loadcommon
|
|
|
|
pla
|
|
|
|
sta PARAM
|
|
|
|
txa
|
|
|
|
pha
|
|
|
|
and #6
|
|
|
|
clc
|
|
|
|
adc PARAM
|
|
|
|
tay
|
|
|
|
pla
|
|
|
|
tax
|
|
|
|
pla
|
|
|
|
sta PARAM+1
|
|
|
|
adc #0
|
|
|
|
pha
|
|
|
|
tya
|
|
|
|
pha
|
|
|
|
txa
|
|
|
|
pha
|
2019-09-10 02:38:17 +00:00
|
|
|
+LDPARAM 1
|
|
|
|
jsr SetPath
|
|
|
|
+LDPARAM 3
|
|
|
|
jsr AddToPath
|
2021-10-13 22:58:26 +00:00
|
|
|
plp
|
|
|
|
php
|
|
|
|
bmi +
|
|
|
|
+LDPARAMPTR 5, ldrlo ; set load address
|
|
|
|
+ jsr SwitchToBank2
|
|
|
|
plp
|
|
|
|
bmi ++
|
|
|
|
bcc +
|
|
|
|
jsr LoadFileInternal
|
|
|
|
jmp SwitchToBank1
|
|
|
|
+ ldx #1 ; request aux memory
|
|
|
|
jsr LoadFileAuxInternal
|
|
|
|
jmp SwitchToBank1
|
|
|
|
++ jsr LoadDHRFileInternal
|
2019-09-20 13:33:23 +00:00
|
|
|
jmp SwitchToBank1
|
2018-10-28 18:04:52 +00:00
|
|
|
|
2021-10-13 22:04:56 +00:00
|
|
|
;------------------------------------------------------------------------------
|
2021-10-24 03:53:24 +00:00
|
|
|
; LoadAuxIndexedFile
|
|
|
|
; Load a file from inside an indexed file, all at once into auxiliary memory
|
|
|
|
;
|
|
|
|
; To save disk space, some collections of small, related files (e.g. per-game
|
|
|
|
; help files) are merged into a single data file with an associated index file.
|
|
|
|
; The index stores the original filename along with an offset (into the merged
|
|
|
|
; data file) and a length.
|
|
|
|
;
|
|
|
|
; Callers are responsible for loading the index file and finding the relevant
|
|
|
|
; record within the index. Most callers use okvs_find() for this.
|
|
|
|
;
|
|
|
|
; in: stack contains 6 bytes of parameters:
|
|
|
|
; +1 [word] pointer to filename of merged data file
|
|
|
|
; +3 [word] address of load destination
|
|
|
|
; +5 [word] pointer to index record (see note)
|
|
|
|
; out: all flags clobbered
|
|
|
|
; all registers clobbered
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
LoadAuxIndexedFile
|
2021-10-25 00:09:29 +00:00
|
|
|
lda #$EE ; INC
|
2021-10-24 03:53:24 +00:00
|
|
|
+HIDE_NEXT_2_BYTES
|
|
|
|
;------------------------------------------------------------------------------
|
2021-10-13 22:04:56 +00:00
|
|
|
; LoadIndexedFile
|
|
|
|
; Load a file from inside an indexed file, all at once
|
|
|
|
;
|
|
|
|
; To save disk space, some collections of small, related files (e.g. per-game
|
|
|
|
; help files) are merged into a single data file with an associated index file.
|
|
|
|
; The index stores the original filename along with an offset (into the merged
|
|
|
|
; data file) and a length.
|
|
|
|
;
|
|
|
|
; Callers are responsible for loading the index file and finding the relevant
|
|
|
|
; record within the index. Most callers use okvs_find() for this.
|
|
|
|
;
|
|
|
|
; in: stack contains 6 bytes of parameters:
|
|
|
|
; +1 [word] pointer to filename of merged data file
|
|
|
|
; +3 [word] address of load destination
|
|
|
|
; +5 [word] pointer to index record (see note)
|
|
|
|
; out: all flags clobbered
|
|
|
|
; all registers clobbered
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
LoadIndexedFile
|
2021-10-25 00:09:29 +00:00
|
|
|
lda #$8D ; STA
|
2021-10-24 03:53:24 +00:00
|
|
|
sta @iauxreq
|
2021-10-13 22:04:56 +00:00
|
|
|
+PARAMS_ON_STACK 6
|
2021-10-13 22:58:26 +00:00
|
|
|
jsr @set_nameaddr
|
|
|
|
+LDPARAMPTR 5, zpword
|
2021-10-13 22:04:56 +00:00
|
|
|
inc $BF0E ; disable ROM mapping on return
|
2021-11-13 01:46:05 +00:00
|
|
|
jsr SwitchToBank2
|
|
|
|
jsr resetRoot
|
2021-10-13 22:04:56 +00:00
|
|
|
ldx #2
|
|
|
|
ldy #0
|
|
|
|
lda (zpword), y
|
|
|
|
tay
|
|
|
|
- iny
|
|
|
|
lda (zpword), y
|
|
|
|
sta @offset, x
|
|
|
|
dex
|
|
|
|
bpl -
|
|
|
|
dex
|
|
|
|
- iny
|
|
|
|
lda (zpword), y
|
|
|
|
sta @size - $fe, x
|
|
|
|
inx
|
|
|
|
bmi -
|
|
|
|
jsr $bf00 ; yes, ProDOS abstraction
|
|
|
|
!byte $c8
|
|
|
|
!word @c8_parms
|
|
|
|
jsr $bf00
|
|
|
|
!byte $ce
|
|
|
|
!word @ce_parms
|
2021-10-24 03:53:24 +00:00
|
|
|
@iauxreq
|
2021-10-25 00:09:29 +00:00
|
|
|
sta SavedZP + auxreq - first_zp
|
|
|
|
; SMC
|
2021-10-24 03:53:24 +00:00
|
|
|
|
2021-10-13 22:04:56 +00:00
|
|
|
jsr $bf00
|
|
|
|
!byte $ca
|
|
|
|
!word @ca_parms
|
2021-11-03 17:29:02 +00:00
|
|
|
sta auxreq
|
2021-10-13 22:04:56 +00:00
|
|
|
jsr $bf00
|
|
|
|
!byte $cc
|
|
|
|
!word @cc_parms
|
2021-10-19 18:09:57 +00:00
|
|
|
jsr swap_zpg ; restore sizelo2/hi2
|
2021-10-13 22:04:56 +00:00
|
|
|
dec $BF0E ; re-enable ROM mapping on return
|
|
|
|
jmp SwitchToBank1
|
|
|
|
|
2021-10-13 22:58:26 +00:00
|
|
|
@set_nameaddr
|
|
|
|
ldx #0
|
|
|
|
ldy #1
|
|
|
|
jsr +
|
|
|
|
iny
|
|
|
|
ldx #@address - @filename
|
|
|
|
+ lda (PARAM), y
|
|
|
|
sta @filename, x
|
|
|
|
iny
|
|
|
|
lda (PARAM), y
|
|
|
|
sta @filename + 1, x
|
|
|
|
rts
|
|
|
|
|
2021-10-13 22:04:56 +00:00
|
|
|
@c8_parms
|
|
|
|
!byte 3
|
|
|
|
@filename
|
|
|
|
!word $DFDF ; SMC
|
|
|
|
!byte 0
|
|
|
|
@ce_parms
|
|
|
|
!byte $d0
|
|
|
|
!byte 1
|
|
|
|
@offset !byte 0, 0, 0 ; SMC
|
|
|
|
!byte $ff
|
|
|
|
@ca_parms
|
|
|
|
!byte $ff
|
|
|
|
@cc_parms
|
|
|
|
!byte 1
|
|
|
|
@address !word $DFDF ; SMC
|
|
|
|
@size !word $DFDF ; SMC
|
|
|
|
!word $ffff
|