2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
2007-05-30 21:56:52 +00:00
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
2006-02-11 12:44:16 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2004-05-01 16:15:55 +00:00
|
|
|
// Scripting module thread management component
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/saga.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/gfx.h"
|
|
|
|
#include "saga/actor.h"
|
2004-08-10 18:31:33 +00:00
|
|
|
#include "saga/console.h"
|
2005-01-06 14:02:53 +00:00
|
|
|
#include "saga/interface.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-12 21:39:11 +00:00
|
|
|
#include "saga/script.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-12-15 00:24:12 +00:00
|
|
|
#include "saga/stream.h"
|
2004-12-21 06:49:07 +00:00
|
|
|
#include "saga/scene.h"
|
2006-05-13 10:30:38 +00:00
|
|
|
#include "saga/sagaresnames.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
namespace Saga {
|
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
ScriptThread *Script::createThread(uint16 scriptModuleNumber, uint16 scriptEntryPointNumber) {
|
2005-01-15 20:12:49 +00:00
|
|
|
ScriptThread *newThread;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
loadModule(scriptModuleNumber);
|
|
|
|
if (_modules[scriptModuleNumber].entryPointsCount <= scriptEntryPointNumber) {
|
|
|
|
error("Script::createThread wrong scriptEntryPointNumber");
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-01-15 20:12:49 +00:00
|
|
|
newThread = _threadList.pushFront().operator->();
|
2005-01-21 21:55:54 +00:00
|
|
|
newThread->_flags = kTFlagNone;
|
|
|
|
newThread->_stackSize = DEFAULT_THREAD_STACK_SIZE;
|
|
|
|
newThread->_stackBuf = (uint16 *)malloc(newThread->_stackSize * sizeof(*newThread->_stackBuf));
|
2005-07-29 17:58:00 +00:00
|
|
|
newThread->_stackTopIndex = newThread->_stackSize - 2;
|
2005-01-21 21:55:54 +00:00
|
|
|
newThread->_instructionOffset = _modules[scriptModuleNumber].entryPoints[scriptEntryPointNumber].offset;
|
|
|
|
newThread->_commonBase = _commonBuffer;
|
|
|
|
newThread->_staticBase = _commonBuffer + _modules[scriptModuleNumber].staticOffset;
|
|
|
|
newThread->_moduleBase = _modules[scriptModuleNumber].moduleBase;
|
|
|
|
newThread->_moduleBaseSize = _modules[scriptModuleNumber].moduleBaseSize;
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
newThread->_strings = &_modules[scriptModuleNumber].strings;
|
2005-08-09 16:01:04 +00:00
|
|
|
|
|
|
|
if (_vm->getGameType() == GType_IHNM)
|
|
|
|
newThread->_voiceLUT = &_globalVoiceLUT;
|
|
|
|
else
|
|
|
|
newThread->_voiceLUT = &_modules[scriptModuleNumber].voiceLUT;
|
2004-10-22 07:18:01 +00:00
|
|
|
|
2005-01-15 20:12:49 +00:00
|
|
|
return newThread;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-12-24 10:22:01 +00:00
|
|
|
void Script::wakeUpActorThread(int waitType, void *threadObj) {
|
2005-01-15 20:12:49 +00:00
|
|
|
ScriptThread *thread;
|
2004-12-24 10:22:01 +00:00
|
|
|
ScriptThreadList::iterator threadIterator;
|
|
|
|
|
|
|
|
for (threadIterator = _threadList.begin(); threadIterator != _threadList.end(); ++threadIterator) {
|
|
|
|
thread = threadIterator.operator->();
|
2005-01-21 21:55:54 +00:00
|
|
|
if ((thread->_flags & kTFlagWaiting) && (thread->_waitType == waitType) && (thread->_threadObj == threadObj)) {
|
|
|
|
thread->_flags &= ~kTFlagWaiting;
|
2004-12-24 10:22:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-21 06:49:07 +00:00
|
|
|
void Script::wakeUpThreads(int waitType) {
|
2005-01-15 20:12:49 +00:00
|
|
|
ScriptThread *thread;
|
2004-12-21 06:49:07 +00:00
|
|
|
ScriptThreadList::iterator threadIterator;
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2004-12-21 06:49:07 +00:00
|
|
|
for (threadIterator = _threadList.begin(); threadIterator != _threadList.end(); ++threadIterator) {
|
|
|
|
thread = threadIterator.operator->();
|
2005-01-21 21:55:54 +00:00
|
|
|
if ((thread->_flags & kTFlagWaiting) && (thread->_waitType == waitType)) {
|
|
|
|
thread->_flags &= ~kTFlagWaiting;
|
2004-12-21 06:49:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-12-21 06:49:07 +00:00
|
|
|
void Script::wakeUpThreadsDelayed(int waitType, int sleepTime) {
|
2005-01-15 20:12:49 +00:00
|
|
|
ScriptThread *thread;
|
2004-12-21 06:49:07 +00:00
|
|
|
ScriptThreadList::iterator threadIterator;
|
|
|
|
|
|
|
|
for (threadIterator = _threadList.begin(); threadIterator != _threadList.end(); ++threadIterator) {
|
|
|
|
thread = threadIterator.operator->();
|
2005-01-21 21:55:54 +00:00
|
|
|
if ((thread->_flags & kTFlagWaiting) && (thread->_waitType == waitType)) {
|
|
|
|
thread->_waitType = kWaitTypeDelay;
|
|
|
|
thread->_sleepTime = sleepTime;
|
2004-12-21 06:49:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-19 14:06:20 +00:00
|
|
|
void Script::executeThreads(uint msec) {
|
2005-01-15 20:12:49 +00:00
|
|
|
ScriptThread *thread;
|
2004-12-21 06:49:07 +00:00
|
|
|
ScriptThreadList::iterator threadIterator;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-06-19 14:06:20 +00:00
|
|
|
if (_vm->_interface->_statusTextInput) {
|
|
|
|
return;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-12-21 06:49:07 +00:00
|
|
|
threadIterator = _threadList.begin();
|
2004-10-27 02:27:54 +00:00
|
|
|
|
2004-12-21 06:49:07 +00:00
|
|
|
while (threadIterator != _threadList.end()) {
|
|
|
|
thread = threadIterator.operator->();
|
2004-10-27 02:27:54 +00:00
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
if (thread->_flags & (kTFlagFinished | kTFlagAborted)) {
|
|
|
|
if (thread->_flags & kTFlagFinished)
|
2005-01-15 20:12:49 +00:00
|
|
|
setPointerVerb();
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-07-30 14:41:25 +00:00
|
|
|
if (_vm->getGameType() == GType_IHNM) {
|
|
|
|
thread->_flags &= ~kTFlagFinished;
|
|
|
|
thread->_flags |= kTFlagAborted;
|
2005-07-31 16:38:15 +00:00
|
|
|
++threadIterator;
|
2005-07-30 14:41:25 +00:00
|
|
|
} else {
|
|
|
|
threadIterator = _threadList.erase(threadIterator);
|
|
|
|
}
|
2004-10-27 02:27:54 +00:00
|
|
|
continue;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
2004-10-27 02:27:54 +00:00
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
if (thread->_flags & kTFlagWaiting) {
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-07-30 14:41:25 +00:00
|
|
|
switch (thread->_waitType) {
|
|
|
|
case kWaitTypeDelay:
|
2005-01-21 21:55:54 +00:00
|
|
|
if (thread->_sleepTime < msec) {
|
|
|
|
thread->_sleepTime = 0;
|
2004-12-24 10:22:01 +00:00
|
|
|
} else {
|
2005-01-21 21:55:54 +00:00
|
|
|
thread->_sleepTime -= msec;
|
2004-12-24 10:22:01 +00:00
|
|
|
}
|
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
if (thread->_sleepTime == 0)
|
2005-07-29 17:58:00 +00:00
|
|
|
thread->_flags &= ~kTFlagWaiting;
|
2005-07-30 14:41:25 +00:00
|
|
|
break;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-07-30 14:41:25 +00:00
|
|
|
case kWaitTypeWalk:
|
|
|
|
{
|
2004-12-24 10:22:01 +00:00
|
|
|
ActorData *actor;
|
2005-01-21 21:55:54 +00:00
|
|
|
actor = (ActorData *)thread->_threadObj;
|
2005-08-10 14:53:17 +00:00
|
|
|
if (actor->_currentAction == kActionWait) {
|
2005-07-29 17:58:00 +00:00
|
|
|
thread->_flags &= ~kTFlagWaiting;
|
2004-12-24 10:22:01 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-30 14:41:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kWaitTypeWaitFrames: // IHNM
|
|
|
|
if (thread->_frameWait < _vm->_frameCount)
|
|
|
|
thread->_flags &= ~kTFlagWaiting;
|
|
|
|
break;
|
2004-10-27 02:27:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-29 17:54:53 +00:00
|
|
|
if (!(thread->_flags & kTFlagWaiting)) {
|
|
|
|
if (runThread(thread, STHREAD_TIMESLICE)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-10-27 02:27:54 +00:00
|
|
|
|
2004-12-21 06:49:07 +00:00
|
|
|
++threadIterator;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-03-29 17:54:53 +00:00
|
|
|
void Script::abortAllThreads(void) {
|
|
|
|
ScriptThread *thread;
|
|
|
|
ScriptThreadList::iterator threadIterator;
|
|
|
|
|
|
|
|
threadIterator = _threadList.begin();
|
|
|
|
|
|
|
|
while (threadIterator != _threadList.end()) {
|
|
|
|
thread = threadIterator.operator->();
|
|
|
|
thread->_flags |= kTFlagAborted;
|
|
|
|
++threadIterator;
|
|
|
|
}
|
|
|
|
executeThreads(0);
|
|
|
|
}
|
|
|
|
|
2005-01-15 20:12:49 +00:00
|
|
|
void Script::completeThread(void) {
|
2005-07-30 14:41:25 +00:00
|
|
|
int limit = (_vm->getGameType() == GType_IHNM) ? 100 : 40;
|
|
|
|
|
2006-03-28 09:42:54 +00:00
|
|
|
for (int i = 0; i < limit && !_threadList.empty(); i++)
|
2004-12-21 06:49:07 +00:00
|
|
|
executeThreads(0);
|
2004-08-12 01:11:11 +00:00
|
|
|
}
|
|
|
|
|
2005-03-29 17:54:53 +00:00
|
|
|
bool Script::runThread(ScriptThread *thread, uint instructionLimit) {
|
2005-01-22 14:43:49 +00:00
|
|
|
const char*operandName;
|
2005-01-21 21:55:54 +00:00
|
|
|
uint instructionCount;
|
2005-01-21 23:25:54 +00:00
|
|
|
uint16 savedInstructionOffset;
|
|
|
|
|
|
|
|
byte *addr;
|
2005-10-11 17:20:30 +00:00
|
|
|
byte mode;
|
2005-05-12 15:11:32 +00:00
|
|
|
uint16 jmpOffset1;
|
2005-01-21 23:25:54 +00:00
|
|
|
int16 iparam1;
|
|
|
|
int16 iparam2;
|
2005-05-12 15:11:32 +00:00
|
|
|
int16 iparam3;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-06-19 14:06:20 +00:00
|
|
|
bool disContinue;
|
2005-01-21 23:25:54 +00:00
|
|
|
byte argumentsCount;
|
|
|
|
uint16 functionNumber;
|
2005-06-13 13:40:28 +00:00
|
|
|
uint16 checkStackTopIndex;
|
2005-01-21 23:25:54 +00:00
|
|
|
ScriptFunctionType scriptFunction;
|
|
|
|
|
2004-12-21 06:49:07 +00:00
|
|
|
int operandChar;
|
2004-04-12 21:40:49 +00:00
|
|
|
int i;
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
MemoryReadStream scriptS(thread->_moduleBase, thread->_moduleBaseSize);
|
2004-09-19 14:49:00 +00:00
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
scriptS.seek(thread->_instructionOffset);
|
2004-10-09 07:39:46 +00:00
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
for (instructionCount = 0; instructionCount < instructionLimit; instructionCount++) {
|
|
|
|
if (thread->_flags & (kTFlagAsleep))
|
2004-12-21 06:49:07 +00:00
|
|
|
break;
|
|
|
|
|
2005-01-21 23:25:54 +00:00
|
|
|
savedInstructionOffset = thread->_instructionOffset;
|
2004-12-21 06:49:07 +00:00
|
|
|
operandChar = scriptS.readByte();
|
2005-01-21 23:25:54 +00:00
|
|
|
|
2005-04-24 15:17:38 +00:00
|
|
|
|
|
|
|
#define CASEOP(opName) case opName: \
|
|
|
|
if (operandChar == opName) { \
|
|
|
|
operandName = #opName; \
|
2005-08-10 19:12:10 +00:00
|
|
|
debug(2, operandName); \
|
2005-04-24 15:17:38 +00:00
|
|
|
_vm->_console->DebugPrintf("%s\n", operandName); \
|
2005-01-21 23:25:54 +00:00
|
|
|
}
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2006-03-08 11:37:25 +00:00
|
|
|
debug(8, "Executing thread offset: %u (%x) stack: %d", thread->_instructionOffset, operandChar, thread->pushedSize());
|
2005-01-22 14:43:49 +00:00
|
|
|
operandName="";
|
2004-12-21 06:49:07 +00:00
|
|
|
switch (operandChar) {
|
2005-01-21 23:25:54 +00:00
|
|
|
CASEOP(opNextBlock)
|
2004-09-21 06:35:00 +00:00
|
|
|
// Some sort of "jump to the start of the next memory
|
|
|
|
// page" instruction, I think.
|
2005-08-10 19:12:10 +00:00
|
|
|
thread->_instructionOffset = (((thread->_instructionOffset) >> 10) + 1) << 10;
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
|
2004-05-01 16:15:55 +00:00
|
|
|
// STACK INSTRUCTIONS
|
2005-01-21 23:25:54 +00:00
|
|
|
CASEOP(opDup)
|
|
|
|
thread->push(thread->stackTop());
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-21 23:25:54 +00:00
|
|
|
CASEOP(opDrop)
|
2004-09-23 06:46:44 +00:00
|
|
|
thread->pop();
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-21 23:25:54 +00:00
|
|
|
CASEOP(opZero)
|
2004-09-23 06:46:44 +00:00
|
|
|
thread->push(0);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-21 23:25:54 +00:00
|
|
|
CASEOP(opOne)
|
2004-09-23 06:46:44 +00:00
|
|
|
thread->push(1);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-21 23:25:54 +00:00
|
|
|
CASEOP(opConstint)
|
|
|
|
CASEOP(opStrlit)
|
2005-01-22 14:43:49 +00:00
|
|
|
iparam1 = scriptS.readSint16LE();
|
|
|
|
thread->push(iparam1);
|
2005-04-24 15:17:38 +00:00
|
|
|
debug(8, "0x%X", iparam1);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
|
2005-07-29 17:58:00 +00:00
|
|
|
// DATA INSTRUCTIONS
|
2005-01-21 23:25:54 +00:00
|
|
|
CASEOP(opGetFlag)
|
|
|
|
addr = thread->baseAddress(scriptS.readByte());
|
2005-05-12 15:11:32 +00:00
|
|
|
iparam1 = scriptS.readSint16LE();
|
|
|
|
addr += (iparam1 >> 3);
|
|
|
|
iparam1 = (1 << (iparam1 & 7));
|
|
|
|
thread->push((*addr) & iparam1 ? 1 : 0);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-21 23:25:54 +00:00
|
|
|
CASEOP(opGetInt)
|
2005-10-11 17:20:30 +00:00
|
|
|
mode = scriptS.readByte();
|
|
|
|
addr = thread->baseAddress(mode);
|
2005-01-22 14:43:49 +00:00
|
|
|
iparam1 = scriptS.readSint16LE();
|
|
|
|
addr += iparam1;
|
2005-10-11 17:20:30 +00:00
|
|
|
thread->push(readUint16(addr, mode));
|
|
|
|
debug(8, "0x%X", readUint16(addr, mode));
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-21 23:25:54 +00:00
|
|
|
CASEOP(opPutFlag)
|
|
|
|
addr = thread->baseAddress(scriptS.readByte());
|
2005-05-12 15:11:32 +00:00
|
|
|
iparam1 = scriptS.readSint16LE();
|
|
|
|
addr += (iparam1 >> 3);
|
|
|
|
iparam1 = (1 << (iparam1 & 7));
|
2005-01-21 23:25:54 +00:00
|
|
|
if (thread->stackTop()) {
|
2005-05-12 15:11:32 +00:00
|
|
|
*addr |= iparam1;
|
2004-04-12 21:40:49 +00:00
|
|
|
} else {
|
2005-05-12 15:11:32 +00:00
|
|
|
*addr &= ~iparam1;
|
2005-01-21 23:25:54 +00:00
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-21 23:25:54 +00:00
|
|
|
CASEOP(opPutInt)
|
2005-10-11 17:20:30 +00:00
|
|
|
mode = scriptS.readByte();
|
|
|
|
addr = thread->baseAddress(mode);
|
2005-01-22 14:43:49 +00:00
|
|
|
iparam1 = scriptS.readSint16LE();
|
|
|
|
addr += iparam1;
|
2005-10-11 17:20:30 +00:00
|
|
|
writeUint16(addr, thread->stackTop(), mode);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-21 23:25:54 +00:00
|
|
|
CASEOP(opPutFlagV)
|
|
|
|
addr = thread->baseAddress(scriptS.readByte());
|
2005-05-12 15:11:32 +00:00
|
|
|
iparam1 = scriptS.readSint16LE();
|
|
|
|
addr += (iparam1 >> 3);
|
|
|
|
iparam1 = (1 << (iparam1 & 7));
|
2005-01-21 23:25:54 +00:00
|
|
|
if (thread->pop()) {
|
2005-05-12 15:11:32 +00:00
|
|
|
*addr |= iparam1;
|
2004-04-12 21:40:49 +00:00
|
|
|
} else {
|
2005-05-12 15:11:32 +00:00
|
|
|
*addr &= ~iparam1;
|
2005-01-21 23:25:54 +00:00
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-21 23:25:54 +00:00
|
|
|
CASEOP(opPutIntV)
|
2005-10-11 17:20:30 +00:00
|
|
|
mode = scriptS.readByte();
|
|
|
|
addr = thread->baseAddress(mode);
|
2005-01-22 14:43:49 +00:00
|
|
|
iparam1 = scriptS.readSint16LE();
|
|
|
|
addr += iparam1;
|
2005-10-11 17:20:30 +00:00
|
|
|
writeUint16(addr, thread->pop(), mode);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
|
2005-07-29 17:58:00 +00:00
|
|
|
// FUNCTION CALL INSTRUCTIONS
|
2005-01-21 23:25:54 +00:00
|
|
|
CASEOP(opCall)
|
|
|
|
argumentsCount = scriptS.readByte();
|
2005-05-12 15:11:32 +00:00
|
|
|
iparam1 = scriptS.readByte();
|
|
|
|
if (iparam1 != kAddressModule) {
|
|
|
|
error("Script::runThread iparam1 != kAddressModule");
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
2005-05-12 15:11:32 +00:00
|
|
|
addr = thread->baseAddress(iparam1);
|
2005-01-22 14:43:49 +00:00
|
|
|
iparam1 = scriptS.readSint16LE();
|
|
|
|
addr += iparam1;
|
2005-01-21 23:25:54 +00:00
|
|
|
thread->push(argumentsCount);
|
|
|
|
|
2005-05-12 15:11:32 +00:00
|
|
|
jmpOffset1 = scriptS.pos();
|
2005-01-21 23:25:54 +00:00
|
|
|
// NOTE: The original pushes the program
|
|
|
|
// counter as a pointer here. But I don't think
|
|
|
|
// we will have to do that.
|
2005-05-12 15:11:32 +00:00
|
|
|
thread->push(jmpOffset1);
|
2005-04-03 17:23:02 +00:00
|
|
|
// NOTE2: program counter is 32bit - so we should "emulate" it size - because kAddressStack relies on it
|
|
|
|
thread->push(0);
|
2005-01-22 14:43:49 +00:00
|
|
|
thread->_instructionOffset = iparam1;
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-21 23:25:54 +00:00
|
|
|
CASEOP(opCcall)
|
|
|
|
CASEOP(opCcallV)
|
|
|
|
argumentsCount = scriptS.readByte();
|
|
|
|
functionNumber = scriptS.readUint16LE();
|
2005-07-29 17:58:00 +00:00
|
|
|
if (functionNumber >= ((_vm->getGameType() == GType_IHNM) ?
|
2005-07-21 22:13:06 +00:00
|
|
|
IHNM_SCRIPT_FUNCTION_MAX : ITE_SCRIPT_FUNCTION_MAX)) {
|
2005-01-28 03:47:12 +00:00
|
|
|
error("Script::runThread() Invalid script function number (%d)", functionNumber);
|
2005-01-21 23:25:54 +00:00
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-08-11 14:00:26 +00:00
|
|
|
debug(2, "Calling #%d %s argCount=%i", functionNumber, _scriptFunctionsList[functionNumber].scriptFunctionName, argumentsCount);
|
2005-01-21 23:25:54 +00:00
|
|
|
scriptFunction = _scriptFunctionsList[functionNumber].scriptFunction;
|
2005-06-13 13:40:28 +00:00
|
|
|
checkStackTopIndex = thread->_stackTopIndex + argumentsCount;
|
2005-06-19 14:06:20 +00:00
|
|
|
disContinue = false;
|
|
|
|
(this->*scriptFunction)(thread, argumentsCount, disContinue);
|
|
|
|
if (disContinue) {
|
|
|
|
return true;
|
|
|
|
}
|
2005-07-21 22:13:06 +00:00
|
|
|
if (scriptFunction == &Saga::Script::sfScriptGotoScene ||
|
2005-07-24 13:41:49 +00:00
|
|
|
scriptFunction == &Saga::Script::sfVsetTrack) {
|
2005-03-29 17:54:53 +00:00
|
|
|
return true; // cause abortAllThreads called and _this_ thread destroyed
|
2005-01-21 23:25:54 +00:00
|
|
|
}
|
2004-10-27 02:27:54 +00:00
|
|
|
|
2005-06-15 20:07:56 +00:00
|
|
|
thread->_stackTopIndex = checkStackTopIndex;
|
|
|
|
|
2005-01-21 23:44:34 +00:00
|
|
|
if (operandChar == opCcall) {// CALL function
|
2005-01-21 23:25:54 +00:00
|
|
|
thread->push(thread->_returnValue);
|
2005-01-21 23:44:34 +00:00
|
|
|
}
|
2004-10-27 02:27:54 +00:00
|
|
|
|
2005-01-21 23:25:54 +00:00
|
|
|
if (thread->_flags & kTFlagAsleep)
|
|
|
|
instructionCount = instructionLimit; // break out of loop!
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-21 23:44:34 +00:00
|
|
|
CASEOP(opEnter)
|
2005-01-21 21:55:54 +00:00
|
|
|
thread->push(thread->_frameIndex);
|
|
|
|
thread->_frameIndex = thread->_stackTopIndex;
|
2005-01-22 14:43:49 +00:00
|
|
|
thread->_stackTopIndex -= (scriptS.readSint16LE() / 2);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-21 23:44:34 +00:00
|
|
|
CASEOP(opReturn)
|
|
|
|
thread->_returnValue = thread->pop();
|
|
|
|
CASEOP(opReturnV)
|
2005-01-21 21:55:54 +00:00
|
|
|
thread->_stackTopIndex = thread->_frameIndex;
|
|
|
|
thread->_frameIndex = thread->pop();
|
|
|
|
if (thread->pushedSize() == 0) {
|
|
|
|
thread->_flags |= kTFlagFinished;
|
2005-03-29 17:54:53 +00:00
|
|
|
return true;
|
2004-04-12 21:40:49 +00:00
|
|
|
} else {
|
2005-04-03 17:23:02 +00:00
|
|
|
thread->pop(); //cause it 0
|
2005-01-21 21:55:54 +00:00
|
|
|
thread->_instructionOffset = thread->pop();
|
2005-10-11 13:23:47 +00:00
|
|
|
|
|
|
|
// Pop all the call parameters off the stack
|
2005-01-22 14:43:49 +00:00
|
|
|
iparam1 = thread->pop();
|
|
|
|
while (iparam1--) {
|
2005-01-21 23:44:34 +00:00
|
|
|
thread->pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (operandChar == opReturn) {
|
|
|
|
thread->push(thread->_returnValue);
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-07-29 17:58:00 +00:00
|
|
|
// BRANCH INSTRUCTIONS
|
2005-01-22 14:43:49 +00:00
|
|
|
CASEOP(opJmp)
|
2005-05-12 15:11:32 +00:00
|
|
|
jmpOffset1 = scriptS.readUint16LE();
|
|
|
|
thread->_instructionOffset = jmpOffset1;
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-22 14:43:49 +00:00
|
|
|
CASEOP(opJmpTrueV)
|
2005-05-12 15:11:32 +00:00
|
|
|
jmpOffset1 = scriptS.readUint16LE();
|
2005-01-22 14:43:49 +00:00
|
|
|
if (thread->pop()) {
|
2005-05-12 15:11:32 +00:00
|
|
|
thread->_instructionOffset = jmpOffset1;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-01-22 14:43:49 +00:00
|
|
|
CASEOP(opJmpFalseV)
|
2005-05-12 15:11:32 +00:00
|
|
|
jmpOffset1 = scriptS.readUint16LE();
|
2005-01-22 14:43:49 +00:00
|
|
|
if (!thread->pop()) {
|
2005-05-12 15:11:32 +00:00
|
|
|
thread->_instructionOffset = jmpOffset1;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-01-22 14:43:49 +00:00
|
|
|
CASEOP(opJmpTrue)
|
2005-05-12 15:11:32 +00:00
|
|
|
jmpOffset1 = scriptS.readUint16LE();
|
2005-01-22 14:43:49 +00:00
|
|
|
if (thread->stackTop()) {
|
2005-05-12 15:11:32 +00:00
|
|
|
thread->_instructionOffset = jmpOffset1;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-01-22 14:43:49 +00:00
|
|
|
CASEOP(opJmpFalse)
|
2005-05-12 15:11:32 +00:00
|
|
|
jmpOffset1 = scriptS.readUint16LE();
|
2005-01-22 14:43:49 +00:00
|
|
|
if (!thread->stackTop()) {
|
2005-05-12 15:11:32 +00:00
|
|
|
thread->_instructionOffset = jmpOffset1;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-01-22 14:43:49 +00:00
|
|
|
CASEOP(opJmpSwitch)
|
|
|
|
iparam1 = scriptS.readSint16LE();
|
2005-05-12 15:11:32 +00:00
|
|
|
iparam2 = thread->pop();
|
2005-01-22 14:43:49 +00:00
|
|
|
while (iparam1--) {
|
2005-05-12 15:11:32 +00:00
|
|
|
iparam3 = scriptS.readUint16LE();
|
2005-01-22 14:43:49 +00:00
|
|
|
thread->_instructionOffset = scriptS.readUint16LE();
|
2005-05-12 15:11:32 +00:00
|
|
|
if (iparam3 == iparam2) {
|
2005-01-22 14:43:49 +00:00
|
|
|
break;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
2005-01-22 14:43:49 +00:00
|
|
|
if (iparam1 < 0) {
|
|
|
|
thread->_instructionOffset = scriptS.readUint16LE();
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-22 14:43:49 +00:00
|
|
|
CASEOP(opJmpRandom)
|
|
|
|
// Supposedly the number of possible branches.
|
|
|
|
// The original interpreter ignores it.
|
|
|
|
scriptS.readUint16LE();
|
|
|
|
iparam1 = scriptS.readSint16LE();
|
|
|
|
iparam1 = _vm->_rnd.getRandomNumber(iparam1 - 1);
|
|
|
|
while (1) {
|
|
|
|
iparam2 = scriptS.readSint16LE();
|
|
|
|
thread->_instructionOffset = scriptS.readUint16LE();
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-01-22 14:43:49 +00:00
|
|
|
iparam1 -= iparam2;
|
|
|
|
if (iparam1 < 0) {
|
|
|
|
break;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2004-08-26 23:28:10 +00:00
|
|
|
// UNARY INSTRUCTIONS
|
2005-01-22 14:43:49 +00:00
|
|
|
CASEOP(opNegate)
|
|
|
|
thread->push(-thread->pop());
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-22 14:43:49 +00:00
|
|
|
CASEOP(opNot)
|
|
|
|
thread->push(!thread->pop());
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-22 14:43:49 +00:00
|
|
|
CASEOP(opCompl)
|
|
|
|
thread->push(~thread->pop());
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-22 14:43:49 +00:00
|
|
|
|
|
|
|
CASEOP(opIncV)
|
2005-10-11 17:20:30 +00:00
|
|
|
mode = scriptS.readByte();
|
|
|
|
addr = thread->baseAddress(mode);
|
2005-01-22 14:43:49 +00:00
|
|
|
iparam1 = scriptS.readSint16LE();
|
|
|
|
addr += iparam1;
|
2005-10-11 17:20:30 +00:00
|
|
|
iparam1 = readUint16(addr, mode);
|
|
|
|
writeUint16(addr, iparam1 + 1, mode);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-22 14:43:49 +00:00
|
|
|
CASEOP(opDecV)
|
2005-10-11 17:20:30 +00:00
|
|
|
mode = scriptS.readByte();
|
|
|
|
addr = thread->baseAddress(mode);
|
2005-01-22 14:43:49 +00:00
|
|
|
iparam1 = scriptS.readSint16LE();
|
|
|
|
addr += iparam1;
|
2005-10-11 17:20:30 +00:00
|
|
|
iparam1 = readUint16(addr, mode);
|
|
|
|
writeUint16(addr, iparam1 - 1, mode);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-22 14:43:49 +00:00
|
|
|
CASEOP(opPostInc)
|
2005-10-11 17:20:30 +00:00
|
|
|
mode = scriptS.readByte();
|
|
|
|
addr = thread->baseAddress(mode);
|
2005-01-22 14:43:49 +00:00
|
|
|
iparam1 = scriptS.readSint16LE();
|
|
|
|
addr += iparam1;
|
2005-10-11 17:20:30 +00:00
|
|
|
iparam1 = readUint16(addr, mode);
|
2005-10-11 14:03:36 +00:00
|
|
|
thread->push(iparam1);
|
2005-10-11 17:20:30 +00:00
|
|
|
writeUint16(addr, iparam1 + 1, mode);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-22 14:43:49 +00:00
|
|
|
CASEOP(opPostDec)
|
2005-10-11 17:20:30 +00:00
|
|
|
mode = scriptS.readByte();
|
|
|
|
addr = thread->baseAddress(mode);
|
2005-01-22 14:43:49 +00:00
|
|
|
iparam1 = scriptS.readSint16LE();
|
|
|
|
addr += iparam1;
|
2005-10-11 17:20:30 +00:00
|
|
|
iparam1 = readUint16(addr, mode);
|
2005-10-11 14:03:36 +00:00
|
|
|
thread->push(iparam1);
|
2005-10-11 17:20:30 +00:00
|
|
|
writeUint16(addr, iparam1 - 1, mode);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
|
2005-07-29 17:58:00 +00:00
|
|
|
// ARITHMETIC INSTRUCTIONS
|
2005-01-22 15:28:24 +00:00
|
|
|
CASEOP(opAdd)
|
|
|
|
iparam2 = thread->pop();
|
|
|
|
iparam1 = thread->pop();
|
|
|
|
iparam1 += iparam2;
|
|
|
|
thread->push(iparam1);
|
|
|
|
break;
|
|
|
|
CASEOP(opSub)
|
|
|
|
iparam2 = thread->pop();
|
|
|
|
iparam1 = thread->pop();
|
|
|
|
iparam1 -= iparam2;
|
|
|
|
thread->push(iparam1);
|
|
|
|
break;
|
|
|
|
CASEOP(opMul)
|
|
|
|
iparam2 = thread->pop();
|
|
|
|
iparam1 = thread->pop();
|
|
|
|
iparam1 *= iparam2;
|
|
|
|
thread->push(iparam1);
|
|
|
|
break;
|
|
|
|
CASEOP(opDiv)
|
|
|
|
iparam2 = thread->pop();
|
|
|
|
iparam1 = thread->pop();
|
|
|
|
iparam1 /= iparam2;
|
|
|
|
thread->push(iparam1);
|
|
|
|
break;
|
|
|
|
CASEOP(opMod)
|
|
|
|
iparam2 = thread->pop();
|
|
|
|
iparam1 = thread->pop();
|
|
|
|
iparam1 %= iparam2;
|
|
|
|
thread->push(iparam1);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2004-05-13 01:41:23 +00:00
|
|
|
|
2005-07-29 17:58:00 +00:00
|
|
|
// COMPARISION INSTRUCTIONS
|
2005-01-22 15:28:24 +00:00
|
|
|
CASEOP(opEq)
|
|
|
|
iparam2 = thread->pop();
|
|
|
|
iparam1 = thread->pop();
|
|
|
|
thread->push((iparam1 == iparam2) ? 1 : 0);
|
2005-04-24 15:17:38 +00:00
|
|
|
debug(8, "0x%X 0x%X", iparam1, iparam2);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-22 15:28:24 +00:00
|
|
|
CASEOP(opNe)
|
|
|
|
iparam2 = thread->pop();
|
|
|
|
iparam1 = thread->pop();
|
|
|
|
thread->push((iparam1 != iparam2) ? 1 : 0);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-22 15:28:24 +00:00
|
|
|
CASEOP(opGt)
|
|
|
|
iparam2 = thread->pop();
|
|
|
|
iparam1 = thread->pop();
|
|
|
|
thread->push((iparam1 > iparam2) ? 1 : 0);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-22 15:28:24 +00:00
|
|
|
CASEOP(opLt)
|
|
|
|
iparam2 = thread->pop();
|
|
|
|
iparam1 = thread->pop();
|
|
|
|
thread->push((iparam1 < iparam2) ? 1 : 0);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-22 15:28:24 +00:00
|
|
|
CASEOP(opGe)
|
|
|
|
iparam2 = thread->pop();
|
|
|
|
iparam1 = thread->pop();
|
|
|
|
thread->push((iparam1 >= iparam2) ? 1 : 0);
|
|
|
|
break;
|
|
|
|
CASEOP(opLe)
|
|
|
|
iparam2 = thread->pop();
|
|
|
|
iparam1 = thread->pop();
|
|
|
|
thread->push((iparam1 <= iparam2) ? 1 : 0);
|
|
|
|
break;
|
|
|
|
|
2005-07-29 17:58:00 +00:00
|
|
|
// SHIFT INSTRUCTIONS
|
2005-01-22 15:28:24 +00:00
|
|
|
CASEOP(opRsh)
|
|
|
|
iparam2 = thread->pop();
|
|
|
|
iparam1 = thread->pop();
|
|
|
|
iparam1 >>= iparam2;
|
|
|
|
thread->push(iparam1);
|
|
|
|
break;
|
|
|
|
CASEOP(opLsh)
|
|
|
|
iparam2 = thread->pop();
|
|
|
|
iparam1 = thread->pop();
|
|
|
|
iparam1 <<= iparam2;
|
|
|
|
thread->push(iparam1);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
|
2005-07-29 17:58:00 +00:00
|
|
|
// BITWISE INSTRUCTIONS
|
2005-01-22 15:28:24 +00:00
|
|
|
CASEOP(opAnd)
|
|
|
|
iparam2 = thread->pop();
|
|
|
|
iparam1 = thread->pop();
|
|
|
|
iparam1 &= iparam2;
|
|
|
|
thread->push(iparam1);
|
|
|
|
break;
|
|
|
|
CASEOP(opOr)
|
|
|
|
iparam2 = thread->pop();
|
|
|
|
iparam1 = thread->pop();
|
|
|
|
iparam1 |= iparam2;
|
|
|
|
thread->push(iparam1);
|
|
|
|
break;
|
|
|
|
CASEOP(opXor)
|
|
|
|
iparam2 = thread->pop();
|
|
|
|
iparam1 = thread->pop();
|
|
|
|
iparam1 ^= iparam2;
|
|
|
|
thread->push(iparam1);
|
|
|
|
break;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-29 17:58:00 +00:00
|
|
|
// LOGICAL INSTRUCTIONS
|
2005-01-22 15:28:24 +00:00
|
|
|
CASEOP(opLAnd)
|
|
|
|
iparam2 = thread->pop();
|
|
|
|
iparam1 = thread->pop();
|
|
|
|
thread->push((iparam1 && iparam2) ? 1 : 0);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-22 15:28:24 +00:00
|
|
|
CASEOP(opLOr)
|
|
|
|
iparam2 = thread->pop();
|
|
|
|
iparam1 = thread->pop();
|
|
|
|
thread->push((iparam1 || iparam2) ? 1 : 0);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-22 15:28:24 +00:00
|
|
|
CASEOP(opLXor)
|
|
|
|
iparam2 = thread->pop();
|
2005-07-29 17:58:00 +00:00
|
|
|
iparam1 = thread->pop();
|
2005-01-22 15:28:24 +00:00
|
|
|
thread->push(((iparam1 && !iparam2) || (!iparam1 && iparam2)) ? 1 : 0);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
|
|
|
|
2005-07-29 17:58:00 +00:00
|
|
|
// GAME INSTRUCTIONS
|
2005-01-22 16:32:30 +00:00
|
|
|
CASEOP(opSpeak) {
|
2004-12-21 06:49:07 +00:00
|
|
|
int stringsCount;
|
2004-12-17 11:18:56 +00:00
|
|
|
uint16 actorId;
|
2005-01-22 16:32:30 +00:00
|
|
|
uint16 speechFlags;
|
2004-12-21 06:49:07 +00:00
|
|
|
int sampleResourceId = -1;
|
2005-01-22 16:32:30 +00:00
|
|
|
int16 first;
|
2004-12-21 06:49:07 +00:00
|
|
|
const char *strings[ACTOR_SPEECH_STRING_MAX];
|
|
|
|
|
|
|
|
if (_vm->_actor->isSpeaking()) {
|
|
|
|
thread->wait(kWaitTypeSpeech);
|
2005-03-29 17:54:53 +00:00
|
|
|
return false;
|
2004-12-21 06:49:07 +00:00
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-12-21 06:49:07 +00:00
|
|
|
stringsCount = scriptS.readByte();
|
Allowed IHNM to use the opSpeak opcode. Aborting that code path early meant
that the instruction wasn't fully read, so the next opcode would be wrong.
This is what caused it to crash.
To keep the game from hanging, I also allowed the engine to call the
_actors->direct() function for IHNM. This allows AM's intro speech to be
played in its entirety.
Since this includes the "hate" speech, I've removed that part from the
hard-coded intro. To get the right music playing, I've enabled the
sfPlayMusic() function for IHNM. This is pure guesswork, though. Once the
scene changes, the wrong music plays again. However, this is scene music,
i.e. not scripted.
It doesn't play the background sound. Looks like _fxTable[] isn't generated
for IHNM. More noticeably, until the scene changes it doesn't show any
graphics apart from the subtitles, which are drawn in the wrong colour and
(I believe) the wrong font.
svn-id: r18712
2005-08-26 12:07:31 +00:00
|
|
|
actorId = scriptS.readUint16LE();
|
2004-12-21 06:49:07 +00:00
|
|
|
speechFlags = scriptS.readByte();
|
|
|
|
scriptS.readUint16LE(); // x,y skip
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2004-12-21 06:49:07 +00:00
|
|
|
if (stringsCount == 0)
|
|
|
|
error("opSpeak stringsCount == 0");
|
|
|
|
|
2004-12-22 21:04:50 +00:00
|
|
|
if (stringsCount > ACTOR_SPEECH_STRING_MAX)
|
2004-12-21 06:49:07 +00:00
|
|
|
error("opSpeak stringsCount=0x%X exceed ACTOR_SPEECH_STRING_MAX", stringsCount);
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-01-22 16:32:30 +00:00
|
|
|
iparam1 = first = thread->stackTop();
|
2004-12-21 06:49:07 +00:00
|
|
|
for (i = 0; i < stringsCount; i++) {
|
2005-01-22 16:32:30 +00:00
|
|
|
iparam1 = thread->pop();
|
|
|
|
strings[i] = thread->_strings->getString(iparam1);
|
2004-12-21 06:49:07 +00:00
|
|
|
}
|
|
|
|
// now data contains last string index
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-01-11 21:10:36 +00:00
|
|
|
if (_vm->getGameId() == GID_ITE_DISK_G) { // special ITE dos
|
2005-07-29 17:58:00 +00:00
|
|
|
if ((_vm->_scene->currentSceneNumber() == ITE_DEFAULT_SCENE) &&
|
2005-01-22 16:32:30 +00:00
|
|
|
(iparam1 >= 288) && (iparam1 <= (RID_SCENE1_VOICE_138 - RID_SCENE1_VOICE_009 + 288))) {
|
|
|
|
sampleResourceId = RID_SCENE1_VOICE_009 + iparam1 - 288;
|
2004-12-21 06:49:07 +00:00
|
|
|
}
|
|
|
|
} else {
|
2005-01-21 21:55:54 +00:00
|
|
|
if (thread->_voiceLUT->voicesCount > first) {
|
|
|
|
sampleResourceId = thread->_voiceLUT->voices[first];
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
2004-12-21 06:49:07 +00:00
|
|
|
}
|
|
|
|
|
2005-08-10 13:56:51 +00:00
|
|
|
if (sampleResourceId < 0 || sampleResourceId > 4000)
|
|
|
|
sampleResourceId = -1;
|
|
|
|
|
|
|
|
if (_vm->getGameType() == GType_ITE && !sampleResourceId)
|
2005-08-09 16:01:04 +00:00
|
|
|
sampleResourceId = -1;
|
2005-08-04 14:49:04 +00:00
|
|
|
|
2005-07-29 17:58:00 +00:00
|
|
|
_vm->_actor->actorSpeech(actorId, strings, stringsCount, sampleResourceId, speechFlags);
|
2004-12-21 06:49:07 +00:00
|
|
|
|
|
|
|
if (!(speechFlags & kSpeakAsync)) {
|
|
|
|
thread->wait(kWaitTypeSpeech);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2005-01-22 16:32:30 +00:00
|
|
|
CASEOP(opDialogBegin)
|
2005-01-17 20:17:06 +00:00
|
|
|
if (_conversingThread) {
|
|
|
|
thread->wait(kWaitTypeDialogBegin);
|
2005-03-29 17:54:53 +00:00
|
|
|
return false;
|
2005-01-17 20:17:06 +00:00
|
|
|
}
|
|
|
|
_conversingThread = thread;
|
|
|
|
_vm->_interface->converseClear();
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-22 16:32:30 +00:00
|
|
|
CASEOP(opDialogEnd)
|
2005-01-17 20:17:06 +00:00
|
|
|
if (thread == _conversingThread) {
|
2005-01-06 14:02:53 +00:00
|
|
|
_vm->_interface->activate();
|
|
|
|
_vm->_interface->setMode(kPanelConverse);
|
2005-01-17 20:17:06 +00:00
|
|
|
thread->wait(kWaitTypeDialogEnd);
|
2005-04-18 20:03:14 +00:00
|
|
|
return false;
|
2005-01-06 14:02:53 +00:00
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-01-22 16:32:30 +00:00
|
|
|
CASEOP(opReply) {
|
2005-01-17 20:17:06 +00:00
|
|
|
const char *str;
|
2005-01-22 16:32:30 +00:00
|
|
|
byte replyNum;
|
|
|
|
byte flags;
|
|
|
|
replyNum = scriptS.readByte();
|
|
|
|
flags = scriptS.readByte();
|
2005-05-12 15:11:32 +00:00
|
|
|
iparam1 = 0;
|
2005-01-17 20:17:06 +00:00
|
|
|
|
|
|
|
if (flags & kReplyOnce) {
|
2005-05-12 15:11:32 +00:00
|
|
|
iparam1 = scriptS.readSint16LE();
|
|
|
|
addr = thread->_staticBase + (iparam1 >> 3);
|
|
|
|
if (*addr & (1 << (iparam1 & 7))) {
|
2005-01-22 16:32:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
2005-01-17 20:17:06 +00:00
|
|
|
|
2005-01-21 21:55:54 +00:00
|
|
|
str = thread->_strings->getString(thread->pop());
|
2005-05-12 15:11:32 +00:00
|
|
|
if (_vm->_interface->converseAddText(str, replyNum, flags, iparam1))
|
|
|
|
warning("Error adding ConverseText (%s, %d, %d, %d)", str, replyNum, flags, iparam1);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-01-22 16:32:30 +00:00
|
|
|
CASEOP(opAnimate)
|
2004-08-26 23:28:10 +00:00
|
|
|
scriptS.readUint16LE();
|
|
|
|
scriptS.readUint16LE();
|
2005-05-12 15:11:32 +00:00
|
|
|
jmpOffset1 = scriptS.readByte();
|
|
|
|
thread->_instructionOffset += jmpOffset1;
|
2004-08-26 23:28:10 +00:00
|
|
|
break;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
default:
|
2005-01-22 16:32:30 +00:00
|
|
|
error("Script::runThread() Invalid opcode encountered 0x%X", operandChar);
|
2004-05-01 16:15:55 +00:00
|
|
|
}
|
2005-01-22 16:32:30 +00:00
|
|
|
|
2005-01-22 14:43:49 +00:00
|
|
|
if (thread->_flags & (kTFlagFinished | kTFlagAborted)) {
|
2005-04-11 15:34:13 +00:00
|
|
|
error("Wrong flags %d in thread", thread->_flags);
|
2005-07-29 17:58:00 +00:00
|
|
|
}
|
2005-01-22 14:43:49 +00:00
|
|
|
|
2005-03-29 17:54:53 +00:00
|
|
|
// Set instruction offset only if a previous instruction didn't branch
|
|
|
|
if (savedInstructionOffset == thread->_instructionOffset) {
|
|
|
|
thread->_instructionOffset = scriptS.pos();
|
|
|
|
} else {
|
|
|
|
if (thread->_instructionOffset >= scriptS.size()) {
|
|
|
|
error("Script::runThread() Out of range script execution");
|
2005-01-22 14:43:49 +00:00
|
|
|
}
|
2005-01-03 21:17:32 +00:00
|
|
|
|
2005-03-29 17:54:53 +00:00
|
|
|
scriptS.seek(thread->_instructionOffset);
|
2005-07-29 17:58:00 +00:00
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
2005-03-29 17:54:53 +00:00
|
|
|
return false;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Saga
|
|
|
|
|