A2osX/SYS/KERNEL.S.DIRENT.txt
2017-08-25 17:02:16 +02:00

616 lines
12 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.BUILD
LOMEM $A00
INC 1
AUTO 6
*/--------------------------------------
* # OpenDir.YA
* ## In:
* Y,A = PATH (C-String)
* ## Out:
* CC : success
* A = hDIR
* CS : error
* A = EC
*\--------------------------------------
K.OpenDir.YA jsr PFT.CheckPathYA
>STYA ZPPtr2
jsr STDIO.SetMLIPathYA For GETFILEINFO,MLIOPEN
>LDYAI S.NODE.DIR
jsr K.GetMem0.YA
bcs .99
>STYA ZPPtr1
stx K.ReadDir.A.hDir
ldy #1
lda (ZPPtr2),y One char ?
beq .8 No, Go open dir....
.7 >MLICALL MLIGETFILEINFO
bcs .98 file/dir does not exists....quit
lda K.MLI.PARAMS+4
cmp #$0F Directory ?
bne .98
jsr STDIO.SetIOBUF
bcs .98
>MLICALL MLIOPEN
bcs .98
lda K.MLI.PARAMS+5 get ref_num
ldy #S.NODE.DIR.REF
sta (ZPPtr1),y
.8 lda K.ReadDir.A.hDir
clc
rts
.98 pha save MLI error
lda K.ReadDir.A.hDir
jsr K.CloseDir.A.1
pla get back MLI error
sec
.99 rts
*/--------------------------------------
* # ReadDir.A
* ## In:
* A = hDIR
* ## Out:
* CC : success
* X = hDIRENT
* Y,A = PTR to S.DIRENT
* CS : error
* A = EC
* note : A = 0 means no more entry
*\--------------------------------------
K.ReadDir.A.hDir .BS 1
K.ReadDir.A.hMem .BS 1
K.ReadDir.A.hDIRENT .BS 1
K.ReadDir.A.BufSize .BS 2
K.ReadDir.A.ECIB .BS 1
*--S.DIR Cache ------------------------
K.ReadDir.A.EL .BS 1
K.ReadDir.A.EPB .BS 1
K.ReadDir.A.EC .BS 2
*--------------------------------------
K.ReadDir.A jsr PFT.CheckNodeA
sta K.ReadDir.A.hDir
jsr K.GetMemPtr.A
>STYA ZPPtr1
ldy #S.NODE.DIR.REF
lda (ZPPtr1),y
beq K.ReadDir.A.ROOT
jmp K.ReadDir.A.DIR
K.ReadDir.A.NoMore
lda #0
sec CS,A=0 no more entry
rts
*--------------------------------------
K.ReadDir.A.ROOT
ldy #S.NODE.DIR.FC did we already returned something ?
lda (ZPPtr1),y
bne K.ReadDir.A.NoMore
stz K.MLI.PARAMS+1 All Volumes
>LDYAI K.Buf256
>STYA K.MLI.PARAMS+2
>STYA ZPPtr2
>MLICALL MLIONLINE
bcc .10
sec
.99 rts
* pass #1 compute BufSize.....
.10 lda #1 +1 for Ending 0
sta K.ReadDir.A.BufSize
stz K.ReadDir.A.BufSize+1
stz K.ReadDir.A.EC
ldy #0
.1 lda (ZPPtr2),y
and #$0F
beq .2
inc K.ReadDir.A.EC increase entry count
sec Add Filelen +1
adc #S.STAT will ends with CC
adc K.ReadDir.A.BufSize
sta K.ReadDir.A.BufSize
bcc .2
inc K.ReadDir.A.BufSize+1
.2 tya
clc
adc #16
tay
bcc .1 loop until 256 bytes scanned
* pass #2 Fill Buffer...
jsr K.ReadDir.A.GetBuf
bcs .99
.3 lda (ZPPtr2)
and #$0F
beq .88
tax
inc
sta K.MLI.PATH
lda #'/'
sta K.MLI.PATH+1
ldy #1
.4 lda (ZPPtr2),y
sta K.MLI.PATH+1,y
jsr K.ReadDir.A.AddToBuf
iny
dex
bne .4
txa Add ending 0 for C String
jsr K.ReadDir.A.AddToBuf
jsr K.ReadDir.A.ClrStat
lda (ZPPtr2)
asl DRIVE in Carry
pha
lda #0
rol
inc
sta K.S.STAT+S.STAT.P.DRIVE
pla
lsr CC
lsr
lsr
lsr
lsr
sta K.S.STAT+S.STAT.P.SLOT
>LDYAI K.MLI.PATH
>STYA K.MLI.PARAMS+1
>MLICALL MLIGETFILEINFO
sta K.S.STAT+S.STAT.P.DEVSTATUS
bcs .80
>LDYA K.MLI.PARAMS+5 AUXTYPE=TOTAL BLOCKS
>STYA K.S.STAT+S.STAT.P.DEVBLOCKS
>LDYA K.MLI.PARAMS+8
>STYA K.S.STAT+S.STAT.BLOCKS
.80 jsr K.ReadDir.A.ADDSTAT
.88 lda ZPPtr2
clc
adc #16
sta ZPPtr2
bcc .89
inc ZPPtr2+1
.89 dec K.ReadDir.A.EC
bne .3
* lda #0 done by S.MEM.F.INIT0
* sta (ZPPtr4) Ending 0
ldy #S.NODE.DIR.FC
lda #16
sta (ZPPtr1),y Flag that we returned somthing for next time
lda K.ReadDir.A.hDIRENT
tax
jmp K.GetMemPtr.A
*--------------------------------------
K.ReadDir.A.DIR sta K.MLI.PARAMS+1 A=#S.DIR.PRODOS.REF
>LDYAI 512 Get a 512 bytes buffer for reading dir...
jsr K.GetMem.YA
bcs .99
stx K.ReadDir.A.hMem
>STYA K.MLI.PARAMS+2 For reading
pha
tya
* clc CC from K.GetMem
adc #4 Skip 4 bytes linked list
sta ZPPtr2 PTR to Buffer for PASS #1
sta ZPPtr3 PTR to Buffer for PASS #2
pla
adc #0
sta ZPPtr2+1 PTR to Buffer for PASS #1
sta ZPPtr3+1 PTR to Buffer for PASS #2
>LDYAI 512
>STYA K.MLI.PARAMS+4
>MLICALL MLIREAD Read A block from directory
bcs .98
ldy #S.NODE.DIR.EL Check if first run....
lda (ZPPtr1),y
bne .2 no, we have all we need....
ldy #$1f+3
ldx #3
.1 lda (ZPPtr2),y Get K.ReadDir.A.EL.... From Block
sta K.ReadDir.A.EL,x
dey
dex
bpl .1
inc K.ReadDir.A.EC Add one to EC because we include VOL/DIR Header
bne .4
inc K.ReadDir.A.EC+1 ...and ProDOS does NOT include header entry in EC
bra .4
.98 jsr K.ReadDir.A.CLN
sec
.99 rts
.2 ldy #S.NODE.DIR.EL+3
ldx #3
.3 lda (ZPPtr1),y get this session parameters from S.DIR
sta K.ReadDir.A.EL,x
dey
dex
bpl .3
.4 lda K.ReadDir.A.EC
eor #$ff
tax
lda K.ReadDir.A.EC+1
eor #$ff
tay
inx Any entry remaining ?
bne .5
iny
beq .98 no...exit
* pass #1 compute BufSize...
.5 lda K.ReadDir.A.EPB
sta K.ReadDir.A.ECIB
lda #1 For Ending 0
sta K.ReadDir.A.BufSize
stz K.ReadDir.A.BufSize+1
K.ReadDir.A.DIR1 lda (ZPPtr2) X = EntryCount In This Block
beq .7 Free slot....goto next
and #$F0 get storage_type
cmp #$F0 Volume header ?
beq .1
cmp #$E0 directory header ?
beq .2
lda (ZPPtr2) regular DIR or File, get LEN
and #$F compute filename len
sec add "#<filename>" + S.STAT
adc #S.STAT
.HS 2C bit abs
.1 lda #2+S.STAT add "1." string + S.STAT
.HS 2C bit abs
.2 lda #2+S.STAT+3+S.STAT add "1." + S.STAT + "2.." + S.STAT...
clc
adc K.ReadDir.A.BufSize
sta K.ReadDir.A.BufSize
bcc .3
inc K.ReadDir.A.BufSize+1
.3 inx
bne .7
iny
bra K.ReadDir.A.DIR2 we reached last entry in whole DIR
.7 lda ZPPtr2
clc
adc K.ReadDir.A.EL
sta ZPPtr2
bcc .8
inc ZPPtr2+1
.8 dec K.ReadDir.A.ECIB
bne K.ReadDir.A.DIR1
* pass #2 Fill Buffer...(ZPPtr1 & Ptr2 can now be trashed)
K.ReadDir.A.DIR2 jsr K.ReadDir.A.GetBuf
bcs .9
lda K.ReadDir.A.EPB
sta K.ReadDir.A.ECIB
.1 lda (ZPPtr3)
beq .7 Empty slot, skip
and #$F0
cmp #$F0 Vol Header ?
bne .2
jsr K.ReadDir.A.ADD.
bra .6
.2 cmp #$E0 Dir Header ?
bne .3
jsr K.ReadDir.A.ADD.
jsr K.ReadDir.A.ADD..
bra .6
.3 jsr K.ReadDir.A.AddFNToBuf
jsr K.ReadDir.A.ClrStat
lda (ZPPtr3)
and #$F0
cmp #$D0 Directory ?
bne .5
jsr K.ReadDir.A.ADDD
bra .6
.5 jsr K.ReadDir.A.ADDF
.6 lda K.ReadDir.A.EC decrease global counter...
sec
sbc #1
sta K.ReadDir.A.EC
lda K.ReadDir.A.EC+1
sbc #0
sta K.ReadDir.A.EC+1
ora K.ReadDir.A.EC
beq .8 0! no more files in DIR
.7 dec K.ReadDir.A.ECIB 0! no more file in block
beq .8
lda ZPPtr3
clc
adc K.ReadDir.A.EL
sta ZPPtr3
bcc .1
inc ZPPtr3+1
bra .1
.9 jsr K.ReadDir.A.CLN
sec
rts
.8
* lda #0 S.MEM.F.INIT0 already did this
* sta (ZPPtr4) Ending 0
lda K.ReadDir.A.hDir Restore ZPPtr1 trashed by STR API calls
jsr K.GetMemPtr.A
>STYA ZPPtr1
ldx #3
ldy #S.NODE.DIR.EL+3
.81 lda K.ReadDir.A.EL,x Store back this session prameters to S.DIR
sta (ZPPtr1),y
dey
dex
bpl .81
jsr K.ReadDir.A.CLN Discard READBUFFER
lda K.ReadDir.A.hDIRENT
tax
jmp K.GetMemPtr.A
*--------------------------------------
K.ReadDir.A.CLN pha
lda K.ReadDir.A.hMem
jsr K.FreeMem.A
pla
rts
*--------------------------------------
K.ReadDir.A.GetBuf
>LDYA K.ReadDir.A.BufSize Get a BufSize bytes buffer for storing results
jsr K.GetMem0.YA make sure 0 filled
bcs .9
stx K.ReadDir.A.hDIRENT
>STYA ZPPtr4
.9 rts
*--------------------------------------
K.ReadDir.A.ADD. ldx #1 filename="1."
.HS 2C bit abs
K.ReadDir.A.ADD..
ldx #2 filename="2.."
lda #'.'
.1 jsr K.ReadDir.A.AddToBuf Add X dot(s)
dex
bne .1
txa
jsr K.ReadDir.A.AddToBuf Add Ending 0
jsr K.ReadDir.A.ClrStat
* ldy #$25 total_blocks
* lda (ZPPtr3),y
* sta K.S.STAT+S.STAT.BLOCKS
* iny
* lda (ZPPtr3),y
* sta K.S.STAT+S.STAT.BLOCKS+1
*--------------------------------------
K.ReadDir.A.ADDD
lda #$0F
sta K.S.STAT+S.STAT.P.TYPE
lda /S.STAT.MODE.DIR
sta K.S.STAT+S.STAT.MODE+1
bra K.ReadDir.A.AddAccess
*--------------------------------------
K.ReadDir.A.ADDF
lda /S.STAT.MODE.REG
sta K.S.STAT+S.STAT.MODE+1
ldx #ADDF.DST-ADDF.SRC
.1 ldy ADDF.SRC-1,x
lda (ZPPtr3),y
ldy ADDF.DST-1,x
sta K.S.STAT,y
dex
bne .1
*--------------------------------------
K.ReadDir.A.AddAccess
ldy #$1E ProDOS Access
lda (ZPPtr3),y
ldx #0
bit #$01 ProDOS R
beq .2
ldx #S.STAT.MODE.RO
.2 bit #$C2 ProDOS D,Rn,W
beq .3
txa
ora #S.STAT.MODE.XO+S.STAT.MODE.WO
.HS 89 bit imm to skip txa
.3 txa
sta K.S.STAT+S.STAT.MODE
*--------------------------------------
K.ReadDir.A.AddTime
ldx #K.S.STAT+S.STAT.CTIME
ldy /K.S.STAT+S.STAT.CTIME
lda #$18 creation Date/time
jsr K.ReadDir.A.ConvertTime
ldx #K.S.STAT+S.STAT.MTIME
ldy /K.S.STAT+S.STAT.MTIME
lda #$21 mod Date/time
jsr K.ReadDir.A.ConvertTime
*--------------------------------------
K.ReadDir.A.AddStat
ldy #S.STAT-1
.1 lda K.S.STAT,y
sta (ZPPtr4),y
dey
bpl .1
lda ZPPtr4
clc
adc #S.STAT
sta ZPPtr4
bcc .8
inc ZPPtr4+1
.8 rts
*--------------------------------------
ADDF.SRC .HS 1013141516171f20
ADDF.DST .DA #S.STAT.P.TYPE,#S.STAT.BLOCKS,#S.STAT.BLOCKS+1
.DA #S.STAT.SIZE,#S.STAT.SIZE+1,#S.STAT.SIZE+2
.DA #S.STAT.P.AUXTYPE,#S.STAT.P.AUXTYPE+1
*--------------------------------------
K.ReadDir.A.ClrStat
ldx #S.STAT-1
.1 stz K.S.STAT,x
dex
bpl .1
rts
*--------------------------------------
K.ReadDir.A.AddFNToBuf
ldy #$1C version/min_version for lowercase bitmap
lda (ZPPtr3),y check bxxxxxxx.xxxxxxxx...
bpl .7 not set, no lowercase bitmap present
pha
iny
lda (ZPPtr3),y
pha
lda #$1
sta .2+1
ldy #15
.1 pla
.2 bit #$ff
pha
beq .3
lda (ZPPtr3),y
ora #$20 convert a-z to A-Z adding from $4x to $6x
sta (ZPPtr3),y
.3 asl .2+1
bne .4
rol .2+1
pla
.4 dey
bne .1
pla
.7 lda (ZPPtr3)
and #$0F get filename len
tax
ldy #1
.8 lda (ZPPtr3),y
jsr K.ReadDir.A.AddToBuf
iny
dex
bne .8
txa
jsr K.ReadDir.A.AddToBuf
rts
*--------------------------------------
K.ReadDir.A.AddToBuf
sta (ZPPtr4)
inc ZPPtr4
bne .8
inc ZPPtr4+1
.8 rts
*--------------------------------------
K.ReadDir.A.ConvertTime
stx ZPPtr2
sty ZPPtr2+1
clc
adc ZPPtr3
sta ZPPtr1
lda ZPPtr3+1
adc #0
sta ZPPtr1+1
jmp TIME.PTime2TimePtr1Ptr2
*/-------------------------------------
* # CloseDir.A
* ## In:
* A = hDIR
* ## Out:
* none, always succeed.
*\-------------------------------------
K.CloseDir.A .EQ K.FClose.A
K.CloseDir.A.1 .EQ K.FClose.A.1
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SYS/KERNEL.S.DIRENT
LOAD /A2OSX.SRC/SYS/KERNEL.S
ASM