A2osX/SYS/KERNEL.S.FIO.txt

231 lines
4.5 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
*/--------------------------------------
* #FileSearch
* ##In:
* PUSHW = PSTR to Search Path (PSTRING) %LIB%;/SYS/SLIB
* PUSHW = PSTR to File Name (PSTRING)
* #Out:
* Y,A = PSTR to FilePath (PSTRING)
* X = hMem to FilePath
*\--------------------------------------
K.FileSearch >PULLW ZPQuickPtr4 ZPQuickPtr1 trashed by ExpandPStrYA
>PULLYA Get Search list
>SYSCALL ExpandPStrYA Expand it (SYSCALL to BNK1)
bcs .99
stx K.FileSearch.hSrch
>STYA ZPQuickPtr3 ZPQuickPtr2 trashed by K.STAT !!! expanded search list ;
stz K.FileSearch.Index
.1 stz KrnBuf256 reset String
ldx #0
ldy K.FileSearch.Index
.2 tya
cmp (ZPQuickPtr3) end of src string ?
beq .3 end of string, try it....
iny
lda (ZPQuickPtr3),y
cmp #';'
beq .3
inx
sta KrnBuf256,x
bra .2
.3 txa
beq .98 String is empty....nothing to try
sty K.FileSearch.Index save current index
ldy #0
.4 iny
lda (ZPQuickPtr4),y Append Fiename...
inx
sta KrnBuf256,x
tya
cmp (ZPQuickPtr4)
bne .4
stx KrnBuf256 set string length
>PUSHWI KrnSTAT
>PUSHWI KrnBuf256
jsr K.STAT
bcs .1 Failed...retry next path...
lda K.FileSearch.hSrch Discard Expanded hSrch list
jsr K.FreeMemA
bra K.GetFullPathYA.NewStr
.98 lda K.FileSearch.hSrch Discard Expanded hSrch list
jsr K.FreeMemA
lda #SYSMGR.ERRFNF
sec
.99 rts
*--------------------------------------
K.FileSearch.hSrch .BS 1
K.FileSearch.Index .BS 1
*/--------------------------------------
* #GetFullPathYA
* ##In :
* Y,A = Filename (PSTRING)
* #Out :
* Y,A = FullPath (PSTRING)
* X = hMem of FullPath
*\--------------------------------------
K.GetFullPathYA >STYA ZPQuickPtr3 Ptr1 & 2 used by StrCpy
lda (ZPQuickPtr3)
beq K.GetFullPathYA.9
stz KrnBuf256
ldy #1
lda (ZPQuickPtr3),y
cmp #'/' full path starting with '/'?
beq .1 yes, do not append to current prefix
ldy #S.PS.hPREFIX
lda (pPs),y
jsr K.GetMemPtrA
>PUSHYA
>PUSHWI KrnBuf256
>SYSCALL PStrCpy
.1 >PUSHW ZPQuickPtr3
>PUSHWI KrnBuf256
>SYSCALL PStrCat
K.GetFullPathYA.NewStr
>LDYAI KrnBuf256
>SYSCALL NewPStrYA
rts
K.GetFullPathYA.9
sec
rts
*/--------------------------------------
* #LoadFile
* ##In:
* PUSHW = AUXTYPE (Handled by....
* PUSHB = TYPE ...
* PUSHB = MODE ...
* PUSHW = PATH ...FOPEN)
* ##Out:
* Y,A = File Length
* X = hMem of Loaded File
*\--------------------------------------
K.LoadFile jsr K.FOPEN
bcs .9
sta K.LoadFile.hFile
ldx #SYS.FSEEK.END
jsr K.LoadFile.Seek
bcs .99
lda K.LoadFile.hFile
jsr K.FTELLA
bcs .99
>STYA K.LoadFile.Len
phx
plx
bne .98 LEN > 65535 !!???
>PUSHYA push len
>PUSHBI 0
jsr K.GetMem
bcs .99
>STYA K.LoadFile.Mem
stx K.LoadFile.hMem
ldx #SYS.FSEEK.SET
jsr K.LoadFile.Seek
bcs .97
>PUSHW K.LoadFile.Mem
>PUSHW K.LoadFile.Len
>PUSHB K.LoadFile.hFile
jsr K.FREAD
bcs .97
jsr .99
>LDYA K.LoadFile.Len
ldx K.LoadFile.hMem
clc
.9 rts
.97 pha
lda K.LoadFile.hMem
jsr K.FreeMemA
pla
.HS 2C
.98 lda #SYSMGR.ERRFTB
.99 pha
lda K.LoadFile.hFile
jsr K.FCLOSEA
pla
sec
rts
*--------------------------------------
K.LoadFile.Seek >PUSHWI 0
>PUSHWI 0
txa
>PUSHA
>PUSHB K.LoadFile.hFile
jmp K.FSEEK
*/--------------------------------------
* #SaveFile
* ##In:
* PUSHW = SrcLen
* PUSHW = SrcPtr
* PUSHW = AUXTYPE (Handled by....
* PUSHB = TYPE ...
* PUSHB = MODE ...
* PUSHW = PATH ...FOPEN)
*\--------------------------------------
K.SaveFile jsr K.FOPEN
bcs .9
sta K.LoadFile.hFile
>PUSHB K.LoadFile.hFile
jsr K.FWRITE
bcs .99
jsr .99
clc
rts
.99 pha
lda K.LoadFile.hFile
jsr K.FCLOSEA
pla
sec
rts
.9 >POP 4 Discard SrcPtr & SrcLen
sec
rts
*--------------------------------------
K.LoadFile.hFile .BS 1
K.LoadFile.hMem .BS 1
K.LoadFile.Mem .BS 2
K.LoadFile.Len .BS 2
*--------------------------------------
MAN
SAVE SYS/KERNEL.S.FIO
LOAD SYS/KERNEL.S
ASM