[Scummvm-cvs-logs] CVS: residual blocky16.cpp,NONE,1.1 blocky16.h,NONE,1.1 smush.cpp,NONE,1.1 smush.h,NONE,1.1 vima.cpp,NONE,1.1 bitmap.cpp,1.10,1.11 bits.h,1.5,1.6 keyframe.cpp,1.3,1.4 lab.cpp,1.3,1.4 lua.cpp,1.33,1.34 material.cpp,1.5,1.6 mixer.cpp,1.4,1.5 mixer.h,1.4,1.5 model.cpp,1.11,1.12 residual.vcproj,1.9,1.10 sound.cpp,1.3,1.4 sound.h,1.2,1.3 stdafx.h,1.1,1.2

Pawel Kolodziejski aquadran at users.sourceforge.net
Fri Dec 12 00:40:03 CET 2003


Update of /cvsroot/scummvm/residual
In directory sc8-pr-cvs1:/tmp/cvs-serv5768

Modified Files:
	bitmap.cpp bits.h keyframe.cpp lab.cpp lua.cpp material.cpp 
	mixer.cpp mixer.h model.cpp residual.vcproj sound.cpp sound.h 
	stdafx.h 
Added Files:
	blocky16.cpp blocky16.h smush.cpp smush.h vima.cpp 
Log Message:
changes types as in scummvm, split vima codec to seperate file, added smush code, added hack in lua for play smush currently only intro, output gfx and sound(no mixer yet)

--- NEW FILE: blocky16.cpp ---
// Residual - Virtual machine to run LucasArts' 3D adventure games
// Copyright (C) 2003 The ScummVM-Residual Team (www.scummvm.org)
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library 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
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA

#include "stdafx.h"
#include "bits.h"
#include "blocky16.h"
#include "debug.h"

static int8 codec47_table_small1[] = {
	0, 1, 2, 3, 3, 3, 3, 2, 1, 0, 0, 0, 1, 2, 2, 1,
};

static int8 codec47_table_small2[] = {
	0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 2, 1, 1, 1, 2, 2,
};

static int8 codec47_table_big1[] = {
	0, 2, 5, 7, 7, 7, 7, 7, 7, 5, 2, 0, 0, 0, 0, 0,
};

static int8 codec47_table_big2[] = {
	0, 0, 0, 0, 1, 3, 4, 6, 7, 7, 7, 7, 6, 4, 3, 1,
};

static int8 codec47_table[] = {
	  0,   0,  -1, -43,   6, -43,  -9, -42,  13, -41,
	-16, -40,  19, -39, -23, -36,  26, -34,  -2, -33,
	  4, -33, -29, -32,  -9, -32,  11, -31, -16, -29,
	 32, -29,  18, -28, -34, -26, -22, -25,  -1, -25,
	  3, -25,  -7, -24,   8, -24,  24, -23,  36, -23,
	-12, -22,  13, -21, -38, -20,   0, -20, -27, -19,
	 -4, -19,   4, -19, -17, -18,  -8, -17,   8, -17,
	 18, -17,  28, -17,  39, -17, -12, -15,  12, -15,
	-21, -14,  -1, -14,   1, -14, -41, -13,  -5, -13,
	  5, -13,  21, -13, -31, -12, -15, -11,  -8, -11,
	  8, -11,  15, -11,  -2, -10,   1, -10,  31, -10,
	-23,  -9, -11,  -9,  -5,  -9,   4,  -9,  11,  -9,
	 42,  -9,   6,  -8,  24,  -8, -18,  -7,  -7,  -7,
	 -3,  -7,  -1,  -7,   2,  -7,  18,  -7, -43,  -6,
	-13,  -6,  -4,  -6,   4,  -6,   8,  -6, -33,  -5,
	 -9,  -5,  -2,  -5,   0,  -5,   2,  -5,   5,  -5,
	 13,  -5, -25,  -4,  -6,  -4,  -3,  -4,   3,  -4,
	  9,  -4, -19,  -3,  -7,  -3,  -4,  -3,  -2,  -3,
	 -1,  -3,   0,  -3,   1,  -3,   2,  -3,   4,  -3,
	  6,  -3,  33,  -3, -14,  -2, -10,  -2,  -5,  -2,
	 -3,  -2,  -2,  -2,  -1,  -2,   0,  -2,   1,  -2,
	  2,  -2,   3,  -2,   5,  -2,   7,  -2,  14,  -2,
	 19,  -2,  25,  -2,  43,  -2,  -7,  -1,  -3,  -1,
	 -2,  -1,  -1,  -1,   0,  -1,   1,  -1,   2,  -1,
	  3,  -1,  10,  -1,  -5,   0,  -3,   0,  -2,   0,
	 -1,   0,   1,   0,   2,   0,   3,   0,   5,   0,
	  7,   0, -10,   1,  -7,   1,  -3,   1,  -2,   1,
	 -1,   1,   0,   1,   1,   1,   2,   1,   3,   1,
	-43,   2, -25,   2, -19,   2, -14,   2,  -5,   2,
	 -3,   2,  -2,   2,  -1,   2,   0,   2,   1,   2,
	  2,   2,   3,   2,   5,   2,   7,   2,  10,   2,
	 14,   2, -33,   3,  -6,   3,  -4,   3,  -2,   3,
	 -1,   3,   0,   3,   1,   3,   2,   3,   4,   3,
	 19,   3,  -9,   4,  -3,   4,   3,   4,   7,   4,
	 25,   4, -13,   5,  -5,   5,  -2,   5,   0,   5,
	  2,   5,   5,   5,   9,   5,  33,   5,  -8,   6,
	 -4,   6,   4,   6,  13,   6,  43,   6, -18,   7,
	 -2,   7,   0,   7,   2,   7,   7,   7,  18,   7,
	-24,   8,  -6,   8, -42,   9, -11,   9,  -4,   9,
	  5,   9,  11,   9,  23,   9, -31,  10,  -1,  10,
	  2,  10, -15,  11,  -8,  11,   8,  11,  15,  11,
	 31,  12, -21,  13,  -5,  13,   5,  13,  41,  13,
	 -1,  14,   1,  14,  21,  14, -12,  15,  12,  15,
	-39,  17, -28,  17, -18,  17,  -8,  17,   8,  17,
	 17,  18,  -4,  19,   0,  19,   4,  19,  27,  19,
	 38,  20, -13,  21,  12,  22, -36,  23, -24,  23,
	 -8,  24,   7,  24,  -3,  25,   1,  25,  22,  25,
	 34,  26, -18,  28, -32,  29,  16,  29, -11,  31,
	  9,  32,  29,  32,  -4,  33,   2,  33, -26,  34,
	 23,  36, -19,  39,  16,  40, -13,  41,   9,  42,
	 -6,  43,   1,  43,   0,   0,   0,   0,   0,   0
};

void Blocky16::makeTablesInterpolation(int param) {
	int32 variable1, variable2;
	int32 b1, b2;
	int32 value_table47_1_2, value_table47_1_1, value_table47_2_2, value_table47_2_1;
	int32 tableSmallBig[64], tmp, s;
	int8 *table47_1 = 0, *table47_2 = 0;
	int32 *ptr_small_big;
	byte *ptr;
	int i, x, y;

	if (param == 8) {
		table47_1 = codec47_table_big1;
		table47_2 = codec47_table_big2;
		ptr = _tableBig + 384;
		for (i = 0; i < 256; i++) {
			*ptr = 0;
			ptr += 388;
		}
		ptr = _tableBig + 385;
		for (i = 0; i < 256; i++) {
			*ptr = 0;
			ptr += 388;
		}
	} else if (param == 4) {
		table47_1 = codec47_table_small1;
		table47_2 = codec47_table_small2;
		ptr = _tableSmall + 96;
		for (i = 0; i < 256; i++) {
			*ptr = 0;
			ptr += 128;
		}
		ptr = _tableSmall + 97;
		for (i = 0; i < 256; i++) {
			*ptr = 0;
			ptr += 128;
		}
	} else {
		error("Blocky16::makeTablesInterpolation: unknown param %d", param);
	}

	s = 0;
	for (x = 0; x < 16; x++) {
		value_table47_1_1 = table47_1[x];
		value_table47_2_1 = table47_2[x];
		for (y = 0; y < 16; y++) {
			value_table47_1_2 = table47_1[y];
			value_table47_2_2 = table47_2[y];

			if (value_table47_2_1 == 0) {
				b1 = 0;
			} else if (value_table47_2_1 == param - 1) {
				b1 = 1;
			} else if (value_table47_1_1 == 0) {
				b1 = 2;
			} else if (value_table47_1_1 == param - 1) {
				b1 = 3;
			} else {
				b1 = 4;
			}

			if (value_table47_2_2 == 0) {
				b2 = 0;
			} else if (value_table47_2_2 == param - 1) {
				b2 = 1;
			} else if (value_table47_1_2 == 0) {
				b2 = 2;
			} else if (value_table47_1_2 == param - 1) {
				b2 = 3;
			} else {
				b2 = 4;
			}
			
			memset(tableSmallBig, 0, param * param * 4);

			variable2 = abs(value_table47_2_2 - value_table47_2_1);
			tmp = abs(value_table47_1_2 - value_table47_1_1);
			if (variable2 <= tmp) {
				variable2 = tmp;
			}

			for (variable1 = 0; variable1 <= variable2; variable1++) {
				int32 variable3, variable4;

				if (variable2 > 0) {
					// Linearly interpolate between value_table47_1_1 and value_table47_1_2
					// respectively value_table47_2_1 and value_table47_2_2.
					variable4 = (value_table47_1_1 * variable1 + value_table47_1_2 * (variable2 - variable1) + variable2 / 2) / variable2;
					variable3 = (value_table47_2_1 * variable1 + value_table47_2_2 * (variable2 - variable1) + variable2 / 2) / variable2;
				} else {
					variable4 = value_table47_1_1;
					variable3 = value_table47_2_1;
				}
				ptr_small_big = &tableSmallBig[param * variable3 + variable4];
				*ptr_small_big = 1;

				if ((b1 == 2 && b2 == 3) || (b2 == 2 && b1 == 3) ||
				    (b1 == 0 && b2 != 1) || (b2 == 0 && b1 != 1)) {
					if (variable3 >= 0) {
						i = variable3 + 1;
						while (i--) {
							*ptr_small_big = 1;
							ptr_small_big -= param;
						}
					}
				} else if ((b2 != 0 && b1 == 1) || (b1 != 0 && b2 == 1)) {
					if (param > variable3) {
						i = param - variable3;
						while (i--) {
							*ptr_small_big = 1;
							ptr_small_big += param;
						}
					}
				} else if ((b1 == 2 && b2 != 3) || (b2 == 2 && b1 != 3)) {
					if (variable4 >= 0) {
						i = variable4 + 1;
						while (i--) {
							*(ptr_small_big--) = 1;
						}
					}
				} else if ((b1 == 0 && b2 == 1) || (b2 == 0 && b1 == 1) ||
				           (b1 == 3 && b2 != 2) || (b2 == 3 && b1 != 2)) {
					if (param > variable4) {
						i = param - variable4;
						while (i--) {
							*(ptr_small_big++) = 1;
						}
					}
				}
			}

			if (param == 8) {
				for (i = 64 - 1; i >= 0; i--) {
					if (tableSmallBig[i] != 0) {
						_tableBig[256 + s + _tableBig[384 + s]] = (byte)i;
						_tableBig[384 + s]++;
					} else {
						_tableBig[320 + s + _tableBig[385 + s]] = (byte)i;
						_tableBig[385 + s]++;
					}
				}
				s += 388;
			}
			if (param == 4) {
				for (i = 16 - 1; i >= 0; i--) {
					if (tableSmallBig[i] != 0) {
						_tableSmall[64 + s + _tableSmall[96 + s]] = (byte)i;
						_tableSmall[96 + s]++;
					} else {
						_tableSmall[80 + s + _tableSmall[97 + s]] = (byte)i;
						_tableSmall[97 + s]++;
					}
				}
				s += 128;
			}
		}
	}
}

void Blocky16::makeTables47(int width) {
	if (_lastTableWidth == width)
		return;

	_lastTableWidth = width;

	int32 a, c, d;
	int16 tmp;

	for (int l = 0; l < 512; l += 2) {
		_table[l / 2] = (int16)(codec47_table[l + 1] * width + codec47_table[l]);
	}

	a = 0;
	c = 0;
	do {
		for (d = 0; d < _tableSmall[96 + c]; d++) {
			tmp = _tableSmall[64 + c + d];
			tmp = (int16)((byte)(tmp >> 2) * width + (tmp & 3));
			_tableSmall[c + d * 2] = (byte)tmp;
			_tableSmall[c + d * 2 + 1] = tmp >> 8;
		}
		for (d = 0; d < _tableSmall[97 + c]; d++) {
			tmp = _tableSmall[80 + c + d];
			tmp = (int16)((byte)(tmp >> 2) * width + (tmp & 3));
			_tableSmall[32 + c + d * 2] = (byte)tmp;
			_tableSmall[32 + c + d * 2 + 1] = tmp >> 8;
		}
		for (d = 0; d < _tableBig[384 + a]; d++) {
			tmp = _tableBig[256 + a + d];
			tmp = (int16)((byte)(tmp >> 3) * width + (tmp & 7));
			_tableBig[a + d * 2] = (byte)tmp;
			_tableBig[a + d * 2 + 1] = tmp >> 8;
		}
		for (d = 0; d < _tableBig[385 + a]; d++) {
			tmp = _tableBig[320 + a + d];
			tmp = (int16)((byte)(tmp >> 3) * width + (tmp & 7));
			_tableBig[128 + a + d * 2] = (byte)tmp;
			_tableBig[128 + a + d * 2 + 1] = tmp >> 8;
		}
		
		a += 388;
		c += 128;
	} while (c < 32768);
}

