A2osX/SYS/KERNEL.S.FIO.txt
2016-01-09 23:40:19 +01:00

621 lines
13 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
*--------------------------------------
* PUBLIC
*--------------------------------------
S.CheckPrefixA jsr S.GetMemPtrA
S.CheckPrefixYA >STYA MLICALL.PARAMS+1
>STYA ZPQuickPtr1
lda (ZPQuickPtr1)
beq .98
tax
ldy #1
lda (ZPQuickPtr1),y
cmp #'/'
bne .98
cpx #1 "/" allowed for listing online volumes
beq .8
>MLICALL MLIGETFILEINFO
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 :
* PULLB = hMem to Search Path (PSTRING) %LIB%;/SYS/SLIB
* PULLB = hMem to File Name (PSTRING)
* out :
* A = hMem of FilePath (PSTRING)
*--------------------------------------
S.FileSearch >PULLA Get Search path
jsr S.ExpandPStrA Expand it
bcc .10
pha save error code
>PULLA discard file name
pla
sec
rts
.10 sta S.FileSearch.hSrch Store Expanded path list to search
>PULLB S.FileSearch.hFile Store Filename
lda #1
sta S.FileSearch.Idx Start At Token 1
.1 >PUSHB S.FileSearch.hSrch push expanded path list
>PUSHBI $3B Push SEP=';'
>PUSHB S.FileSearch.Idx Push Token IDX
jsr S.PStrGetTkn Get token in A
bcs .98
sta S.FileSearch.hPath Store Token path
>PUSHB S.FileSearch.hFile push filename
>PUSHB S.FileSearch.hPath Push Token path
jsr S.PStrCat
bcs .97
sta S.FileSearch.hFull Store Full path (Token Path+filename)
jsr S.MLIGetFileInfoA
bcc .8
lda S.FileSearch.hFull Discard this Full Path
jsr S.FreeMemA
lda S.FileSearch.hPath Discard Token path
jsr S.FreeMemA
inc S.FileSearch.Idx Try next Token
bne .1
beq .98 go to discard Expanded path list
.97 lda S.FileSearch.hPath Discard Token path
jsr S.FreeMemA
.98 lda S.FileSearch.hSrch Discard Expanded hSrch list
jsr S.FreeMemA
lda #SYSMGR.ERRFNF
sec
rts
.8 jsr .97 Dicard all except Full Path
lda S.FileSearch.hFull
clc
rts
*--------------------------------------
S.FileSearch.hSrch .BS 1
S.FileSearch.hFile .BS 1
S.FileSearch.Idx .BS 1
S.FileSearch.hPath .BS 1
S.FileSearch.hFull .BS 1
*--------------------------------------
* S.LoadFileA
* in :
* A = hMem of FilePath (PSTRING)
* out :
* Y,A = File Length
* X = hMem of Loaded File
*--------------------------------------
S.LoadFileA jsr S.GetMemPtrA
S.LoadFileYA jsr S.ExpandPStrYA
sta S.LoadFile.hExp
jsr S.GetMemPtrA
jsr S.MLIOpenYA
bcc .10
jmp .99
.10 sta S.LoadFile.hRef save ref_num
stx S.LoadFile.hBuf save Prodos Buffer for freemem
jsr S.MLIGetEOFA
bcs .98
phx Larger than 64k?
plx
beq .1 File too big!!!!
lda #SYSMGR.ERRFTB
bra .98
.1 >STYA S.LoadFile.Len save Length
>PUSHYA Push Length for S.GetMem
>PUSHBI 0
jsr S.GetMem
bcs .98
phy save Ptr
pha
stx S.LoadFile.hMem save Segment hMem
>PUSHW S.LoadFile.Len Push Length for S.MLIRead
pla restore Dest PTR
ply
>PUSHYA and push for S.MLIRead
>PUSHB S.LoadFile.hRef Push ref_num
jsr S.MLIRead
bcs .97
lda S.LoadFile.hRef
jsr S.MLICloseA
lda S.LoadFile.hBuf
jsr S.FreeMemA Discard ProDOS IO Buffer
>LDYA S.LoadFile.Len Return File Length...
ldx S.LoadFile.hMem ...and hMem to Caller
clc
rts
.97 pha
lda S.LoadFile.hMem
jsr S.FreeMemA freemem because of failed load
pla
.98 pha
lda S.LoadFile.hRef
jsr S.MLICloseA
lda S.LoadFile.hBuf
jsr S.FreeMemA ProDOS IO Buffer
pla
.99 pha
lda S.LoadFile.hExp
jsr S.FreeMemA
pla
sec
rts
*--------------------------------------
S.LoadFile.hRef .BS 1
S.LoadFile.hBuf .BS 1
S.LoadFile.hExp .BS 1
S.LoadFile.hMem .BS 1
S.LoadFile.Len .BS 2
*--------------------------------------
* S.ListDirInitA
* in :
* A = PATH (PSTR) /DIR,/DIR/*.?s
* out :
* A = hMem of Dir Listing
*--------------------------------------
S.ListDirInitA
* sta R.AL
stz TmpFileName Reset File.Pattern
jsr S.GetMemPtrA
>STYA R.BX Store path
* jsr S.CheckPrefixYA is it a existing directory?
* bcc .4 yes, continue with empty pattern
lda (R.BX) no, get pattern at end of full path
tay
ldx #0
.1 lda (R.BX),y
cmp #'/'
beq .2
inx
dey
bne .1
.2 stx TmpFileName
txa
beq .4
lda (R.BX)
tay
.3 lda (R.BX),y
sta TmpFileName,x
dey
dex
bne .3
tya
sta (R.BX) remove pattern from path
.4 >PUSHWI S.LISTDIR.SIZE get LISTDIR Struct
>PUSHBI S.MEM.F.INIT0 reset all bytes
jsr S.GetMem
bcs .99
stx R.AH
>STYA R.CX Store LISTDIR Struct
>LDYA R.BX
jsr S.NewPStrYA
bcs .99
ldy #S.LISTDIR.hPATH
sta (R.CX),y
ldy TmpFileName
beq .5
lda #0
>PUSHYA
>PUSHBI 0
jsr S.GetMem
bcs .98
>STYA ZPQuickPtr1
txa
ldy #S.LISTDIR.hPATTERN
sta (R.CX),y
ldy TmpFileName
.40 lda TmpFileName,y
sta (ZPQuickPtr1),y
dey
bpl .40
.5 lda (R.BX)
cmp #1 length = 1 ? ('/')
bne .6
jsr S.ListDirInitAV
bcs .98
lda R.AH
rts
.6 jsr S.ListDirInitAD
bcs .98
lda R.AH
rts
.98 pha
lda R.AH Discard S.LISTDIR
jsr S.ListDirCloseA
pla
.99 sec
rts
*--------------------------------------
S.ListDirInitAV >PUSHWI 256
>PUSHBI 0
jsr S.GetMem
bcs .99
>PUSHYA push buffer for online call
txa
sta (R.CX) save hONLINE buffer
>PUSHBI 0 All devices
jsr S.MLIOnline
bcs .98
ldy #S.LISTDIR.ONLINEPTR
* lda #0 make index point first Entry
* sta (R.CX),y
clc
rts
.98 lda (R.CX)
jsr S.FreeMemA
.99 sec
rts
*--------------------------------------
S.ListDirInitAD
* lda #0
* sta (R.CX) reset hONLINE
>LDYA R.BX Open DIR
jsr S.MLIOpenYA
bcs .99
ldy #S.LISTDIR.REFNUM
sta (R.CX),y save ref_num
txa
ldy #S.LISTDIR.hIOBUF
sta (R.CX),y save ProDOS IO buffer hMem
>PUSHWI 512 get Read buffer
>PUSHBI 0
jsr S.GetMem
bcs .99
txa
ldy #S.LISTDIR.hREADBUF save Read Buffer hMem
sta (R.CX),y
jsr S.ListDirReadBlock
bcs .99
>STYA ZPQuickPtr1
ldy #$23 get entry_length
lda (ZPQuickPtr1),y
ldy #S.LISTDIR.EL
sta (R.CX),y
ldy #$24 get entry_per_block
lda (ZPQuickPtr1),y
ldy #S.LISTDIR.EPB
sta (R.CX),y
ldy #$25 get File_count LO
lda (ZPQuickPtr1),y
clc
adc #1 Add 1 for VOL/DIR Header
ldy #S.LISTDIR.FC
sta (R.CX),y
ldy #$26 get File_count HI
lda (ZPQuickPtr1),y
adc #0
ldy #S.LISTDIR.FC+1
sta (R.CX),y
* ldy #S.LISTDIR.FI
* lda #0
* sta (R.CX),y
* iny
* sta (R.CX),y set FI to $0000
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 R.DL Reset Return Record hMem
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
beq .5
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
jsr S.GetMemPtrA
>PUSHYA push Filter PTR
lda (R.AX)
and #$0F
sta TmpFileName
tay
.31 lda (R.AX),y
sta TmpFileName,y
dey
bne .31
>PUSHWI TmpFileName push Filename PTR
jsr S.PStrMatchP
bcs .5 no match
.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 R.DL
ldy #S.LISTDIR.EL
lda (R.CX),y
tay
dey
.4 lda (R.AX),y
sta (R.BX),y
dey
bpl .4
.5 ldy #S.LISTDIR.EIB Set ENTRY INDEX IN BLOCK +=1
lda (R.CX),y
inc
sta (R.CX),y
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
adc #0
sta (R.CX),y
lda (R.AX)
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 R.DL
bne .8
jmp S.ListDirNextAD Nothing to return, start over for next file entry
.8 clc
rts
.99 sec
rts
*--------------------------------------
* 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
.3 ldy #S.LISTDIR.hONLINE
lda (ZPQuickPtr1),y
beq .4
jsr S.FreeMemA
.4 ldy #S.LISTDIR.hPATTERN
lda (ZPQuickPtr1),y
beq .5
jsr S.FreeMemA
.5 ldy #S.LISTDIR.hPATH
lda (ZPQuickPtr1),y
beq .6
jsr S.FreeMemA
.6 pla
jsr S.FreeMemA
clc
rts
*--------------------------------------
* PRIVATE
*--------------------------------------
* 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
*--------------------------------------
TmpFileName .BS 16
*--------------------------------------
MAN
SAVE SYS/KERNEL.S.FIO
LOAD SYS/KERNEL.S
ASM