diff options
author | Filippos Karapetis | 2008-05-18 10:57:58 +0000 |
---|---|---|
committer | Filippos Karapetis | 2008-05-18 10:57:58 +0000 |
commit | 0c81b70ba35c03b2d5a862eb4afb3f0eae28c9b8 (patch) | |
tree | dbc8b98061d6c19ad0b879b332b0470fa2ce90d5 /engines/made | |
parent | 1ea774e95f8ce0927a38aa0e5d467cc6ca82b78b (diff) | |
download | scummvm-rg350-0c81b70ba35c03b2d5a862eb4afb3f0eae28c9b8.tar.gz scummvm-rg350-0c81b70ba35c03b2d5a862eb4afb3f0eae28c9b8.tar.bz2 scummvm-rg350-0c81b70ba35c03b2d5a862eb4afb3f0eae28c9b8.zip |
Rewrote the MADE script dumper, hopefully in a more efficient way
svn-id: r32167
Diffstat (limited to 'engines/made')
-rw-r--r-- | engines/made/script.cpp | 91 | ||||
-rw-r--r-- | engines/made/script.h | 2 | ||||
-rw-r--r-- | engines/made/scriptfuncs.h | 1 |
3 files changed, 35 insertions, 59 deletions
diff --git a/engines/made/script.cpp b/engines/made/script.cpp index b14798bab6..d757a21b50 100644 --- a/engines/made/script.cpp +++ b/engines/made/script.cpp @@ -175,6 +175,9 @@ ScriptInterpreter::ScriptInterpreter(MadeEngine *vm) : _vm(vm) { _functions = new ScriptFunctions(_vm); _functions->setupExternalsTable(); + // set to true to dump scripts instead of parsing them + _dumpScripts = false; + #undef COMMAND } @@ -194,7 +197,7 @@ void ScriptInterpreter::runScript(int16 scriptObjectIndex) { while (!_vm->_quit) { byte opcode = readByte(); if (opcode >= 1 && opcode <= _commandsMax) { - debug(4, "[%04X:%04X] opcode = %s", _runningScriptObjectIndex, (uint) (_codeIp - _codeBase), _commands[opcode - 1].desc); + debug(4, "[%04X:%04X] %s", _runningScriptObjectIndex, (uint) (_codeIp - _codeBase), _commands[opcode - 1].desc); (this->*_commands[opcode - 1].proc)(); } else { warning("ScriptInterpreter::runScript(%d) Unknown opcode %02X", _runningScriptObjectIndex, opcode); @@ -202,61 +205,6 @@ void ScriptInterpreter::runScript(int16 scriptObjectIndex) { } } -void ScriptInterpreter::dumpScript(int16 scriptObjectIndex) { - _codeBase = _vm->_dat->getObject(scriptObjectIndex)->getData(); - _codeIp = _codeBase; - int16 val = 0; - - // TODO: script size - while (true) { - byte opcode = readByte(); - if (opcode >= 1 && opcode <= _commandsMax) { - printf("[%04X:%04X] %s\n", _runningScriptObjectIndex, (uint) (_codeIp - _codeBase), _commands[opcode - 1].desc); - //(this->*_commands[opcode - 1].proc)(); - - // Handle command data - if (!strcmp(_commands[opcode - 1].desc, "cmd_branchTrue") || - !strcmp(_commands[opcode - 1].desc, "cmd_branchFalse") || - !strcmp(_commands[opcode - 1].desc, "cmd_branch")) { - val = readInt16(); - printf("Offset = %04X\n", val); - } else if (!strcmp(_commands[opcode - 1].desc, "cmd_loadConstant")) { - val = readInt16(); - printf("Constant = %04X\n", val); - } else if (!strcmp(_commands[opcode - 1].desc, "cmd_loadVariable")) { - val = readInt16(); - printf("Variable = %04X\n", val); - } else if (!strcmp(_commands[opcode - 1].desc, "cmd_set")) { - val = readInt16(); - printf("Variable = %04X\n", val); - } else if (!strcmp(_commands[opcode - 1].desc, "cmd_call")) { - /*byte argc = */readByte(); - // TODO - printf("TODO\n"); - } else if (!strcmp(_commands[opcode - 1].desc, "cmd_arg") || - !strcmp(_commands[opcode - 1].desc, "cmd_aset") || - !strcmp(_commands[opcode - 1].desc, "cmd_tmp") || - !strcmp(_commands[opcode - 1].desc, "cmd_tset") || - !strcmp(_commands[opcode - 1].desc, "cmd_tspace")) { - val = readByte(); - printf("argIndex = %d\n", val); - } else if (!strcmp(_commands[opcode - 1].desc, "cmd_send")) { - /*byte argc = */readByte(); - // TODO - printf("TODO\n"); - } else if (!strcmp(_commands[opcode - 1].desc, "cmd_extend")) { - /*byte func = */readByte(); - - /*byte argc = */readByte(); - // TODO - printf("TODO\n"); - } - } else { - warning("ScriptInterpreter::runScript(%d) Unknown opcode %02X", _runningScriptObjectIndex, opcode); - } - } -} - byte ScriptInterpreter::readByte() { return *_codeIp++; } @@ -269,18 +217,27 @@ int16 ScriptInterpreter::readInt16() { } void ScriptInterpreter::cmd_branchTrue() { + if (_dumpScripts) + return; + int16 ofs = readInt16(); if (_stack.top() != 0) _codeIp = _codeBase + ofs; } void ScriptInterpreter::cmd_branchFalse() { + if (_dumpScripts) + return; + int16 ofs = readInt16(); if (_stack.top() == 0) _codeIp = _codeBase + ofs; } void ScriptInterpreter::cmd_branch() { + if (_dumpScripts) + return; + int16 ofs = readInt16(); _codeIp = _codeBase + ofs; } @@ -474,6 +431,9 @@ void ScriptInterpreter::cmd_return() { return; } + if (_dumpScripts) + return; + int16 funcResult = _stack.top(); _stack.setStackPos(_localStackPos); _localStackPos = kScriptStackLimit - _stack.pop(); @@ -489,6 +449,10 @@ void ScriptInterpreter::cmd_return() { void ScriptInterpreter::cmd_call() { debug(4, "\nENTER: stackPtr = %d; _localStackPos = %d", _stack.getStackPos(), _localStackPos); byte argc = readByte(); + + if (_dumpScripts) + return; + _stack.push(argc); _stack.push(_codeIp - _codeBase); _stack.push(_runningScriptObjectIndex); @@ -521,6 +485,9 @@ void ScriptInterpreter::cmd_yorn() { } void ScriptInterpreter::cmd_save() { + if (_dumpScripts) + return; + int16 result = 0; int16 stringOfs = _stack.top(); const char *filename = _vm->_dat->getString(stringOfs); @@ -529,6 +496,9 @@ void ScriptInterpreter::cmd_save() { } void ScriptInterpreter::cmd_restore() { + if (_dumpScripts) + return; + int16 result = 0; int16 stringOfs = _stack.top(); const char *filename = _vm->_dat->getString(stringOfs); @@ -603,6 +573,9 @@ void ScriptInterpreter::cmd_send() { debug(4, "argc = %d", argc); + if (_dumpScripts) + return; + _stack.push(argc); _stack.push(_codeIp - _codeBase); _stack.push(_runningScriptObjectIndex); @@ -645,11 +618,13 @@ void ScriptInterpreter::cmd_extend() { byte argc = readByte(); int16 *argv = _stack.getStackPtr(); - //debug(4, "func = %d (%s); argc = %d", func, extendFuncNames[func], argc); - debug(2, "func = %d; argc = %d", func, argc); + debug(4, "func = %d (%s); argc = %d", func, _functions->getFuncName(func), argc); for (int i = 0; i < argc; i++) debug(2, "argv[%02d] = %04X (%d)", i, argv[i], argv[i]); + if (_dumpScripts) + return; + int16 result = _functions->callFunction(func, argc, argv); debug(2, "result = %04X (%d)", result, result); diff --git a/engines/made/script.h b/engines/made/script.h index f2c49bd818..0ec43478ab 100644 --- a/engines/made/script.h +++ b/engines/made/script.h @@ -63,7 +63,6 @@ public: ScriptInterpreter(MadeEngine *vm); ~ScriptInterpreter(); void runScript(int16 scriptObjectIndex); - void dumpScript(int16 scriptObjectIndex); protected: MadeEngine *_vm; @@ -72,6 +71,7 @@ protected: int16 _runningScriptObjectIndex; byte *_codeBase, *_codeIp; bool _terminated; + bool _dumpScripts; ScriptFunctions *_functions; diff --git a/engines/made/scriptfuncs.h b/engines/made/scriptfuncs.h index 052856065e..2b0f15c7a2 100644 --- a/engines/made/scriptfuncs.h +++ b/engines/made/scriptfuncs.h @@ -53,6 +53,7 @@ public: return (*_externalFuncs[index])(argc, argv); } void setupExternalsTable(); + const char* getFuncName(int index) { return _externalFuncNames[index]; } protected: MadeEngine *_vm; Audio::SoundHandle _audioStreamHandle; |