A2osX/SYS/KERNEL.S.DIRENT.txt

479 lines
9.1 KiB
Plaintext
Raw Normal View History

2017-12-22 21:24:30 +00:00
NEW
2019-05-25 19:24:07 +00:00
AUTO 3,1
*/--------------------------------------
2018-06-21 15:12:10 +00:00
* # OpenDir
2018-07-20 11:51:08 +00:00
* ## C
* `int hDIR opendir (const char * dirpath);`
* ## ASM
2020-03-16 06:50:15 +00:00
* `>LDYA dirpath`
2018-07-20 11:51:08 +00:00
* `>SYSCALL opendir`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
* CC : success
* A = hDIR
* CS : error
* A = EC
*\--------------------------------------
2020-03-16 06:50:15 +00:00
K.OpenDir jsr PFT.CheckPathYA
2020-03-10 16:42:07 +00:00
bcs .9
2020-02-14 07:21:56 +00:00
2019-07-12 14:51:57 +00:00
ldx #1
jsr IO.MkFD
2020-03-10 16:42:07 +00:00
bcs .9
2019-07-12 14:51:57 +00:00
lda K.Buf256+1 One char ("/") ?
beq .8 No, Go open dir....
2019-10-03 06:25:27 +00:00
2018-10-08 05:55:28 +00:00
>MLICALL MLIGETFILEINFO
bcs .98 file/dir does not exists....quit
lda K.MLI.PARAMS+4
cmp #$0F Directory ?
bne .98
2020-03-16 06:50:15 +00:00
2019-07-26 14:23:07 +00:00
jsr IO.MLI.OPEN
2019-01-30 16:23:00 +00:00
bcs .98
2016-08-24 15:42:33 +00:00
2020-03-11 16:41:45 +00:00
.8 jsr STDIO.NewHFile
2018-10-08 05:55:28 +00:00
2019-02-28 16:45:33 +00:00
bcc K.ReadDir.RTS
2020-03-10 16:42:07 +00:00
.98 jmp UNISTD.Open.ERR
.9 >RET 2
2019-10-03 06:25:27 +00:00
*/--------------------------------------
2018-06-21 15:12:10 +00:00
* # ReadDir
2018-07-20 11:51:08 +00:00
* ## C
* `int readdir (int hDIR, S.DIRENT * dirent);`
* ## ASM
* `>PUSHW dirent`
* `lda hDIR`
* `>SYSCALL readdir`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
* CC : success
* X = hDIRENT
* Y,A = PTR to S.DIRENT
* CS : error
* A = EC
* note : A = 0 means no more entry
*\--------------------------------------
2019-01-04 13:17:31 +00:00
.DUMMY
2019-07-26 14:23:07 +00:00
.OR ZPTMP 8 Bytes
2020-03-11 16:41:45 +00:00
K.ReadDir.hBlk .BS 1
2018-06-21 15:12:10 +00:00
K.ReadDir.ECIB .BS 1
K.ReadDir.EL .BS 1
K.ReadDir.EPB .BS 1
K.ReadDir.EC .BS 2
2020-03-11 16:41:45 +00:00
K.ReadDir.BufSize .BS 2
K.ReadDir.hBuf .BS 1
2019-01-04 13:17:31 +00:00
.ED
*--------------------------------------
2018-06-22 14:59:24 +00:00
K.ReadDir jsr PFT.CheckNodeA
2018-11-16 16:04:20 +00:00
bcs K.ReadDir.RTS
2020-03-16 06:50:15 +00:00
2019-01-30 16:23:00 +00:00
ldy #S.FD.REG.REF
2018-08-11 10:57:57 +00:00
lda (pFD),y
2018-06-21 15:12:10 +00:00
beq K.ReadDir.ROOT
2020-03-16 06:50:15 +00:00
2020-03-17 16:03:32 +00:00
bpl .1
2020-03-16 06:50:15 +00:00
jmp K.ReadDir.DEV
.1 jmp K.ReadDir.DIR
2018-06-21 15:12:10 +00:00
K.ReadDir.NoMore
2019-02-22 13:34:06 +00:00
lda #MLI.E.EOF
sec
2018-11-16 16:04:20 +00:00
K.ReadDir.RTS rts
*--------------------------------------
2020-03-16 06:50:15 +00:00
K.ReadDir.ROOT ldy #S.FD.DIR.FC did we already returned something ?
2018-08-11 10:57:57 +00:00
lda (pFD),y
2018-06-21 15:12:10 +00:00
bne K.ReadDir.NoMore
2020-02-16 20:45:16 +00:00
2019-06-24 15:32:22 +00:00
stz K.MLI.PARAMS+1 All Volumes
>LDYAI K.Buf256
>STYA K.MLI.PARAMS+2
2017-01-12 17:43:45 +00:00
>STYA ZPPtr2
2016-09-01 15:42:38 +00:00
>MLICALL MLIONLINE
2019-06-24 15:32:22 +00:00
bcs K.ReadDir.RTS
2019-11-27 22:04:55 +00:00
2020-02-16 20:45:16 +00:00
>LDYAI 16*16+16*S.STAT+1 16 (Vols+Stat) + \0
jsr K.ReadDir.GetBufYA
2019-06-24 15:32:22 +00:00
bcs K.ReadDir.RTS
2020-02-16 20:45:16 +00:00
lda #16
sta K.ReadDir.EC
.1 lda (ZPPtr2)
2016-09-02 06:09:44 +00:00
and #$0F
2020-02-16 20:45:16 +00:00
beq .6
2016-09-02 15:14:24 +00:00
tax
inc
sta K.MLI.PATH
lda #'/'
sta K.MLI.PATH+1
ldy #1
2020-02-16 20:45:16 +00:00
.2 lda (ZPPtr2),y
sta K.MLI.PATH+1,y
2018-06-21 15:12:10 +00:00
jsr K.ReadDir.AddToBuf
iny
dex
2020-02-16 20:45:16 +00:00
bne .2
txa Add ending 0 for C String
2018-06-21 15:12:10 +00:00
jsr K.ReadDir.AddToBuf
2019-12-02 07:09:58 +00:00
jsr SHARED.ClrStat
2020-02-29 14:06:28 +00:00
lda /S.STAT.MODE.BDEV
sta K.S.STAT+S.STAT.MODE+1
lda (ZPPtr2)
2020-02-16 20:45:16 +00:00
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
2016-09-02 15:14:24 +00:00
>MLICALL MLIGETFILEINFO
sta K.S.STAT+S.STAT.P.DEVSTATUS
2020-02-16 20:45:16 +00:00
bcs .3
>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
2020-02-16 20:45:16 +00:00
.3 jsr K.ReadDir.AddStat
.6 lda ZPPtr2
2016-09-02 15:14:24 +00:00
clc
adc #16
2017-01-12 17:43:45 +00:00
sta ZPPtr2
2020-02-16 20:45:16 +00:00
bcc .7
2017-01-12 17:43:45 +00:00
inc ZPPtr2+1
2020-02-16 20:45:16 +00:00
.7 dec K.ReadDir.EC
bne .1
* lda #0 done by S.MEM.F.INIT0
2017-01-12 17:43:45 +00:00
* sta (ZPPtr4) Ending 0
2020-02-16 20:45:16 +00:00
ldy #S.FD.DIR.FC
lda #16
2020-03-16 06:50:15 +00:00
sta (pFD),y Flag that we returned something for next time
2018-06-21 15:12:10 +00:00
jmp K.ReadDir.EXIT
*--------------------------------------
2020-03-16 06:50:15 +00:00
K.ReadDir.DEV >DEBUG
jmp K.ReadDir.NoMore
*--------------------------------------
2019-06-24 15:32:22 +00:00
K.ReadDir.DIR sta K.MLI.PARAMS+1 A=#S.DIR.PRODOS.REF
2016-09-02 06:09:44 +00:00
>LDYAI 512 Get a 512 bytes buffer for reading dir...
2018-06-21 15:12:10 +00:00
jsr K.GetMem
bcs .99
2019-12-02 07:09:58 +00:00
2020-03-11 16:41:45 +00:00
stx K.ReadDir.hBlk
>STYA K.MLI.PARAMS+2 For reading
pha
tya
2016-09-21 15:20:37 +00:00
* 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
2019-12-02 07:09:58 +00:00
>LDYAI 512
>STYA K.MLI.PARAMS+4
>MLICALL MLIREAD Read A block from directory
bcs .98
2019-12-02 07:09:58 +00:00
2018-07-10 15:33:13 +00:00
ldy #S.FD.DIR.EL Check if first run....
2018-08-11 10:57:57 +00:00
lda (pFD),y
bne .2 no, we have all we need....
2019-12-02 07:09:58 +00:00
2016-09-23 06:00:00 +00:00
ldy #$1f+3
ldx #3
2019-12-02 07:09:58 +00:00
2018-06-21 15:12:10 +00:00
.1 lda (ZPPtr2),y Get K.ReadDir.EL.... From Block
sta K.ReadDir.EL,x
dey
2016-09-23 06:00:00 +00:00
dex
bpl .1
2019-12-02 07:09:58 +00:00
2018-06-21 15:12:10 +00:00
inc K.ReadDir.EC Add one to EC because we include VOL/DIR Header
bne .4
2019-12-02 07:09:58 +00:00
2018-06-21 15:12:10 +00:00
inc K.ReadDir.EC+1 ...and ProDOS does NOT include header entry in EC
bra .4
2020-03-11 16:41:45 +00:00
.98 jmp K.ReadDir.FreeBlk
.99 rts
2019-12-02 07:09:58 +00:00
2018-07-10 15:33:13 +00:00
.2 ldy #S.FD.DIR.EL+3
ldx #3
2018-08-11 10:57:57 +00:00
.3 lda (pFD),y get this session parameters from S.DIR
2018-06-21 15:12:10 +00:00
sta K.ReadDir.EL,x
dey
dex
bpl .3
2019-12-02 07:09:58 +00:00
2018-06-21 15:12:10 +00:00
.4 lda K.ReadDir.EC
eor #$ff
tax
2018-06-21 15:12:10 +00:00
lda K.ReadDir.EC+1
eor #$ff
tay
inx Any entry remaining ?
bne .5
2019-12-02 07:09:58 +00:00
iny
beq .98 no...exit
* pass #1 compute BufSize...
2018-06-21 15:12:10 +00:00
.5 lda K.ReadDir.EPB
sta K.ReadDir.ECIB
lda #1 For Ending 0
2018-06-21 15:12:10 +00:00
sta K.ReadDir.BufSize
stz K.ReadDir.BufSize+1
2019-12-02 07:09:58 +00:00
2018-06-21 15:12:10 +00:00
K.ReadDir.DIR1 lda (ZPPtr2) X = EntryCount In This Block
beq .7 Free slot....goto next
2019-12-02 07:09:58 +00:00
and #$F0 get storage_type
cmp #$F0 Volume header ?
beq .1
2019-12-02 07:09:58 +00:00
cmp #$E0 directory header ?
beq .2
2019-12-02 07:09:58 +00:00
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
2018-06-21 15:12:10 +00:00
adc K.ReadDir.BufSize
sta K.ReadDir.BufSize
bcc .3
2019-12-02 07:09:58 +00:00
2018-06-21 15:12:10 +00:00
inc K.ReadDir.BufSize+1
.3 inx
bne .7
2019-12-02 07:09:58 +00:00
iny
2018-06-21 15:12:10 +00:00
bra K.ReadDir.DIR2 we reached last entry in whole DIR
2019-12-02 07:09:58 +00:00
2017-01-12 17:43:45 +00:00
.7 lda ZPPtr2
clc
2018-06-21 15:12:10 +00:00
adc K.ReadDir.EL
2017-01-12 17:43:45 +00:00
sta ZPPtr2
bcc .8
2019-12-02 07:09:58 +00:00
2017-01-12 17:43:45 +00:00
inc ZPPtr2+1
2019-12-02 07:09:58 +00:00
2018-06-21 15:12:10 +00:00
.8 dec K.ReadDir.ECIB
bne K.ReadDir.DIR1
2017-01-12 17:43:45 +00:00
* pass #2 Fill Buffer...(ZPPtr1 & Ptr2 can now be trashed)
2018-06-21 15:12:10 +00:00
K.ReadDir.DIR2 jsr K.ReadDir.GetBuf
2020-03-11 16:41:45 +00:00
bcs K.ReadDir.FreeBlk
2019-12-02 07:09:58 +00:00
2018-06-21 15:12:10 +00:00
lda K.ReadDir.EPB
sta K.ReadDir.ECIB
2019-12-02 07:09:58 +00:00
2017-01-12 17:43:45 +00:00
.1 lda (ZPPtr3)
beq .7 Empty slot, skip
and #$F0
cmp #$F0 Vol Header ?
bne .2
2019-12-02 07:09:58 +00:00
2018-06-21 15:12:10 +00:00
jsr K.ReadDir.ADD.
2020-02-16 20:45:16 +00:00
bra .4
2019-12-02 07:09:58 +00:00
.2 cmp #$E0 Dir Header ?
bne .3
2019-12-02 07:09:58 +00:00
2018-06-21 15:12:10 +00:00
jsr K.ReadDir.ADD.
2020-02-16 20:45:16 +00:00
jsr SHARED.DirEnt2Stat
jsr K.ReadDir.AddStat
2018-06-21 15:12:10 +00:00
jsr K.ReadDir.ADD..
2020-02-16 20:45:16 +00:00
bra .4
2019-12-02 07:09:58 +00:00
2018-06-21 15:12:10 +00:00
.3 jsr K.ReadDir.AddFNToBuf
2020-02-16 20:45:16 +00:00
.4 jsr SHARED.DirEnt2Stat
jsr K.ReadDir.AddStat
2020-02-16 20:45:16 +00:00
lda K.ReadDir.EC decrease global counter...
sec
sbc #1
2018-06-21 15:12:10 +00:00
sta K.ReadDir.EC
lda K.ReadDir.EC+1
sbc #0
2018-06-21 15:12:10 +00:00
sta K.ReadDir.EC+1
ora K.ReadDir.EC
beq .8 0! no more files in DIR
2019-12-02 07:09:58 +00:00
2018-06-21 15:12:10 +00:00
.7 dec K.ReadDir.ECIB 0! no more file in block
beq .8
2017-01-12 17:43:45 +00:00
lda ZPPtr3
clc
2018-06-21 15:12:10 +00:00
adc K.ReadDir.EL
2017-01-12 17:43:45 +00:00
sta ZPPtr3
bcc .1
2019-12-02 07:09:58 +00:00
2017-01-12 17:43:45 +00:00
inc ZPPtr3+1
bra .1
2019-12-02 07:09:58 +00:00
.8 ldx #3
2018-07-10 15:33:13 +00:00
ldy #S.FD.DIR.EL+3
2019-12-02 07:09:58 +00:00
2020-03-11 16:41:45 +00:00
.81 lda K.ReadDir.EL,x Store back this session parameters to S.DIR
2018-08-11 10:57:57 +00:00
sta (pFD),y
dey
dex
bpl .81
2019-12-02 07:09:58 +00:00
2020-03-11 16:41:45 +00:00
jsr K.ReadDir.FreeBlk
2019-12-02 07:09:58 +00:00
2020-03-11 16:41:45 +00:00
K.ReadDir.EXIT ldx K.ReadDir.hBuf
2017-09-29 06:36:27 +00:00
txa
2018-06-21 15:12:10 +00:00
jmp K.GetMemPtr
*--------------------------------------
2020-03-11 16:41:45 +00:00
K.ReadDir.FreeBlk
pha
lda K.ReadDir.hBlk
2018-06-22 06:24:35 +00:00
jsr K.FreeMem
pla
2020-03-11 16:41:45 +00:00
sec
rts
*--------------------------------------
2018-06-21 15:12:10 +00:00
K.ReadDir.GetBuf
>LDYA K.ReadDir.BufSize Get a BufSize bytes buffer for storing results
2020-02-16 20:45:16 +00:00
K.ReadDir.GetBufYA
2018-06-21 15:12:10 +00:00
jsr K.GetMem0 make sure 0 filled
bcs .9
2020-03-11 16:41:45 +00:00
stx K.ReadDir.hBuf
2017-01-12 17:43:45 +00:00
>STYA ZPPtr4
.9 rts
*--------------------------------------
2019-06-24 15:32:22 +00:00
K.ReadDir.ADD. ldx #1 filename="1."
.HS 2C bit abs
2018-06-21 15:12:10 +00:00
K.ReadDir.ADD..
ldx #2 filename="2.."
lda #'.'
2019-12-02 07:09:58 +00:00
2018-06-21 15:12:10 +00:00
.1 jsr K.ReadDir.AddToBuf Add X dot(s)
dex
bne .1
2019-12-02 07:09:58 +00:00
txa
2020-02-16 20:45:16 +00:00
jmp K.ReadDir.AddToBuf Add Ending 0
*--------------------------------------
2018-06-21 15:12:10 +00:00
K.ReadDir.AddFNToBuf
ldy #$1C version/min_version for lowercase bitmap
lda (ZPPtr3),y check bxxxxxxx.xxxxxxxx...
bpl .7 not set, no lowercase bitmap present
2019-12-02 16:47:53 +00:00
pha
iny
lda (ZPPtr3),y
pha
2019-12-02 16:47:53 +00:00
lda #$1
sta .2+1
2019-12-02 16:47:53 +00:00
ldy #15
2019-12-02 16:47:53 +00:00
.1 pla
.2 bit #$ff
pha
beq .3
2019-12-02 16:47:53 +00:00
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
2019-12-02 16:47:53 +00:00
rol .2+1
pla
2019-12-02 16:47:53 +00:00
.4 dey
bne .1
2019-12-02 16:47:53 +00:00
pla
.7 lda (ZPPtr3)
and #$0F get filename len
tax
ldy #1
2019-12-02 16:47:53 +00:00
.8 lda (ZPPtr3),y
2018-06-21 15:12:10 +00:00
jsr K.ReadDir.AddToBuf
iny
dex
bne .8
2019-12-02 16:47:53 +00:00
txa
2019-06-24 15:32:22 +00:00
* jsr K.ReadDir.AddToBuf
2019-06-24 15:32:22 +00:00
* rts
*--------------------------------------
2018-06-21 15:12:10 +00:00
K.ReadDir.AddToBuf
2017-01-12 17:43:45 +00:00
sta (ZPPtr4)
inc ZPPtr4
bne .8
2017-01-12 17:43:45 +00:00
inc ZPPtr4+1
.8 rts
2020-02-16 20:45:16 +00:00
*--------------------------------------
K.ReadDir.AddStat
ldy #0
.1 lda K.S.STAT,y
jsr K.ReadDir.AddToBuf
iny
cpy #S.STAT
bne .1
rts
*/-------------------------------------
2018-06-22 06:24:35 +00:00
* # CloseDir
2018-07-20 11:51:08 +00:00
* ## C
* `void closedir(hDIR);`
* ## ASM
* `lda hDIR`
* `>SYSCALL closedir`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
* none, always succeed.
*\-------------------------------------
2018-09-06 15:36:44 +00:00
*K.CloseDir .EQ K.FClose
*--------------------------------------
2016-08-24 15:42:33 +00:00
MAN
2018-11-17 17:17:13 +00:00
SAVE USR/SRC/SYS/KERNEL.S.DIRENT
LOAD USR/SRC/SYS/KERNEL.S
2016-08-24 15:42:33 +00:00
ASM