[Scummvm-cvs-logs] SF.net SVN: scummvm: [31535] scummvm/trunk/engines/kyra

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Thu Apr 17 15:38:44 CEST 2008


Revision: 31535
          http://scummvm.svn.sourceforge.net/scummvm/?rev=31535&view=rev
Author:   lordhoto
Date:     2008-04-17 06:38:44 -0700 (Thu, 17 Apr 2008)

Log Message:
-----------
- fixed bug in script interpreter code (could've also affected HoF)
- some more Kyra3 code:
  -> start sequence should show up now partially
  -> fixed a scene animation related bug
  -> a few more opcodes

Modified Paths:
--------------
    scummvm/trunk/engines/kyra/animator_v3.cpp
    scummvm/trunk/engines/kyra/kyra_v3.cpp
    scummvm/trunk/engines/kyra/kyra_v3.h
    scummvm/trunk/engines/kyra/scene_v3.cpp
    scummvm/trunk/engines/kyra/screen_v3.cpp
    scummvm/trunk/engines/kyra/screen_v3.h
    scummvm/trunk/engines/kyra/script.cpp
    scummvm/trunk/engines/kyra/script.h
    scummvm/trunk/engines/kyra/script_v3.cpp

Modified: scummvm/trunk/engines/kyra/animator_v3.cpp
===================================================================
--- scummvm/trunk/engines/kyra/animator_v3.cpp	2008-04-17 11:59:20 UTC (rev 31534)
+++ scummvm/trunk/engines/kyra/animator_v3.cpp	2008-04-17 13:38:44 UTC (rev 31535)
@@ -338,7 +338,7 @@
 	if (!animObject->enabled)
 		return;
 
-	animObject->needRefresh = 1;
+	animObject->needRefresh = true;
 
 	if (_sceneAnims[anim].flags & 2)
 		animObject->flags |= 1;
@@ -370,4 +370,20 @@
 	}
 }
 
+void KyraEngine_v3::removeSceneAnimObject(int anim, int refresh) {
+	debugC(9, kDebugLevelAnimator, "KyraEngine_v3::removeSceneAnimObject(%d, %d)", anim, refresh);
+	AnimObj *obj = &_animObjects[anim+1];
+	restorePage3();
+	obj->shapeIndex3 = 0xFFFF;
+	obj->animNum = 0xFFFF;
+	obj->needRefresh = true;
+
+	if (refresh)
+		refreshAnimObjectsIfNeed();
+
+	obj->enabled = false;
+	_animList = deleteAnimListEntry(_animList, obj);
+	_sceneAnimMovie[anim]->close();
+}
+
 } // end of namespace Kyra

Modified: scummvm/trunk/engines/kyra/kyra_v3.cpp
===================================================================
--- scummvm/trunk/engines/kyra/kyra_v3.cpp	2008-04-17 11:59:20 UTC (rev 31534)
+++ scummvm/trunk/engines/kyra/kyra_v3.cpp	2008-04-17 13:38:44 UTC (rev 31535)
@@ -916,6 +916,19 @@
 	_screen->updateScreen();
 }
 
+void KyraEngine_v3::delay(uint32 millis, bool doUpdate, bool isMainLoop) {
+	debugC(9, kDebugLevelMain, "KyraEngine_v3::delay(%d, %d, %d)", millis, doUpdate, isMainLoop);
+	uint32 endTime = _system->getMillis() + millis;
+	while (endTime > _system->getMillis()) {
+		if (doUpdate) {
+			//XXX
+			update();
+		}
+
+		_system->delayMillis(10);
+	}
+}
+
 #pragma mark -
 
 void KyraEngine_v3::updateInput() {
@@ -1103,6 +1116,23 @@
 	return buffer ? size : 0 ;
 }
 
