LS / FILEENUM : 2 passes enabled & code cleanup......and i also SAVE BYTES....pffff!

This commit is contained in:
Rémy GIBERT 2021-06-10 16:00:05 +02:00
parent 1304a9a076
commit b044632bcd
2 changed files with 243 additions and 154 deletions

View File

@ -25,13 +25,23 @@ ZPPtr2 .BS 2
ZPFileName .BS 2
ZPFileStat .BS 2
ZPPW .BS 2
bCRLF .BS 1
hLineBuf .BS 1
ZPLineBuf .BS 2
ZS.END
.ED
ZPPWBuf .BS 2
ArgCount .BS 1
ColCount .BS 1
bPass2 .BS 1
bPause .BS 1
bAllmostAll .BS 1
bColumn .BS 1
bFullPath .BS 1
bLong .BS 1
bRecurse .BS 1
ZS.END .ED
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
@ -51,7 +61,7 @@ CS.START cld
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.DOEVENT
.DA CS.QUIT
L.MSG.REG .DA MSG.REG
L.MSG.REGEXT .DA MSG.REGEXT
@ -78,8 +88,9 @@ J.CS.RUN.PRINT .DA CS.RUN.PRINT.REG
CS.INIT clc
rts
*--------------------------------------
CS.RUN
.1 >INC.G ArgCount
CS.RUN
.1 inc ArgCount
lda ArgCount
>SYSCALL ArgV
bcs .6
@ -90,26 +101,28 @@ CS.RUN
ldy #1
lda (ZPPtr1),y
ldx #OptionVars-OptionList-1
.2 cmp OptionList,x
beq .3
dex
bpl .2
lda #E.SYN
sec
rts
.3 ldy OptionVars,x
lda #$80
sta (pData),y
sta $0,y
bra .1
.4 >LDYA ZPPtr1
jsr InitSrcDirYA
bcc .1 scan for any other args
.9 rts
.6 >LDA.G index do we have a Source dir ?
@ -120,39 +133,30 @@ CS.RUN
>SYSCALL GetMemPtr
jsr InitSrcDirYA
bcs .9
.8 >PUSHEA.G TIME.SysTime
>SYSCALL Time
>LDYAI S.PW
>SYSCALL GetMem
bcs .9
>STYA ZPPW
>STYA ZPPWBuf
txa
>STA.G hPW
>STA.G hPWBuf
>LDYAI 256
>SYSCALL GetMem
bcs .9
>STYA ZPLineBuf
stx hLineBuf
* ldy #S.PS.hStdOut
* lda (pPS),y
* tax
* lda OF.Table.hFD-1,x
* >SYSCALL GetMemPtr
* >STYA ZPPtr1
txa
* lda (ZPPtr1) S.FD.T
* beq CS.RUN.LOOP S.FD.T.REG
* cmp #S.FD.T.PIPE
* beq CS.RUN.LOOP
dec bCRLF
>STA.G hLineBuf
*--------------------------------------
CS.RUN.LOOP ldy #S.PS.hStdIn
CS.RUN.LOOP stz bPass2
.1 ldy #S.PS.hStdIn
lda (pPS),y
>SYSCALL FEOF
bcs .99 I/O error
@ -162,20 +166,18 @@ CS.RUN.LOOP ldy #S.PS.hStdIn
>SYSCALL GetChar
cmp #$03 Ctrl-C
bne .1 Abort....
beq .99 Abort....
rts CS
.1 cmp #$13 Ctrl-S
cmp #$13 Ctrl-S
bne .2
>LDA.G bPause
lda bPause
eor #$ff
sta (pData),y
bne CS.RUN.LOOP
sta bPause
bne .1
.2 >LDA.G bPause
bne CS.RUN.LOOP
.2 bit bPause
bmi .1
jsr GetEntry
bcs .9
@ -183,7 +185,7 @@ CS.RUN.LOOP ldy #S.PS.hStdIn
jsr FilterMatch
bcs .8 no match, skip....
>LDA.G bAllmostAll
bit bAllmostAll
bmi .4
lda (ZPFileName)
@ -202,11 +204,18 @@ CS.RUN.LOOP ldy #S.PS.hStdIn
bcs .99
.8 jsr GetNextEntry
bcc .1
bcc .92
bit bPass2
bmi .9
.9 ldy #bLong
lda (pData),y
jsr ResetSrcDir
bcs .99
dec bPass2
bra .1
.9 bit bLong
bmi .91
jsr CS.RUN.NewLine
@ -216,8 +225,13 @@ CS.RUN.LOOP ldy #S.PS.hStdIn
bcs .98
jsr BasePath..
jsr CS.RUN.ENTER.MSG
bcs .99
jsr GetNextEntry
.92 jmp CS.RUN.LOOP
jmp CS.RUN.LOOP
.98 lda #0
sec
.99 rts
@ -226,18 +240,20 @@ CS.RUN.PRINT.JMP
jmp (J.CS.RUN.PRINT,x)
*--------------------------------------
CS.RUN.PRINT.REG
ldy #bLong
lda (pData),y
bmi .1
bit bPass2
bpl .8
>LDA.G bColumn
bit bLong
bmi .1
bit bColumn
bmi .23
>LDA.G bFullPath
bit bFullPath
bpl .22
jsr CS.RUN.PRINT.SRCPATH
.23 >LDYA ZPFileName
>SYSCALL PutS
rts
@ -247,12 +263,14 @@ CS.RUN.PRINT.REG
>PUSHBI 2
>SYSCALL PrintF
bcs .9
jmp CS.RUN.UpdateColCnt
jmp CS.RUN.UpdateColCnt
.8 clc
.9 rts
*--------------------------------------
.1
* >PUSHW ZPLineBuf
>PUSHW L.MSG.REGEXT
.1 >PUSHW L.MSG.REGEXT
jsr Mod2CSTR (2)
jsr CS.RUN.PushUidGid (4)
@ -285,18 +303,20 @@ CS.RUN.PRINT.REG
>PUSHBI 20
>SYSCALL PrintF
bcs .9
jmp CS.RUN.NewLine.1
.9 rts
*--------------------------------------
CS.RUN.PRINT.DIR
>LDA.G bLong
bit bPass2
bmi .8
bit bLong
bmi .4
>LDA.G bColumn
bit bColumn
bmi .23
>LDA.G bFullPath
bit bFullPath
bpl .22
jsr CS.RUN.PRINT.SRCPATH
@ -304,13 +324,17 @@ CS.RUN.PRINT.DIR
.23 >LDYA ZPFileName
>SYSCALL PutS
bcs .9
>LDA.G bRecurse
bit bRecurse
bpl .8
lda (ZPFileName)
cmp #'.'
beq .8
>LDYA ZPFileName
jmp EnterSubDirYA
jmp EnterSubDirYA
.8 clc
.9 rts
@ -342,29 +366,33 @@ CS.RUN.PRINT.DIR
rts
*--------------------------------------
.4 >PUSHW L.MSG.DIREXT
jsr Mod2CSTR
jsr CS.RUN.PushUidGid
jsr CS.RUN.PUSHDATES
>PUSHW ZPFileName
>PUSHBI 12
>SYSCALL PrintF
bcs .90
jsr CS.RUN.NewLine.1
bcs .90
.5 >LDA.G bRecurse
.5 bit bRecurse
bpl .80
lda (ZPFileName)
cmp #'.'
beq .80
jsr CS.RUN.NewLine
bcs .90
>LDYA ZPFileName
jsr EnterSubDirYA
bcs .90
jmp CS.RUN.ENTER.MSG
.80 clc
@ -375,12 +403,13 @@ CS.RUN.PRINT.CDEV
rts
*--------------------------------------
CS.RUN.PRINT.BDEV
>LDA.G bLong
bit bLong
bmi .20
>LDA.G bColumn
bit bColumn
bmi .23
>LDA.G bFullPath
bit bFullPath
bpl .22
jsr CS.RUN.PRINT.SRCPATH
@ -388,16 +417,19 @@ CS.RUN.PRINT.BDEV
.23 >LDYA ZPFileName
>SYSCALL PutS
bcs .9
>LDA.G bRecurse
bit bRecurse
bpl .8
lda (ZPFileName)
cmp #'.'
beq .8
>LDYA ZPFileName
jmp EnterSubDirYA
.8 clc
.9 rts
.9 rts
.22 >PUSHW L.MSG.BDEV
>PUSHW ZPFileName
@ -420,6 +452,7 @@ CS.RUN.PRINT.BDEV
>SYSCALL PutChar
ply
bcc .11
rts
.2 jsr CS.RUN.UpdateColCnt
@ -428,7 +461,7 @@ CS.RUN.PRINT.BDEV
*--------------------------------------
.20 >PUSHW L.MSG.BDEVEXT
>PUSHW ZPFileName
ldy #S.STAT.P.SLOT
>PUSHB (ZPFileStat),y
iny DRIVE
@ -443,22 +476,24 @@ CS.RUN.PRINT.BDEV
>PUSHB (ZPFileStat),y
dey
>PUSHB (ZPFileStat),y
>PUSHBI 8
>SYSCALL PrintF
bcs .90
jsr CS.RUN.NewLine.1
bcs .90
ldy #bRecurse
lda (pData),y
bit bRecurse
bpl .80
>LDYA ZPFileName
jsr EnterSubDirYA
bcs .90
jmp CS.RUN.ENTER.MSG
.80 clc
.90 rts
*--------------------------------------
@ -475,17 +510,17 @@ CS.RUN.PushUidGid
ldy #S.STAT.UID
lda (ZPFileStat),y
>PUSHA
>PUSHW ZPPW
>PUSHW ZPPWBuf
>SYSCALL GetPWUID
bcs .2
>PUSHEA.G USER
jsr CS.RUN.PushUidGidStr
bra .3
.2 >PUSHEA.G USER
>PUSHW L.FMT.int16
ldy #S.STAT.UID+1
lda (ZPFileStat),y
>PUSHA
@ -498,18 +533,18 @@ CS.RUN.PushUidGid
.3 ldy #S.STAT.GID
lda (ZPFileStat),y
>PUSHA
>PUSHW ZPPW
>PUSHW ZPPWBuf
>SYSCALL GetGRGID
bcs .5
>PUSHEA.G GROUP
jsr CS.RUN.PushUidGidStr
bra .8
.5 >PUSHEA.G GROUP
>PUSHW L.FMT.int16
ldy #S.STAT.GID+1
lda (ZPFileStat),y
>PUSHA
@ -518,15 +553,15 @@ CS.RUN.PushUidGid
>PUSHA
>PUSHBI 2
>SYSCALL SPrintF
.8 >PUSHEA.G USER
>PUSHEA.G GROUP
clc
rts
CS.RUN.PushUidGidStr
>PUSHW L.FMT.string6
>PUSHW ZPPW
>PUSHW ZPPWBuf
>PUSHBI 2
>SYSCALL SPrintF
rts
@ -534,16 +569,16 @@ CS.RUN.PushUidGidStr
CS.RUN.PUSHDATES
ldy #TIME.Mod-1 Set NODATE as default
jsr CS.RUN.NODATES.INIT
ldy #TIME.Create-1 Set NODATE as default
jsr CS.RUN.NODATES.INIT
ldy #S.STAT.MTIME+S.TIME.MONTH
lda (ZPFileStat),y
beq .1 Month=0.....invalid date/time
>PUSHEA.G TIME.Mod
lda ZPFileStat
clc
adc #S.STAT.MTIME
@ -558,7 +593,7 @@ CS.RUN.PUSHDATES
beq .2 Month=0.....invalid date/time
>PUSHEA.G TIME.Create
lda ZPFileStat
clc
adc #S.STAT.CTIME
@ -580,7 +615,7 @@ CS.RUN.NODATES.INIT
lda MSG.NODATE,x
sta (pData),y
bne .1
rts
*--------------------------------------
CS.RUN.DATEFMT.SELECT
@ -609,20 +644,21 @@ CS.RUN.DATEFMT.SELECT
ldy #TIME.SysTime+S.TIME.DAY
cmp (pData),y
bne .9
.8 >PUSHW L.FMT.Time
>PUSHW ZPPtr1
rts
.9 >PUSHW L.FMT.Date
>PUSHW ZPPtr1
rts
*--------------------------------------
CS.RUN.UpdateColCnt
>INC.G ColCount
inc ColCount
lda ColCount
cmp #MAX.COL
bne CS.RUN.NewLine.8
lda #0
sta (pData),y
bra CS.RUN.NewLine.1
@ -634,20 +670,17 @@ CS.RUN.ENTER.MSG
>SYSCALL GetMemPtr
>PUSHYA
>PUSHBI 2
>SYSCALL PrintF
bcc CS.RUN.NewLine.1
rts
*--------------------------------------
CS.RUN.NewLine >LDA.G ColCount
CS.RUN.NewLine lda ColCount
beq CS.RUN.NewLine.8
CS.RUN.NewLine.1
lda #C.CR
>SYSCALL PutChar
* bit bCRLF
* bpl CS.RUN.NewLine.8
lda #C.LF
>SYSCALL PutChar
@ -660,54 +693,63 @@ CS.DOEVENT sec
*--------------------------------------
CS.QUIT jsr LeaveSubDir
bcc CS.QUIT
>LDA.G hFilter
beq .3
>SYSCALL FreeMem
ldy #hFilter
jsr .7
.3 >LDA.G hPW
beq .4
>SYSCALL FreeMem
.4 lda hLineBuf
ldy #hPWBuf
jsr .7
ldy #hLineBuf
.7 lda (pData),y
beq .8
>SYSCALL FreeMem
.8 clc
rts
*--------------------------------------
FileType2PSTR ldy #0
.1 cmp PRODOS.FT.HEX,y
beq .8
iny
cpy #PRODOS.FT.TXT-PRODOS.FT.HEX
bne .1
pha
lsr
lsr
lsr
lsr
ora #$30
cmp #$3A
cmp #'9'+1
bcc .2
adc #6
.2 sta PRODOS.FT.DFLT+2
.2 sta PRODOS.FT.DFLT+1
pla
and #$0F
ora #$30
cmp #$3A
cmp #'9'+1
bcc .3
adc #6
.3 sta PRODOS.FT.DFLT+3
.3 sta PRODOS.FT.DFLT+2
.8 tya
asl
asl CC
adc L.PRODOS.FT.TXT
tay
lda L.PRODOS.FT.TXT+1
adc #0
rts
*--------------------------------------
Mod2CSTR ldy #S.STAT.MODE+1
@ -733,15 +775,15 @@ Mod2CSTR ldy #S.STAT.MODE+1
.1 pha
lda #'-'
bcc .2
lda ACCESS,x
.2 sta (pData),y
iny
pla
asl
dex
bpl .1
@ -755,7 +797,7 @@ CS.END
OptionList .AS "ACFLRacflr"
OptionVars .DA #bAllmostAll,#bColumn,#bFullPath,#bLong,#bRecurse,#bAllmostAll,#bColumn,#bFullPath,#bLong,#bRecurse
*--------------------------------------
MSG.REGEXT .AZ "%s %6s %6s %10u %s %s %S %H %s"
MSG.REGEXT .AZ "%s %6s %6s %10u %s %s %s %H %s"
MSG.REG .AZ "%19s"
MSG.DIREXT .AZ "%s %6s %6s %s %s <dir> %s"
MSG.DIR .AZ "\e[32m%s/\e[0m"
@ -764,17 +806,17 @@ MSG.BDEV .AZ "\e[32m%s/\e[0m"
MSG.ENTER .AZ "Directory:%s"
*--------------------------------------
PRODOS.FT.HEX .HS 0406FAFCFDE2CBCCCFFF
PRODOS.FT.TXT >PSTR "txt"
>PSTR "bin"
>PSTR "asm"
>PSTR "bas"
>PSTR "var"
>PSTR "atk"
>PSTR "pix"
>PSTR "fon"
>PSTR "pak"
>PSTR "sys"
PRODOS.FT.DFLT >PSTR "$ "
PRODOS.FT.TXT .AZ "txt"
.AZ "bin"
.AZ "asm"
.AZ "bas"
.AZ "var"
.AZ "atk"
.AZ "pix"
.AZ "fon"
.AZ "pak"
.AZ "sys"
PRODOS.FT.DFLT .AZ "$ "
MSG.NODATE .AZ "<no-date>"
FMT.Date .AZ "%d-%b-%y"
FMT.Time .AZ "%H:%M:%S "
@ -786,8 +828,6 @@ ACCESS .AS "xwrxwrxwr"
.DUMMY
.OR 0
DS.START
ArgCount .BS 1
MOD .BS 11 drwxrwxrwx0
USER .BS 7
GROUP .BS 7
@ -796,15 +836,8 @@ TIME.Create .BS 20
TIME.Mod .BS 20
TIME.SysTime .BS S.TIME
bPause .BS 1
bAllmostAll .BS 1
bColumn .BS 1
bFullPath .BS 1
bLong .BS 1
bRecurse .BS 1
ColCount .BS 1
hPW .BS 1
hLineBuf .BS 1
hPWBuf .BS 1
.INB usr/src/shared/x.fileenum.g
DS.END .ED

