aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kurushin2005-01-22 16:32:30 +0000
committerAndrew Kurushin2005-01-22 16:32:30 +0000
commit8543306e5617cd067c246f5b56a612bffc3fdfe7 (patch)
treef443f5d19ee061a4c1cc6a3512323af7ba52024c
parent0030e821fe0e417d96387d52ba0c6acf56f93cfe (diff)
downloadscummvm-rg350-8543306e5617cd067c246f5b56a612bffc3fdfe7.tar.gz
scummvm-rg350-8543306e5617cd067c246f5b56a612bffc3fdfe7.tar.bz2
scummvm-rg350-8543306e5617cd067c246f5b56a612bffc3fdfe7.zip
all opcodes revisited
all ITE opcodes supported (now we should go through scriptFunctions) svn-id: r16617
-rw-r--r--saga/script.cpp12
-rw-r--r--saga/script.h5
-rw-r--r--saga/sthread.cpp73
3 files changed, 32 insertions, 58 deletions
diff --git a/saga/script.cpp b/saga/script.cpp
index dd775608d0..7f6d0b78e5 100644
--- a/saga/script.cpp
+++ b/saga/script.cpp
@@ -302,18 +302,6 @@ void Script::loadModuleVoiceLUT(ModuleData &module, const byte *resourcePointer,
}
}
-void Script::scriptError(ScriptThread *thread, const char *format, ...) {
- char buf[STRINGBUFLEN];
- va_list argptr;
-
- va_start(argptr, format);
- vsprintf(buf, format, argptr);
- va_end (argptr);
-
- thread->_flags |= kTFlagAborted;
- debug(0, "Script::scriptError %X: %s", thread->_instructionOffset, buf);
- _vm->_console->DebugPrintf("Script::scriptError %X: %s", thread->_instructionOffset, buf);
-}
void Script::scriptInfo() {
/* uint32 n_entrypoints;
diff --git a/saga/script.h b/saga/script.h
index ffc3dca69a..04d8f62dd7 100644
--- a/saga/script.h
+++ b/saga/script.h
@@ -173,12 +173,12 @@ enum OpCodes {
opLAnd = 0x44,
opLOr = 0x45,
opLXor = 0x46,
-
//...
opSpeak = 0x53,
opDialogBegin = 0x54,
opDialogEnd = 0x55,
- opReply = 0x56
+ opReply = 0x56,
+ opAnimate = 0x57
};
enum CycleFlags {
@@ -453,7 +453,6 @@ private:
const ScriptFunctionDescription *_scriptFunctionsList;
void setupScriptFuncList(void);
- void scriptError(ScriptThread *thread, const char *format, ...);
int SDebugPrintInstr(ScriptThread *thread);
int SF_putString(SCRIPTFUNC_PARAMS);
diff --git a/saga/sthread.cpp b/saga/sthread.cpp
index 400efe766d..f084a5d80a 100644
--- a/saga/sthread.cpp
+++ b/saga/sthread.cpp
@@ -174,20 +174,15 @@ void Script::runThread(ScriptThread *thread, uint instructionLimit) {
uint16 param2;
int16 iparam1;
int16 iparam2;
-// long iresult;
byte argumentsCount;
uint16 functionNumber;
int scriptFunctionReturnValue;
ScriptFunctionType scriptFunction;
- uint16 data;
int debug_print = 0;
-// int n_buf;
-// int bitstate;
int operandChar;
int i;
- int unhandled = 0;
// Handle debug single-stepping
if ((thread == _dbg_thread) && _dbg_singlestep) {
@@ -582,12 +577,12 @@ void Script::runThread(ScriptThread *thread, uint instructionLimit) {
break;
// GAME INSTRUCTIONS
- case opSpeak: { // (opSpeak): Play Character Speech
+ CASEOP(opSpeak) {
int stringsCount;
uint16 actorId;
- int speechFlags;
+ uint16 speechFlags;
int sampleResourceId = -1;
- int first;
+ int16 first;
const char *strings[ACTOR_SPEECH_STRING_MAX];
if (_vm->_actor->isSpeaking()) {
@@ -606,16 +601,17 @@ void Script::runThread(ScriptThread *thread, uint instructionLimit) {
if (stringsCount > ACTOR_SPEECH_STRING_MAX)
error("opSpeak stringsCount=0x%X exceed ACTOR_SPEECH_STRING_MAX", stringsCount);
- data = first = thread->stackTop();
+ iparam1 = first = thread->stackTop();
for (i = 0; i < stringsCount; i++) {
- data = thread->pop();
- strings[i] = thread->_strings->getString(data);
+ iparam1 = thread->pop();
+ strings[i] = thread->_strings->getString(iparam1);
}
// now data contains last string index
if (_vm->getGameId() == GID_ITE_DISK_G) { // special ITE dos
- if ((_vm->_scene->currentSceneNumber() == ITE_DEFAULT_SCENE) && (data >= 288) && (data <= (RID_SCENE1_VOICE_138 - RID_SCENE1_VOICE_009 + 288))) {
- sampleResourceId = RID_SCENE1_VOICE_009 + data - 288;
+ if ((_vm->_scene->currentSceneNumber() == ITE_DEFAULT_SCENE) &&
+ (iparam1 >= 288) && (iparam1 <= (RID_SCENE1_VOICE_138 - RID_SCENE1_VOICE_009 + 288))) {
+ sampleResourceId = RID_SCENE1_VOICE_009 + iparam1 - 288;
}
} else {
if (thread->_voiceLUT->voicesCount > first) {
@@ -627,13 +623,10 @@ void Script::runThread(ScriptThread *thread, uint instructionLimit) {
if (!(speechFlags & kSpeakAsync)) {
thread->wait(kWaitTypeSpeech);
- thread->_instructionOffset = scriptS.pos();
- return;
}
}
break;
-
- case opDialogBegin: // (DLGS): Initialize dialogue interface
+ CASEOP(opDialogBegin)
if (_conversingThread) {
thread->wait(kWaitTypeDialogBegin);
return;
@@ -641,46 +634,45 @@ void Script::runThread(ScriptThread *thread, uint instructionLimit) {
_conversingThread = thread;
_vm->_interface->converseClear();
break;
-
- case opDialogEnd: // (DLGX): Run dialogue interface
+ CASEOP(opDialogEnd)
if (thread == _conversingThread) {
_vm->_interface->activate();
_vm->_interface->setMode(kPanelConverse);
thread->wait(kWaitTypeDialogEnd);
- return;
}
break;
-
- case opReply: // (DLGO): Add a dialogue option to interface
- {
- uint16 n = 0;
+ CASEOP(opReply) {
const char *str;
- int replyNum = scriptS.readByte();
- int flags = scriptS.readByte();
+ byte replyNum;
+ byte flags;
+ replyNum = scriptS.readByte();
+ flags = scriptS.readByte();
+ param1 = 0;
if (flags & kReplyOnce) {
- n = scriptS.readUint16LE();
- // TODO:
+ param1 = scriptS.readUint16LE();
+ addr = thread->_staticBase + (param1 >> 3);
+ if (*addr & (1 << (param1 & 7))) {
+ break;
+ }
}
str = thread->_strings->getString(thread->pop());
- if (_vm->_interface->converseAddText(str, replyNum, flags, n))
- warning("Error adding ConverseText (%s, %d, %d, %d)", str, replyNum, flags, n);
+ if (_vm->_interface->converseAddText(str, replyNum, flags, param1))
+ warning("Error adding ConverseText (%s, %d, %d, %d)", str, replyNum, flags, param1);
}
break;
- case 0x57: // animate
+ CASEOP(opAnimate)
scriptS.readUint16LE();
scriptS.readUint16LE();
- iparam1 = (long)scriptS.readByte();
- thread->_instructionOffset += iparam1;
+ param1 = scriptS.readByte();
+ thread->_instructionOffset += param1;
break;
-// End instruction list
-
default:
- scriptError(thread, "Invalid opcode encountered");
- return;
+ error("Script::runThread() Invalid opcode encountered 0x%X", operandChar);
}
+
debug(8, operandName);
_vm->_console->DebugPrintf("%s\n", operandName);
@@ -695,18 +687,13 @@ void Script::runThread(ScriptThread *thread, uint instructionLimit) {
thread->_instructionOffset = scriptS.pos();
} else {
if (thread->_instructionOffset >= scriptS.size()) {
- scriptError(thread, "Out of range script execution");
- return;
+ error("Script::runThread() Out of range script execution");
}
scriptS.seek(thread->_instructionOffset);
}
}
-
- if (unhandled) { // TODO: remove it
- scriptError(thread, "Unhandled opcode");
- }
}
}