void Blocky16::level3(byte *d_dst) {
	int32 tmp2;
	uint32 t, val;
	byte code = *_d_src++;
	int i;

	if (code <= 0xF5) {
		if (code == 0xF5) {
			int16 tmp = READ_LE_UINT16(_d_src);
			tmp2 = tmp * 2;
			_d_src += 2;
		} else {
			tmp2 = _table[code] * 2;
		}
		tmp2 += _offset1;
		for (i = 0; i < 2; i++) {
			*(uint32 *)(d_dst +  0) = *(uint32 *)(d_dst + tmp2 +  0);
			d_dst += _d_pitch;
		}
	} else if ((code == 0xFF) || (code == 0xF8)) {
		*(uint32 *)(d_dst) = *(uint32 *)(_d_src);
		d_dst += _d_pitch;
		*(uint32 *)(d_dst) = *(uint32 *)(_d_src + 4);
		_d_src += 8;
	} else if (code == 0xFD) {
		t = *_d_src++;
		t = READ_LE_UINT16(_param6_7Ptr + t * 2);
		t = ((t << 16) & 0xffff0000) | (t & 0xffff);
		for (i = 0; i < 2; i++) {
			*(uint32 *)(d_dst +  0) = t;
			d_dst += _d_pitch;
		}
	} else if (code == 0xFE) {
		t = READ_LE_UINT16(_d_src);
		_d_src += 2;
		t = ((t << 16) & 0xffff0000) | (t & 0xffff);
		for (i = 0; i < 2; i++) {
			*(uint32 *)(d_dst +  0) = t;
			d_dst += _d_pitch;
		}
	} else if (code == 0xF6) {
		tmp2 = _offset2;
		for (i = 0; i < 2; i++) {
			*(uint32 *)(d_dst +  0) = *(uint32 *)(d_dst + tmp2 +  0);
			d_dst += _d_pitch;
		}
	} else if (code == 0xF7) {
		tmp2 = READ_LE_UINT32(_d_src);
		_d_src += 4;
		val = READ_LE_UINT16(_param6_7Ptr + (tmp2 & 0xff) * 2);
		*(uint16 *)(d_dst +  0) = val;
		val = READ_LE_UINT16(_param6_7Ptr + ((tmp2 >> 8) & 0xff) * 2);
		*(uint16 *)(d_dst +  2) = val;
		tmp2 >>= 16;
		d_dst += _d_pitch;
		val = READ_LE_UINT16(_param6_7Ptr + (tmp2 & 0xff) * 2);
		*(uint16 *)(d_dst +  0) = val;
		val = READ_LE_UINT16(_param6_7Ptr + ((tmp2 >> 8) & 0xff) * 2);
		*(uint16 *)(d_dst +  2) = val;
	} else if ((code == 0xF9) || (code == 0xFA) || (code == 0xFB) || (code == 0xFC))  {
		t = READ_LE_UINT16(_paramPtr + code * 2);
		t = ((t << 16) & 0xffff0000) | (t & 0xffff);
		for (i = 0; i < 2; i++) {
			*(uint32 *)(d_dst +  0) = t;
			d_dst += _d_pitch;
		}
	}
}

void Blocky16::level2(byte *d_dst) {
	int32 tmp2;
	uint32 t, val;
	byte code = *_d_src++;
	int i;

	if (code <= 0xF5) {
		if (code == 0xF5) {
			int16 tmp = READ_LE_UINT16(_d_src);
			tmp2 = tmp * 2;
			_d_src += 2;
		} else {
			tmp2 = _table[code] * 2;
		}
		tmp2 += _offset1;
		for (i = 0; i < 4; i++) {
			*(uint32 *)(d_dst +  0) = *(uint32 *)(d_dst + tmp2 +  0);
			*(uint32 *)(d_dst +  4) = *(uint32 *)(d_dst + tmp2 +  4);
			d_dst += _d_pitch;
		}
	} else if (code == 0xFF) {
		level3(d_dst);
		d_dst += 4;
		level3(d_dst);
		d_dst += _d_pitch * 2 - 4;
		level3(d_dst);
		d_dst += 4;
		level3(d_dst);
	} else if (code == 0xF6) {
		tmp2 = _offset2;
		for (i = 0; i < 4; i++) {
			*(uint32 *)(d_dst +  0) = *(uint32 *)(d_dst + tmp2 +  0);
			*(uint32 *)(d_dst +  4) = *(uint32 *)(d_dst + tmp2 +  4);
			d_dst += _d_pitch;
		}
	} else if ((code == 0xF7) || (code == 0xF8)) {
		byte tmp = *_d_src++;
		if (code == 0xF8) {
			val = READ_LE_UINT32(_d_src);
			_d_src += 4;
		} else {
			tmp2 = READ_LE_UINT16(_d_src);
			val = READ_LE_UINT16(_param6_7Ptr + ((tmp2 >> 8) & 0xff) * 2) << 16;
			val |= READ_LE_UINT16(_param6_7Ptr + (tmp2 & 0xff) * 2);
			_d_src += 2;
		}
		byte *tmp_ptr = _tableSmall + (tmp << 7);
		byte l = tmp_ptr[96];
		int16 *tmp_ptr2 = (int16 *)tmp_ptr;
		while (l--) {
			*(uint16* )(d_dst + READ_LE_UINT16(tmp_ptr2) * 2) = val & 0xffff;
			tmp_ptr2++;
		}
		l = tmp_ptr[97];
		val >>= 16;
		tmp_ptr2 = (int16 *)(tmp_ptr + 32);
		while (l--) {
			*(uint16* )(d_dst + READ_LE_UINT16(tmp_ptr2) * 2) = val;
			tmp_ptr2++;
		}
	} else if (code >= 0xF9) {
		if (code == 0xFD) {
			t = *_d_src++;
			t = READ_LE_UINT16(_param6_7Ptr + t * 2);
			t = ((t << 16) & 0xffff0000) | (t & 0xffff);
		} else if (code == 0xFE) {
			t = READ_LE_UINT16(_d_src);
			t = ((t << 16) & 0xffff0000) | (t & 0xffff);
			_d_src += 2;
		} else if ((code == 0xF9) || (code == 0xFA) || (code == 0xFB) || (code == 0xFC))  {
			t = READ_LE_UINT16(_paramPtr + code * 2);
			t = ((t << 16) & 0xffff0000) | (t & 0xffff);
		}
		for (i = 0; i < 4; i++) {
			*(uint32 *)(d_dst +  0) = t;
			*(uint32 *)(d_dst +  4) = t;
			d_dst += _d_pitch;
		}
	}
}

void Blocky16::level1(byte *d_dst) {
	int32 tmp2;
	uint32 t, val;
	byte code = *_d_src++;
	int i;

	if (code <= 0xF5) {
		if (code == 0xF5) {
			int16 tmp = READ_LE_UINT16(_d_src);
			tmp2 = tmp * 2;
			_d_src += 2;
		} else {
			tmp2 = _table[code] * 2;
		}
		tmp2 += _offset1;
		for (i = 0; i < 8; i++) {
			*(uint32 *)(d_dst +  0) = *(uint32 *)(d_dst + tmp2 +  0);
			*(uint32 *)(d_dst +  4) = *(uint32 *)(d_dst + tmp2 +  4);
			*(uint32 *)(d_dst +  8) = *(uint32 *)(d_dst + tmp2 +  8);
			*(uint32 *)(d_dst + 12) = *(uint32 *)(d_dst + tmp2 + 12);
			d_dst += _d_pitch;
		}
	} else if (code == 0xFF) {
		level2(d_dst);
		d_dst += 8;
		level2(d_dst);
		d_dst += _d_pitch * 4 - 8;
		level2(d_dst);
		d_dst += 8;
		level2(d_dst);
	} else if (code == 0xF6) {
		tmp2 = _offset2;
		for (i = 0; i < 8; i++) {
			*(uint32 *)(d_dst +  0) = *(uint32 *)(d_dst + tmp2 +  0);
			*(uint32 *)(d_dst +  4) = *(uint32 *)(d_dst + tmp2 +  4);
			*(uint32 *)(d_dst +  8) = *(uint32 *)(d_dst + tmp2 +  8);
			*(uint32 *)(d_dst + 12) = *(uint32 *)(d_dst + tmp2 + 12);
			d_dst += _d_pitch;
		}
	} else if ((code == 0xF7) || (code == 0xF8)) {
		byte tmp = *_d_src++;
		if (code == 0xF8) {
			val = READ_LE_UINT32(_d_src);
			_d_src += 4;
		} else {
			tmp2 = READ_LE_UINT16(_d_src);
			val = READ_LE_UINT16(_param6_7Ptr + ((tmp2 >> 8) & 0xff) * 2) << 16;
			val |= READ_LE_UINT16(_param6_7Ptr + (tmp2 & 0xff) * 2);
			_d_src += 2;
		}
		byte *tmp_ptr = _tableBig + (tmp * 4) + (tmp << 7) + (tmp << 7) + (tmp << 7);
		byte l = tmp_ptr[384];
		int16 *tmp_ptr2 = (int16 *)tmp_ptr;
		while (l--) {
			*(uint16* )(d_dst + READ_LE_UINT16(tmp_ptr2) * 2) = val & 0xffff;
			tmp_ptr2++;
		}
		l = tmp_ptr[385];
		val >>= 16;
		tmp_ptr2 = (int16 *)(tmp_ptr + 128);
		while (l--) {
			*(uint16* )(d_dst + READ_LE_UINT16(tmp_ptr2) * 2) = val;
			tmp_ptr2++;
		}
	} else if (code >= 0xF9) {
		if (code == 0xFD) {
			t = *_d_src++;
			t = READ_LE_UINT16(_param6_7Ptr + t * 2);
			t = ((t << 16) & 0xffff0000) | (t & 0xffff);
		} else if (code == 0xFE) {
			t = READ_LE_UINT16(_d_src);
			t = ((t << 16) & 0xffff0000) | (t & 0xffff);
			_d_src += 2;
		} else if ((code == 0xF9) || (code == 0xFA) || (code == 0xFB) || (code == 0xFC))  {
			t = READ_LE_UINT16(_paramPtr + code * 2);
			t = ((t << 16) & 0xffff0000) | (t & 0xffff);
		}
		for (i = 0; i < 8; i++) {
			*(uint32 *)(d_dst +  0) = t;
			*(uint32 *)(d_dst +  4) = t;
			*(uint32 *)(d_dst +  8) = t;
			*(uint32 *)(d_dst + 12) = t;
			d_dst += _d_pitch;
		}
	}
}

void Blocky16::decode2(byte *dst, const byte *src, int width, int height, const byte *param_ptr, const byte *param6_7_ptr) {
	_d_src = src;
	_paramPtr = param_ptr - 0xf9 - 0xf9;
	_param6_7Ptr = param6_7_ptr;
	int bw = (width + 7) / 8;
	int bh = (height + 7) / 8;
	int next_line = width * 2 * 7;
	_d_pitch = width * 2;

	do {
		int tmp_bw = bw;
		do {
			level1(dst);
			dst += 16;
		} while (--tmp_bw);
		dst += next_line;
	} while (--bh);
}

void Blocky16::init(int width, int height) {
	deinit();
	_width = width;
	_height = height;
	makeTablesInterpolation(4);
	makeTablesInterpolation(8);

	_frameSize = _width * _height * 2;
	_deltaSize = _frameSize * 3;
	_deltaBuf = (byte *)malloc(_deltaSize);
	_deltaBufs[0] = _deltaBuf;
	_deltaBufs[1] = _deltaBuf + _frameSize;
	_curBuf = _deltaBuf + _frameSize * 2;
}

Blocky16::Blocky16() {
	_tableBig = (byte *)malloc(99328);
	_tableSmall = (byte *)malloc(32768);
	memset(_tableBig, 0, 99328);
	memset(_tableSmall, 0, 32768);
	_deltaBuf = NULL;
}

void Blocky16::deinit() {
	_lastTableWidth = -1;
	if (_deltaBuf) {
		free(_deltaBuf);
		_deltaSize = 0;
		_deltaBuf = NULL;
		_deltaBufs[0] = NULL;
		_deltaBufs[1] = NULL;
	}
}

Blocky16::~Blocky16() {
	deinit();
	if (_tableBig) {
		free(_tableBig);
		_tableBig = NULL;
	}
	if (_tableSmall) {
		free(_tableSmall);
		_tableSmall = NULL;
	}
}

static int bomp_left;
static int bomp_num;
static int bomp_color;
static const byte *bomp_src;

static byte bompDecode() {
	byte code, result;
	const byte *src;

	if (bomp_left == 2) {
		src = bomp_src;
		bomp_num = (*src >> 1) + 1;
		code = *(src++) & 1;
		bomp_src = src;
		if (code != 0) {
			bomp_left = 1;
			bomp_color = *src++;
			bomp_src = src;
		} else {
			bomp_left = 0;
		}
	} else {
		src = bomp_src;
	}
	if (bomp_left != 0) {
		if (bomp_left - 1 == 0) {
			result = bomp_color;
		} else {
			result = 255;
		}
	} else {
		result = *(src++);
		bomp_src = src;
	}

	bomp_num--;
	if (bomp_num == 0) {
		bomp_left = 2;
	}
	
	return result;
}

static void bompInit(const byte *src) {
	bomp_left = 2;
	bomp_src = src;
}

static void bompDecodeMain(byte *dst, const byte *src, int size) {
	bompInit(src);
	while (size--) {
		*dst++ = bompDecode();
	}
}

