A2osX/SYS/KERNEL.S.FIO.txt

633 lines
13 KiB
Plaintext
Raw Normal View History

2015-03-14 21:48:35 +00:00
PR#3
2015-06-03 18:30:57 +00:00
PREFIX /A2OSX.SRC
2015-03-14 21:48:35 +00:00
NEW
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
* PUBLIC
*--------------------------------------
2015-06-03 18:30:57 +00:00
S.CheckPrefixYA >STYA MLICALL.PARAMS+1
2015-03-14 21:48:35 +00:00
>STYA ZPQuickPtr1
lda (ZPQuickPtr1)
beq .98
tax
ldy #1
lda (ZPQuickPtr1),y
cmp #'/'
bne .98
cpx #1 "/" allowed for listing online volumes
beq .8
2015-06-03 18:30:57 +00:00
>MLICALL MLIGETFILEINFO
2015-03-14 21:48:35 +00:00
bcs .98 No, invalid path...
lda MLICALL.PARAMS+4 Check file type
cmp #$0F Directory?
bne .98
.8 clc
rts
.98 lda #SYSMGR.ERRIDIR
.99 sec
rts
*--------------------------------------
* S.FileSearch
* in :
2016-08-17 06:25:58 +00:00
* PULLW = PSTR to File Name (PSTRING)
* PULLW = PSTR to Search Path (PSTRING) %LIB%;/SYS/SLIB
2015-03-14 21:48:35 +00:00
* out :
2016-08-17 06:25:58 +00:00
* Y,A = PSTR to FilePath (PSTRING)
* X = hMem to FilePath
2015-03-14 21:48:35 +00:00
*--------------------------------------
2016-08-17 06:25:58 +00:00
S.FileSearch >PULLW ZPQuickPtr4 ZPQuickPtr1 trashed by ExpandPStrYA
>PULLYA Get Search list
jsr S.ExpandPStrYA Expand it
bcs .99
stx S.FileSearch.hSrch
>STYA ZPQuickPtr2 expanded search list ;
2015-06-03 18:30:57 +00:00
2016-08-17 06:25:58 +00:00
stz S.FileSearch.Index
.1 stz KrnBuffer256 reset String
ldx #0
2016-06-07 06:10:18 +00:00
2016-08-17 06:25:58 +00:00
ldy S.FileSearch.Index
2016-06-07 06:10:18 +00:00
2016-08-17 06:25:58 +00:00
.2 tya
cmp (ZPQuickPtr2) end of src string ?
beq .3 end of string, try it....
iny
lda (ZPQuickPtr2),y
cmp #';'
beq .3
inx
sta KrnBuffer256,x
bra .2
.3 txa
beq .98 String is empty....nothing to try
sty S.FileSearch.Index save current index
2015-06-03 18:30:57 +00:00
2016-08-17 06:25:58 +00:00
ldy #0
2016-06-07 06:10:18 +00:00
2016-08-17 06:25:58 +00:00
.4 iny
lda (ZPQuickPtr4),y Append Fiename...
inx
sta KrnBuffer256,x
tya
cmp (ZPQuickPtr4)
bne .4
2015-06-03 18:30:57 +00:00
2016-08-17 06:25:58 +00:00
stx KrnBuffer256 set string length
2015-06-03 18:30:57 +00:00
2016-08-17 06:25:58 +00:00
>LDYAI KrnBuffer256
2016-06-07 06:10:18 +00:00
jsr S.MLIGetFileInfoYA
2016-08-17 06:25:58 +00:00
bcs .1 Failed...retry next path...
2015-06-03 18:30:57 +00:00
2016-08-17 06:25:58 +00:00
lda S.FileSearch.hSrch Discard Expanded hSrch list
2015-03-14 21:48:35 +00:00
jsr S.FreeMemA
2016-08-17 06:25:58 +00:00
>LDYAI KrnBuffer256
jmp S.NewPStrYA
.98 lda S.FileSearch.hSrch Discard Expanded hSrch list
2015-03-14 21:48:35 +00:00
jsr S.FreeMemA
lda #SYSMGR.ERRFNF
sec
2016-08-17 06:25:58 +00:00
.99 rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
2016-08-17 06:25:58 +00:00
S.FileSearch.File .BS 2
S.FileSearch.hSrch .BS 1
2016-08-17 06:25:58 +00:00
S.FileSearch.Index .BS 1
*--------------------------------------
* S.GetFullPathYA
* in :
* Y,A = Filename (PSTRING)
* out :
* Y,A = FullPath (PSTRING)
* X = hMem of FullPath
*--------------------------------------
S.GetFullPathYA >STYA ZPQuickPtr3 Ptr1 & 2 used by StrCpy
lda (ZPQuickPtr3)
beq .9
stz KrnBuffer256
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 S.GetMemPtrA
>PUSHYA
>PUSHWI KrnBuffer256
jsr S.PStrCpy
.1 >PUSHW ZPQuickPtr3
>PUSHWI KrnBuffer256
jsr S.PStrCat
>LDYAI KrnBuffer256
jmp S.NewPStrYA
.9 sec
rts
*--------------------------------------
2016-06-07 06:10:18 +00:00
* S.LoadFileYA
2015-03-14 21:48:35 +00:00
* in :
2016-06-07 06:10:18 +00:00
* Y,A = FilePath (PSTRING)
2015-03-14 21:48:35 +00:00
* out :
* Y,A = File Length
* X = hMem of Loaded File
*--------------------------------------
2016-08-17 06:25:58 +00:00
S.LoadFileYA jsr S.MLIOpenYA
bcc .10
2016-08-17 06:25:58 +00:00
rts
2015-06-03 18:30:57 +00:00
.10 sta S.LoadFile.hRef save ref_num
stx S.LoadFile.hBuf save Prodos Buffer for freemem
2015-03-14 21:48:35 +00:00
jsr S.MLIGetEOFA
bcs .98
2015-06-03 18:30:57 +00:00
2015-03-14 21:48:35 +00:00
phx Larger than 64k?
plx
beq .1 File too big!!!!
lda #SYSMGR.ERRFTB
bra .98
2015-06-03 18:30:57 +00:00
.1 >STYA S.LoadFile.Len save Length
2015-03-14 21:48:35 +00:00
>PUSHYA Push Length for S.GetMem
>PUSHBI 0
jsr S.GetMem
bcs .98
2015-06-03 18:30:57 +00:00
2016-08-17 06:25:58 +00:00
>STYA S.LoadFile.Mem
stx S.LoadFile.hMem save Segment hMem
>PUSHW S.LoadFile.Len Push Length for S.MLIRead
2016-08-17 06:25:58 +00:00
>PUSHW S.LoadFile.Mem Push PTR
>PUSHB S.LoadFile.hRef Push ref_num
2015-03-14 21:48:35 +00:00
jsr S.MLIRead
bcs .97
2015-06-03 18:30:57 +00:00
2016-08-17 06:25:58 +00:00
jsr .98 Close File....
2016-03-13 21:47:19 +00:00
>LDYA S.LoadFile.Len Return File Length...
ldx S.LoadFile.hMem ...and hMem to Caller
2015-03-14 21:48:35 +00:00
clc
rts
2015-06-03 18:30:57 +00:00
2015-03-14 21:48:35 +00:00
.97 pha
lda S.LoadFile.hMem
2015-03-14 21:48:35 +00:00
jsr S.FreeMemA freemem because of failed load
pla
2015-06-03 18:30:57 +00:00
2015-03-14 21:48:35 +00:00
.98 pha
lda S.LoadFile.hRef
2015-03-14 21:48:35 +00:00
jsr S.MLICloseA
lda S.LoadFile.hBuf
2015-03-14 21:48:35 +00:00
jsr S.FreeMemA ProDOS IO Buffer
pla
2015-06-03 18:30:57 +00:00
2016-08-17 06:25:58 +00:00
.99 sec
2015-03-14 21:48:35 +00:00
rts
*--------------------------------------
S.LoadFile.hRef .BS 1
S.LoadFile.hBuf .BS 1
S.LoadFile.hMem .BS 1
2016-08-17 06:25:58 +00:00
S.LoadFile.Mem .BS 2
S.LoadFile.Len .BS 2
*--------------------------------------
2016-06-24 06:02:32 +00:00
* S.ListDirInitYA
2015-03-14 21:48:35 +00:00
* in :
2016-06-24 06:02:32 +00:00
* Y,A = PSTR /DIR,/DIR/*.?s
2015-03-14 21:48:35 +00:00
* out :
* A = hMem of Dir Listing
*--------------------------------------
2016-08-28 20:48:01 +00:00
S.ListDirInitYA >STYA ZPQuickPtr3 Store path
2016-05-01 21:13:54 +00:00
2016-08-28 20:48:01 +00:00
lda (ZPQuickPtr3)
2015-03-14 21:48:35 +00:00
tay
ldx #0
2016-08-28 20:48:01 +00:00
.1 lda (ZPQuickPtr3),y reverse read path until '/' found
2015-03-14 21:48:35 +00:00
cmp #'/'
beq .2
inx
dey
bne .1
2016-08-28 20:48:01 +00:00
.2 stx TmpFileName store file pattern len in buffer
2015-03-14 21:48:35 +00:00
txa
2016-08-28 20:48:01 +00:00
beq .4 no pattern ?
2015-03-14 21:48:35 +00:00
2016-08-28 20:48:01 +00:00
lda (ZPQuickPtr3)
2015-03-14 21:48:35 +00:00
tay
2016-08-28 20:48:01 +00:00
.3 lda (ZPQuickPtr3),y
2015-03-14 21:48:35 +00:00
sta TmpFileName,x
dey
dex
bne .3
tya
2016-08-28 20:48:01 +00:00
sta (ZPQuickPtr3) remove pattern from path
2015-03-14 21:48:35 +00:00
.4 >PUSHWI S.LISTDIR.SIZE get LISTDIR Struct
2015-06-03 18:30:57 +00:00
>PUSHBI S.MEM.F.INIT0 reset all bytes
2015-03-14 21:48:35 +00:00
jsr S.GetMem
bcs .99
2016-08-28 20:48:01 +00:00
stx S.ListDirInitYA.hDir
2016-08-28 20:48:01 +00:00
>STYA ZPQuickPtr4 Store LISTDIR Struct
2015-03-14 21:48:35 +00:00
2016-08-28 20:48:01 +00:00
>LDYA ZPQuickPtr3
jsr S.NewPStrYA
bcs .99
2016-08-17 06:25:58 +00:00
txa
ldy #S.LISTDIR.hPATH
2016-08-28 20:48:01 +00:00
sta (ZPQuickPtr4),y
lda TmpFileName
2015-03-14 21:48:35 +00:00
beq .5
2016-08-28 20:48:01 +00:00
>LDYAI TmpFileName
jsr S.NewPStrYA
bcs .99
2015-03-14 21:48:35 +00:00
txa
ldy #S.LISTDIR.hPATTERN
2016-08-28 20:48:01 +00:00
sta (ZPQuickPtr4),y
2015-03-14 21:48:35 +00:00
2016-08-28 20:48:01 +00:00
.5 lda (ZPQuickPtr3)
2015-03-14 21:48:35 +00:00
cmp #1 length = 1 ? ('/')
bne .6
2016-08-28 20:48:01 +00:00
2015-03-14 21:48:35 +00:00
jsr S.ListDirInitAV
bcs .98
lda S.ListDirInitYA.hDir
2015-03-14 21:48:35 +00:00
rts
.6 jsr S.ListDirInitAD
bcs .98
lda S.ListDirInitYA.hDir
2015-03-14 21:48:35 +00:00
rts
.98 pha
lda S.ListDirInitYA.hDir Discard S.LISTDIR
2015-03-14 21:48:35 +00:00
jsr S.ListDirCloseA
pla
.99 sec
rts
*--------------------------------------
S.ListDirInitYA.hDir .BS 1
*--------------------------------------
2015-03-14 21:48:35 +00:00
S.ListDirInitAV >PUSHWI 256
>PUSHBI 0
jsr S.GetMem
bcs .99
>PUSHYA push buffer for online call
txa
2016-08-28 20:48:01 +00:00
sta (ZPQuickPtr4) save hONLINE buffer
2015-03-14 21:48:35 +00:00
>PUSHBI 0 All devices
jsr S.MLIOnline
bcs .98
ldy #S.LISTDIR.ONLINEPTR
2015-06-03 18:30:57 +00:00
* lda #0 make index point first Entry
2016-08-28 20:48:01 +00:00
* sta (ZPQuickPtr4),y
2015-06-03 18:30:57 +00:00
2015-03-14 21:48:35 +00:00
clc
rts
2016-08-28 20:48:01 +00:00
.98 lda (ZPQuickPtr4)
2015-03-14 21:48:35 +00:00
jsr S.FreeMemA
.99 sec
rts
*--------------------------------------
2015-06-03 18:30:57 +00:00
S.ListDirInitAD
* lda #0
2016-08-28 20:48:01 +00:00
* sta (ZPQuickPtr4) reset hONLINE
2015-06-03 18:30:57 +00:00
2016-08-28 20:48:01 +00:00
>LDYA ZPQuickPtr3 Open DIR
2015-06-03 18:30:57 +00:00
jsr S.MLIOpenYA
2015-03-14 21:48:35 +00:00
bcs .99
ldy #S.LISTDIR.REFNUM
2016-08-28 20:48:01 +00:00
sta (ZPQuickPtr4),y save ref_num
2015-03-14 21:48:35 +00:00
txa
ldy #S.LISTDIR.hIOBUF
2016-08-28 20:48:01 +00:00
sta (ZPQuickPtr4),y save ProDOS IO buffer hMem
2015-03-14 21:48:35 +00:00
>PUSHWI 512 get Read buffer
>PUSHBI 0
jsr S.GetMem
bcs .99
txa
ldy #S.LISTDIR.hREADBUF save Read Buffer hMem
2016-08-28 20:48:01 +00:00
sta (ZPQuickPtr4),y
2015-03-14 21:48:35 +00:00
jsr S.ListDirReadBlock
bcs .99
>STYA ZPQuickPtr1
ldy #$23 get entry_length
lda (ZPQuickPtr1),y
ldy #S.LISTDIR.EL
2016-08-28 20:48:01 +00:00
sta (ZPQuickPtr4),y
2015-03-14 21:48:35 +00:00
ldy #$24 get entry_per_block
lda (ZPQuickPtr1),y
ldy #S.LISTDIR.EPB
2016-08-28 20:48:01 +00:00
sta (ZPQuickPtr4),y
2015-03-14 21:48:35 +00:00
ldy #$25 get File_count LO
lda (ZPQuickPtr1),y
2015-06-24 20:48:53 +00:00
clc
adc #1 Add 1 for VOL/DIR Header
2015-03-14 21:48:35 +00:00
ldy #S.LISTDIR.FC
2016-08-28 20:48:01 +00:00
sta (ZPQuickPtr4),y
2015-03-14 21:48:35 +00:00
ldy #$26 get File_count HI
lda (ZPQuickPtr1),y
2015-06-24 20:48:53 +00:00
adc #0
2015-03-14 21:48:35 +00:00
ldy #S.LISTDIR.FC+1
2016-08-28 20:48:01 +00:00
sta (ZPQuickPtr4),y
2015-03-14 21:48:35 +00:00
2015-06-03 18:30:57 +00:00
* ldy #S.LISTDIR.FI
* lda #0
2016-08-28 20:48:01 +00:00
* sta (ZPQuickPtr4),y
2015-06-03 18:30:57 +00:00
* iny
2016-08-28 20:48:01 +00:00
* sta (ZPQuickPtr4),y set FI to $0000
2015-03-14 21:48:35 +00:00
clc
.99 rts
*--------------------------------------
* S.DirListNextA
* A = S.LISTDIR hMEM
* out :
* A = hMem To Dir Entry
*--------------------------------------
S.ListDirNextA jsr S.GetMemPtrA Get PTR to S.LISTDIR
>STYA R.CX
lda (R.CX) Online Data?
beq S.ListDirNextAD no,list files
*--------------------------------------
S.ListDirNextAV jsr S.GetMemPtrA
>STYA ZPQuickPtr1 ZPQuickPtr1 = Online DATA
.10 ldy #S.LISTDIR.ONLINEPTR
lda (R.CX),y
cmp #16
beq .9
inc
sta (R.CX),y
dec
asl
asl
asl
asl
tay
lda (ZPQuickPtr1),y
and #$0F
beq .10
sta TmpFileName
ldx #0
.1 iny
inx
lda (ZPQuickPtr1),y
sta TmpFileName,x
cpx TmpFileName
bne .1
>PUSHWI 16
>PUSHBI 0
jsr S.GetMem
bcs .9
>STYA ZPQuickPtr2
ldy #15
.2 lda TmpFileName,y
sta (ZPQuickPtr2),y
dey
bpl .2
lda (ZPQuickPtr2) Mark Record as "VOL"
ora #$C0
sta (ZPQuickPtr2)
txa Get back hMem of Volume.Name
clc
rts
.9 sec
rts
*--------------------------------------
S.ListDirNextAD stz S.ListDirNext.hRec Reset Return Record hMem
2015-03-14 21:48:35 +00:00
ldy #S.LISTDIR.FI File Index = File count ?
lda (R.CX),y
ldy #S.LISTDIR.FC
cmp (R.CX),y
bne .1
ldy #S.LISTDIR.FI+1
lda (R.CX),y
ldy #S.LISTDIR.FC+1
cmp (R.CX),y
bne .1
sec yes, exit no more file
rts
*--------------------------------------
.1 ldy #S.LISTDIR.EIB Entry Index in block = Entry per block ?
lda (R.CX),y
ldy #S.LISTDIR.EPB
cmp (R.CX),y
bne .2
jsr S.ListDirReadBlock
bcc .3
rts
*--------------------------------------
.2 ldy #S.LISTDIR.hREADBUF
lda (R.CX),y
jsr S.GetMemPtrA
.3 >STYA R.AX R.AX = READ BUFFER
ldy #S.LISTDIR.BLKPTR
lda (R.CX),y
clc
adc R.AX
sta R.AX
iny
lda (R.CX),y
adc R.AX+1
sta R.AX+1
lda (R.AX) Is is a deleted file ? (storage_type=0)
and #$F0
2015-06-03 18:30:57 +00:00
beq .5
2015-03-14 21:48:35 +00:00
cmp #$F0 Volume header ?
beq .30 yes, do not filter
cmp #$E0 Directory header ?
beq .30 yes, do not filter
ldy #S.LISTDIR.hPATTERN any filter ?
lda (R.CX),y
beq .30
2015-06-03 18:30:57 +00:00
2015-03-14 21:48:35 +00:00
jsr S.GetMemPtrA
2015-06-03 18:30:57 +00:00
>PUSHYA push Filter PTR
2015-03-14 21:48:35 +00:00
lda (R.AX)
and #$0F
sta TmpFileName
tay
.31 lda (R.AX),y
sta TmpFileName,y
dey
bne .31
2015-06-03 18:30:57 +00:00
>PUSHWI TmpFileName push Filename PTR
jsr S.PStrMatch
2015-06-03 18:30:57 +00:00
bcs .5 no match
2015-03-14 21:48:35 +00:00
.30 ldy #S.LISTDIR.EL Get Entry length
lda (R.CX),y
tay
lda #0
>PUSHYA Get an entry_length buffer
>PUSHBI 0
jsr S.GetMem
bcs .99
>STYA R.BX R.BX = DEST RECORD
stx S.ListDirNext.hRec
2015-03-14 21:48:35 +00:00
ldy #S.LISTDIR.EL
lda (R.CX),y
tay
dey
.4 lda (R.AX),y
sta (R.BX),y
dey
bpl .4
2015-06-03 18:30:57 +00:00
.5 ldy #S.LISTDIR.EIB Set ENTRY INDEX IN BLOCK +=1
2015-03-14 21:48:35 +00:00
lda (R.CX),y
inc
sta (R.CX),y
2015-06-03 18:30:57 +00:00
2015-03-14 21:48:35 +00:00
ldy #S.LISTDIR.EL Set BLOCK PTR +=entry_length
lda (R.CX),y
ldy #S.LISTDIR.BLKPTR
clc
adc (R.CX),y
sta (R.CX),y
iny
lda (R.CX),y
2015-06-03 18:30:57 +00:00
adc #0
2015-03-14 21:48:35 +00:00
sta (R.CX),y
2015-06-03 18:30:57 +00:00
lda (R.AX)
2015-03-14 21:48:35 +00:00
and #$E0 is storage_type = $F or $E ?
cmp #$E0 yes, do NOT increase FI
bne .6
ldy #S.LISTDIR.FI Increase FILE INDEX
lda (R.CX),y
inc
sta (R.CX),y
bne .6
iny
lda (R.CX),y
inc
sta (R.CX),y
.6 lda S.ListDirNext.hRec
2015-03-14 21:48:35 +00:00
bne .8
jmp S.ListDirNextAD Nothing to return, start over for next file entry
.8 clc
rts
.99 sec
rts
*--------------------------------------
* S.ListDirReadBlock
* In :
* CX = LISTDIR
* Out :
* Y,A = READ BUFFER
*--------------------------------------
S.ListDirReadBlock
ldy #S.LISTDIR.REFNUM
lda (R.CX),y get ref_num
sta MLICALL.PARAMS+1
ldy #S.LISTDIR.hREADBUF
lda (R.CX),y get READ BUFFER
jsr S.GetMemPtrA
>STYA MLICALL.PARAMS+2
>LDYAI 512
>STYA MLICALL.PARAMS+4
>MLICALL MLIREAD
bcs .9
ldy #S.LISTDIR.BLKPTR set BLKPTR to $0004
lda #4
sta (R.CX),y
iny
lda #0
sta (R.CX),y
ldy #S.LISTDIR.EIB set EIB to 0
sta (R.CX),y
>LDYA MLICALL.PARAMS+2
.9 rts
*--------------------------------------
S.ListDirNext.hRec .BS 1
*--------------------------------------
2015-03-14 21:48:35 +00:00
* S.DirListCloseA
* in :
* A = hS.LISTDIR
*--------------------------------------
S.ListDirCloseA pha
jsr S.GetMemPtrA
>STYA ZPQuickPtr1
ldy #S.LISTDIR.REFNUM
lda (ZPQuickPtr1),y
beq .1
jsr S.MLICloseA
bcs * If Close Failed, we cannot free IOBUF
.1 ldy #S.LISTDIR.hIOBUF
lda (ZPQuickPtr1),y
beq .2
jsr S.FreeMemA
.2 ldy #S.LISTDIR.hREADBUF
lda (ZPQuickPtr1),y
beq .3
jsr S.FreeMemA
2015-06-03 18:30:57 +00:00
.3 ldy #S.LISTDIR.hONLINE
lda (ZPQuickPtr1),y
2015-03-14 21:48:35 +00:00
beq .4
jsr S.FreeMemA
.4 ldy #S.LISTDIR.hPATTERN
lda (ZPQuickPtr1),y
beq .5
jsr S.FreeMemA
2015-06-24 20:48:53 +00:00
.5 ldy #S.LISTDIR.hPATH
lda (ZPQuickPtr1),y
beq .6
jsr S.FreeMemA
.6 pla
2015-03-14 21:48:35 +00:00
jsr S.FreeMemA
clc
rts
*--------------------------------------
TmpFileName .BS 16
*--------------------------------------
MAN
SAVE SYS/KERNEL.S.FIO
2015-03-14 21:48:35 +00:00
LOAD SYS/KERNEL.S
ASM