[Scummvm-cvs-logs] SF.net SVN: scummvm: [24394] scummvm/trunk/engines/agos

kirben at users.sourceforge.net kirben at users.sourceforge.net
Fri Oct 20 04:11:17 CEST 2006


Revision: 24394
          http://svn.sourceforge.net/scummvm/?rev=24394&view=rev
Author:   kirben
Date:     2006-10-19 19:10:51 -0700 (Thu, 19 Oct 2006)

Log Message:
-----------
Split code into more specific files and cleanup

Modified Paths:
--------------
    scummvm/trunk/engines/agos/agos.cpp
    scummvm/trunk/engines/agos/agos.h
    scummvm/trunk/engines/agos/icons.cpp
    scummvm/trunk/engines/agos/module.mk
    scummvm/trunk/engines/agos/script.cpp
    scummvm/trunk/engines/agos/script_ff.cpp
    scummvm/trunk/engines/agos/script_pp.cpp
    scummvm/trunk/engines/agos/script_s1.cpp
    scummvm/trunk/engines/agos/script_s2.cpp
    scummvm/trunk/engines/agos/string.cpp
    scummvm/trunk/engines/agos/subroutine.cpp
    scummvm/trunk/engines/agos/verb.cpp
    scummvm/trunk/engines/agos/vga.cpp

Added Paths:
-----------
    scummvm/trunk/engines/agos/gfx.cpp
    scummvm/trunk/engines/agos/input.cpp
    scummvm/trunk/engines/agos/items.cpp
    scummvm/trunk/engines/agos/vga_ff.cpp
    scummvm/trunk/engines/agos/vga_s1.cpp
    scummvm/trunk/engines/agos/vga_s2.cpp
    scummvm/trunk/engines/agos/zones.cpp

Modified: scummvm/trunk/engines/agos/agos.cpp
===================================================================
--- scummvm/trunk/engines/agos/agos.cpp	2006-10-19 23:57:54 UTC (rev 24393)
+++ scummvm/trunk/engines/agos/agos.cpp	2006-10-20 02:10:51 UTC (rev 24394)
@@ -791,1416 +791,6 @@
 	} while (--num);
 }
 
