UNPAK: Added -p flag which shows progress spinner

This commit is contained in:
Bobbi Webber-Manners 2021-06-18 20:35:05 -04:00
parent baf9655700
commit f03f4d82d7

View File

@ -31,6 +31,8 @@ ZPOutBufLen .BS 2
ZPFullPathPtr .BS 2
ZPRelPathPtr .BS 2
ZPProgress .BS 1
ZS.END .ED
*--------------------------------------
* File Header (16 Bytes)
@ -57,14 +59,18 @@ L.MSG.DIR .DA MSG.DIR
L.MSG.FILE .DA MSG.FILE
L.MSG.OK .DA MSG.OK
L.MSG.E.IARC .DA MSG.E.IARC
L.MSG.SPINNER .DA MSG.SPINNER
.DA 0
*--------------------------------------
CS.INIT clc
rts
*--------------------------------------
CS.RUN >LDYAI CHNK.SIZE
CS.RUN stz ZPProgress
>LDYAI CHNK.SIZE
>SYSCALL GetMem
bcs .9
bcc s1
rts
s1
>STYA ZPInBufPtr
txa
>STA.G hInBuf
@ -73,26 +79,50 @@ CS.RUN >LDYAI CHNK.SIZE
>SYSCALL ArgV
bcs .99
jsr CS.RUN.OpenArc
>STYA ZPPtr1 See if first arg is -p
pha
lda (ZPPtr1)
cmp #'-'
bne .1 No dash-arguments
pla
ldy #$01
lda (ZPPtr1),y
cmp #'p'
bne .99 -p is only valid argument
sty ZPProgress
lda #2
>SYSCALL ArgV
bcs .99
bra .11
.1 pla
.11 jsr CS.RUN.OpenArc
bcs .9
>LDYAI 256
>SYSCALL GetMem
bcs .9
bcc .15
rts
>STYA ZPFullPathPtr
.15 >STYA ZPFullPathPtr
txa
>STA.G hFullPath
lda #2
>SYSCALL ArgV
bcc .1
lda ZPProgress See if -p was provided
beq .2
lda #' ' Space for spinner to eat
>SYSCALL PutChar
lda #3 Have dash-args, check arg #3
bra .3
.2 lda #2 No dash-args, check arg #2
.3 >SYSCALL ArgV
bcc .4
ldy #S.PS.hCWD
lda (pPS),y
>SYSCALL GetMemPtr
.1 jsr CS.RUN.SetupPath
.4 jsr CS.RUN.SetupPath
>LDYAI CHNK.SIZE
>SYSCALL GetMem
@ -104,6 +134,7 @@ CS.RUN >LDYAI CHNK.SIZE
jsr CS.RUN.LOOP
bcs .9
jsr CS.RUN.TidyUp
lda #0
sec
.9 rts
@ -152,6 +183,8 @@ CS.RUN.LOOP jsr CS.RUN.GetByte
jsr CS.RUN.CheckDir
bcs .99
lda ZPProgress
bne CS.RUN.LOOP
>LDYA L.MSG.OK
>SYSCALL PutS
bra CS.RUN.LOOP
@ -179,10 +212,14 @@ CS.RUN.LOOP jsr CS.RUN.GetByte
.2 cmp #CHNK.T.DATA
bne .3 Could be a 0 byte file
.20 lda #'.'
.20 lda ZPProgress
beq .21
jsr CS.RUN.Spinner
bra .22
.21 lda #'.'
>SYSCALL PutChar
jsr CS.RUN.GetByte DataLen LO
.22 jsr CS.RUN.GetByte DataLen LO
bcs .99
sta ZPInBufLen
@ -224,21 +261,53 @@ CS.RUN.LOOP jsr CS.RUN.GetByte
.8 >LDA.G hFile
>SYSCALL FClose
LDA ZPProgress
bne S1
>LDYA L.MSG.OK
>SYSCALL PutS
rts
S1 rts
*--------------------------------------
CS.RUN.PrintFN >PUSHW L.MSG.DIR,x
CS.RUN.PrintFN lda ZPProgress
bne .9
>PUSHW L.MSG.DIR,x
>PUSHW ZPFullPathPtr
>PUSHBI 2
>SYSCALL PrintF
.9 rts
*--------------------------------------
CS.RUN.Spinner lda #8 Backspace
>SYSCALL PutChar
>LDYA L.MSG.SPINNER
>STYA ZPPtr2
>LDA.G SpinState
tay
lda (ZPPtr2),y
>SYSCALL PutChar
>INC.G SpinState
cmp #4
bne .9
>STZ.G SpinState
.9 rts
*--------------------------------------
CS.RUN.NewLine LDA #C.CR
>SYSCALL PutChar
LDA #C.LF
>SYSCALL PutChar
rts
*--------------------------------------
CS.RUN.TidyUp lda ZPProgress
beq .9
lda #8
>SYSCALL PutChar
lda #' '
>SYSCALL PutChar
jsr CS.RUN.NewLine
.9 rts
*--------------------------------------
CS.RUN.OpenArc >PUSHYA
>PUSHBI O.RDONLY
>PUSHBI $CF PAK
>PUSHWZ Aux type
>SYSCALL FOpen
bcs .9
@ -382,12 +451,14 @@ CS.QUIT >LDA.G hFile
.INB usr/src/shared/x.unpak.s
*--------------------------------------
CS.END
MSG.USAGE .AZ "Usage : UNPAK Archive [DstDir]\r\n"
MSG.USAGE .AS "Usage : UNPAK [-p] Archive [DstDir]\r\n"
.AZ " -p: Show progress spinner\r\n"
MSG.DIR .AZ "Creating Dir:%s..."
MSG.FILE .AZ "Extracting File:%s..."
MSG.OK .AZ "[OK]"
MSG.E.IARC .AZ "\r\nInvalid/corrupt archive"
MSG.PAK .AS "PAK"
MSG.SPINNER .AS "|/-\"
*--------------------------------------
.DUMMY
.OR 0
@ -399,6 +470,7 @@ hOutBuf .BS 1
hFile .BS 1
FileType .BS 1
FileAuxType .BS 2
SpinState .BS 1
STAT .BS S.STAT
DS.END
.ED