diff --git a/cli/lz/build.sh b/cli/lz/build.sh new file mode 100755 index 0000000..2f0ae04 --- /dev/null +++ b/cli/lz/build.sh @@ -0,0 +1,21 @@ +#!/bin/sh -e + +LIN="uxncli $HOME/roms/uxnlin.rom" +ASM="uxncli $HOME/roms/drifblim.rom" + +if [[ "$*" == *"--lint"* ]] +then + $LIN decoder.tal + clang-format -i lz_main.c +fi + +# Make c file +cc lz_main.c -o main && ./main +./main # read example.txt, write compressed.bin + +$ASM decoder.tal decoder.rom +uxncli decoder.rom compressed.bin decompressed.txt + +rm ./main +rm ./compressed.bin +rm ./decompressed.txt diff --git a/cli/lz/decoder.tal b/cli/lz/decoder.tal index 2a626f6..cb24d11 100644 --- a/cli/lz/decoder.tal +++ b/cli/lz/decoder.tal @@ -25,9 +25,13 @@ @on-ready ( -> ) ;src decompress - ;mem pstr #0a18 DEO - ( debug ) #010e DEO - ( halt ) #010f DEO + ( ;mem pstr #0a18 DEO ) + ( debug #800e DEO ) + ( write ) + ;dst .File1/name DEO2 + ;mem .ptr LDZ2 SUB2 .File1/length DEO2 + ;mem .File1/write DEO2 + ( halt ) #800f DEO BRK diff --git a/cli/lz/explanation.md b/cli/lz/explanation.md index 63b40fa..116eb01 100644 --- a/cli/lz/explanation.md +++ b/cli/lz/explanation.md @@ -53,4 +53,67 @@ Dictionary ┌─────────────────┬── * Example: an offset of 0 means go back by 1 bytes into the history. * `a b c d e f|g` * Example: an offset of 5 means go back by 6 bytes into the history. - * `a|b c d e f g` \ No newline at end of file + * `a|b c d e f g` + + +22:56 < neauoire> how large do I make the dictionary? +22:57 < cancel> yeah. and the dictionary is just the + previous 256 bytes of the file. or, if you + haven't progressed through 256 bytes yet, + whatever you have +22:57 < cancel> so if you're 20 bytes into the file, your + dictionary is the 20 bytes you've already + processed +22:57 < cancel> if you're on the first byte of the file, + your dictionary size is 0 +22:57 < cancel> if you're on byte 500, the dictionary size + is 256 + +22:58 < cancel> if your dictionary size is 0, you're + definitely not gonna have a match +22:58 < cancel> if you don't have a match, you need to + emit the literal command + +22:58 < cancel> if your dictionary size is 0, you're + definitely not gonna have a match +22:58 < cancel> if you don't have a match, you need to + emit the literal command +22:58 < cancel> and then just slap some bytes down into + the output +22:58 < cancel> but... how many? +22:59 < neauoire> it's designed to be stream right? +22:59 < neauoire> mhmm maybe not +22:59 < cancel> yeah, but you have to write the size of + the literal first +22:59 < cancel> so... how big should the literal be? +22:59 < cancel> well, you don't know yet +23:00 < cancel> so, just write that the literal is 1 byte + long, and then put that first byte of the + file you were looking at for a match +23:01 < cancel> now, you're looking at the second byte of + the file +23:01 < cancel> repeat the process above +23:01 < cancel> your dictionary is now size 1 +23:01 < cancel> and it has that first character in it +23:01 < cancel> let's say your file is 'abcdefg' +23:01 < neauoire> yeah +23:01 < cancel> your dictionary is 'a' +23:01 < cancel> and the next character is 'b' +23:01 < cancel> well, there's no match in the dictionary. +23:02 < cancel> so you need to write a literal again... +23:02 < cancel> but the last thing you wrote was already a + literal +23:02 < cancel> so just combine it with the previous + literal + +23:03 < cancel> ok +23:03 < cancel> you can make a 'compressed' file that + doesn't actually compress +23:03 < cancel> it can just be all literals +23:03 < neauoire> it'll take me a while to even just + accomplish this bit +23:03 < cancel> it will be bigger than the original input +23:03 < neauoire> ah yes +23:03 < cancel> but it will still be a usable file for the + decompressor +23:03 < neauoire> let me try that \ No newline at end of file diff --git a/cli/lz/lz_main.c b/cli/lz/lz_main.c index 230a1e8..6237bcb 100644 --- a/cli/lz/lz_main.c +++ b/cli/lz/lz_main.c @@ -247,7 +247,6 @@ main(int argc, char *argv[]) break; } buffer[i] = c; - printf("%02x\n", c); } int res = uxn_lz_compress(my_byte_buffer, 1000000, &buffer, i); @@ -267,8 +266,6 @@ main(int argc, char *argv[]) printf("!!!%d -> %d\n", res, res2); - printf("%s\n", output2); - // return 0;