-byte *AGOSEngine::allocateItem(uint size) {
-	byte *org = _itemHeapPtr;
-	size = (size + sizeof(void*) - 1) & ~(sizeof(void*) - 1);
-
-	_itemHeapPtr += size;
-	_itemHeapCurPos += size;
-
-	if (_itemHeapCurPos > _itemHeapSize)
-		error("allocateItem: Itemheap overflow");
-
-	return org;
-}
-
-int AGOSEngine::getUserFlag(Item *item, int a) {
-	SubUserFlag *subUserFlag;
-
-	subUserFlag = (SubUserFlag *) findChildOfType(item, 9);
-	if (subUserFlag == NULL)
-		return 0;
-
-	if (a < 0 || a > 7)
-		return 0;
-
-	return	subUserFlag->userFlags[a];
-}
-
-void AGOSEngine::setUserFlag(Item *item, int a, int b) {
-	SubUserFlag *subUserFlag;
-
-	subUserFlag = (SubUserFlag *) findChildOfType(item, 9);
-	if (subUserFlag == NULL) {
-		subUserFlag = (SubUserFlag *) allocateChildBlock(item, 9, sizeof(SubUserFlag));
-	}
-
-	if (a < 0 || a > 7)
-		return;
-
-	subUserFlag->userFlags[a] = b;
-}
-
-int AGOSEngine::getUserItem(Item *item, int n) {
-	SubUserFlag *subUserFlag;
-
-	subUserFlag = (SubUserFlag *) findChildOfType(item, 9);
-	if (subUserFlag == NULL)
-		return 0;
-
-	if (n < 0 || n > 0)
-		return 0;
-
-	return	subUserFlag->userItems[n];
-}
-
-void AGOSEngine::setUserItem(Item *item, int n, int m) {
-	SubUserFlag *subUserFlag;
-
-	subUserFlag = (SubUserFlag *) findChildOfType(item, 9);
-	if (subUserFlag == NULL) {
-		subUserFlag = (SubUserFlag *) allocateChildBlock(item, 9, sizeof(SubUserFlag));
-	}
-
-	if (n == 0)
-		subUserFlag->userItems[n] = m;
-}
-
-void AGOSEngine::createPlayer() {
-	SubPlayer *p;
-
-	_currentPlayer = _itemArrayPtr[1];
-	_currentPlayer->adjective = -1;
-	_currentPlayer->noun = 10000;
-
-	p = (SubPlayer *)allocateChildBlock(_currentPlayer, 3, sizeof(SubPlayer));
-	if (p == NULL)
-		error("createPlayer: player create failure");
-
-	p->size = 0;
-	p->weight = 0;
-	p->strength = 6000;
-	//p->flag = xxx;
-	p->level = 1;
-	p->score = 0;
-
-	setUserFlag(_currentPlayer, 0, 0);
-}
-
-Child *AGOSEngine::findChildOfType(Item *i, uint type) {
-	Child *child = i->children;
-	for (; child; child = child->next)
-		if (child->type == type)
-			return child;
-	return NULL;
-}
-
-bool AGOSEngine::isRoom(Item *item) {
-	return findChildOfType(item, 1) != NULL;
-}
-
-bool AGOSEngine::isObject(Item *item) {
-	return findChildOfType(item, 2) != NULL;
-}
-
-bool AGOSEngine::isPlayer(Item *item) {
-	return findChildOfType(item, 3) != NULL;
-}
-
-uint AGOSEngine::getOffsetOfChild2Param(SubObject *child, uint prop) {
-	uint m = 1;
-	uint offset = 0;
-	while (m != prop) {
-		if (child->objectFlags & m)
-			offset++;
-		m *= 2;
-	}
-	return offset;
-}
-
-Child *AGOSEngine::allocateChildBlock(Item *i, uint type, uint size) {
-	Child *child = (Child *)allocateItem(size);
-	child->next = i->children;
-	i->children = child;
-	child->type = type;
-	return child;
-}
-
-void AGOSEngine::allocItemHeap() {
-	_itemHeapSize = _itemMemSize;
-	_itemHeapCurPos = 0;
-	_itemHeapPtr = (byte *)calloc(_itemMemSize, 1);
-	if (!_itemHeapPtr)
-		error("Out Of Memory - Items");
-}
-
-void AGOSEngine::allocTablesHeap() {
-	_tablesHeapSize = _tableMemSize;
-	_tablesHeapCurPos = 0;
-	_tablesHeapPtr = (byte *)calloc(_tableMemSize, 1);
-	if (!_tablesHeapPtr)
-		error("Out Of Memory - Tables");
-}
-
-void AGOSEngine::setItemState(Item *item, int value) {
-	item->state = value;
-}
-
-byte AGOSEngine::getByte() {
-	return *_codePtr++;
-}
-
-int AGOSEngine::getNextWord() {
-	int16 a = (int16)READ_BE_UINT16(_codePtr);
-	_codePtr += 2;
-	return a;
-}
-
-uint AGOSEngine::getNextStringID() {
-	return (uint16)getNextWord();
-}
-
-uint AGOSEngine::getVarOrByte() {
-	if (getGameType() == GType_ELVIRA1) {
-		return getVarOrWord();
-	} else {
-		uint a = *_codePtr++;
-		if (a != 255)
-			return a;
-		return readVariable(*_codePtr++);
-	}
-}
-
-uint AGOSEngine::getVarOrWord() {
-	uint a = READ_BE_UINT16(_codePtr);
-	_codePtr += 2;
-	if (getGameType() == GType_PP) {
-		if (a >= 60000 && a < 62048) {
-			return readVariable(a - 60000);
-		}
-	} else {
-		if (a >= 30000 && a < 30512) {
-			return readVariable(a - 30000);
-		}
-	}
-	return a;
-}
-
-uint AGOSEngine::getVarWrapper() {
-	if (getGameType() == GType_ELVIRA1 || getGameType() == GType_PP)
-		return getVarOrWord();
-	else
-		return getVarOrByte();
-}
-
-Item *AGOSEngine::getNextItemPtr() {
-	int a = getNextWord();
-	switch (a) {
-	case -1:
-		return _subjectItem;
-	case -3:
-		return _objectItem;
-	case -5:
-		return me();
-	case -7:
-		return actor();
-	case -9:
-		return derefItem(me()->parent);
-	default:
-		return derefItem(a);
-	}
-}
-
-Item *AGOSEngine::getNextItemPtrStrange() {
-	int a = getNextWord();
-	switch (a) {
-	case -1:
-		return _subjectItem;
-	case -3:
-		return _objectItem;
-	case -5:
-		return _dummyItem2;
-	case -7:
-		return NULL;
-	case -9:
-		return _dummyItem3;
-	default:
-		return derefItem(a);
-	}
-}
-
-uint AGOSEngine::getNextItemID() {
-	int a = getNextWord();
-	switch (a) {
-	case -1:
-		return itemPtrToID(_subjectItem);
-	case -3:
-		return itemPtrToID(_objectItem);
-	case -5:
-		return getItem1ID();
-	case -7:
-		return 0;
-	case -9:
-		return me()->parent;
-	default:
-		return a;
-	}
-}
-
-Item *AGOSEngine::me() {
-	if (_currentPlayer)
-		return _currentPlayer;
-	return _dummyItem1;
-}
-
-Item *AGOSEngine::actor() {
-	error("actor: is this code ever used?");
-	//if (_actorPlayer)
-	//	return _actorPlayer;
-	return _dummyItem1;
-}
-
-uint AGOSEngine::getNextVarContents() {
-	return (uint16)readVariable(getVarWrapper());
-}
-
-uint AGOSEngine::readVariable(uint variable) {
-	if (variable >= _numVars)
-		error("readVariable: Variable %d out of range", variable);
-
-	if (getGameType() == GType_PP) {
-		return (uint16)_variableArray[variable];
-	} else if (getGameType() == GType_FF) {
-		if (getBitFlag(83))
-			return (uint16)_variableArray2[variable];
-		else
-			return (uint16)_variableArray[variable];
-	} else {
-			return _variableArray[variable];
-	}
-}
-
-void AGOSEngine::writeNextVarContents(uint16 contents) {
-	writeVariable(getVarWrapper(), contents);
-}
-
-void AGOSEngine::writeVariable(uint variable, uint16 contents) {
-	if (variable >= _numVars)
-		error("writeVariable: Variable %d out of range", variable);
-
-	if (getGameType() == GType_FF && getBitFlag(83))
-		_variableArray2[variable] = contents;
-	else
-		_variableArray[variable] = contents;
-}
-
-void AGOSEngine::setItemParent(Item *item, Item *parent) {
-	Item *old_parent = derefItem(item->parent);
-
-	if (item == parent)
-		error("setItemParent: Trying to set item as its own parent");
-
-	// unlink it if it has a parent
-	if (old_parent)
-		unlinkItem(item);
-	itemChildrenChanged(old_parent);
-	linkItem(item, parent);
-	itemChildrenChanged(parent);
-}
-
-void AGOSEngine::itemChildrenChanged(Item *item) {
-	int i;
-	WindowBlock *window;
-
-	if (_noParentNotify)
-		return;
-
-	mouseOff();
-
-	for (i = 0; i != 8; i++) {
-		window = _windowArray[i];
-		if (window && window->iconPtr && window->iconPtr->itemRef == item) {
-			if (_fcsData1[i]) {
-				_fcsData2[i] = true;
-			} else {
-				_fcsData2[i] = false;
-				drawIconArray(i, item, window->iconPtr->line, window->iconPtr->classMask);
-			}
-		}
-	}
-
-	mouseOn();
-}
-
-void AGOSEngine::unlinkItem(Item *item) {
-	Item *first, *parent, *next;
-
-	// can't unlink item without parent
-	if (item->parent == 0)
-		return;
-
-	// get parent and first child of parent
-	parent = derefItem(item->parent);
-	first = derefItem(parent->child);
-
-	// the node to remove is first in the parent's children?
-	if (first == item) {
-		parent->child = item->next;
-		item->parent = 0;
-		item->next = 0;
-		return;
-	}
-
-	for (;;) {
-		if (!first)
-			error("unlinkItem: parent empty");
-		if (first->next == 0)
-			error("unlinkItem: parent does not contain child");
-
-		next = derefItem(first->next);
-		if (next == item) {
-			first->next = next->next;
-			item->parent = 0;
-			item->next = 0;
-			return;
-		}
-		first = next;
-	}
-}
-
-void AGOSEngine::linkItem(Item *item, Item *parent) {
-	uint id;
-	// Don't allow that an item that is already linked is relinked
-	if (item->parent)
-		return;
-
-	id = itemPtrToID(parent);
-	item->parent = id;
-
-	if (parent != 0) {
-		item->next = parent->child;
-		parent->child = itemPtrToID(item);
-	} else {
-		item->next = 0;
-	}
-}
-
-void AGOSEngine::setup_cond_c_helper() {
-	HitArea *last;
-	uint id;
-
-	_noRightClick = 1;
-
-	if (getGameType() == GType_WW)
-		clearMenuStrip();
-
-	if (getGameType() == GType_FF) {
-		int cursor = 5;
-		int animMax = 16;
-
-		if (getBitFlag(200)) {
-			cursor = 11;
-			animMax = 5;
-		} else if (getBitFlag(201)) {
-			cursor = 12;
-			animMax = 5;
-		} else if (getBitFlag(202)) {
-			cursor = 13;
-			animMax = 5;
-		} else if (getBitFlag(203)) {
-			cursor = 14;
-			animMax = 9;
-		} else if (getBitFlag(205)) {
-			cursor = 17;
-			animMax = 11;
-		} else if (getBitFlag(206)) {
-			cursor = 16;
-			animMax = 2;
-		} else if (getBitFlag(208)) {
-			cursor = 26;
-			animMax = 2;
-		} else if (getBitFlag(209)) {
-			cursor = 27;
-			animMax = 9;
-		} else if (getBitFlag(210)) {
-			cursor = 28;
-			animMax = 9;
-		}
-
-		_animatePointer = 0;
-		_mouseCursor = cursor;
-		_mouseAnimMax = animMax;
-		_mouseAnim = 1;
-		_needHitAreaRecalc++;
-	}
-
-	if (getGameType() == GType_SIMON2) {
-		_mouseCursor = 0;
-		if (_defaultVerb != 999) {
-			_mouseCursor = 9;
-			_needHitAreaRecalc++;
-			_defaultVerb = 0;
-		}
-	}
-
-	_lastHitArea = 0;
-	_hitAreaObjectItem = NULL;
-	_nameLocked = 0;
-
-	last = _lastNameOn;
-	clearName();
-	_lastNameOn = last;
-
-	for (;;) {
-		_lastHitArea = NULL;
-		_lastHitArea3 = 0;
-		_leftButtonDown = 0;
-
-		do {
-			if (_exitCutscene && getBitFlag(9)) {
-				endCutscene();
-				goto out_of_here;
-			}
-
-			if (getGameType() == GType_FF) {
-				if (_variableArray[254] == 63) {
-					hitarea_stuff_helper_2();
-				} else if (_variableArray[254] == 75) {
-					hitarea_stuff_helper_2();
-					_variableArray[60] = 9999;
-					goto out_of_here;
-				}
-			}
-
-			delay(100);
-		} while (_lastHitArea3 == (HitArea *) -1 || _lastHitArea3 == 0);
-
-		if (_lastHitArea == NULL) {
-		} else if (_lastHitArea->id == 0x7FFB) {
-			inventoryUp(_lastHitArea->window);
-		} else if (_lastHitArea->id == 0x7FFC) {
-			inventoryDown(_lastHitArea->window);
-		} else if (_lastHitArea->item_ptr != NULL) {
-			_hitAreaObjectItem = _lastHitArea->item_ptr;
-			id = 0xFFFF;
-			if (_lastHitArea->flags & kBFTextBox) {
-				if (getGameType() == GType_PP)
-					id = _lastHitArea->id;
-				else if (getGameType() == GType_FF && (_lastHitArea->flags & kBFHyperBox))
-					id = _lastHitArea->data;
-				else
-					id = _lastHitArea->flags / 256;
-			}
-			if (getGameType() == GType_PP)
-				_variableArray[199] = id;
-			else if (getGameType() == GType_WW)
-				_variableArray[10] = id;
-			else
-				_variableArray[60] = id;
-			break;
-		}
-	}
-
-out_of_here:
-	_lastHitArea3 = 0;
-	_lastHitArea = 0;
-	_lastNameOn = NULL;
-	_mouseCursor = 0;
-	_noRightClick = 0;
-}
-
-void AGOSEngine::endCutscene() {
-	Subroutine *sub;
-
-	_sound->stopVoice();
-
-	sub = getSubroutineByID(170);
-	if (sub != NULL)
-		startSubroutineEx(sub);
-
-	_runScriptReturn1 = true;
-}
-
-bool AGOSEngine::has_item_childflag_0x10(Item *item) {
-	SubObject *child = (SubObject *)findChildOfType(item, 2);
-	return child && (child->objectFlags & kOFIcon) != 0;
-}
-
-uint AGOSEngine::itemGetIconNumber(Item *item) {
-	if (getGameType() == GType_ELVIRA1) {
-		return getUserFlag(item, 7);
-	} else {
-		SubObject *child = (SubObject *)findChildOfType(item, 2);
-		uint offs;
-
-		if (child == NULL || !(child->objectFlags & kOFIcon))
-			return 0;
-
-		offs = getOffsetOfChild2Param(child, 0x10);
-		return child->objectFlagValue[offs];
-	}
-}
-
-void AGOSEngine::waitForInput() {
-	HitArea *ha;
-	uint id;
-
-	_leftButtonDown = 0;
-	_lastHitArea = 0;
-	_verbHitArea = 0;
-	_hitAreaSubjectItem = NULL;
-	_hitAreaObjectItem = NULL;
-	_nameLocked = 0;
-
-	if (getGameType() == GType_WW) {
-		_mouseCursor = 0;
-		_needHitAreaRecalc++;
-		clearMenuStrip();
-	} else {
-		resetVerbs();
-	}
-
-startOver:
-	for (;;) {
-		_lastHitArea = NULL;
-		_lastHitArea3 = NULL;
-
-		for (;;) {
-			if (getGameType() != GType_FF && getGameType() != GType_PP && _keyPressed == 35)
-				displayBoxStars();
-			if (processSpecialKeys() != 0) {
-				goto out_of_here;
-			}
-			if (_lastHitArea3 == (HitArea *) -1)
-				goto startOver;
-			if (_lastHitArea3 != 0)
-				break;
-			hitarea_stuff_helper();
-			delay(100);
-		}
-
-		ha = _lastHitArea;
-
-		if (ha == NULL) {
-		} else if (ha->id == 0x7FFB) {
-			inventoryUp(ha->window);
-		} else if (ha->id == 0x7FFC) {
-			inventoryDown(ha->window);
-		} else if ((getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) &&
-			(ha->id >= 101 && ha->id < 113)) {
-			_verbHitArea = ha->verb;
-			setVerb(ha);
-			_defaultVerb = 0;
-		} else {
-			if (getGameType() == GType_WW) {
-				if (_mouseCursor == 3)
-					_verbHitArea = 236;
-
-				if (ha->id == 98) {
-					loadSprite(2, 0, 110, 0, 0, 0);
-					waitForSync(34);
-				} else if (ha->id == 108) {
-					loadSprite(2, 0, 106, 0, 0, 0);
-					waitForSync(34);
-				} else if (ha->id == 109) {
-					loadSprite(2, 0, 107, 0, 0, 0);
-					waitForSync(34);
-				} else if (ha->id == 115) {
-					loadSprite(2, 0, 109, 0, 0, 0);
-					waitForSync(34);
-				} else if (ha->id == 116) {
-					loadSprite(2, 0, 113, 0, 0, 0);
-					waitForSync(34);
-				} else if (ha->id == 117) {
-					loadSprite(2, 0, 112, 0, 0, 0);
-					waitForSync(34);
-				} else if (ha->id == 118) {
-					loadSprite(2, 0, 108, 0, 0, 0);
-					waitForSync(34);
-				} else if (ha->id == 119) {
-					loadSprite(2, 0, 111, 0, 0, 0);
-					waitForSync(34);
-				}
-			}
-			if ((_verbHitArea != 0 || _hitAreaSubjectItem != ha->item_ptr && ha->flags & kBFBoxItem) &&
-					ha->item_ptr) {
-			if_1:;
-				_hitAreaSubjectItem = ha->item_ptr;
-				id = 0xFFFF;
-				if (ha->flags & kBFTextBox) {
-					if (getGameType() == GType_PP)
-						id = _lastHitArea->id;
-					else if (getGameType() == GType_FF && (ha->flags & kBFHyperBox))
-						id = ha->data;
-					else
-						id = ha->flags / 256;
-				}
-				if (getGameType() == GType_PP)
-					_variableArray[199] = id;
-				else if (getGameType() == GType_WW)
-					_variableArray[10] = id;
-				else
-					_variableArray[60] = id;
-
-				_nameLocked = 2;
-				displayName(ha);
-				_nameLocked = 1;
-
-				if (_verbHitArea != 0) {
-					break;
-				}
-
-				if (getGameType() == GType_ELVIRA2)
-					doMenuStrip(menuFor_e2(ha->item_ptr, id));
-				else if (getGameType() == GType_WW)
-					doMenuStrip(menuFor_ww(ha->item_ptr, id));
-			} else {
-				// else 1
-				if (ha->verb == 0) {
-					if (ha->item_ptr)
-						goto if_1;
-				} else {
-					if (getGameType() == GType_WW && _mouseCursor != 0 && _mouseCursor < 4) {
-						_hitAreaSubjectItem = ha->item_ptr;
-						break;
-					}
-
-					_verbHitArea = ha->verb & 0xBFFF;
-					if (ha->verb & 0x4000) {
-						_hitAreaSubjectItem = ha->item_ptr;
-						break;
-					}
-					if (_hitAreaSubjectItem != NULL)
-						break;
-
-					if (getGameType() == GType_WW) {
-						if (ha->id == 109) {
-							_mouseCursor = 2;
-							_needHitAreaRecalc++;
-						} else if (ha->id == 117) {
-							_mouseCursor = 3;
-							_needHitAreaRecalc++;
-						}
-					}
-				}
-			}
-		}
-	}
-
-out_of_here:
-	if (getGameType() == GType_ELVIRA2 || getGameType() == GType_WW)
-		clearMenuStrip();
-
-	_nameLocked = 0;
-	_needHitAreaRecalc++;
-}
-
-void AGOSEngine::hitarea_stuff_helper() {
-	time_t cur_time;
-
-	if (getGameType() == GType_SIMON2 || getGameType() == GType_FF ||
-		getGameType() == GType_PP) {
-		if (_variableArray[254] || _variableArray[249]) {
-			hitarea_stuff_helper_2();
-		}
-	} else if (getGameType() == GType_ELVIRA2 || getGameType() == GType_WW || 
-		getGameType() == GType_SIMON1) {
-		uint subr_id = (uint16)_variableArray[254];
-		if (subr_id != 0) {
-			Subroutine *sub = getSubroutineByID(subr_id);
-			if (sub != NULL) {
-				startSubroutineEx(sub);
-				permitInput();
-			}
-			_variableArray[254] = 0;
-			_runScriptReturn1 = false;
-		}
-	}
-
-	time(&cur_time);
-	if ((uint) cur_time != _lastTime) {
-		_lastTime = cur_time;
-		if (kickoffTimeEvents())
-			permitInput();
-	}
-}
-
-void AGOSEngine::hitarea_stuff_helper_2() {
-	uint subr_id;
-	Subroutine *sub;
-
-	subr_id = (uint16)_variableArray[249];
-	if (subr_id != 0) {
-		sub = getSubroutineByID(subr_id);
-		if (sub != NULL) {
-			_variableArray[249] = 0;
-			startSubroutineEx(sub);
-			permitInput();
-		}
-		_variableArray[249] = 0;
-	}
-
-	subr_id = (uint16)_variableArray[254];
-	if (subr_id != 0) {
-		sub = getSubroutineByID(subr_id);
-		if (sub != NULL) {
-			_variableArray[254] = 0;
-			startSubroutineEx(sub);
-			permitInput();
-		}
-		_variableArray[254] = 0;
-	}
-
-	_runScriptReturn1 = false;
-}
-
-void AGOSEngine::permitInput() {
-	if (!_mortalFlag) {
-		_mortalFlag = true;
-		showmessage_print_char(0);
-		_curWindow = 0;
-		if (_windowArray[0] != 0) {
-			_textWindow = _windowArray[0];
-			if (getGameType() == GType_FF || getGameType() == GType_PP)
-				showmessage_helper_3(_textWindow->textColumn, _textWindow->width);
-			else
-				showmessage_helper_3(_textWindow->textLength, _textWindow->textMaxLength);
-		}
-		_mortalFlag = false;
-	}
-}
-
-TextLocation *AGOSEngine::getTextLocation(uint a) {
-	switch (a) {
-	case 1:
-		return &_textLocation1;
-	case 2:
-		return &_textLocation2;
-	case 101:
-		return &_textLocation3;
-	case 102:
-		return &_textLocation4;
-	default:
-		error("getTextLocation: Invalid text location %d", a);
-	}
-	return NULL;
-}
-
-void AGOSEngine::loadZone(uint zoneNum) {
-	VgaPointersEntry *vpe;
-
-	CHECK_BOUNDS(zoneNum, _vgaBufferPointers);
-
-	vpe = _vgaBufferPointers + zoneNum;
-	if (vpe->vgaFile1 != NULL)
-		return;
-
-	// Loading order is important
-	// due to resource managment
-
-	loadVGAVideoFile(zoneNum, 2);
-	vpe->vgaFile2 = _block;
-	vpe->vgaFile2End = _blockEnd;
-
-	loadVGAVideoFile(zoneNum, 1);
-	vpe->vgaFile1 = _block;
-	vpe->vgaFile1End = _blockEnd;
-
-	vpe->sfxFile = NULL;
-	if (!(getFeatures() & GF_ZLIBCOMP)) {
-		if (loadVGASoundFile(zoneNum, 3)) {
-			vpe->sfxFile = _block;
-			vpe->sfxFileEnd = _blockEnd;
-		}
-	}
-}
-
-void AGOSEngine::setZoneBuffers() {
-	_zoneBuffers = (byte *)malloc(_vgaMemSize);
-
-	_vgaMemPtr = _zoneBuffers;
-	_vgaMemBase = _zoneBuffers;
-	_vgaFrozenBase = _zoneBuffers;
-	_vgaRealBase = _zoneBuffers;
-	_vgaMemEnd = _zoneBuffers + _vgaMemSize;
-}
-
-byte *AGOSEngine::allocBlock(uint32 size) {
-	for (;;) {
-		_block = _vgaMemPtr;
-		_blockEnd = _block + size;
-
-		if (_blockEnd >= _vgaMemEnd) {
-			_vgaMemPtr = _vgaMemBase;
-		} else {
-			_rejectBlock = false;
-			checkNoOverWrite();
-			if (_rejectBlock)
-				continue;
-			checkRunningAnims();
-			if (_rejectBlock)
-				continue;
-			checkZonePtrs();
-			_vgaMemPtr = _blockEnd;
-			return _block;
-		}
-	}
-}
-
-void AGOSEngine::checkNoOverWrite() {
-	VgaPointersEntry *vpe;
-
-	if (_noOverWrite == 0xFFFF)
-		return;
-
-	vpe = &_vgaBufferPointers[_noOverWrite];
-
-	if (getGameType() == GType_FF || getGameType() == GType_PP) {
-		if (vpe->vgaFile1 < _blockEnd && vpe->vgaFile1End > _block) {
-			_rejectBlock = true;
-			_vgaMemPtr = vpe->vgaFile1End;
-		} else if (vpe->vgaFile2 < _blockEnd && vpe->vgaFile2End > _block) {
-			_rejectBlock = true;
-			_vgaMemPtr = vpe->vgaFile2End;
-		} else if (vpe->sfxFile && vpe->sfxFile < _blockEnd && vpe->sfxFileEnd > _block) {
-			_rejectBlock = true;
-			_vgaMemPtr = vpe->sfxFileEnd;
-		} else {
-			_rejectBlock = false;
-		}
-	} else {
-		if (_block <= vpe->vgaFile1 && _blockEnd >= vpe->vgaFile1 ||
-			_vgaMemPtr <= vpe->vgaFile2 && _blockEnd >= vpe->vgaFile2) {
-			_rejectBlock = true;
-			_vgaMemPtr = vpe->vgaFile1 + 0x5000;
-		} else {
-			_rejectBlock = false;
-		}
-	}
-}
-
-void AGOSEngine::checkRunningAnims() {
-	VgaSprite *vsp;
-	if (getGameType() != GType_FF && getGameType() != GType_PP && (_lockWord & 0x20)) {
-		return;
-	}
-
-	for (vsp = _vgaSprites; vsp->id; vsp++) {
-		checkAnims(vsp->zoneNum);
-		if (_rejectBlock == true)
-			return;
-	}
-}
-
-void AGOSEngine::checkAnims(uint a) {
-	VgaPointersEntry *vpe;
-
-	vpe = &_vgaBufferPointers[a];
-
-	if (getGameType() == GType_FF || getGameType() == GType_PP) {
-		if (vpe->vgaFile1 < _blockEnd && vpe->vgaFile1End > _block) {
-			_rejectBlock = true;
-			_vgaMemPtr = vpe->vgaFile1End;
-		} else if (vpe->vgaFile2 < _blockEnd && vpe->vgaFile2End > _block) {
-			_rejectBlock = true;
-			_vgaMemPtr = vpe->vgaFile2End;
-		} else if (vpe->sfxFile && vpe->sfxFile < _blockEnd && vpe->sfxFileEnd > _block) {
-			_rejectBlock = true;
-			_vgaMemPtr = vpe->sfxFileEnd;
-		} else {
-			_rejectBlock = false;
-		}
-	} else {
-		if (_block <= vpe->vgaFile1 && _blockEnd >= vpe->vgaFile1 ||
-				_block <= vpe->vgaFile2 && _blockEnd >= vpe->vgaFile2) {
-			_rejectBlock = true;
-			_vgaMemPtr = vpe->vgaFile1 + 0x5000;
-		} else {
-			_rejectBlock = false;
-		}
-	}
-}
-
-void AGOSEngine::checkZonePtrs() {
-	uint count = ARRAYSIZE(_vgaBufferPointers);
-	VgaPointersEntry *vpe = _vgaBufferPointers;
-	do {
-		if (getGameType() == GType_FF || getGameType() == GType_PP) {
-			if (vpe->vgaFile1 < _blockEnd && vpe->vgaFile1End > _block ||
-					vpe->vgaFile2 < _blockEnd && vpe->vgaFile2End > _block ||
-					vpe->sfxFile < _blockEnd && vpe->sfxFileEnd > _block) {
-				vpe->vgaFile1 = NULL;
-				vpe->vgaFile1End = NULL;
-				vpe->vgaFile2 = NULL;
-				vpe->vgaFile2End = NULL;
-				vpe->sfxFile = NULL;
-				vpe->sfxFileEnd = NULL;
-			}
-		} else {
-			if (_block <= vpe->vgaFile1 && _blockEnd >= vpe->vgaFile1 ||
-					_block <= vpe->vgaFile2 && _blockEnd >= vpe->vgaFile2) {
-				vpe->vgaFile1 = NULL;
-				vpe->vgaFile2 = NULL;
-			}
-		}
-	} while (++vpe, --count);
-}
-
-void AGOSEngine::set_video_mode_internal(uint16 mode, uint16 vga_res_id) {
-	uint num, num_lines;
-	VgaPointersEntry *vpe;
-	byte *bb, *b;
-	uint16 count, updateWindow;
-	const byte *vc_ptr_org;
-
-	_windowNum = updateWindow = mode;
-	_lockWord |= 0x20;
-
-	if (getGameType() == GType_FF || getGameType() == GType_PP) {
-		vc27_resetSprite();
-	}
-
-	if (vga_res_id == 0) {
-		if (getGameType() == GType_SIMON1) {
-			_unkPalFlag = true;
-		} else if (getGameType() == GType_SIMON2) {
-			_useBackGround = true;
-			_restoreWindow6 = true;
-		}
-	}
-
-	_zoneNumber = num = vga_res_id / 100;
-
-	for (;;) {
-		vpe = &_vgaBufferPointers[num];
-
-		_curVgaFile1 = vpe->vgaFile1;
-		_curVgaFile2 = vpe->vgaFile2;
-		_curSfxFile = vpe->sfxFile;
-
-		if (vpe->vgaFile1 != NULL)
-			break;
-
-		loadZone(num);
-	}
-
-	// ensure flipping complete
-
-	bb = _curVgaFile1;
-
-	if (getGameType() == GType_FF || getGameType() == GType_PP) {
-		b = bb + READ_LE_UINT16(bb + 2);
-		count = READ_LE_UINT16(&((VgaFileHeader2_Feeble *) b)->imageCount);
-		b = bb + READ_LE_UINT16(&((VgaFileHeader2_Feeble *) b)->imageTable);
-
-		while (count--) {
-			if (READ_LE_UINT16(&((ImageHeader_Feeble *) b)->id) == vga_res_id)
-				break;
-			b += sizeof(ImageHeader_Feeble);
-		}
-		assert(READ_LE_UINT16(&((ImageHeader_Feeble *) b)->id) == vga_res_id);
-
-	} else if (getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) {
-		b = bb + READ_BE_UINT16(bb + 4);
-		count = READ_BE_UINT16(&((VgaFileHeader2_Common *) b)->imageCount);
-		b = bb + READ_BE_UINT16(&((VgaFileHeader2_Common *) b)->imageTable);
-
-		while (count--) {
-			if (READ_BE_UINT16(&((ImageHeader_Simon *) b)->id) == vga_res_id)
-				break;
-			b += sizeof(ImageHeader_Simon);
-		}
-		assert(READ_BE_UINT16(&((ImageHeader_Simon *) b)->id) == vga_res_id);
-	} else {
-		b = bb + READ_BE_UINT16(bb + 10);
-		b += 20;
-
-		count = READ_BE_UINT16(&((VgaFileHeader2_Common *) b)->imageCount);
-		b = bb + READ_BE_UINT16(&((VgaFileHeader2_Common *) b)->imageTable);
-
-		while (count--) {
-			if (READ_BE_UINT16(&((ImageHeader_WW *) b)->id) == vga_res_id)
-				break;
-			b += sizeof(ImageHeader_WW);
-		}
-		assert(READ_BE_UINT16(&((ImageHeader_WW *) b)->id) == vga_res_id);
-
-		clearWindow(_windowNum, READ_BE_UINT16(&((ImageHeader_WW *) b)->color));
-	}
-
-	if (_startVgaScript) {
-		if (getGameType() == GType_FF || getGameType() == GType_PP) {
-			dump_vga_script(_curVgaFile1 + READ_LE_UINT16(&((ImageHeader_Feeble*)b)->scriptOffs), num, vga_res_id);
-		} else if (getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) {
-			dump_vga_script(_curVgaFile1 + READ_BE_UINT16(&((ImageHeader_Simon*)b)->scriptOffs), num, vga_res_id);
-		} else {
-			dump_vga_script(_curVgaFile1 + READ_BE_UINT16(&((ImageHeader_WW*)b)->scriptOffs), num, vga_res_id);
-		}
-	}
-
-	if (getGameType() == GType_SIMON1) {
-		if (vga_res_id == 16300) {
-			clearBackFromTop(134);
-			_usePaletteDelay = true;
-		}
-	} else if (getGameType() == GType_SIMON2 || getGameType() == GType_FF) {
-		_scrollX = 0;
-		_scrollY = 0;
-		_scrollXMax = 0;
-		_scrollYMax = 0;
-		_scrollCount = 0;
-		_scrollFlag = 0;
-		_scrollHeight = 134;
-		_variableArrayPtr = _variableArray;
-		if (_variableArray[34] >= 0) {
-			if (getGameType() == GType_FF)
-				_variableArray[250] = 0;
-			_variableArray[251] = 0;
-		}
-	}
-
-	vc_ptr_org = _vcPtr;
-
-	if (getGameType() == GType_FF || getGameType() == GType_PP) {
-		_vcPtr = _curVgaFile1 + READ_LE_UINT16(&((ImageHeader_Feeble *) b)->scriptOffs);
-	} else if (getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) {
-		_vcPtr = _curVgaFile1 + READ_BE_UINT16(&((ImageHeader_Simon *) b)->scriptOffs);
-	} else {
-		_vcPtr = _curVgaFile1 + READ_BE_UINT16(&((ImageHeader_WW *) b)->scriptOffs);
-	}
-
-	runVgaScript();
-	_vcPtr = vc_ptr_org;
-
-	if (getGameType() == GType_FF || getGameType() == GType_PP) {
-		fillFrontFromBack(0, 0, _screenWidth, _screenHeight);
-		fillBackGroundFromBack(_screenHeight);
-		_syncFlag2 = 1;
-	} else if (getGameType() == GType_SIMON2) {
-		if (!_useBackGround) {
-			num_lines = _windowNum == 4 ? 134 : 200;
-			_boxStarHeight = num_lines;
-			fillFrontFromBack(0, 0, _screenWidth, num_lines);
-			fillBackGroundFromBack(num_lines);
-			_syncFlag2 = 1;
-		}
-		_useBackGround = false;
-	} else {
-		// Allow one section of Simon the Sorcerer 1 introduction to be displayed
-		// in lower half of screen
-		if (_subroutine == 2923 || _subroutine == 2926)
-			num_lines = 200;
-		else
-			num_lines = _windowNum == 4 ? 134 : 200;
-
-		fillFrontFromBack(0, 0, _screenWidth, num_lines);
-		fillBackGroundFromBack(num_lines);
-
-		_syncFlag2 = 1;
-		_timer5 = 0;
-	}
-
-	if (getGameType() == GType_ELVIRA1 && updateWindow == 3 && _bottomPalette != 0) {
-		byte *dst = getBackBuf() + 42560;
-		int size = 21440;
-
-		while (size--) {
-			*dst += 0x10;
-			dst++;
-		}
-	}
-
-	_lockWord &= ~0x20;
-
-	if (getGameType() == GType_SIMON1) {
-		if (_unkPalFlag) {
-			_unkPalFlag = false;
-			while (_fastFadeInFlag != 0) {
-				delay(10);
-			}
-		}
-	}
-}
-
-void AGOSEngine::waitForSync(uint a) {
-	const uint maxCount = (getGameType() == GType_SIMON1) ? 500 : 1000;
-
-	if (getGameType() == GType_SIMON1 && (getFeatures() & GF_TALKIE)) {
-		if (a != 200) {
-			uint16 tmp = _lastVgaWaitFor;
-			_lastVgaWaitFor = 0;
-			if (tmp == a)
-				return;
-		}
-	}
-
-	_vgaWaitFor = a;
-	_syncCount = 0;
-	_exitCutscene = false;
-	_rightButtonDown = false;
-
-	while (_vgaWaitFor != 0) {
-		if (_rightButtonDown) {
-			if (_vgaWaitFor == 200 && (getGameType() == GType_FF || !getBitFlag(14))) {
-				skipSpeech();
-				break;
-			}
-		}
-		if (_exitCutscene) {
-			if (getGameType() == GType_ELVIRA1) {
-				if (_variableArray[105] == 0) {
-					_variableArray[105] = 255;
-					break;
-				}
-			} else if (getGameType() == GType_ELVIRA2 || getGameType() == GType_WW) {
-				if (_vgaWaitFor == 51) {
-					setBitFlag(244, 1);
-					break;
-				}
-			} else {
-				if (getBitFlag(9)) {
-					endCutscene();
-					break;
-				}
-			}
-		}
-		processSpecialKeys();
-
-		if (_syncCount >= maxCount) {
-			warning("waitForSync: wait timed out");
-			break;
-		}
-
-		delay(1);
-	}
-}
-
-void AGOSEngine::skipSpeech() {
-	_sound->stopVoice();
-	if (!getBitFlag(28)) {
-		setBitFlag(14, true);
-		if (getGameType() == GType_FF) {
-			_variableArray[103] = 5;
-			loadSprite(4, 2, 13, 0, 0, 0);
-			waitForSync(213);
-			stopAnimateSimon2(2, 1);
-		} else if (getGameType() == GType_SIMON2) {
-			_variableArray[100] = 5;
-			loadSprite(4, 1, 30, 0, 0, 0);
-			waitForSync(130);
-			stopAnimateSimon2(2, 1);
-		} else {
-			_variableArray[100] = 15;
-			loadSprite(4, 1, 130, 0, 0, 0);
-			waitForSync(130);
-			stopAnimateSimon1(1);
-		}
-	}
-}
-
-int AGOSEngine::wordMatch(Item *item, int16 a, int16 n) {
-	if ((a == -1) && (n == item->noun))
-		return 1;
-	if ((a == item->adjective) && (n == item->noun))
-		return 1 ;
-
-	return 0;
-}
-
-Item *AGOSEngine::derefItem(uint item) {
-	if (item >= _itemArraySize) {
-		debug(1, "derefItem: invalid item %d", item);
-		return 0;
-	}
-	return _itemArrayPtr[item];
-}
-
-Item *AGOSEngine::findInByClass(Item *i, int16 m) {
-	i = derefItem(i->child);
-
-	while (i) {
-		if (i->classFlags & m) {
-			//_findNextPtr = derefItem(i->next);
-			return i;
-		}
-		if (m == 0) {
-			//_findNextPtr = derefItem(i->next);
-			return i;
-		}
-		i = derefItem(i->next);
-	}
-
-	return NULL;
-}
-
-Item *AGOSEngine::findMaster(int16 a, int16 n) {
-	uint j;
-
-	for (j = 1; j < _itemArraySize; j++) {
-		Item *item = derefItem(j);
-		if (wordMatch(item, a, n))
-			return item;
-	}
-
-	return NULL;
-}
-
-Item *AGOSEngine::nextMaster(Item *i, int16 a, int16 n) {
-	uint j;
-	uint first = itemPtrToID(i) + 1;
-
-	for (j = first; j < _itemArraySize; j++) {
-		Item *item = derefItem(j);
-		if (wordMatch(item, a, n))
-			return item;
-	}
-
-	return NULL;
-}
-
-uint AGOSEngine::itemPtrToID(Item *id) {
-	uint i;
-	for (i = 0; i != _itemArraySize; i++)
-		if (_itemArrayPtr[i] == id)
-			return i;
-	error("itemPtrToID: not found");
-	return 0;
-}
-
-bool AGOSEngine::isSpriteLoaded(uint16 id, uint16 zoneNum) {
-	VgaSprite *vsp = _vgaSprites;
-	while (vsp->id) {
-		if (getGameType() == GType_SIMON2 || getGameType() == GType_FF || getGameType() == GType_PP) {
-			if (vsp->id == id && vsp->zoneNum == zoneNum)
-				return true;
-		} else {
-			if (vsp->id == id)
-				return true;
-		}
-		vsp++;
-	}
-	return false;
-}
-
-bool AGOSEngine::processSpecialKeys() {
-	switch (_keyPressed) {
-	case 17: // Up
-		if (getGameType() == GType_PP)
-			_verbHitArea = 302;
-		else if (getGameType() == GType_WW)
-			_verbHitArea = 239;
-		break;
-	case 18: // Down
-		if (getGameType() == GType_PP)
-			_verbHitArea = 304;
-		else if (getGameType() == GType_WW)
-			_verbHitArea = 241;
-		break;
-	case 19: // Right
-		if (getGameType() == GType_PP)
-			_verbHitArea = 303;
-		else if (getGameType() == GType_WW)
-			_verbHitArea = 240;
-		break;
-	case 20: // Left
-		if (getGameType() == GType_PP)
-			_verbHitArea = 301;
-		else if (getGameType() == GType_WW)
-			_verbHitArea = 242;
-		break;
-	case 27: // escape
-		_exitCutscene = true;
-		break;
-	case 59: // F1
-		if (getGameType() == GType_SIMON1) {
-			vcWriteVar(5, 40);
-		} else {
-			vcWriteVar(5, 50);
-		}
-		vcWriteVar(86, 0);
-		break;
-	case 60: // F2
-		if (getGameType() == GType_SIMON1) {
-			vcWriteVar(5, 60);
-		} else {
-			vcWriteVar(5, 75);
-		}
-		vcWriteVar(86, 1);
-		break;
-	case 61: // F3
-		if (getGameType() == GType_SIMON1) {
-			vcWriteVar(5, 100);
-		} else {
-			vcWriteVar(5, 125);
-		}
-		vcWriteVar(86, 2);
-		break;
-	case 63: // F5
-		if (getGameType() == GType_SIMON2 || getGameType() == GType_FF)
-			_exitCutscene = true;
-		break;
-	case 65: // F7
-		if (getGameType() == GType_FF && getBitFlag(76))
-			_variableArray[254] = 70;
-		break;
-	case 67: // F9
-		if (getGameType() == GType_FF)
-			setBitFlag(73, !getBitFlag(73));
-		break;
-	case 'p':
-		pause();
-		break;
-	case 't':
-		if (getGameType() == GType_FF || (getGameType() == GType_SIMON2 && (getFeatures() & GF_TALKIE)) ||
-			((getFeatures() & GF_TALKIE) && _language != Common::EN_ANY && _language != Common::DE_DEU)) {
-			if (_speech)
-				_subtitles ^= 1;
-		}
-		break;
-	case 'v':
-		if (getGameType() == GType_FF || (getGameType() == GType_SIMON2 && (getFeatures() & GF_TALKIE))) {
-			if (_subtitles)
-				_speech ^= 1;
-		}
-	case '+':
-		midi.set_volume(midi.get_volume() + 16);
-		break;
-	case '-':
-		midi.set_volume(midi.get_volume() - 16);
-		break;
-	case 'm':
-		midi.pause(_musicPaused ^= 1);
-		break;
-	case 's':
-		if (getGameId() == GID_SIMON1DOS)
-			midi._enable_sfx ^= 1;
-		else
-			_sound->effectsPause(_effectsPaused ^= 1);
-		break;
-	case 'b':
-		_sound->ambientPause(_ambientPaused ^= 1);
-		break;
-	case 'r':
-		if (_debugMode)
-			_startMainScript ^= 1;
-		break;
-	case 'o':
-		if (_debugMode)
-			_continousMainScript ^= 1;
-		break;
-	case 'a':
-		if (_debugMode)
-			_startVgaScript ^= 1;
-		break;
-	case 'g':
-		if (_debugMode)
-			_continousVgaScript ^= 1;
-		break;
-	case 'i':
-		if (_debugMode)
-			_drawImagesDebug ^= 1;
-		break;
-	case 'd':
-		if (_debugMode)
-			_dumpImages ^=1;
-		break;
-	}
-
-	bool result = (_keyPressed != 0);
-	_keyPressed = 0;
-	return result;
-}
-
 void AGOSEngine::pause() {
 	_keyPressed = 1;
 	_pause = 1;
@@ -2219,110 +809,6 @@
 
 }
 
