[Scummvm-cvs-logs] CVS: scummvm/sky rnc_deco.h,NONE,1.1 rnc_deco.cpp,1.9,1.10 disk.cpp,1.9,1.10

Joost Peters joostp at users.sourceforge.net
Thu Mar 6 07:36:03 CET 2003


Update of /cvsroot/scummvm/scummvm/sky
In directory sc8-pr-cvs1:/tmp/cvs-serv4705/sky

Modified Files:
	rnc_deco.cpp disk.cpp 
Added Files:
	rnc_deco.h 
Log Message:
Major cleanup in rnc_deco.cpp, is now a seperate RncDecoder class, modified disk.cpp to use the class + added rnc_deco.h

--- NEW FILE: rnc_deco.h ---
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2003 The ScummVM project
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header: /cvsroot/scummvm/scummvm/sky/rnc_deco.h,v 1.1 2003/03/06 15:35:07 joostp Exp $
 *
 */

#ifndef RNC_DECO_H
#define RNC_DECO_H

class RncDecoder {

protected:
	uint16 _rawTable[64];
	uint16 _posTable[64];
	uint16 _lenTable[64];

	uint16 _crcTable[256];
	
	uint16 _bitBuffl;
	uint16 _bitBuffh;
	uint8 _bitCount;

	uint8 *_srcPtr, *_dstPtr;

public:
	RncDecoder();
	~RncDecoder();
	int32 unpackM1(void *input, void *output, uint16 key);	
	
protected:
	void initCrc();
	uint16 crcBlock(uint8 *block, uint32 size);
	uint16 inputBits(uint8 amount);
	void makeHufftable(uint16 *table);
	uint16 inputValue(uint16 *table);
	
};

#endif

Index: rnc_deco.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/rnc_deco.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- rnc_deco.cpp	6 Mar 2003 13:48:05 -0000	1.9
+++ rnc_deco.cpp	6 Mar 2003 15:35:06 -0000	1.10
@@ -21,6 +21,7 @@
 
 #include <string.h>
 #include "common/scummsys.h"
+#include "sky/rnc_deco.h"
 
 #define ROL(x, n) (((x) << (n)) | ((x) >> (16 - (n))))
 #define ROR(x, n) (((x) << (16 - (n))) | ((x) >> (n)))
@@ -40,21 +41,19 @@
 #define MIN_LENGTH	  2
 #define HEADER_LEN	  18
 
-uint16 raw_table[TABLE_SIZE / 2];
-uint16 pos_table[TABLE_SIZE / 2];
-uint16 len_table[TABLE_SIZE / 2];
-
-#ifdef CHECKSUMS
-uint16 crc_table[0x100];
-#endif
+RncDecoder::RncDecoder()
+{
+	_bitBuffl = 0;
+	_bitBuffh = 0;
+	_bitCount = 0;
+}
 
-uint16 bit_buffl = 0;
-uint16 bit_buffh = 0;
-uint8 bit_count = 0;
+RncDecoder::~RncDecoder()
+{
 
-uint8 *srcPtr, *dstPtr; //these need to be global because input_bits() uses them
+}
 
-void init_crc()
+void RncDecoder::initCrc()
 {
 	uint16 cnt = 0;
 	uint16 tmp1 = 0;
@@ -69,15 +68,15 @@
 			} else
 				tmp1 /= 2;
 		}
-		crc_table[tmp2] = tmp1;
+		_crcTable[tmp2] = tmp1;
 	}
 }
 
 //calculate 16 bit crc of a block of memory
-uint16 crc_block(uint8 *block, uint32 size)
+uint16 RncDecoder::crcBlock(uint8 *block, uint32 size)
 {
 	uint16 crc = 0;
-	uint8 *crcTable8 = (uint8 *)crc_table; //make a uint8* to crc_table
+	uint8 *crcTable8 = (uint8 *)_crcTable; //make a uint8* to crc_table
 	uint8 tmp;
 	uint32 i;
 
@@ -94,11 +93,11 @@
 	return crc;
 }
 
-uint16 input_bits(uint8 amount)
+uint16 RncDecoder::inputBits(uint8 amount)
 {
-	uint16 newBitBuffh = bit_buffh;
-	uint16 newBitBuffl = bit_buffl;
-	int16 newBitCount = bit_count;
+	uint16 newBitBuffh = _bitBuffh;
+	uint16 newBitBuffl = _bitBuffl;
+	int16 newBitCount = _bitCount;
 	uint16 remBits, returnVal;
 
 	returnVal = ((1 << amount) - 1) & newBitBuffl;	
@@ -111,31 +110,31 @@
 		newBitBuffh >>= amount;
 		newBitBuffl >>= amount;
 		newBitBuffl |= remBits;	
-		srcPtr += 2;
-		newBitBuffh = READ_LE_UINT16(srcPtr);
+		_srcPtr += 2;
+		newBitBuffh = READ_LE_UINT16(_srcPtr);
 		XCHG(newBitCount, amount);
 		amount -= newBitCount;
 		newBitCount = 16 - amount;
 	}
 	remBits = ROR((uint16)(((1 << amount) - 1) & newBitBuffh), amount);
