uxn-utils/cli/lz/ulzdec.tal

84 lines
1.6 KiB
Tal

( 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
@src $30
@dst $30
@ptr $1
|0100
@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 decode_ulz
( ;mem pstr #0a18 DEO )
( debug #800e DEO )
( write )
;dst .File/name DEO2
;mem .ptr LDZ2 SUB2 .File/length DEO2
;mem .File/write DEO2
( halt ) #800f DEO
BRK
@decode_ulz ( str* -- )
;mem .ptr STZ2
.File/name DEO2
&stream
#0001 .File/length DEO2
;&b
DUP2 .File/read DEO2
.File/success DEI2 ORA ?{ POP2 JMP2r }
[ LIT &b $1 ] decode_ulz_byte
!&stream
@decode_ulz_byte ( byte -- )
DUP #80 AND ?op-dict
@op-lit ( byte -- )
#00 SWP INC2
DUP2 .File/length DEO2
.ptr LDZ2
DUP2 .File/read DEO2
ADD2 .ptr STZ2
JMP2r
@op-dict ( byte )
#7f AND
DUP #40 AND ?&dict2
#00 SWP !do-copy
&dict2 ( byte -- )
#3f AND getc
@do-copy ( length* -- )
( +4 ) #0004 ADD2
( +1 ) getc INC
#00 SWP #0000 SWP2 SUB2 .ptr LDZ2 ADD2 STH2
#0000
&l
DUP2 STH2kr ADD2 LDA
.ptr LDZ2 STH2k STA
STH2r INC2 .ptr STZ2
INC2 GTH2k ?&l
POP2 POP2
POP2r
JMP2r
(
@|stdlib )
@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
@getc ( -- b ) #0001 .File/length DEO2 ;&b .File/read DEO2 [ LIT &b $1 ] JMP2r
@mem