void Blocky16::decode(byte *dst, const byte *src) {
	_offset1 = ((_deltaBufs[1] - _curBuf) / 2) * 2;
	_offset2 = ((_deltaBufs[0] - _curBuf) / 2) * 2;

	int32 seq_nb = READ_LE_UINT16(src + 16);

	const byte *gfx_data = src + 560;

	if (seq_nb == 0) {
		makeTables47(_width);
		if (src[32] == src[33]) {
			memset(_deltaBufs[0], src[32], _frameSize);
			memset(_deltaBufs[1], src[32], _frameSize);
		} else {
			int count = _frameSize / 2;
			byte *ptr1 = _deltaBufs[0];
			byte *ptr2 = _deltaBufs[1];
			uint16 val = READ_LE_UINT16(src + 32);
			while (count--) {
				*(uint16 *)(ptr1) = *(uint16 *)(ptr2) = val;
				ptr1 += 2; ptr2 += 2;
			};
		
		}
		_prevSeqNb = -1;
	}

	switch(src[18]) {
	case 0:
		memcpy(_curBuf, gfx_data, _frameSize);
		break;
	case 1:
		error("codec47: not implemented decode1 proc");
		break;
	case 2:
		if (seq_nb == _prevSeqNb + 1) {
			decode2(_curBuf, gfx_data, _width, _height, src + 24, src + 40);
		}
		break;
	case 3:
		memcpy(_curBuf, _deltaBufs[1], _frameSize);
		break;
	case 4:
		memcpy(_curBuf, _deltaBufs[0], _frameSize);
		break;
	case 5:
		bompDecodeMain(_curBuf, gfx_data, READ_LE_UINT32(src + 36));
		break;
	case 6:
		{
			int count = _frameSize / 2;
			byte *ptr = _curBuf;
			while (count--) {
				int offset = *gfx_data++ * 2;
				*ptr++ = *(src + 40 + offset);
				*ptr++ = *(src + 40 + offset + 1);
			};
			break;
		}
	case 7:
		error("codec47: not implemented decode7 proc");
		break;
	case 8:
		{
			bompInit(gfx_data);
			int count = _frameSize / 2;
			byte *ptr = _curBuf;
			while (count--) {
				int offset = bompDecode() * 2;
				*ptr++ = *(src + 40 + offset);
				*ptr++ = *(src + 40 + offset + 1);
			};
			break;
		}
	}

	memcpy(dst, _curBuf, _frameSize);

	if (seq_nb == _prevSeqNb + 1) {
		byte *tmp_ptr = NULL;
		if (src[19] == 1) {
			tmp_ptr = _curBuf;
			_curBuf = _deltaBufs[1];
			_deltaBufs[1] = tmp_ptr;
		} else if (src[19] == 2) {
			tmp_ptr = _deltaBufs[0];
			_deltaBufs[0] = _deltaBufs[1];
			_deltaBufs[1] = _curBuf;
			_curBuf = tmp_ptr;
		}
	}
	_prevSeqNb = seq_nb;
}

--- NEW FILE: blocky16.h ---
// Residual - Virtual machine to run LucasArts' 3D adventure games
// Copyright (C) 2003 The ScummVM-Residual Team (www.scummvm.org)
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library 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
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA

#ifndef BLOCKY16_H
#define BLOCKY16_H

#include "bits.h"

class Blocky16 {
private:

	int32 _deltaSize;
	byte *_deltaBufs[2];
	byte *_deltaBuf;
	byte *_curBuf;
	int32 _prevSeqNb;
	int _lastTableWidth;
	const byte *_d_src, *_paramPtr, *_param6_7Ptr;
	int _d_pitch;
	int32 _offset1, _offset2;
	byte *_tableBig;
	byte *_tableSmall;
	int16 _table[256];
	int32 _frameSize;
	int _width, _height;

	void makeTablesInterpolation(int param);
	void makeTables47(int width);
	void level1(byte *d_dst);
	void level2(byte *d_dst);
	void level3(byte *d_dst);
	void decode2(byte *dst, const byte *src, int width, int height, const byte *param_ptr, const byte *param6_7_ptr);

public:
	Blocky16();
	~Blocky16();
	void init(int width, int height);
	void deinit();
	void decode(byte *dst, const byte *src);
};

#endif

--- NEW FILE: smush.cpp ---
// Residual - Virtual machine to run LucasArts' 3D adventure games
// Copyright (C) 2003 The ScummVM-Residual Team (www.scummvm.org)
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library 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
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA

#include "stdafx.h"
#include "bits.h"
#include "debug.h"
#include <cstring>
//#include "file.h"
//#include "util.h"
#include "smush.h"
//#include "system.h"
#include <SDL.h>

Smush::Smush() {
	_nbframes = 0;
	_dst = NULL;
	_width = 0;
	_height = 0;
	_speed = 0;
	_channels = -1;
	_freq = 0;
//	g_system = new OSystem();
//	_mixer = new SoundMixer();
//	_mixer->bindToSystem(g_system);
//	_mixer->setVolume(100);
//	_mixer->setMusicVolume(100);
//	_soundHandle = 0;
}

Smush::~Smush() {
	deinit();
//	delete g_system;
//	delete _mixer;
}

void Smush::init() {
	_frame = 0;
	_channels = -1;
	_freq = 22050;
	_alreadyInit = false;
}

void Smush::deinit() {
}

void Smush::handleBlocky16(byte *src) {
	if (!_alreadyInit) {
		_blocky16.init(_width, _height);
		_alreadyInit = true;
	}
	_blocky16.decode(_dst, src);
}

void decompressVima(const char *src, int16 *dest, int destLen);
void vimaInit();

void Smush::handleWave(const byte *src, uint32 size) {
    
	int16 *dst = new int16[size * _channels];
	decompressVima((char *)src, dst, size * _channels * 2); delete dst;
/*	// convert our LE ones to BE
	for (uint32_t j = 0; j < size * _channels; j++)
		dst[j] = SWAP_BYTES_16(dst[j]);

	int flags = SoundMixer::FLAG_16BITS | SoundMixer::FLAG_AUTOFREE;
	if (_channels == 2)
		flags |= SoundMixer::FLAG_STEREO;
	if (_soundHandle == 0)
		_mixer->newStream(&_soundHandle, (byte *)dst, size * _channels * 2, _freq,
							flags, 300000);
	else
		_mixer->appendStream(_soundHandle, (byte *)dst, size * _channels * 2);
*/
}

void Smush::handleFrame() {
	uint32 tag;
	int32 size;
	int pos = 0;

	tag = _file.readUint32BE();
	if (tag == MKID_BE('ANNO')) {
		size = _file.readUint32BE();
		_file.seek(size, SEEK_CUR);
		tag = _file.readUint32BE();
	}
	assert(tag == MKID_BE('FRME'));
	size = _file.readUint32BE();
	byte *frame = (byte*)malloc(size);
	_file.read(frame, size);
	do {
		if (READ_BE_UINT32(frame + pos) == MKID_BE('Bl16')) {
			handleBlocky16(frame + pos + 8);
			pos += READ_BE_UINT32(frame + pos + 4) + 8;
		} else if (READ_BE_UINT32(frame + pos) == MKID_BE('Wave')) {
			handleWave(frame + pos + 8 + 4, READ_BE_UINT32(frame + pos + 8));
			pos += READ_BE_UINT32(frame + pos + 4) + 8;
		} else {
			error("unknown tag");
		}
	} while (pos < size);
	free(frame);
}

void Smush::handleFramesHeader() {
	uint32 tag;
	int32 size;
	int pos = 0;

	tag = _file.readUint32BE();
	assert(tag == MKID_BE('FLHD'));
	size = _file.readUint32BE();
	byte *f_header = (byte*)malloc(size);
	_file.read(f_header, size);
	do {
		if (READ_BE_UINT32(f_header + pos) == MKID_BE('Bl16')) {
			pos += READ_BE_UINT32(f_header + pos + 4) + 8;
		} else if (READ_BE_UINT32(f_header + pos) == MKID_BE('Wave')) {
			_freq = READ_LE_UINT32(f_header + pos + 8);
			_channels = READ_LE_UINT32(f_header + pos + 12);
			vimaInit();
			pos += 20;
		} else {
			error("unknown tag");
		}
	} while (pos < size);
	free(f_header);
}

void Smush::setupAnim(const char *file, const char *directory) {
	_file.open(file, directory);
	uint32 tag;
	int32 size;
	
	tag = _file.readUint32BE();
	assert(tag == MKID_BE('SANM'));
	size = _file.readUint32BE();
	tag = _file.readUint32BE();
	assert(tag == MKID_BE('SHDR'));
	size = _file.readUint32BE();
	byte *s_header = (byte *)malloc(size);
	_file.read(s_header, size);
	_nbframes = READ_LE_UINT32(s_header + 2);
	_width = READ_LE_UINT16(s_header + 8);
	_height = READ_LE_UINT16(s_header + 10);
	if ((_width != 640) || (_height != 480))
		error("resolution of smush frame other than 640x480 not supported");
	_speed = READ_LE_UINT32(s_header + 14);
	free(s_header);
}

void Smush::play(const char *filename, const char *directory) {

	// Verify the specified file exists
	File f;
	f.open(filename, directory);
	if (!f.isOpen()) {
		warning("Smush::play() File not found %s", filename);
		return;
	}
	f.close();

	// Load the video
	init();
	setupAnim(filename, directory);
	handleFramesHeader();

	SDL_Surface* image;
	image = SDL_CreateRGBSurface(SDL_SWSURFACE, 640, 480, 16, 0x0000f800, 0x000007e0, 0x0000001f, 0x00000000);

	SDL_Rect src;
	src.x = 0;
	src.y = 0;
	src.w = image->w;
	src.h = image->h;

	_dst = (byte *)image->pixels;

	for (int l = 0; l < _nbframes; l++) {
		handleFrame();
		_frame++;

//		SDL_BlitSurface(image, &src, screen, NULL);
//		SDL_UpdateRect(screen, 0, 0, 0, 0);
//		SDL_Delay(_speed / 1000);
	}
}

FILE *File::fopenNoCase(const char *filename, const char *directory, const char *mode) {
	FILE *file;
	char buf[512];
	char *ptr;

	assert(directory);
	strcpy(buf, directory);

#ifdef WIN32
	// Fix for Win98 issue related with game directory pointing to root drive ex. "c:\"
	if ((buf[0] != 0) && (buf[1] == ':') && (buf[2] == '\\') && (buf[3] == 0)) {
		buf[2] = 0;
	}
#endif

	// Record the length of the dir name (so we can cut of anything trailing it
	// later, when we try with different file names).
	const int dirLen = strlen(buf);

	if (dirLen > 0) {
		strcat(buf, "/");	// prevent double /
	}
	strcat(buf, filename);

	file = fopen(buf, mode);
	if (file)
		return file;

	const char *dirs[] = {
		"",
		"video/",
		"VIDEO/",
	};

	for (int dirIdx = 0; dirIdx < ARRAYSIZE(dirs); dirIdx++) {
		buf[dirLen] = 0;
		strcat(buf, dirs[dirIdx]);
		int8 len = strlen(buf);
		strcat(buf, filename);

		ptr = buf + len;
		do
			*ptr = toupper(*ptr);
		while (*ptr++);
		file = fopen(buf, mode);
		if (file)
			return file;

		ptr = buf + len;
		do
			*ptr = tolower(*ptr);
		while (*ptr++);
		file = fopen(buf, mode);
		if (file)
			return file;
	}

	return NULL;
}

File::File() {
	_handle = NULL;
	_ioFailed = false;
	_encbyte = 0;
	_name = 0;
}

File::~File() {
	close();
	delete [] _name;
}

bool File::open(const char *filename, const char *directory, int mode, byte encbyte) {
	if (_handle) {
		warning("File %s already opened", filename);
		return false;
	}

	if (filename == NULL || *filename == 0)
		return false;
	
	// If no directory was specified, use the default directory (if any).
	if (directory == NULL)
		directory = "";

	clearIOFailed();

	if (mode == kFileReadMode) {
		_handle = fopenNoCase(filename, directory, "rb");
		if (_handle == NULL) {
			warning("File %s not found", filename);
			return false;
		}
	}	else {
		warning("Only read/write mode supported!");
		return false;
	}

	_encbyte = encbyte;

	int len = strlen(filename);
	if (_name != 0)
		delete [] _name;
	_name = new char[len+1];
	memcpy(_name, filename, len+1);

	return true;
}

void File::close() {
	if (_handle)
		fclose(_handle);
	_handle = NULL;
}

bool File::isOpen() {
	return _handle != NULL;
}

bool File::ioFailed() {
	return _ioFailed != 0;
}

void File::clearIOFailed() {
	_ioFailed = false;
}

bool File::eof() {
	if (_handle == NULL) {
		error("File is not open!");
		return false;
	}

	return feof(_handle) != 0;
}

uint32 File::pos() {
	if (_handle == NULL) {
		error("File is not open!");
		return 0;
	}

	return ftell(_handle);
}

uint32 File::size() {
	if (_handle == NULL) {
		error("File is not open!");
		return 0;
	}

	uint32 oldPos = ftell(_handle);
	fseek(_handle, 0, SEEK_END);
	uint32 length = ftell(_handle);
	fseek(_handle, oldPos, SEEK_SET);

	return length;
}

void File::seek(int32 offs, int whence) {
	if (_handle == NULL) {
		error("File is not open!");
		return;
	}

	if (fseek(_handle, offs, whence) != 0)
		clearerr(_handle);
}

uint32 File::read(void *ptr, uint32 len) {
	byte *ptr2 = (byte *)ptr;
	uint32 real_len;

	if (_handle == NULL) {
		error("File is not open!");
		return 0;
	}

	if (len == 0)
		return 0;

	real_len = fread(ptr2, 1, len, _handle);
	if (real_len < len) {
		clearerr(_handle);
		_ioFailed = true;
	}

	if (_encbyte != 0) {
		uint32 t_size = real_len;
		do {
			*ptr2++ ^= _encbyte;
		} while (--t_size);
	}

	return real_len;
}

byte File::readByte() {
	byte b;

	if (_handle == NULL) {
		error("File is not open!");
		return 0;
	}

	if (fread(&b, 1, 1, _handle) != 1) {
		clearerr(_handle);
		_ioFailed = true;
	}
	return b ^ _encbyte;
}

uint16 File::readUint16LE() {
	uint16 a = readByte();
	uint16 b = readByte();
	return a | (b << 8);
}

uint32 File::readUint32LE() {
	uint32 a = readUint16LE();
	uint32 b = readUint16LE();
	return (b << 16) | a;
}

uint16 File::readUint16BE() {
	uint16 b = readByte();
	uint16 a = readByte();
	return a | (b << 8);
}

uint32 File::readUint32BE() {
	uint32 b = readUint16BE();
	uint32 a = readUint16BE();
	return (b << 16) | a;
}
--- NEW FILE: smush.h ---
// Residual - Virtual machine to run LucasArts' 3D adventure games
// Copyright (C) 2003 The ScummVM-Residual Team (www.scummvm.org)
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library 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
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA

#ifndef SMUSH_PLAYER_H
#define SMUSH_PLAYER_H

#include "bits.h"
#include "debug.h"
#include <cstring>
#include "blocky16.h"
//#include "mixer.h"

class File {
private:

	FILE * _handle;
	bool _ioFailed;
	uint8 _encbyte;
	char *_name;	// For debugging

	static FILE *fopenNoCase(const char *filename, const char *directory, const char *mode);

public:
	enum {
		kFileReadMode = 1,
	};
	
