A2osX/BIN/UNPAK.S.txt

457 lines
8.7 KiB
Plaintext
Raw Normal View History

NEW
2019-04-10 07:45:09 +00:00
AUTO 3,1
.LIST OFF
.OP 65C02
.OR $2000
2019-04-10 07:45:09 +00:00
.TF ROOT/UNPAK
*--------------------------------------
2018-07-23 15:28:42 +00:00
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/LIBPAK.I
*--------------------------------------
2018-02-09 16:02:47 +00:00
ZPPakHdrPtr .EQ ZPBIN
ZPPakDataPtr .EQ ZPBIN+2
ZPPakSrcPtr .EQ ZPBIN+4
*--------------------------------------
UNPAK.Mask .EQ ZPBIN+8
UNPAK.LastByte .EQ ZPBIN+9
UNPAK.Cnt .EQ ZPBIN+10
UNPAK.Ofs .EQ ZPBIN+12
UNPAK.BLOfs .EQ ZPBIN+14
*--------------------------------------
* 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
2018-02-09 16:02:47 +00:00
.DA #16 ZP
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
2018-02-05 16:25:25 +00:00
L.LIBPAK .DA LIBPAK
2018-08-23 15:16:20 +00:00
L.CONST.PI .DA CONST.PI
L.CONST.3 .DA CONST.3
2017-10-27 14:56:46 +00:00
L.MSG1 .DA MSG1
L.MSG2 .DA MSG2
L.MSG3 .DA MSG3
L.MSG4 .DA MSG4
L.MSG5 .DA MSG5
2018-02-05 16:25:25 +00:00
L.MSG6 .DA MSG6
2018-02-09 16:02:47 +00:00
L.MSG.UnpakErr .DA MSG.UnpakErr
L.MSG.DEBUG.S3 .DA MSG.DEBUG.S3
.DA 0
*--------------------------------------
2018-02-05 16:25:25 +00:00
CS.INIT >LDYA L.LIBPAK
2018-07-19 15:33:55 +00:00
>SYSCALL LoadLib
2018-02-05 16:25:25 +00:00
bcs .9
sta hLIBPAK
clc
.9 rts
*--------------------------------------
CS.RUN ldy #S.PS.ARGC
lda (pPs),y
bne CS.RUN.Pak
jmp CS.RUN.Math
*--------------------------------------
2019-06-07 15:02:51 +00:00
CS.RUN.Pak >PUSHWZ Aux type
2018-02-05 16:25:25 +00:00
>PUSHBI 0
2018-10-02 15:52:30 +00:00
>PUSHBI O.RDONLY
2018-02-05 16:25:25 +00:00
lda #1
2018-10-16 15:48:03 +00:00
>SYSCALL ArgV
2018-07-18 15:30:42 +00:00
>SYSCALL RealPath
2018-02-05 16:25:25 +00:00
>PUSHYA
txa
>STA.G PAK.hFileName
>SYSCALL LoadFile
bcs .9
>STYA.G PAK.FileSize
txa
>STA.G PAK.hFileBuf
>LDYA.G PAK.FileSize
2018-07-20 11:51:08 +00:00
>SYSCALL getmem
2018-02-05 16:25:25 +00:00
bcs .9
2018-02-09 16:02:47 +00:00
>STYA ZPPakSrcPtr
2018-02-05 16:25:25 +00:00
txa
>STA.G PAK.hOutBuf
>LDA.G PAK.hFileBuf
2018-07-18 15:30:42 +00:00
>SYSCALL GetMemPtr
2018-02-05 16:25:25 +00:00
>PUSHYA
>PUSHW.G PAK.FileSize
>LDA.G PAK.hOutBuf
2018-07-18 15:30:42 +00:00
>SYSCALL GetMemPtr
2018-02-09 16:02:47 +00:00
>STYA ZPPakHdrPtr
2018-02-05 16:25:25 +00:00
>PUSHYA
>PUSHEA.G PAK.Stat
>LIBCALL hLIBPAK,LIBPAK.Pak
bcc .1
.9 rts
.1 >PUSHW.G PAK.Stat+S.PAKSTAT.STORE
>PUSHW.G PAK.Stat+S.PAKSTAT.S4
>PUSHW.G PAK.Stat+S.PAKSTAT.S3
>PUSHW.G PAK.Stat+S.PAKSTAT.REP
>PUSHW.G PAK.Stat+S.PAKSTAT.BL
2018-02-08 16:39:56 +00:00
>PUSHW.G PAK.Stat+S.PAKSTAT.PASS2
>PUSHW.G PAK.Stat+S.PAKSTAT.PASS1
2018-02-05 16:25:25 +00:00
>PUSHW.G PAK.FileSize
2018-08-23 15:16:20 +00:00
>PUSHBI 16
2018-02-05 16:25:25 +00:00
>LDYA L.MSG6
2018-06-21 15:12:10 +00:00
>SYSCALL printf
2018-02-09 16:02:47 +00:00
*--------------------------------------
CS.RUN.Unpak lda ZPPakHdrPtr
clc
adc #S.PAKSTAT
sta ZPPakDataPtr
lda ZPPakHdrPtr+1
adc /S.PAKSTAT
sta ZPPakDataPtr+1
lda (ZPPakHdrPtr)
eor #$ff
sta UNPAK.Cnt
2018-02-05 16:25:25 +00:00
2018-02-09 16:02:47 +00:00
ldy #1
lda (ZPPakHdrPtr),y
eor #$ff
sta UNPAK.Cnt+1
lda #$80
sta UNPAK.Mask
>LDA.G PAK.hFileBuf
2018-07-18 15:30:42 +00:00
>SYSCALL GetMemPtr
2018-02-09 16:02:47 +00:00
>STYA ZPPakSrcPtr
stz UNPAK.Ofs
stz UNPAK.Ofs+1
.1 inc UNPAK.Cnt
bne .2
inc UNPAK.Cnt+1
bne .2
lda #0
sec
rts
.2 lda #'>'
2018-07-18 15:30:42 +00:00
>SYSCALL PutChar
2018-02-09 16:02:47 +00:00
jsr CS.RUN.UnpakGetBitInC
bcs .3
*--------------------------------------
* SHORT3
ldx #3
jsr CS.RUN.UnpakGetXBitInA
clc
adc #S.PAKHDR.SHORT3
tay
lda (ZPPakHdrPtr),y
sta UNPAK.LastByte
jsr DEBUG.S3
jsr CS.RUN.UnpakCmpA
bcs .9
bra .1
.3 jsr CS.RUN.UnpakGetBitInC
bcs .4
*--------------------------------------
* SHORT4
ldx #4
jsr CS.RUN.UnpakGetXBitInA
clc
adc #S.PAKHDR.SHORT4
tay
lda (ZPPakHdrPtr),y
sta UNPAK.LastByte
jsr CS.RUN.UnpakCmpA
bcs .9
bra .1
.4 jsr CS.RUN.UnpakGetBitInC
bcs .5
*--------------------------------------
* REPn
ldx #4
jsr CS.RUN.UnpakGetXBitInA
tay
tax
lda UNPAK.LastByte
.41 jsr CS.RUN.UnpakCmpA
bcs .9
dey
bne .41
.42 txa
clc
adc UNPAK.Cnt
sta UNPAK.Cnt
bcc .2
inc UNPAK.Cnt+1
bra .2
.5 jsr CS.RUN.UnpakGetBitInC
bcs .6
*--------------------------------------
* BACKLINK
ldx #4
jsr CS.RUN.UnpakGetXBitInA
sta UNPAK.BLOfs+1
jsr CS.RUN.UnpakGetByteInA
sta UNPAK.BLOfs
jsr CS.RUN.UnpakGetByteInA
tax
tay
.51
bra .42
*--------------------------------------
* STOREn
.6 ldx #4
jsr CS.RUN.UnpakGetXBitInA
tay
tax
.61 jsr CS.RUN.UnpakGetByteInA
dey
bne .61
sta UNPAK.LastByte
bra .42
.9 >PUSHW UNPAK.Ofs
2018-08-23 15:16:20 +00:00
>PUSHBI 2
2018-02-09 16:02:47 +00:00
>LDYA L.MSG.UnpakErr
2018-06-21 15:12:10 +00:00
>SYSCALL printf
2018-02-09 16:02:47 +00:00
2018-02-05 16:25:25 +00:00
lda #0
sec
2018-02-09 16:02:47 +00:00
rts
*--------------------------------------
CS.RUN.UnpakGetByteInA
ldx #8
*--------------------------------------
CS.RUN.UnpakGetXBitInA
lda #0
.1 jsr CS.RUN.UnpakGetBitInC
rol
dex
bne .1
rts
*--------------------------------------
CS.RUN.UnpakGetBitInC
pha
clc
lda (ZPPakDataPtr)
and UNPAK.Mask
beq .1
sec
.1 php
lsr UNPAK.Mask
bne .8
lda #$80
sta UNPAK.Mask
inc ZPPakDataPtr
bne .8
inc ZPPakDataPtr+1
.8 plp
pla
rts
*--------------------------------------
CS.RUN.UnpakCmpA
cmp (ZPPakSrcPtr)
bne .9
inc ZPPakSrcPtr
bne .1
inc ZPPakSrcPtr+1
.1 inc UNPAK.Ofs
bne .8
inc UNPAK.Ofs+1
.8 clc
rts
.9 sec
rts
*--------------------------------------
DEBUG.S3 pha
phx
phy
>PUSHA
2018-08-23 15:16:20 +00:00
>PUSHBI 1
2018-02-09 16:02:47 +00:00
>LDYA L.MSG.DEBUG.S3
2018-06-21 15:12:10 +00:00
>SYSCALL printf
2018-02-09 16:02:47 +00:00
ply
plx
pla
rts
*--------------------------------------
2018-02-05 16:25:25 +00:00
CS.RUN.Math >PUSHEA.G ENDPTR
2018-08-23 15:16:20 +00:00
>LDYA L.CONST.PI
>SYSCALL StrToF
2018-08-23 15:16:20 +00:00
>PULLF.G MYFLOAT.PI
>PUSHEA.G ENDPTR
2018-08-23 15:16:20 +00:00
>LDYA L.CONST.3
>SYSCALL StrToF
2018-08-23 15:16:20 +00:00
>PULLF.G MYFLOAT.3
>PUSHF.G MYFLOAT.PI
>PUSHF.G MYFLOAT.3
2018-08-23 15:16:20 +00:00
>PUSHF FLOAT5
>PUSHF FLOAT4
>PUSHF FLOAT3
>PUSHF FLOAT2
>PUSHF FLOAT1
2018-08-23 15:16:20 +00:00
>PUSHBI 35
>LDYA L.MSG1
2018-06-21 15:12:10 +00:00
>SYSCALL printf
*--------------------------------------
2018-08-23 15:16:20 +00:00
>PUSHF.G MYFLOAT.PI
>PUSHF.G MYFLOAT.3
>SYSCALL FDiv
2018-08-23 15:16:20 +00:00
>PULLF.G MYFLOAT3
2017-10-27 14:56:46 +00:00
2018-08-23 15:16:20 +00:00
>PUSHF.G MYFLOAT3
>PUSHBI 5
>LDYA L.MSG2
2018-06-21 15:12:10 +00:00
>SYSCALL printf
*--------------------------------------
2018-08-23 15:16:20 +00:00
>PUSHF.G MYFLOAT3
>SYSCALL Cos
2018-08-23 15:16:20 +00:00
>PULLF.G MYFLOAT3
>PUSHF.G MYFLOAT3
>PUSHBI 5
>LDYA L.MSG3
2018-06-21 15:12:10 +00:00
>SYSCALL printf
*--------------------------------------
2018-08-23 15:16:20 +00:00
>PUSHF FLOAT1
>SYSCALL LRIntF
2018-08-23 15:16:20 +00:00
>PULLL.G MYLONG
>PUSHL.G MYLONG
>PUSHBI 4
>LDYA L.MSG4
2018-06-21 15:12:10 +00:00
>SYSCALL printf
*--------------------------------------
2018-08-23 15:16:20 +00:00
>PUSHL LONG1
>SYSCALL Float
2018-08-23 15:16:20 +00:00
* >PULLF.G MYFLOAT3
* >PUSHF.G MYFLOAT3
>PUSHBI 5
>LDYA L.MSG5
2018-06-21 15:12:10 +00:00
>SYSCALL printf
lda #0
sec
2017-10-27 14:56:46 +00:00
rts
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
2018-02-05 16:25:25 +00:00
CS.QUIT >LDA.G PAK.hFileName
beq .1
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
2018-02-05 16:25:25 +00:00
.1 >LDA.G PAK.hFileBuf
beq .2
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
2018-02-05 16:25:25 +00:00
.2 >LDA.G PAK.hOutBuf
beq .8
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
2018-02-05 16:25:25 +00:00
.8 lda hLIBPAK
2018-07-20 14:10:10 +00:00
>SYSCALL UnloadLib
2018-02-05 16:25:25 +00:00
clc
rts
*--------------------------------------
CS.END
2018-02-05 16:25:25 +00:00
LIBPAK .AZ "libpak.o"
hLIBPAK .BS 1
2018-08-24 10:20:23 +00:00
MSG1 .AS "PrintF:\r\n"
.AS " %e, %e, %e, %e, %e\r\n"
.AS "StrToF:\r\n"
.AZ " %e, %e\r\n"
2018-08-23 15:16:20 +00:00
MSG2 .AZ "PI/3=%e\r\n"
MSG3 .AZ "COS(PI/3)=%e\r\n"
2018-08-24 10:20:23 +00:00
MSG4 .AZ "LRIntF(99,999,999.9)=%L\r\n"
MSG5 .AZ "Float(123456789)=%e\r\n"
2018-08-23 15:16:20 +00:00
CONST.PI .AZ "3.141592653"
CONST.3 .AZ "3"
FLOAT1 .HS 9B3EBC1FFD 99,999,999.9
FLOAT2 .HS 9E6E6B27FD 999,999,999
FLOAT3 .HS 9E6E6B2800 1,000,000,000
FLOAT4 .HS 8100000000 1
FLOAT5 .HS 9080000000 -32768
LONG1 .DA >123456789
2018-08-23 15:16:20 +00:00
*--------------------------------------
2018-02-05 16:25:25 +00:00
MSG6 .AS "Src Length : %D\r\n"
2018-02-08 16:39:56 +00:00
.AS "Pass #1 : %D\r\n"
.AS "Pass #2 : %D\r\n"
2018-02-05 16:25:25 +00:00
.AS "BL Count : %D\r\n"
.AS "REP Count : %D\r\n"
.AS "S3 Count : %D\r\n"
.AS "S4 Count : %D\r\n"
.AZ "STO Count : %D\r\n"
2018-02-09 16:02:47 +00:00
MSG.UnpakErr .AZ "UnPak Error at Offset : %H\r\n"
MSG.DEBUG.S3 .AZ "S3:%h\r\n"
*--------------------------------------
.DUMMY
.OR 0
DS.START
2018-08-23 15:16:20 +00:00
MYFLOAT.PI .BS 5
MYFLOAT.3 .BS 5
2017-10-27 14:56:46 +00:00
MYFLOAT3 .BS 5
MYLONG .BS 4
ENDPTR .BS 2
2018-02-05 16:25:25 +00:00
PAK.hFileName .BS 1
PAK.FileSize .BS 2
PAK.hFileBuf .BS 1
PAK.hOutBuf .BS 1
PAK.Stat .BS S.PAKSTAT
DS.END
.ED
*--------------------------------------
MAN
2019-04-10 07:45:09 +00:00
SAVE BIN/UNPAK.S
ASM