From 964d793199793cdaeabf0ae2ed9f0ecadc8d56a1 Mon Sep 17 00:00:00 2001 From: neauoire Date: Tue, 14 Nov 2023 20:30:09 -0800 Subject: [PATCH] Starting decoder --- cli/lz/build.sh | 14 ++++++++++ cli/lz/decoder.tal | 31 ++++++++++----------- cli/lz/encoder.tal | 58 +++++++++++++++++++++++++++++++++++++++ cli/lz/example-small.txt | 1 + cli/lz/recompressed.bin | Bin 0 -> 14 bytes cli/lz/redecoded.txt | Bin 0 -> 64956 bytes 6 files changed, 88 insertions(+), 16 deletions(-) create mode 100644 cli/lz/encoder.tal create mode 100644 cli/lz/example-small.txt create mode 100644 cli/lz/recompressed.bin create mode 100644 cli/lz/redecoded.txt diff --git a/cli/lz/build.sh b/cli/lz/build.sh index 2f0ae04..bd31f63 100755 --- a/cli/lz/build.sh +++ b/cli/lz/build.sh @@ -10,12 +10,26 @@ then fi # Make c file + cc lz_main.c -o main && ./main ./main # read example.txt, write compressed.bin +# Decoding + $ASM decoder.tal decoder.rom uxncli decoder.rom compressed.bin decompressed.txt rm ./main rm ./compressed.bin rm ./decompressed.txt + +# Encoding + +$ASM encoder.tal encoder.rom +uxncli encoder.rom example-small.txt recompressed.bin + +# Redecoding + +uxncli decoder.rom recompressed.bin redecoded.txt + +cat redecoded.txt diff --git a/cli/lz/decoder.tal b/cli/lz/decoder.tal index cb24d11..e950c06 100644 --- a/cli/lz/decoder.tal +++ b/cli/lz/decoder.tal @@ -1,8 +1,7 @@ ( decompressor ) |10 @Console &vector $2 &read $1 &pad $5 &write $1 &err $1 -|a0 @File1 &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 -|b0 @File2 &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 |0000 @@ -28,9 +27,9 @@ ( ;mem pstr #0a18 DEO ) ( debug #800e DEO ) ( write ) - ;dst .File1/name DEO2 - ;mem .ptr LDZ2 SUB2 .File1/length DEO2 - ;mem .File1/write DEO2 + ;dst .File/name DEO2 + ;mem .ptr LDZ2 SUB2 .File/length DEO2 + ;mem .File/write DEO2 ( halt ) #800f DEO BRK @@ -38,15 +37,15 @@ BRK @decompress ( str* -- ) ;mem .ptr STZ2 - .File1/name DEO2 + .File/name DEO2 #0001 .input-size STZ2 &stream - .input-size LDZ2 .File1/length DEO2 + .input-size LDZ2 .File/length DEO2 ;&b - DUP2 .File1/read DEO2 - .File1/success DEI2 #0000 EQU2 ?&eof + DUP2 .File/read DEO2 + .File/success DEI2 #0000 EQU2 ?&eof LDA decompress/run - .File1/success DEI2 ORA ?&stream + .File/success DEI2 ORA ?&stream JMP2r &eof POP2 JMP2r @@ -65,7 +64,7 @@ JMP2r ( 1 byte ) #00 SWP #0004 ADD2 ( offset ) - ;&b .File1/read DEO2 + ;&b .File/read DEO2 ;&b LDA INC !do-copy @@ -75,11 +74,11 @@ JMP2r ( hb ) #3f AND ( lb ) - #0001 .File1/length DEO2 - ;&b .File1/read DEO2 + #0001 .File/length DEO2 + ;&b .File/read DEO2 ;&b LDA #0004 ADD2 ( offset ) - ;&b .File1/read DEO2 + ;&b .File/read DEO2 ;&b LDA INC !do-copy @@ -105,9 +104,9 @@ JMP2r @do-literal ( length* -- ) - DUP2 .File1/length DEO2 + DUP2 .File/length DEO2 .ptr LDZ2 - DUP2 .File1/read DEO2 + DUP2 .File/read DEO2 ADD2 .ptr STZ2 JMP2r diff --git a/cli/lz/encoder.tal b/cli/lz/encoder.tal new file mode 100644 index 0000000..b2b0ed2 --- /dev/null +++ b/cli/lz/encoder.tal @@ -0,0 +1,58 @@ +( 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 diff --git a/cli/lz/example-small.txt b/cli/lz/example-small.txt new file mode 100644 index 0000000..0373d93 --- /dev/null +++ b/cli/lz/example-small.txt @@ -0,0 +1 @@ +abcdef diff --git a/cli/lz/recompressed.bin b/cli/lz/recompressed.bin new file mode 100644 index 0000000000000000000000000000000000000000..611cd5ed31c2c4cf011b2113471f77fbf2063618 GIT binary patch literal 14 VcmZQbWJqF2W=LU3Wk_S-0ss=70$>0D literal 0 HcmV?d00001 diff --git a/cli/lz/redecoded.txt b/cli/lz/redecoded.txt new file mode 100644 index 0000000000000000000000000000000000000000..e85ef19bc91fb5d61a5a6ecd7cbe5cd96d98f077 GIT binary patch literal 64956 zcmeIuK@k8T2mmnOv{Zrq5y-*a7Gd}Otd4^L0|pEjFkrxd0RsjM7%*VKfB^#r3>YwA zz<>b*1`HT5V8DO@0|pEjFkrxd0RsjM7%*VKfB^#r3>YwAz<>b*1`HT5V8DO@0|pEj zFkrxd0RsjM7%*VKfB^#r3>YwAz<>b*1`HT5V8DO@0|pEjFkrxd0RsjM7%*VKfB^#r z3>YwAz<>b*1`HT5V8DO@0|pEjFkrxd0RsjM7%*VKfB^#r3>YwAz<>b*1`HT5V8DO@ z0|pEjFkrxd0RsjM7%*VKfB^#r3>YwAz<>b*1`HT5V8DO@0|pEjFkrxd0RsjM7%*VK zfB^#r3>YwAz<>b*1`HT5V8DO@0|pEjFkrxd0RsjM7%*VKfB^#r3>YwAz<>b*y9Wll Cqyk_7 literal 0 HcmV?d00001