From dabc6723aab9851af8ef08af312658c2c929f2dc Mon Sep 17 00:00:00 2001 From: neauoire Date: Sat, 18 Nov 2023 19:54:27 -0800 Subject: [PATCH] (lz) Housekeeping --- cli/lz/ulzenc.tal | 53 ++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/cli/lz/ulzenc.tal b/cli/lz/ulzenc.tal index b9166af..3a4e03d 100644 --- a/cli/lz/ulzenc.tal +++ b/cli/lz/ulzenc.tal @@ -38,7 +38,7 @@ #4000 .File/length DEO2 ;raw .File/read DEO2 ;raw .File/success DEI2 uxn_lz_compress - ( write ) + ( | write ) ;dst .File/name DEO2 .output-ptr LDZ2 ;compressed SUB2 .File/length DEO2 ;compressed .File/write DEO2 @@ -50,17 +50,14 @@ JMP2r @uxn_lz_compress ( input* length* -- ) - ( fill variables ) + ( | fill variables ) ;compressed .output-ptr STZ2 - - ADD2k NIP2 SWP2 &w ( end* start* -- ) EQU2k ?&end ( | get available dictionary size ) DUP2 ;raw SUB2 #0100 LTH2k ?{ SWP2 } POP2 .dict-len STZ2 - ( | size of the string to search for ) SUB2k #3fff #0004 ADD2 LTH2k ?{ SWP2 } POP2 ,&string-len STR2 @@ -69,29 +66,25 @@ DUP2 .dict-len LDZ2 SUB2 .dict STZ2 &for1 ( for ; dict_len; dict++, dict_len-- ) .dict-len LDZ2 #0000 EQU2 ?&end-for1 - ( Find common prefix length with the string ) #0000 &for2 ( for i = 0;; i++ ) - ( If we reach the end of the string, it's the best possible match. ) + ( | If we reach the end of the string, it's the best possible match. ) DUP2 [ LIT2 &string-len $2 ] NEQ2 ?{ DUP2 .match-len STZ2 .dict LDZ2 .dict-best STZ2 POP2 !&done-search } - - ( in[i] != dict[i % dict_len] break; ) + ( | in[i] != dict[i % dict_len] break; ) ( a ) ADD2k LDA STH ( b ) DUP2 .dict-len LDZ2 DIV2k MUL2 SUB2 .dict LDZ2 ADD2 LDA STHr NEQ ?&end-for2 INC2 ORAk ?&for2 &end-for2 - - ( i > match_len ) + ( | i > match_len ) DUP2 .match-len LDZ2 LTH2 ?{ DUP2 .match-len STZ2 .dict LDZ2 .dict-best STZ2 } POP2 - .dict LDZ2 INC2 .dict STZ2 .dict-len LDZ2 #0001 SUB2 .dict-len STZ2 !&for1 &end-for1 @@ -99,49 +92,47 @@ ( CPY ) .match-len LDZ2 #0003 GTH2 ?op-cpy ( LIT ) !op-lit &end - POP2 POP2 JMP2r - + POP2 POP2 + JMP2r ( @|opcodes ) @op-cpy ( in* -- ) - ( More numeric range: treat 0 as 4, 1 as 5, etc. ) + ( | More numeric range: treat 0 as 4, 1 as 5, etc. ) .match-len LDZ2 #0004 SUB2 .match-ctl STZ2 - ( CPY2 ) + ( | CPY2 ) .match-ctl LDZ2 #003f GTH2 ?&cpy2 - ( CPY1 ) - ( *output_ptr++ = match_ctl | 0x80; ) + ( | *output_ptr++ = match_ctl | 0x80; ) .match-ctl LDZ2 NIP #80 ORA !&cpy-resume - &cpy2 + &cpy2 ( -- ) .match-ctl LDZ2 - ( match_ctl >> 8 | 0xc0 ) SWP #c0 ORA - ( match_ctl ) - &cpy-resume - ( *output_ptr++ = in - dict_best - 1; ) + SWP #c0 ORA + &cpy-resume ( -- ) + ( | *output_ptr++ = in - dict_best - 1; ) DUP2 .dict-best LDZ2 SUB2 #0001 SUB2 NIP - ( in += match_len; Advance input by size of the match ) + ( | in += match_len; Advance input by size of the match ) .match-len LDZ2 ADD2 - ( Disable combining previous literal, if any ) + ( | Disable combining previous literal, if any ) #0000 .combine STZ2 !uxn_lz_compress/w @op-lit ( in* -- ) .combine LDZ2 ORA ?&combine - ( start a new literal ) - ( Store this address, and later use it to increment the literal size. ) - ( combine = output_ptr++; ) + ( | start a new literal ) + ( | Store this address, and later use it to increment the literal size. ) + ( | combine = output_ptr++; ) .output-ptr LDZ2 INC2k .output-ptr STZ2 .combine STZ2 - ( *combine = 0; ) + ( | *combine = 0; ) #00 .combine LDZ2 LDA2 STA - ( *output_ptr++ = *in++; ) + ( | *output_ptr++ = *in++; ) LDAk INC2 !uxn_lz_compress/w &combine ( -- ) - ( if ++*combine == 127 ) + ( | if ++*combine == 127 ) .combine LDZ2 LDA INC DUP #7f NEQ ?{ POP #00 } .combine LDZ2 STA LDAk