4cade/src/glue.prorwts2.a
2021-11-17 00:25:17 -05:00

177 lines
5.1 KiB
Plaintext

;license:MIT
;(c) 2018-2021 by 4am & qkumba
;
; ProRWTS2 glue functions
;
; Public functions
; - LoadFile
; - LoadAuxFile
; - LoadIndexedFile
; - LoadAuxIndexedFile
;
; A general note about paths:
;
; 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.
;
; The PROGRAM ROOT DIRECTORY is not guaranteed to be the root directory of the
; 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.
;
; 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.
;------------------------------------------------------------------------------
; LoadFile/LoadAuxFile
; Load a file into main or auxiliary 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
;------------------------------------------------------------------------------
LoadFile
ldx #7
bne .loadcommon
LoadAuxFile
ldx #6
.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
+LDPARAM 1
jsr SetPath
+LDPARAM 3
jsr AddToPath
plp
php
bmi +
+LDPARAMPTR 5, ldrlo ; set load address
+ jsr SwitchToBank2
plp
bcc +
jsr LoadFileInternal
jmp SwitchToBank1
+ ldx #1 ; request aux memory
jsr LoadFileAuxInternal
jmp SwitchToBank1
;------------------------------------------------------------------------------
; LoadIndexedFile/LoadAuxIndexedFile
; Load a file from inside an indexed file, all at once, into main or 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, although some
; have hard-coded records generated at build time.
;
; in: stack contains 4 bytes of parameters:
; +1 [word] address of load destination
; +3 [word] pointer to index record
; out: all flags clobbered
; all registers clobbered
;------------------------------------------------------------------------------
LoadAuxIndexedFile
lda #$EE ; INC
+HIDE_NEXT_2_BYTES
LoadIndexedFile
lda #$8D ; STA
sta @iauxreq
+PARAMS_ON_STACK 4
+LDPARAMPTR 1, @address
+LDPARAMPTR 3, zpword
inc $BF0E ; disable ROM mapping on return
jsr SwitchToBank2
jsr resetRoot
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
@iauxreq
sta SavedZP + auxreq - first_zp
; SMC
jsr $bf00
!byte $ca
!word @ca_parms
sta auxreq
jsr $bf00
!byte $cc
!word @cc_parms
jsr swap_zpg ; restore sizelo2/hi2
dec $BF0E ; re-enable ROM mapping on return
+LD16 @address
sta ldrlo2 ; support Launch of what we just loaded
sty ldrhi2
jmp SwitchToBank1
@c8_parms
!byte 3
@filename
!word kTotalDataFile
!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