-	bit_buffh = newBitBuffh >> amount;
-	bit_buffl = (newBitBuffl >> amount) | remBits;
-	bit_count = (uint8)newBitCount;
+	_bitBuffh = newBitBuffh >> amount;
+	_bitBuffl = (newBitBuffl >> amount) | remBits;
+	_bitCount = (uint8)newBitCount;
 
 	return returnVal;
 }
 
-void make_huftable(uint16 *table) 
+void RncDecoder::makeHufftable(uint16 *table) 
 {
 	uint16 bitLength, i, j;
-	uint16 numCodes = input_bits(5);
+	uint16 numCodes = inputBits(5);
 
 	if (!numCodes)
 		return;
 
 	uint8 huffLength[16];
 	for (i = 0; i < numCodes; i++)
-		huffLength[i] = (uint8)(input_bits(4) & 0x00FF);
+		huffLength[i] = (uint8)(inputBits(4) & 0x00FF);
 
 	uint16 huffCode = 0;
 
@@ -158,9 +157,9 @@
 	}
 }
 
-uint16 input_value(uint16 *table)
+uint16 RncDecoder::inputValue(uint16 *table)
 {
-	uint16 valOne, valTwo, value = bit_buffl;
+	uint16 valOne, valTwo, value = _bitBuffl;
 
 	do {
 		valTwo = (*table++) & value;
@@ -169,12 +168,12 @@
 	} while (valOne != valTwo);
 
 	value = *(table + 0x1e);
-	input_bits((uint8)((value>>8) & 0x00FF));
+	inputBits((uint8)((value>>8) & 0x00FF));
 	value &= 0x00FF;
 
 	if (value >= 2) {
 		value--;
-		valOne = input_bits((uint8)value & 0x00FF);
+		valOne = inputBits((uint8)value & 0x00FF);
 		valOne |= (1 << value);
 		value = valOne;
 	}
@@ -182,22 +181,22 @@
 	return value;
 }
 
