void ScriptInterpreter::runScript() { uint32 lastScreenUpdate = 0; while (!_vm->shouldQuit()) { if (_vm->_movieSceneFlag) _vm->_mouseButton = 0; if (_vm->_saveLoadRequested != 0) { if (_vm->_saveLoadRequested == 1) _vm->loadGameState(_vm->_saveLoadSlot); else if (_vm->_saveLoadRequested == 2) _vm->saveGameState(_vm->_saveLoadSlot, _vm->_saveLoadDescription); _vm->_saveLoadRequested = 0; } if (_switchLocalDataNear) { _switchLocalDataNear = false; _localData = getSlotData(_regs.reg4); } if (_switchLocalDataFar) { _switchLocalDataFar = false; _localData = getSlotData(_regs.reg5); _switchLocalDataNear = true; } if (_switchLocalDataToStack) { _switchLocalDataToStack = false; _localData = _stack + 2; _switchLocalDataNear = true; } byte opcode = readByte(); execOpcode(opcode); // Update the screen at semi-regular intervals, else the mouse // cursor will be jerky. uint32 now = _vm->_system->getMillis(); if (now < lastScreenUpdate || now - lastScreenUpdate > 10) { _vm->_system->updateScreen(); lastScreenUpdate = _vm->_system->getMillis(); } } }
int ScriptInterpreter::runFunction(ScriptFunction *scriptFunction) { bool done = false; int oldLocalStackPtr = _localStackPtr; ScriptFunction *oldRunningFunction = _runningFunction; // TODO: Also initialize _localStackPtr _runningFunction = scriptFunction; _runningFunction->jumpAbsolute(0); while (!done) { byte opcode = _runningFunction->readByte(); done = !execOpcode(opcode); } _localStackPtr = oldLocalStackPtr; _runningFunction = oldRunningFunction; return 0; }