Cleaned up progress on encoder

This commit is contained in:
neauoire 2023-11-16 11:02:10 -08:00
parent 082b7386a5
commit 1859cd66a5
3 changed files with 39 additions and 12 deletions

View File

@ -12,6 +12,7 @@ then
$LIN decoder.tal
clang-format -i lz_main.c
clang-format -i ulzdec.c
clang-format -i ulzenc.c
fi
# Building
@ -30,8 +31,7 @@ $ASM ulzdec.tal ulzdec.rom
echo ""
echo "C Decoder"
echo ""
./ulzdec a.ulz b.bin
cat b.bin
./ulzdec a.ulz b.bin && cat b.bin
# Uxn Decoding
@ -47,6 +47,10 @@ echo "C Encoder"
echo ""
./ulzenc example.txt a.ulz
# Uxn Decoding
uxncli ulzdec.rom a.ulz b.bin && cat b.bin
# ./ulzdec a.ulz b.bin && cat b.bin
rm ./main
rm ./ulzdec
rm ./ulzenc

View File

@ -45,9 +45,8 @@
@op-cpy ( byte -- )
#7f AND
DUP #40 AND ?&long
#00 SWP !&copy
&long ( byte -- )
DUP #40 AND ?{
#00 SWP !&copy }
#3f AND getc
&copy ( length* -- )
.ptr LDZ2 #00 getc INC2 SUB2 STH2

View File

@ -10,13 +10,37 @@ error(const char *name, const char *msg)
return 0;
}
char *mem, *ptr;
char *ptr, *a, mem[0x10000];
int
get_lit(int i)
{
return 0;
}
int
encode_ulz(FILE *src)
{
int i, j, ptr = 0, length = 0;
a = malloc(0x10000);
/* load */
while(fread(a + length, 1, 1, src) && ++length) {}
/* encode */
for(i = 0; i < length; i++) {
/* try to make a CPY */
return 0;
/* try to make a LIT */
for(j = i; j - i < 127 && j < length; j++) {}
if(i != j) {
int litlen = j - i;
/* LIT */
mem[ptr++] = litlen;
/* LIT(body) */
for(j = i; j - i < litlen + 1; j++) mem[ptr++] = a[j];
}
i += j - 1;
}
return ptr - 1;
}
int
@ -33,7 +57,7 @@ main(int argc, char *argv[])
res = encode_ulz(src);
if(!(dst = fopen(argv[2], "wb")))
return !error("Invalid output file", argv[1]);
fwrite(mem, res, 1, dst);
fwrite(&mem, res, 1, dst);
printf("Compressed %s -> %s(%d bytes).\n", argv[1], argv[2], res);
return 0;
}