+uint8 *KyraEngine_v3::getTableEntry(uint8 *buffer, int id) {
+	debugC(9, kDebugLevelMain, "KyraEngine_v3::getTableEntry(%p, %d)", (const void*)buffer, id);
+	uint16 tableEntries = READ_LE_UINT16(buffer);
+	const uint16 *indexTable = (const uint16*)(buffer + 2);
+	const uint16 *offsetTable = indexTable + tableEntries;
+
+	int num = 0;
+	while (id != READ_LE_UINT16(indexTable)) {
+		++indexTable;
+		++num;
+	}
+
+	return buffer + READ_LE_UINT16(offsetTable + num);
+}
+
+#pragma mark -
+
 Movie *KyraEngine_v3::createWSAMovie() {
 	WSAMovieV2 *movie = new WSAMovieV2(this, _screen);
 	assert(movie);

Modified: scummvm/trunk/engines/kyra/kyra_v3.h
===================================================================
--- scummvm/trunk/engines/kyra/kyra_v3.h	2008-04-17 11:59:20 UTC (rev 31534)
+++ scummvm/trunk/engines/kyra/kyra_v3.h	2008-04-17 13:38:44 UTC (rev 31535)
@@ -76,6 +76,8 @@
 
 	void update();
 
+	void delay(uint32 millis, bool update = false, bool isMainLoop = false);
+
 	// - Input
 	void updateInput();
 	int checkInput(Button *buttonList, bool mainLoop = false);
@@ -185,6 +187,9 @@
 	bool _loadingState;
 	void updateCharacterAnim(int charId);
 
+	void updateSceneAnim(int anim, int newFrame);
+	void removeSceneAnimObject(int anim, int refresh);
+
 	// interface
 	uint8 *_interface;
 	uint8 *_interfaceCommandLine;
@@ -200,7 +205,7 @@
 	bool _restoreCommandLine;
 	bool _inventoryState;
 
-	// translation stuff
+	// localization
 	uint8 *_scoreFile;
 	uint8 *_cCodeFile;
 	uint8 *_scenesFile;
@@ -209,6 +214,8 @@
 	uint32 _actorFileSize;
 	uint8 *_sceneStrings;
 
+	uint8 *getTableEntry(uint8 *buffer, int id);
+
 	// items
 	uint8 *_itemBuffer1;
 	uint8 *_itemBuffer2;
@@ -262,8 +269,6 @@
 	void freeSceneShapes();
 	void freeSceneAnims();
 
-	void updateSceneAnim(int anim, int newFrame);
-
 	// voice
 	int _currentTalkFile;
 	void openTalkFile(int file);
@@ -396,10 +401,17 @@
 	void loadExtrasShapes();
 
 	// opcodes
+	int o3_setCharacterPos(ScriptState *script);
+	int o3_refreshCharacter(ScriptState *script);
+	int o3_showSceneFileMessage(ScriptState *script);
 	int o3_defineItem(ScriptState *script);
 	int o3_queryGameFlag(ScriptState *script);
 	int o3_resetGameFlag(ScriptState *script);
 	int o3_setGameFlag(ScriptState *script);
+	int o3_hideMouse(ScriptState *script);
+	int o3_setMousePos(ScriptState *script);
+	int o3_showMouse(ScriptState *script);
+	int o3_delay(ScriptState *script);
 	int o3_setSceneFilename(ScriptState *script);
 	int o3_getRand(ScriptState *script);
 	int o3_defineRoomEntrance(ScriptState *script);
@@ -412,6 +424,7 @@
 	int o3_querySpecialSceneScriptState(ScriptState *script);
 	int o3_setHiddenItemsEntry(ScriptState *script);
 	int o3_getHiddenItemsEntry(ScriptState *script);
+	int o3_removeSceneAnimObject(ScriptState *script);
 	int o3_dummy(ScriptState *script);
 
 	// misc

Modified: scummvm/trunk/engines/kyra/scene_v3.cpp
===================================================================
--- scummvm/trunk/engines/kyra/scene_v3.cpp	2008-04-17 11:59:20 UTC (rev 31534)
+++ scummvm/trunk/engines/kyra/scene_v3.cpp	2008-04-17 13:38:44 UTC (rev 31535)
@@ -366,9 +366,8 @@
 	// HACK
 	uint8 data[320*200];
 	_screen->copyRegionToBuffer(5, 0, 0, 320, 200, data);
-	_screen->fillRect(0, 0, 319, _maskPageMinY - 1, 0xFF, 5);
+	_screen->clearPage(5);
 	_screen->copyBlockToPage(5, 0, _maskPageMinY, 320, height, data);
-	_screen->fillRect(0, _maskPageMaxY + 1, 319, 199, 0xFF, 5);
 
 	musicUpdate(0);
 }
