summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FAQ-cd.txt (renamed from FAQ.cd)0
-rw-r--r--generic.h3
-rw-r--r--lz77.cpp81
-rw-r--r--lz77.h3
4 files changed, 57 insertions, 30 deletions
diff --git a/FAQ.cd b/FAQ-cd.txt
index 4a3a92b..4a3a92b 100644
--- a/FAQ.cd
+++ b/FAQ-cd.txt
diff --git a/generic.h b/generic.h
index 08fb7eb..2798235 100644
--- a/generic.h
+++ b/generic.h
@@ -30,6 +30,9 @@
#define bcopy(x,y,z) memcpy((y),(x),(z))
#endif
+#define MIN(a,b) ((a)<(b)?(a):(b))
+#define MAX(a,b) ((a)<(b)?(b):(a)
+
extern char verbosity;
void printm(int level, char * fmt, ...);
char ** split(char * s, char t);
diff --git a/lz77.cpp b/lz77.cpp
index 8497868..10423d4 100644
--- a/lz77.cpp
+++ b/lz77.cpp
@@ -32,18 +32,18 @@ int tolerate = 1;
int blockb = 0;
scheme_t schemes[] = {
-/* Nom 1 I J O N 16 Op F Lm1 Ls1 Lm2 Ls2 Jm1 Js1 Jm2 Js2 Fm1 Fs1 Fm2 Fs2 Vm1 Vs1 Vm2 Vs2 */
- {"Xenogears", 1, 0, 0, 1, 0, 0, 0, 0, 0x00, 0, 0xf0, -4, 0xff, 0, 0x0f, 8, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0},
- {"DBZ RPG", 0, 0, 0, 0, 0, 0, 0, 0, 0x0f, 0, 0x00, 0, 0xf0, -4, 0xff, 4, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0},
- {"FF7", 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0, 0x0f, 0, 0xff, 0, 0xf0, 4, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0},
- {"Leen Mean", 1, 1, 1, 1, 0, 0, 0, 0, 0x0f, 0, 0x00, 0, 0xf0, 4, 0xff, 0, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0},
- {"Metal Max", 0, 0, 0,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 0x00, 0, 0x0f, 0, 0xff, 0, 0xf0, 4, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0},
+ {"Leen Mean", 1, 1, 1, 1, 0, 0, 0, 0, 0, 0x0f, 0, 0x00, 0, 0xf0, 4, 0xff, 0, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0},
+ {"Metal Max", 0, 0, 0, 1, 0, 0, 2, 0, 0x12, 0x00, 0, 0x0f, 0, 0xff, 0, 0xf0, 4, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0},
+ {"Ogre Battle", 0, 0, 0, 1, 0, 0, 1, 0, 0, 0xf8, -3, 0x00, 0, 0x07, 8, 0xff, 0, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0},
+ {"Lodoss Wars", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0, 0x7f, 0, 0xff, 0, 0x80, 1, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0},
+ {"FF6 PSX", 0, 0, 0, 1, 1, 1, 0, 0, 0, 0x1f, 1, 0x00, 0, 0xe0, -4, 0xff, 4, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0},
+ {"Valkyrie-1", 0, 0, 0, 1, 1, 0, 0, 0, 0, 0x00, 0, 0xf0, -4, 0xff, 0, 0x0f, 8, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0},
+ {"Valkyrie-2", 0, 0, 0, 1, 1, 0, 0, 2, 0, 0x00, 0, 0xf0, -4, 0xff, 0, 0x0f, 8, 0x00, 0, 0x0f, 0, 0xff, 0, 0x00, 0},
+ {0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0}
};
scheme_t scheme = schemes[0];
@@ -107,7 +107,7 @@ unsigned long lz77_decomp(FILE * f_source, FILE * f_cible, long true_length)
int decomp_length;
int decomp_fill;
int decomp_jump;
- int decomp_offset;
+ int decomp_offset = 0;
int loop_length;
int whole_count;
int i, j;
@@ -185,10 +185,16 @@ unsigned long lz77_decomp(FILE * f_source, FILE * f_cible, long true_length)
if (blockb)
whole_count++;
} else {
- if (scheme.opposite) {
- decomp_offset = r - lz77_maxptr - 1 + decomp_jump;
- } else {
+ switch (scheme.ptrb) {
+ case 0:
decomp_offset = r - decomp_jump;
+ break;
+ case 1:
+ decomp_offset = r - lz77_maxptr - 1 + decomp_jump;
+ break;
+ case 2:
+ decomp_offset = decomp_jump - scheme.window_start;
+ break;
}
loop_length = decomp_offset + decomp_length;
if ((loop_length >= r) && (!overlap_error)) {
@@ -311,6 +317,10 @@ unsigned char * lz77_memcomp(unsigned char * r, long * l, long * delta) {
farest = ptr - lz77_maxptr;
farest = farest > ((-lz77_maxsize) * scheme.negative_trick) ? farest : -lz77_maxsize * scheme.negative_trick;
needle_length = ptr - farest;
+ if (scheme.ptrb == 2) {
+ farest = 0;
+ needle_length = MIN(lz77_maxptr - scheme.window_start, ptr);
+ }
needle = lz77_comp_strstr(&r[ptr], r, &needle_length, farest);
if ((needle < 0) && ((-needle) > needle_length)) {
needle = -needle_length;
@@ -329,7 +339,7 @@ unsigned char * lz77_memcomp(unsigned char * r, long * l, long * delta) {
printm(M_INFO, " Found a needle of %i bytes at offset %i (jump = %i = 0x%04x)\n", needle_length, needle, jump, jump);
}
- if ((needle_length <= (2 + scheme.sixteen_bits)) || (jump > lz77_maxptr) || (!jump)) {
+ if ((needle_length <= (2 + scheme.sixteen_bits)) || (!jump)) {
if (needle_length > 2) {
printm(M_ERROR, " ** REJECTED **\n");
}
@@ -344,17 +354,24 @@ unsigned char * lz77_memcomp(unsigned char * r, long * l, long * delta) {
int j;
printm(M_INFO, " Found a needle of %li bytes at %li = 0x%04x\n", needle_length, needle, needle);
for (j = 0; j < needle_length; j++) {
- printm(M_INFO, "@0x%04x: 0x%02x - @0x%04x: 0x%02x\n", needle + j, lz77_rd(r, needle + j), ptr + j, lz77_rd(r, ptr + j));
+ printm(M_INFO, "@0x%04x: 0x%02x - @0x%04x: 0x%02x\n", needle + j, lz77_rd(r, needle + j - scheme.window_start), ptr + j, lz77_rd(r, ptr + j));
if (lz77_rd(r, needle + j) != lz77_rd(r, ptr + j)) {
printm(M_ERROR, "ERROR!!\n");
}
}
+ jump -= scheme.one_jump;
printm(M_INFO, "ptr = %li, needle = %li, jump = %li = 0x%03x\n", ptr, needle, jump, jump);
ptr += needle_length;
needle_length -= 3;
- jump -= scheme.one_jump;
- if (scheme.opposite) {
+ switch (scheme.ptrb) {
+ case 0:
+ break;
+ case 1:
jump = lz77_maxptr + 1 - jump;
+ break;
+ case 2:
+ jump = needle + scheme.window_start;
+ break;
}
val1 = comp[comp_ptr++] = (shift(jump, -scheme.j_shft_1) & scheme.j_mask_1) |
(shift(needle_length, -scheme.l_shft_1) & scheme.l_mask_1);
@@ -432,10 +449,11 @@ struct option long_options[] = {
{"overlap", 1, &lga, 2 },
{"16bits", 1, &lga, 11 },
{"negative", 1, &lga, 12 },
- {"opposite", 1, &lga, 13 },
+ {"ptrb", 1, &lga, 13 },
{"filling", 1, &lga, 14 },
{"inverse", 1, &lga, 23 },
{"onejump", 1, &lga, 24 },
+ {"window", 1, &lga, 25 },
{"lmask1", 1, &lga, 3 },
{"lshft1", 1, &lga, 4 },
{"lmask2", 1, &lga, 5 },
@@ -483,7 +501,8 @@ void showhelp(void) {
"-b --blocks Switch to blocks decompression behaviour\n"
"\n"
"Additionnaly you have the scheme manipulation options:\n"
-"--1iscomp --overlap --negative --16bits --filling --inverse --onejump\n"
+"--1iscomp --overlap --negative --16bits --ptrb\n"
+"--filling --inverse --onejump --window\n"
"--lmask1 --lshft1 --lmask2 --lshft2 --jmask1 --jshft1 --jmask2 --jshft2\n"
"--vmask1 --vshft1 --vmask2 --vshft2 --fmask1 --fshft1 --fmask2 --fshft2\n"
"\n"
@@ -500,10 +519,11 @@ void showscheme(void) {
"--overlap %i\n"
"--negative %i\n"
"--16bits %i\n"
-"--opposite %i\n"
+"--ptrb %i\n"
"--filling %i\n"
"--inverse %i\n"
"--onejump %i\n"
+"--window %i\n"
"--lmask1 0x%02x\n"
"--lshft1 %i\n"
"--lmask2 0x%02x\n"
@@ -521,7 +541,7 @@ void showscheme(void) {
"--vmask2 0x%02x\n"
"--vshft2 %i\n"
"\n", scheme.one_is_compressed, scheme.overlap_trick, scheme.negative_trick, scheme.sixteen_bits,
-scheme.opposite, scheme.filling, scheme.bitmap_inversed, scheme.one_jump,
+scheme.ptrb, scheme.filling, scheme.bitmap_inversed, scheme.one_jump, scheme.window_start,
scheme.l_mask_1, scheme.l_shft_1, scheme.l_mask_2, scheme.l_shft_2,
scheme.j_mask_1, scheme.j_shft_1, scheme.j_mask_2, scheme.j_shft_2,
scheme.f_mask_1, scheme.f_shft_1, scheme.f_mask_2, scheme.f_shft_2,
@@ -560,7 +580,7 @@ LZ77_NAME " compressor/decompressor version " LZ77_VERSION ",\n"
"Special thanks to Yazoo, who taught me PSX hacking.\n"
"\n");
- while ((c = getopt_long(argc, argv, "Hhs:l:vVScd", long_options, NULL)) != EOF) {
+ while ((c = getopt_long(argc, argv, "Hhs:l:vVScdb", long_options, NULL)) != EOF) {
switch (c) {
case 0:
switch (lga) {
@@ -622,10 +642,10 @@ LZ77_NAME " compressor/decompressor version " LZ77_VERSION ",\n"
break;
case 13:
t = atoi(optarg);
- if ((t != 1) && (t != 0)) {
- printm(M_ERROR, "Invalid value for boolean: %s\n", optarg);
+ if ((t != 2) && (t != 1) && (t != 0)) {
+ printm(M_ERROR, "Invalid value for ter: %s\n", optarg);
} else {
- scheme.opposite = t;
+ scheme.ptrb = t;
}
break;
case 14:
@@ -676,6 +696,9 @@ LZ77_NAME " compressor/decompressor version " LZ77_VERSION ",\n"
scheme.one_jump = t;
}
break;
+ case 25:
+ t = sscanf(optarg, "%i", &scheme.window_start);
+ break;
default:
showhelp();
printm(M_ERROR, "Unknow option.\n");
@@ -765,7 +788,7 @@ LZ77_NAME " compressor/decompressor version " LZ77_VERSION ",\n"
if (!bitmap_count)
bitmap_count = 8;
if (compress)
- printm(M_STATUS, "Compressed %i = 0x%08x blocs, containing %i = 0x%08x chunks.\n", blk + 1, blk + 1, blk + bitmap_count, blk + bitmap_count);
+ printm(M_STATUS, "Compressed %i = 0x%08x blocs, containing %i = 0x%08x chunks.\n", blk + 1, blk + 1, blk * 8 + bitmap_count, blk * 8 + bitmap_count);
fclose(f1);
fclose(f2);
diff --git a/lz77.h b/lz77.h
index 418578e..34888c5 100644
--- a/lz77.h
+++ b/lz77.h
@@ -28,7 +28,8 @@
typedef struct {
char * name;
- int one_is_compressed, bitmap_inversed, one_jump, overlap_trick, negative_trick, sixteen_bits, opposite, filling;
+ int one_is_compressed, bitmap_inversed, one_jump, overlap_trick, negative_trick, sixteen_bits, ptrb, filling;
+ int window_start;
int l_mask_1, l_shft_1, l_mask_2, l_shft_2;
int j_mask_1, j_shft_1, j_mask_2, j_shft_2;
int f_mask_1, f_shft_1, f_mask_2, f_shft_2;