View File

@ -84,6 +84,7 @@ ExcludeMatch sec
cmp #'*' another '*' ?
beq .5 yes, '**' = '*', go next char
cmp #'?' '*?' ? we must match a least one char
beq .3
@ -111,6 +112,7 @@ FilterMatch.CmpPtr2CharPtr1Y
lda (ZPFileName),y
cmp #'a'
bcc .1
cmp #'z'+1
bcs .1
@ -126,7 +128,9 @@ FilterMatch.CmpPtr2CharPtr1Y
FilterMatch.NextPtr2
inc ZPPtr2 Make PTR2 advance to next char
bne .1
inc ZPPtr2+1
.1 lda (ZPPtr2)
rts
*--------------------------------------
@ -153,6 +157,7 @@ InitSrcDirYA >PUSHYA
and #$F0
cmp /S.STAT.MODE.DIR
bne .4 TYPE not a DIR, extract....
bra .5 TYPE=DIR, do not extract pattern
.ELSE
bra .4
@ -257,6 +262,28 @@ InitSrcDirYA >PUSHYA
sec
InitSrcDirYA.RTS
rts
*--------------------------------------
ResetSrcDir jsr GethDIR
>SYSCALL CloseDir
>LDA.G hSrcBasePath
>SYSCALL GetMemPtr
>SYSCALL OpenDir
bcs .9
pha
>LDA.G index
clc
adc #hDIRs-1
tay
pla
sta (pData),y
* clc
.9 rts
*--------------------------------------
.DO X.COPY.TO.DEST=1
InitDstDirYA >PUSHYA
@ -296,6 +323,7 @@ InitDstDirYA >PUSHYA
>SYSCALL StrDup
bcs .9
txa
>STA.G hDstFileName
@ -339,6 +367,7 @@ InitDstDirYA >PUSHYA
*--------------------------------------
GetNextEntry jsr GetEntry
bcs .9
jsr GetFilenameLen Save actual file len for setting up
pha new offset later
lda ZPFileStat
@ -351,6 +380,7 @@ GetNextEntry jsr GetEntry
jsr GetFilenameLen are we at end of this buffer ?
beq .1 yes, go read next one ...
jsr SetFileStatPtr
jsr GetoDIRENT
@ -376,21 +406,25 @@ GetNextEntry jsr GetEntry
sta (pData),y
clc
rts
.1 pla
jsr GetEntry.ReadDir
bcs .9
jsr GetFilenameLen
beq GetNextEntry.99
beq .99
jsr SetFileStatPtr
clc
.9 rts
GetNextEntry.99 sec
.99 sec
rts
*--------------------------------------
GetEntry jsr GethDIRENT
bne .1 we have a buffer to scan
jsr GetEntry.ReadDir First run, get first block
bcs .9 ZPFileName = start of buffer
@ -403,15 +437,20 @@ GetEntry jsr GethDIRENT
.1 >SYSCALL GetMemPtr
>STYA ZPFileName
jsr GetoDIRENT
lda ZPFileName
clc
adc (pData),y
sta ZPFileName
iny
lda ZPFileName+1
adc (pData),y
sta ZPFileName+1 ZPFileName=ZPFileName+oDIRENT
.8 jsr GetFilenameLen
jsr SetFileStatPtr
clc
@ -439,7 +478,9 @@ GetEntry.ReadDir
tay
txa get hDIRENT in A
sta (pData),y
jsr GetoDIRENT
lda #0 and reset offset for this buffer
sta (pData),y
iny
@ -457,8 +498,8 @@ EnterSubDirYA >STYA ZPPtr2 save SUBDIR for StrCat
jsr EnterSubDirY
>LDYA ZPPtr1
>SYSCALL OpenDir
bcs .9
pha
>INC.G index
tax
@ -472,10 +513,12 @@ EnterSubDirYA >STYA ZPPtr2 save SUBDIR for StrCat
tay
lda #0
sta (pData),y
.DO X.COPY.TO.DEST=1
ldy #hDstBasePath
jsr EnterSubDirY
.FIN
clc
.9 rts
@ -495,17 +538,21 @@ EnterSubDirY lda (pData),y
lda #'/'
cmp (ZPPtr1),y
beq .8
iny
sta (ZPPtr1),y
iny
lda #0
sta (ZPPtr1),y
.8 rts
*--------------------------------------
LeaveSubDir >LDA.G index
beq .9
jsr GethDIRENT.A
beq .1
pha
lda #0
sta (pData),y
@ -513,6 +560,7 @@ LeaveSubDir >LDA.G index
>SYSCALL FreeMem
.1 jsr GethDIR
pha
lda #0
sta (pData),y
@ -521,6 +569,7 @@ LeaveSubDir >LDA.G index
>DEC.G index
bne .8
ldy #hSrcBasePath
lda (pData),y
>SYSCALL FreeMem
@ -530,8 +579,10 @@ LeaveSubDir >LDA.G index
lda (pData),y
>SYSCALL FreeMem
.FIN
.9 sec
rts
.8 clc
rts
*--------------------------------------
@ -564,8 +615,10 @@ BasePath..1 lda (pData),y
GetPtr1Len ldy #$ff
.1 iny
lda (ZPPtr1),y get len
bne .1
rts
*--------------------------------------
StrcpyPtr1ptr2 ldy #$ff
@ -574,6 +627,7 @@ StrcpyPtr1ptr2 ldy #$ff
lda (ZPPtr1),y
sta (ZPPtr2),y
bne .1
rts
*--------------------------------------
GetFilenameLen ldy #$ff
@ -581,6 +635,7 @@ GetFilenameLen ldy #$ff
.1 iny
lda (ZPFileName),y
bne .1
tya
rts
*--------------------------------------
@ -602,6 +657,7 @@ GethDIR ldy #index
*--------------------------------------
GethDIRENT ldy #index
lda (pData),y
GethDIRENT.A clc
adc #hDIRENTs-1
tay