A2osX/BIN/X.FILEENUM.S.txt

392 lines
6.5 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
*--------------------------------------
* Uses: (pData)
* hDIRs .BS X.MAX.RECURSE+1
* hDIRENTs .BS X.MAX.RECURSE+1
* hSrcBasePath .BS 1
* hDstBasePath .BS 1 (optional)
*--------------------------------------
.DO X.DST.BASE.PATH=1
InitDstDirYA >SYSCALL GetFullPathYA
bcs .99
stx .90+1
>STYA ZPPtr1
.5 >PUSHWI 256
>PUSHBI 0
>SYSCALL GetMem 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
*--------------------------------------
InitSrcDirPatYA ldx #$80
.HS 2C bit abs
InitSrcDirYA ldx #0
stx .11+1
>SYSCALL GetFullPathYA
bcc .10
rts
.10 stx .90+1
>STYA ZPPtr1
lda (ZPPtr1)
cmp #1
beq .5 we have '/'
.11 lda #$ff Self Modified
bmi .1 Force using pattern
>PUSHW L.STAT
>PUSHW ZPPtr1
>SYSCALL STAT
bcs .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)
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 #hFilter
sta (pData),y
.5 >PUSHWI 256
>PUSHBI 0
>SYSCALL GetMem Get a 256 buffer to store BasePath
bcs .9
>STYA ZPPtr2
txa
ldy #hSrcBasePath
sta (pData),y
lda (ZPPtr1)
sta (ZPPtr2)
tay
.6 lda (ZPPtr1),y
sta (ZPPtr2),y
dey
bne .6
>LDYA ZPPtr1
>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
.9 pha
.90 lda #$ff self modified
>SYSCALL FreeMemA
pla
sec
InitSrcDirYA.RTS
rts
*--------------------------------------
GetNextEntry ldy #index
lda (pData),y
tax keep index for later
clc
adc #hDIRENTs-1
tay
lda (pData),y
bne .1 we have a buffer to scan
txa get back index....
clc
adc #hDIRs-1
tay
lda (pData),y
>SYSCALL ReadDirA
bcs InitSrcDirYA.RTS
>STYA ZPPtr1
ldy #index
lda (pData),y
pha save index for later
clc
adc #hDIRENTs-1
tay
txa get hDIRENT in A
sta (pData),y
pla get back index
asl
adc #oDIRENTs-1 and reset offset for this buffer
tay
lda #0
sta (pData),y
iny
sta (pData),y
bra .2
.1 >SYSCALL GetMemPtrA
>STYA ZPPtr1
ldy #index
lda (pData),y
asl
adc #oDIRENTs-1 CC from ASL
tay
lda ZPPtr1
* clc from ADC
adc (pData),y
sta ZPPtr1
lda ZPPtr1+1
iny
adc (pData),y
sta ZPPtr1+1
.2 lda (ZPPtr1) first/next DIRENT
bne .8
sta (pData),y reset offset...
dey
sta (pData),y
ldy #index
lda (pData),y
clc
adc #hDIRENTs-1
tay
lda (pData),y
pha
lda #0
sta (pData),y reset hDIRENT
pla
>SYSCALL FreeMemA discard hDIRENT
bra GetNextEntry ...startover
.8 ldy #index
lda (pData),y
asl
adc #oDIRENTs-1
tay
lda (ZPPtr1) Add file len+1...
sec
adc #S.STAT +S.STAT
* clc from ADC
adc (pData),y Make oDIRENTs[i] point to next DIRENT
sta (pData),y
iny
lda (pData),y
adc #0
sta (pData),y
lda ZPPtr1 set Ptr2=Ptr1+LEN-> S.STAT
sec
adc (ZPPtr1)
sta ZPPtr2
lda ZPPtr1+1
adc #0
sta ZPPtr2+1
clc
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.DST.BASE.PATH=1
ldy #hDstBasePath
jsr EnterSubDirYA.1
.FIN
.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
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
.9 sec
rts
.8 clc
rts
*--------------------------------------
BasePath.. .DO X.DST.BASE.PATH=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 BIN/X.FILEENUM.S