-void AGOSEngine::loadSprite(uint windowNum, uint zoneNum, uint vgaSpriteId, uint x, uint y, uint palette) {
-	VgaSprite *vsp;
-	VgaPointersEntry *vpe;
-	byte *p, *pp;
-	uint count;
-
-	if (getGameType() == GType_SIMON1 && (getFeatures() & GF_TALKIE) && vgaSpriteId >= 400) {
-		_lastVgaWaitFor = 0;
-	}
-
-	_lockWord |= 0x40;
-
-	if (isSpriteLoaded(vgaSpriteId, zoneNum)) {
-		_lockWord &= ~0x40;
-		return;
-	}
-
-	vsp = _vgaSprites;
-	while (vsp->id != 0)
-		vsp++;
-
-	vsp->windowNum = windowNum;
-	vsp->priority = 0;
-	vsp->flags = 0;
-
-	vsp->y = y;
-	vsp->x = x;
-	vsp->image = 0;
-	if (getGameType() == GType_ELVIRA1 || getGameType() == GType_ELVIRA2 || getGameType() == GType_WW)
-		vsp->palette = 0;
-	else
-		vsp->palette = palette;
-	vsp->id = vgaSpriteId;
-
-	if (getGameType() == GType_SIMON2 || getGameType() == GType_FF || getGameType() == GType_PP)
-		vsp->zoneNum = zoneNum;
-	else
-		vsp->zoneNum = zoneNum = vgaSpriteId / 100;
-
-	for (;;) {
-		vpe = &_vgaBufferPointers[zoneNum];
-		_zoneNumber = zoneNum;
-		_curVgaFile1 = vpe->vgaFile1;
-		if (vpe->vgaFile1 != NULL)
-			break;
-		loadZone(zoneNum);
-	}
-
-	pp = _curVgaFile1;
-	if (getGameType() == GType_FF || getGameType() == GType_PP) {
-		p = pp + READ_LE_UINT16(pp + 2);
-		count = READ_LE_UINT16(&((VgaFileHeader2_Feeble *) p)->animationCount);
-		p = pp + READ_LE_UINT16(&((VgaFileHeader2_Feeble *) p)->animationTable);
-	} else if (getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) {
-		p = pp + READ_BE_UINT16(pp + 4);
-		count = READ_BE_UINT16(&((VgaFileHeader2_Common *) p)->animationCount);
-		p = pp + READ_BE_UINT16(&((VgaFileHeader2_Common *) p)->animationTable);
-	} else {
-		p = pp + READ_BE_UINT16(pp + 10);
-		p += 20;
-
-		count = READ_BE_UINT16(&((VgaFileHeader2_Common *) p)->animationCount);
-		p = pp + READ_BE_UINT16(&((VgaFileHeader2_Common *) p)->animationTable);
-	}
-
-	for (;;) {
-		if (getGameType() == GType_FF || getGameType() == GType_PP) {
-			if (READ_LE_UINT16(&((AnimationHeader_Feeble *) p)->id) == vgaSpriteId) {
-				if (_startVgaScript)
-					dump_vga_script(pp + READ_LE_UINT16(&((AnimationHeader_Feeble*)p)->scriptOffs), zoneNum, vgaSpriteId);
-
-				addVgaEvent(_vgaBaseDelay, pp + READ_LE_UINT16(&((AnimationHeader_Feeble *) p)->scriptOffs), vgaSpriteId, zoneNum);
-				break;
-			}
-			p += sizeof(AnimationHeader_Feeble);
-		} else if (getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) {
-			if (READ_BE_UINT16(&((AnimationHeader_Simon *) p)->id) == vgaSpriteId) {
-				if (_startVgaScript)
-					dump_vga_script(pp + READ_BE_UINT16(&((AnimationHeader_Simon*)p)->scriptOffs), zoneNum, vgaSpriteId);
-
-				addVgaEvent(_vgaBaseDelay, pp + READ_BE_UINT16(&((AnimationHeader_Simon *) p)->scriptOffs), vgaSpriteId, zoneNum);
-				break;
-			}
-			p += sizeof(AnimationHeader_Simon);
-		} else {
-			if (READ_BE_UINT16(&((AnimationHeader_WW *) p)->id) == vgaSpriteId) {
-				if (_startVgaScript)
-					dump_vga_script(pp + READ_BE_UINT16(&((AnimationHeader_WW *)p)->scriptOffs), zoneNum, vgaSpriteId);
-
-				addVgaEvent(_vgaBaseDelay, pp + READ_BE_UINT16(&((AnimationHeader_WW *) p)->scriptOffs), vgaSpriteId, zoneNum);
-				break;
-			}
-			p += sizeof(AnimationHeader_WW);
-		}
-
-		if (!--count) {
-			vsp->id = 0;
-			break;
-		}
-	}
-
-	_lockWord &= ~0x40;
-}
-
 void AGOSEngine::playSpeech(uint speech_id, uint vgaSpriteId) {
 	if (getGameType() == GType_SIMON1) {
 		if (speech_id == 9999) {
@@ -2331,19 +817,19 @@
 			if (!getBitFlag(14) && !getBitFlag(28)) {
 				setBitFlag(14, true);
 				_variableArray[100] = 15;
-				loadSprite(4, 1, 130, 0, 0, 0);
+				animate(4, 1, 130, 0, 0, 0);
 				waitForSync(130);
 			}
 			_skipVgaWait = true;
 		} else {
 			if (_subtitles && _scriptVar2) {
-				loadSprite(4, 2, 204, 0, 0, 0);
+				animate(4, 2, 204, 0, 0, 0);
 				waitForSync(204);
 				stopAnimateSimon1(204);
 			}
 			stopAnimateSimon1(vgaSpriteId + 201);
 			loadVoice(speech_id);
-			loadSprite(4, 2, vgaSpriteId + 201, 0, 0, 0);
+			animate(4, 2, vgaSpriteId + 201, 0, 0, 0);
 		}
 	} else {
 		if (speech_id == 0xFFFF) {
@@ -2352,7 +838,7 @@
 			if (!getBitFlag(14) && !getBitFlag(28)) {
 				setBitFlag(14, true);
 				_variableArray[100] = 5;
-				loadSprite(4, 1, 30, 0, 0, 0);
+				animate(4, 1, 30, 0, 0, 0);
 				waitForSync(130);
 			}
 			_skipVgaWait = true;
@@ -2363,18 +849,41 @@
 			}
 
 			if (_subtitles && _scriptVar2) {
-				loadSprite(4, 2, 5, 0, 0, 0);
+				animate(4, 2, 5, 0, 0, 0);
 				waitForSync(205);
 				stopAnimateSimon2(2,5);
 			}
 
 			stopAnimateSimon2(2, vgaSpriteId + 2);
 			loadVoice(speech_id);
-			loadSprite(4, 2, vgaSpriteId + 2, 0, 0, 0);
+			animate(4, 2, vgaSpriteId + 2, 0, 0, 0);
 		}
 	}
 }
 
