A2osX/BIN/X.FILEENUM.S.txt

568 lines
9.0 KiB
Plaintext
Raw Normal View History

NEW
2017-12-22 21:24:30 +00:00
PREFIX /A2OSX.BUILD
AUTO 4,1
.LIST OFF
*--------------------------------------
X.MAX.RECURSE .EQ 8
*--------------------------------------
* Uses: (pData)
* hDIRs .BS X.MAX.RECURSE+1
* hDIRENTs .BS X.MAX.RECURSE+1
* Index .BS 1
* hSrcBasePath .BS 1
* hDstBasePath .BS 1 (optional)
* STAT .BS S.STAT
*--------------------------------------
2018-07-18 15:30:42 +00:00
InitSrcDirYA >SYSCALL RealPath
bcc .10
rts
.10 >STYA ZPPtr1
txa
>STA.G hFullPath
ldy #1
lda (ZPPtr1),y
* beq .5 we have '/'
bne .55
jmp .5
.55 >PUSHEA.G STAT
2018-07-20 11:51:08 +00:00
>LDYA ZPPtr1
>SYSCALL Stat
bcs .1 File/DIR does not exists, go extract pattern
>LDA.G STAT+S.STAT.P.TYPE
cmp #$0f
bne .4 TYPE not a DIR, extract....
beq .5 TYPE=DIR, do not extract pattern
.1 ldy #0 TYPE is not DIR, check if wc
.11 iny
lda (ZPPtr1),y Get Src Path Len
bne .11
dey
ldx #0 Init Wildcard count
.2 lda (ZPPtr1),y search backward for a /
cmp #'/'
beq .3
cmp #'?' Test if some wildcard chars....
beq .21
cmp #'*'
bne .22
.21 inx inc wildcard count
.22 dey
bne .2
.3 txa
beq .91 no wc, file not found....
.4 ldy #0
.41 iny Search end of string.....
lda (ZPPtr1),y
bne .41
lda #'/'
.42 dey
cmp (ZPPtr1),y Search backward /
bne .42
tya
sec +1 to skip '/'
adc ZPPtr1
sta ZPPtr2
tay
lda ZPPtr1+1
adc #0
sta ZPPtr2+1
2018-07-18 15:30:42 +00:00
>SYSCALL Newstr
bcs .9
txa
>STA.G hFilter
lda #0
sta (ZPPtr2)
.5 >LDYAI 256
2018-07-18 15:30:42 +00:00
>SYSCALL GetMem Get a 256 buffer to store BasePath
bcs .9
>STYA ZPPtr2
txa
>STA.G hSrcBasePath
ldy #$ff
.6 iny
lda (ZPPtr1),y
sta (ZPPtr2),y
bne .6
>LDYA ZPPtr2
2018-07-18 15:30:42 +00:00
>SYSCALL OpenDir
bcs .9
ldy #hDIRs
sta (pData),y set hDIRs[0] = Src Hdir
ldy #index
lda #1
sta (pData),y index=hDIRs[0]
jsr .9 Cleanup
clc
rts
.91 lda #MLI.E.FNOTFND
.9 pha
>LDA.G hFullPath
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
pla
sec
InitSrcDirYA.RTS
rts
*--------------------------------------
.DO X.COPY.TO.DEST=1
2017-10-04 15:12:03 +00:00
2018-07-18 15:30:42 +00:00
InitDstDirYA >SYSCALL RealPath
bcs InitSrcDirYA.RTS
>STYA ZPPtr1
txa
>STA.G hFullPath
>PUSHEA.G STAT
2018-07-20 11:51:08 +00:00
>LDYA ZPPtr1
>SYSCALL Stat
bcs .1 File/DIR does not exists, go extract DstFileName
>LDA.G STAT+S.STAT.P.TYPE
cmp #$0f
beq .5 Dst is a directory...no destfilename
.1 ldy #0
.11 iny Search end of string.....
lda (ZPPtr1),y
bne .11
lda #'/'
.2 dey
cmp (ZPPtr1),y Search backward /
bne .2
tya
sec +1 to skip '/'
adc ZPPtr1
sta ZPPtr2
tay
lda ZPPtr1+1
adc #0
sta ZPPtr2+1
2018-07-18 15:30:42 +00:00
>SYSCALL NewStr
bcs .9
txa
>STA.G hDstFileName
lda #0
sta (ZPPtr2)
.5 >LDYAI 256
2018-07-18 15:30:42 +00:00
>SYSCALL GetMem Get a 256 buffer to store DstBasePath
bcs .9
>STYA ZPPtr2
txa
>STA.G hDstBasePath
ldy #$ff
.6 iny
lda (ZPPtr1),y
sta (ZPPtr2),y
bne .6
dey
lda #'/'
cmp (ZPPtr2),y
beq .7
iny
sta (ZPPtr2),y
iny
lda #0
sta (ZPPtr2),y
.7 jsr .9 Cleanup
clc
.99 rts
.9 pha
>LDA.G hFullPath
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
pla
sec
rts
.FIN
*--------------------------------------
GetNextEntry jsr GetEntry
bcs .9
ldy #0
.10 iny
lda (ZPFileName),y Save actual file len for setting up
bne .10
phy new offset later
lda ZPFileStat
clc
adc #S.STAT
sta ZPFileName
lda ZPFileStat+1
adc /S.STAT
sta ZPFileName+1 Make nDIRENTs[i] point to next DIRENT
lda (ZPFileName) are we at end of this buffer ?
beq .1 yes, go read next one ...
sec
adc ZPFileName
sta ZPFileStat
lda ZPFileName+1
adc #0
sta ZPFileStat+1
ldy #index
lda (pData),y
asl
clc
adc #oDIRENTs-1
tay
pla Get back previous file len
sec
adc (pData),y
sta (pData),y
iny
lda #0
adc (pData),y
sta (pData),y
dey
lda #S.STAT
clc
adc (pData),y
sta (pData),y
iny
lda /S.STAT
adc (pData),y
sta (pData),y
clc
rts
.1 pla
jsr GetEntry.ReadDir
bcs .9
lda (ZPFileName)
beq .99
ldy #0
.2 iny
lda (ZPFileName),y
bne .2
tya
sec
adc ZPFileName
sta ZPFileStat
lda ZPFileName+1
adc #0
sta ZPFileStat+1
clc
.9 rts
.99 sec
rts
*--------------------------------------
GetEntry ldy #index
lda (pData),y
clc
adc #hDIRENTs-1
tay
lda (pData),y
bne .1 we have a buffer to scan
jsr GetEntry.ReadDir First run, get first block
bcs .9 ZPFileName = start of buffer
lda (ZPFileName) Empty !!!
bne .8
* txa
2018-07-18 15:30:42 +00:00
* >SYSCALL FreeMem
sec
rts
2018-07-18 15:30:42 +00:00
.1 >SYSCALL GetMemPtr
>STYA ZPFileName
ldy #index
lda (pData),y
asl
clc
adc #oDIRENTs-1
tay
lda ZPFileName
clc
adc (pData),y
sta ZPFileName
iny
lda ZPFileName+1
adc (pData),y
sta ZPFileName+1 ZPFileName=ZPFileName+oDIRENT
.8 ldy #0
.81 iny
lda (ZPFileName),y
bne .81
tya
sec
adc ZPFileName
sta ZPFileStat
lda ZPFileName+1
adc #0
sta ZPFileStat+1
clc
.9 rts
*--------------------------------------
GetEntry.ReadDir
ldy #index
lda (pData),y
clc
adc #hDIRENTs-1
tay
lda (pData),y
beq .1
pha
lda #0
sta (pData),y reset hDIRENT
pla
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem discard previous hDIRENT
.1 ldy #index
lda (pData),y
clc
adc #hDIRs-1
tay
lda (pData),y
2018-07-20 11:51:08 +00:00
2018-07-18 15:30:42 +00:00
>SYSCALL ReadDir
bcs .9
>STYA ZPFileName
ldy #index
lda (pData),y
clc
adc #hDIRENTs-1
tay
txa get hDIRENT in A
sta (pData),y
ldy #index
lda (pData),y
asl
clc
adc #oDIRENTs-1 and reset offset for this buffer
tay
lda #0
sta (pData),y
iny
sta (pData),y
clc
.9 rts
*--------------------------------------
EnterSubDirYA >STYA ZPPtr2 save SUBDIR for StrCat
ldy #index
lda (pData),y
cmp #X.MAX.RECURSE
beq .9
ldy #hSrcBasePath
jsr EnterSubDirYA.1
>LDYA ZPPtr1
2018-07-18 15:30:42 +00:00
>SYSCALL OpenDir
bcs .9
pha
ldy #index
lda (pData),y
inc
sta (pData),y
tax
* clc from BCS
adc #hDIRs-1
tay
pla
sta (pData),y
txa make sure hDIRENTs[i] is closed
adc #hDIRENTs-1
tay
lda #0
sta (pData),y
.DO X.COPY.TO.DEST=1
ldy #hDstBasePath
jsr EnterSubDirYA.1
.FIN
clc
.9 rts
EnterSubDirYA.1 lda (pData),y
2018-07-18 15:30:42 +00:00
>SYSCALL GetMemPtr
>STYA ZPPtr1 save full path
>PUSHW ZPPtr2
2018-07-16 05:52:52 +00:00
>LDYA ZPPtr1
>SYSCALL StrCat
ldy #0
.1 iny
lda (ZPPtr1),y
bne .1
lda #'/'
sta (ZPPtr1),y
iny
lda #0
sta (ZPPtr1),y
rts
*--------------------------------------
LeaveSubDir ldy #index
lda (pData),y
beq .9
ldy #index
lda (pData),y
clc
adc #hDIRENTs-1
tay
lda (pData),y
beq .1
pha
lda #0
sta (pData),y
pla
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
.1 ldy #index
lda (pData),y
clc
adc #hDIRs-1
tay
lda (pData),y
pha
lda #0
sta (pData),y
pla
2018-07-18 15:30:42 +00:00
>SYSCALL CloseDir
ldy #index
lda (pData),y
dec
sta (pData),y
bne .8
ldy #hSrcBasePath
lda (pData),y
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
.DO X.COPY.TO.DEST=1
ldy #hDstBasePath
lda (pData),y
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
.FIN
2016-10-30 18:19:43 +00:00
.9 sec
rts
.8 clc
rts
2016-10-30 18:19:43 +00:00
*--------------------------------------
BasePath.. .DO X.COPY.TO.DEST=1
2017-10-04 15:12:03 +00:00
ldy #hDstBasePath
jsr BasePath..1
2017-10-04 15:12:03 +00:00
.FIN
ldy #hSrcBasePath
BasePath..1 lda (pData),y
2018-07-18 15:30:42 +00:00
>SYSCALL GetMemPtr
2016-10-30 18:19:43 +00:00
>STYA ZPPtr1 save full path
ldy #0
.1 iny
lda (ZPPtr1),y get len
bne .1
2017-10-04 15:12:03 +00:00
dey discard ending /
.2 dey
lda (ZPPtr1),y
cmp #'/'
bne .2
iny
lda #0
sta (ZPPtr1),y cut DIR2/ from /dir1/DIR2/
rts
*--------------------------------------
MAN
SAVE /A2OSX.SRC/BIN/X.FILEENUM.S
2018-07-20 11:51:08 +00:00
LOAD /A2OSX.SRC/BIN/LS.S
ASM