A2osX/BIN/UNPAK.S.txt

403 lines
7.0 KiB
Plaintext
Raw Normal View History

NEW
2019-04-10 07:45:09 +00:00
AUTO 3,1
.LIST OFF
.OP 65C02
.OR $2000
2020-02-29 14:06:28 +00:00
.TF bin/unpak
*--------------------------------------
2020-08-23 19:46:37 +00:00
.INB inc/macros.i
.INB inc/a2osx.i
.INB inc/mli.e.i
.INB inc/pak.i
2018-02-09 16:02:47 +00:00
*--------------------------------------
2019-09-23 14:08:17 +00:00
.DUMMY
.OR ZPBIN
ZS.START
ZPPtr1 .BS 2
2019-09-24 15:25:07 +00:00
ZPPtr2 .BS 2
2019-09-23 14:08:17 +00:00
2019-09-24 15:25:07 +00:00
ZPInBufPtr .BS 2
ZPOutBufPtr .BS 2
2019-10-14 15:58:16 +00:00
2019-09-24 15:25:07 +00:00
ZPnCnt .BS 2
ZPInMask .BS 1
2019-10-14 05:23:09 +00:00
ZPBLOfsLBits .BS 1
ZPBLOfsHBits .BS 1
ZPBLLenBits .BS 1
2019-10-14 15:58:16 +00:00
ZPInBufLen .BS 2
ZPOutBufLen .BS 2
ZPFullPathPtr .BS 2
ZPRelPathPtr .BS 2
2019-09-23 14:08:17 +00:00
ZS.END .ED
2018-02-09 16:02:47 +00:00
*--------------------------------------
* 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 CS
.DA DS.END-DS.START DS
.DA #64 SS
2019-09-23 14:08:17 +00:00
.DA #ZS.END-ZS.START Zero Page Size
.DA 0
*--------------------------------------
* Relocation Table
2019-10-03 06:25:27 +00:00
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
2019-09-23 14:08:17 +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.E.IARC .DA MSG.E.IARC
.DA 0
*--------------------------------------
2019-09-20 15:15:06 +00:00
CS.INIT clc
rts
2018-02-05 16:25:25 +00:00
*--------------------------------------
2019-09-23 14:08:17 +00:00
CS.RUN >LDYAI CHNK.SIZE
2020-02-28 07:21:46 +00:00
>SYSCALL GetMem
2019-09-23 14:08:17 +00:00
bcs .9
>STYA ZPInBufPtr
txa
>STA.G hInBuf
lda #1
2020-08-23 19:46:37 +00:00
>SYSCALL ArgV
2019-10-14 15:58:16 +00:00
bcs .99
2019-09-23 14:08:17 +00:00
jsr CS.RUN.OpenArc
bcs .9
2019-10-14 15:58:16 +00:00
2019-09-23 14:08:17 +00:00
>LDYAI 256
2020-02-28 07:21:46 +00:00
>SYSCALL GetMem
2019-09-23 14:08:17 +00:00
bcs .9
2019-10-14 15:58:16 +00:00
2019-09-23 14:08:17 +00:00
>STYA ZPFullPathPtr
txa
>STA.G hFullPath
2019-10-14 15:58:16 +00:00
2019-09-23 14:08:17 +00:00
lda #2
2020-08-25 06:01:56 +00:00
>SYSCALL ArgV
2019-09-23 14:08:17 +00:00
bcc .1
2019-10-14 15:58:16 +00:00
2019-09-23 14:08:17 +00:00
ldy #S.PS.hCWD
lda (pPS),y
2020-08-23 19:46:37 +00:00
>SYSCALL GetMemPtr
2019-09-23 14:08:17 +00:00
.1 jsr CS.RUN.SetupPath
>LDYAI CHNK.SIZE
2020-02-28 07:21:46 +00:00
>SYSCALL GetMem
2019-09-23 14:08:17 +00:00
bcs .9
2019-10-15 15:32:50 +00:00
2019-09-23 14:08:17 +00:00
txa
>STA.G hOutBuf
jsr CS.RUN.LOOP
bcs .9
2018-02-05 16:25:25 +00:00
2019-09-23 14:08:17 +00:00
lda #0
sec
.9 rts
2020-02-29 14:06:28 +00:00
.99 >PUSHW L.MSG.USAGE
>PUSHBI 0
2020-02-28 07:21:46 +00:00
>SYSCALL PrintF
2019-09-20 15:15:06 +00:00
lda #E.SYN
sec
rts
*--------------------------------------
2019-09-23 14:08:17 +00:00
CS.RUN.SetupPath
>STYA ZPPtr1
ldy #$ff
.2 iny
lda (ZPPtr1),y
sta (ZPFullPathPtr),y
bne .2
dey
lda #'/'
cmp (ZPFullPathPtr),y
beq .3
iny
sta (ZPFullPathPtr),y
.3 tya
sec
adc ZPFullPathPtr
sta ZPRelPathPtr
lda #0
adc ZPFullPathPtr+1
sta ZPRelPathPtr+1
rts
*--------------------------------------
CS.RUN.LOOP jsr CS.RUN.GetByte
bcs .9
.10 cmp #CHNK.T.DIR
bne .1
jsr CS.RUN.GetFileName
2019-10-17 10:36:45 +00:00
bcs .99
2019-09-23 14:08:17 +00:00
ldx #0
jsr CS.RUN.PrintFN
jsr CS.RUN.CheckDir
bcs .99
>LDYA L.MSG.OK
2020-02-28 07:21:46 +00:00
>SYSCALL PutS
2019-09-23 14:08:17 +00:00
bra CS.RUN.LOOP
clc
.99 rts
2019-10-14 05:23:09 +00:00
2019-09-23 14:08:17 +00:00
.9 jmp CS.RUN.E.IARC
2019-10-14 15:58:16 +00:00
2019-09-23 14:08:17 +00:00
.1 cmp #CHNK.T.FILE
bne .9
jsr CS.RUN.GetFileType
2019-10-17 10:36:45 +00:00
bcs .99
2019-09-23 14:08:17 +00:00
jsr CS.RUN.GetFileName
2019-10-17 10:36:45 +00:00
bcs .99
2019-09-23 14:08:17 +00:00
ldx #2
jsr CS.RUN.PrintFN
jsr CS.RUN.OpenFile
2019-10-17 10:36:45 +00:00
bcs .99
2019-09-23 14:08:17 +00:00
*--------------------------------------
jsr CS.RUN.GetByte DATA
bcs .8 eof
.2 cmp #CHNK.T.DATA
bne .3 Could be a 0 byte file
2019-10-16 14:31:49 +00:00
.20 lda #'.'
2020-08-23 19:46:37 +00:00
>SYSCALL PutChar
2019-10-16 14:31:49 +00:00
jsr CS.RUN.GetByte DataLen LO
2019-10-17 10:36:45 +00:00
bcs .99
2019-10-14 15:58:16 +00:00
sta ZPInBufLen
2019-09-23 14:08:17 +00:00
2019-10-14 15:58:16 +00:00
jsr CS.RUN.GetByte DataLen HI
2019-10-17 10:36:45 +00:00
bcs .99
2019-10-14 15:58:16 +00:00
sta ZPInBufLen+1
2019-10-16 14:31:49 +00:00
2019-10-14 15:58:16 +00:00
jsr CS.RUN.ReadData
2019-10-17 10:36:45 +00:00
bcs .99
2019-10-14 05:23:09 +00:00
2019-10-16 14:31:49 +00:00
ldy #1
lda (ZPInBufPtr),y
2019-10-14 15:58:16 +00:00
sta ZPOutBufLen
2019-10-16 14:31:49 +00:00
iny
2019-10-14 15:58:16 +00:00
lda (ZPInBufPtr),y
sta ZPOutBufLen+1
2019-10-15 06:43:24 +00:00
2019-10-15 15:32:50 +00:00
>LDA.G hOutBuf
2020-08-23 19:46:37 +00:00
>SYSCALL GetMemPtr
2019-10-15 15:32:50 +00:00
>STYA ZPOutBufPtr
2019-10-14 15:58:16 +00:00
jsr X.Unpak
2019-10-16 20:42:21 +00:00
bcs .9
2019-10-14 15:58:16 +00:00
2019-09-23 14:08:17 +00:00
jsr CS.RUN.WriteFile
2019-10-17 10:36:45 +00:00
bcs .99
2019-10-16 14:31:49 +00:00
2019-09-23 14:08:17 +00:00
jsr CS.RUN.GetByte
bcs .8
2019-10-16 14:31:49 +00:00
2019-09-23 14:08:17 +00:00
cmp #CHNK.T.DATA
beq .20
2019-10-14 15:58:16 +00:00
2019-09-23 14:08:17 +00:00
.3 pha
jsr .8
pla
2019-10-14 15:58:16 +00:00
jmp .10
2019-09-23 14:08:17 +00:00
.8 >LDA.G hFile
2020-02-28 07:21:46 +00:00
>SYSCALL FClose
2019-09-23 14:08:17 +00:00
>LDYA L.MSG.OK
2020-02-28 07:21:46 +00:00
>SYSCALL PutS
2019-09-23 14:08:17 +00:00
rts
*--------------------------------------
2020-02-29 14:06:28 +00:00
CS.RUN.PrintFN >PUSHW L.MSG.DIR,x
>PUSHW ZPFullPathPtr
2019-09-23 14:08:17 +00:00
>PUSHBI 2
2020-02-28 07:21:46 +00:00
>SYSCALL PrintF
2019-09-23 14:08:17 +00:00
rts
*--------------------------------------
2020-02-29 14:06:28 +00:00
CS.RUN.OpenArc >PUSHYA
2019-09-23 14:08:17 +00:00
>PUSHBI O.RDONLY
2020-02-29 14:06:28 +00:00
>PUSHBI $CF PAK
>PUSHWZ Aux type
2019-09-23 14:08:17 +00:00
>SYSCALL FOpen
bcs .9
2020-02-29 14:06:28 +00:00
2019-09-23 14:08:17 +00:00
>STA.G hArcFile
pha
>PUSHWI 3
>PUSHW ZPInBufPtr
pla
2020-08-23 19:46:37 +00:00
>SYSCALL FRead
2019-09-23 14:08:17 +00:00
bcs .9
cpy #3
bne .99
dey
.1 lda MSG.PAK,y
cmp (ZPInBufPtr),y
bne .99
dey
bpl .1
clc
.9 rts
.99
2020-02-29 14:06:28 +00:00
CS.RUN.E.IARC >PUSHW L.MSG.E.IARC
>PUSHBI 0
2020-02-28 07:21:46 +00:00
>SYSCALL PrintF
2019-09-23 14:08:17 +00:00
lda #E.SYN
sec
rts
*--------------------------------------
CS.RUN.GetFileType
>PUSHWI 3
>PUSHEA.G FileType
>LDA.G hArcFile
2020-08-23 19:46:37 +00:00
>SYSCALL FRead
2019-09-23 14:08:17 +00:00
rts
*--------------------------------------
CS.RUN.GetFileName
jsr CS.RUN.GetByte
bcs .9
tay
lda #0
>PUSHYA
>PUSHW ZPRelPathPtr
>LDA.G hArcFile
2020-08-23 19:46:37 +00:00
>SYSCALL FRead
2019-09-23 14:08:17 +00:00
bcs .9
lda #0
sta (ZPRelPathPtr),y
2019-10-03 06:25:27 +00:00
* clc
.9 rts
2019-09-23 14:08:17 +00:00
*--------------------------------------
2019-10-14 15:58:16 +00:00
CS.RUN.ReadData >PUSHW ZPInBufLen
2019-10-16 14:31:49 +00:00
>LDA.G hInBuf
2020-08-23 19:46:37 +00:00
>SYSCALL GetMemPtr
2019-10-16 14:31:49 +00:00
>STYA ZPInBufPtr
>PUSHYA
2019-09-23 14:08:17 +00:00
>LDA.G hArcFile
2020-08-23 19:46:37 +00:00
>SYSCALL FRead
2019-09-23 14:08:17 +00:00
rts
*--------------------------------------
CS.RUN.GetByte >LDA.G hArcFile
2020-08-23 19:46:37 +00:00
>SYSCALL GetC
2019-09-23 14:08:17 +00:00
rts
*--------------------------------------
2020-02-29 14:06:28 +00:00
CS.RUN.CheckDir >PUSHW ZPFullPathPtr
>PUSHEA.G STAT
2020-08-23 19:46:37 +00:00
>SYSCALL Stat
2019-09-23 14:08:17 +00:00
bcc .1
2020-02-29 14:06:28 +00:00
>PUSHW ZPFullPathPtr
>PUSHWI S.STAT.MODE.FO+S.STAT.MODE.FG+S.STAT.MODE.FU
2020-08-23 19:46:37 +00:00
>SYSCALL MKDir
2019-09-23 14:08:17 +00:00
rts
2019-10-14 05:23:09 +00:00
2019-09-23 14:08:17 +00:00
.1 ldy #STAT+S.STAT.P.TYPE
lda (pData),y
cmp #$F
bne .99
clc
rts
2019-10-14 05:23:09 +00:00
2019-09-23 14:08:17 +00:00
.99 lda #MLI.E.INVPATH
sec
.9 rts
*--------------------------------------
2020-02-29 14:06:28 +00:00
CS.RUN.OpenFile >PUSHW ZPFullPathPtr
2019-09-23 14:08:17 +00:00
>PUSHBI O.CREATE+O.WRONLY+O.TRUNC
2020-02-29 14:06:28 +00:00
>PUSHB.G FileType
>PUSHW.G FileAuxType
2019-09-23 14:08:17 +00:00
>SYSCALL FOpen
bcs .9
>STA.G hFile
.9 rts
*--------------------------------------
CS.RUN.WriteFile
2019-10-14 15:58:16 +00:00
>PUSHW ZPOutBufLen
2019-10-15 15:32:50 +00:00
>LDA.G hOutBuf
2020-08-23 19:46:37 +00:00
>SYSCALL GetMemPtr
2019-10-15 15:32:50 +00:00
>PUSHYA
2019-09-23 14:08:17 +00:00
>LDA.G hFile
2020-08-23 19:46:37 +00:00
>SYSCALL FWrite
2019-09-23 14:08:17 +00:00
rts
2018-02-09 16:02:47 +00:00
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
2019-09-23 14:08:17 +00:00
CS.QUIT >LDA.G hFile
2018-02-05 16:25:25 +00:00
beq .1
2020-02-28 07:21:46 +00:00
>SYSCALL FClose
2019-10-14 05:23:09 +00:00
2019-09-23 14:08:17 +00:00
.1 >LDA.G hFullPath
2018-02-05 16:25:25 +00:00
beq .2
2019-10-14 05:23:09 +00:00
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
2019-09-23 14:08:17 +00:00
.2 >LDA.G hOutBuf
beq .3
2019-10-14 05:23:09 +00:00
2019-09-23 14:08:17 +00:00
>SYSCALL FreeMem
.3 >LDA.G hInBuf
beq .4
2019-10-14 05:23:09 +00:00
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
2019-10-14 05:23:09 +00:00
2019-09-23 14:08:17 +00:00
.4 >LDA.G hArcFile
beq .8
2020-02-28 07:21:46 +00:00
>SYSCALL FClose
2019-09-23 14:08:17 +00:00
2019-09-20 15:15:06 +00:00
.8 clc
rts
2019-09-24 15:25:07 +00:00
*--------------------------------------
2020-08-25 06:01:56 +00:00
.INB usr/src/shared/x.unpak.s
*--------------------------------------
CS.END
2019-09-23 14:08:17 +00:00
MSG.USAGE .AZ "Usage : UNPAK Archive [DstDir]\r\n"
MSG.DIR .AZ "Creating Dir:%s..."
MSG.FILE .AZ "Extracting File:%s..."
MSG.OK .AZ "[OK]"
2019-10-16 20:42:21 +00:00
MSG.E.IARC .AZ "\r\nInvalid/corrupt archive"
2019-09-23 14:08:17 +00:00
MSG.PAK .AS "PAK"
*--------------------------------------
.DUMMY
.OR 0
DS.START
2019-09-23 14:08:17 +00:00
hArcFile .BS 1
hFullPath .BS 1
hInBuf .BS 1
hOutBuf .BS 1
hFile .BS 1
FileType .BS 1
FileAuxType .BS 2
STAT .BS S.STAT
DS.END
.ED
*--------------------------------------
MAN
2020-08-23 19:46:37 +00:00
SAVE usr/src/bin/unpak.s
ASM