+void AGOSEngine::skipSpeech() {
+	_sound->stopVoice();
+	if (!getBitFlag(28)) {
+		setBitFlag(14, true);
+		if (getGameType() == GType_FF) {
+			_variableArray[103] = 5;
+			animate(4, 2, 13, 0, 0, 0);
+			waitForSync(213);
+			stopAnimateSimon2(2, 1);
+		} else if (getGameType() == GType_SIMON2) {
+			_variableArray[100] = 5;
+			animate(4, 1, 30, 0, 0, 0);
+			waitForSync(130);
+			stopAnimateSimon2(2, 1);
+		} else {
+			_variableArray[100] = 15;
+			animate(4, 1, 130, 0, 0, 0);
+			waitForSync(130);
+			stopAnimateSimon1(1);
+		}
+	}
+}
+
 int AGOSEngine::go() {
 
 	loadGamePcFile();

Modified: scummvm/trunk/engines/agos/agos.h
===================================================================
--- scummvm/trunk/engines/agos/agos.h	2006-10-19 23:57:54 UTC (rev 24393)
+++ scummvm/trunk/engines/agos/agos.h	2006-10-20 02:10:51 UTC (rev 24394)
@@ -771,7 +771,7 @@
 
 	void loadZone(uint zoneNum);
 
-	void loadSprite(uint windowNum, uint vga_res, uint vga_sprite_id, uint x, uint y, uint palette);
+	void animate(uint windowNum, uint zoneNum, uint vgaSpriteId, uint x, uint y, uint palette, bool setZone = true);
 	void playSpeech(uint speech_id, uint vga_sprite_id);
 	void skipSpeech();
 

Added: scummvm/trunk/engines/agos/gfx.cpp
===================================================================
--- scummvm/trunk/engines/agos/gfx.cpp	                        (rev 0)
+++ scummvm/trunk/engines/agos/gfx.cpp	2006-10-20 02:10:51 UTC (rev 24394)
@@ -0,0 +1,743 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001  Ludvig Strigeus
+ * Copyright (C) 2001-2006 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "common/stdafx.h"
+
+#include "agos/agos.h"
+#include "agos/intern.h"
+#include "agos/vga.h"
+
+namespace AGOS {
+
+byte *vc10_depackColumn(VC10_state * vs) {
+	int8 a = vs->depack_cont;
+	const byte *src = vs->depack_src;
+	byte *dst = vs->depack_dest;
+	uint16 dh = vs->dh;
+	byte color;
+
+	if (a == -0x80)
+		a = *src++;
+
+	for (;;) {
+		if (a >= 0) {
+			color = *src++;
+			do {
+				*dst++ = color;
+				if (!--dh) {
+					if (--a < 0)
+						a = -0x80;
+					else
+						src--;
+					goto get_out;
+				}
+			} while (--a >= 0);
+		} else {
+			do {
+				*dst++ = *src++;
+				if (!--dh) {
+					if (++a == 0)
+						a = -0x80;
+					goto get_out;
+				}
+			} while (++a != 0);
+		}
+		a = *src++;
+	}
+
+get_out:;
+	vs->depack_src = src;
+	vs->depack_cont = a;
+	return vs->depack_dest + vs->y_skip;
+}
+
+void vc10_skip_cols(VC10_state *vs) {
+	while (vs->x_skip) {
+		vc10_depackColumn(vs);
+		vs->x_skip--;
+	}
+}
+
+void AGOSEngine::decodeColumn(byte *dst, const byte *src, int height) {
+	const uint pitch = _dxSurfacePitch;
+	int8 reps = (int8)0x80;
+	byte color;
+	byte *dstPtr = dst;
+	uint h = height, w = 8;
+
+	for (;;) {
+		reps = *src++;
+		if (reps >= 0) {
+			color = *src++;
+
+			do {
+				*dst = color;
+				dst += pitch;
+
+				/* reached bottom? */
+				if (--h == 0) {
+					/* reached right edge? */
+					if (--w == 0)
+						return;
+					dst = ++dstPtr;
+					h = height;
+				}
+			} while (--reps >= 0);
+		} else {
+
+			do {
+				*dst = *src++;
+				dst += pitch;
+
+				/* reached bottom? */
+				if (--h == 0) {
+					/* reached right edge? */
+					if (--w == 0)
+						return;
+					dst = ++dstPtr;
+					h = height;
+				}
+			} while (++reps != 0);
+		}
+	}
+}
+
+void AGOSEngine::decodeRow(byte *dst, const byte *src, int width) {
+	const uint pitch = _dxSurfacePitch;
+	int8 reps = (int8)0x80;
+	byte color;
+	byte *dstPtr = dst;
+	uint w = width, h = 8;
+
+	for (;;) {
+		reps = *src++;
+		if (reps >= 0) {
+			color = *src++;
+
+			do {
+				*dst++ = color;
+
+				/* reached right edge? */
+				if (--w == 0) {
+					/* reached bottom? */
+					if (--h == 0)
+						return;
+					dstPtr += pitch;
+					dst = dstPtr;
+					w = width;
+				}
+			} while (--reps >= 0);
+		} else {
+
+			do {
+				*dst++ = *src++;
+
+				/* reached right edge? */
+				if (--w == 0) {
+					/* reached bottom? */
+					if (--h == 0)
+						return;
+					dstPtr += pitch;
+					dst = dstPtr;
+					w = width;
+				}
+			} while (++reps != 0);
+		}
+	}
+}
+
+bool AGOSEngine::drawImages_clip(VC10_state *state) {
+	const uint16 *vlut;
+	uint maxWidth, maxHeight;
+	int cur;
+
+	vlut = &_videoWindows[_windowNum * 4];
+
+	if (getGameType() != GType_FF && getGameType() != GType_PP) {
+		state->draw_width = state->width * 2;
+	} 
+
+	cur = state->x;
+	if (cur < 0) {
+		do {
+			if (!--state->draw_width)
+				return 0;
+			state->x_skip++;
+		} while (++cur);
+	}
+	state->x = cur;
+
+	maxWidth = (getGameType() == GType_FF || getGameType() == GType_PP) ? _screenWidth : (vlut[2] * 2);
+	cur += state->draw_width - maxWidth;
+	if (cur > 0) {
+		do {
+			if (!--state->draw_width)
+				return 0;
+		} while (--cur);
+	}
+
+	cur = state->y;
+	if (cur < 0) {
+		do {
+			if (!--state->draw_height)
+				return 0;
+			state->y_skip++;
+		} while (++cur);
+	}
+	state->y = cur;
+
+	maxHeight = (getGameType() == GType_FF || getGameType() == GType_PP) ? _screenHeight : vlut[3];
+	cur += state->draw_height - maxHeight;
+	if (cur > 0) {
+		do {
+			if (!--state->draw_height)
+				return 0;
+		} while (--cur);
+	}
+
+	assert(state->draw_width != 0 && state->draw_height != 0);
+
+	if (getGameType() != GType_FF && getGameType() != GType_PP) {
+		state->draw_width *= 4;
+	}
+
+	return 1;
+}
+
+void AGOSEngine::drawImages_Feeble(VC10_state *state) {
+	if (state->flags & kDFCompressed) {
+		if (state->flags & kDFScaled) {
+			state->surf_addr = getScaleBuf();
+			state->surf_pitch = _dxSurfacePitch;
+
+			uint w, h;
+			byte *src, *dst, *dstPtr;
+
+			state->dl = state->width;
+			state->dh = state->height;
+
+			dstPtr = state->surf_addr;
+			w = 0;
+			do {
+				src = vc10_depackColumn(state);
+				dst = dstPtr;
+
+				h = 0;
+				do {
+					*dst = *src;
+					dst += _screenWidth;
+					src++;
+				} while (++h != state->draw_height);
+				dstPtr++;
+			} while (++w != state->draw_width);
+
+			if (_vgaCurSpritePriority % 10 != 9) {
+				_scaleX = state->x;
+				_scaleY = state->y;
+				_scaleWidth = state->width;
+				_scaleHeight = state->height;
+			} else {
+				scaleClip(state->height, state->width, state->y, state->x, state->y + _scrollY);
+			}
+		} else if (state->flags & kDFOverlayed) {
+			state->surf_addr = getScaleBuf();
+			state->surf_pitch = _dxSurfacePitch;
+			state->surf_addr += (state->x + _scrollX) + (state->y + _scrollY) * state->surf_pitch;
+
+			uint w, h;
+			byte *src, *dst, *dstPtr;
+
+			state->dl = state->width;
+			state->dh = state->height;
+
+			dstPtr = state->surf_addr;
+			w = 0;
+			do {
+				byte color;
+
+				src = vc10_depackColumn(state);
+				dst = dstPtr;
+
+				h = 0;
+				do {
+					color = *src;
+					if (color != 0)
+						*dst = color;
+					dst += _screenWidth;
+					src++;
+				} while (++h != state->draw_height);
+				dstPtr++;
+			} while (++w != state->draw_width);
+
+			if (_vgaCurSpritePriority % 10 == 9) {
+				scaleClip(_scaleHeight, _scaleWidth, _scaleY, _scaleX, _scaleY + _scrollY);
+			}
+		} else {
+			if (drawImages_clip(state) == 0)
+				return;
+
+			state->surf_addr += state->x + state->y * state->surf_pitch;
+
+			uint w, h;
+			byte *src, *dst, *dstPtr;
+
+			state->dl = state->width;
+			state->dh = state->height;
+
+			vc10_skip_cols(state);
+
+
+			if (state->flags & kDFMasked) {
+				if (getGameType() == GType_FF && !getBitFlag(81)) {
+					if (state->x  > _feebleRect.right)
+						return;
+					if (state->y > _feebleRect.bottom)
+						return;
+					if (state->x + state->width < _feebleRect.left)
+						return;
+					if (state->y + state->height < _feebleRect.top)
+						return;
+				}
+
+				dstPtr = state->surf_addr;
+				w = 0;
+				do {
+					byte color;
+
+					src = vc10_depackColumn(state);
+					dst = dstPtr;
+
+					h = 0;
+					do {
+						color = *src;
+						if (color)
+							*dst = color;
+						dst += _screenWidth;
+						src++;
+					} while (++h != state->draw_height);
+					dstPtr++;
+				} while (++w != state->draw_width);
+			} else {
+				dstPtr = state->surf_addr;
+				w = 0;
+				do {
+					byte color;
+
+					src = vc10_depackColumn(state);
+					dst = dstPtr;
+
+					h = 0;
+					do {
+						color = *src;
+						if ((state->flags & kDFNonTrans) || color != 0)
+							*dst = color;
+						dst += _screenWidth;
+						src++;
+					} while (++h != state->draw_height);
+					dstPtr++;
+				} while (++w != state->draw_width);
+			}
+		}
+	} else {
+		if (drawImages_clip(state) == 0)
+			return;
+
+		state->surf_addr += state->x + state->y * state->surf_pitch;
+
+		const byte *src;
+		byte *dst;
+		uint count;
+
+		src = state->depack_src + state->width * state->y_skip;
+		dst = state->surf_addr;
+		do {
+			for (count = 0; count != state->draw_width; count++) {
+				byte color;
+				color = src[count + state->x_skip];
+				if (color) {
+					if ((state->flags & kDFShaded) && color == 220)
+						color = 244;
+
+					dst[count] = color;
+				}
+			}
+			dst += _screenWidth;
+			src += state->width;
+		} while (--state->draw_height);
+	} 
+}
+
+void AGOSEngine::drawImages(VC10_state *state) {
+	const uint16 *vlut = &_videoWindows[_windowNum * 4];
+
+	if (drawImages_clip(state) == 0)
+		return;
+
+	uint xoffs, yoffs;
+	if (getGameType() == GType_ELVIRA1) {
+		//if (_windowNum != 2 && _windowNum != 3 && _windowNum != 6) {
+		//	xoffs = ((vlut[0] - _videoWindows[16]) * 2 + state->x) * 8;
+		//	yoffs = (vlut[1] - _videoWindows[17] + state->y);
+		//} else {
+			xoffs = (vlut[0] * 2 + state->x) * 8;
+			yoffs = vlut[1] + state->y;
+		//}
+	} else if (getGameType() == GType_ELVIRA2) {
+		//if (_windowNum == 4 || _windowNum >= 10) {
+		//	xoffs = ((vlut[0] - _videoWindows[16]) * 2 + state->x) * 8;
+		//	yoffs = (vlut[1] - _videoWindows[17] + state->y);
+		//} else {
+			xoffs = (vlut[0] * 2 + state->x) * 8;
+			yoffs = vlut[1] + state->y;
+		//}
+	} else if (getGameType() == GType_WW) {
+		//if (_windowNum == 4 || (_windowNum >= 10 && _windowNum < 28)) {
+		//	xoffs = ((vlut[0] - _videoWindows[16]) * 2 + state->x) * 8;
+		//	yoffs = (vlut[1] - _videoWindows[17] + state->y);
+		//} else {
+			xoffs = (vlut[0] * 2 + state->x) * 8;
+			yoffs = vlut[1] + state->y;
+		//}
+	} else if (getGameType() == GType_SIMON1 && (_subroutine == 2923 || _subroutine == 2926)) {
+		// Allow one section of Simon the Sorcerer 1 introduction to be displayed
+		// in lower half of screen
+		xoffs = state->x * 8;
+		yoffs = state->y;
+	} else {
+		xoffs = ((vlut[0] - _videoWindows[16]) * 2 + state->x) * 8;
+		yoffs = (vlut[1] - _videoWindows[17] + state->y);
+	}
+
+	state->surf2_addr += xoffs + yoffs * state->surf_pitch;
+	state->surf_addr += xoffs + yoffs * state->surf2_pitch;
+
+	if (state->flags & kDFMasked) {
+		byte *mask, *src, *dst;
+		byte h;
+		uint w;
+
+		state->x_skip *= 4;
+		state->dl = state->width;
+		state->dh = state->height;
+
+		vc10_skip_cols(state);
+
+		w = 0;
+		do {
+			mask = vc10_depackColumn(state);	/* esi */
+			src = state->surf2_addr + w * 2;	/* ebx */
+			dst = state->surf_addr + w * 2;		/* edi */
+
+			h = state->draw_height;
+			if ((getGameType() == GType_SIMON1) && getBitFlag(88)) {
+				/* transparency */
+				do {
+					if (mask[0] & 0xF0) {
+						if ((dst[0] & 0x0F0) == 0x20)
+							dst[0] = src[0];
+					}
+					if (mask[0] & 0x0F) {
+						if ((dst[1] & 0x0F0) == 0x20)
+							dst[1] = src[1];
+					}
+					mask++;
+					dst += state->surf_pitch;
+					src += state->surf2_pitch;
+				} while (--h);
+			} else {
+				/* no transparency */
+				do {
+					if (mask[0] & 0xF0)
+						dst[0] = src[0];
+					if (mask[0] & 0x0F)
+						dst[1] = src[1];
+					mask++;
+					dst += state->surf_pitch;
+					src += state->surf2_pitch;
+				} while (--h);
+			}
+		} while (++w != state->draw_width);
+	} else if ((((_lockWord & 0x20) && state->palette == 0) || state->palette == 0xC0) &&
+		(getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) &&
+		getPlatform() != Common::kPlatformAmiga) {
+		const byte *src;
+		byte *dst;
+		uint h, i;
+
+		if (state->flags & kDFCompressed) {
+			byte *dstPtr = state->surf_addr;
+			src = state->depack_src;
+			/* AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE
+			 * aaaaabbb bbcccccd ddddeeee efffffgg ggghhhhh
+			 */
+
+			do {
+				uint count = state->draw_width / 4;
+
+				dst = dstPtr;
+				do {
+					uint32 bits = (src[0] << 24) | (src[1] << 16) | (src[2] << 8) | (src[3]);
+					byte color;
+
+					color = (byte)((bits >> (32 - 5)) & 31);
+					if ((state->flags & kDFNonTrans) || color)
+						dst[0] = color;
+					color = (byte)((bits >> (32 - 10)) & 31);
+					if ((state->flags & kDFNonTrans) || color)
+						dst[1] = color;
+					color = (byte)((bits >> (32 - 15)) & 31);
+					if ((state->flags & kDFNonTrans) || color)
+						dst[2] = color;
+					color = (byte)((bits >> (32 - 20)) & 31);
+					if ((state->flags & kDFNonTrans) || color)
+						dst[3] = color;
+					color = (byte)((bits >> (32 - 25)) & 31);
+					if ((state->flags & kDFNonTrans) || color)
+						dst[4] = color;
+					color = (byte)((bits >> (32 - 30)) & 31);
+					if ((state->flags & kDFNonTrans) || color)
+						dst[5] = color;
+
+					bits = (bits << 8) | src[4];
+
+					color = (byte)((bits >> (40 - 35)) & 31);
+					if ((state->flags & kDFNonTrans) || color)
+						dst[6] = color;
+					color = (byte)((bits) & 31);
+					if ((state->flags & kDFNonTrans) || color)
+						dst[7] = color;
+
+					dst += 8;
+					src += 5;
+				} while (--count);
+				dstPtr += _screenWidth;
+			} while (--state->draw_height);
+		} else {
+			src = state->depack_src + (state->width * state->y_skip * 16) + (state->x_skip * 8);
+			dst = state->surf_addr;
+
+			state->draw_width *= 2;
+
+			h = state->draw_height;
+			do {
+				for (i = 0; i != state->draw_width; i++)
+					if ((state->flags & kDFNonTrans) || src[i])
+						dst[i] = src[i];
+				dst += _screenWidth;
+				src += state->width * 16;
+			} while (--h);
+		}
+	} else {
+		if (getGameType() == GType_SIMON2 && state->flags & kDFUseFrontBuf && getBitFlag(171)) {
+			state->surf_addr = state->surf2_addr;
+			state->surf_pitch = state->surf2_pitch;
+		}
+
+		if (getGameType() == GType_ELVIRA2 || getGameType() == GType_WW)
+			state->palette = state->surf_addr[0] & 0xF0;
+
+		if (state->flags & kDFCompressed) {
+			uint w, h;
+			byte *src, *dst, *dstPtr;
+
+			state->x_skip *= 4;				/* reached */
+
+			state->dl = state->width;
+			state->dh = state->height;
+
+			vc10_skip_cols(state);
+
+			dstPtr = state->surf_addr;
+			if (!(state->flags & kDFNonTrans) && (state->flags & 0x40)) { /* reached */
+				dstPtr += vcReadVar(252);
+			}
+			w = 0;
+			do {
+				byte color;
+
+				src = vc10_depackColumn(state);
+				dst = dstPtr;
+
+				h = 0;
+				do {
+					color = (*src / 16);
+					if ((state->flags & kDFNonTrans) || color != 0)
+						dst[0] = color | state->palette;
+					color = (*src & 15);
+					if ((state->flags & kDFNonTrans) || color != 0)
+						dst[1] = color | state->palette;
+					dst += _screenWidth;
+					src++;
+				} while (++h != state->draw_height);
+				dstPtr += 2;
+			} while (++w != state->draw_width);
+		} else {
+			const byte *src;
+			byte *dst;
+			uint count;
+
+			src = state->depack_src + (state->width * state->y_skip) * 8;
+			dst = state->surf_addr;
+			state->x_skip *= 4;
+
+			do {
+				for (count = 0; count != state->draw_width; count++) {
+					byte color;
+					color = (src[count + state->x_skip] / 16);
+					if ((state->flags & kDFNonTrans) || color)
+						dst[count * 2] = color | state->palette;
+					color = (src[count + state->x_skip] & 15);
+					if ((state->flags & kDFNonTrans) || color)
+						dst[count * 2 + 1] = color | state->palette;
+				}
+				dst += _screenWidth;
+				src += state->width * 8;
+			} while (--state->draw_height);
+		}
+	}
+}
+
+void AGOSEngine::horizontalScroll(VC10_state *state) {
+	const byte *src;
+	byte *dst;
+	int w;
+
+	if (getGameType() == GType_FF)
+		_scrollXMax = state->width - 640;
+	else
+		_scrollXMax = state->width * 2 - 40;
+	_scrollYMax = 0;
+	_scrollImage = state->depack_src;
+	_scrollHeight = state->height;
+	if (_variableArrayPtr[34] < 0)
+		state->x = _variableArrayPtr[251];
+
+	_scrollX = state->x;
+
+	vcWriteVar(251, _scrollX);
+
+	dst = getBackBuf();
+
+	if (getGameType() == GType_FF)
+		src = state->depack_src + _scrollX / 2;
+	else
+		src = state->depack_src + _scrollX * 4;
+
+	for (w = 0; w < _screenWidth; w += 8) {
+		decodeColumn(dst, src + readUint32Wrapper(src), state->height);
+		dst += 8;
+		src += 4;
+	}
+}
+
+void AGOSEngine::verticalScroll(VC10_state *state) {
+	const byte *src;
+	byte *dst;
+	int h;
+
+	_scrollXMax = 0;
+	_scrollYMax = state->height - 480;
+	_scrollImage = state->depack_src;
+	_scrollWidth = state->width;
+	if (_variableArrayPtr[34] < 0)
+		state->y = _variableArrayPtr[250];
+
+	_scrollY = state->y;
+
+	vcWriteVar(250, _scrollY);
+
+	dst = getBackBuf();
+	src = state->depack_src + _scrollY / 2;
+
+	for (h = 0; h < _screenHeight; h += 8) {
+		decodeRow(dst, src + READ_LE_UINT32(src), state->width);
+		dst += 8 * state->width;
+		src += 4;
+	}
+}
+
+void AGOSEngine::scaleClip(int16 h, int16 w, int16 y, int16 x, int16 scrollY) {
+	Common::Rect srcRect, dstRect;
+	float factor, xscale;
+
+	srcRect.left = 0;
+	srcRect.top = 0;
+	srcRect.right = w;
+	srcRect.bottom = h;
+
+	if (scrollY > _baseY)
+		factor = 1 + ((scrollY - _baseY) * _scale);
+	else
+		factor = 1 - ((_baseY - scrollY) * _scale);
+
+	xscale = ((w * factor) / 2);
+
+	dstRect.left   = (int16)(x - xscale);
+	if (dstRect.left > _screenWidth - 1)
+		return;
+	dstRect.top    = (int16)(y - (h * factor));
+	if (dstRect.top > _screenHeight - 1)
+		return;
+
+	dstRect.right  = (int16)(x + xscale);
+	dstRect.bottom = y;
+
+	_feebleRect = dstRect;
+
+	_variableArray[20] = _feebleRect.top;
+	_variableArray[21] = _feebleRect.left;
+	_variableArray[22] = _feebleRect.bottom;
+	_variableArray[23] = _feebleRect.right;
+
+	debug(5, "Left %d Right %d Top %d Bottom %d", dstRect.left, dstRect.right, dstRect.top, dstRect.bottom);
+
+	// Unlike normal rectangles in ScummVM, it seems that in the case of
+	// the destination rectangle the bottom and right coordinates are
+	// considered to be inside the rectangle. For the source rectangle,
+	// I believe that they are not.
+
+	int scaledW = dstRect.width() + 1;
+	int scaledH = dstRect.height() + 1;
+
+	byte *src = getScaleBuf();
+	byte *dst = getBackBuf();
+
+	dst += _dxSurfacePitch * dstRect.top + dstRect.left;
+
+	for (int dstY = 0; dstY < scaledH; dstY++) {
+		if (dstRect.top + dstY >= 0 && dstRect.top + dstY < _screenHeight) {
+			int srcY = (dstY * h) / scaledH;
+			byte *srcPtr = src + _dxSurfacePitch * srcY;
+			byte *dstPtr = dst + _dxSurfacePitch * dstY;
+			for (int dstX = 0; dstX < scaledW; dstX++) {
+				if (dstRect.left + dstX >= 0 && dstRect.left + dstX < _screenWidth) {
+					int srcX = (dstX * w) / scaledW;
+					if (srcPtr[srcX])
+						dstPtr[dstX] = srcPtr[srcX];
+				}
+			}
+		}
+	}
+}
+
+} // End of namespace AGOS


Property changes on: scummvm/trunk/engines/agos/gfx.cpp
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Modified: scummvm/trunk/engines/agos/icons.cpp
===================================================================
--- scummvm/trunk/engines/agos/icons.cpp	2006-10-19 23:57:54 UTC (rev 24393)
+++ scummvm/trunk/engines/agos/icons.cpp	2006-10-20 02:10:51 UTC (rev 24394)
@@ -557,7 +557,7 @@
 		ha->verb = 1;
 
 		stopAnimateSimon1(128);
-		loadSprite(0, 1, 128, 0, 0, 14);
+		animate(0, 1, 128, 0, 0, 14);
 	} else if (getGameType() == GType_WW) {
 		ha->x = 255;
 		ha->y = 170;

Added: scummvm/trunk/engines/agos/input.cpp
===================================================================
--- scummvm/trunk/engines/agos/input.cpp	                        (rev 0)
+++ scummvm/trunk/engines/agos/input.cpp	2006-10-20 02:10:51 UTC (rev 24394)
@@ -0,0 +1,518 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001  Ludvig Strigeus
+ * Copyright (C) 2001-2006 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "common/stdafx.h"
+
+#include "common/file.h"
+
+#include "agos/intern.h"
+#include "agos/agos.h"
+#include "agos/vga.h"
+
+namespace AGOS {
+
+void AGOSEngine::setup_cond_c_helper() {
+	HitArea *last;
+	uint id;
+
+	_noRightClick = 1;
+
+	if (getGameType() == GType_WW)
+		clearMenuStrip();
+
+	if (getGameType() == GType_FF) {
+		int cursor = 5;
+		int animMax = 16;
+
+		if (getBitFlag(200)) {
+			cursor = 11;
+			animMax = 5;
+		} else if (getBitFlag(201)) {
+			cursor = 12;
+			animMax = 5;
+		} else if (getBitFlag(202)) {
+			cursor = 13;
+			animMax = 5;
+		} else if (getBitFlag(203)) {
+			cursor = 14;
+			animMax = 9;
+		} else if (getBitFlag(205)) {
+			cursor = 17;
+			animMax = 11;
+		} else if (getBitFlag(206)) {
+			cursor = 16;
+			animMax = 2;
+		} else if (getBitFlag(208)) {
+			cursor = 26;
+			animMax = 2;
+		} else if (getBitFlag(209)) {
+			cursor = 27;
+			animMax = 9;
+		} else if (getBitFlag(210)) {
+			cursor = 28;
+			animMax = 9;
+		}
+
+		_animatePointer = 0;
+		_mouseCursor = cursor;
+		_mouseAnimMax = animMax;
+		_mouseAnim = 1;
+		_needHitAreaRecalc++;
+	}
+
+	if (getGameType() == GType_SIMON2) {
+		_mouseCursor = 0;
+		if (_defaultVerb != 999) {
+			_mouseCursor = 9;
+			_needHitAreaRecalc++;
+			_defaultVerb = 0;
+		}
+	}
+
+	_lastHitArea = 0;
+	_hitAreaObjectItem = NULL;
+	_nameLocked = 0;
+
+	last = _lastNameOn;
+	clearName();
+	_lastNameOn = last;
+
+	for (;;) {
+		_lastHitArea = NULL;
+		_lastHitArea3 = 0;
+		_leftButtonDown = 0;
+
+		do {
+			if (_exitCutscene && getBitFlag(9)) {
+				endCutscene();
+				goto out_of_here;
+			}
+
+			if (getGameType() == GType_FF) {
+				if (_variableArray[254] == 63) {
+					hitarea_stuff_helper_2();
+				} else if (_variableArray[254] == 75) {
+					hitarea_stuff_helper_2();
+					_variableArray[60] = 9999;
+					goto out_of_here;
+				}
+			}
+
+			delay(100);
+		} while (_lastHitArea3 == (HitArea *) -1 || _lastHitArea3 == 0);
+
+		if (_lastHitArea == NULL) {
+		} else if (_lastHitArea->id == 0x7FFB) {
+			inventoryUp(_lastHitArea->window);
+		} else if (_lastHitArea->id == 0x7FFC) {
+			inventoryDown(_lastHitArea->window);
+		} else if (_lastHitArea->item_ptr != NULL) {
+			_hitAreaObjectItem = _lastHitArea->item_ptr;
+			id = 0xFFFF;
+			if (_lastHitArea->flags & kBFTextBox) {
+				if (getGameType() == GType_PP)
+					id = _lastHitArea->id;
+				else if (getGameType() == GType_FF && (_lastHitArea->flags & kBFHyperBox))
+					id = _lastHitArea->data;
+				else
+					id = _lastHitArea->flags / 256;
+			}
+			if (getGameType() == GType_PP)
+				_variableArray[199] = id;
+			else if (getGameType() == GType_WW)
+				_variableArray[10] = id;
+			else
+				_variableArray[60] = id;
+			break;
+		}
+	}
+
+out_of_here:
+	_lastHitArea3 = 0;
+	_lastHitArea = 0;
+	_lastNameOn = NULL;
+	_mouseCursor = 0;
+	_noRightClick = 0;
+}
+
+void AGOSEngine::waitForInput() {
+	HitArea *ha;
+	uint id;
+
+	_leftButtonDown = 0;
+	_lastHitArea = 0;
+	_verbHitArea = 0;
+	_hitAreaSubjectItem = NULL;
+	_hitAreaObjectItem = NULL;
+	_nameLocked = 0;
+
+	if (getGameType() == GType_WW) {
+		_mouseCursor = 0;
+		_needHitAreaRecalc++;
+		clearMenuStrip();
+	} else {
+		resetVerbs();
+	}
+
+startOver:
+	for (;;) {
+		_lastHitArea = NULL;
+		_lastHitArea3 = NULL;
+
+		for (;;) {
+			if (getGameType() != GType_FF && getGameType() != GType_PP && _keyPressed == 35)
+				displayBoxStars();
+			if (processSpecialKeys() != 0) {
+				goto out_of_here;
+			}
+			if (_lastHitArea3 == (HitArea *) -1)
+				goto startOver;
+			if (_lastHitArea3 != 0)
+				break;
+			hitarea_stuff_helper();
+			delay(100);
+		}
+
+		ha = _lastHitArea;
+
+		if (ha == NULL) {
+		} else if (ha->id == 0x7FFB) {
+			inventoryUp(ha->window);
+		} else if (ha->id == 0x7FFC) {
+			inventoryDown(ha->window);
+		} else if ((getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) &&
+			(ha->id >= 101 && ha->id < 113)) {
+			_verbHitArea = ha->verb;
+			setVerb(ha);
+			_defaultVerb = 0;
+		} else {
+			if (getGameType() == GType_WW) {
+				if (_mouseCursor == 3)
+					_verbHitArea = 236;
+
+				if (ha->id == 98) {
+					animate(2, 0, 110, 0, 0, 0);
+					waitForSync(34);
+				} else if (ha->id == 108) {
+					animate(2, 0, 106, 0, 0, 0);
+					waitForSync(34);
+				} else if (ha->id == 109) {
+					animate(2, 0, 107, 0, 0, 0);
+					waitForSync(34);
+				} else if (ha->id == 115) {
+					animate(2, 0, 109, 0, 0, 0);
+					waitForSync(34);
+				} else if (ha->id == 116) {
+					animate(2, 0, 113, 0, 0, 0);
+					waitForSync(34);
+				} else if (ha->id == 117) {
+					animate(2, 0, 112, 0, 0, 0);
+					waitForSync(34);
+				} else if (ha->id == 118) {
+					animate(2, 0, 108, 0, 0, 0);
+					waitForSync(34);
+				} else if (ha->id == 119) {
+					animate(2, 0, 111, 0, 0, 0);
+					waitForSync(34);
+				}
+			}
+			if ((_verbHitArea != 0 || _hitAreaSubjectItem != ha->item_ptr && ha->flags & kBFBoxItem) &&
+					ha->item_ptr) {
+			if_1:;
+				_hitAreaSubjectItem = ha->item_ptr;
+				id = 0xFFFF;
+				if (ha->flags & kBFTextBox) {
+					if (getGameType() == GType_PP)
+						id = _lastHitArea->id;
+					else if (getGameType() == GType_FF && (ha->flags & kBFHyperBox))
+						id = ha->data;
+					else
+						id = ha->flags / 256;
+				}
+				if (getGameType() == GType_PP)
+					_variableArray[199] = id;
+				else if (getGameType() == GType_WW)
+					_variableArray[10] = id;
+				else
+					_variableArray[60] = id;
+
+				_nameLocked = 2;
+				displayName(ha);
+				_nameLocked = 1;
+
+				if (_verbHitArea != 0) {
+					break;
+				}
+
+				if (getGameType() == GType_ELVIRA2)
+					doMenuStrip(menuFor_e2(ha->item_ptr, id));
+				else if (getGameType() == GType_WW)
+					doMenuStrip(menuFor_ww(ha->item_ptr, id));
+			} else {
+				// else 1
+				if (ha->verb == 0) {
+					if (ha->item_ptr)
+						goto if_1;
+				} else {
+					if (getGameType() == GType_WW && _mouseCursor != 0 && _mouseCursor < 4) {
+						_hitAreaSubjectItem = ha->item_ptr;
+						break;
+					}
+
+					_verbHitArea = ha->verb & 0xBFFF;
+					if (ha->verb & 0x4000) {
+						_hitAreaSubjectItem = ha->item_ptr;
+						break;
+					}
+					if (_hitAreaSubjectItem != NULL)
+						break;
+
+					if (getGameType() == GType_WW) {
+						if (ha->id == 109) {
+							_mouseCursor = 2;
+							_needHitAreaRecalc++;
+						} else if (ha->id == 117) {
+							_mouseCursor = 3;
+							_needHitAreaRecalc++;
+						}
+					}
+				}
+			}
+		}
+	}
+
+out_of_here:
+	if (getGameType() == GType_ELVIRA2 || getGameType() == GType_WW)
+		clearMenuStrip();
+
+	_nameLocked = 0;
+	_needHitAreaRecalc++;
+}
+
+void AGOSEngine::hitarea_stuff_helper() {
+	time_t cur_time;
+
+	if (getGameType() == GType_SIMON2 || getGameType() == GType_FF ||
+		getGameType() == GType_PP) {
+		if (_variableArray[254] || _variableArray[249]) {
+			hitarea_stuff_helper_2();
+		}
+	} else if (getGameType() == GType_ELVIRA2 || getGameType() == GType_WW || 
+		getGameType() == GType_SIMON1) {
+		uint subr_id = (uint16)_variableArray[254];
+		if (subr_id != 0) {
+			Subroutine *sub = getSubroutineByID(subr_id);
+			if (sub != NULL) {
+				startSubroutineEx(sub);
+				permitInput();
+			}
+			_variableArray[254] = 0;
+			_runScriptReturn1 = false;
+		}
+	}
+
+	time(&cur_time);
+	if ((uint) cur_time != _lastTime) {
+		_lastTime = cur_time;
+		if (kickoffTimeEvents())
+			permitInput();
+	}
+}
+
+void AGOSEngine::hitarea_stuff_helper_2() {
+	uint subr_id;
+	Subroutine *sub;
+
+	subr_id = (uint16)_variableArray[249];
+	if (subr_id != 0) {
+		sub = getSubroutineByID(subr_id);
+		if (sub != NULL) {
+			_variableArray[249] = 0;
+			startSubroutineEx(sub);
+			permitInput();
+		}
+		_variableArray[249] = 0;
+	}
+
+	subr_id = (uint16)_variableArray[254];
+	if (subr_id != 0) {
+		sub = getSubroutineByID(subr_id);
+		if (sub != NULL) {
+			_variableArray[254] = 0;
+			startSubroutineEx(sub);
+			permitInput();
+		}
+		_variableArray[254] = 0;
+	}
+
+	_runScriptReturn1 = false;
+}
+
+void AGOSEngine::permitInput() {
+	if (!_mortalFlag) {
+		_mortalFlag = true;
+		showmessage_print_char(0);
+		_curWindow = 0;
+		if (_windowArray[0] != 0) {
+			_textWindow = _windowArray[0];
+			if (getGameType() == GType_FF || getGameType() == GType_PP)
+				showmessage_helper_3(_textWindow->textColumn, _textWindow->width);
+			else
+				showmessage_helper_3(_textWindow->textLength, _textWindow->textMaxLength);
+		}
+		_mortalFlag = false;
+	}
+}
+
+bool AGOSEngine::processSpecialKeys() {
+	switch (_keyPressed) {
+	case 17: // Up
+		if (getGameType() == GType_PP)
+			_verbHitArea = 302;
+		else if (getGameType() == GType_WW)
+			_verbHitArea = 239;
+		break;
+	case 18: // Down
+		if (getGameType() == GType_PP)
+			_verbHitArea = 304;
+		else if (getGameType() == GType_WW)
+			_verbHitArea = 241;
+		break;
+	case 19: // Right
+		if (getGameType() == GType_PP)
+			_verbHitArea = 303;
+		else if (getGameType() == GType_WW)
+			_verbHitArea = 240;
+		break;
+	case 20: // Left
+		if (getGameType() == GType_PP)
+			_verbHitArea = 301;
+		else if (getGameType() == GType_WW)
+			_verbHitArea = 242;
+		break;
+	case 27: // escape
+		_exitCutscene = true;
+		break;
+	case 59: // F1
+		if (getGameType() == GType_SIMON1) {
+			vcWriteVar(5, 40);
+		} else {
+			vcWriteVar(5, 50);
+		}
+		vcWriteVar(86, 0);
+		break;
+	case 60: // F2
+		if (getGameType() == GType_SIMON1) {
+			vcWriteVar(5, 60);
+		} else {
+			vcWriteVar(5, 75);
+		}
+		vcWriteVar(86, 1);
+		break;
+	case 61: // F3
+		if (getGameType() == GType_SIMON1) {
+			vcWriteVar(5, 100);
+		} else {
+			vcWriteVar(5, 125);
+		}
+		vcWriteVar(86, 2);
+		break;
+	case 63: // F5
+		if (getGameType() == GType_SIMON2 || getGameType() == GType_FF)
+			_exitCutscene = true;
+		break;
+	case 65: // F7
+		if (getGameType() == GType_FF && getBitFlag(76))
+			_variableArray[254] = 70;
+		break;
+	case 67: // F9
+		if (getGameType() == GType_FF)
+			setBitFlag(73, !getBitFlag(73));
+		break;
+	case 'p':
+		pause();
+		break;
+	case 't':
+		if (getGameType() == GType_FF || (getGameType() == GType_SIMON2 && (getFeatures() & GF_TALKIE)) ||
+			((getFeatures() & GF_TALKIE) && _language != Common::EN_ANY && _language != Common::DE_DEU)) {
+			if (_speech)
+				_subtitles ^= 1;
+		}
+		break;
+	case 'v':
+		if (getGameType() == GType_FF || (getGameType() == GType_SIMON2 && (getFeatures() & GF_TALKIE))) {
+			if (_subtitles)
+				_speech ^= 1;
+		}
+	case '+':
+		midi.set_volume(midi.get_volume() + 16);
+		break;
+	case '-':
+		midi.set_volume(midi.get_volume() - 16);
+		break;
+	case 'm':
+		midi.pause(_musicPaused ^= 1);
+		break;
+	case 's':
+		if (getGameId() == GID_SIMON1DOS)
+			midi._enable_sfx ^= 1;
+		else
+			_sound->effectsPause(_effectsPaused ^= 1);
+		break;
+	case 'b':
+		_sound->ambientPause(_ambientPaused ^= 1);
+		break;
+	case 'r':
+		if (_debugMode)
+			_startMainScript ^= 1;
+		break;
+	case 'o':
+		if (_debugMode)
+			_continousMainScript ^= 1;
+		break;
+	case 'a':
+		if (_debugMode)
+			_startVgaScript ^= 1;
+		break;
+	case 'g':
+		if (_debugMode)
+			_continousVgaScript ^= 1;
+		break;
+	case 'i':
+		if (_debugMode)
+			_drawImagesDebug ^= 1;
+		break;
+	case 'd':
+		if (_debugMode)
+			_dumpImages ^=1;
+		break;
+	}
+
+	bool result = (_keyPressed != 0);
+	_keyPressed = 0;
+	return result;
+}
+
+} // End of namespace AGOS
+
+


Property changes on: scummvm/trunk/engines/agos/input.cpp
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Added: scummvm/trunk/engines/agos/items.cpp
===================================================================
--- scummvm/trunk/engines/agos/items.cpp	                        (rev 0)
+++ scummvm/trunk/engines/agos/items.cpp	2006-10-20 02:10:51 UTC (rev 24394)
@@ -0,0 +1,418 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001  Ludvig Strigeus
+ * Copyright (C) 2001-2006 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "common/stdafx.h"
+
+#include "common/file.h"
+
+#include "agos/intern.h"
+#include "agos/agos.h"
+#include "agos/vga.h"
+
+namespace AGOS {
+
+Child *AGOSEngine::allocateChildBlock(Item *i, uint type, uint size) {
+	Child *child = (Child *)allocateItem(size);
+	child->next = i->children;
+	i->children = child;
+	child->type = type;
+	return child;
+}
+
+byte *AGOSEngine::allocateItem(uint size) {
+	byte *org = _itemHeapPtr;
+	size = (size + sizeof(void*) - 1) & ~(sizeof(void*) - 1);
+
+	_itemHeapPtr += size;
+	_itemHeapCurPos += size;
+
+	if (_itemHeapCurPos > _itemHeapSize)
+		error("allocateItem: Itemheap overflow");
+
+	return org;
+}
+
+void AGOSEngine::allocItemHeap() {
+	_itemHeapSize = _itemMemSize;
+	_itemHeapCurPos = 0;
+	_itemHeapPtr = (byte *)calloc(_itemMemSize, 1);
+	if (!_itemHeapPtr)
+		error("Out Of Memory - Items");
+}
+
+uint AGOSEngine::itemGetIconNumber(Item *item) {
+	if (getGameType() == GType_ELVIRA1) {
+		return getUserFlag(item, 7);
+	} else {
+		SubObject *child = (SubObject *)findChildOfType(item, 2);
+		uint offs;
+
+		if (child == NULL || !(child->objectFlags & kOFIcon))
+			return 0;
+
+		offs = getOffsetOfChild2Param(child, 0x10);
+		return child->objectFlagValue[offs];
+	}
+}
+
+void AGOSEngine::setItemState(Item *item, int value) {
+	item->state = value;
+}
+
+void AGOSEngine::createPlayer() {
+	SubPlayer *p;
+
+	_currentPlayer = _itemArrayPtr[1];
+	_currentPlayer->adjective = -1;
+	_currentPlayer->noun = 10000;
+
+	p = (SubPlayer *)allocateChildBlock(_currentPlayer, 3, sizeof(SubPlayer));
+	if (p == NULL)
+		error("createPlayer: player create failure");
+
+	p->size = 0;
+	p->weight = 0;
+	p->strength = 6000;
+	//p->flag = xxx;
+	p->level = 1;
+	p->score = 0;
+
+	setUserFlag(_currentPlayer, 0, 0);
+}
+
+Child *AGOSEngine::findChildOfType(Item *i, uint type) {
+	Child *child = i->children;
+	for (; child; child = child->next)
+		if (child->type == type)
+			return child;
+	return NULL;
+}
+
+int AGOSEngine::getUserFlag(Item *item, int a) {
+	SubUserFlag *subUserFlag;
+
+	subUserFlag = (SubUserFlag *) findChildOfType(item, 9);
+	if (subUserFlag == NULL)
+		return 0;
+
+	if (a < 0 || a > 7)
+		return 0;
+
+	return	subUserFlag->userFlags[a];
+}
+
+void AGOSEngine::setUserFlag(Item *item, int a, int b) {
+	SubUserFlag *subUserFlag;
+
+	subUserFlag = (SubUserFlag *) findChildOfType(item, 9);
+	if (subUserFlag == NULL) {
+		subUserFlag = (SubUserFlag *) allocateChildBlock(item, 9, sizeof(SubUserFlag));
+	}
+
+	if (a < 0 || a > 7)
+		return;
+
+	subUserFlag->userFlags[a] = b;
+}
+
+int AGOSEngine::getUserItem(Item *item, int n) {
+	SubUserFlag *subUserFlag;
+
+	subUserFlag = (SubUserFlag *) findChildOfType(item, 9);
+	if (subUserFlag == NULL)
+		return 0;
+
+	if (n < 0 || n > 0)
+		return 0;
+
+	return	subUserFlag->userItems[n];
+}
+
+void AGOSEngine::setUserItem(Item *item, int n, int m) {
+	SubUserFlag *subUserFlag;
+
+	subUserFlag = (SubUserFlag *) findChildOfType(item, 9);
+	if (subUserFlag == NULL) {
+		subUserFlag = (SubUserFlag *) allocateChildBlock(item, 9, sizeof(SubUserFlag));
+	}
+
+	if (n == 0)
+		subUserFlag->userItems[n] = m;
+}
+
+bool AGOSEngine::isRoom(Item *item) {
+	return findChildOfType(item, 1) != NULL;
+}
+
+bool AGOSEngine::isObject(Item *item) {
+	return findChildOfType(item, 2) != NULL;
+}
+
+bool AGOSEngine::isPlayer(Item *item) {
+	return findChildOfType(item, 3) != NULL;
+}
+
+uint AGOSEngine::getOffsetOfChild2Param(SubObject *child, uint prop) {
+	uint m = 1;
+	uint offset = 0;
+	while (m != prop) {
+		if (child->objectFlags & m)
+			offset++;
+		m *= 2;
+	}
+	return offset;
+}
+
+Item *AGOSEngine::me() {
+	if (_currentPlayer)
+		return _currentPlayer;
+	return _dummyItem1;
+}
+
+Item *AGOSEngine::actor() {
+	error("actor: is this code ever used?");
+	//if (_actorPlayer)
+	//	return _actorPlayer;
+	return _dummyItem1;
+}
+
+Item *AGOSEngine::getNextItemPtr() {
+	int a = getNextWord();
+	switch (a) {
+	case -1:
+		return _subjectItem;
+	case -3:
+		return _objectItem;
+	case -5:
+		return me();
+	case -7:
+		return actor();
+	case -9:
+		return derefItem(me()->parent);
+	default:
+		return derefItem(a);
+	}
+}
+
+Item *AGOSEngine::getNextItemPtrStrange() {
+	int a = getNextWord();
+	switch (a) {
+	case -1:
+		return _subjectItem;
+	case -3:
+		return _objectItem;
+	case -5:
+		return _dummyItem2;
+	case -7:
+		return NULL;
+	case -9:
+		return _dummyItem3;
+	default:
+		return derefItem(a);
+	}
+}
+
+uint AGOSEngine::getNextItemID() {
+	int a = getNextWord();
+	switch (a) {
+	case -1:
+		return itemPtrToID(_subjectItem);
+	case -3:
+		return itemPtrToID(_objectItem);
+	case -5:
+		return getItem1ID();
+	case -7:
+		return 0;
+	case -9:
+		return me()->parent;
+	default:
+		return a;
+	}
+}
+
+void AGOSEngine::setItemParent(Item *item, Item *parent) {
+	Item *old_parent = derefItem(item->parent);
+
+	if (item == parent)
+		error("setItemParent: Trying to set item as its own parent");
+
+	// unlink it if it has a parent
+	if (old_parent)
+		unlinkItem(item);
+	itemChildrenChanged(old_parent);
+	linkItem(item, parent);
+	itemChildrenChanged(parent);
+}
+
+void AGOSEngine::itemChildrenChanged(Item *item) {
+	int i;
+	WindowBlock *window;
+
+	if (_noParentNotify)
+		return;
+
+	mouseOff();
+
+	for (i = 0; i != 8; i++) {
+		window = _windowArray[i];
+		if (window && window->iconPtr && window->iconPtr->itemRef == item) {
+			if (_fcsData1[i]) {
+				_fcsData2[i] = true;
+			} else {
+				_fcsData2[i] = false;
+				drawIconArray(i, item, window->iconPtr->line, window->iconPtr->classMask);
+			}
+		}
+	}
+
+	mouseOn();
+}
+
+void AGOSEngine::unlinkItem(Item *item) {
+	Item *first, *parent, *next;
+
+	// can't unlink item without parent
+	if (item->parent == 0)
+		return;
+
+	// get parent and first child of parent
+	parent = derefItem(item->parent);
+	first = derefItem(parent->child);
+
+	// the node to remove is first in the parent's children?
+	if (first == item) {
+		parent->child = item->next;
+		item->parent = 0;
+		item->next = 0;
+		return;
+	}
+
+	for (;;) {
+		if (!first)
+			error("unlinkItem: parent empty");
+		if (first->next == 0)
+			error("unlinkItem: parent does not contain child");
+
+		next = derefItem(first->next);
+		if (next == item) {
+			first->next = next->next;
+			item->parent = 0;
+			item->next = 0;
+			return;
+		}
+		first = next;
+	}
+}
+
+void AGOSEngine::linkItem(Item *item, Item *parent) {
+	uint id;
+	// Don't allow that an item that is already linked is relinked
+	if (item->parent)
+		return;
+
+	id = itemPtrToID(parent);
+	item->parent = id;
+
+	if (parent != 0) {
+		item->next = parent->child;
+		parent->child = itemPtrToID(item);
+	} else {
+		item->next = 0;
+	}
+}
+
+bool AGOSEngine::has_item_childflag_0x10(Item *item) {
+	SubObject *child = (SubObject *)findChildOfType(item, 2);
+	return child && (child->objectFlags & kOFIcon) != 0;
+}
+
+int AGOSEngine::wordMatch(Item *item, int16 a, int16 n) {
+	if ((a == -1) && (n == item->noun))
+		return 1;
+	if ((a == item->adjective) && (n == item->noun))
+		return 1 ;
+
+	return 0;
+}
+
+Item *AGOSEngine::derefItem(uint item) {
+	if (item >= _itemArraySize) {
+		debug(1, "derefItem: invalid item %d", item);
+		return 0;
+	}
+	return _itemArrayPtr[item];
+}
+
+Item *AGOSEngine::findInByClass(Item *i, int16 m) {
+	i = derefItem(i->child);
+
+	while (i) {
+		if (i->classFlags & m) {
+			//_findNextPtr = derefItem(i->next);
+			return i;
+		}
+		if (m == 0) {
+			//_findNextPtr = derefItem(i->next);
+			return i;
+		}
+		i = derefItem(i->next);
+	}
+
+	return NULL;
+}
+
+Item *AGOSEngine::findMaster(int16 a, int16 n) {
+	uint j;
+
+	for (j = 1; j < _itemArraySize; j++) {
+		Item *item = derefItem(j);
+		if (wordMatch(item, a, n))
+			return item;
+	}
+
+	return NULL;
+}
+
+Item *AGOSEngine::nextMaster(Item *i, int16 a, int16 n) {
+	uint j;
+	uint first = itemPtrToID(i) + 1;
+
+	for (j = first; j < _itemArraySize; j++) {
+		Item *item = derefItem(j);
+		if (wordMatch(item, a, n))
+			return item;
+	}
+
+	return NULL;
+}
+
+uint AGOSEngine::itemPtrToID(Item *id) {
+	uint i;
+	for (i = 0; i != _itemArraySize; i++)
+		if (_itemArrayPtr[i] == id)
+			return i;
+	error("itemPtrToID: not found");
+	return 0;
+}
+
+} // End of namespace AGOS


Property changes on: scummvm/trunk/engines/agos/items.cpp
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Modified: scummvm/trunk/engines/agos/module.mk
===================================================================
--- scummvm/trunk/engines/agos/module.mk	2006-10-19 23:57:54 UTC (rev 24393)
+++ scummvm/trunk/engines/agos/module.mk	2006-10-20 02:10:51 UTC (rev 24394)
@@ -11,7 +11,10 @@
 	draw.o \
 	event.o \
 	game.o \
+	gfx.o \
 	icons.o \
+	input.o \
+	items.o \
 	menus.o \
 	midi.o \
 	midiparser_s1d.o \
@@ -33,7 +36,11 @@
 	subroutine.o \
 	verb.o \
 	vga.o \
-	window.o
+	vga_s1.o \
+	vga_s2.o \
+	vga_ff.o \
+	window.o \
+	zones.o
 
 # This module can be built as a plugin
 ifdef BUILD_PLUGINS

Modified: scummvm/trunk/engines/agos/script.cpp
===================================================================
--- scummvm/trunk/engines/agos/script.cpp	2006-10-19 23:57:54 UTC (rev 24393)
+++ scummvm/trunk/engines/agos/script.cpp	2006-10-20 02:10:51 UTC (rev 24394)
@@ -1333,6 +1333,87 @@
 
 // -----------------------------------------------------------------------
 
+byte AGOSEngine::getByte() {
+	return *_codePtr++;
+}
+
+int AGOSEngine::getNextWord() {
+	int16 a = (int16)READ_BE_UINT16(_codePtr);
+	_codePtr += 2;
+	return a;
+}
+
+uint AGOSEngine::getNextStringID() {
+	return (uint16)getNextWord();
+}
+
+uint AGOSEngine::getVarOrByte() {
+	if (getGameType() == GType_ELVIRA1) {
+		return getVarOrWord();
+	} else {
+		uint a = *_codePtr++;
+		if (a != 255)
+			return a;
+		return readVariable(*_codePtr++);
+	}
+}
+
+uint AGOSEngine::getVarOrWord() {
+	uint a = READ_BE_UINT16(_codePtr);
+	_codePtr += 2;
+	if (getGameType() == GType_PP) {
+		if (a >= 60000 && a < 62048) {
+			return readVariable(a - 60000);
+		}
+	} else {
+		if (a >= 30000 && a < 30512) {
+			return readVariable(a - 30000);
+		}
+	}
+	return a;
+}
+
+uint AGOSEngine::getVarWrapper() {
+	if (getGameType() == GType_ELVIRA1 || getGameType() == GType_PP)
+		return getVarOrWord();
+	else
+		return getVarOrByte();
+}
+
+uint AGOSEngine::getNextVarContents() {
+	return (uint16)readVariable(getVarWrapper());
+}
+
+uint AGOSEngine::readVariable(uint variable) {
+	if (variable >= _numVars)
+		error("readVariable: Variable %d out of range", variable);
+
+	if (getGameType() == GType_PP) {
+		return (uint16)_variableArray[variable];
+	} else if (getGameType() == GType_FF) {
+		if (getBitFlag(83))
+			return (uint16)_variableArray2[variable];
+		else
+			return (uint16)_variableArray[variable];
+	} else {
+			return _variableArray[variable];
+	}
+}
+
+void AGOSEngine::writeNextVarContents(uint16 contents) {
+	writeVariable(getVarWrapper(), contents);
+}
+
+void AGOSEngine::writeVariable(uint variable, uint16 contents) {
+	if (variable >= _numVars)
+		error("writeVariable: Variable %d out of range", variable);
+
+	if (getGameType() == GType_FF && getBitFlag(83))
+		_variableArray2[variable] = contents;
+	else
+		_variableArray[variable] = contents;
+}
+
 int AGOSEngine::runScript() {
 	int opcode;
 	bool flag;

Modified: scummvm/trunk/engines/agos/script_ff.cpp
===================================================================
--- scummvm/trunk/engines/agos/script_ff.cpp	2006-10-19 23:57:54 UTC (rev 24393)
+++ scummvm/trunk/engines/agos/script_ff.cpp	2006-10-20 02:10:51 UTC (rev 24394)
@@ -46,7 +46,6 @@
 	op[122] = &AGOSEngine::o3_oracleTextDown;
 	op[123] = &AGOSEngine::o3_oracleTextUp;
 	op[124] = &AGOSEngine::o3_ifTime;
-	op[127] = NULL;
 	op[131] = &AGOSEngine::o3_setTime;
 	op[132] = &AGOSEngine::o3_saveUserGame;
 	op[133] = &AGOSEngine::o3_loadUserGame;

Modified: scummvm/trunk/engines/agos/script_pp.cpp
===================================================================
--- scummvm/trunk/engines/agos/script_pp.cpp	2006-10-19 23:57:54 UTC (rev 24393)
+++ scummvm/trunk/engines/agos/script_pp.cpp	2006-10-20 02:10:51 UTC (rev 24394)
@@ -49,7 +49,6 @@
 	op[122] = &AGOSEngine::o3_oracleTextDown;
 	op[123] = &AGOSEngine::o3_oracleTextUp;
 	op[124] = &AGOSEngine::o3_ifTime;
-	op[127] = NULL;
 	op[131] = &AGOSEngine::o3_setTime;
 	op[132] = &AGOSEngine::o4_saveUserGame;
 	op[133] = &AGOSEngine::o4_loadUserGame;

Modified: scummvm/trunk/engines/agos/script_s1.cpp
===================================================================
--- scummvm/trunk/engines/agos/script_s1.cpp	2006-10-19 23:57:54 UTC (rev 24393)
+++ scummvm/trunk/engines/agos/script_s1.cpp	2006-10-20 02:10:51 UTC (rev 24394)
@@ -79,14 +79,19 @@
 
 void AGOSEngine::o1_animate() {
 	// 98: start vga
-	uint vga_res, vgaSpriteId, windowNum, x, y, palette;
-	vgaSpriteId = getVarOrWord();
-	vga_res = vgaSpriteId / 100;
-	windowNum = getVarOrByte();
-	x = getVarOrWord();
-	y = getVarOrWord();
-	palette = getVarOrWord();
-	loadSprite(windowNum, vga_res, vgaSpriteId, x, y, palette);
+	uint vgaSpriteId = getVarOrWord();
+	uint windowNum = getVarOrByte();
+	uint x = getVarOrWord();
+	uint y = getVarOrWord();
+	uint palette = getVarOrWord();
+
+	if (getGameType() == GType_SIMON1 && (getFeatures() & GF_TALKIE) && vgaSpriteId >= 400) {
+		_lastVgaWaitFor = 0;
+	}
+
+	_lockWord |= 0x40;
+	animate(windowNum, vgaSpriteId / 100, vgaSpriteId, x, y, palette);
+	_lockWord &= ~0x40;
 }
 
 void AGOSEngine::o1_stopAnimate() {

Modified: scummvm/trunk/engines/agos/script_s2.cpp
===================================================================
--- scummvm/trunk/engines/agos/script_s2.cpp	2006-10-19 23:57:54 UTC (rev 24393)
+++ scummvm/trunk/engines/agos/script_s2.cpp	2006-10-20 02:10:51 UTC (rev 24394)
@@ -87,13 +87,16 @@
 
 void AGOSEngine::o2_animate() {
 	// 98: start vga
-	uint vga_res = getVarOrWord();
+	uint zoneNum = getVarOrWord();
 	uint vgaSpriteId = getVarOrWord();
 	uint windowNum = getVarOrByte();
 	uint x = getVarOrWord();
 	uint y = getVarOrWord();
 	uint palette = getVarOrWord();
-	loadSprite(windowNum, vga_res, vgaSpriteId, x, y, palette);
+
+	_lockWord |= 0x40;
+	animate(windowNum, zoneNum, vgaSpriteId, x, y, palette);
+	_lockWord &= ~0x40;
 }
 
 void AGOSEngine::o2_stopAnimate() {

Modified: scummvm/trunk/engines/agos/string.cpp
===================================================================
--- scummvm/trunk/engines/agos/string.cpp	2006-10-19 23:57:54 UTC (rev 24393)
+++ scummvm/trunk/engines/agos/string.cpp	2006-10-20 02:10:51 UTC (rev 24394)
@@ -54,6 +54,22 @@
 	return _localStringtable[stringId - _stringIdLocalMin];
 }
 
+TextLocation *AGOSEngine::getTextLocation(uint a) {
+	switch (a) {
+	case 1:
+		return &_textLocation1;
+	case 2:
+		return &_textLocation2;
+	case 101:
+		return &_textLocation3;
+	case 102:
+		return &_textLocation4;
+	default:
+		error("getTextLocation: Invalid text location %d", a);
+	}
+	return NULL;
+}
+
 void AGOSEngine::allocateStringTable(int num) {
 	_stringTabPtr = (byte **)calloc(num, sizeof(byte *));
 	_stringTabPos = 0;
@@ -319,7 +335,7 @@
 
 	stopAnimateSimon2(2, num + 6);
 	renderString(num, 0, w, height, convertedString);
-	loadSprite(4, 2, num + 6, x, _interactY, 12);
+	animate(4, 2, num + 6, x, _interactY, 12);
 
 	_interactY += height;
 }
@@ -463,9 +479,9 @@
 	}
 
 	if (getGameType() == GType_SIMON1)
-		loadSprite(b, 2, vgaSpriteId + 199, x, y, 12);
+		animate(b, 2, vgaSpriteId + 199, x, y, 12);
 	else
-		loadSprite(b, 2, vgaSpriteId, x, y, 12);
+		animate(b, 2, vgaSpriteId, x, y, 12);
 }
 
 // String code for boxes in Waxworks
@@ -665,7 +681,7 @@
 	stopAnimateSimon1(105);
 	BoxSize = getBoxSize();
 	_variableArray[53] = BoxSize;
-	loadSprite(3, 1, 100, 0, 0, 0);
+	animate(3, 1, 100, 0, 0, 0);
 	changeWindow(5);
 
 	switch (BoxSize) {

Modified: scummvm/trunk/engines/agos/subroutine.cpp
===================================================================
--- scummvm/trunk/engines/agos/subroutine.cpp	2006-10-19 23:57:54 UTC (rev 24393)
+++ scummvm/trunk/engines/agos/subroutine.cpp	2006-10-20 02:10:51 UTC (rev 24394)
@@ -241,6 +241,26 @@
 	return org;
 }
 
+void AGOSEngine::allocTablesHeap() {
+	_tablesHeapSize = _tableMemSize;
+	_tablesHeapCurPos = 0;
+	_tablesHeapPtr = (byte *)calloc(_tableMemSize, 1);
+	if (!_tablesHeapPtr)
+		error("Out Of Memory - Tables");
+}
+
+void AGOSEngine::endCutscene() {
+	Subroutine *sub;
+
+	_sound->stopVoice();
+
+	sub = getSubroutineByID(170);
+	if (sub != NULL)
+		startSubroutineEx(sub);
+
+	_runScriptReturn1 = true;
+}
+
 File *AGOSEngine::openTablesFile(const char *filename) {
 	if (getFeatures() & GF_OLD_BUNDLE)
 		return openTablesFile_simon1(filename);

Modified: scummvm/trunk/engines/agos/verb.cpp
===================================================================
--- scummvm/trunk/engines/agos/verb.cpp	2006-10-19 23:57:54 UTC (rev 24393)
+++ scummvm/trunk/engines/agos/verb.cpp	2006-10-20 02:10:51 UTC (rev 24394)
@@ -606,14 +606,14 @@
 		if (!isBoxDead(j + 201)) {
 			uint index = getWindowNum(window);
 			drawIconArray(index, window->iconPtr->itemRef, 0, window->iconPtr->classMask);
-			loadSprite(4, 9, k + 34, 0, 0, 0);	
+			animate(4, 9, k + 34, 0, 0, 0);	
 		}
 	}
 	if ((_variableArray[31] - _variableArray[30]) == 76) {
 		k = ((_variableArray[31] / 52) % 3);
 		j = k * 6;
 		if (isBoxDead(j + 201)) {
-			loadSprite(4, 9, k + 31, 0, 0, 0);
+			animate(4, 9, k + 31, 0, 0, 0);
 			undefineBox(j + 201);
 			undefineBox(j + 202);
 			undefineBox(j + 203);
@@ -633,14 +633,14 @@
 		uint index = getWindowNum(window);
 		drawIconArray(index, window->iconPtr->itemRef, 0, window->iconPtr->classMask);
 		k = ((_variableArray[31] / 52) % 3);
-		loadSprite(4, 9, k + 25, 0, 0, 0);	
+		animate(4, 9, k + 25, 0, 0, 0);	
 		_variableArray[31] += 52;
 	}
 	if (((_variableArray[31] - _variableArray[30]) == 40) && (_variableArray[30] > 52)) {
 		k = (((_variableArray[31] / 52) + 1) % 3);
 		j = k * 6;
 		if (isBoxDead(j + 201)) {
-			loadSprite(4, 9, k + 28, 0, 0, 0);
+			animate(4, 9, k + 28, 0, 0, 0);
 			undefineBox(j + 201);
 			undefineBox(j + 202);
 			undefineBox(j + 203);
@@ -655,7 +655,7 @@
 	if (getGameType() == GType_FF) {
 		_marks = 0;
 		checkUp(window);
-		loadSprite(4, 9, 21, 0 ,0, 0);	
+		animate(4, 9, 21, 0 ,0, 0);	
 		while (1) {
 			if (_currentBoxNumber != 0x7FFB || !getBitFlag(89))
 				break;
@@ -682,7 +682,7 @@
 	if (getGameType() == GType_FF) {
 		_marks = 0;
 		checkDown(window);
-		loadSprite(4, 9, 23, 0, 0, 0);	
+		animate(4, 9, 23, 0, 0, 0);	
 		while (1) {
 			if (_currentBoxNumber != 0x7FFC || !getBitFlag(89))
 				break;

Modified: scummvm/trunk/engines/agos/vga.cpp
===================================================================
--- scummvm/trunk/engines/agos/vga.cpp	2006-10-19 23:57:54 UTC (rev 24393)
+++ scummvm/trunk/engines/agos/vga.cpp	2006-10-20 02:10:51 UTC (rev 24394)
@@ -159,57 +159,6 @@
 	op[63] = &AGOSEngine::vc63_fastFadeIn;
 }
 
-void AGOSEngine::setupSimon1VideoOpcodes(VgaOpcodeProc *op) {
-	setupCommonVideoOpcodes(op);
-
-	op[11] = &AGOSEngine::vc11_clearPathFinder;
-	op[17] = &AGOSEngine::vc17_setPathfinderItem;
-	op[22] = &AGOSEngine::vc22_setPaletteNew;
-	op[32] = &AGOSEngine::vc32_copyVar;
-	op[37] = &AGOSEngine::vc37_addToSpriteY;
-	op[48] = &AGOSEngine::vc48_setPathFinder;
-	op[59] = &AGOSEngine::vc59_skipIfSpeechEnded;
-	op[60] = &AGOSEngine::vc60_stopAnimation;
-	op[61] = &AGOSEngine::vc61_setMaskImage;
-	op[62] = &AGOSEngine::vc62_fastFadeOut;
-	op[63] = &AGOSEngine::vc63_fastFadeIn;
-}
-
-void AGOSEngine::setupSimon2VideoOpcodes(VgaOpcodeProc *op) {
-	setupSimon1VideoOpcodes(op);
-
-	op[56] = &AGOSEngine::vc56_delayLong;
-	op[58] = &AGOSEngine::vc58_changePriority;
-	op[59] = &AGOSEngine::vc59_stopAnimations;
-	op[64] = &AGOSEngine::vc64_skipIfSpeechEnded;
-	op[65] = &AGOSEngine::vc65_slowFadeIn;
-	op[66] = &AGOSEngine::vc66_skipIfNotEqual;
-	op[67] = &AGOSEngine::vc67_skipIfGE;
-	op[68] = &AGOSEngine::vc68_skipIfLE;
-	op[69] = &AGOSEngine::vc69_playTrack;
-	op[70] = &AGOSEngine::vc70_queueMusic;
-	op[71] = &AGOSEngine::vc71_checkMusicQueue;
-	op[72] = &AGOSEngine::vc72_play_track_2;
-	op[73] = &AGOSEngine::vc73_setMark;
-	op[74] = &AGOSEngine::vc74_clearMark;
-}
-
-void AGOSEngine::setupFeebleVideoOpcodes(VgaOpcodeProc *op) {
-	setupSimon2VideoOpcodes(op);
-
-	op[53] = &AGOSEngine::vc53_panSFX;
-	op[75] = &AGOSEngine::vc75_setScale;
-	op[76] = &AGOSEngine::vc76_setScaleXOffs;
-	op[77] = &AGOSEngine::vc77_setScaleYOffs;
-	op[78] = &AGOSEngine::vc78_computeXY;
-	op[79] = &AGOSEngine::vc79_computePosNum;
-	op[80] = &AGOSEngine::vc80_setOverlayImage;
-	op[81] = &AGOSEngine::vc81_setRandom;
-	op[82] = &AGOSEngine::vc82_getPathValue;
-	op[83] = &AGOSEngine::vc83_playSoundLoop;
-	op[84] = &AGOSEngine::vc84_stopSoundLoop;
-}
-
 void AGOSEngine::setupVgaOpcodes() {
 	memset(_vga_opcode_table, 0, sizeof(_vga_opcode_table));
 
@@ -295,6 +244,21 @@
 	return derefItem(item_a->parent) == item_b;
 }
 
+bool AGOSEngine::isSpriteLoaded(uint16 id, uint16 zoneNum) {
+	VgaSprite *vsp = _vgaSprites;
+	while (vsp->id) {
+		if (getGameType() == GType_SIMON2 || getGameType() == GType_FF || getGameType() == GType_PP) {
+			if (vsp->id == id && vsp->zoneNum == zoneNum)
+				return true;
+		} else {
+			if (vsp->id == id)
+				return true;
+		}
+		vsp++;
+	}
+	return false;
+}
+
 bool AGOSEngine::vc_maybe_skip_proc_1(uint16 a, int16 b) {
 	Item *item;
 
@@ -543,10 +507,6 @@
 
 void AGOSEngine::vc3_loadSprite() {
 	uint16 windowNum, zoneNum, palette, x, y, vgaSpriteId;
-	uint16 count, res;
-	VgaSprite *vsp;
-	VgaPointersEntry *vpe;
-	byte *p, *pp;
 	byte *old_file_1;
 
 	if (getGameType() == GType_PP && getBitFlag(100)) {
@@ -568,116 +528,8 @@
 	y = vcReadNextWord();			/* 6 */
 	palette = vcReadNextWord();		/* 8 */
 
-	if (isSpriteLoaded(vgaSpriteId, zoneNum))
-		return;
+	animate(windowNum, zoneNum, vgaSpriteId, x, y, palette, false);
 
-	vsp = _vgaSprites;
-	while (vsp->id)
-		vsp++;
-
-	if (getGameType() == GType_ELVIRA1 || getGameType() == GType_ELVIRA2 || getGameType() == GType_WW)
-		vsp->palette = 0;
-	else
-		vsp->palette = palette;
-	vsp->windowNum = windowNum;
-	vsp->priority = 0;
-	vsp->flags = 0;
-	vsp->image = 0;
-	vsp->x = x;
-	vsp->y = y;
-	vsp->id = vgaSpriteId;
-	vsp->zoneNum = res = zoneNum;
-
-	old_file_1 = _curVgaFile1;
-	for (;;) {
-		vpe = &_vgaBufferPointers[res];
-		_curVgaFile1 = vpe->vgaFile1;
-
-		if (vpe->vgaFile1 != NULL)
-			break;
-		if (_zoneNumber != res)
-			_noOverWrite = _zoneNumber;
-
-		loadZone(res);
-		_noOverWrite = 0xFFFF;
-	}
-
-	pp = _curVgaFile1;
-	if (getGameType() == GType_FF || getGameType() == GType_PP) {
-		p = pp + READ_LE_UINT16(pp + 2);
-		count = READ_LE_UINT16(&((VgaFileHeader2_Feeble *) p)->animationCount);
-		p = pp + READ_LE_UINT16(&((VgaFileHeader2_Feeble *) p)->animationTable);
-
-		while (count--) {
-			if (READ_LE_UINT16(&((AnimationHeader_Feeble *) p)->id) == vgaSpriteId)
-				break;
-			p += sizeof(AnimationHeader_Feeble);
-		}
-		assert(READ_LE_UINT16(&((AnimationHeader_Feeble *) p)->id) == vgaSpriteId);
-	} else if (getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) {
-		p = pp + READ_BE_UINT16(pp + 4);
-		count = READ_BE_UINT16(&((VgaFileHeader2_Common *) p)->animationCount);
-		p = pp + READ_BE_UINT16(&((VgaFileHeader2_Common *) p)->animationTable);
-
-		while (count--) {
-			if (READ_BE_UINT16(&((AnimationHeader_Simon *) p)->id) == vgaSpriteId)
-				break;
-			p += sizeof(AnimationHeader_Simon);
-		}
-		assert(READ_BE_UINT16(&((AnimationHeader_Simon *) p)->id) == vgaSpriteId);
-	} else {
-		p = pp + READ_BE_UINT16(pp + 10);
-		p += 20;
-
-		count = READ_BE_UINT16(&((VgaFileHeader2_Common *) p)->animationCount);
-		p = pp + READ_BE_UINT16(&((VgaFileHeader2_Common *) p)->animationTable);
-
-		while (count--) {
-			if (READ_BE_UINT16(&((AnimationHeader_WW *) p)->id) == vgaSpriteId)
-				break;
-			p += sizeof(AnimationHeader_WW);
-		}
-		assert(READ_BE_UINT16(&((AnimationHeader_WW *) p)->id) == vgaSpriteId);
-	}
-
-#ifdef DUMP_FILE_NR
-	{
-		static bool dumped = false;
-		if (res == DUMP_FILE_NR && !dumped) {
-			dumped = true;
-			dump_vga_file(_curVgaFile1);
-		}
-	}
-#endif
-
-#ifdef DUMP_BITMAPS_FILE_NR
-	{
-		static bool dumped = false;
-		if (res == DUMP_BITMAPS_FILE_NR && !dumped) {
-			dumped = true;
-			dump_vga_bitmaps(_curVgaFile2, _curVgaFile1, res);
-		}
-	}
-#endif
-
-	if (_startVgaScript) {
-		if (getGameType() == GType_FF || getGameType() == GType_PP) {
-			dump_vga_script(_curVgaFile1 + READ_LE_UINT16(&((AnimationHeader_Feeble*)p)->scriptOffs), res, vgaSpriteId);
-		} else if (getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) {
-			dump_vga_script(_curVgaFile1 + READ_BE_UINT16(&((AnimationHeader_Simon*)p)->scriptOffs), res, vgaSpriteId);
-		} else {
-			dump_vga_script(_curVgaFile1 + READ_BE_UINT16(&((AnimationHeader_WW*)p)->scriptOffs), res, vgaSpriteId);
-		}
-	}
-
-	if (getGameType() == GType_FF || getGameType() == GType_PP) {
-		addVgaEvent(_vgaBaseDelay, _curVgaFile1 + READ_LE_UINT16(&((AnimationHeader_Feeble *) p)->scriptOffs), vgaSpriteId, res);
-	} else if (getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) {
-		addVgaEvent(_vgaBaseDelay, _curVgaFile1 + READ_BE_UINT16(&((AnimationHeader_Simon *) p)->scriptOffs), vgaSpriteId, res);
-	} else {
-		addVgaEvent(_vgaBaseDelay, _curVgaFile1 + READ_BE_UINT16(&((AnimationHeader_WW *) p)->scriptOffs), vgaSpriteId, res);
-	}
-
 	_curVgaFile1 = old_file_1;
 }
 
@@ -723,55 +575,6 @@
 		vcSkipNextInstruction();
 }
 
-byte *vc10_depackColumn(VC10_state * vs) {
-	int8 a = vs->depack_cont;
-	const byte *src = vs->depack_src;
-	byte *dst = vs->depack_dest;
-	uint16 dh = vs->dh;
-	byte color;
-
-	if (a == -0x80)
-		a = *src++;
-
-	for (;;) {
-		if (a >= 0) {
-			color = *src++;
-			do {
-				*dst++ = color;
-				if (!--dh) {
-					if (--a < 0)
-						a = -0x80;
-					else
-						src--;
-					goto get_out;
-				}
-			} while (--a >= 0);
-		} else {
-			do {
-				*dst++ = *src++;
-				if (!--dh) {
-					if (++a == 0)
-						a = -0x80;
-					goto get_out;
-				}
-			} while (++a != 0);
-		}
-		a = *src++;
-	}
-
-get_out:;
-	vs->depack_src = src;
-	vs->depack_cont = a;
-	return vs->depack_dest + vs->y_skip;
-}
-
-void vc10_skip_cols(VC10_state *vs) {
-	while (vs->x_skip) {
-		vc10_depackColumn(vs);
-		vs->x_skip--;
-	}
-}
-
 byte *AGOSEngine::vc10_uncompressFlip(const byte *src, uint w, uint h) {
 	w *= 8;
 
@@ -862,94 +665,6 @@
 	return _videoBuf1;
 }
 
-void AGOSEngine::decodeColumn(byte *dst, const byte *src, int height) {
-	const uint pitch = _dxSurfacePitch;
-	int8 reps = (int8)0x80;
-	byte color;
-	byte *dstPtr = dst;
-	uint h = height, w = 8;
-
-	for (;;) {
-		reps = *src++;
-		if (reps >= 0) {
-			color = *src++;
-
-			do {
-				*dst = color;
-				dst += pitch;
-
-				/* reached bottom? */
-				if (--h == 0) {
-					/* reached right edge? */
-					if (--w == 0)
-						return;
-					dst = ++dstPtr;
-					h = height;
-				}
-			} while (--reps >= 0);
-		} else {
-
-			do {
-				*dst = *src++;
-				dst += pitch;
-
-				/* reached bottom? */
-				if (--h == 0) {
-					/* reached right edge? */
-					if (--w == 0)
-						return;
-					dst = ++dstPtr;
-					h = height;
-				}
-			} while (++reps != 0);
-		}
-	}
-}
-
-void AGOSEngine::decodeRow(byte *dst, const byte *src, int width) {
-	const uint pitch = _dxSurfacePitch;
-	int8 reps = (int8)0x80;
-	byte color;
-	byte *dstPtr = dst;
-	uint w = width, h = 8;
-
-	for (;;) {
-		reps = *src++;
-		if (reps >= 0) {
-			color = *src++;
-
-			do {
-				*dst++ = color;
-
-				/* reached right edge? */
-				if (--w == 0) {
-					/* reached bottom? */
-					if (--h == 0)
-						return;
-					dstPtr += pitch;
-					dst = dstPtr;
-					w = width;
-				}
-			} while (--reps >= 0);
-		} else {
-
-			do {
-				*dst++ = *src++;
-
-				/* reached right edge? */
-				if (--w == 0) {
-					/* reached bottom? */
-					if (--h == 0)
-						return;
-					dstPtr += pitch;
-					dst = dstPtr;
-					w = width;
-				}
-			} while (++reps != 0);
-		}
-	}
-}
-
 void AGOSEngine::vc10_draw() {
 	byte *p2;
 	uint width, height;
@@ -1062,589 +777,11 @@
 	}
 }
 
-bool AGOSEngine::drawImages_clip(VC10_state *state) {
-	const uint16 *vlut;
-	uint maxWidth, maxHeight;
-	int cur;
-
-	vlut = &_videoWindows[_windowNum * 4];
-
-	if (getGameType() != GType_FF && getGameType() != GType_PP) {
-		state->draw_width = state->width * 2;
-	} 
-
-	cur = state->x;
-	if (cur < 0) {
-		do {
-			if (!--state->draw_width)
-				return 0;
-			state->x_skip++;
-		} while (++cur);
-	}
-	state->x = cur;
-
-	maxWidth = (getGameType() == GType_FF || getGameType() == GType_PP) ? _screenWidth : (vlut[2] * 2);
-	cur += state->draw_width - maxWidth;
-	if (cur > 0) {
-		do {
-			if (!--state->draw_width)
-				return 0;
-		} while (--cur);
-	}
-
-	cur = state->y;
-	if (cur < 0) {
-		do {
-			if (!--state->draw_height)
-				return 0;
-			state->y_skip++;
-		} while (++cur);
-	}
-	state->y = cur;
-
-	maxHeight = (getGameType() == GType_FF || getGameType() == GType_PP) ? _screenHeight : vlut[3];
-	cur += state->draw_height - maxHeight;
-	if (cur > 0) {
-		do {
-			if (!--state->draw_height)
-				return 0;
-		} while (--cur);
-	}
-
-	assert(state->draw_width != 0 && state->draw_height != 0);
-
-	if (getGameType() != GType_FF && getGameType() != GType_PP) {
-		state->draw_width *= 4;
-	}
-
-	return 1;
-}
-
-void AGOSEngine::drawImages_Feeble(VC10_state *state) {
-	if (state->flags & kDFCompressed) {
-		if (state->flags & kDFScaled) {
-			state->surf_addr = getScaleBuf();
-			state->surf_pitch = _dxSurfacePitch;
-
-			uint w, h;
-			byte *src, *dst, *dstPtr;
-
-			state->dl = state->width;
-			state->dh = state->height;
-
-			dstPtr = state->surf_addr;
-			w = 0;
-			do {
-				src = vc10_depackColumn(state);
-				dst = dstPtr;
-
-				h = 0;
-				do {
-					*dst = *src;
-					dst += _screenWidth;
-					src++;
-				} while (++h != state->draw_height);
-				dstPtr++;
-			} while (++w != state->draw_width);
-
-			if (_vgaCurSpritePriority % 10 != 9) {
-				_scaleX = state->x;
-				_scaleY = state->y;
-				_scaleWidth = state->width;
-				_scaleHeight = state->height;
-			} else {
-				scaleClip(state->height, state->width, state->y, state->x, state->y + _scrollY);
-			}
-		} else if (state->flags & kDFOverlayed) {
-			state->surf_addr = getScaleBuf();
-			state->surf_pitch = _dxSurfacePitch;
-			state->surf_addr += (state->x + _scrollX) + (state->y + _scrollY) * state->surf_pitch;
-
-			uint w, h;
-			byte *src, *dst, *dstPtr;
-
-			state->dl = state->width;
-			state->dh = state->height;
-
-			dstPtr = state->surf_addr;
-			w = 0;
-			do {
-				byte color;
-
-				src = vc10_depackColumn(state);
-				dst = dstPtr;
-
-				h = 0;
-				do {
-					color = *src;
-					if (color != 0)
-						*dst = color;
-					dst += _screenWidth;
-					src++;
-				} while (++h != state->draw_height);
-				dstPtr++;
-			} while (++w != state->draw_width);
-
-			if (_vgaCurSpritePriority % 10 == 9) {
-				scaleClip(_scaleHeight, _scaleWidth, _scaleY, _scaleX, _scaleY + _scrollY);
-			}
-		} else {
-			if (drawImages_clip(state) == 0)
-				return;
-
-			state->surf_addr += state->x + state->y * state->surf_pitch;
-
-			uint w, h;
-			byte *src, *dst, *dstPtr;
-
-			state->dl = state->width;
-			state->dh = state->height;
-
-			vc10_skip_cols(state);
-
-
-			if (state->flags & kDFMasked) {
-				if (getGameType() == GType_FF && !getBitFlag(81)) {
-					if (state->x  > _feebleRect.right)
-						return;
-					if (state->y > _feebleRect.bottom)
-						return;
-					if (state->x + state->width < _feebleRect.left)
-						return;
-					if (state->y + state->height < _feebleRect.top)
-						return;
-				}
-
-				dstPtr = state->surf_addr;

@@ Diff output truncated at 100000 characters. @@

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list