A2osX/BIN/PAKME.S.txt

573 lines
10 KiB
Plaintext
Raw Normal View History

2019-10-16 15:23:29 +00:00
NEW
AUTO 3,1
.LIST OFF
.OP 65C02
.OR $2000
.TF BIN/PAKME
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/KERNEL.I
.INB INC/PAK.I
.INB INC/LIBPAK.I
.INB INC/MLI.E.I
2019-10-29 14:47:25 +00:00
*--------------------------------------
CHUNK.MAX .EQ 32
2019-10-16 15:23:29 +00:00
*--------------------------------------
.DUMMY
.OR ZPBIN
ZS.START
ZPPtr1 .BS 2
ZPPtr2 .BS 2
2019-10-29 14:47:25 +00:00
ZPSrcFileSize .BS 2
ZPDstTableOfs .BS 2
2019-10-30 16:29:46 +00:00
hSrcFile .BS 1
hDstFile .BS 1
2019-10-29 14:47:25 +00:00
ZPChunkIndex .BS 1
ZPChunkCnt .BS 1
2019-10-29 16:11:45 +00:00
ZPChunkOfs .BS 2
ZPChunkLen .BS 2
2019-10-29 14:47:25 +00:00
2019-10-30 16:29:46 +00:00
ZPChunkPakedLen .BS 2
ZPChunkNewOfs .BS 2
hSrcBuf .BS 1
hDstBuf .BS 1
ZPSrcBufPtr .BS 2
ZPDstBufPtr .BS 2
2019-10-16 15:23:29 +00:00
2019-10-30 16:29:46 +00:00
bPause .BS 1
2019-10-29 14:47:25 +00:00
2019-10-16 15:23:29 +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
.DA #64 Stack Size
.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
L.LIBPAK .DA LIBPAK
L.MSG.USAGE .DA MSG.USAGE
2019-10-29 14:47:25 +00:00
L.MSG.SRCFILE .DA MSG.SRCFILE
L.MSG.CHUNK .DA MSG.CHUNK
2019-10-30 16:29:46 +00:00
L.MSG.PAKED .DA MSG.PAKED
2019-11-05 13:36:10 +00:00
L.MSG.STORE .DA MSG.STORE
2019-10-16 15:23:29 +00:00
L.MSG.E.IARC .DA MSG.E.IARC
2019-10-29 14:47:25 +00:00
L.TAG .DA TAG
2019-10-16 15:23:29 +00:00
.DA 0
*--------------------------------------
CS.INIT >LDYA L.LIBPAK
>SYSCALL LoadLib
bcs .9
sta hLIB
.9 rts
*--------------------------------------
2019-10-29 14:47:25 +00:00
CS.RUN ldy #S.PS.ARGC
lda (pPs),y
cmp #2
bne .9
jsr CS.RUN.CheckSrcFile
bcs .99
>PUSHW.G STATBUF+S.STAT.P.AUXTYPE
>PUSHB.G STATBUF+S.STAT.P.TYPE
>PUSHBI O.CREATE+O.WRONLY
lda #2
2019-10-16 15:23:29 +00:00
>SYSCALL ArgV
2019-10-29 14:47:25 +00:00
>SYSCALL FOpen
bcs .99
2019-10-16 15:23:29 +00:00
2019-10-29 14:47:25 +00:00
sta hDstFile
2019-10-16 15:23:29 +00:00
2019-10-29 14:47:25 +00:00
bra CS.RUN.START
2019-10-16 15:23:29 +00:00
.9 >PUSHBI 0
>LDYA L.MSG.USAGE
>SYSCALL printf
lda #E.SYN
sec
.99 rts
*--------------------------------------
2019-10-30 16:29:46 +00:00
CS.RUN.START >PUSHW ZPDstTableOfs
>PUSHB.G PAKME.HEADER+7
2019-10-29 14:47:25 +00:00
>PUSHW.G PAKME.HEADER+5
2019-10-30 16:29:46 +00:00
>PUSHW ZPSrcFileSize
2019-10-29 14:47:25 +00:00
lda #1
>SYSCALL ArgV
>PUSHYA
2019-10-16 15:23:29 +00:00
2019-10-30 16:29:46 +00:00
>PUSHBI 9
2019-10-29 14:47:25 +00:00
>LDYA L.MSG.SRCFILE
>SYSCALL printf
2019-10-16 15:23:29 +00:00
2019-10-30 16:29:46 +00:00
>LDYA ZPDstTableOfs
jsr CS.RUN.GetSrcBufYA
bcs CS.RUN.RTS
>PUSHBI SEEK.SET
>PUSHWZ
>PUSHWZ
lda hSrcFile
>SYSCALL fseek
bcs CS.RUN.RTS
>PUSHW ZPDstTableOfs
>PUSHW ZPSrcBufPtr
lda hSrcFile
>SYSCALL fread
bcs CS.RUN.RTS
>PUSHW ZPDstTableOfs
>PUSHW ZPSrcBufPtr
lda hDstFile
>SYSCALL fwrite
bcs CS.RUN.RTS
jsr CS.QUIT.BUF
jsr CS.RUN.WriteTable Write Fake table
bcc CS.RUN.LOOP
CS.RUN.RTS rts
2019-10-16 15:23:29 +00:00
*--------------------------------------
CS.RUN.LOOP ldy #S.PS.hStdIn
lda (pPS),y
>SYSCALL feof
2019-10-30 16:29:46 +00:00
bcs CS.RUN.RTS
2019-10-16 15:23:29 +00:00
tay
bne .1
>SYSCALL GetChar
2019-10-30 16:29:46 +00:00
bcs CS.RUN.RTS
2019-10-16 15:23:29 +00:00
cmp #$03 Ctrl-C
2019-10-30 16:29:46 +00:00
beq CS.RUN.RTS Abort....
2019-10-16 15:23:29 +00:00
cmp #$13 Ctrl-S
bne .1
lda bPause
eor #$ff
sta bPause
bne CS.RUN.LOOP
.1 lda bPause
bne CS.RUN.LOOP Pause...
*--------------------------------------
2019-10-29 16:11:45 +00:00
jsr CS.RUN.GetChunk
2019-10-30 16:29:46 +00:00
bcs CS.RUN.RTS
2019-10-16 15:23:29 +00:00
2019-10-29 16:11:45 +00:00
>PUSHW ZPChunkLen
>PUSHW ZPChunkOfs
2019-10-30 16:29:46 +00:00
lda ZPChunkIndex
inc
>PUSHA
>PUSHBI 5
2019-10-29 14:47:25 +00:00
>LDYA L.MSG.CHUNK
>SYSCALL printf
2019-10-30 16:29:46 +00:00
bcs .9
2019-10-16 15:23:29 +00:00
2019-10-30 16:29:46 +00:00
jsr CS.RUN.Pak
2019-11-05 13:36:10 +00:00
bcs .2
2019-10-30 16:29:46 +00:00
jsr CS.RUN.WritePak
2019-11-05 13:36:10 +00:00
bcc .7
rts
.2 jsr CS.RUN.WriteStore
2019-10-30 16:29:46 +00:00
bcs .9
2019-11-05 13:36:10 +00:00
.7 jsr CS.QUIT.BUF
2019-10-30 16:29:46 +00:00
jsr CS.RUN.UpdateTable
inc ZPChunkIndex
2019-10-29 16:11:45 +00:00
dec ZPChunkCnt
beq .8
2019-10-30 16:29:46 +00:00
jmp CS.RUN.LOOP
2019-10-16 15:23:29 +00:00
2019-11-05 13:36:10 +00:00
.8 jsr CS.RUN.RewriteTable Write modified Table
2019-10-30 16:29:46 +00:00
bcs .9
lda #0
2019-10-16 15:23:29 +00:00
sec
2019-10-29 14:47:25 +00:00
.9 rts
2019-10-16 15:23:29 +00:00
*--------------------------------------
2019-10-29 14:47:25 +00:00
CS.RUN.CheckSrcFile
>PUSHWZ Aux type
>PUSHBI 0 Type
>PUSHBI O.RDONLY
lda #1
>SYSCALL ArgV
2019-10-16 15:23:29 +00:00
2019-10-29 14:47:25 +00:00
>SYSCALL FOpen
bcs .99
2019-10-16 15:23:29 +00:00
2019-10-29 14:47:25 +00:00
sta hSrcFile
2019-10-16 15:23:29 +00:00
2019-10-29 14:47:25 +00:00
>PUSHEA.G STATBUF
lda hSrcFile
>SYSCALL fstat
.99 bcs .9
2019-10-16 15:23:29 +00:00
2019-10-29 14:47:25 +00:00
>LDA.G STATBUF+S.STAT.SIZE+3
dey
ora (pData),y
bne .90
2019-10-16 15:23:29 +00:00
2019-10-29 14:47:25 +00:00
dey
lda (pData),y
sta ZPSrcFileSize+1
dey
lda (pData),y
sta ZPSrcFileSize
jsr CS.RUN.CheckTAG
2019-10-16 15:23:29 +00:00
bcs .9
2019-10-29 14:47:25 +00:00
jsr CS.RUN.GetTable
2019-10-16 15:23:29 +00:00
bcs .9
2019-10-29 14:47:25 +00:00
clc
rts
2019-10-16 15:23:29 +00:00
2019-10-29 14:47:25 +00:00
.90 lda #MLI.E.INCFF
2019-10-16 15:23:29 +00:00
sec
2019-10-29 14:47:25 +00:00
.9
CS.RUN.CheckSrcFile.RTS
rts
2019-10-16 15:23:29 +00:00
*--------------------------------------
2019-10-29 14:47:25 +00:00
CS.RUN.CheckTAG >PUSHBI SEEK.SET
>PUSHWZ
2019-10-16 15:23:29 +00:00
2019-10-29 14:47:25 +00:00
lda ZPSrcFileSize
2019-10-16 15:23:29 +00:00
sec
2019-10-29 14:47:25 +00:00
sbc #10
tay
lda ZPSrcFileSize+1
sbc #0
2019-10-16 15:23:29 +00:00
>PUSHYA
2019-10-29 14:47:25 +00:00
lda hSrcFile
>SYSCALL fseek
bcs CS.RUN.CheckSrcFile.RTS
2019-10-16 15:23:29 +00:00
2019-10-29 14:47:25 +00:00
>PUSHWI 10
>PUSHEA.G PAKME.HEADER
lda hSrcFile
2019-10-16 15:23:29 +00:00
>SYSCALL fread
2019-10-29 14:47:25 +00:00
bcs CS.RUN.CheckSrcFile.RTS
2019-10-16 15:23:29 +00:00
2019-10-29 14:47:25 +00:00
ldx #4
2019-10-16 15:23:29 +00:00
2019-10-29 14:47:25 +00:00
ldy #PAKME.HEADER+4
2019-10-16 15:23:29 +00:00
2019-10-29 14:47:25 +00:00
.1 lda TAG,x
cmp (pData),y
bne .90
2019-10-16 15:23:29 +00:00
dey
2019-10-29 14:47:25 +00:00
dex
bpl .1
2019-10-16 15:23:29 +00:00
clc
rts
2019-10-29 14:47:25 +00:00
.90 lda #MLI.E.INCFF
sec
2019-10-16 15:23:29 +00:00
.9 rts
*--------------------------------------
2019-10-30 16:29:46 +00:00
CS.RUN.GetTable >LDA.G PAKME.HEADER+8
2019-10-29 14:47:25 +00:00
sec
>SBC.G PAKME.HEADER+5
2019-10-30 16:29:46 +00:00
sta ZPDstTableOfs
2019-10-29 14:47:25 +00:00
>LDA.G PAKME.HEADER+9
>SBC.G PAKME.HEADER+6
2019-10-30 16:29:46 +00:00
sta ZPDstTableOfs+1
2019-10-30 18:25:04 +00:00
>PUSHBI SEEK.SET
>PUSHWZ
>PUSHW ZPDstTableOfs
lda hSrcFile
>SYSCALL fseek
2019-10-16 15:23:29 +00:00
bcs .9
2019-10-29 14:47:25 +00:00
>LDA.G PAKME.HEADER+7
sta ZPChunkCnt
2019-10-16 15:23:29 +00:00
2019-10-29 14:47:25 +00:00
asl
tay
lda #0
>PUSHYA
2019-10-16 15:23:29 +00:00
2019-10-29 14:47:25 +00:00
>PUSHEA.G PAKME.TABLE
lda hSrcFile
>SYSCALL fread
2019-10-16 15:23:29 +00:00
.9 rts
*--------------------------------------
2019-10-29 16:11:45 +00:00
CS.RUN.GetChunk lda ZPChunkIndex
asl
clc
adc #PAKME.TABLE+1
tay
lda (pData),y
pha
dey
lda (pData),y
sec
ldy #PAKME.HEADER+5
sbc (pData),y
sta ZPChunkOfs
iny
pla
sbc (pData),y
sta ZPChunkOfs+1
2019-10-30 16:29:46 +00:00
2019-10-29 16:11:45 +00:00
>PUSHBI SEEK.SET
>PUSHWZ
>PUSHW ZPChunkOfs
lda hSrcFile
>SYSCALL fseek
bcs .9
>PUSHWI 3
>PUSHEA.G CHUNK.HEADER
lda hSrcFile
>SYSCALL fread
bcs .9
>LDA.G CHUNK.HEADER
2019-10-30 16:29:46 +00:00
bne .90
2019-10-29 16:11:45 +00:00
>LDA.G CHUNK.HEADER+1
sta ZPChunkLen
2019-10-30 16:29:46 +00:00
pha
2019-10-29 16:11:45 +00:00
iny
lda (pData),y
sta ZPChunkLen+1
2019-10-30 16:29:46 +00:00
ply
2019-10-29 16:11:45 +00:00
2019-10-30 16:29:46 +00:00
jsr CS.RUN.GetSrcBufYA
bcs .9
>PUSHW ZPChunkLen
>PUSHW ZPSrcBufPtr
lda hSrcFile
>SYSCALL fread
bcs .9
* clc
2019-10-29 16:11:45 +00:00
rts
.90 lda #MLI.E.INCFF
sec
.9 rts
*--------------------------------------
2019-10-30 16:29:46 +00:00
CS.RUN.GetSrcBufYA
>SYSCALL getmem
bcs .9
stx hSrcBuf
>STYA ZPSrcBufPtr
.9 rts
*--------------------------------------
CS.RUN.Pak >LDYA ZPChunkLen
>SYSCALL getmem
bcs .9
stx hDstBuf
>STYA ZPDstBufPtr
>PUSHEA.G PAKSTAT
>PUSHW ZPDstBufPtr
>PUSHW ZPChunkLen
>PUSHW ZPSrcBufPtr
>LIBCALL hLIB,LIBPAK.Pak
bcs .9
>STYA ZPChunkPakedLen
.9 rts
*--------------------------------------
2019-10-30 18:25:04 +00:00
CS.RUN.RewriteTable
2019-10-30 16:29:46 +00:00
>PUSHBI SEEK.SET
>PUSHWZ
>PUSHW ZPDstTableOfs
2019-10-30 18:25:04 +00:00
lda hDstFile
2019-10-30 16:29:46 +00:00
>SYSCALL fseek
2019-10-30 18:25:04 +00:00
bcs CS.RUN.WriteTable.RTS
2019-10-30 16:29:46 +00:00
*--------------------------------------
CS.RUN.WriteTable
2019-10-30 18:25:04 +00:00
>LDA.G PAKME.HEADER+7
2019-10-30 16:29:46 +00:00
asl
tay
lda #0
>PUSHYA
>PUSHEA.G PAKME.TABLE
lda hDstFile
>SYSCALL fwrite
2019-10-30 18:25:04 +00:00
CS.RUN.WriteTable.RTS
2019-10-30 16:29:46 +00:00
rts
*--------------------------------------
CS.RUN.WritePak lda hDstFile
>SYSCALL ftell
bcs .9
>PULLW ZPChunkNewOfs
inc pStack
inc pStack
>PUSHW ZPChunkPakedLen
>PUSHW ZPDstBufPtr
lda hDstFile
>SYSCALL fwrite
2019-11-05 13:36:10 +00:00
bcs .9
>PUSHW ZPChunkNewOfs
>PUSHW ZPChunkPakedLen
>PUSHBI 4
>LDYA L.MSG.PAKED
>SYSCALL printf
.9
CS.RUN.WritePak.RTS
rts
*--------------------------------------
CS.RUN.WriteStore
lda hDstFile
>SYSCALL ftell
bcs CS.RUN.WritePak.RTS
>PULLW ZPChunkNewOfs
inc pStack
inc pStack
>PUSHWI 3
>PUSHEA.G CHUNK.HEADER
lda hDstFile
>SYSCALL fwrite
bcs .9
>PUSHW ZPChunkLen
>PUSHW ZPSrcBufPtr
lda hDstFile
>SYSCALL fwrite
bcs .9
>PUSHW ZPChunkNewOfs
>PUSHW ZPChunkLen
>PUSHBI 4
>LDYA L.MSG.STORE
>SYSCALL printf
2019-10-30 16:29:46 +00:00
.9 rts
*--------------------------------------
CS.RUN.UpdateTable
ldy #PAKME.HEADER+6
lda (pData),y
pha
dey
lda (pData),y
pha
lda ZPChunkIndex
asl
clc
adc #PAKME.TABLE
tay
2019-10-30 18:25:04 +00:00
2019-10-30 16:29:46 +00:00
pla
clc
adc ZPChunkNewOfs
sta (pData),y
iny
pla
adc ZPChunkNewOfs+1
sta (pData),y
rts
*--------------------------------------
2019-10-16 15:23:29 +00:00
CS.DOEVENT sec
rts
*--------------------------------------
2019-10-29 14:47:25 +00:00
CS.QUIT lda hDstFile
2019-10-16 15:23:29 +00:00
beq .2
2019-10-29 14:47:25 +00:00
>SYSCALL fclose
2019-10-16 15:23:29 +00:00
2019-10-29 14:47:25 +00:00
.2 lda hSrcFile
2019-10-16 15:23:29 +00:00
beq .3
>SYSCALL fclose
2019-10-30 16:29:46 +00:00
.3 jsr CS.QUIT.BUF
2019-10-16 15:23:29 +00:00
2019-10-30 16:29:46 +00:00
lda hLIB
2019-10-16 15:23:29 +00:00
beq .8
>SYSCALL UnloadLib
.8 clc
rts
*--------------------------------------
2019-10-30 16:29:46 +00:00
CS.QUIT.BUF lda hDstBuf
beq .1
stz hDstBuf
>SYSCALL FreeMem
.1 lda hSrcBuf
beq .8
stz hSrcBuf
>SYSCALL FreeMem
.8 rts
*--------------------------------------
2019-10-16 15:23:29 +00:00
CS.END
*--------------------------------------
MSG.USAGE .AZ "Usage : PAKME SourceBIN PackedBIN\r\n"
2019-10-30 16:29:46 +00:00
MSG.SRCFILE .AZ "Source File : %s, Size=%5D, Org=$%H, %d Chunks at $%H.\r\n"
MSG.CHUNK .AZ " Chunk #%02d : Ofs=$%H, Len=%5D ... "
MSG.PAKED .AZ "PAKed : %5D Bytes, New Ofs=$%H\r\n"
2019-11-05 13:36:10 +00:00
MSG.STORE .AZ "Store : %5D Bytes, New Ofs=$%H\r\n"
2019-10-16 15:23:29 +00:00
MSG.E.IARC .AZ "Invalid/corrupt archive"
2019-10-29 14:47:25 +00:00
TAG .AZ "PAKME"
2019-10-16 15:23:29 +00:00
*--------------------------------------
LIBPAK .AZ "libpak"
hLIB .BS 1
*--------------------------------------
.DUMMY
.OR 0
DS.START
2019-10-29 14:47:25 +00:00
STATBUF .BS S.STAT
PAKME.HEADER .BS 10
PAKME.TABLE .BS CHUNK.MAX*2
2019-10-29 16:11:45 +00:00
CHUNK.HEADER .BS 3
2019-10-16 15:23:29 +00:00
PAKSTAT .BS S.PAKSTAT
DS.END .ED
*--------------------------------------
MAN
SAVE USR/SRC/BIN/PAKME.S
ASM