(lz) Cleanup

This commit is contained in:
neauoire 2023-11-19 09:52:22 -08:00
parent f134a4a1c0
commit 08e3d61701
3 changed files with 69 additions and 50 deletions

View File

@ -20,6 +20,7 @@ cc ulzdec.c $DEBUG_flags -o ulzdec
cc ulzenc.c $DEBUG_flags -o ulzenc cc ulzenc.c $DEBUG_flags -o ulzenc
$ASM ulzdec.tal ulzdec.rom $ASM ulzdec.tal ulzdec.rom
$ASM ulzenc.tal ulzenc.rom $ASM ulzenc.tal ulzenc.rom
$ASM ulzdis.tal ulzdis.rom
if [[ "$*" == *"--install"* ]] if [[ "$*" == *"--install"* ]]
then then
@ -31,27 +32,26 @@ fi
# Make compressed file # Make compressed file
echo ""
echo "Encoder(C89):"
./ulzenc example.txt a.ulz ./ulzenc example.txt a.ulz
echo "Decoder(C89):"
./ulzdec a.ulz b.bin ./ulzdec a.ulz b.bin
echo "" echo "Result(C89):"
echo "c decoder:"
echo ""
cat b.bin cat b.bin
echo "" echo ""
echo ""
echo "uxn decoder:"
echo ""
uxncli ulzdec.rom a.ulz b.bin && cat b.bin
echo ""
echo ""
echo "================================" rm ./a.ulz
rm ./b.bin
# ./ulzenc example.txt a.ulz echo ""
# ./ulzenc example.txt a.ulz echo "Encoder(Uxn):"
rm a.ulz
uxncli ulzenc.rom example.txt a.ulz uxncli ulzenc.rom example.txt a.ulz
uxncli ulzdec.rom a.ulz b.bin && cat b.bin echo "Decoder(Uxn):"
uxncli ulzdec.rom a.ulz b.bin
echo "Result(Uxn):"
cat b.bin
echo ""
rm ./ulzdec rm ./ulzdec
rm ./ulzenc rm ./ulzenc

View File

@ -2,22 +2,34 @@
|10 @Console &vector $2 &read $1 &pad $5 &write $1 &err $1 |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 |a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|00 @src $30 @dst $30 @ptr $1 |00 @src $30
@dst $30
@ptr $1
|0100 |0100
@ready-src ( -> ) ;&await .Console/vector DEO2 BRK @ready-src ( -> )
&await ( -> ) .Console/read DEI .src skey ?ready-dst BRK ;&await .Console/vector DEO2
@ready-dst ( -> ) ;&await .Console/vector DEO2 BRK BRK
&await ( -> ) .Console/read DEI .dst skey ?on-ready 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 ( -> ) @on-ready ( -> )
;src decode_ulz ;src decode_ulz
( export ) ( export ) ;dst .File/name DEO2
;dst .File/name DEO2 ;mem DUP2 .ptr LDZ2 SUB2 .File/length DEO2
;mem .File/write DEO2
DUP2 .ptr LDZ2 SUB2 .File/length DEO2
.File/write DEO2
( halt ) #800f DEO ( halt ) #800f DEO
BRK BRK
@ -26,44 +38,52 @@
.File/name DEO2 .File/name DEO2
&stream ( -- ) &stream ( -- )
#0001 .File/length DEO2 #0001 .File/length DEO2
;&b ;&b DUP2 .File/read DEO2
DUP2 .File/read DEO2 .File/success DEI2 ORA ?{ POP2 JMP2r }
.File/success DEI2 ORA ?{ POP2 JMP2r } [ LIT &b $1 ] decode_ulz_byte !&stream
[ LIT &b $1 ] decode_ulz_byte
!&stream
@decode_ulz_byte ( byte -- ) @decode_ulz_byte ( byte -- )
DUP #80 AND ?op-cpy DUP #80 AND ?op-cpy
@op-lit ( byte -- ) @op-lit ( byte -- )
#00 SWP INC2 #00 SWP INC2 DUP2 .File/length DEO2
DUP2 .File/length DEO2 .ptr LDZ2 DUP2 .File/read DEO2
.ptr LDZ2 ADD2 .ptr STZ2
DUP2 .File/read DEO2
ADD2 .ptr STZ2
JMP2r JMP2r
@op-cpy ( byte -- ) @op-cpy ( byte -- )
#7f AND #7f AND DUP #40 AND ?{ #00 SWP !&copy }
DUP #40 AND ?{
#00 SWP !&copy }
#3f AND getc #3f AND getc
&copy ( length* -- ) &copy ( length* -- )
.ptr LDZ2 #00 getc INC2 SUB2 STH2 .ptr LDZ2 #00 getc INC2 SUB2 ,&offset STR2 #0004 ADD2 #0000
#0004 ADD2 #0000
&l ( -- ) &l ( -- )
( get ) DUP2 STH2kr ADD2 LDA ( get ) DUP2 [ LIT2 &offset $2 ] ADD2 LDA
( put ) .ptr LDZ2 STAk INC2 .ptr STZ2 POP ( put ) .ptr LDZ2 STAk INC2 .ptr STZ2
INC2 GTH2k ?&l POP INC2 GTH2k ?&l
POP2 POP2 POP2r POP2 POP2 JMP2r
JMP2r
( (
@|stdlib ) @|stdlib )
@skey ( key buf -- proc ) OVR #21 LTH ?&eval #00 SWP sput #00 JMP2r &eval POP2 #01 JMP2r @skey ( key buf -- proc )
@scap ( str* -- end* ) &w INC2 & LDAk ?&w JMP2r OVR #21 LTH ?&eval
@sput ( chr str* -- ) scap/ INC2k #00 ROT ROT STA STA JMP2r #00 SWP sput #00 JMP2r
@getc ( -- b ) #0001 .File/length DEO2 ;&b .File/read DEO2 [ LIT &b $1 ] JMP2r &eval POP2 #01 JMP2r
@scap ( str* -- end* )
&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 @mem

View File

@ -80,7 +80,6 @@
( res ) LDA STHr NEQ ?&end-for2 ( res ) LDA STHr NEQ ?&end-for2
INC2 ORAk ?&for2 INC2 ORAk ?&for2
&end-for2 ( | i > match_len ) &end-for2 ( | i > match_len )
DUP2 .match-len LDZ2 LTH2 ?{ DUP2 .match-len LDZ2 LTH2 ?{
DUP2 .match-len STZ2 DUP2 .match-len STZ2
.dict LDZ2 .dict-best STZ2 } .dict LDZ2 .dict-best STZ2 }