aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/scicore/decompress1.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sci/scicore/decompress1.cpp')
-rw-r--r--engines/sci/scicore/decompress1.cpp45
1 files changed, 23 insertions, 22 deletions
diff --git a/engines/sci/scicore/decompress1.cpp b/engines/sci/scicore/decompress1.cpp
index 7269e29479..250aa9bb83 100644
--- a/engines/sci/scicore/decompress1.cpp
+++ b/engines/sci/scicore/decompress1.cpp
@@ -25,6 +25,7 @@
/* Reads data from a resource file and stores the result in memory */
+#include "common/util.h"
#include "sci/include/sci_memory.h"
#include "sci/include/sciresource.h"
@@ -72,7 +73,7 @@ getbits_msb_first(struct bit_read_struct *inp, int bits) {
int i;
if (inp->bytepos + morebytes >= inp->length) {
- fprintf(stderr, "read out-of-bounds with bytepos %d + morebytes %d >= length %d\n",
+ error("read out-of-bounds with bytepos %d + morebytes %d >= length %d\n",
inp->bytepos, morebytes, inp->length);
return -SCI_ERROR_DECOMPRESSION_OVERFLOW;
}
@@ -98,7 +99,7 @@ getbits(struct bit_read_struct *inp, int bits) {
int i;
if (inp->bytepos + morebytes >= inp->length) {
- fprintf(stderr, "read out-of-bounds with bytepos %d + morebytes %d >= length %d\n",
+ error("read out-of-bounds with bytepos %d + morebytes %d >= length %d\n",
inp->bytepos, morebytes, inp->length);
return -SCI_ERROR_DECOMPRESSION_OVERFLOW;
}
@@ -113,7 +114,7 @@ getbits(struct bit_read_struct *inp, int bits) {
inp->bytepos += morebytes;
if (DEBUG_DCL_INFLATE)
- fprintf(stderr, "(%d:%04x)", bits, result);
+ error("(%d:%04x)", bits, result);
return result;
}
@@ -126,14 +127,14 @@ huffman_lookup(struct bit_read_struct *inp, int *tree) {
while (!(tree[pos] & HUFFMAN_LEAF)) {
CALLC(bit = getbits(inp, 1));
if (DEBUG_DCL_INFLATE)
- fprintf(stderr, "[%d]:%d->", pos, bit);
+ error("[%d]:%d->", pos, bit);
if (bit)
pos = tree[pos] & ~(~0 << BRANCH_SHIFT);
else
pos = tree[pos] >> BRANCH_SHIFT;
}
if (DEBUG_DCL_INFLATE)
- fprintf(stderr, "=%02x\n", tree[pos] & 0xffff);
+ error("=%02x\n", tree[pos] & 0xffff);
return tree[pos] & 0xffff;
}
@@ -150,28 +151,28 @@ decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader) {
CALLC(length_param = getbits(reader, 8));
if (mode == DCL_ASCII_MODE) {
- fprintf(stderr, "DCL-INFLATE: Warning: Decompressing ASCII mode (untested)\n");
+ error("DCL-INFLATE: Warning: Decompressing ASCII mode (untested)\n");
/* DEBUG_DCL_INFLATE = 1; */
} else if (mode) {
- fprintf(stderr, "DCL-INFLATE: Error: Encountered mode %02x, expected 00 or 01\n", mode);
+ error("DCL-INFLATE: Error: Encountered mode %02x, expected 00 or 01\n", mode);
return 1;
}
if (DEBUG_DCL_INFLATE) {
int i;
for (i = 0; i < reader->length; i++) {
- fprintf(stderr, "%02x ", reader->data[i]);
+ error("%02x ", reader->data[i]);
if (!((i + 1) & 0x1f))
- fprintf(stderr, "\n");
+ error("\n");
}
- fprintf(stderr, "\n---\n");
+ error("\n---\n");
}
if (length_param < 3 || length_param > 6)
- fprintf(stderr, "Warning: Unexpected length_param value %d (expected in [3,6])\n", length_param);
+ error("Warning: Unexpected length_param value %d (expected in [3,6])\n", length_param);
while (write_pos < length) {
CALLC(value = getbits(reader, 1));
@@ -190,7 +191,7 @@ decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader) {
}
if (DEBUG_DCL_INFLATE)
- fprintf(stderr, " | ");
+ error(" | ");
CALLC(value = huffman_lookup(reader, distance_tree));
@@ -208,15 +209,15 @@ decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader) {
++val_distance;
if (DEBUG_DCL_INFLATE)
- fprintf(stderr, "\nCOPY(%d from %d)\n", val_length, val_distance);
+ error("\nCOPY(%d from %d)\n", val_length, val_distance);
if (val_length + write_pos > length) {
- fprintf(stderr, "DCL-INFLATE Error: Write out of bounds while copying %d bytes\n", val_length);
+ error("DCL-INFLATE Error: Write out of bounds while copying %d bytes\n", val_length);
return -SCI_ERROR_DECOMPRESSION_OVERFLOW;
}
if (write_pos < val_distance) {
- fprintf(stderr, "DCL-INFLATE Error: Attempt to copy from before beginning of input stream\n");
+ error("DCL-INFLATE Error: Attempt to copy from before beginning of input stream\n");
return -SCI_ERROR_DECOMPRESSION_INSANE;
}
@@ -228,8 +229,8 @@ decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader) {
if (DEBUG_DCL_INFLATE) {
int i;
for (i = 0; i < copy_length; i++)
- fprintf(stderr, "\33[32;31m%02x\33[37;37m ", dest[write_pos + i]);
- fprintf(stderr, "\n");
+ error("\33[32;31m%02x\33[37;37m ", dest[write_pos + i]);
+ error("\n");
}
val_length -= copy_length;
@@ -247,7 +248,7 @@ decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader) {
dest[write_pos++] = value;
if (DEBUG_DCL_INFLATE)
- fprintf(stderr, "\33[32;31m%02x \33[37;37m", value);
+ error("\33[32;31m%02x \33[37;37m", value);
}
}
@@ -343,14 +344,14 @@ int decompress1(resource_t *result, Common::ReadStream &stream, int sci_version)
#ifdef _SCI_DECOMPRESS_DEBUG
- fprintf(stderr, "Resource %i.%s encrypted with method SCI1%c/%hi at %.2f%%"
+ error("Resource %i.%s encrypted with method SCI1%c/%hi at %.2f%%"
" ratio\n",
result->number, sci_resource_type_suffixes[result->type],
early ? 'e' : 'l',
compressionMethod,
(result->size == 0) ? -1.0 :
(100.0 * compressedLength / result->size));
- fprintf(stderr, " compressedLength = 0x%hx, actualLength=0x%hx\n",
+ error(" compressedLength = 0x%hx, actualLength=0x%hx\n",
compressedLength, result->size);
#endif
@@ -418,8 +419,8 @@ int decompress1(resource_t *result, Common::ReadStream &stream, int sci_version)
break;
default:
- fprintf(stderr, "Resource %s.%03hi: Compression method SCI1/%hi not "
- "supported!\n", sci_resource_types[result->type], result->number,
+ error("Resource %s.%03hi: Compression method SCI1/%hi not "
+ "supported", sci_resource_types[result->type], result->number,
compressionMethod);
free(result->data);
result->data = 0; /* So that we know that it didn't work */