mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-26 13:49:18 +00:00
544 lines
9.1 KiB
Plaintext
544 lines
9.1 KiB
Plaintext
PR#3
|
||
PREFIX /A2OSX.BUILD
|
||
NEW
|
||
INC 1
|
||
AUTO 6
|
||
.LIST OFF
|
||
*--------------------------------------
|
||
* Uses: (pData)
|
||
* hDIRs .BS X.MAX.RECURSE+1
|
||
* hDIRENTs .BS X.MAX.RECURSE+1
|
||
* hSrcBasePath .BS 1
|
||
* hDstBasePath .BS 1 (optional)
|
||
*--------------------------------------
|
||
X.MAX.RECURSE .EQ 8
|
||
*--------------------------------------
|
||
InitSrcDirYA >SYSCALL GetFullPathYA
|
||
bcc .10
|
||
rts
|
||
|
||
.10 stx .90+1
|
||
>STYA ZPPtr1
|
||
|
||
lda (ZPPtr1)
|
||
cmp #1
|
||
beq .5 we have '/'
|
||
|
||
>PUSHW L.STAT
|
||
>PUSHW ZPPtr1
|
||
>SYSCALL Stat
|
||
ror
|
||
sta .30+1 save file exists for later.....
|
||
bmi .1 File/DIR does not exists, go extract pattern
|
||
|
||
lda STAT+S.STAT.P.TYPE
|
||
cmp #$0f
|
||
beq .5 TYPE=DIR, do not extract wildcard
|
||
|
||
.1 lda (ZPPtr1) Get Src Path Len
|
||
tay
|
||
|
||
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 tya
|
||
cmp (ZPPtr1)
|
||
beq .5 Make sure at least one char
|
||
|
||
txa
|
||
bne .31 we have wc, go extract....
|
||
|
||
.30 lda #$ff no wc, remember if file exists?
|
||
bmi .91 no, file not found....
|
||
|
||
.31 ldx #0
|
||
phy save / pos to trunk string later
|
||
|
||
.4 iny
|
||
inx
|
||
lda (ZPPtr1),y
|
||
sta UsrBuf256,x
|
||
tya
|
||
cmp (ZPPtr1)
|
||
bne .4
|
||
|
||
pla get back / pos
|
||
sta (ZPPtr1) trunk it for Opendir
|
||
stx UsrBuf256 set pattern len
|
||
|
||
>LDYAI UsrBuf256
|
||
>SYSCALL NewPstrYA
|
||
bcs .9
|
||
txa
|
||
ldy #hFilter
|
||
sta (pData),y
|
||
|
||
.5 >LDYAI 256
|
||
>SYSCALL GetMemYA Get a 256 buffer to store BasePath
|
||
bcs .9
|
||
|
||
>STYA ZPPtr2
|
||
txa
|
||
ldy #hSrcBasePath
|
||
sta (pData),y
|
||
|
||
lda (ZPPtr1)
|
||
pha
|
||
tay
|
||
|
||
.6 lda (ZPPtr1),y
|
||
sta (ZPPtr2),y
|
||
dey
|
||
bne .6
|
||
|
||
ply
|
||
lda #'/'
|
||
cmp (ZPPtr1),y
|
||
beq .7
|
||
|
||
iny
|
||
sta (ZPPtr2),y
|
||
|
||
.7 tya
|
||
sta (ZPPtr2)
|
||
|
||
>LDYA ZPPtr2
|
||
>SYSCALL OpenDirYA
|
||
|
||
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.ERR.FNOTFND
|
||
.9 pha
|
||
.90 lda #$ff self modified
|
||
>SYSCALL FreeMemA
|
||
pla
|
||
sec
|
||
InitSrcDirYA.RTS
|
||
rts
|
||
*--------------------------------------
|
||
.DO X.COPY.TO.DEST=1
|
||
InitDstDirYA >SYSCALL GetFullPathYA
|
||
bcs InitSrcDirYA.RTS
|
||
|
||
stx .90+1
|
||
>STYA ZPPtr1
|
||
|
||
>PUSHW L.STAT
|
||
>PUSHW ZPPtr1
|
||
>SYSCALL Stat
|
||
bcs .1 File/DIR does not exists, go extract DstFileName
|
||
|
||
lda STAT+S.STAT.P.TYPE
|
||
cmp #$0f
|
||
beq .5 Dst is a directory...no destfilename
|
||
|
||
.1 lda (ZPPtr1)
|
||
tay
|
||
|
||
.2 lda (ZPPtr1),y search backward for a /
|
||
cmp #'/'
|
||
beq .3
|
||
dey
|
||
bne .2
|
||
|
||
.3 tya
|
||
cmp (ZPPtr1)
|
||
beq .5 Make sure at least one char
|
||
|
||
ldx #0
|
||
phy save / pos to trunk string later
|
||
|
||
.4 iny
|
||
inx
|
||
lda (ZPPtr1),y
|
||
sta UsrBuf256,x
|
||
tya
|
||
cmp (ZPPtr1)
|
||
bne .4
|
||
|
||
pla get back / pos
|
||
sta (ZPPtr1) trunk it for Opendir
|
||
|
||
stx UsrBuf256
|
||
>LDYAI UsrBuf256
|
||
>SYSCALL NewPstrYA
|
||
bcs .9
|
||
txa
|
||
ldy #hDstFileName
|
||
sta (pData),y
|
||
|
||
.5 >LDYAI 256
|
||
>SYSCALL GetMemYA Get a 256 buffer to store DstBasePath
|
||
bcs .9
|
||
|
||
>STYA ZPPtr2
|
||
txa
|
||
ldy #hDstBasePath
|
||
sta (pData),y
|
||
|
||
lda (ZPPtr1)
|
||
sta (ZPPtr2)
|
||
tay
|
||
|
||
.6 lda (ZPPtr1),y
|
||
sta (ZPPtr2),y
|
||
dey
|
||
bne .6
|
||
|
||
lda (ZPPtr2)
|
||
tay
|
||
lda #'/'
|
||
cmp (ZPPtr2),y
|
||
beq .7
|
||
|
||
iny
|
||
sta (ZPPtr2),y
|
||
tya
|
||
sta (ZPPtr2)
|
||
|
||
.7 jsr .9 Cleanup
|
||
|
||
clc
|
||
.99 rts
|
||
|
||
.9 pha
|
||
.90 lda #$ff self modified
|
||
>SYSCALL FreeMemA
|
||
pla
|
||
sec
|
||
rts
|
||
|
||
.FIN
|
||
*--------------------------------------
|
||
GetNextEntry jsr GetEntry
|
||
bcs .9
|
||
|
||
lda (ZPFileName) Save actual file len for setting up
|
||
tax 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
|
||
|
||
txa 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 jsr GetEntry.ReadDir
|
||
bcs .9
|
||
lda (ZPFileName)
|
||
beq .99
|
||
|
||
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
|
||
* >SYSCALL FreeMemA
|
||
sec
|
||
rts
|
||
|
||
.1 >SYSCALL GetMemPtrA
|
||
>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 lda ZPFileName
|
||
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
|
||
>SYSCALL FreeMemA discard previous hDIRENT
|
||
|
||
.1 ldy #index
|
||
lda (pData),y
|
||
clc
|
||
adc #hDIRs-1
|
||
tay
|
||
lda (pData),y
|
||
|
||
>SYSCALL ReadDirA
|
||
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
|
||
>SYSCALL OpenDirYA
|
||
|
||
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
|
||
>SYSCALL GetMemPtrA
|
||
|
||
>STYA ZPPtr1 save full path
|
||
|
||
>PUSHW ZPPtr2
|
||
>PUSHW ZPPtr1
|
||
>SYSCALL PStrCat
|
||
|
||
lda (ZPPtr1)
|
||
inc
|
||
tay
|
||
sta (ZPPtr1)
|
||
lda #'/'
|
||
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
|
||
>SYSCALL FreeMemA
|
||
|
||
.1 ldy #index
|
||
lda (pData),y
|
||
clc
|
||
adc #hDIRs-1
|
||
tay
|
||
lda (pData),y
|
||
|
||
pha
|
||
lda #0
|
||
sta (pData),y
|
||
pla
|
||
>SYSCALL CloseDirA
|
||
|
||
ldy #index
|
||
lda (pData),y
|
||
dec
|
||
sta (pData),y
|
||
bne .8
|
||
|
||
ldy #hSrcBasePath
|
||
lda (pData),y
|
||
>SYSCALL FreeMemA
|
||
|
||
.DO X.COPY.TO.DEST=1
|
||
ldy #hDstBasePath
|
||
lda (pData),y
|
||
>SYSCALL FreeMemA
|
||
.FIN
|
||
|
||
.9 sec
|
||
rts
|
||
|
||
.8 clc
|
||
rts
|
||
*--------------------------------------
|
||
BasePath.. .DO X.COPY.TO.DEST=1
|
||
ldy #hDstBasePath
|
||
jsr BasePath..1
|
||
.FIN
|
||
|
||
ldy #hSrcBasePath
|
||
|
||
BasePath..1 lda (pData),y
|
||
>SYSCALL GetMemPtrA
|
||
|
||
>STYA ZPPtr1 save full path
|
||
|
||
lda (ZPPtr1) get len
|
||
tay
|
||
|
||
.1 dey At first run, discard ending /
|
||
lda (ZPPtr1),y
|
||
cmp #'/'
|
||
bne .1
|
||
|
||
tya
|
||
sta (ZPPtr1) cut DIR2/ from /dir1/DIR2/
|
||
|
||
rts
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE /A2OSX.SRC/BIN/X.FILEENUM.S
|