From 2d260e34fc4aac413ef0d9737645e6e0e9fb3a07 Mon Sep 17 00:00:00 2001 From: neauoire Date: Sat, 18 Nov 2023 19:45:01 -0800 Subject: [PATCH] (lz) Ported encoder --- cli/lz/build.sh | 2 ++ cli/lz/ulzenc.c | 4 ++-- cli/lz/ulzenc.tal | 16 +++++++++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/cli/lz/build.sh b/cli/lz/build.sh index c591569..363ba10 100755 --- a/cli/lz/build.sh +++ b/cli/lz/build.sh @@ -48,6 +48,8 @@ echo "" echo "================================" # ./ulzenc example.txt a.ulz +# ./ulzenc example.txt a.ulz +rm a.ulz uxncli ulzenc.rom example.txt a.ulz uxncli ~/roms/hx.rom a.ulz diff --git a/cli/lz/ulzenc.c b/cli/lz/ulzenc.c index f56f54f..695ddde 100644 --- a/cli/lz/ulzenc.c +++ b/cli/lz/ulzenc.c @@ -69,13 +69,13 @@ uxn_lz_compress(const void *input, int input_size) /* CPY */ if(match_len >= MinMatchLength) { + printf("*"); /* More numeric range: treat 0 as 4, 1 as 5, etc. */ match_ctl = match_len - MinMatchLength; /* CPY2 */ if(match_ctl > 0x3F) { *output_ptr++ = match_ctl >> 8 | 0xc0; /* High byte of the length, with both flags set */ - *output_ptr++ = match_ctl; /* Low byte of the length */ - /* CPY */ + *output_ptr++ = match_ctl; /* Low byte of the length */ } else *output_ptr++ = match_ctl | 0x80; /* offset(0 is -1, 1 is -2, ...) */ diff --git a/cli/lz/ulzenc.tal b/cli/lz/ulzenc.tal index 7922bc0..da56205 100644 --- a/cli/lz/ulzenc.tal +++ b/cli/lz/ulzenc.tal @@ -38,6 +38,10 @@ #4000 .File/length DEO2 ;raw .File/read DEO2 ;raw .File/success DEI2 uxn_lz_compress + ( write ) + ;dst .File/name DEO2 + .output-ptr LDZ2 ;compressed SUB2 .File/length DEO2 + ;compressed .File/write DEO2 ( halt ) #800f DEO BRK @@ -91,7 +95,7 @@ NEQ ?&end-for2 INC2 ORAk ?&for2 &end-for2 - + ( i > match_len ) DUP2 .match-len LDZ2 LTH2 ?{ DUP2 .match-len STZ2 @@ -112,20 +116,22 @@ @|opcodes ) @op-cpy ( in* -- ) - #2222 phex + LIT "* #18 DEO ( More numeric range: treat 0 as 4, 1 as 5, etc. ) .match-len LDZ2 #0004 SUB2 .match-ctl STZ2 ( CPY2 ) .match-ctl LDZ2 #003f GTH2 ?&cpy2 ( CPY1 ) ( *output_ptr++ = match_ctl | 0x80; ) - .match-ctl LDZ2 #0080 ORA2 + .match-ctl LDZ2 NIP #80 ORA !&cpy-resume &cpy2 - ( TODO ) + .match-ctl LDZ2 + ( match_ctl >> 8 | 0xc0 ) SWP #c0 ORA + ( match_ctl ) &cpy-resume ( *output_ptr++ = in - dict_best - 1; ) - DUP2 .dict-best LDZ2 #0001 SUB2 SUB2 + DUP2 .dict-best LDZ2 SUB2 #0001 SUB2 NIP ( in += match_len; Advance input by size of the match ) .match-len LDZ2 ADD2 ( Disable combining previous literal, if any )