@@ -617,7 +616,13 @@
 
 	updateCharPal(0);
 
-	//XXX when loading from main menu
+	if (1/*!_menuDirectlyToLoad*/) {
+		_scriptInterpreter->startScript(&_sceneScriptState, 3);
+		_sceneScriptState.regs[5] = unk1;
+
+		while (_scriptInterpreter->validScript(&_sceneScriptState))
+			_scriptInterpreter->runScript(&_sceneScriptState);
+	}
 }
 
 void KyraEngine_v3::updateSpecialSceneScripts() {

Modified: scummvm/trunk/engines/kyra/screen_v3.cpp
===================================================================
--- scummvm/trunk/engines/kyra/screen_v3.cpp	2008-04-17 11:59:20 UTC (rev 31534)
+++ scummvm/trunk/engines/kyra/screen_v3.cpp	2008-04-17 13:38:44 UTC (rev 31535)
@@ -47,4 +47,29 @@
 	return &_screenDimTable[dim];
 }
 
+int Screen_v3::getLayer(int x, int y) {
+	debugC(9, kDebugLevelScreen, "Screen_v3::getLayer(%d, %d)", x, y);
+	if (x < 0)
+		x = 0;
+	else if (x >= 320)
+		x = 319;
+	if (y < 0)
+		y = 0;
+	else if (y >= 188)
+		y = 187;
+
+	if (y < _maskMinY || y > _maskMaxY)
+		return 15;
+
+	uint8 pixel = *(getCPagePtr(5) + y * 320 + x);
+	pixel &= 0x7F;
+	pixel >>= 3;
+
+	if (pixel < 1)
+		pixel = 1;
+	else if (pixel > 15)
+		pixel = 15;
+	return pixel;
+}
+
 } // end of namespace Kyra

Modified: scummvm/trunk/engines/kyra/screen_v3.h
===================================================================
--- scummvm/trunk/engines/kyra/screen_v3.h	2008-04-17 11:59:20 UTC (rev 31534)
+++ scummvm/trunk/engines/kyra/screen_v3.h	2008-04-17 13:38:44 UTC (rev 31535)
@@ -39,6 +39,8 @@
 
 	virtual void setScreenDim(int dim);
 	virtual const ScreenDim *getScreenDim(int dim);
+
+	int getLayer(int x, int y);
 private:
 	static const ScreenDim _screenDimTable[];
 	static const int _screenDimTableCount;

Modified: scummvm/trunk/engines/kyra/script.cpp
===================================================================
--- scummvm/trunk/engines/kyra/script.cpp	2008-04-17 11:59:20 UTC (rev 31534)
+++ scummvm/trunk/engines/kyra/script.cpp	2008-04-17 13:38:44 UTC (rev 31535)
@@ -183,7 +183,6 @@
 
 bool ScriptHelper::runScript(ScriptState *script) {
 	_parameter = 0;
-	_continue = true;
 
 	if (!script->ip)
 		return false;
@@ -212,10 +211,7 @@
 		(this->*(_commands[opcode].proc))(script);
 	}
 
-	if (!_continue)
-		script->ip = 0;
-
-	return _continue;
+	return (script->ip != 0);
 }
 
 #pragma mark -
@@ -319,7 +315,7 @@
 		break;
 
 	default:
-		_continue = false;
+		script->ip = 0;
 		break;
 	}
 }
@@ -348,7 +344,7 @@
 
 	case 1:
 		if (script->sp >= 60) {
-			_continue = false;
+			script->ip = 0;
 		} else {
 			script->bp = script->stack[script->sp++];
 			script->ip = script->dataPtr->data + script->stack[script->sp++];
@@ -356,7 +352,7 @@
 		break;
 
 	default:
-		_continue = false;
+		script->ip = 0;
 		break;
 	}
 }