	File();
	virtual ~File();
	bool open(const char *filename, const char *directory = NULL, int mode = kFileReadMode, byte encbyte = 0);
	void close();
	bool isOpen();
	bool ioFailed();
	void clearIOFailed();
	bool eof();
	uint32 pos();
	uint32 size();
	const char *name() const { return _name; }
	void seek(int32 offs, int whence = SEEK_SET);
	uint32 read(void *ptr, uint32 size);
	uint8 readByte();
	uint16 readUint16LE();
	uint32 readUint32LE();
	uint16 readUint16BE();
	uint32 readUint32BE();
	void setEnc(byte value) { _encbyte = value; }
};

class Smush {
private:
	int32 _nbframes;
	Blocky16 _blocky16;
	File _file;
//	SoundMixer *_mixer;
//	PlayingSoundHandle _soundHandle;

	int32 _frame;
	bool _alreadyInit;
	int32 _speed;
	int _channels;
	int _freq;

	int _width, _height;
	uint8 *_dst;

public:
	Smush();
	~Smush();

	void play(const char *filename, const char *directory);

private:
	void parseNextFrame();
	void handleFramesHeader();
	void handleFrame();
	void handleBlocky16(byte *src);
	void handleWave(const byte *src, uint32 size);
	void init();
	void deinit();
	void setupAnim(const char *file, const char *directory);
	void updateScreen();
};

#endif

--- NEW FILE: vima.cpp ---
// Residual - Virtual machine to run LucasArts' 3D adventure games
// Copyright (C) 2003 The ScummVM-Residual Team (www.scummvm.org)
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library 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
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA

#include "stdafx.h"
#include "bits.h"
#include "debug.h"

static uint16 imcTable1[] = {
  0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e,
  0x0010, 0x0011, 0x0013, 0x0015, 0x0017, 0x0019, 0x001c, 0x001f,
  0x0022, 0x0025, 0x0029, 0x002d, 0x0032, 0x0037, 0x003c, 0x0042,
  0x0049, 0x0050, 0x0058, 0x0061, 0x006b, 0x0076, 0x0082, 0x008f,
  0x009d, 0x00ad, 0x00be, 0x00d1, 0x00e6, 0x00fd, 0x0117, 0x0133,
  0x0151, 0x0173, 0x0198, 0x01c1, 0x01ee, 0x0220, 0x0256, 0x0292,
  0x02d4, 0x031c, 0x036c, 0x03c3, 0x0424, 0x048e, 0x0502, 0x0583,
  0x0610, 0x06ab, 0x0756, 0x0812, 0x08e0, 0x09c3, 0x0abd, 0x0bd0,
  0x0cff, 0x0e4c, 0x0fba, 0x114c, 0x1307, 0x14ee, 0x1706, 0x1954,
  0x1bdc, 0x1ea5, 0x21b6, 0x2515, 0x28ca, 0x2cdf, 0x315b, 0x364b,
  0x3bb9, 0x41b2, 0x4844, 0x4f7e, 0x5771, 0x602f, 0x69ce, 0x7462,
  0x7fff
};

static int8 imcTable2[] = {
  0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
  0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
  0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
  0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
  0x04, 0x04, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x05,
  0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x06,
  0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
  0x06, 0x06, 0x06, 0x06, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
  0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07
};

static int8 imcOtherTable1[] = {
  -1, 4, -1, 4
};

static int8 imcOtherTable2[] = {
  -1, -1, 2, 6, -1, -1, 2, 6
};

static int8 imcOtherTable3[] = {
  -1, -1, -1, -1, 1, 2, 4, 6,
  -1, -1, -1, -1, 1, 2, 4, 6
};

static int8 imcOtherTable4[] = {
  -1, -1, -1, -1, -1, -1, -1, -1,
  1, 1, 1, 2, 2, 4, 5, 6,
  -1, -1, -1, -1, -1, -1, -1, -1,
  1, 1, 1, 2, 2, 4, 5, 6
};

static int8 imcOtherTable5[] = {
  -1, -1, -1, -1, -1, -1, -1, -1,
  -1, -1, -1, -1, -1, -1, -1, -1,
  1, 1, 1, 1, 1, 2, 2, 2,
  2, 4, 4, 4, 5, 5, 6, 6,
  -1, -1, -1, -1, -1, -1, -1, -1,
  -1, -1, -1, -1, -1, -1, -1, -1,
  1, 1, 1, 1, 1, 2, 2, 2,
  2, 4, 4, 4, 5, 5, 6, 6
};

static int8 imcOtherTable6[] = {
  -1, -1, -1, -1, -1, -1, -1, -1,
  -1, -1, -1, -1, -1, -1, -1, -1,
  -1, -1, -1, -1, -1, -1, -1, -1,
  -1, -1, -1, -1, -1, -1, -1, -1,
  1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 2, 2, 2, 2, 2, 2,
  2, 2, 4, 4, 4, 4, 4, 4,
  5, 5, 5, 5, 6, 6, 6, 6,
  -1, -1, -1, -1, -1, -1, -1, -1,
  -1, -1, -1, -1, -1, -1, -1, -1,
  -1, -1, -1, -1, -1, -1, -1, -1,
  -1, -1, -1, -1, -1, -1, -1, -1,
  1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 2, 2, 2, 2, 2, 2,
  2, 2, 4, 4, 4, 4, 4, 4,
  5, 5, 5, 5, 6, 6, 6, 6
};

static int8 *offsets[] = {
	imcOtherTable1, imcOtherTable2, imcOtherTable3,
	imcOtherTable4, imcOtherTable5, imcOtherTable6
};

static uint16 destTable[5786];

void vimaInit() {
	int destTableStartPos, incer;
	for (destTableStartPos = 0, incer = 0; destTableStartPos < 64; destTableStartPos++, incer++) {
	unsigned int destTablePos, imcTable1Pos;
		for (imcTable1Pos = 0, destTablePos = destTableStartPos;
		imcTable1Pos < sizeof(imcTable1) / sizeof(imcTable1[0]);
		imcTable1Pos++, destTablePos += 64) {
			int put = 0, count, tableValue;
		for (count = 32, tableValue = imcTable1[imcTable1Pos]; count != 0;
			count >>= 1, tableValue >>= 1) {
		if ((incer & count) != 0)
			put += tableValue;
		}
		destTable[destTablePos] = put;
		}
	}
}

void decompressVima(const char *src, int16 *dest, int destLen) {
	int numChannels = 1;
	uint8 sBytes[2];
	int16 sWords[2];

	sBytes[0] = *(uint8*)(src++);
	if (sBytes[0] & 0x80) {
		sBytes[0] = ~sBytes[0];
		numChannels = 2;
	}
	sWords[0] = READ_BE_UINT16(src);
	src += 2;
	if (numChannels > 1) {
		sBytes[1] = *(uint8*)(src++);
		sWords[1] = READ_BE_UINT16(src);
		src += 2;
	}

	int numSamples = destLen / (numChannels * 2);
	int bits = READ_BE_UINT16(src);
	int bitPtr = 0;
	src += 2;

	for (int channel = 0; channel < numChannels; channel++) {
		int16 *destPos = dest + channel;
		int currTablePos = sBytes[channel];
		int outputWord = sWords[channel];

		for (int sample = 0; sample < numSamples; sample++) {
			int numBits = imcTable2[currTablePos];
			bitPtr += numBits;
			int highBit = 1 << (numBits - 1);
			int lowBits = highBit - 1;
			int val = (bits >> (16 - bitPtr)) & (highBit | lowBits);

			if (bitPtr > 7) {
				bits = ((bits & 0xff) << 8) | *(uint8*)(src++);
				bitPtr -= 8;
			}

			if (val & highBit)
				val ^= highBit;
			else
				highBit = 0;

			if (val == lowBits) {
				outputWord = ((signed short) (bits << bitPtr) & 0xffffff00);
				bits = ((bits & 0xff) << 8) | *(uint8*)(src++);
				outputWord |= ((bits >> (8 - bitPtr)) & 0xff);
				bits = ((bits & 0xff) << 8) | *(uint8*)(src++);
			} else {
				int index = (val << (7 - numBits)) | (currTablePos << 6);
				int delta = destTable[index];

				if (val != 0)
					delta += (imcTable1[currTablePos] >> (numBits - 1));
				if (highBit != 0)
					delta = -delta;

				outputWord += delta;
				if (outputWord < -0x8000)
					outputWord = -0x8000;
				else if (outputWord > 0x7fff)
					outputWord = 0x7fff;
			}

			*destPos = outputWord;
			destPos += numChannels;

			currTablePos += offsets[numBits - 2][val];

			if (currTablePos < 0)
				currTablePos = 0;
			else if (currTablePos > 88)
				currTablePos = 88;
		}
	}
}

Index: bitmap.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/bitmap.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- bitmap.cpp	21 Sep 2003 09:51:59 -0000	1.10
+++ bitmap.cpp	12 Dec 2003 08:39:07 -0000	1.11
@@ -34,13 +34,13 @@
   if (len < 8 || memcmp(data, "BM  F\0\0\0", 8) != 0)
     error("Invalid magic loading bitmap\n");
 
-  int codec = get_LE_uint32(data + 8);
-  num_images_ = get_LE_uint32(data + 16);
-  x_ = get_LE_uint32(data + 20);
-  y_ = get_LE_uint32(data + 24);
-  format_ = get_LE_uint32(data + 32);
-  width_ = get_LE_uint32(data + 128);
-  height_ = get_LE_uint32(data + 132);
+  int codec = READ_LE_UINT32(data + 8);
+  num_images_ = READ_LE_UINT32(data + 16);
+  x_ = READ_LE_UINT32(data + 20);
+  y_ = READ_LE_UINT32(data + 24);
+  format_ = READ_LE_UINT32(data + 32);
+  width_ = READ_LE_UINT32(data + 128);
+  height_ = READ_LE_UINT32(data + 132);
   curr_image_ = 0;
 
   data_ = new char*[num_images_];
@@ -52,7 +52,7 @@
       pos += 2 * width_ * height_ + 8;
     }
     else if (codec == 3) {
-      int compressed_len = get_LE_uint32(data + pos);
+      int compressed_len = READ_LE_UINT32(data + pos);
       decompress_codec3(data + pos + 4, data_[i]);
       pos += compressed_len + 12;
     }
@@ -97,9 +97,9 @@
     glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
   } else {
     for (int i = 0; i < (width_ * height_); i++) {
-      uint16_t val = get_LE_uint16(data_[curr_image_] + 2 * i);
-      ((uint16_t *) data_[curr_image_])[i] =
-	0xffff - ((uint32_t) val) * 0x10000 / 100 / (0x10000 - val);
+      uint16 val = READ_LE_UINT16(data_[curr_image_] + 2 * i);
+      ((uint16 *) data_[curr_image_])[i] =
+	0xffff - ((uint32) val) * 0x10000 / 100 / (0x10000 - val);
     }
     tex_ids_ = NULL;
   }
