summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <Pixel>2002-05-25 05:35:07 +0000
committerPixel <Pixel>2002-05-25 05:35:07 +0000
commitc19473a09f0e7a0262a603faee0b0e50654c0bae (patch)
tree6ee80c696cd302d03b37a816915051b08f15c4a4
parent28374301bfd1f96490c1906cd239be05af062953 (diff)
Welcome to the DTE thing.
-rwxr-xr-xMakefile8
-rwxr-xr-xVP/map2sqr35
-rw-r--r--dte-asm.S70
-rw-r--r--dteutils.cpp101
4 files changed, 213 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 5a3134a..d741a4d 100755
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@
CPPFLAGS=-Wall -g -I. -O3 -mcpu=i686 -pedantic -pedantic-errors -Werror
CXX=g++
-TARGET = lz77 dlz77 yazedc cd-tool
+TARGET = lz77 dlz77 yazedc cd-tool dte-tool dte-tool-asm
all: ${TARGET}
@@ -19,5 +19,11 @@ yazedc: yazedc.cpp crctables crctable.out
cd-tool: cd-tool.cpp cdutils.cpp cdutils.h fileutils.cpp fileutils.h generic.cpp generic.h yazedc.cpp yazedc.h
${CXX} ${CPPFLAGS} ${LDFLAGAS} cd-tool.cpp cdutils.cpp fileutils.cpp yazedc.cpp generic.cpp -o cd-tool
+dte-tool-asm: dteutils.cpp generic.h generic.cpp fileutils.cpp fileutils.h dte-asm.S
+ ${CXX} ${CPPFLAGS} ${LDFLAGS} dteutils.cpp generic.cpp fileutils.cpp dte-asm.S -o dte-tool-asm -DUSEASM -DDTEMAIN
+
+dte-tool: dteutils.cpp generic.h generic.cpp fileutils.cpp fileutils.h
+ ${CXX} ${CPPFLAGS} ${LDFLAGS} dteutils.cpp generic.cpp fileutils.cpp -o dte-tool -DDTEMAIN
+
clean:
rm -f *.o ${TARGET} compil.c
diff --git a/VP/map2sqr b/VP/map2sqr
new file mode 100755
index 0000000..a5739a0
--- /dev/null
+++ b/VP/map2sqr
@@ -0,0 +1,35 @@
+#!/usr/bin/awk -f
+BEGIN {
+ ol = -1;
+}
+
+NR <= 4 {
+ print $0;
+}
+
+NR > 4 {
+ f = $1;
+ l = $2;
+ c = l - f + 1;
+ if ((ol + 1) != f) {
+ print "You blew it @ line", NR > "/dev/stderr"
+ exit -1;
+ }
+ ol = l;
+ print c;
+
+ d = $3;
+ print d;
+ d = $4;
+ print d;
+
+ for (i = 5; i <= NF; i++) {
+ $(i - 4) = $i;
+ }
+ NF -= 4;
+ print $0;
+}
+
+END {
+ print 0;
+}
diff --git a/dte-asm.S b/dte-asm.S
new file mode 100644
index 0000000..7fc9563
--- /dev/null
+++ b/dte-asm.S
@@ -0,0 +1,70 @@
+.text
+.align 4
+
+.global dte_reset
+.type dte_reset, @function
+
+dte_reset:
+ push %ecx
+ push %edi
+ movl $0x10000, %ecx
+ movl $dte_counters, %edi
+ xorl %eax, %eax
+ rep stosl
+ movl %eax, dte_counter
+ movl %eax, dte_most
+ pop %edi
+ pop %ecx
+ ret
+
+.global build_dte
+.type build_dte, @function
+
+build_dte:
+ push %eax
+ push %ebx
+ push %ecx
+ push %edx
+ push %esi
+ push %edi
+ movl dte_text_size, %ecx
+ movl dte_text, %esi
+ movl $dte_flags, %edi
+ movl $dte_counters, %ebx
+
+
+ lodsl
+ movl %eax, %edx
+
+ jmp innerjump
+
+loop:
+ lodsb
+ shrd $8, %eax, %edx
+
+innerjump:
+ push %edx
+
+ andl $0xffff, %edx
+ testb $0xff, (%edi, %edx)
+ jnz invalid
+ incl (%ebx, %edx, 4)
+ movl (%ebx, %edx, 4), %eax
+ cmpl %eax, dte_counter
+ ja invalid
+ movl %edx, dte_most
+ movl %eax, dte_counter
+
+invalid:
+ pop %edx
+
+ decl %ecx
+ jnz loop
+
+ pop %edi
+ pop %esi
+ pop %edx
+ pop %ecx
+ pop %ebx
+ pop %eax
+ ret
diff --git a/dteutils.cpp b/dteutils.cpp
new file mode 100644
index 0000000..0cbf30c
--- /dev/null
+++ b/dteutils.cpp
@@ -0,0 +1,101 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include "fileutils.h"
+
+char * dte_text;
+char dte_flags[256 * 256];
+long dte_counters[256 * 256];
+
+long dte_most;
+long dte_counter;
+long dte_text_size;
+int dte_size;
+long gain;
+
+#ifdef USEASM
+extern "C" {
+ void build_dte(void);
+ void dte_reset(void);
+}
+#else
+void dte_reset(void) {
+ memset(dte_counters, 0, 0x40000);
+ dte_most = 0;
+ dte_counter = 0;
+}
+
+void build_dte(void) {
+ int i;
+ unsigned short t;
+
+ for (i = 0; i < dte_text_size; i++) {
+ t = *((unsigned short *) (dte_text + i));
+ if (!dte_flags[t]) {
+ if ((++dte_counters[t]) > dte_counter) {
+ dte_most = t;
+ dte_counter = dte_counters[t];
+ }
+ }
+ }
+}
+#endif
+
+void dte_compress(char alloweds[]) {
+ int i, j;
+ char c1, c2;
+
+ for (i = 0; i < 256; i++) {
+ for (j = 0; j < 256; j++) {
+ dte_flags[i * 256 + j] = alloweds[i] ? alloweds[j] ? 0 : 1 : 1;
+ }
+ }
+
+ gain = 0;
+
+ fprintf(stderr, "Going for it: dte_size = %i\n", dte_size);
+ for (i = 0; i < dte_size; i++) {
+ dte_reset();
+ build_dte();
+ c1 = dte_most & 0xff;
+ c2 = dte_most >> 8;
+ fprintf(stderr, "Entry #%i, most count: %li, couple = 0x%04x = (%c %c)\n", i, dte_counter, (int) dte_most, c1, c2);
+ dte_flags[c1 + c2 * 256] = 1;
+ gain += dte_counter;
+ }
+
+ fprintf(stderr, "Total gain: %li bytes\n", gain);
+}
+
+
+#ifdef DTEMAIN
+
+int main(int argc, char ** argv) {
+ int i;
+ FILE * f;
+ char alloweds[256];
+
+ dte_size = 128;
+
+ f = fopen(argv[1], "r");
+ dte_text_size = filesize(f);
+ dte_text = (char *) calloc(dte_text_size + 4, 1);
+ fprintf(stderr, "Reading file, size = %li\n", dte_text_size);
+ fread(dte_text, 1, dte_text_size, f);
+ fclose(f);
+
+ memset(alloweds, 0, 256);
+ fprintf(stderr, "Building alloweds table\n");
+ for (i = 0; i < dte_text_size; i++) {
+ if ((dte_text[i] != '\n') && (dte_text[i] != '\r')) {
+ alloweds[dte_text[i]] = 1;
+ }
+ }
+
+ dte_compress(alloweds);
+
+ free(dte_text);
+}
+
+#endif