A2osX/BIN/DU.S.txt

475 lines
11 KiB
Plaintext
Raw Normal View History

2021-06-11 17:25:09 +00:00
NEW
AUTO 3,1
2022-11-02 06:54:30 +00:00
.LIST OFF
.OP 65C02
.OR $2000
.TF bin/du
2021-06-11 17:25:09 +00:00
*--------------------------------------
2022-11-02 06:54:30 +00:00
.INB inc/macros.i
.INB inc/a2osx.i
.INB inc/kernel.i
.INB inc/mli.i
.INB inc/mli.e.i
2021-06-11 17:25:09 +00:00
*--------------------------------------
2022-11-02 06:54:30 +00:00
X.ENTER.SUBDIR .EQ 1
X.COPY.TO.DEST .EQ 0
X.DELETE.SOURCE .EQ 0
2021-06-11 17:25:09 +00:00
*--------------------------------------
.DUMMY
.OR ZPBIN
2021-06-11 17:25:09 +00:00
ZS.START
ZPPtr1 .BS 2
ZPPtr2 .BS 2
ZPFileName .BS 2
ZPFileStat .BS 2
bPass2 .BS 1
bDirLevel .BS 1
bCRLF .BS 1
bPause .BS 1
bSummary .BS 1
bAllFiles .BS 1
ArgCount .BS 1
ArgDir .BS 1
2021-06-11 17:25:09 +00:00
ZS.END
2022-11-02 06:54:30 +00:00
.ED
2021-06-11 17:25:09 +00:00
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
2022-11-02 06:54:30 +00:00
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA #0 S.PS.F.EVENT
2022-11-02 06:54:30 +00:00
.DA #0
.DA CS.END-CS.START Code Size (without Constants)
.DA DS.END-DS.START Data SegmentSize
.DA #64 Stack Size
.DA #ZS.END-ZS.START Zero Page Size
2022-11-02 06:54:30 +00:00
.DA 0
2021-06-11 17:25:09 +00:00
*--------------------------------------
* Relocation Table
*--------------------------------------
2022-11-02 06:54:30 +00:00
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.MSG.USAGE .DA MSG.USAGE
L.MSG.REG1 .DA MSG.REG1
L.MSG.REG2 .DA MSG.REG2
L.MSG.DIRSUMM .DA MSG.DIRSUMM
L.MSG.BDEV .DA MSG.BDEV
L.MSG.BDEVEXT .DA MSG.BDEVEXT
L.MSG.CWD .DA MSG.CWD
J.CS.RUN.PRINT .DA CS.RUN.PRINT.REG
.DA CS.RUN.PRINT.DIR
.DA CS.RUN.PRINT.CDEV
.DA CS.RUN.PRINT.BDEV
.DA CS.RUN.PRINT.CDEV
.DA CS.RUN.PRINT.CDEV
.DA CS.RUN.PRINT.CDEV
.DA CS.RUN.PRINT.CDEV
.DA 0
2021-06-11 17:25:09 +00:00
*--------------------------------------
2022-11-02 06:54:30 +00:00
CS.INIT clc
rts
2021-06-11 17:25:09 +00:00
*--------------------------------------
CS.RUN jsr CS.RUN.SetCRLF
2022-11-02 06:54:30 +00:00
.1 inc ArgCount
lda ArgCount
2022-11-02 06:54:30 +00:00
>SYSCALL ArgV
bcs .6
>STYA ZPPtr1
2022-11-02 06:54:30 +00:00
lda (ZPPtr1)
cmp #'-'
bne .4
ldy #1
2022-11-02 06:54:30 +00:00
lda (ZPPtr1),y
beq .9
2022-11-02 06:54:30 +00:00
ldy #OptionVars-OptionList-1
2022-11-02 06:54:30 +00:00
.2 cmp OptionList,y
2022-11-02 06:54:30 +00:00
beq .3
dey
2022-11-02 06:54:30 +00:00
bpl .2
.9 >LDYA L.MSG.USAGE
>SYSCALL PutS
lda #E.SYN
sec
.99 rts
.3 ldx OptionVars,y
2022-11-02 06:54:30 +00:00
sec
ror $0,x
2022-11-02 06:54:30 +00:00
bra .1
.4 lda ArgDir
bne .9
lda ArgCount
sta ArgDir
>LDYA ZPPtr1
2022-11-02 06:54:30 +00:00
jsr InitSrcDirYA
bcc .1 scan for any other args
rts
*--------------------------------------
.6 lda ArgDir do we have a Source dir ?
2022-11-02 06:54:30 +00:00
bne .8
2022-11-02 06:54:30 +00:00
ldy #S.PS.hCWD
lda (pPS),y
>SYSCALL GetMemPtr
jsr InitSrcDirYA
bcs .99
2022-11-02 06:54:30 +00:00
.8 >PUSHEA.G TIME.SysTime
>SYSCALL Time
2021-06-11 17:25:09 +00:00
*--------------------------------------
2022-11-02 06:54:30 +00:00
CS.RUN.LOOP stz bPass2
2021-06-11 17:25:09 +00:00
2022-11-02 06:54:30 +00:00
.1 ldy #S.PS.hStdIn
lda (pPS),y
>SYSCALL FEOF
bcc .2
rts I/O error
2021-06-11 17:25:09 +00:00
2022-11-02 06:54:30 +00:00
.2 tay
bne .3 no char
2021-06-11 17:25:09 +00:00
2022-11-02 06:54:30 +00:00
>SYSCALL GetChar
cmp #$03 Ctrl-C
beq .99 Abort....
2021-06-11 17:25:09 +00:00
2022-11-02 06:54:30 +00:00
cmp #$13 Ctrl-S
bne .3
2021-06-11 17:25:09 +00:00
lda bPause
2022-11-02 06:54:30 +00:00
eor #$ff
sta bPause
2022-11-02 06:54:30 +00:00
bne .1
2021-06-11 17:25:09 +00:00
.3 bit bPause
bmi .1
2021-06-11 17:25:09 +00:00
2022-11-02 06:54:30 +00:00
jsr GetEntry First entry
bcs .9
2021-06-11 17:25:09 +00:00
2022-11-02 06:54:30 +00:00
jsr FilterMatch Filter filename
bcs .8 no match, skip....
2021-06-11 17:25:09 +00:00
2022-11-02 06:54:30 +00:00
lda (ZPFileName)
cmp #'.'
beq .8
2021-06-11 17:25:09 +00:00
2022-11-02 06:54:30 +00:00
.4 ldy #S.STAT.MODE+1
lda (ZPFileStat),y
2021-06-11 17:25:09 +00:00
2022-11-02 06:54:30 +00:00
and #$70
lsr
lsr
lsr
tax
jsr CS.RUN.PRINT.JMP
bcs .99
2021-06-11 17:25:09 +00:00
2022-11-02 06:54:30 +00:00
.8 jsr GetNextEntry Next entry
bcc .1 If there is one, go again
2021-06-11 17:25:09 +00:00
2022-11-02 06:54:30 +00:00
bit bPass2
bmi .9
2021-06-11 17:25:09 +00:00
2022-11-02 06:54:30 +00:00
jsr ResetSrcDir
bcs .99
2021-06-11 17:25:09 +00:00
2022-11-02 06:54:30 +00:00
dec bPass2
bra .1
2021-06-11 17:25:09 +00:00
.9 bit bSummary
bmi .91
2021-06-11 17:25:09 +00:00
2022-11-02 06:54:30 +00:00
jsr CS.RUN.PrintDirSumm
jsr CS.RUN.PrintCwd
jsr CS.RUN.NewLine
2021-06-11 17:25:09 +00:00
2022-11-02 06:54:30 +00:00
.91 dec bDirLevel
jsr LeaveSubDir "cd .."
bcs .97 This means we are done
2021-06-11 17:25:09 +00:00
2022-11-02 06:54:30 +00:00
jsr BasePath.. Prune pathname
2021-06-11 17:25:09 +00:00
2022-11-02 06:54:30 +00:00
jsr GetNextEntry Get next entry
jmp CS.RUN.LOOP Go again
2021-06-11 17:25:09 +00:00
.97 bit bSummary
bpl .98
2022-11-02 06:54:30 +00:00
inc bDirLevel
jsr CS.RUN.PrintDirSumm
jsr CS.RUN.PrintBaseDir
2022-11-02 06:54:30 +00:00
jsr CS.RUN.NewLine
2022-11-02 06:54:30 +00:00
.98 lda #0
sec
.99 rts
2021-06-11 17:25:09 +00:00
*--------------------------------------
CS.RUN.PRINT.JMP
2022-11-02 06:54:30 +00:00
jmp (J.CS.RUN.PRINT,x)
2021-06-11 17:25:09 +00:00
*--------------------------------------
2022-11-02 06:54:30 +00:00
CS.RUN.PRINT.REG
bit bPass2
bmi .1
clc
rts
.1 ldx bDirLevel X is loop ctr bDirLevel..0
2022-11-02 06:54:30 +00:00
.2 >LEA.G BlkCounters
>STYA ZPPtr1
ldy #S.STAT.BLOCKS+3 Read 32-bit number of blocks
lda (ZPFileStat),y
pha And push to stack
dey
lda (ZPFileStat),y
pha
dey
lda (ZPFileStat),y
pha
dey
lda (ZPFileStat),y
pha
txa Get loop counter
asl x2
asl x2 again
tay
pla Do 32-bit add
clc
adc (ZPPtr1),y LSB
sta (ZPPtr1),y
pla
iny
adc (ZPPtr1),y
sta (ZPPtr1),y
pla
iny
adc (ZPPtr1),y
sta (ZPPtr1),y
pla
iny
adc (ZPPtr1),y MSB
sta (ZPPtr1),y
dex Decrement loop counter
cpx #$ff Stop if -1
bne .2
bit bAllFiles
bpl .8
>PUSHW L.MSG.REG1
ldy #S.STAT.BLOCKS+3
ldx #4
2022-11-02 06:54:30 +00:00
.3 lda (ZPFileStat),y
>PUSHA
dey
dex
bne .3
2022-11-02 06:54:30 +00:00
>PUSHBI 4
>SYSCALL PrintF
bcs .9
2022-11-02 06:54:30 +00:00
jsr CS.RUN.PrintCwd
>PUSHW L.MSG.REG2
>PUSHW ZPFileName
2022-11-02 06:54:30 +00:00
>PUSHBI 2
>SYSCALL PrintF
bcs .9
2022-11-02 06:54:30 +00:00
jmp CS.RUN.NewLine
.8 clc
.9 rts
2021-06-11 17:25:09 +00:00
*--------------------------------------
2022-11-02 06:54:30 +00:00
CS.RUN.PRINT.DIR
bit bPass2
bmi .8
2021-06-11 17:25:09 +00:00
2022-11-02 06:54:30 +00:00
lda (ZPFileName)
cmp #'.'
beq .8
2021-06-11 17:25:09 +00:00
2022-11-02 06:54:30 +00:00
inc bDirLevel
>LDYA ZPFileName
jmp EnterSubDirYA
2021-06-11 17:25:09 +00:00
2022-11-02 06:54:30 +00:00
.8 clc
.9 rts
2021-06-11 17:25:09 +00:00
*--------------------------------------
2022-11-02 06:54:30 +00:00
CS.RUN.PRINT.CDEV
clc
rts
2021-06-11 17:25:09 +00:00
*--------------------------------------
2022-11-02 06:54:30 +00:00
CS.RUN.PRINT.BDEV
bit bPass2
bmi .8
>PUSHW L.MSG.BDEVEXT
>PUSHW ZPFileName
ldy #S.STAT.P.SLOT
>PUSHB (ZPFileStat),y
iny DRIVE
>PUSHB (ZPFileStat),y
ldy #S.STAT.BLOCKS+1
>PUSHB (ZPFileStat),y
dey
>PUSHB (ZPFileStat),y
ldy #S.STAT.P.DEVBLOCKS+1
>PUSHB (ZPFileStat),y
dey
>PUSHB (ZPFileStat),y
>PUSHBI 8
>SYSCALL PrintF
bcs .9
jsr CS.RUN.NewLine
bcs .9
inc bDirLevel
>LDYA ZPFileName
jsr EnterSubDirYA
bcs .9
.8 clc
.9 rts
2021-06-11 17:25:09 +00:00
*--------------------------------------
CS.RUN.PrintDirSumm
>PUSHW L.MSG.DIRSUMM
2022-11-02 06:54:30 +00:00
lda bDirLevel
asl
asl
ora #3
2022-11-02 06:54:30 +00:00
clc
adc #BlkCounters
tay
ldx #3
.1 >PUSHB (pData),y
lda #0
sta (pData),y
dey
dex
bpl .1
2022-11-02 06:54:30 +00:00
>PUSHBI 4
>SYSCALL PrintF
rts
2021-06-11 17:25:09 +00:00
*--------------------------------------
CS.RUN.PrintBaseDir
lda ArgDir
beq .1
>SYSCALL ArgV
>SYSCALL PutS
rts
.1 ldy #S.PS.hCWD
lda (pPS),y
>SYSCALL GetMemPtr
>SYSCALL PutS
rts
*--------------------------------------
2022-11-02 06:54:30 +00:00
CS.RUN.PrintCwd >PUSHW L.MSG.CWD
ldy #hSrcBasePath
lda (pData),y
>SYSCALL GetMemPtr
>PUSHYA
>PUSHBI 2
>SYSCALL PrintF
rts
2021-06-11 17:25:09 +00:00
*--------------------------------------
2022-11-02 06:54:30 +00:00
CS.RUN.NewLine lda #C.CR
>SYSCALL PutChar
lda bCRLF
2022-11-02 06:54:30 +00:00
beq .9
2022-11-02 06:54:30 +00:00
lda #C.LF
>SYSCALL PutChar
.9 rts
*--------------------------------------
CS.RUN.SetCRLF ldy #S.PS.hStdOut
lda (pPS),y
tax
lda hFDs-1,x
>SYSCALL GetMemPtr
>STYA ZPPtr1
lda (ZPPtr1) #S.FD.T.REG ?
beq .9 no CRLF if REG
inc bCRLF
.9 rts
2021-06-11 17:25:09 +00:00
*--------------------------------------
2022-11-02 06:54:30 +00:00
CS.DOEVENT sec
rts
2021-06-11 17:25:09 +00:00
*--------------------------------------
CS.QUIT jsr LeaveSubDir
bcc CS.QUIT
2022-11-02 06:54:30 +00:00
>LDA.G hFilter
beq .8
>SYSCALL FreeMem
.8 clc
2022-11-02 06:54:30 +00:00
rts
2021-06-11 17:25:09 +00:00
*--------------------------------------
2022-11-02 06:54:30 +00:00
.INB usr/src/shared/x.fileenum.s
2021-06-11 17:25:09 +00:00
*--------------------------------------
CS.END
*--------------------------------------
2022-11-02 06:54:30 +00:00
OptionList .AS "SAsa"
OptionVars .DA #bSummary,#bAllFiles,#bSummary,#bAllFiles
2021-06-11 17:25:09 +00:00
*--------------------------------------
2022-11-02 06:54:30 +00:00
MSG.USAGE .CS "Usage : DU [-A] [-S] [filespec]\r\n"
.CS " -A : Show all files (not only directories)\r\n"
.CZ " -S : Show only summary\r\n"
MSG.REG1 .CZ "%5u "
MSG.REG2 .CZ "%s"
MSG.CWD .CZ "%s"
MSG.DIRSUMM .CZ "%5u "
MSG.BDEVEXT .CZ "/%15s s%dd%d Blocks Used:%5D Total:%5D"
MSG.BDEV .CZ "\e[32m%s/\e[0m"
2021-06-11 17:25:09 +00:00
*--------------------------------------
2022-11-02 06:54:30 +00:00
.DUMMY
.OR 0
2021-06-11 17:25:09 +00:00
DS.START
2022-11-02 06:54:30 +00:00
TIME.SysTime .BS S.TIME
BlkCounters .BS 64 Array of 32 bit integers, size 16
.INB usr/src/shared/x.fileenum.g
DS.END .ED
2021-06-11 17:25:09 +00:00
*--------------------------------------
MAN
SAVE usr/src/bin/du.s
ASM