@@ -422,7 +418,7 @@
 
 	default:
 		warning("Unknown negation func: %d", _parameter);
-		_continue = false;
+		script->ip = 0;
 		break;
 	}
 }
@@ -538,14 +534,14 @@
 	}
 
 	if (error)
-		_continue = false;
+		script->ip = 0;
 	else
 		script->stack[--script->sp] = ret;
 }
 
 void ScriptHelper::cmd_setRetAndJmp(ScriptState* script) {
 	if (script->sp >= 60) {
-		_continue = false;
+		script->ip = 0;
 	} else {
 		script->retValue = script->stack[script->sp++];
 		uint16 temp = script->stack[script->sp++];

Modified: scummvm/trunk/engines/kyra/script.h
===================================================================
--- scummvm/trunk/engines/kyra/script.h	2008-04-17 11:59:20 UTC (rev 31534)
+++ scummvm/trunk/engines/kyra/script.h	2008-04-17 13:38:44 UTC (rev 31535)
@@ -99,7 +99,6 @@
 protected:
 	KyraEngine *_vm;
 	int16 _parameter;
-	bool _continue;
 
 	typedef void (ScriptHelper::*CommandProc)(ScriptState*);
 	struct CommandEntry {

Modified: scummvm/trunk/engines/kyra/script_v3.cpp
===================================================================
--- scummvm/trunk/engines/kyra/script_v3.cpp	2008-04-17 11:59:20 UTC (rev 31534)
+++ scummvm/trunk/engines/kyra/script_v3.cpp	2008-04-17 13:38:44 UTC (rev 31535)
@@ -32,6 +32,49 @@
 
 namespace Kyra {
 
+int KyraEngine_v3::o3_setCharacterPos(ScriptState *script) {
+	debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v3::o3_setCharacterPos(%p) (%d, %d)", (const void *)script, stackPos(0), stackPos(1));
+	int x = stackPos(0);
+	int y = stackPos(1);
+
+	if (x != -1 && y != -1) {
+		x &= ~3;
+		y &= ~1;
+	}
+
+	_mainCharacter.x1 = _mainCharacter.x2 = x;
+	_mainCharacter.y1 = _mainCharacter.y2 = y;
+
+	return 0;
+}
+
+int KyraEngine_v3::o3_refreshCharacter(ScriptState *script) {
+	debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v3::o3_refreshCharacter(%p) (%d, %d, %d)", (const void *)script, stackPos(0), stackPos(1), stackPos(2));
+	const int frame = stackPos(0);
+	const int facing = stackPos(1);
+	const bool updateNeed = stackPos(2) != 0;
+
+	if (facing >= 0)
+		_mainCharacter.facing = facing;
+
+	if (frame >= 0 && frame != 87)
+		_mainCharacter.animFrame = _characterFrameTable[_mainCharacter.facing];
+	else
+		_mainCharacter.animFrame = 87;
+
+	updateCharacterAnim(0);
+
+	if (updateNeed)
+		refreshAnimObjectsIfNeed();
+	return 0;
+}
+
+int KyraEngine_v3::o3_showSceneFileMessage(ScriptState *script) {
+	debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v3::o3_showSceneFileMessage(%p) (%d)", (const void *)script, stackPos(0));
+	showMessage((const char*)getTableEntry(_scenesFile, stackPos(0)), 0xFF, 0xF0);
+	return 0;
+}
+
 int KyraEngine_v3::o3_defineItem(ScriptState *script) {
 	debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v3::o3_defineItem(%p) (%d, %d, %d, %d)", (const void *)script, stackPos(0), stackPos(1), stackPos(2), stackPos(3));
 	int freeItem = findFreeItem();
@@ -61,6 +104,36 @@
 	return 1;
 }
 
+int KyraEngine_v3::o3_hideMouse(ScriptState *script) {
+	debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v3::o3_hideMouse(%p) ()", (const void *)script);
+	_screen->hideMouse();
+	return 0;
+}
+
+int KyraEngine_v3::o3_setMousePos(ScriptState *script) {
+	debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v3::o3_setMousePos(%p) (%d, %d)", (const void *)script, stackPos(0), stackPos(1));
+	setMousePos(stackPos(0), stackPos(1));
+	return 0;
+}
+
+int KyraEngine_v3::o3_showMouse(ScriptState *script) {
+	debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v3::o3_showMouse(%p) ()", (const void *)script);
+	_screen->showMouse();
+	return 0;
+}
+
+int KyraEngine_v3::o3_delay(ScriptState *script) {
+	debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v3::o3_delay(%p) (%d, %d)", (const void *)script, stackPos(0), stackPos(1));
+	const uint32 delayTime = stackPos(0) * _tickLength;
+	const int delayFunc = stackPos(1);
+
+	if (delayFunc)
+		warning("STUB o3_delay func 1");
+
+	delay(delayTime, true);
+	return 0;
+}
+
 int KyraEngine_v3::o3_setSceneFilename(ScriptState *script) {
 	debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v3::o3_setSceneFilename(%p) (%d, '%s')", (const void *)script, stackPos(0), stackPosString(1));
 	strcpy(_sceneList[stackPos(0)].filename1, stackPosString(1));
@@ -143,7 +216,7 @@
 			if (x2 == -1)
 				x2 = _sceneAnimMovie[animId]->xAdd();
 			if (y2 == -1)
-				y2 = _sceneAnimMovie[animId]->xAdd();
+				y2 = _sceneAnimMovie[animId]->yAdd();
 			if (w == -1)
 				w = _sceneAnimMovie[animId]->width();
 			if (h == -1)
@@ -227,6 +300,12 @@
 	return (int16)_hiddenItems[stackPos(0)];
 }
 
+int KyraEngine_v3::o3_removeSceneAnimObject(ScriptState *script) {
+	debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v3::o3_removeSceneAnimObject(%p) (%d, %d)", (const void *)script, stackPos(0), stackPos(1));
+	removeSceneAnimObject(stackPos(0), stackPos(1));
+	return 0;
+}
+
 int KyraEngine_v3::o3_dummy(ScriptState *script) {
 	debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v3::o3_dummy(%p) ()", (const void *)script);
 	return 0;
@@ -239,9 +318,9 @@
 	static const OpcodeV3 opcodeTable[] = {
 		// 0x00
 		OpcodeUnImpl(),
+		Opcode(o3_setCharacterPos),
 		OpcodeUnImpl(),
-		OpcodeUnImpl(),
-		OpcodeUnImpl(),
+		Opcode(o3_refreshCharacter),
 		// 0x04
 		OpcodeUnImpl(),
 		OpcodeUnImpl(),
@@ -259,7 +338,7 @@
 		OpcodeUnImpl(),
 		// 0x10
 		OpcodeUnImpl(),
-		OpcodeUnImpl(),
+		Opcode(o3_showSceneFileMessage),
 		Opcode(o3_dummy),
 		Opcode(o3_dummy),
 		// 0x14
@@ -294,19 +373,19 @@
 		OpcodeUnImpl(),
 		// 0x2c
 		OpcodeUnImpl(),
+		Opcode(o3_hideMouse),
 		OpcodeUnImpl(),
-		OpcodeUnImpl(),
-		OpcodeUnImpl(),
+		Opcode(o3_setMousePos),
 		// 0x30
+		Opcode(o3_showMouse),
 		OpcodeUnImpl(),
 		OpcodeUnImpl(),
-		OpcodeUnImpl(),
 		Opcode(o3_dummy),
 		// 0x34
 		OpcodeUnImpl(),
 		OpcodeUnImpl(),
 		Opcode(o3_dummy),
-		OpcodeUnImpl(),
+		Opcode(o3_delay),
 		// 0x38
 		OpcodeUnImpl(),
 		OpcodeUnImpl(),
@@ -431,7 +510,7 @@
 		OpcodeUnImpl(),
 		OpcodeUnImpl(),
 		OpcodeUnImpl(),
-		OpcodeUnImpl(),
+		Opcode(o3_removeSceneAnimObject),
 		// 0x9c
 		OpcodeUnImpl(),
 		OpcodeUnImpl(),


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