uxn-utils/cli/lz/encoder.tal

59 lines
1.2 KiB
Tal
Raw Normal View History

2023-11-14 23:30:09 -05:00
( decompressor )
|10 @Console &vector $2 &read $1 &pad $5 &write $1 &err $1
|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|0000
@input-length $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 .File/name DEO2
#1000 .File/length DEO2
;history .File/read DEO2
.File/success DEI2 .input-length STZ2
;history pstr #0a18 DEO
( make a file full of literals )
;dst .File/name DEO2
#0002 .File/length DEO2
( make a bunch of literals )
.input-length LDZ2 #0000
&l ( -- )
DUP2 ;history ADD2 LDA ,&b STR
;&literal .File/write DEO2
INC2 GTH2k ?&l
POP2
( halt ) #800f DEO
BRK
&literal 00 &b
(
@|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
@history $1000
@mem