uxn-utils/cli/lz/decoder.tal

123 lines
2.0 KiB
Tal
Raw Normal View History

2023-02-06 18:54:12 -05:00
( decompressor )
|10 @Console &vector $2 &read $1 &pad $5 &write $1 &err $1
2023-11-14 23:30:09 -05:00
|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
2023-02-06 18:54:12 -05:00
|0000
@input-size $2
@src $30
@dst $30
@ptr $1
|0100
(
@|vectors )
@ready-src ( -> ) ;&await .Console/vector DEO2 BRK
&await ( -> ) .Console/read DEI .src skey ?ready-dst BRK
@ready-dst ( -> ) ;&await .Console/vector DEO2 BRK
&await ( -> ) .Console/read DEI .dst skey ?on-ready BRK
@on-ready ( -> )
;src decompress
2023-11-14 23:12:28 -05:00
( ;mem pstr #0a18 DEO )
( debug #800e DEO )
( write )
2023-11-14 23:30:09 -05:00
;dst .File/name DEO2
;mem .ptr LDZ2 SUB2 .File/length DEO2
;mem .File/write DEO2
2023-11-14 23:12:28 -05:00
( halt ) #800f DEO
2023-02-06 18:54:12 -05:00
BRK
@decompress ( str* -- )
;mem .ptr STZ2
2023-11-14 23:30:09 -05:00
.File/name DEO2
2023-02-06 18:54:12 -05:00
#0001 .input-size STZ2
&stream
2023-11-14 23:30:09 -05:00
.input-size LDZ2 .File/length DEO2
2023-02-06 18:54:12 -05:00
;&b
2023-11-14 23:30:09 -05:00
DUP2 .File/read DEO2
.File/success DEI2 #0000 EQU2 ?&eof
2023-02-06 18:54:12 -05:00
LDA decompress/run
2023-11-14 23:30:09 -05:00
.File/success DEI2 ORA ?&stream
2023-02-06 18:54:12 -05:00
JMP2r
2023-11-14 22:53:02 -05:00
&eof POP2 JMP2r
2023-02-06 18:54:12 -05:00
&b $1
&run ( byte -- )
DUP #80 AND ?&dict
( literal )
#00 SWP INC2 !do-literal
&dict ( byte -- )
#7f AND
DUP #40 AND ?&dict3
( 1 byte )
#00 SWP #0004 ADD2
( offset )
2023-11-14 23:30:09 -05:00
;&b .File/read DEO2
2023-02-06 18:54:12 -05:00
;&b LDA INC
!do-copy
&dict3 ( byte -- )
( hb )
#3f AND
( lb )
2023-11-14 23:30:09 -05:00
#0001 .File/length DEO2
;&b .File/read DEO2
2023-02-06 18:54:12 -05:00
;&b LDA #0004 ADD2
( offset )
2023-11-14 23:30:09 -05:00
;&b .File/read DEO2
2023-02-06 18:54:12 -05:00
;&b LDA INC
!do-copy
@do-copy ( length* offset -- )
#00 SWP #0000 SWP2 SUB2 .ptr LDZ2 ADD2 STH2
#0000
&l
DUP2 STH2kr ADD2 LDA do-append
INC2 GTH2k ?&l
POP2 POP2
POP2r
JMP2r
@do-append ( byte -- )
.ptr LDZ2 STH2k STA
STH2r INC2 .ptr STZ2
JMP2r
@do-literal ( length* -- )
2023-11-14 23:30:09 -05:00
DUP2 .File/length DEO2
2023-02-06 18:54:12 -05:00
.ptr LDZ2
2023-11-14 23:30:09 -05:00
DUP2 .File/read DEO2
2023-02-06 18:54:12 -05:00
ADD2 .ptr STZ2
JMP2r
(
@|stdlib )
@pstr ( str* -- ) LDAk ?&w POP2 JMP2r &w LDAk #18 DEO INC2 LDAk ?&w POP2 JMP2r
@skey ( key buf -- proc ) OVR #21 LTH ?&eval #00 SWP sput #00 JMP2r &eval POP2 #01 JMP2r
@scap ( str* -- end* ) LDAk ?&w JMP2r &w INC2 LDAk ?&w JMP2r
@sput ( chr str* -- ) scap INC2k #00 ROT ROT STA STA JMP2r
@mem