A2osX/BIN/PAK.S.txt

648 lines
11 KiB
Plaintext
Raw Normal View History

2019-04-03 05:51:28 +00:00
NEW
2019-05-02 09:52:32 +00:00
AUTO 3,1
2019-04-03 05:51:28 +00:00
.LIST OFF
.OP 65C02
.OR $2000
.TF BIN/PAK
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
2019-09-19 15:22:14 +00:00
.INB INC/KERNEL.I
2019-09-25 15:34:43 +00:00
.INB INC/PAK.I
2019-09-23 14:08:17 +00:00
.INB INC/LIBPAK.I
2019-04-03 05:51:28 +00:00
.INB INC/MLI.E.I
*--------------------------------------
2019-04-30 16:08:47 +00:00
X.ENTER.SUBDIR .EQ 0
2019-04-03 05:51:28 +00:00
X.COPY.TO.DEST .EQ 0
X.DELETE.SOURCE .EQ 0
*--------------------------------------
.DUMMY
.OR ZPBIN
ZS.START
ZPPtr1 .BS 2
ZPPtr2 .BS 2
ZPFileName .BS 2
ZPFileStat .BS 2
2019-09-19 15:22:14 +00:00
2019-04-03 05:51:28 +00:00
ZPFullPath .BS 2
2019-09-19 15:22:14 +00:00
ZPRelPath .BS 2
2019-10-02 15:21:03 +00:00
ZPSrcBufPtr .BS 2
ZPDstBufPtr .BS 2
2019-09-19 15:22:14 +00:00
bAppend .BS 1
bRecurse .BS 1
bPause .BS 1
2019-04-03 05:51:28 +00:00
ZS.END .ED
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA 0
.DA CS.END-CS.START Code Size (without Constants)
.DA DS.END-DS.START Data SegmentSize
2019-04-17 15:31:18 +00:00
.DA #64 Stack Size
2019-04-03 05:51:28 +00:00
.DA #ZS.END-ZS.START Zero Page Size
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
2019-09-25 15:34:43 +00:00
L.LIBPAK .DA LIBPAK
2019-04-03 05:51:28 +00:00
L.MSG.USAGE .DA MSG.USAGE
L.MSG.DIR .DA MSG.DIR
L.MSG.FILE .DA MSG.FILE
L.MSG.OK .DA MSG.OK
L.MSG.ERR .DA MSG.ERR
2019-09-23 14:08:17 +00:00
L.MSG.E.IARC .DA MSG.E.IARC
2019-09-19 15:22:14 +00:00
L.ARC.Header .DA ARC.Header
2019-04-03 05:51:28 +00:00
.DA 0
*--------------------------------------
2019-09-25 15:34:43 +00:00
CS.INIT >LDYA L.LIBPAK
>SYSCALL LoadLib
bcs .9
sta hLIB
.9 rts
2019-04-05 05:59:06 +00:00
*--------------------------------------
CS.RUN >INC.G ArgIndex
2019-04-03 05:51:28 +00:00
>SYSCALL ArgV
bcs .8
>STYA ZPPtr1
lda (ZPPtr1)
cmp #'-'
bne .4
2019-09-19 15:22:14 +00:00
jsr CS.RUN.CheckOpt
bcc CS.RUN
2019-04-03 05:51:28 +00:00
2019-04-05 05:59:06 +00:00
.9 >PUSHBI 0
2019-04-03 05:51:28 +00:00
>LDYA L.MSG.USAGE
>SYSCALL printf
lda #E.SYN
sec
2019-04-05 05:59:06 +00:00
.99 rts
2019-04-03 05:51:28 +00:00
*--------------------------------------
.4 >LDA.G ArcName
bne .5
2019-04-17 15:31:18 +00:00
>LDA.G ArgIndex
>STA.G ArcName
bra CS.RUN
2019-04-03 05:51:28 +00:00
2019-04-17 15:31:18 +00:00
.5 >LDA.G hSrcBasePath
2019-04-05 05:59:06 +00:00
bne .9
2019-04-03 05:51:28 +00:00
>LDYA ZPPtr1
jsr InitSrcDirYA
2019-04-05 05:59:06 +00:00
bcc CS.RUN
2019-04-03 05:51:28 +00:00
rts
2019-04-17 15:31:18 +00:00
.8 >LDA.G ArcName
beq .9
>LDA.G hSrcBasePath
beq .9
>LDYAI 256
2019-04-03 05:51:28 +00:00
>SYSCALL getmem
bcs .99
>STYA ZPFullPath
txa
>STA.G hSrcFullPath
2019-09-19 15:22:14 +00:00
>LDA.G hSrcBasePath
>SYSCALL GetMemPtr
>STYA ZPPtr1
ldy #$ff
.80 iny
lda (ZPPtr1),y
bne .80
tya
clc
adc ZPFullPath
sta ZPRelPath
lda ZPFullPath+1
adc #0
sta ZPRelPath+1
jsr CS.RUN.OpenArc
2019-10-02 15:21:03 +00:00
.98 bcs .99
2019-09-19 15:22:14 +00:00
2019-09-23 14:08:17 +00:00
>LDYAI CHNK.SIZE
2019-09-19 15:22:14 +00:00
>SYSCALL getmem
bcs .99
2019-10-02 15:21:03 +00:00
>STYA ZPSrcBufPtr
txa
>STA.G hSrcBuf
>LDYAI CHNK.SIZE
>SYSCALL getmem
bcs .98
>STYA ZPDstBufPtr
2019-09-19 15:22:14 +00:00
txa
2019-10-02 15:21:03 +00:00
>STA.G hDstBuf
2019-04-03 05:51:28 +00:00
*--------------------------------------
2019-04-05 05:59:06 +00:00
CS.RUN.LOOP ldy #S.PS.hStdIn
2019-04-03 05:51:28 +00:00
lda (pPS),y
>SYSCALL feof
bcs .99
tay
2019-05-02 09:52:32 +00:00
bne .1
2019-04-03 05:51:28 +00:00
>SYSCALL GetChar
bcs .99
cmp #$03 Ctrl-C
2019-04-17 15:31:18 +00:00
beq .99 Abort....
2019-04-03 05:51:28 +00:00
cmp #$13 Ctrl-S
2019-04-17 15:31:18 +00:00
bne .1
2019-04-03 05:51:28 +00:00
2019-09-19 15:22:14 +00:00
lda bPause
2019-04-03 05:51:28 +00:00
eor #$ff
2019-09-19 15:22:14 +00:00
sta bPause
2019-04-17 15:31:18 +00:00
bne CS.RUN.LOOP
2019-04-03 05:51:28 +00:00
2019-09-19 15:22:14 +00:00
.1 lda bPause
2019-04-17 15:31:18 +00:00
bne CS.RUN.LOOP Pause...
2019-09-23 14:08:17 +00:00
*--------------------------------------
2019-04-03 05:51:28 +00:00
jsr GetEntry
bcs .9
2019-04-17 15:31:18 +00:00
ldy #S.STAT.P.DRIVE
2019-04-03 05:51:28 +00:00
lda (ZPFileStat),y ProDOS Device ?
2019-04-17 15:31:18 +00:00
beq .5
2019-04-03 05:51:28 +00:00
2019-04-17 15:31:18 +00:00
jsr CS.RUN.DEV
bcc CS.RUN.LOOP
rts
.5 ldy #S.STAT.P.TYPE
2019-04-03 05:51:28 +00:00
lda (ZPFileStat),y
cmp #$0F Directory ?
2019-04-17 15:31:18 +00:00
bne .6
2019-04-03 05:51:28 +00:00
2019-04-17 15:31:18 +00:00
jsr CS.RUN.DIR
bcs .99
2019-09-20 15:15:06 +00:00
bra .8
2019-04-03 05:51:28 +00:00
2019-04-17 15:31:18 +00:00
.6 jsr CS.RUN.FILE
bcs .99
2019-09-20 15:15:06 +00:00
bra .8
2019-04-17 15:31:18 +00:00
2019-04-03 05:51:28 +00:00
.9 jsr LeaveSubDir
2019-04-17 15:31:18 +00:00
bcs .90
2019-04-03 05:51:28 +00:00
jsr BasePath..
.8 jsr GetNextEntry
2019-04-17 15:31:18 +00:00
jmp CS.RUN.LOOP
2019-04-03 05:51:28 +00:00
2019-04-17 15:31:18 +00:00
.90 lda #0
2019-04-03 05:51:28 +00:00
sec
.99 rts
*--------------------------------------
2019-04-17 15:31:18 +00:00
CS.RUN.DEV lda #E.BADPATH
sec
rts
*--------------------------------------
2019-09-19 15:22:14 +00:00
CS.RUN.DIR lda bRecurse
2019-08-26 06:29:18 +00:00
bpl .8
lda (ZPFileName)
2019-04-17 15:31:18 +00:00
cmp #'.'
beq .8
jsr CS.RUN.GetFilePath
2019-04-03 05:51:28 +00:00
2019-09-19 15:22:14 +00:00
>PUSHW ZPRelPath
2019-04-03 05:51:28 +00:00
>PUSHBI 2
>LDYA L.MSG.DIR
>SYSCALL printf
bcs .9
2019-09-23 14:08:17 +00:00
jsr CS.RUN.WriteArcHdrDir
2019-09-19 15:22:14 +00:00
bcs .9
2019-04-17 15:31:18 +00:00
>LDYA ZPFileName
2019-09-19 15:22:14 +00:00
jsr EnterSubDirYA
2019-04-17 15:31:18 +00:00
2019-09-19 15:22:14 +00:00
.9 jmp CS.RUN.CheckErr
2019-04-17 15:31:18 +00:00
.8 clc
2019-09-19 15:22:14 +00:00
rts
2019-04-03 05:51:28 +00:00
*--------------------------------------
2019-04-30 16:08:47 +00:00
CS.RUN.FILE jsr FilterMatch
2019-04-17 15:31:18 +00:00
bcs .8 no match, skip....
2019-09-23 14:08:17 +00:00
jsr CS.RUN.GetFilePath
2019-04-17 15:31:18 +00:00
2019-09-19 15:22:14 +00:00
>PUSHW ZPFullPath
>LDA.G hArcFile
tay
2019-09-23 14:08:17 +00:00
lda OF.Table.hPath-1,y
2019-09-19 15:22:14 +00:00
>SYSCALL getmemptr
>SYSCALL strcmp
bcc .8
>PUSHW ZPRelPath
2019-04-03 05:51:28 +00:00
>PUSHBI 2
>LDYA L.MSG.FILE
>SYSCALL printf
bcs .9
2019-09-23 14:08:17 +00:00
jsr CS.RUN.WriteArcHdrFile
2019-09-19 15:22:14 +00:00
bcs .9
jsr CS.RUN.OpenFile
bcs .9
2019-04-03 05:51:28 +00:00
2019-09-23 14:08:17 +00:00
.1 lda #'.'
>SYSCALL putchar
jsr CS.RUN.ReadFile
bcc .2
cmp #MLI.E.EOF
bne .4
2019-09-20 15:15:06 +00:00
jsr CS.RUN.CloseFile
2019-09-23 14:08:17 +00:00
bra .9
2019-10-02 15:21:03 +00:00
.2 jsr CS.RUN.Pak
2019-10-14 15:58:16 +00:00
bcs .3
jsr CS.RUN.WritePakData
bcc .1
bra .4
.3 jsr CS.RUN.WriteSrcData
2019-09-23 14:08:17 +00:00
bcc .1
.4 pha
jsr CS.RUN.CloseFile
pla
sec
2019-09-20 15:15:06 +00:00
.9 jmp CS.RUN.CheckErr
2019-04-03 05:51:28 +00:00
2019-04-17 15:31:18 +00:00
.8 clc
2019-09-19 15:22:14 +00:00
rts
2019-04-03 05:51:28 +00:00
*--------------------------------------
CS.RUN.CheckErr bcs .1
>LDYA L.MSG.OK
>SYSCALL puts
rts
.1 pha
>PUSHA
>PUSHBI 1
>LDYA L.MSG.ERR
>SYSCALL printf
2019-09-19 15:22:14 +00:00
2019-04-03 05:51:28 +00:00
pla
2019-09-19 15:22:14 +00:00
sec
2019-04-03 05:51:28 +00:00
rts
*--------------------------------------
CS.RUN.GetFilePath
>LDA.G hSrcBasePath
>SYSCALL GetMemPtr
>PUSHYA
>LDYA ZPFullPath
>SYSCALL StrCpy
>PUSHW ZPFileName
>LDYA ZPFullPath
>SYSCALL StrCat
rts
*--------------------------------------
2019-09-23 14:08:17 +00:00
CS.RUN.OpenFile >PUSHWZ Aux type
>PUSHBI 0 Type
>PUSHBI O.RDONLY
>LDYA ZPFullPath
>SYSCALL FOpen
bcs .9
>STA.G hFile
.9 rts
*--------------------------------------
CS.RUN.ReadFile >PUSHWI CHNK.SIZE
2019-10-02 15:21:03 +00:00
>PUSHW ZPSrcBufPtr
2019-09-23 14:08:17 +00:00
>LDA.G hFile
>SYSCALL fread
bcs .9
2019-10-02 15:21:03 +00:00
>STYA.G Shunk.SrcSize
2019-09-23 14:08:17 +00:00
.9 rts
*--------------------------------------
CS.RUN.CloseFile
>LDA.G hFile
>SYSCALL fclose
bcs .9
>STZ.G hFile
.9 rts
*--------------------------------------
2019-10-02 15:21:03 +00:00
CS.RUN.Pak >PUSHEA.G PAKSTAT
>PUSHW ZPDstBufPtr
>PUSHW.G Shunk.SrcSize
>PUSHW ZPSrcBufPtr
>LIBCALL hLIB,LIBPAK.Pak
2019-10-16 14:31:49 +00:00
bcs .9
2019-10-02 15:21:03 +00:00
>STYA.G Shunk.DstSize
2019-10-16 14:31:49 +00:00
.9 rts
2019-10-02 15:21:03 +00:00
*--------------------------------------
2019-09-19 15:22:14 +00:00
CS.RUN.OpenArc >PUSHWZ Aux type
>PUSHBI $CF PAK
2019-09-23 14:08:17 +00:00
bit bAppend
bmi .1
2019-09-19 15:22:14 +00:00
>PUSHBI O.CREATE+O.WRONLY
>LDA.G ArcName
>SYSCALL Argv
>SYSCALL FOpen
bcs .9
>STA.G hArcFile
2019-09-23 14:08:17 +00:00
2019-09-19 15:22:14 +00:00
>PUSHW L.ARC.Header
>LDA.G hArcFile
>SYSCALL fputs
.9 rts
*--------------------------------------
2019-09-23 14:08:17 +00:00
.1 >PUSHBI O.RDWR
>LDA.G ArcName
>SYSCALL Argv
>SYSCALL FOpen
2019-09-19 15:22:14 +00:00
bcs .9
2019-09-23 14:08:17 +00:00
>STA.G hArcFile
2019-09-19 15:22:14 +00:00
2019-09-23 14:08:17 +00:00
pha
>PUSHWI 3
2019-10-02 15:21:03 +00:00
>PUSHW ZPSrcBufPtr
2019-09-23 14:08:17 +00:00
pla
>SYSCALL fread
2019-09-19 15:22:14 +00:00
bcs .9
2019-09-23 14:08:17 +00:00
cpy #3
bne .99
dey
.2 lda ARC.Header,y
2019-10-02 15:21:03 +00:00
cmp (ZPSrcBufPtr),y
2019-09-23 14:08:17 +00:00
bne .99
dey
bpl .2
>PUSHBI SEEK.END
>PUSHWI 0
>PUSHWI 0
>LDA.G hArcFile
>SYSCALL fseek
bcc .8
cmp #MLI.E.EOF
bne .99
clc
.8 rts
.99 >LDYA L.MSG.E.IARC
>SYSCALL puts
lda #E.SYN
sec
rts
*--------------------------------------
CS.RUN.WriteArcHdrDir
lda #CHNK.T.DIR
jsr CS.RUN.WriteArcByteA
bcc CS.RUN.WriteArcHdr
rts
CS.RUN.WriteArcHdrFile
lda #CHNK.T.FILE
jsr CS.RUN.WriteArcByteA
bcs CS.RUN.WriteArcHdr.9
ldy #S.STAT.P.TYPE
jsr CS.RUN.WriteArcByteY
bcs CS.RUN.WriteArcHdr.9
2019-09-19 15:22:14 +00:00
ldy #S.STAT.P.AUXTYPE
2019-09-23 14:08:17 +00:00
jsr CS.RUN.WriteArcByteY
bcs CS.RUN.WriteArcHdr.9
2019-09-19 15:22:14 +00:00
ldy #S.STAT.P.AUXTYPE+1
2019-09-23 14:08:17 +00:00
jsr CS.RUN.WriteArcByteY
bcs CS.RUN.WriteArcHdr.9
2019-09-19 15:22:14 +00:00
2019-09-23 14:08:17 +00:00
CS.RUN.WriteArcHdr
2019-09-19 15:22:14 +00:00
ldy #$ff
.1 iny
lda (ZPRelPath),y
bne .1
tya
2019-09-23 14:08:17 +00:00
jsr CS.RUN.WriteArcByteA
bcs CS.RUN.WriteArcHdr.9
2019-09-19 15:22:14 +00:00
>PUSHW ZPRelPath
>LDA.G hArcFile
2019-09-23 14:08:17 +00:00
>SYSCALL fputs
CS.RUN.WriteArcHdr.9
2019-09-19 15:22:14 +00:00
rts
*--------------------------------------
2019-10-14 15:58:16 +00:00
CS.RUN.WriteSrcData
2019-09-23 14:08:17 +00:00
lda #CHNK.T.DATA
jsr CS.RUN.WriteArcByteA
2019-09-19 15:22:14 +00:00
bcs .9
2019-10-14 15:58:16 +00:00
>LDA.G Shunk.SrcSize
2019-10-17 10:36:45 +00:00
clc
adc #3
pha
>LDA.G Shunk.SrcSize+1
adc #0
sta ZPPtr1+1
pla
2019-09-23 14:08:17 +00:00
jsr CS.RUN.WriteArcByteA
2019-09-20 15:15:06 +00:00
bcs .9
2019-10-17 10:36:45 +00:00
lda ZPPtr1+1
2019-09-23 14:08:17 +00:00
jsr CS.RUN.WriteArcByteA
2019-10-02 15:21:03 +00:00
bcs .9
2019-09-23 14:08:17 +00:00
2019-10-14 15:58:16 +00:00
lda #0 NO COMPRESSION
2019-09-23 14:08:17 +00:00
jsr CS.RUN.WriteArcByteA
bcs .9
2019-10-15 15:33:51 +00:00
2019-10-17 10:36:45 +00:00
>LDA.G Shunk.SrcSize
jsr CS.RUN.WriteArcByteA
bcs .9
>LDA.G Shunk.SrcSize+1
jsr CS.RUN.WriteArcByteA
bcs .9
2019-10-14 15:58:16 +00:00
>PUSHW.G Shunk.SrcSize
>PUSHW ZPSrcBufPtr
>LDA.G hArcFile
>SYSCALL fwrite
.9 rts
*--------------------------------------
CS.RUN.WritePakData
lda #CHNK.T.DATA
jsr CS.RUN.WriteArcByteA
bcs .9
>LDA.G Shunk.DstSize
jsr CS.RUN.WriteArcByteA
bcs .9
>LDA.G Shunk.DstSize+1
jsr CS.RUN.WriteArcByteA
bcs .9
2019-10-16 06:09:13 +00:00
2019-10-02 15:21:03 +00:00
>PUSHW.G Shunk.DstSize
>PUSHW ZPDstBufPtr
2019-09-23 14:08:17 +00:00
>LDA.G hArcFile
>SYSCALL fwrite
2019-09-20 15:15:06 +00:00
.9 rts
*--------------------------------------
2019-09-23 14:08:17 +00:00
CS.RUN.WriteArcByteY
lda (ZPFileStat),y
CS.RUN.WriteArcByteA
>PUSHA
>LDA.G hArcFile
>SYSCALL fputc
rts
*--------------------------------------
2019-04-03 05:51:28 +00:00
CS.DOEVENT sec
rts
*--------------------------------------
CS.QUIT jsr LeaveSubDir
bcc CS.QUIT
>LDA.G hFilter
beq .1
>SYSCALL FreeMem
.1 >LDA.G hSrcFullPath
2019-09-19 15:22:14 +00:00
beq .2
>SYSCALL FreeMem
.2 >LDA.G hArcFile
beq .3
>SYSCALL fclose
2019-10-02 15:21:03 +00:00
.3 >LDA.G hDstBuf
2019-09-25 15:34:43 +00:00
beq .4
2019-04-03 05:51:28 +00:00
>SYSCALL FreeMem
2019-09-23 14:08:17 +00:00
2019-10-02 15:21:03 +00:00
.4 >LDA.G hSrcBuf
beq .5
>SYSCALL FreeMem
.5 lda hLIB
2019-09-25 15:34:43 +00:00
beq .8
>SYSCALL UnloadLib
2019-04-03 05:51:28 +00:00
.8 clc
rts
2019-09-19 15:22:14 +00:00
*--------------------------------------
CS.RUN.CheckOpt ldy #1
lda (ZPPtr1),y
ldx #OptionVars-OptionList-1
.2 cmp OptionList,x
beq .3
dex
bpl .2
sec
rts
.3 ldy OptionVars,x
lda #$ff
sta 0,y
clc
rts
2019-04-03 05:51:28 +00:00
*--------------------------------------
.INB USR/SRC/BIN/X.FILEENUM.S
*--------------------------------------
CS.END
*--------------------------------------
2019-09-19 15:22:14 +00:00
OptionList .AS "AaRr"
OptionVars .DA #bAppend,#bAppend,#bRecurse,#bRecurse
2019-04-03 05:51:28 +00:00
*--------------------------------------
MSG.USAGE .AS "Usage : PAK Archive [File *,? wildcards allowed]\r\n"
2019-09-19 15:22:14 +00:00
.AS " -A : Append to archive\r\n"
2019-04-03 05:51:28 +00:00
.AZ " -R : Recurse subdirectories\r\n"
MSG.OK .AZ "[OK]"
MSG.ERR .AZ "[%h]\r\n"
2019-09-23 14:08:17 +00:00
MSG.E.IARC .AZ "Invalid/corrupt archive"
2019-04-17 15:31:18 +00:00
MSG.DIR .AZ "Reading Dir:%s..."
MSG.FILE .AZ "Adding File:%s..."
2019-09-19 15:22:14 +00:00
ARC.Header .AZ "PAK"
2019-09-25 15:34:43 +00:00
*--------------------------------------
LIBPAK .AZ "libpak"
hLIB .BS 1
2019-04-03 05:51:28 +00:00
*--------------------------------------
.DUMMY
.OR 0
DS.START
ArgIndex .BS 1
2019-04-17 15:31:18 +00:00
ArcName .BS 1
2019-04-03 05:51:28 +00:00
hSrcFullPath .BS 1
2019-10-02 15:21:03 +00:00
2019-09-19 15:22:14 +00:00
hFile .BS 1
2019-10-02 15:21:03 +00:00
hArcFile .BS 1
2019-04-17 15:31:18 +00:00
2019-10-02 15:21:03 +00:00
hSrcBuf .BS 1
hDstBuf .BS 1
Shunk.SrcSize .BS 2
Shunk.DstSize .BS 2
PAKSTAT .BS S.PAKSTAT
2019-09-19 15:22:14 +00:00
.INB USR/SRC/BIN/X.FILEENUM.G
2019-04-03 05:51:28 +00:00
DS.END
.ED
*--------------------------------------
MAN
SAVE USR/SRC/BIN/PAK.S
ASM