@@ -190,14 +190,14 @@
   bitstr_len--; \
   bitstr_value >>= 1; \
   if (bitstr_len == 0) { \
-    bitstr_value = get_LE_uint16(compressed); \
+    bitstr_value = READ_LE_UINT16(compressed); \
     bitstr_len = 16; \
     compressed += 2; \
   } \
   do {} while (0)
 
 static void decompress_codec3(const char *compressed, char *result) {
-  int bitstr_value = get_LE_uint16(compressed);
+  int bitstr_value = READ_LE_UINT16(compressed);
   int bitstr_len = 16;
   compressed += 2;
   bool bit;
@@ -214,15 +214,15 @@
 	copy_len = 2 * bit;
 	GET_BIT;
 	copy_len += bit + 3;
-	copy_offset = get_uint8(compressed++) - 0x100;
+	copy_offset = *(uint8 *)(compressed++) - 0x100;
       }
       else {
-	copy_offset = (get_uint8(compressed) |
-		       (get_uint8(compressed + 1) & 0xf0) << 4) - 0x1000;
-	copy_len = (get_uint8(compressed + 1) & 0xf) + 3;
+	copy_offset = (*(uint8 *)(compressed) |
+		       (*(uint8 *)(compressed + 1) & 0xf0) << 4) - 0x1000;
+	copy_len = (*(uint8 *)(compressed + 1) & 0xf) + 3;
 	compressed += 2;
 	if (copy_len == 3) {
-	  copy_len = get_uint8(compressed++) + 1;
+	  copy_len = *(uint8 *)(compressed++) + 1;
 	  if (copy_len == 1)
 	    return;
 	}

Index: bits.h
===================================================================
RCS file: /cvsroot/scummvm/residual/bits.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- bits.h	25 Aug 2003 19:20:51 -0000	1.5
+++ bits.h	12 Dec 2003 08:39:07 -0000	1.6
@@ -22,42 +22,327 @@
 #include "stdafx.h"
 #include "vector3d.h"
 
-#ifdef _MSC_VER
-	typedef unsigned char byte;
-	typedef unsigned char uint8_t;
-	typedef unsigned short uint16_t;
-	typedef signed short int16_t;
-	typedef unsigned long uint32_t;
-	typedef unsigned int uint_t;
-	typedef signed char int8_t;
-	typedef signed short int16_t;
-	typedef signed long int32_t;
+#include <stdlib.h>
+#include <stdio.h>
+
+// Use config.h, generated by configure
+#if defined(HAVE_CONFIG_H)
+#include "config.h"
 #endif
 
-inline uint8_t get_uint8(const char *data) {
-  return *(reinterpret_cast<const unsigned char *>(data));
-}
+#ifndef PI
+#define PI 3.14159265358979323846
+#endif
 
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+#define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0])))
 
-inline uint32_t get_LE_uint32(const char *data) {
-  const unsigned char *udata = reinterpret_cast<const unsigned char *>(data);
-  return udata[0] | (udata[1] << 8) | (udata[2] << 16) | (udata[3] << 24);
-}
+#if defined(_MSC_VER)
 
-inline uint16_t get_LE_uint16(const char *data) {
-  const unsigned char *udata = reinterpret_cast<const unsigned char *>(data);
-  return udata[0] | (udata[1] << 8);
-}
+	#define scumm_stricmp stricmp
+	#define scumm_strnicmp strnicmp
+	#define snprintf _snprintf
 
-inline uint16_t get_BE_uint16(const char *data) {
-  return *(reinterpret_cast<const uint16_t *>(data));
+	#if defined(CHECK_HEAP)
+	#undef CHECK_HEAP
+	#define CHECK_HEAP checkHeap();
+	#else
+	#define CHECK_HEAP
+	#endif
+
+	#define SYSTEM_LITTLE_ENDIAN
+
+	#define FORCEINLINE __forceinline
+	#define NORETURN _declspec(noreturn)
+
+	typedef unsigned char byte;
+	typedef unsigned char uint8;
+	typedef unsigned short uint16;
+	typedef unsigned long uint32;
+	typedef unsigned int uint;
+	typedef signed char int8;
+	typedef signed short int16;
+	typedef signed long int32;
+	
+	#define START_PACK_STRUCTS pack(push, 1)
+	#define END_PACK_STRUCTS	 pack(pop)
+	#define GCC_PACK
+
+#elif defined(__MINGW32__)
+
+	#define CHECK_HEAP
+	#define SYSTEM_LITTLE_ENDIAN
+
+	#define FORCEINLINE inline
+	#define NORETURN __attribute__((__noreturn__))
+	#define GCC_PACK __attribute__((packed))
+	#define _HEAPOK 0
+
+	typedef unsigned char byte;
+	typedef unsigned char uint8;
+	typedef unsigned short uint16;
+	typedef unsigned int uint32;
+	typedef unsigned int uint;
+	typedef signed char int8;
+	typedef signed short int16;
+	typedef signed int int32;
+
+	#define START_PACK_STRUCTS pack (push, 1)
+	#define END_PACK_STRUCTS	 pack(pop)
+
+#elif defined(UNIX)
+
+	#define CHECK_HEAP
+
+	#ifdef X11_BACKEND
+
+	// You need to set this manually if necessary
+//	#define SCUMM_LITTLE_ENDIAN
+	
+	#else
+	/* need this for the SDL_BYTEORDER define */
+	#include <SDL_byteorder.h>
+
+	#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+	#define SCUMM_LITTLE_ENDIAN
+	#elif SDL_BYTEORDER == SDL_BIG_ENDIAN
+	#define SCUMM_BIG_ENDIAN
+	#else
+	#error Neither SDL_BIG_ENDIAN nor SDL_LITTLE_ENDIAN is set.
+	#endif
+	#endif
+
+	// You need to set this manually if necessary
+//	#define SCUMM_NEED_ALIGNMENT
+
+	#define FORCEINLINE inline
+	#define CDECL 
+
+	#ifndef HAVE_CONFIG_H
+	typedef unsigned char byte;
+	typedef unsigned char uint8;
+	typedef unsigned short uint16;
+	typedef unsigned int uint;
+	typedef unsigned int uint32;
+	typedef signed char int8;
+	typedef signed short int16;
+	typedef signed int int32;
+	#endif
+
+	#if defined(__DECCXX) // Assume alpha architecture
+	#define INVERSE_MKID
+	#define SCUMM_NEED_ALIGNMENT
+	#endif
+
+	#if defined(__GNUC__)
+	#define START_PACK_STRUCTS
+	#define END_PACK_STRUCTS
+	#define GCC_PACK __attribute__((packed))
+	#define NORETURN __attribute__((__noreturn__)) 
+	#else
+	#define START_PACK_STRUCTS pack (1)
+	#define END_PACK_STRUCTS	 pack ()
+	#define GCC_PACK
+	#define NORETURN
+	#endif
+
+#elif defined(__MORPHOS__)
+	#define scumm_stricmp stricmp
+	#define scumm_strnicmp strnicmp
+	#define CHECK_HEAP
+
+	#define SCUMM_BIG_ENDIAN
+	#define SCUMM_NEED_ALIGNMENT
+
+	#define FORCEINLINE inline
+	#define CDECL
+
+	typedef unsigned char byte;
+	typedef unsigned char uint8;
+	typedef unsigned short uint16;
+	typedef unsigned long uint32;
+	typedef unsigned int uint;
+	typedef signed char int8;
+	typedef signed short int16;
+	typedef signed long int32;
+
+	#if defined(__GNUC__)
+		#define START_PACK_STRUCTS
+		#define END_PACK_STRUCTS
+		#define GCC_PACK __attribute__((packed))
+		#define NORETURN __attribute__((__noreturn__))
+	#else
+		#define START_PACK_STRUCTS pack (1)
+		#define END_PACK_STRUCTS	 pack ()
+		#define GCC_PACK
+		#define NORETURN
+	#endif
+	#define main morphos_main
+
+#elif defined(__DC__)
+
+	#define CHECK_HEAP
+	#define SCUMM_LITTLE_ENDIAN
+	#define SCUMM_NEED_ALIGNMENT
+
+	#define FORCEINLINE inline
+	#define NORETURN __attribute__((__noreturn__))
+	#define GCC_PACK __attribute__((packed))
+	#define CDECL
+
+	typedef unsigned char byte;
+	typedef unsigned char uint8;
+	typedef unsigned short uint16;
+	typedef unsigned long uint32;
+	typedef unsigned int uint;
+	typedef signed char int8;
+	typedef signed short int16;
+	typedef signed long int32;
+
+	#define START_PACK_STRUCTS pack (push, 1)
+	#define END_PACK_STRUCTS	 pack(pop)
+
+#else
+	#error No system type defined
+#endif
+
+FORCEINLINE uint32 SWAP_BYTES_32(uint32 a) {
+	return ((a >> 24) & 0x000000FF) |
+		   ((a >>  8) & 0x0000FF00) |
+		   ((a <<  8) & 0x00FF0000) |
+		   ((a << 24) & 0xFF000000);
 }
 
-inline uint32_t get_BE_uint32(const char *data) {
-  return *(reinterpret_cast<const uint32_t *>(data));
+FORCEINLINE uint16 SWAP_BYTES_16(uint16 a) {
+	return ((a >> 8) & 0x00FF) + ((a << 8) & 0xFF00);
 }
 
+
+#if defined(SYSTEM_LITTLE_ENDIAN)
+
+	#define PROTO_MKID(a) ((uint32) \
+			(((a) >> 24) & 0x000000FF) | \
+			(((a) >>  8) & 0x0000FF00) | \
+			(((a) <<  8) & 0x00FF0000) | \
+			(((a) << 24) & 0xFF000000))
+	#define PROTO_MKID_BE(a) ((uint32)(a))
+
+	#if defined(INVERSE_MKID)
+	#  define MKID(a) PROTO_MKID_BE(a)
+	#  define MKID_BE(a) PROTO_MKID(a)
+	#else
+	#  define MKID(a) PROTO_MKID(a)
+	#  define MKID_BE(a) PROTO_MKID_BE(a)
+	#endif
+
+	#define READ_UINT32(a) READ_LE_UINT32(a)
+
+	#define FROM_LE_32(a) (a)
+	#define FROM_LE_16(a) (a)
+
+	#define TO_LE_32(a) (a)
+	#define TO_LE_16(a) (a)
+
+	#define TO_BE_32(a) SWAP_BYTES_32(a)
+	#define TO_BE_16(a) SWAP_BYTES_16(a)
+
+#elif defined(SYSTEM_BIG_ENDIAN)
+
+	#define MKID(a) (a)
+	#define MKID_BE(a) (a)
+
+	#define READ_UINT32(a) READ_BE_UINT32(a)
+
+	#define FROM_LE_32(a) SWAP_BYTES_32(a)
+	#define FROM_LE_16(a) SWAP_BYTES_16(a)
+
+	#define TO_LE_32(a) SWAP_BYTES_32(a)
+	#define TO_LE_16(a) SWAP_BYTES_16(a)
+
+	#define TO_BE_32(a) (a)
+	#define TO_BE_16(a) (a)
+
+#else
+
+	#error No endianness defined
+
+#endif
+
+
+#if defined(SYSTEM_NEED_ALIGNMENT) || defined(SYSTEM_BIG_ENDIAN)
+	FORCEINLINE uint16 READ_LE_UINT16(const void *ptr) {
+		const byte *b = (const byte *)ptr;
+		return (b[1] << 8) + b[0];
+	}
+	FORCEINLINE uint32 READ_LE_UINT32(const void *ptr) {
+		const byte *b = (const byte *)ptr;
+		return (b[3] << 24) + (b[2] << 16) + (b[1] << 8) + (b[0]);
+	}
+	FORCEINLINE void WRITE_LE_UINT16(void *ptr, uint16 value) {
+		byte *b = (byte *)ptr;
+		b[0] = (byte)(value >> 0);
+		b[1] = (byte)(value >> 8);
+	}
+	FORCEINLINE void WRITE_LE_UINT32(void *ptr, uint32 value) {
+		byte *b = (byte *)ptr;
+		b[0] = (byte)(value >>  0);
+		b[1] = (byte)(value >>  8);
+		b[2] = (byte)(value >> 16);
+		b[3] = (byte)(value >> 24);
+	}
+#else
+	FORCEINLINE uint16 READ_LE_UINT16(const void *ptr) {
+		return *(const uint16 *)(ptr);
+	}
+	FORCEINLINE uint32 READ_LE_UINT32(const void *ptr) {
+		return *(const uint32 *)(ptr);
+	}
+	FORCEINLINE void WRITE_LE_UINT16(void *ptr, uint16 value) {
+		*(uint16 *)(ptr) = value;
+	}
+	FORCEINLINE void WRITE_LE_UINT32(void *ptr, uint32 value) {
+		*(uint32 *)(ptr) = value;
+	}
+#endif
+
+
+#if defined(SYSTEM_NEED_ALIGNMENT) || defined(SYSTEM_LITTLE_ENDIAN)
+	FORCEINLINE uint16 READ_BE_UINT16(const void *ptr) {
+		const byte *b = (const byte *)ptr;
+		return (b[0] << 8) + b[1];
+	}
+	FORCEINLINE uint32 READ_BE_UINT32(const void *ptr) {
+		const byte *b = (const byte*)ptr;
+		return (b[0] << 24) + (b[1] << 16) + (b[2] << 8) + (b[3]);
+	}
+	FORCEINLINE void WRITE_BE_UINT16(void *ptr, uint16 value) {
+		byte *b = (byte *)ptr;
+		b[0] = (byte)(value >> 8);
+		b[1] = (byte)(value >> 0);
+	}
+	FORCEINLINE void WRITE_BE_UINT32(void *ptr, uint32 value) {
+		byte *b = (byte *)ptr;
+		b[0] = (byte)(value >> 24);
+		b[1] = (byte)(value >> 16);
+		b[2] = (byte)(value >>  8);
+		b[3] = (byte)(value >>  0);
+	}
+#else
+	FORCEINLINE uint16 READ_BE_UINT16(const void *ptr) {
+		return *(const uint16 *)(ptr);
+	}
+	FORCEINLINE uint32 READ_BE_UINT32(const void *ptr) {
+		return *(const uint32 *)(ptr);
+	}
+	FORCEINLINE void WRITE_BE_UINT16(void *ptr, uint16 value) {
+		*(uint16 *)(ptr) = value;
+	}
+	FORCEINLINE void WRITE_BE_UINT32(void *ptr, uint32 value) {
+		*(uint32 *)(ptr) = value;
+	}
+#endif
+
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+
 inline float get_float(const char *data) {
   const unsigned char *udata = reinterpret_cast<const unsigned char *>(data);
   unsigned char fdata[4];
@@ -69,24 +354,6 @@
 }
 
 #else
-
-inline uint32_t get_LE_uint32(const char *data) {
-  return *(reinterpret_cast<const uint32_t *>(data));
-}
-
-inline uint16_t get_LE_uint16(const char *data) {
-  return *(reinterpret_cast<const uint16_t *>(data));
-}
-
-inline uint16_t get_BE_uint16(const char *data) {
-  const unsigned char *udata = reinterpret_cast<const unsigned char *>(data);
-  return (udata[0] << 8) | udata[1];
-}
-
-inline uint32_t get_BE_uint32(const char *data) {
-  const unsigned char *udata = reinterpret_cast<const unsigned char *>(data);
-  return (udata[0] << 24) | (udata[1] << 16) | (udata[2] << 8) | udata[3];
-}
 
 inline float get_float(const char *data) {
   return *(reinterpret_cast<const float *>(data));

Index: keyframe.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/keyframe.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- keyframe.cpp	28 Aug 2003 01:55:48 -0000	1.3
+++ keyframe.cpp	12 Dec 2003 08:39:07 -0000	1.4
@@ -33,16 +33,16 @@
 }
 
 void KeyframeAnim::loadBinary(const char *data, int len) {
-  flags_ = get_LE_uint32(data + 40);
-  type_ = get_LE_uint32(data + 48);
+  flags_ = READ_LE_UINT32(data + 40);
+  type_ = READ_LE_UINT32(data + 48);
   fps_ = get_float(data + 52);
-  numFrames_ = get_LE_uint32(data + 56);
-  numJoints_ = get_LE_uint32(data + 60);
-  numMarkers_ = get_LE_uint32(data + 68);
+  numFrames_ = READ_LE_UINT32(data + 56);
+  numJoints_ = READ_LE_UINT32(data + 60);
+  numMarkers_ = READ_LE_UINT32(data + 68);
   markers_ = new Marker[numMarkers_];
   for (int i = 0; i < numMarkers_; i++) {
     markers_[i].frame_ = get_float(data + 72 + 4 * i);
-    markers_[i].val_ = get_LE_uint32(data + 104 + 4 * i);
+    markers_[i].val_ = READ_LE_UINT32(data + 104 + 4 * i);
   }
 
   nodes_ = new KeyframeNode*[numJoints_];
@@ -51,7 +51,7 @@
   const char *dataEnd = data + len;
   data += 180;
   while (data < dataEnd) {
-    int nodeNum = get_LE_uint32(data + 32);
+    int nodeNum = READ_LE_UINT32(data + 32);
     nodes_[nodeNum] = new KeyframeNode;
     nodes_[nodeNum]->loadBinary(data);
   }
@@ -111,7 +111,7 @@
 
 void KeyframeAnim::KeyframeEntry::loadBinary(const char *&data) {
   frame_ = get_float(data);
-  flags_ = get_LE_uint32(data + 4);
+  flags_ = READ_LE_UINT32(data + 4);
   pos_ = get_vector3d(data + 8);
   pitch_ = get_float(data + 20);
   yaw_ = get_float(data + 24);
@@ -125,7 +125,7 @@
 
 void KeyframeAnim::KeyframeNode::loadBinary(const char *&data) {
   std::memcpy(meshName_, data, 32);
-  numEntries_ = get_LE_uint32(data + 36);
+  numEntries_ = READ_LE_UINT32(data + 36);
   data += 44;
   entries_ = new KeyframeEntry[numEntries_];
   for (int i = 0; i < numEntries_; i++)

Index: lab.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lab.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- lab.cpp	24 Aug 2003 17:56:03 -0000	1.3
+++ lab.cpp	12 Dec 2003 08:39:07 -0000	1.4
@@ -38,8 +38,8 @@
     return false;
   }
 
-  int num_entries = get_LE_uint32(header + 8);
-  int string_table_size = get_LE_uint32(header + 12);
+  int num_entries = READ_LE_UINT32(header + 8);
+  int string_table_size = READ_LE_UINT32(header + 12);
 
   char *string_table = new char[string_table_size];
   std::fseek(f_, 16 * (num_entries + 1), SEEK_SET);
@@ -52,9 +52,9 @@
 #endif
   for (int i = 0; i < num_entries; i++) {
     std::fread(binary_entry, 1, 16, f_);
-    int fname_offset = get_LE_uint32(binary_entry);
-    int start = get_LE_uint32(binary_entry + 4);
-    int size = get_LE_uint32(binary_entry + 8);
+    int fname_offset = READ_LE_UINT32(binary_entry);
+    int start = READ_LE_UINT32(binary_entry + 4);
+    int size = READ_LE_UINT32(binary_entry + 8);
 
     std::string fname = string_table + fname_offset;
     std::transform(fname.begin(), fname.end(), fname.begin(), tolower);

Index: lua.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua.cpp,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- lua.cpp	12 Oct 2003 13:04:46 -0000	1.33
+++ lua.cpp	12 Dec 2003 08:39:07 -0000	1.34
@@ -27,6 +27,7 @@
 #include "engine.h"
 #include "mixer.h"
 #include "sound.h"
+#include "smush.h"
 #include "textobject.h"
 #include <SDL_keysym.h>
 #include <SDL_keyboard.h>
@@ -1020,6 +1021,16 @@
  lua_pushnumber(100);	// Dummy Y
 }
 
+static void StartMovie() {
+	Smush player;
+	player.play("intro.snm", "");
+}
+
+static void StartFullscreenMovie() {
+	Smush player;
+	player.play("intro.snm", "");
+}
+
 // Stub function for builtin functions not yet implemented
 
 static void stubWarning() {
@@ -1163,9 +1174,7 @@
   "IsMoviePlaying",
   "PauseMovie",
   "StopMovie",
-  "StartMovie",
   "IsFullscreenMoviePlaying",
-  "StartFullscreenMovie",
   "PreviousSetup",
   "NextSetup",
   "UnLockSet",
@@ -1454,6 +1463,8 @@
   { "SetActorLookRate", SetActorLookRate },
   { "GetActorLookRate", GetActorLookRate },
   { "SetActorHead", SetActorHead },
+  { "StartMovie", StartMovie },
+  { "StartFullscreenMovie", StartFullscreenMovie },
 };
 
 void register_lua() {

Index: material.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/material.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- material.cpp	5 Oct 2003 17:45:46 -0000	1.5
+++ material.cpp	12 Dec 2003 08:39:07 -0000	1.6
@@ -28,12 +28,12 @@
   if (len < 4 || memcmp(data, "MAT ", 4) != 0)
     error("invalid magic loading texture\n");
 
-  num_images_ = get_LE_uint32(data + 12);
+  num_images_ = READ_LE_UINT32(data + 12);
   curr_image_ = 0;
   textures_ = new GLuint[num_images_];
   glGenTextures(num_images_, textures_);
-  width_ = get_LE_uint32(data + 76 + num_images_ * 40);
-  height_ = get_LE_uint32(data + 80 + num_images_ * 40);
+  width_ = READ_LE_UINT32(data + 76 + num_images_ * 40);
+  height_ = READ_LE_UINT32(data + 80 + num_images_ * 40);
 
   if ((width_ == 0) || (height_ == 0)) {
     warning("bad texture size (%dx%d) for texture %s\n", width_, height_, filename);
@@ -45,11 +45,11 @@
     char *texdatapos = texdata;
     for (int y = 0; y < height_; y++) {
       for (int x = 0; x < width_; x++) {
-	int col = get_uint8(data);
+	int col = *(uint8 *)(data);
 	if (col == 0)
 	  memset(texdatapos, 0, 4); // transparent
 	else {
-	  memcpy(texdatapos, cmap.colors + 3 * get_uint8(data), 3);
+	  memcpy(texdatapos, cmap.colors + 3 * *(uint8 *)(data), 3);
 	  texdatapos[3] = '\xff'; // fully opaque
 	}
 	texdatapos += 4;

Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/mixer.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- mixer.cpp	24 Aug 2003 17:56:03 -0000	1.4
+++ mixer.cpp	12 Dec 2003 08:39:07 -0000	1.5
@@ -264,7 +264,7 @@
 
 void mixerCallback(void *userdata, Uint8 *stream, int len) {
   Mixer *m = static_cast<Mixer *>(userdata);
-  int16_t *samples = reinterpret_cast<int16_t *>(stream);
+  int16 *samples = reinterpret_cast<int16 *>(stream);
   m->getAudio(samples, len / 2);
 }
 
@@ -409,7 +409,7 @@
   return ! voiceSounds_.empty();
 }
 
-void Mixer::getAudio(int16_t *data, int numSamples) {
+void Mixer::getAudio(int16 *data, int numSamples) {
   memset(data, 0, numSamples * 2);
   for (sound_list::iterator i = voiceSounds_.begin();
        i != voiceSounds_.end(); ) {

Index: mixer.h
===================================================================
RCS file: /cvsroot/scummvm/residual/mixer.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- mixer.h	24 Aug 2003 17:56:03 -0000	1.4
+++ mixer.h	12 Dec 2003 08:39:07 -0000	1.5
@@ -43,14 +43,14 @@
 
 private:
   Mixer();
-  void getAudio(int16_t *data, int numSamples);
+  void getAudio(int16 *data, int numSamples);
 
   static Mixer *instance_;
   typedef std::list<ResPtr<Sound> > sound_list;
   sound_list voiceSounds_, sfxSounds_;
   ResPtr<Sound> musicSound_, seqSound_;
 
-  friend void mixerCallback(void *userdata, Uint8 *stream, int len);
+  friend void mixerCallback(void *userdata, uint8 *stream, int len);
 };
 
 #endif

Index: model.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/model.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- model.cpp	5 Oct 2003 17:45:46 -0000	1.11
+++ model.cpp	12 Dec 2003 08:39:07 -0000	1.12
@@ -39,7 +39,7 @@
 }
 
 void Model::loadBinary(const char *data, const CMap &cmap) {
-  numMaterials_ = get_LE_uint32(data + 4);
+  numMaterials_ = READ_LE_UINT32(data + 4);
   data += 8;
   materials_ = new ResPtr<Material>[numMaterials_];
   for (int i = 0; i < numMaterials_; i++) {
@@ -47,12 +47,12 @@
     data += 32;
   }
   data += 32;			// skip name
-  numGeosets_ = get_LE_uint32(data + 4);
+  numGeosets_ = READ_LE_UINT32(data + 4);
   data += 8;
   geosets_ = new Geoset[numGeosets_];
   for (int i = 0; i < numGeosets_; i++)
     geosets_[i].loadBinary(data, materials_);
-  numHierNodes_ = get_LE_uint32(data + 4);
+  numHierNodes_ = READ_LE_UINT32(data + 4);
   data += 8;
   rootHierNode_ = new HierNode[numHierNodes_];
   for (int i = 0; i < numHierNodes_; i++)
@@ -69,7 +69,7 @@
 
 void Model::Geoset::loadBinary(const char *&data,
 			       ResPtr<Material> *materials) {
-  numMeshes_ = get_LE_uint32(data);
+  numMeshes_ = READ_LE_UINT32(data);
   data += 4;
   meshes_ = new Mesh[numMeshes_];
   for (int i = 0; i < numMeshes_; i++)
@@ -83,12 +83,12 @@
 void Model::Mesh::loadBinary(const char *&data,
 			     ResPtr<Material> *materials) {
   memcpy(name_, data, 32);
-  geometryMode_ = get_LE_uint32(data + 36);
-  lightingMode_ = get_LE_uint32(data + 40);
-  textureMode_ = get_LE_uint32(data + 44);
-  numVertices_ = get_LE_uint32(data + 48);
-  numTextureVerts_ = get_LE_uint32(data + 52);
-  numFaces_ = get_LE_uint32(data + 56);
+  geometryMode_ = READ_LE_UINT32(data + 36);
+  lightingMode_ = READ_LE_UINT32(data + 40);
+  textureMode_ = READ_LE_UINT32(data + 44);
+  numVertices_ = READ_LE_UINT32(data + 48);
+  numTextureVerts_ = READ_LE_UINT32(data + 52);
+  numFaces_ = READ_LE_UINT32(data + 56);
   vertices_ = new float[3 * numVertices_];
   verticesI_ = new float[numVertices_];
   vertNormals_ = new float[3 * numVertices_];
@@ -115,7 +115,7 @@
     vertNormals_[i] = get_float(data);
     data += 4;
   }
-  shadow_ = get_LE_uint32(data);
+  shadow_ = READ_LE_UINT32(data);
   radius_ = get_float(data + 8);
   data += 36;
 }
@@ -189,20 +189,20 @@
 }
 
 void Model::Face::loadBinary(const char *&data, ResPtr<Material> *materials) {
-  type_ = get_LE_uint32(data + 4);
-  geo_ = get_LE_uint32(data + 8);
-  light_ = get_LE_uint32(data + 12);
-  tex_ = get_LE_uint32(data + 16);
-  numVertices_ = get_LE_uint32(data + 20);
-  int texPtr = get_LE_uint32(data + 28);
-  int materialPtr = get_LE_uint32(data + 32);
+  type_ = READ_LE_UINT32(data + 4);
+  geo_ = READ_LE_UINT32(data + 8);
+  light_ = READ_LE_UINT32(data + 12);
+  tex_ = READ_LE_UINT32(data + 16);
+  numVertices_ = READ_LE_UINT32(data + 20);
+  int texPtr = READ_LE_UINT32(data + 28);
+  int materialPtr = READ_LE_UINT32(data + 32);
   extraLight_ = get_float(data + 48);
   normal_ = get_vector3d(data + 64);
   data += 76;
 
   vertices_ = new int[numVertices_];
   for (int i = 0; i < numVertices_; i++) {
-    vertices_[i] = get_LE_uint32(data);
+    vertices_[i] = READ_LE_UINT32(data);
     data += 4;
   }
   if (texPtr == 0)
@@ -210,14 +210,14 @@
   else {
     texVertices_ = new int[numVertices_];
     for (int i = 0; i < numVertices_; i++) {
-      texVertices_[i] = get_LE_uint32(data);
+      texVertices_[i] = READ_LE_UINT32(data);
       data += 4;
     }
   }
   if (materialPtr == 0)
     material_ = 0;
   else {
-    material_ = materials[get_LE_uint32(data)];
+    material_ = materials[READ_LE_UINT32(data)];
     data += 4;
   }
 }
@@ -231,18 +231,18 @@
 				 Model::HierNode *hierNodes,
 				 const Geoset &g) {
   memcpy(name_, data, 64);
-  flags_ = get_LE_uint32(data + 64);
-  type_ = get_LE_uint32(data + 72);
-  int meshNum = get_LE_uint32(data + 76);
+  flags_ = READ_LE_UINT32(data + 64);
+  type_ = READ_LE_UINT32(data + 72);
+  int meshNum = READ_LE_UINT32(data + 76);
   if (meshNum < 0)
     mesh_ = NULL;
   else
     mesh_ = g.meshes_ + meshNum;
-  depth_ = get_LE_uint32(data + 80);
-  int parentPtr = get_LE_uint32(data + 84);
-  numChildren_ = get_LE_uint32(data + 88);
-  int childPtr = get_LE_uint32(data + 92);
-  int siblingPtr = get_LE_uint32(data + 96);
+  depth_ = READ_LE_UINT32(data + 80);
+  int parentPtr = READ_LE_UINT32(data + 84);
+  numChildren_ = READ_LE_UINT32(data + 88);
+  int childPtr = READ_LE_UINT32(data + 92);
+  int siblingPtr = READ_LE_UINT32(data + 96);
   pivot_ = get_vector3d(data + 100);
   pos_ = get_vector3d(data + 112);
   pitch_ = get_float(data + 124);
@@ -251,19 +251,19 @@
   data += 184;
 
   if (parentPtr != 0) {
-    parent_ = hierNodes + get_LE_uint32(data);
+    parent_ = hierNodes + READ_LE_UINT32(data);
     data += 4;
   }
   else
     parent_ = NULL;
   if (childPtr != 0) {
-    child_ = hierNodes + get_LE_uint32(data);
+    child_ = hierNodes + READ_LE_UINT32(data);
     data += 4;
   }
   else
     child_ = NULL;
   if (siblingPtr != 0) {
-    sibling_ = hierNodes + get_LE_uint32(data);
+    sibling_ = hierNodes + READ_LE_UINT32(data);
     data += 4;
   }
   else

Index: residual.vcproj
===================================================================
RCS file: /cvsroot/scummvm/residual/residual.vcproj,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- residual.vcproj	30 Aug 2003 17:58:33 -0000	1.9
+++ residual.vcproj	12 Dec 2003 08:39:07 -0000	1.10
@@ -1,287 +1,302 @@
-<?xml version="1.0" encoding = "windows-1250"?>
-<VisualStudioProject
-	ProjectType="Visual C++"
-	Version="7.00"
-	Name="residual"
-	ProjectGUID="{44D38F29-303D-4E3D-AF45-B96523BF1F9F}"
-	Keyword="Win32Proj">
-	<Platforms>
-		<Platform
-			Name="Win32"/>
-	</Platforms>
-	<Configurations>
-		<Configuration
-			Name="Debug|Win32"
-			OutputDirectory="Debug_Residual"
-			IntermediateDirectory="Debug_Residual"
-			ConfigurationType="1"
-			CharacterSet="2">
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="0"
-				AdditionalIncludeDirectories="lua\include"
-				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
-				MinimalRebuild="TRUE"
-				BasicRuntimeChecks="3"
-				RuntimeLibrary="3"
-				RuntimeTypeInfo="TRUE"
-				UsePrecompiledHeader="2"
-				WarningLevel="3"
-				Detect64BitPortabilityProblems="TRUE"
-				DebugInformationFormat="4"/>
-			<Tool
-				Name="VCCustomBuildTool"/>
-			<Tool
-				Name="VCLinkerTool"
+<?xml version="1.0" encoding = "windows-1250"?>

+<VisualStudioProject

+	ProjectType="Visual C++"

+	Version="7.00"

+	Name="residual"

+	ProjectGUID="{44D38F29-303D-4E3D-AF45-B96523BF1F9F}"

+	Keyword="Win32Proj">

+	<Platforms>

+		<Platform

+			Name="Win32"/>

+	</Platforms>

+	<Configurations>

+		<Configuration

+			Name="Debug|Win32"

+			OutputDirectory="Debug_Residual"

+			IntermediateDirectory="Debug_Residual"

+			ConfigurationType="1"

+			CharacterSet="2">

+			<Tool

+				Name="VCCLCompilerTool"

+				Optimization="0"

+				AdditionalIncludeDirectories="lua\include"

+				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"

+				MinimalRebuild="TRUE"

+				BasicRuntimeChecks="3"

+				RuntimeLibrary="3"

+				RuntimeTypeInfo="TRUE"

+				UsePrecompiledHeader="2"

+				WarningLevel="3"

+				Detect64BitPortabilityProblems="TRUE"

+				DebugInformationFormat="4"/>

+			<Tool

+				Name="VCCustomBuildTool"/>

+			<Tool

+				Name="VCLinkerTool"

 				AdditionalOptions="OpenGL32.Lib GlAux.Lib GLU32.Lib SDL.Lib SDLMain.Lib

-/NODEFAULTLIB:LIBCMTD"
-				OutputFile="$(OutDir)/residual.exe"
-				LinkIncremental="2"
-				GenerateDebugInformation="TRUE"
-				ProgramDatabaseFile="$(OutDir)/residual.pdb"
-				SubSystem="1"
-				TargetMachine="1"/>
-			<Tool
-				Name="VCMIDLTool"/>
-			<Tool
-				Name="VCPostBuildEventTool"/>
-			<Tool
-				Name="VCPreBuildEventTool"/>
-			<Tool
-				Name="VCPreLinkEventTool"/>
-			<Tool
-				Name="VCResourceCompilerTool"/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"/>
-			<Tool
-				Name="VCWebDeploymentTool"/>
-		</Configuration>
-		<Configuration
-			Name="Release|Win32"
-			OutputDirectory="Release_Residual"
-			IntermediateDirectory="Release_Residual"
-			ConfigurationType="1"
-			CharacterSet="2">
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="2"
-				InlineFunctionExpansion="1"
-				OmitFramePointers="TRUE"
-				AdditionalIncludeDirectories="lua\include"
-				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
-				StringPooling="TRUE"
-				RuntimeLibrary="2"
-				EnableFunctionLevelLinking="TRUE"
-				RuntimeTypeInfo="TRUE"
-				UsePrecompiledHeader="2"
-				WarningLevel="3"
-				Detect64BitPortabilityProblems="TRUE"
-				DebugInformationFormat="3"/>
-			<Tool
-				Name="VCCustomBuildTool"/>
-			<Tool
-				Name="VCLinkerTool"
+/NODEFAULTLIB:LIBCMTD"

+				OutputFile="$(OutDir)/residual.exe"

+				LinkIncremental="2"

+				GenerateDebugInformation="TRUE"

+				ProgramDatabaseFile="$(OutDir)/residual.pdb"

+				SubSystem="1"

+				TargetMachine="1"/>

+			<Tool

+				Name="VCMIDLTool"/>

+			<Tool

+				Name="VCPostBuildEventTool"/>

+			<Tool

+				Name="VCPreBuildEventTool"/>

+			<Tool

+				Name="VCPreLinkEventTool"/>

+			<Tool

+				Name="VCResourceCompilerTool"/>

+			<Tool

+				Name="VCWebServiceProxyGeneratorTool"/>

+			<Tool

+				Name="VCWebDeploymentTool"/>

+		</Configuration>

+		<Configuration

+			Name="Release|Win32"

+			OutputDirectory="Release_Residual"

+			IntermediateDirectory="Release_Residual"

+			ConfigurationType="1"

+			CharacterSet="2">

+			<Tool

+				Name="VCCLCompilerTool"

+				Optimization="2"

+				InlineFunctionExpansion="1"

+				OmitFramePointers="TRUE"

+				AdditionalIncludeDirectories="lua\include"

+				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"

+				StringPooling="TRUE"

+				RuntimeLibrary="2"

+				EnableFunctionLevelLinking="TRUE"

+				RuntimeTypeInfo="TRUE"

+				UsePrecompiledHeader="2"

+				WarningLevel="3"

+				Detect64BitPortabilityProblems="TRUE"

+				DebugInformationFormat="3"/>

+			<Tool

+				Name="VCCustomBuildTool"/>

+			<Tool

+				Name="VCLinkerTool"

 				AdditionalOptions="OpenGL32.Lib GlAux.Lib GLU32.Lib SDL.Lib SDLMain.Lib

-/NODEFAULTLIB:LIBCMTD"
-				OutputFile="$(OutDir)/residual.exe"
-				LinkIncremental="1"
-				GenerateDebugInformation="TRUE"
-				SubSystem="2"
-				OptimizeReferences="2"
-				EnableCOMDATFolding="2"
-				TargetMachine="1"/>
-			<Tool
-				Name="VCMIDLTool"/>
-			<Tool
-				Name="VCPostBuildEventTool"/>
-			<Tool
-				Name="VCPreBuildEventTool"/>
-			<Tool
-				Name="VCPreLinkEventTool"/>
-			<Tool
-				Name="VCResourceCompilerTool"/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"/>
-			<Tool
-				Name="VCWebDeploymentTool"/>
-		</Configuration>
-	</Configurations>
-	<Files>
-		<Filter
-			Name="Source Files"
-			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
-			<File
-				RelativePath="actor.cpp">
-			</File>
-			<File
-				RelativePath="actor.h">
-			</File>
-			<File
-				RelativePath="bitmap.cpp">
-			</File>
-			<File
-				RelativePath="bitmap.h">
-			</File>
-			<File
-				RelativePath="bits.h">
-			</File>
-			<File
-				RelativePath="color.h">
-			</File>
-			<File
-				RelativePath="colormap.h">
-			</File>
-			<File
-				RelativePath="costume.cpp">
-			</File>
-			<File
-				RelativePath="costume.h">
-			</File>
-			<File
-				RelativePath="debug.cpp">
-			</File>
-			<File
-				RelativePath="debug.h">
-			</File>
-			<File
-				RelativePath="engine.cpp">
-			</File>
-			<File
-				RelativePath="engine.h">
-			</File>
-			<File
-				RelativePath="hash_map.h">
-			</File>
-			<File
-				RelativePath="keyframe.cpp">
-			</File>
-			<File
-				RelativePath="keyframe.h">
-			</File>
-			<File
-				RelativePath="lab.cpp">
-			</File>
-			<File
-				RelativePath="lab.h">
-			</File>
-			<File
-				RelativePath="localize.cpp">
-			</File>
-			<File
-				RelativePath="localize.h">
-			</File>
-			<File
-				RelativePath="lua.cpp">
-			</File>
-			<File
-				RelativePath="lua.h">
-			</File>
-			<File
-				RelativePath="main.cpp">
-			</File>
-			<File
-				RelativePath="material.cpp">
-			</File>
-			<File
-				RelativePath="material.h">
-			</File>
-			<File
-				RelativePath="mixer.cpp">
-			</File>
-			<File
-				RelativePath="mixer.h">
-			</File>
-			<File
-				RelativePath="model.cpp">
-			</File>
-			<File
-				RelativePath="model.h">
-			</File>
-			<File
-				RelativePath="registry.cpp">
-			</File>
-			<File
-				RelativePath="registry.h">
-			</File>
-			<File
-				RelativePath="resource.cpp">
-			</File>
-			<File
-				RelativePath="resource.h">
-			</File>
-			<File
-				RelativePath="scene.cpp">
-			</File>
-			<File
-				RelativePath="scene.h">
-			</File>
-			<File
-				RelativePath="screen.cpp">
-			</File>
-			<File
-				RelativePath="screen.h">
-			</File>
-			<File
-				RelativePath="sound.cpp">
-			</File>
-			<File
-				RelativePath="sound.h">
-			</File>
-			<File
-				RelativePath="stdafx.h">
-			</File>
-			<File
-				RelativePath="textobject.cpp">
-			</File>
-			<File
-				RelativePath="textobject.h">
-			</File>
-			<File
-				RelativePath="textsplit.cpp">
-			</File>
-			<File
-				RelativePath="textsplit.h">
-			</File>
-			<File
-				RelativePath="walkplane.cpp">
-			</File>
-			<File
-				RelativePath="walkplane.h">
-			</File>
-			<Filter
-				Name="3DEngine"
-				Filter="">
-				<File
-					RelativePath="matrix3.cpp">
-				</File>
-				<File
-					RelativePath="matrix3.h">
-				</File>
-				<File
-					RelativePath="matrix4.cpp">
-				</File>
-				<File
-					RelativePath="matrix4.h">
-				</File>
-				<File
-					RelativePath="vector3d.h">
-				</File>
-			</Filter>
-		</Filter>
-		<Filter
-			Name="Resource Files"
-			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
-			<File
-				RelativePath="README">
-			</File>
-			<File
-				RelativePath="TODO">
-			</File>
-			<File
-				RelativePath="residual.rc">
-			</File>
-		</Filter>
-	</Files>
-	<Globals>
-	</Globals>
-</VisualStudioProject>
+/NODEFAULTLIB:LIBCMTD"

+				OutputFile="$(OutDir)/residual.exe"

+				LinkIncremental="1"

+				GenerateDebugInformation="TRUE"

+				SubSystem="2"

+				OptimizeReferences="2"

+				EnableCOMDATFolding="2"

+				TargetMachine="1"/>

+			<Tool

+				Name="VCMIDLTool"/>

+			<Tool

+				Name="VCPostBuildEventTool"/>

+			<Tool

+				Name="VCPreBuildEventTool"/>

+			<Tool

+				Name="VCPreLinkEventTool"/>

+			<Tool

+				Name="VCResourceCompilerTool"/>

+			<Tool

+				Name="VCWebServiceProxyGeneratorTool"/>

+			<Tool

+				Name="VCWebDeploymentTool"/>

+		</Configuration>

+	</Configurations>

+	<Files>

+		<Filter

+			Name="Source Files"

+			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">

+			<File

+				RelativePath="actor.cpp">

+			</File>

+			<File

+				RelativePath="actor.h">

+			</File>

+			<File

+				RelativePath="bitmap.cpp">

+			</File>

+			<File

+				RelativePath="bitmap.h">

+			</File>

+			<File

+				RelativePath="bits.h">

+			</File>

+			<File

+				RelativePath="blocky16.cpp">

+			</File>

+			<File

+				RelativePath="blocky16.h">

+			</File>

+			<File

+				RelativePath="color.h">

+			</File>

+			<File

+				RelativePath="colormap.h">

+			</File>

+			<File

+				RelativePath="costume.cpp">

+			</File>

+			<File

+				RelativePath="costume.h">

+			</File>

+			<File

+				RelativePath="debug.cpp">

+			</File>

+			<File

+				RelativePath="debug.h">

+			</File>

+			<File

+				RelativePath="engine.cpp">

+			</File>

+			<File

+				RelativePath="engine.h">

+			</File>

+			<File

+				RelativePath="hash_map.h">

+			</File>

+			<File

+				RelativePath="keyframe.cpp">

+			</File>

+			<File

+				RelativePath="keyframe.h">

+			</File>

+			<File

+				RelativePath="lab.cpp">

+			</File>

+			<File

+				RelativePath="lab.h">

+			</File>

+			<File

+				RelativePath="localize.cpp">

+			</File>

+			<File

+				RelativePath="localize.h">

+			</File>

+			<File

+				RelativePath="lua.cpp">

+			</File>

+			<File

+				RelativePath="lua.h">

+			</File>

+			<File

+				RelativePath="main.cpp">

+			</File>

+			<File

+				RelativePath="material.cpp">

+			</File>

+			<File

+				RelativePath="material.h">

+			</File>

+			<File

+				RelativePath="mixer.cpp">

+			</File>

+			<File

+				RelativePath="mixer.h">

+			</File>

+			<File

+				RelativePath="model.cpp">

+			</File>

+			<File

+				RelativePath="model.h">

+			</File>

+			<File

+				RelativePath="registry.cpp">

+			</File>

+			<File

+				RelativePath="registry.h">

+			</File>

+			<File

+				RelativePath="resource.cpp">

+			</File>

+			<File

+				RelativePath="resource.h">

+			</File>

+			<File

+				RelativePath="scene.cpp">

+			</File>

+			<File

+				RelativePath="scene.h">

+			</File>

+			<File

+				RelativePath="screen.cpp">

+			</File>

+			<File

+				RelativePath="screen.h">

+			</File>

+			<File

+				RelativePath="smush.cpp">

+			</File>

+			<File

+				RelativePath="smush.h">

+			</File>

+			<File

+				RelativePath="sound.cpp">

+			</File>

+			<File

+				RelativePath="sound.h">

+			</File>

+			<File

+				RelativePath="stdafx.h">

+			</File>

+			<File

+				RelativePath="textobject.cpp">

+			</File>

+			<File

+				RelativePath="textobject.h">

+			</File>

+			<File

+				RelativePath="textsplit.cpp">

+			</File>

+			<File

+				RelativePath="textsplit.h">

+			</File>

+			<File

+				RelativePath="vima.cpp">

+			</File>

+			<File

+				RelativePath="walkplane.cpp">

+			</File>

+			<File

+				RelativePath="walkplane.h">

+			</File>

+			<Filter

+				Name="3DEngine"

+				Filter="">

+				<File

+					RelativePath="matrix3.cpp">

+				</File>

+				<File

+					RelativePath="matrix3.h">

+				</File>

+				<File

+					RelativePath="matrix4.cpp">

+				</File>

+				<File

+					RelativePath="matrix4.h">

+				</File>

+				<File

+					RelativePath="vector3d.h">

+				</File>

+			</Filter>

+		</Filter>

+		<Filter

+			Name="Resource Files"

+			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">

+			<File

+				RelativePath="README">

+			</File>

+			<File

+				RelativePath="TODO">

+			</File>

+			<File

+				RelativePath="residual.rc">

+			</File>

+		</Filter>

+	</Files>

+	<Globals>

+	</Globals>

+</VisualStudioProject>


Index: sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/sound.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- sound.cpp	24 Aug 2003 17:56:03 -0000	1.3
+++ sound.cpp	12 Dec 2003 08:39:07 -0000	1.4
@@ -25,7 +25,7 @@
 #define ST_SAMPLE_MAX 0x7fffL
 #define ST_SAMPLE_MIN (-ST_SAMPLE_MAX - 1L)
 
-static inline void clampedAdd(int16_t& a, int b) {
+static inline void clampedAdd(int16& a, int b) {
         register int val = a + b;
 
         if (val > ST_SAMPLE_MAX)
@@ -36,173 +36,11 @@
         a = val;
 }
 
-static uint16_t imcTable1[] = {
-  0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e,
-  0x0010, 0x0011, 0x0013, 0x0015, 0x0017, 0x0019, 0x001c, 0x001f,
-  0x0022, 0x0025, 0x0029, 0x002d, 0x0032, 0x0037, 0x003c, 0x0042,
-  0x0049, 0x0050, 0x0058, 0x0061, 0x006b, 0x0076, 0x0082, 0x008f,
-  0x009d, 0x00ad, 0x00be, 0x00d1, 0x00e6, 0x00fd, 0x0117, 0x0133,
-  0x0151, 0x0173, 0x0198, 0x01c1, 0x01ee, 0x0220, 0x0256, 0x0292,
-  0x02d4, 0x031c, 0x036c, 0x03c3, 0x0424, 0x048e, 0x0502, 0x0583,
-  0x0610, 0x06ab, 0x0756, 0x0812, 0x08e0, 0x09c3, 0x0abd, 0x0bd0,
-  0x0cff, 0x0e4c, 0x0fba, 0x114c, 0x1307, 0x14ee, 0x1706, 0x1954,
-  0x1bdc, 0x1ea5, 0x21b6, 0x2515, 0x28ca, 0x2cdf, 0x315b, 0x364b,
-  0x3bb9, 0x41b2, 0x4844, 0x4f7e, 0x5771, 0x602f, 0x69ce, 0x7462,
-  0x7fff
-};
-
-static int8_t imcTable2[] = {
-  0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
-  0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
-  0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
-  0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
-  0x04, 0x04, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x05,
-  0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x06,
-  0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
-  0x06, 0x06, 0x06, 0x06, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
-  0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07
-};
-
-static int8_t imcOtherTable1[] = {
-  -1, 4, -1, 4
-};
-static int8_t imcOtherTable2[] = {
-  -1, -1, 2, 6, -1, -1, 2, 6
-};
-static int8_t imcOtherTable3[] = {
-  -1, -1, -1, -1, 1, 2, 4, 6,
-  -1, -1, -1, -1, 1, 2, 4, 6
-};
-static int8_t imcOtherTable4[] = {
-  -1, -1, -1, -1, -1, -1, -1, -1,
-  1, 1, 1, 2, 2, 4, 5, 6,
-  -1, -1, -1, -1, -1, -1, -1, -1,
-  1, 1, 1, 2, 2, 4, 5, 6
-};
-static int8_t imcOtherTable5[] = {
-  -1, -1, -1, -1, -1, -1, -1, -1,
-  -1, -1, -1, -1, -1, -1, -1, -1,
-  1, 1, 1, 1, 1, 2, 2, 2,
-  2, 4, 4, 4, 5, 5, 6, 6,
-  -1, -1, -1, -1, -1, -1, -1, -1,
-  -1, -1, -1, -1, -1, -1, -1, -1,
-  1, 1, 1, 1, 1, 2, 2, 2,
-  2, 4, 4, 4, 5, 5, 6, 6
-};
-static int8_t imcOtherTable6[] = {
-  -1, -1, -1, -1, -1, -1, -1, -1,
-  -1, -1, -1, -1, -1, -1, -1, -1,
-  -1, -1, -1, -1, -1, -1, -1, -1,
-  -1, -1, -1, -1, -1, -1, -1, -1,
-  1, 1, 1, 1, 1, 1, 1, 1,
-  1, 1, 2, 2, 2, 2, 2, 2,
-  2, 2, 4, 4, 4, 4, 4, 4,
-  5, 5, 5, 5, 6, 6, 6, 6,
-  -1, -1, -1, -1, -1, -1, -1, -1,
-  -1, -1, -1, -1, -1, -1, -1, -1,
-  -1, -1, -1, -1, -1, -1, -1, -1,
-  -1, -1, -1, -1, -1, -1, -1, -1,
-  1, 1, 1, 1, 1, 1, 1, 1,
-  1, 1, 2, 2, 2, 2, 2, 2,
-  2, 2, 4, 4, 4, 4, 4, 4,
-  5, 5, 5, 5, 6, 6, 6, 6
-};
-static int8_t *offsets[] = {
-  imcOtherTable1, imcOtherTable2, imcOtherTable3,
-  imcOtherTable4, imcOtherTable5, imcOtherTable6
-};
-
-static uint16_t destTable[5786];
+void vimaInit();
+void decompressVima(const char *src, int16 *dest, int destLen);
 
 void Sound::init() {
-  int destTableStartPos, incer;
-  for (destTableStartPos = 0, incer = 0; destTableStartPos < 64;
-       destTableStartPos++, incer++) {
-    unsigned int destTablePos, imcTable1Pos;
-    for (imcTable1Pos = 0, destTablePos = destTableStartPos;
-	 imcTable1Pos < sizeof(imcTable1) / sizeof(imcTable1[0]);
-	 imcTable1Pos++, destTablePos += 64) {
-      int put = 0, count, tableValue;
-      for (count = 32, tableValue = imcTable1[imcTable1Pos]; count != 0;
-	   count >>= 1, tableValue >>= 1) {
-	if ((incer & count) != 0)
-	  put += tableValue;
-      }
-      destTable[destTablePos] = put;
-    }
-  }
-}
-
-static void decompressVima(const char *src, int16_t *dest, int destLen) {
-  int numChannels = 1;
-  uint8_t sBytes[2];
-  int16_t sWords[2];
-
-  sBytes[0] = get_uint8(src++);
-  if (sBytes[0] & 0x80) {
-    sBytes[0] = ~sBytes[0];
-    numChannels = 2;
-  }
-  sWords[0] = get_BE_uint16(src);
-  src += 2;
-  if (numChannels > 1) {
-    sBytes[1] = get_uint8(src++);
-    sWords[1] = get_BE_uint16(src);
-    src += 2;
-  }
-
-  int numSamples = destLen / (numChannels * 2);
-  int bits = get_BE_uint16(src);
-  int bitPtr = 0;
-  src += 2;
-
-  for (int channel = 0; channel < numChannels; channel++) {
-    int16_t *destPos = dest + channel;
-    int currTablePos = sBytes[channel];
-    int outputWord = sWords[channel];
-
-    for (int sample = 0; sample < numSamples; sample++) {
-      int numBits = imcTable2[currTablePos];
-      bitPtr += numBits;
-      int highBit = 1 << (numBits - 1);
-      int lowBits = highBit - 1;
-      int val = (bits >> (16 - bitPtr)) & (highBit | lowBits);
-      if (bitPtr > 7) {
-	bits = ((bits & 0xff) << 8) | get_uint8(src++);
-	bitPtr -= 8;
-      }
-      if (val & highBit)
-	val ^= highBit;
-      else
-	highBit = 0;
-      if (val == lowBits) {
-	outputWord = ((signed short) (bits << bitPtr) & 0xffffff00);
-	bits = ((bits & 0xff) << 8) | get_uint8(src++);
-	outputWord |= ((bits >> (8 - bitPtr)) & 0xff);
-	bits = ((bits & 0xff) << 8) | get_uint8(src++);
-      }
-      else {
-	int index = (val << (7 - numBits)) | (currTablePos << 6);
-	int delta = destTable[index];
-	if (val != 0)
-	  delta += (imcTable1[currTablePos] >> (numBits - 1));
-	if (highBit != 0)
-	  delta = -delta;
-	outputWord += delta;
-	if (outputWord < -0x8000)
-	  outputWord = -0x8000;
-	else if (outputWord > 0x7fff)
-	  outputWord = 0x7fff;
-      }
-      *destPos = outputWord;
-      destPos += numChannels;
-      currTablePos += offsets[numBits - 2][val];
-      if (currTablePos < 0)
-	currTablePos = 0;
-      else if (currTablePos > 88)
-	currTablePos = 88;
-    }
-  }
+	vimaInit();
 }
 
 Sound::Sound(const char *filename, const char *data, int /* len */) :
@@ -221,25 +59,25 @@
       error("Invalid file format in %s\n", filename);
 
     // The first block is the WAVE or IMUS header
-    numBlocks = get_BE_uint16(data + 4);
+    numBlocks = READ_BE_UINT16(data + 4);
     codecsStart = data + 8 + numBlocks * 9;
-    codecsLen = get_BE_uint16(codecsStart - 2);
+    codecsLen = READ_BE_UINT16(codecsStart - 2);
     headerPos = codecsStart + codecsLen;
   }
 
   if (strcasecmp(extension, "wav") == 0) {
-    numChannels_ = get_LE_uint16(headerPos + 22);
-    dataStart = headerPos + 28 + get_LE_uint32(headerPos + 16);
-    dataSize = get_LE_uint32(dataStart - 4);
+    numChannels_ = READ_LE_UINT16(headerPos + 22);
+    dataStart = headerPos + 28 + READ_LE_UINT32(headerPos + 16);
+    dataSize = READ_LE_UINT32(dataStart - 4);
   }
   else if (strcasecmp(extension, "imc") == 0 ||
 	   strcasecmp(extension, "imu") == 0) {
     // Ignore MAP info for now...
     if (memcmp(headerPos + 16, "FRMT", 4) != 0)
       error("FRMT block not where it was expected\n");
-    numChannels_ = get_BE_uint32(headerPos + 40);
-    dataStart = headerPos + 24 + get_BE_uint32(headerPos + 12);
-    dataSize = get_BE_uint32(dataStart - 4);
+    numChannels_ = READ_BE_UINT32(headerPos + 40);
+    dataStart = headerPos + 24 + READ_BE_UINT32(headerPos + 12);
+    dataSize = READ_BE_UINT32(dataStart - 4);
   }
   else {
     error("Unrecognized extension for sound file %s\n", filename);
@@ -248,22 +86,22 @@
   if (strcasecmp(extension, "wav") == 0 || strcasecmp(extension, "imc") == 0) {
     // Uncompress the samples
     numSamples_ = dataSize / 2;
-    samples_ = new int16_t[dataSize / 2];
-    int16_t *destPos = samples_;
+    samples_ = new int16[dataSize / 2];
+    int16 *destPos = samples_;
     const char *srcPos = dataStart;
     for (int i = 1; i < numBlocks; i++) { // Skip header block
-      if (std::strcmp(codecsStart + 5 * get_uint8(data + 6 + i * 9),
+      if (std::strcmp(codecsStart + 5 * *(uint8 *)(data + 6 + i * 9),
 		      "VIMA") != 0)
 	error("Unsupported codec %s\n",
-	      codecsStart + 5 * get_uint8(data + 6 + i * 9));
-      decompressVima(srcPos, destPos, get_BE_uint32(data + 7 + i * 9));
-      srcPos += get_BE_uint32(data + 11 + i * 9);
-      destPos += get_BE_uint32(data + 7 + i * 9) / 2;
+	      codecsStart + 5 * *(uint8 *)(data + 6 + i * 9));
+      decompressVima(srcPos, destPos, READ_BE_UINT32(data + 7 + i * 9));
+      srcPos += READ_BE_UINT32(data + 11 + i * 9);
+      destPos += READ_BE_UINT32(data + 7 + i * 9) / 2;
     }
   }
   else {
     numSamples_ = dataSize / 2;
-    samples_ = new int16_t[dataSize / 2];
+    samples_ = new int16[dataSize / 2];
     std::memcpy(samples_, dataStart, dataSize);
 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
     for (int i = 0; i < numSamples_; i++)
@@ -278,7 +116,7 @@
   currPos_ = 0;
 }
 
-void Sound::mix(int16_t *data, int samples) {
+void Sound::mix(int16 *data, int samples) {
   while (samples > 0 && currPos_ < numSamples_) {
     clampedAdd(*data, samples_[currPos_]);
     data++;

Index: sound.h
===================================================================
RCS file: /cvsroot/scummvm/residual/sound.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- sound.h	24 Aug 2003 17:56:03 -0000	1.2
+++ sound.h	12 Dec 2003 08:39:07 -0000	1.3
@@ -30,12 +30,12 @@
 
 private:
   int numSamples_, numChannels_, currPos_;
-  int16_t *samples_;
+  int16 *samples_;
 
   static void init();
 
   void reset();
-  void mix(int16_t *data, int samples);
+  void mix(int16 *data, int samples);
 
   friend class Mixer;
 };

Index: stdafx.h
===================================================================
RCS file: /cvsroot/scummvm/residual/stdafx.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- stdafx.h	24 Aug 2003 17:56:03 -0000	1.1
+++ stdafx.h	12 Dec 2003 08:39:07 -0000	1.2
@@ -18,17 +18,8 @@
 #ifndef _STDAFX_H
 #define _STDAFX_H
 
-#if defined(_WIN32_WCE) && _WIN32_WCE < 300
-
-#define NONSTANDARD_PORT
 
-#endif
-
-#if defined(NONSTANDARD_PORT)
-
-#include <portdefs.h>
-
-#elif defined(WIN32)
+#if defined(WIN32)
 
 #ifdef _MSC_VER
 #pragma once





More information about the Scummvm-git-logs mailing list