-int32 UnpackM1(void *input, void *output, uint16 key)
+int32 RncDecoder::unpackM1(void *input, void *output, uint16 key)
 {
 	uint8 *inputHigh, *outputLow, *outputHigh;
 	uint8 *inputptr = (uint8 *)input;
 
-	uint32 unpack_len = 0;
-	uint32 pack_len = 0;
+	uint32 unpackLen = 0;
+	uint32 packLen = 0;
 	uint16 counts = 0;
 
 #ifdef CHECKSUMS
-	uint16 crc_u = 0;
-	uint16 crc_p = 0;
+	uint16 crcUnpacked = 0;
+	uint16 crcPacked = 0;
 #endif
 	
 	if (CHECKSUMS)
-		init_crc();
+		initCrc();
 
 	//Check for "RNC "
 	if (READ_BE_UINT32(inputptr) != 0x524e4301)
@@ -206,83 +205,82 @@
 	inputptr += 4;
 
 	// read unpacked/packed file length
-	unpack_len = READ_BE_UINT32(inputptr); inputptr += 4;
-	pack_len = READ_BE_UINT32(inputptr); inputptr += 4;
+	unpackLen = READ_BE_UINT32(inputptr); inputptr += 4;
+	packLen = READ_BE_UINT32(inputptr); inputptr += 4;
 
 	uint8 blocks = *(inputptr + 5);
 
 	if (CHECKSUMS) {
 		//read CRC's
-		crc_u = READ_BE_UINT16(inputptr); inputptr += 2;
-		crc_p = READ_BE_UINT16(inputptr); inputptr += 2;
+		crcUnpacked = READ_BE_UINT16(inputptr); inputptr += 2;
+		crcPacked = READ_BE_UINT16(inputptr); inputptr += 2;
 		inputptr = (inputptr + HEADER_LEN - 16);
 
-		if (crc_block(inputptr, pack_len) != crc_p)
+		if (crcBlock(inputptr, packLen) != crcPacked)
 			return PACKED_CRC;
 
 		inputptr = (((uint8 *)input) + HEADER_LEN); 
-		srcPtr = inputptr;
+		_srcPtr = inputptr;
 	}
 
 	// inputLow = *input
-	inputHigh = ((uint8 *)input) + pack_len + HEADER_LEN;;
+	inputHigh = ((uint8 *)input) + packLen + HEADER_LEN;;
 	outputLow = (uint8 *)output;
-	outputHigh = *(((uint8 *)input) + 16) + unpack_len + outputLow;
+	outputHigh = *(((uint8 *)input) + 16) + unpackLen + outputLow;
 
 	if (! ((inputHigh <= outputLow) || (outputHigh <= inputHigh)) ) {
-		srcPtr = inputHigh;
-		dstPtr = outputHigh;
-		memcpy((dstPtr-pack_len), (srcPtr-pack_len), pack_len);
-		srcPtr = (dstPtr-pack_len);
+		_srcPtr = inputHigh;
+		_dstPtr = outputHigh;
+		memcpy((_dstPtr-packLen), (_srcPtr-packLen), packLen);
+		_srcPtr = (_dstPtr-packLen);
 	}
 
-	//unpack3:
-	dstPtr = (uint8 *)output;
-	bit_count = 0;
+	_dstPtr = (uint8 *)output;
+	_bitCount = 0;
 
-	bit_buffl = READ_LE_UINT16(srcPtr);
-	input_bits(2);
+	_bitBuffl = READ_LE_UINT16(_srcPtr);
+	inputBits(2);
 	
 	do {
-		make_huftable(raw_table);
-		make_huftable(pos_table);
-		make_huftable(len_table);
+		makeHufftable(_rawTable);
+		makeHufftable(_posTable);
+		makeHufftable(_lenTable);
 
-		counts = input_bits(16);
+		counts = inputBits(16);
 
 		for (;;) {
-			uint32 input_bits = input_value(raw_table);
+			uint32 inputBits = inputValue(_rawTable);
 
-			if (input_bits) {
-				memcpy(dstPtr, srcPtr, input_bits); //memcpy is allowed here
-				dstPtr += input_bits;
-				srcPtr += input_bits;
-				uint16 b = READ_LE_UINT16(srcPtr);
-				uint16 a = ROL(b, bit_count);
-				uint16 d = ((1 << bit_count) - 1);
-				bit_buffl &= d;
+			if (inputBits) {
+				memcpy(_dstPtr, _srcPtr, inputBits); //memcpy is allowed here
+				_dstPtr += inputBits;
+				_srcPtr += inputBits;
+				uint16 b = READ_LE_UINT16(_srcPtr);
+				uint16 a = ROL(b, _bitCount);
+				uint16 d = ((1 << _bitCount) - 1);
+				_bitBuffl &= d;
 				d &= a;
 
-				a = READ_LE_UINT16((srcPtr + 2));
-				b = (b << bit_count);
-				a = (a << bit_count);
+				a = READ_LE_UINT16((_srcPtr + 2));
+				b = (b << _bitCount);
+				a = (a << _bitCount);
 				a |= d;
-				bit_buffl |= b;
-				bit_buffh = a;
+				_bitBuffl |= b;
+				_bitBuffh = a;
 			}
 
 			if (--counts) {
-				uint32 input_offset = input_value(pos_table) + 1;
-				uint32 input_length = input_value(len_table) + MIN_LENGTH;
+				uint32 inputOffset = inputValue(_posTable) + 1;
+				uint32 inputLength = inputValue(_lenTable) + MIN_LENGTH;
 
-				inputHigh = srcPtr;
-				srcPtr = (dstPtr-input_offset);
+				inputHigh = _srcPtr;
+				_srcPtr = (_dstPtr-inputOffset);
 
 				//Don't use memcpy here! because input and output overlap	
-				while (input_length--)
-					*dstPtr++ = *srcPtr++;
+				while (inputLength--)
+					*_dstPtr++ = *_srcPtr++;
 
-				srcPtr = inputHigh;
+				_srcPtr = inputHigh;
 			} else
 				break;
 
@@ -290,11 +288,11 @@
 	} while (--blocks);
 
 	if (CHECKSUMS) {
-		if (crc_block((uint8 *)output, unpack_len) != crc_u)
+		if (crcBlock((uint8 *)output, unpackLen) != crcUnpacked)
 			return UNPACKED_CRC;
 	}
 
 	// all is done..return the amount of unpacked bytes
-	return unpack_len;
+	return unpackLen;
 }
 

Index: disk.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/disk.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- disk.cpp	6 Mar 2003 13:04:13 -0000	1.9
+++ disk.cpp	6 Mar 2003 15:35:07 -0000	1.10
@@ -25,13 +25,12 @@
 #include "common/file.h"
 #include "sky/skydefs.h"
 #include "sky/sky.h"
+#include "sky/rnc_deco.h"
 
 #define no_of_files_hd	1600
 #define no_of_files_cd	5200
 #define max_files_in_list		60
 
-int32 UnpackM1(void *, void *, uint16);
-
 const char *data_file_name = "sky.dsk";
 const char *dinner_file_name = "sky.dnr";
 uint8 *dinner_table_area, *fixed_dest, *file_dest, *comp_dest;
@@ -151,7 +150,8 @@
 				outputPtr += sizeof(struct dataFileHeader);
 			}
 
-			int32 unPackLen = UnpackM1(inputPtr, outputPtr, 0);
+			RncDecoder rncDecoder;
+			int32 unPackLen = rncDecoder.unpackM1(inputPtr, outputPtr, 0);
 
 			debug(2, "UnpackM1 returned: %d", unPackLen);
 





More information about the Scummvm-git-logs mailing list