From 14566d5c271da0710fecacc2496a05d85708f70a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Zbr=C3=B3g?= Date: Tue, 10 Dec 2013 00:26:42 +0000 Subject: [PATCH] PRINCE: script code refactored --- engines/prince/prince.cpp | 36 +- engines/prince/prince.h | 4 + engines/prince/script.cpp | 1087 +++++++++++++++++++------------------ engines/prince/script.h | 77 ++- 4 files changed, 627 insertions(+), 577 deletions(-) diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp index 207c60181081..687081d60c0b 100644 --- a/engines/prince/prince.cpp +++ b/engines/prince/prince.cpp @@ -74,10 +74,10 @@ void PrinceEngine::debugEngine(const char *s, ...) { } PrinceEngine::PrinceEngine(OSystem *syst, const PrinceGameDescription *gameDesc) : - Engine(syst), _gameDescription(gameDesc), _graph(NULL), _script(NULL), - _locationNr(0), _debugger(NULL), _midiPlayer(NULL), - _cameraX(0), _newCameraX(0), _frameNr(0), _cursor1(NULL), _cursor2(NULL), _font(NULL), - _walizkaBmp(NULL), _roomBmp(NULL), _cursorNr(0) { + Engine(syst), _gameDescription(gameDesc), _graph(nullptr), _script(nullptr), _interpreter(nullptr), _flags(nullptr), + _locationNr(0), _debugger(nullptr), _midiPlayer(nullptr), + _cameraX(0), _newCameraX(0), _frameNr(0), _cursor1(nullptr), _cursor2(nullptr), _font(nullptr), + _walizkaBmp(nullptr), _roomBmp(nullptr), _cursorNr(0) { // Debug/console setup DebugMan.addDebugChannel(DebugChannel::kScript, "script", "Prince Script debug channel"); @@ -99,6 +99,8 @@ PrinceEngine::~PrinceEngine() { delete _cursor2; delete _midiPlayer; delete _script; + delete _flags; + delete _interpreter; delete _font; delete _roomBmp; delete _walizkaBmp; @@ -153,9 +155,12 @@ void PrinceEngine::init() { _walizkaBmp = new MhwanhDecoder(); Resource::loadResource(_walizkaBmp, "all/walizka"); - _script = new Script(this); + _script = new Script(); Resource::loadResource(_script, "all/skrypt.dat"); + _flags = new InterpreterFlags(); + _interpreter = new Interpreter(this, _script, _flags); + _variaTxt = new VariaTxt(); Resource::loadResource(_variaTxt, "all/variatxt.dat"); @@ -249,8 +254,8 @@ bool PrinceEngine::loadLocation(uint16 locationNr) { _cameraX = 0; _newCameraX = 0; - _script->setFlagValue(Flags::CURRROOM, _locationNr); - _script->stopBg(); + _flags->setFlagValue(Flags::CURRROOM, _locationNr); + _interpreter->stopBg(); changeCursor(0); @@ -290,7 +295,7 @@ bool PrinceEngine::loadLocation(uint16 locationNr) { void PrinceEngine::changeCursor(uint16 curId) { _debugger->_cursorNr = curId; - const Graphics::Surface *curSurface = NULL; + const Graphics::Surface *curSurface = nullptr; uint16 hotspotX = 0; uint16 hotspotY = 0; @@ -353,7 +358,7 @@ void PrinceEngine::playSample(uint16 sampleId, uint16 loopType) { void PrinceEngine::stopSample(uint16 sampleId) { _mixer->stopID(sampleId); - _voiceStream[sampleId] = NULL; + _voiceStream[sampleId] = nullptr; } bool PrinceEngine::loadSample(uint32 sampleSlot, const Common::String &streamName) { @@ -364,12 +369,12 @@ bool PrinceEngine::loadSample(uint32 sampleSlot, const Common::String &streamNam debugEngine("loadSample slot %d, name %s", sampleSlot, normalizedPath.c_str()); _mixer->stopID(sampleSlot); - _voiceStream[sampleSlot] = NULL; + _voiceStream[sampleSlot] = nullptr; _voiceStream[sampleSlot] = SearchMan.createReadStreamForMember(normalizedPath); - if (_voiceStream[sampleSlot] == NULL) { + if (_voiceStream[sampleSlot] == nullptr) { error("Can't load sample %s to slot %d", normalizedPath.c_str(), sampleSlot); } - return _voiceStream[sampleSlot] == NULL; + return _voiceStream[sampleSlot] == nullptr; } bool PrinceEngine::loadVoice(uint32 slot, uint32 sampleSlot, const Common::String &streamName) { @@ -466,7 +471,7 @@ void PrinceEngine::keyHandler(Common::Event event) { scrollCameraRight(32); break; case Common::KEYCODE_ESCAPE: - _script->setFlagValue(Flags::ESCAPED2, 1); + _flags->setFlagValue(Flags::ESCAPED2, 1); break; } } @@ -551,7 +556,7 @@ void PrinceEngine::showTexts() { --text._time; if (text._time == 0) { - text._str = NULL; + text._str = nullptr; } } } @@ -587,7 +592,6 @@ void PrinceEngine::drawScreen() { void PrinceEngine::mainLoop() { - loadLocation(4); changeCursor(0); while (!shouldQuit()) { @@ -622,7 +626,7 @@ void PrinceEngine::mainLoop() { // TODO: Update all structures, animations, naks, heros etc. - _script->step(); + _interpreter->step(); drawScreen(); diff --git a/engines/prince/prince.h b/engines/prince/prince.h index edb4f1999fed..9802769ed9a7 100644 --- a/engines/prince/prince.h +++ b/engines/prince/prince.h @@ -53,6 +53,8 @@ struct PrinceGameDescription; class PrinceEngine; class GraphicsMan; class Script; +class Interpreter; +class InterpreterFlags; class Debugger; class MusicPlayer; class VariaTxt; @@ -162,6 +164,8 @@ class PrinceEngine : public Engine { Debugger *_debugger; GraphicsMan *_graph; Script *_script; + InterpreterFlags *_flags; + Interpreter *_interpreter; Font *_font; MusicPlayer *_midiPlayer; diff --git a/engines/prince/script.cpp b/engines/prince/script.cpp index 3011bc78ee5d..afd4311ea6d4 100644 --- a/engines/prince/script.cpp +++ b/engines/prince/script.cpp @@ -39,41 +39,58 @@ namespace Prince { static const uint16 NUM_OPCODES = 144; -Script::Script(PrinceEngine *vm) : - _code(NULL), _stacktop(0), _vm(vm), _opcodeNF(false), - _waitFlag(0), _result(true) { - memset(_flags, 0, sizeof(_flags)); +Script::Script() : _data(nullptr), _dataSize(0) { } Script::~Script() { - delete[] _code; + delete[] _data; + _dataSize = 0; + _data = nullptr; +} + +bool Script::loadFromStream(Common::SeekableReadStream &stream) { + _dataSize = stream.size(); + if (!_dataSize) + return false; + + _data = new byte[_dataSize]; + + if (!_data) + return false; + + stream.read(_data, _dataSize); + + return true; +} + +InterpreterFlags::InterpreterFlags() { + resetAllFlags(); } -void Script::setFlagValue(Flags::Id flagId, uint16 value) { +void InterpreterFlags::resetAllFlags() { + memset(_flags, 0, sizeof(_flags)); +} + +void InterpreterFlags::setFlagValue(Flags::Id flagId, uint16 value) { _flags[(uint16)flagId - FLAG_MASK] = value; } -uint16 Script::getFlagValue(Flags::Id flagId) { +uint16 InterpreterFlags::getFlagValue(Flags::Id flagId) { return _flags[(uint16)flagId - FLAG_MASK]; } -bool Script::loadFromStream(Common::SeekableReadStream &stream) { - _codeSize = stream.size(); - _code = new byte[_codeSize]; - - if (!_code) - return false; +Interpreter::Interpreter(PrinceEngine *vm, Script *script, InterpreterFlags *flags) : + _vm(vm), _script(script), _flags(flags), + _stacktop(0), _opcodeNF(false), + _waitFlag(0), _result(true) { - stream.read(_code, _codeSize); // Initialize the script _mode = "fg"; - _fgOpcodePC = READ_LE_UINT32(_code + 4); + _fgOpcodePC = _script->getStartGameOffset(); _bgOpcodePC = 0; - - return true; } -void Script::debugScript(const char *s, ...) { +void Interpreter::debugInterpreter(const char *s, ...) { char buf[STRINGBUFLEN]; va_list va; @@ -88,7 +105,7 @@ void Script::debugScript(const char *s, ...) { debug("Prince::Script frame %08ld mode %s %s %s", _vm->_frameNr, _mode, str.c_str(), buf); } -void Script::step() { +void Interpreter::step() { if (_bgOpcodePC) { _mode = "bg"; _bgOpcodePC = step(_bgOpcodePC); @@ -99,14 +116,14 @@ void Script::step() { } } -uint32 Script::step(uint32 opcodePC) { +uint32 Interpreter::step(uint32 opcodePC) { _currentInstruction = opcodePC; while (!_opcodeNF) { _lastInstruction = _currentInstruction; // Get the current opcode - _lastOpcode = readScript16bits(); + _lastOpcode = readScript(); if (_lastOpcode > NUM_OPCODES) error( @@ -126,162 +143,148 @@ uint32 Script::step(uint32 opcodePC) { return _currentInstruction; } -uint8 Script::getCodeByte(uint32 address) { - if (address >= _codeSize) - error("Trying to read a script byte at address 0x%04X, while the " - "script is just 0x%04X bytes long", address, _codeSize); - return _code[address]; -} - -uint8 Script::readScript8bits() { - uint8 data = getCodeByte(_currentInstruction); - _currentInstruction++; +template +T Interpreter::readScript() { + T data = _script->read(_currentInstruction); + _currentInstruction += sizeof(data); return data; } -uint16 Script::readScript16bits() { - uint8 lower = readScript8bits(); - uint8 upper = readScript8bits(); - return lower | (upper << 8); -} - -uint16 Script::readScriptValue() { - uint16 value = readScript16bits(); - if (value & FLAG_MASK) { - return getFlagValue((Flags::Id)value); +uint16 Interpreter::readScriptValue() { + uint16 value = readScript(); + if (value & InterpreterFlags::FLAG_MASK) { + return _flags->getFlagValue((Flags::Id)value); } return value; } -uint32 Script::readScript32bits() { - uint16 lower = readScript16bits(); - uint16 upper = readScript16bits(); - return lower | (upper << 16); +Flags::Id Interpreter::readScriptFlagId() { + return (Flags::Id)readScript(); } -void Script::O_WAITFOREVER() { - debugScript("O_WAITFOREVER"); +void Interpreter::O_WAITFOREVER() { + debugInterpreter("O_WAITFOREVER"); _opcodeNF = 1; _currentInstruction -= 2; } -void Script::O_BLACKPALETTE() { - debugScript("O_BLACKPALETTE"); +void Interpreter::O_BLACKPALETTE() { + debugInterpreter("O_BLACKPALETTE"); } -void Script::O_SETUPPALETTE() { - debugScript("O_SETUPPALETTE"); +void Interpreter::O_SETUPPALETTE() { + debugInterpreter("O_SETUPPALETTE"); } -void Script::O_INITROOM() { +void Interpreter::O_INITROOM() { uint16 roomId = readScriptValue(); - debugScript("O_INITROOM %d", roomId); + debugInterpreter("O_INITROOM %d", roomId); _vm->loadLocation(roomId); _opcodeNF = 1; } -void Script::O_SETSAMPLE() { +void Interpreter::O_SETSAMPLE() { uint16 sampleId = readScriptValue(); - int32 sampleNameOffset = readScript32bits(); - const char * sampleName = (const char *)&_code[_currentInstruction + sampleNameOffset - 4]; - debugScript("O_SETSAMPLE %d %s", sampleId, sampleName); + int32 sampleNameOffset = readScript(); + const char * sampleName = _script->getString(_currentInstruction + sampleNameOffset - 4); + debugInterpreter("O_SETSAMPLE %d %s", sampleId, sampleName); _vm->loadSample(sampleId, sampleName); } -void Script::O_FREESAMPLE() { +void Interpreter::O_FREESAMPLE() { uint16 sample = readScriptValue(); - debugScript("O_FREESAMPLE %d", sample); + debugInterpreter("O_FREESAMPLE %d", sample); } -void Script::O_PLAYSAMPLE() { +void Interpreter::O_PLAYSAMPLE() { uint16 sampleId = readScriptValue(); - uint16 loopType = readScript16bits(); - debugScript("O_PLAYSAMPLE sampleId %d loopType %d", sampleId, loopType); + uint16 loopType = readScript(); + debugInterpreter("O_PLAYSAMPLE sampleId %d loopType %d", sampleId, loopType); _vm->playSample(sampleId, loopType); } -void Script::O_PUTOBJECT() { +void Interpreter::O_PUTOBJECT() { uint16 roomId = readScriptValue(); uint16 slot = readScriptValue(); uint16 objectId = readScriptValue(); - debugScript("O_PUTOBJECT roomId %d, slot %d, objectId %d", roomId, slot, objectId); + debugInterpreter("O_PUTOBJECT roomId %d, slot %d, objectId %d", roomId, slot, objectId); } -void Script::O_REMOBJECT() { +void Interpreter::O_REMOBJECT() { uint16 roomId = readScriptValue(); uint16 objectId = readScriptValue(); - debugScript("O_REMOBJECT roomId %d objectId %d", roomId, objectId); + debugInterpreter("O_REMOBJECT roomId %d objectId %d", roomId, objectId); } -void Script::O_SHOWANIM() { +void Interpreter::O_SHOWANIM() { uint16 slot = readScriptValue(); uint16 animId = readScriptValue(); - debugScript("O_SHOWANIM slot %d, animId %d", slot, animId); + debugInterpreter("O_SHOWANIM slot %d, animId %d", slot, animId); } -void Script::O_CHECKANIMEND() { +void Interpreter::O_CHECKANIMEND() { uint16 slot = readScriptValue(); uint16 frameId = readScriptValue(); - debugScript("O_CHECKANIMEND slot %d, frameId %d", slot, frameId); + debugInterpreter("O_CHECKANIMEND slot %d, frameId %d", slot, frameId); _opcodeNF = 1; } -void Script::O_FREEANIM() { +void Interpreter::O_FREEANIM() { uint16 slot = readScriptValue(); - debugScript("O_FREEANIM slot %d", slot); + debugInterpreter("O_FREEANIM slot %d", slot); } -void Script::O_CHECKANIMFRAME() { +void Interpreter::O_CHECKANIMFRAME() { uint16 slot = readScriptValue(); uint16 frameId = readScriptValue(); - debugScript("O_CHECKANIMFRAME slot %d, frameId %d", slot, frameId); + debugInterpreter("O_CHECKANIMFRAME slot %d, frameId %d", slot, frameId); _opcodeNF = 1; } -void Script::O_PUTBACKANIM() { +void Interpreter::O_PUTBACKANIM() { uint16 roomId = readScriptValue(); uint16 slot = readScriptValue(); - int32 animId = readScript32bits(); - debugScript("O_PUTBACKANIM roomId %d, slot %d, animId %d", roomId, slot, animId); + int32 animId = readScript(); + debugInterpreter("O_PUTBACKANIM roomId %d, slot %d, animId %d", roomId, slot, animId); } -void Script::O_REMBACKANIM() { +void Interpreter::O_REMBACKANIM() { uint16 roomId = readScriptValue(); uint16 slot = readScriptValue(); - debugScript("O_REMBACKANIM roomId %d, slot %d", roomId, slot); + debugInterpreter("O_REMBACKANIM roomId %d, slot %d", roomId, slot); } -void Script::O_CHECKBACKANIMFRAME() { +void Interpreter::O_CHECKBACKANIMFRAME() { uint16 slotId = readScriptValue(); uint16 frameId = readScriptValue(); - debugScript("O_CHECKBACKANIMFRAME slotId %d, frameId %d", slotId, frameId); + debugInterpreter("O_CHECKBACKANIMFRAME slotId %d, frameId %d", slotId, frameId); _opcodeNF = 1; } -void Script::O_FREEALLSAMPLES() { - debugScript("O_FREEALLSAMPLES"); +void Interpreter::O_FREEALLSAMPLES() { + debugInterpreter("O_FREEALLSAMPLES"); } -void Script::O_SETMUSIC() { - uint16 musicId = readScript16bits(); +void Interpreter::O_SETMUSIC() { + uint16 musicId = readScript(); - debugScript("O_SETMUSIC musicId %d", musicId); + debugInterpreter("O_SETMUSIC musicId %d", musicId); } -void Script::O_STOPMUSIC() { - debugScript("O_STOPMUSIC"); +void Interpreter::O_STOPMUSIC() { + debugInterpreter("O_STOPMUSIC"); } -void Script::O__WAIT() { +void Interpreter::O__WAIT() { uint16 pause = readScriptValue(); - debugScript("O__WAIT pause %d", pause); + debugInterpreter("O__WAIT pause %d", pause); if (_waitFlag == 0) { // set new wait flag value and continue @@ -300,398 +303,398 @@ void Script::O__WAIT() { } } -void Script::O_UPDATEOFF() { - debugScript("O_UPDATEOFF"); +void Interpreter::O_UPDATEOFF() { + debugInterpreter("O_UPDATEOFF"); //_updateEnable = false; } -void Script::O_UPDATEON() { - debugScript("O_UPDATEON"); +void Interpreter::O_UPDATEON() { + debugInterpreter("O_UPDATEON"); //_updateEnable = true; } -void Script::O_UPDATE () { - debugScript("O_UPDATE"); +void Interpreter::O_UPDATE () { + debugInterpreter("O_UPDATE"); // Refresh screen } -void Script::O_CLS() { - debugScript("O_CLS"); +void Interpreter::O_CLS() { + debugInterpreter("O_CLS"); // do nothing } -void Script::O__CALL() { - int32 address = readScript32bits(); +void Interpreter::O__CALL() { + int32 address = readScript(); _stack[_stacktop] = _currentInstruction; _stacktop++; _currentInstruction += address - 4; - debugScript("O__CALL 0x%04X", _currentInstruction); + debugInterpreter("O__CALL 0x%04X", _currentInstruction); } -void Script::O_RETURN() { +void Interpreter::O_RETURN() { // Get the return address if (_stacktop > 0) { _stacktop--; _currentInstruction = _stack[_stacktop]; - debugScript("O_RETURN 0x%04X", _currentInstruction); + debugInterpreter("O_RETURN 0x%04X", _currentInstruction); } else { error("Return: Stack is empty"); } } -void Script::O_GO() { - int32 opPC = readScript32bits(); - debugScript("O_GO 0x%04X", opPC); +void Interpreter::O_GO() { + int32 opPC = readScript(); + debugInterpreter("O_GO 0x%04X", opPC); _currentInstruction += opPC - 4; } -void Script::O_BACKANIMUPDATEOFF() { +void Interpreter::O_BACKANIMUPDATEOFF() { uint16 slotId = readScriptValue(); - debugScript("O_BACKANIMUPDATEOFF slotId %d", slotId); + debugInterpreter("O_BACKANIMUPDATEOFF slotId %d", slotId); } -void Script::O_BACKANIMUPDATEON() { +void Interpreter::O_BACKANIMUPDATEON() { uint16 slot = readScriptValue(); - debugScript("O_BACKANIMUPDATEON %d", slot); + debugInterpreter("O_BACKANIMUPDATEON %d", slot); } -void Script::O_CHANGECURSOR() { +void Interpreter::O_CHANGECURSOR() { uint16 cursorId = readScriptValue(); - debugScript("O_CHANGECURSOR %x", cursorId); + debugInterpreter("O_CHANGECURSOR %x", cursorId); _vm->changeCursor(cursorId); } -void Script::O_CHANGEANIMTYPE() { +void Interpreter::O_CHANGEANIMTYPE() { // NOT IMPLEMENTED } -void Script::O__SETFLAG() { +void Interpreter::O__SETFLAG() { Flags::Id flagId = readScriptFlagId(); uint16 value = readScriptValue(); - debugScript("O__SETFLAG 0x%04X (%s) = %d", flagId, Flags::getFlagName(flagId), value); + debugInterpreter("O__SETFLAG 0x%04X (%s) = %d", flagId, Flags::getFlagName(flagId), value); - setFlagValue((Flags::Id)(flagId), value); + _flags->setFlagValue((Flags::Id)(flagId), value); } -void Script::O_COMPARE() { +void Interpreter::O_COMPARE() { Flags::Id flagId = readScriptFlagId(); uint16 value = readScriptValue(); - _result = getFlagValue(flagId) != value; - debugScript("O_COMPARE flagId 0x%04X (%s), value %d == %d (%d)", flagId, Flags::getFlagName(flagId), value, getFlagValue(flagId), _result); + _result = _flags->getFlagValue(flagId) != value; + debugInterpreter("O_COMPARE flagId 0x%04X (%s), value %d == %d (%d)", flagId, Flags::getFlagName(flagId), value, _flags->getFlagValue(flagId), _result); } -void Script::O_JUMPZ() { - int32 offset = readScript32bits(); +void Interpreter::O_JUMPZ() { + int32 offset = readScript(); if (! _result) { _currentInstruction += offset - 4; } - debugScript("O_JUMPZ result = %d, next %08x, offset 0x%08X", _result, _currentInstruction, offset); + debugInterpreter("O_JUMPZ result = %d, next %08x, offset 0x%08X", _result, _currentInstruction, offset); } -void Script::O_JUMPNZ() { - int32 offset = readScript32bits(); +void Interpreter::O_JUMPNZ() { + int32 offset = readScript(); if (_result) { _currentInstruction += offset - 4; } - debugScript("O_JUMPNZ result = %d, next %08x, offset 0x%08X", _result, _currentInstruction, offset); + debugInterpreter("O_JUMPNZ result = %d, next %08x, offset 0x%08X", _result, _currentInstruction, offset); } -void Script::O_EXIT() { +void Interpreter::O_EXIT() { uint16 exitCode = readScriptValue(); - debugScript("O_EXIT exitCode %d", exitCode); + debugInterpreter("O_EXIT exitCode %d", exitCode); // Set exit code and shows credits // if exit code == 0x02EAD } -void Script::O_ADDFLAG() { +void Interpreter::O_ADDFLAG() { Flags::Id flagId = readScriptFlagId(); uint16 value = readScriptValue(); - setFlagValue(flagId, getFlagValue(flagId) + value); - if (getFlagValue(flagId)) + _flags->setFlagValue(flagId, _flags->getFlagValue(flagId) + value); + if (_flags->getFlagValue(flagId)) _result = 1; else _result = 0; - debugScript("O_ADDFLAG flagId %04x (%s), value %d", flagId, Flags::getFlagName(flagId), value); + debugInterpreter("O_ADDFLAG flagId %04x (%s), value %d", flagId, Flags::getFlagName(flagId), value); } -void Script::O_TALKANIM() { +void Interpreter::O_TALKANIM() { uint16 animSlot = readScriptValue(); uint16 slot = readScriptValue(); - debugScript("O_TALKANIM animSlot %d, slot %d", animSlot, slot); + debugInterpreter("O_TALKANIM animSlot %d, slot %d", animSlot, slot); } -void Script::O_SUBFLAG() { +void Interpreter::O_SUBFLAG() { Flags::Id flagId = readScriptFlagId(); uint16 value = readScriptValue(); - setFlagValue(flagId, getFlagValue(flagId) - value); - if (getFlagValue(flagId)) + _flags->setFlagValue(flagId, _flags->getFlagValue(flagId) - value); + if (_flags->getFlagValue(flagId)) _result = 1; else _result = 0; - debugScript("O_SUBFLAG flagId %d, value %d", flagId, value); + debugInterpreter("O_SUBFLAG flagId %d, value %d", flagId, value); } -void Script::O_SETSTRING() { - int32 offset = readScript32bits(); +void Interpreter::O_SETSTRING() { + int32 offset = readScript(); _currentString = offset; // FIXME: Make it better ;) if (offset >= 80000) { - debugScript("GetVaria %s", _vm->_variaTxt->getString(offset - 80000)); + debugInterpreter("GetVaria %s", _vm->_variaTxt->getString(offset - 80000)); } else if (offset < 2000) { uint32 of = READ_LE_UINT32(_vm->_talkTxt+offset*4); const char * txt = (const char *)&_vm->_talkTxt[of]; _string = &_vm->_talkTxt[of]; - debugScript("TalkTxt %d %s", of, txt); + debugInterpreter("TalkTxt %d %s", of, txt); } - debugScript("O_SETSTRING %04d", offset); + debugInterpreter("O_SETSTRING %04d", offset); } -void Script::O_ANDFLAG() { +void Interpreter::O_ANDFLAG() { Flags::Id flagId = readScriptFlagId(); uint16 value = readScriptValue(); - debugScript("O_ANDFLAG flagId %d, value %d", flagId, value); + debugInterpreter("O_ANDFLAG flagId %d, value %d", flagId, value); - setFlagValue(flagId, getFlagValue(flagId) & value); + _flags->setFlagValue(flagId, _flags->getFlagValue(flagId) & value); - if (getFlagValue(flagId)) { + if (_flags->getFlagValue(flagId)) { _result = 1; } else { _result = 0; } } -void Script::O_GETMOBDATA() { +void Interpreter::O_GETMOBDATA() { Flags::Id flagId = readScriptFlagId(); - uint16 mobId = readScript16bits(); - uint16 mobOffset = readScript16bits(); + uint16 mobId = readScript(); + uint16 mobOffset = readScript(); - debugScript("O_GETMOBDATA flagId %d, modId %d, mobOffset %d", flagId, mobId, mobOffset); + debugInterpreter("O_GETMOBDATA flagId %d, modId %d, mobOffset %d", flagId, mobId, mobOffset); } -void Script::O_ORFLAG() { +void Interpreter::O_ORFLAG() { Flags::Id flagId = readScriptFlagId(); uint16 value = readScriptValue(); - debugScript("O_ORFLAG flagId %d, value %d", flagId, value); + debugInterpreter("O_ORFLAG flagId %d, value %d", flagId, value); - setFlagValue(flagId, getFlagValue(flagId) | value); + _flags->setFlagValue(flagId, _flags->getFlagValue(flagId) | value); - if (getFlagValue(flagId)) { + if (_flags->getFlagValue(flagId)) { _result = 1; } else { _result = 0; } } -void Script::O_SETMOBDATA() { +void Interpreter::O_SETMOBDATA() { uint16 mobId = readScriptValue(); uint16 mobOffset = readScriptValue(); uint16 value = readScriptValue(); - debugScript("O_SETMOBDATA mobId %d, mobOffset %d, value %d", mobId, mobOffset, value); + debugInterpreter("O_SETMOBDATA mobId %d, mobOffset %d, value %d", mobId, mobOffset, value); } -void Script::O_XORFLAG() { +void Interpreter::O_XORFLAG() { Flags::Id flagId = readScriptFlagId(); uint16 value = readScriptValue(); - debugScript("O_XORFLAG flagId %d, value %d", flagId, value); + debugInterpreter("O_XORFLAG flagId %d, value %d", flagId, value); - setFlagValue(flagId, getFlagValue(flagId) ^ value); + _flags->setFlagValue(flagId, _flags->getFlagValue(flagId) ^ value); - if (getFlagValue(flagId)) { + if (_flags->getFlagValue(flagId)) { _result = 1; } else { _result = 0; } } -void Script::O_GETMOBTEXT() { +void Interpreter::O_GETMOBTEXT() { uint16 value = readScriptValue(); - debugScript("O_GETMOBTEXT value %d", value); + debugInterpreter("O_GETMOBTEXT value %d", value); // Use Mob::ExamText as current string } -void Script::O_MOVEHERO() { +void Interpreter::O_MOVEHERO() { uint16 heroId = readScriptValue(); uint16 x = readScriptValue(); uint16 y = readScriptValue(); uint16 dir = readScriptValue(); - debugScript("O_MOVEHERO heroId %d, x %d, y %d, dir %d", heroId, x, y, dir); + debugInterpreter("O_MOVEHERO heroId %d, x %d, y %d, dir %d", heroId, x, y, dir); } -void Script::O_WALKHERO() { +void Interpreter::O_WALKHERO() { uint16 heroId = readScriptValue(); - debugScript("O_WALKHERO %d", heroId); + debugInterpreter("O_WALKHERO %d", heroId); _opcodeNF = 1; } -void Script::O_SETHERO() { +void Interpreter::O_SETHERO() { uint16 hero = readScriptValue(); int16 x = readScriptValue(); int16 y = readScriptValue(); uint16 dir = readScriptValue(); - debugScript("O_SETHERO hero %d, x %d, y %d, dir %d", hero, x, y, dir); + debugInterpreter("O_SETHERO hero %d, x %d, y %d, dir %d", hero, x, y, dir); _vm->_mainHero->setPos(x, y); } -void Script::O_HEROOFF() { +void Interpreter::O_HEROOFF() { uint16 heroId = readScriptValue(); - debugScript("O_HEROOFF %d", heroId); + debugInterpreter("O_HEROOFF %d", heroId); _vm->_mainHero->setVisible(false); } -void Script::O_HEROON() { +void Interpreter::O_HEROON() { uint16 heroId = readScriptValue(); - debugScript("O_HEROON %d", heroId); + debugInterpreter("O_HEROON %d", heroId); _vm->_mainHero->setVisible(true); } -void Script::O_CLSTEXT() { +void Interpreter::O_CLSTEXT() { uint16 slot = readScriptValue(); - debugScript("O_CLSTEXT slot %d", slot); + debugInterpreter("O_CLSTEXT slot %d", slot); // Sets text line to null // Sets text timeout to zero } -void Script::O_CALLTABLE() { - uint16 flag = readScript16bits(); - int32 table = readScript32bits(); +void Interpreter::O_CALLTABLE() { + uint16 flag = readScript(); + int32 table = readScript(); - debugScript("O_CALLTABLE flag %d, table %d", flag, table); + debugInterpreter("O_CALLTABLE flag %d, table %d", flag, table); // makes a call from script function table // must read table pointer from _code and // use table entry as next opcode } -void Script::O_CHANGEMOB() { +void Interpreter::O_CHANGEMOB() { uint16 mob = readScriptValue(); uint16 value = readScriptValue(); - debugScript("O_CHANGEMOB mob %d, value %d", mob, value); + debugInterpreter("O_CHANGEMOB mob %d, value %d", mob, value); // Probably sets mobs visible flag to value } -void Script::O_ADDINV() { +void Interpreter::O_ADDINV() { uint16 hero = readScriptValue(); uint16 item = readScriptValue(); - debugScript("O_ADDINV hero %d, item %d", hero, item); + debugInterpreter("O_ADDINV hero %d, item %d", hero, item); } -void Script::O_REMINV() { +void Interpreter::O_REMINV() { uint16 hero = readScriptValue(); uint16 item = readScriptValue(); - debugScript("O_REMINV hero %d, item %d", hero, item); + debugInterpreter("O_REMINV hero %d, item %d", hero, item); } -void Script::O_REPINV() { - uint16 hero = readScript16bits(); - uint16 item1 = readScript16bits(); - uint16 item2 = readScript16bits(); +void Interpreter::O_REPINV() { + uint16 hero = readScript(); + uint16 item1 = readScript(); + uint16 item2 = readScript(); // shouldn't be uses error("O_REPINV hero %d, item1 %d, item2 %d", hero, item1, item2); } -void Script::O_OBSOLETE_GETACTION() { +void Interpreter::O_OBSOLETE_GETACTION() { // shouldn't be uses error("O_OBSOLETE_GETACTION"); } -void Script::O_ADDWALKAREA() { - uint16 x1 = readScript16bits(); - uint16 y1 = readScript16bits(); - uint16 x2 = readScript16bits(); - uint16 y2 = readScript16bits(); +void Interpreter::O_ADDWALKAREA() { + uint16 x1 = readScript(); + uint16 y1 = readScript(); + uint16 x2 = readScript(); + uint16 y2 = readScript(); // shouldn't be uses error("O_ADDWALKAREA x1 %d, y1 %d, x2 %d, y2 %d", x1, y1, x2, y2); } -void Script::O_REMWALKAREA() { - uint16 x1 = readScript16bits(); - uint16 y1 = readScript16bits(); - uint16 x2 = readScript16bits(); - uint16 y2 = readScript16bits(); +void Interpreter::O_REMWALKAREA() { + uint16 x1 = readScript(); + uint16 y1 = readScript(); + uint16 x2 = readScript(); + uint16 y2 = readScript(); // shouldn't be uses error("O_REMWALKAREA x1 %d, y1 %d, x2 %d, y2 %d", x1, y1, x2, y2); } -void Script::O_RESTOREWALKAREA() { - debugScript("O_RESTOREWALKAREA"); +void Interpreter::O_RESTOREWALKAREA() { + debugInterpreter("O_RESTOREWALKAREA"); } -void Script::O_WAITFRAME() { - debugScript("O_WAITFRAME"); +void Interpreter::O_WAITFRAME() { + debugInterpreter("O_WAITFRAME"); _opcodeNF = true; } -void Script::O_SETFRAME() { +void Interpreter::O_SETFRAME() { uint16 anim = readScriptValue(); uint16 frame = readScriptValue(); - debugScript("O_SETFRAME anim %d, frame %d", anim, frame); + debugInterpreter("O_SETFRAME anim %d, frame %d", anim, frame); } -void Script::O_RUNACTION() { +void Interpreter::O_RUNACTION() { // It's empty in original and never used in script // it's better to report error error("O_RUNACTION"); } -void Script::O_COMPAREHI() { +void Interpreter::O_COMPAREHI() { Flags::Id flag = readScriptFlagId(); uint16 value = readScriptValue(); - debugScript("O_COMPAREHI flag %d, value %d", flag, value); - _result = value < getFlagValue(flag); + debugInterpreter("O_COMPAREHI flag %d, value %d", flag, value); + _result = value < _flags->getFlagValue(flag); } -void Script::O_COMPARELO() { +void Interpreter::O_COMPARELO() { Flags::Id flag = readScriptFlagId(); uint16 value = readScriptValue(); - debugScript("O_COMPARELO flag %d, value %d", flag, value); - _result = value > getFlagValue(flag); + debugInterpreter("O_COMPARELO flag %d, value %d", flag, value); + _result = value > _flags->getFlagValue(flag); } -void Script::O_PRELOADSET() { +void Interpreter::O_PRELOADSET() { // not used in script - int32 offset = readScript32bits(); - debugScript("O_PRELOADSET offset %04x", offset); + int32 offset = readScript(); + debugInterpreter("O_PRELOADSET offset %04x", offset); } -void Script::O_FREEPRELOAD() { +void Interpreter::O_FREEPRELOAD() { // not used in script - debugScript("O_FREEPRELOAD"); + debugInterpreter("O_FREEPRELOAD"); } -void Script::O_CHECKINV() { +void Interpreter::O_CHECKINV() { uint16 hero = readScriptValue(); uint16 item = readScriptValue(); - debugScript("O_CHECKINV hero %d, item %d", hero, item); + debugInterpreter("O_CHECKINV hero %d, item %d", hero, item); // checks if item is in heros inventory } -void Script::O_TALKHERO() { +void Interpreter::O_TALKHERO() { uint16 hero = readScriptValue(); - debugScript("O_TALKHERO hero %d", hero); + debugInterpreter("O_TALKHERO hero %d", hero); } -void Script::O_WAITTEXT() { +void Interpreter::O_WAITTEXT() { uint16 slot = readScriptValue(); Text &text = _vm->_textSlots[slot]; if (text._time) { @@ -700,36 +703,36 @@ void Script::O_WAITTEXT() { } } -void Script::O_SETHEROANIM() { +void Interpreter::O_SETHEROANIM() { uint16 hero = readScriptValue(); - int32 offset = readScript32bits(); - debugScript("O_SETHEROANIM hero %d, offset %d", hero, offset); + int32 offset = readScript(); + debugInterpreter("O_SETHEROANIM hero %d, offset %d", hero, offset); } -void Script::O_WAITHEROANIM() { +void Interpreter::O_WAITHEROANIM() { uint16 hero = readScriptValue(); - debugScript("O_WAITHEROANIM hero %d", hero); + debugInterpreter("O_WAITHEROANIM hero %d", hero); } -void Script::O_GETHERODATA() { - uint16 flag = readScript16bits(); +void Interpreter::O_GETHERODATA() { + uint16 flag = readScript(); uint16 hero = readScriptValue(); uint16 heroOffset = readScriptValue(); - debugScript("O_GETHERODATA flag %d, hero %d, heroOffset %d", flag, hero, heroOffset); + debugInterpreter("O_GETHERODATA flag %d, hero %d, heroOffset %d", flag, hero, heroOffset); } -void Script::O_GETMOUSEBUTTON() { - debugScript("O_GETMOUSEBUTTON"); +void Interpreter::O_GETMOUSEBUTTON() { + debugInterpreter("O_GETMOUSEBUTTON"); } -void Script::O_CHANGEFRAMES() { +void Interpreter::O_CHANGEFRAMES() { uint16 anim = readScriptValue(); uint16 frame = readScriptValue(); uint16 lastFrame = readScriptValue(); uint16 loopFrame = readScriptValue(); - debugScript( + debugInterpreter( "O_CHANGFRAMES anim %d, fr1 %d, fr2 %d, fr3 %d", anim, frame, @@ -738,13 +741,13 @@ void Script::O_CHANGEFRAMES() { } -void Script::O_CHANGEBACKFRAMES() { +void Interpreter::O_CHANGEBACKFRAMES() { uint16 anim = readScriptValue(); uint16 frame = readScriptValue(); uint16 lastFrame = readScriptValue(); uint16 loopFrame = readScriptValue(); - debugScript( + debugInterpreter( "O_CHANGEBACKFRAMES anim %d, fr1 %d, fr2 %d, fr3 %d", anim, frame, @@ -752,94 +755,94 @@ void Script::O_CHANGEBACKFRAMES() { loopFrame); } -void Script::O_GETBACKANIMDATA() { - uint16 flag = readScript16bits(); - uint16 anim = readScript16bits(); - uint16 animOffset = readScript16bits(); - debugScript("O_GETBACKANIMDATA flag %d, anim %d, animOffset %d", flag, anim, animOffset); +void Interpreter::O_GETBACKANIMDATA() { + uint16 flag = readScript(); + uint16 anim = readScript(); + uint16 animOffset = readScript(); + debugInterpreter("O_GETBACKANIMDATA flag %d, anim %d, animOffset %d", flag, anim, animOffset); } -void Script::O_GETANIMDATA() { - uint16 flag = readScript16bits(); +void Interpreter::O_GETANIMDATA() { + uint16 flag = readScript(); uint16 anim = readScriptValue(); uint16 animOffset = readScriptValue(); - debugScript("O_GETANIMDATA flag %d, anim %d, animOffset %d", flag, anim, animOffset); + debugInterpreter("O_GETANIMDATA flag %d, anim %d, animOffset %d", flag, anim, animOffset); // Gets value of anim data // use anim offset as attribute id not an offset } -void Script::O_SETBGCODE() { - int32 offset = readScript32bits(); +void Interpreter::O_SETBGCODE() { + int32 offset = readScript(); _bgOpcodePC = _currentInstruction + offset - 4; - debugScript("O_SETBGCODE next %08x, offset %08x", _bgOpcodePC, offset); + debugInterpreter("O_SETBGCODE next %08x, offset %08x", _bgOpcodePC, offset); } -void Script::O_SETBACKFRAME() { +void Interpreter::O_SETBACKFRAME() { uint16 anim = readScriptValue(); uint16 frame = readScriptValue(); - debugScript("O_SETBACKFRAME anim %d, frame %d", anim, frame); + debugInterpreter("O_SETBACKFRAME anim %d, frame %d", anim, frame); } -void Script::O_GETRND() { +void Interpreter::O_GETRND() { Flags::Id flag = readScriptFlagId(); - uint16 rndSeed = readScript16bits(); - debugScript("O_GETRND flag %d, rndSeed %d", flag, rndSeed); + uint16 rndSeed = readScript(); + debugInterpreter("O_GETRND flag %d, rndSeed %d", flag, rndSeed); // puts and random value as flag value // fairly random value ;) - // setFlagValue(flag, 4); + // _flags->setFlagValue(flag, 4); } -void Script::O_TALKBACKANIM() { +void Interpreter::O_TALKBACKANIM() { uint16 animSlot = readScriptValue(); uint16 slot = readScriptValue(); - debugScript("O_TALKBACKANIM animSlot %d, slot %d", animSlot, slot); + debugInterpreter("O_TALKBACKANIM animSlot %d, slot %d", animSlot, slot); } -void Script::O_LOADPATH() { - int32 offset = readScript32bits(); - debugScript("O_LOADPATH offset %d", offset); +void Interpreter::O_LOADPATH() { + int32 offset = readScript(); + debugInterpreter("O_LOADPATH offset %d", offset); // _currentInstruction + offset path file name ptr // free path bitmap // load packet path bitmap and puts in Sala } -void Script::O_GETCHAR() { +void Interpreter::O_GETCHAR() { Flags::Id flagId = readScriptFlagId(); - setFlagValue(flagId, *_string); + _flags->setFlagValue(flagId, *_string); - debugScript( + debugInterpreter( "O_GETCHAR %04X (%s) %02x", flagId, Flags::getFlagName(flagId), - getFlagValue(flagId)); + _flags->getFlagValue(flagId)); ++_string; } -void Script::O_SETDFLAG() { - uint16 flag = readScript16bits(); - int32 offset = readScript32bits(); - debugScript("O_SETDFLAG flag %d, offset %04x", flag, offset); +void Interpreter::O_SETDFLAG() { + uint16 flag = readScript(); + int32 offset = readScript(); + debugInterpreter("O_SETDFLAG flag %d, offset %04x", flag, offset); // run this through debugger looks strange // it looks like this one store two 16 bit value in one go } -void Script::O_CALLDFLAG() { - uint16 flag = readScript16bits(); - debugScript("O_CALLDFLAG flag %d", flag); +void Interpreter::O_CALLDFLAG() { + uint16 flag = readScript(); + debugInterpreter("O_CALLDFLAG flag %d", flag); // it seems that some flags are 32 bit long } -void Script::O_PRINTAT() { +void Interpreter::O_PRINTAT() { uint16 slot = readScriptValue(); uint16 fr1 = readScriptValue(); uint16 fr2 = readScriptValue(); - debugScript("O_PRINTAT slot %d, fr1 %d, fr2 %d", slot, fr1, fr2); + debugInterpreter("O_PRINTAT slot %d, fr1 %d, fr2 %d", slot, fr1, fr2); - uint8 color = getFlagValue(Flags::KOLOR); + uint8 color = _flags->getFlagValue(Flags::KOLOR); _vm->printAt(slot, color, (const char *)_string, fr1, fr2); @@ -849,214 +852,214 @@ void Script::O_PRINTAT() { ++_string; } -void Script::O_ZOOMIN() { +void Interpreter::O_ZOOMIN() { uint16 slot = readScriptValue(); - debugScript("O_ZOOMIN slot %04d", slot); + debugInterpreter("O_ZOOMIN slot %04d", slot); } -void Script::O_ZOOMOUT() { +void Interpreter::O_ZOOMOUT() { uint16 slot = readScriptValue(); - debugScript("O_ZOOMOUT slot %d", slot); + debugInterpreter("O_ZOOMOUT slot %d", slot); } -void Script::O_SETSTRINGOFFSET() { - int32 offset = readScript32bits(); - debugScript("O_SETSTRINGOFFSET offset %04x", offset); +void Interpreter::O_SETSTRINGOFFSET() { + int32 offset = readScript(); + debugInterpreter("O_SETSTRINGOFFSET offset %04x", offset); // _currentString = "" // _string = (const char *)_currentInstruction + offset } -void Script::O_GETOBJDATA() { +void Interpreter::O_GETOBJDATA() { Flags::Id flag = readScriptFlagId(); uint16 obj = readScriptValue(); int16 objOffset = readScriptValue(); - debugScript("O_GETOBJDATA flag %d, obj %d, objOffset %d", flag, obj, objOffset); + debugInterpreter("O_GETOBJDATA flag %d, obj %d, objOffset %d", flag, obj, objOffset); } -void Script::O_SETOBJDATA() { +void Interpreter::O_SETOBJDATA() { uint16 obj = readScriptValue(); int16 objOffset = readScriptValue(); uint16 value = readScriptValue(); - debugScript("O_SETOBJDATA obj %d, objOffset %d, value %d", obj, objOffset, value); + debugInterpreter("O_SETOBJDATA obj %d, objOffset %d, value %d", obj, objOffset, value); } -void Script::O_SWAPOBJECTS() { - uint16 obj1 = readScript16bits(); - uint16 obj2 = readScript16bits(); - debugScript("O_SWAPOBJECTS obj1 %d, obj2 %d", obj1, obj2); +void Interpreter::O_SWAPOBJECTS() { + uint16 obj1 = readScript(); + uint16 obj2 = readScript(); + debugInterpreter("O_SWAPOBJECTS obj1 %d, obj2 %d", obj1, obj2); } -void Script::O_CHANGEHEROSET() { +void Interpreter::O_CHANGEHEROSET() { uint16 hero = readScriptValue(); uint16 heroSet = readScriptValue(); - debugScript("O_CHANGEHEROSET hero %d, heroSet %d", hero, heroSet); + debugInterpreter("O_CHANGEHEROSET hero %d, heroSet %d", hero, heroSet); } -void Script::O_ADDSTRING() { +void Interpreter::O_ADDSTRING() { uint16 value = readScriptValue(); - debugScript("O_ADDSTRING value %d", value); + debugInterpreter("O_ADDSTRING value %d", value); // _string += value } -void Script::O_SUBSTRING() { +void Interpreter::O_SUBSTRING() { uint16 value = readScriptValue(); - debugScript("O_SUBSTRING value %d", value); + debugInterpreter("O_SUBSTRING value %d", value); // _string -= value } -void Script::O_INITDIALOG() { - debugScript("O_INITDIALOG"); +void Interpreter::O_INITDIALOG() { + debugInterpreter("O_INITDIALOG"); } -void Script::O_ENABLEDIALOGOPT() { +void Interpreter::O_ENABLEDIALOGOPT() { uint16 opt = readScriptValue(); - debugScript("O_ENABLEDIALOGOPT opt %d", opt); + debugInterpreter("O_ENABLEDIALOGOPT opt %d", opt); } -void Script::O_DISABLEDIALOGOPT() { +void Interpreter::O_DISABLEDIALOGOPT() { uint16 opt = readScriptValue(); - debugScript("O_DISABLEDIALOGOPT opt %d", opt); + debugInterpreter("O_DISABLEDIALOGOPT opt %d", opt); } -void Script::O_SHOWDIALOGBOX() { +void Interpreter::O_SHOWDIALOGBOX() { uint16 box = readScriptValue(); - debugScript("O_SHOWDIALOGBOX box %d", box); + debugInterpreter("O_SHOWDIALOGBOX box %d", box); } -void Script::O_STOPSAMPLE() { +void Interpreter::O_STOPSAMPLE() { uint16 slot = readScriptValue(); - debugScript("O_STOPSAMPLE slot %d", slot); + debugInterpreter("O_STOPSAMPLE slot %d", slot); _vm->stopSample(slot); } -void Script::O_BACKANIMRANGE() { +void Interpreter::O_BACKANIMRANGE() { uint16 slotId = readScriptValue(); - uint16 animId = readScript16bits(); + uint16 animId = readScript(); uint16 low = readScriptValue(); uint16 high = readScriptValue(); if (animId != 0xFFFF) { - if (animId & FLAG_MASK) { - animId = getFlagValue((Flags::Id)animId); + if (animId & InterpreterFlags::FLAG_MASK) { + animId = _flags->getFlagValue((Flags::Id)animId); } } - debugScript("O_BACKANIMRANGE slotId %d, animId %d, low %d, high %d", slotId, animId, low, high); + debugInterpreter("O_BACKANIMRANGE slotId %d, animId %d, low %d, high %d", slotId, animId, low, high); _result = 1; } -void Script::O_CLEARPATH() { - debugScript("O_CLEARPATH"); +void Interpreter::O_CLEARPATH() { + debugInterpreter("O_CLEARPATH"); // Fill Sala with 255 } -void Script::O_SETPATH() { - debugScript("O_SETPATH"); +void Interpreter::O_SETPATH() { + debugInterpreter("O_SETPATH"); // CopyPath } -void Script::O_GETHEROX() { +void Interpreter::O_GETHEROX() { uint16 heroId = readScriptValue(); Flags::Id flagId = readScriptFlagId(); - debugScript("O_GETHEROX heroId %d, flagId %d", heroId, flagId); + debugInterpreter("O_GETHEROX heroId %d, flagId %d", heroId, flagId); } -void Script::O_GETHEROY() { - uint16 heroId = readScript16bits(); +void Interpreter::O_GETHEROY() { + uint16 heroId = readScript(); Flags::Id flagId = readScriptFlagId(); - debugScript("O_GETHEROY heroId %d, flagId %d", heroId, flagId); + debugInterpreter("O_GETHEROY heroId %d, flagId %d", heroId, flagId); } -void Script::O_GETHEROD() { +void Interpreter::O_GETHEROD() { uint16 heroId = readScriptValue(); Flags::Id flagId = readScriptFlagId(); - debugScript("O_GETHEROD heroId %d, flagId %d", heroId, flagId); + debugInterpreter("O_GETHEROD heroId %d, flagId %d", heroId, flagId); } -void Script::O_PUSHSTRING() { - debugScript("O_PUSHSTRING"); +void Interpreter::O_PUSHSTRING() { + debugInterpreter("O_PUSHSTRING"); // push on the stack // _currentString // _dialogData // _string } -void Script::O_POPSTRING() { - debugScript("O_POPSTRING"); +void Interpreter::O_POPSTRING() { + debugInterpreter("O_POPSTRING"); // pop from the stack // _currentString // _dialogData // _string } -void Script::O_SETFGCODE() { - int32 offset = readScript32bits(); +void Interpreter::O_SETFGCODE() { + int32 offset = readScript(); _fgOpcodePC = _currentInstruction + offset - 4; - debugScript("O_SETFGCODE next %08x, offset %08x", _fgOpcodePC, offset); + debugInterpreter("O_SETFGCODE next %08x, offset %08x", _fgOpcodePC, offset); } -void Script::O_STOPHERO() { +void Interpreter::O_STOPHERO() { uint16 heroId = readScriptValue(); - debugScript("O_STOPHERO heroId %d", heroId); + debugInterpreter("O_STOPHERO heroId %d", heroId); // clear move steps for hero } -void Script::O_ANIMUPDATEOFF() { - uint16 slotId = readScript16bits(); - debugScript("O_ANIMUPDATEOFF slotId %d", slotId); +void Interpreter::O_ANIMUPDATEOFF() { + uint16 slotId = readScript(); + debugInterpreter("O_ANIMUPDATEOFF slotId %d", slotId); } -void Script::O_ANIMUPDATEON() { +void Interpreter::O_ANIMUPDATEON() { uint16 slotId = readScriptValue(); - debugScript("O_ANIMUPDATEON slotId %d", slotId); + debugInterpreter("O_ANIMUPDATEON slotId %d", slotId); } -void Script::O_FREECURSOR() { - debugScript("O_FREECURSOR"); +void Interpreter::O_FREECURSOR() { + debugInterpreter("O_FREECURSOR"); // Change cursor to 0 // free inv cursor 1 } -void Script::O_ADDINVQUIET() { +void Interpreter::O_ADDINVQUIET() { uint16 heroId = readScriptValue(); uint16 itemId = readScriptValue(); - debugScript("O_ADDINVQUIET heorId %d, itemId %d", heroId, itemId); + debugInterpreter("O_ADDINVQUIET heorId %d, itemId %d", heroId, itemId); } -void Script::O_RUNHERO() { +void Interpreter::O_RUNHERO() { uint16 heroId = readScriptValue(); uint16 x = readScriptValue(); uint16 y = readScriptValue(); uint16 dir = readScriptValue(); - debugScript("O_RUNHERO heroId %d, x %d, y %d, dir %d", heroId, x, y, dir); + debugInterpreter("O_RUNHERO heroId %d, x %d, y %d, dir %d", heroId, x, y, dir); } -void Script::O_SETBACKANIMDATA() { +void Interpreter::O_SETBACKANIMDATA() { uint16 animId = readScriptValue(); uint16 animOffset = readScriptValue(); uint16 wart = readScriptValue(); - debugScript("O_SETBACKANIMDATA animId %d, animOffset %d, wart %d", animId, animOffset, wart); + debugInterpreter("O_SETBACKANIMDATA animId %d, animOffset %d, wart %d", animId, animOffset, wart); } -void Script::O_VIEWFLC() { +void Interpreter::O_VIEWFLC() { uint16 animNr = readScriptValue(); - debugScript("O_VIEWFLC animNr %d", animNr); + debugInterpreter("O_VIEWFLC animNr %d", animNr); _vm->loadAnim(animNr, false); } -void Script::O_CHECKFLCFRAME() { +void Interpreter::O_CHECKFLCFRAME() { uint16 frameNr = readScriptValue(); - debugScript("O_CHECKFLCFRAME frame number %d", frameNr); + debugInterpreter("O_CHECKFLCFRAME frame number %d", frameNr); const Video::FlicDecoder &flicPlayer = _vm->_flicPlayer; @@ -1068,9 +1071,9 @@ void Script::O_CHECKFLCFRAME() { } } -void Script::O_CHECKFLCEND() { +void Interpreter::O_CHECKFLCEND() { - //debugScript("O_CHECKFLCEND"); + //debugInterpreter("O_CHECKFLCEND"); const Video::FlicDecoder &flicPlayer = _vm->_flicPlayer; @@ -1084,55 +1087,55 @@ void Script::O_CHECKFLCEND() { } } -void Script::O_FREEFLC() { - debugScript("O_FREEFLC"); +void Interpreter::O_FREEFLC() { + debugInterpreter("O_FREEFLC"); } -void Script::O_TALKHEROSTOP() { +void Interpreter::O_TALKHEROSTOP() { uint16 heroId = readScriptValue(); - debugScript("O_TALKHEROSTOP %d", heroId); + debugInterpreter("O_TALKHEROSTOP %d", heroId); } -void Script::O_HEROCOLOR() { +void Interpreter::O_HEROCOLOR() { uint16 heroId = readScriptValue(); uint16 kolorr = readScriptValue(); - debugScript("O_HEROCOLOR heroId %d, kolorr %d", heroId, kolorr); + debugInterpreter("O_HEROCOLOR heroId %d, kolorr %d", heroId, kolorr); } -void Script::O_GRABMAPA() { - debugScript("O_GRABMAPA"); +void Interpreter::O_GRABMAPA() { + debugInterpreter("O_GRABMAPA"); } -void Script::O_ENABLENAK() { +void Interpreter::O_ENABLENAK() { uint16 nakId = readScriptValue(); - debugScript("O_ENABLENAK nakId %d", nakId); + debugInterpreter("O_ENABLENAK nakId %d", nakId); } -void Script::O_DISABLENAK() { +void Interpreter::O_DISABLENAK() { uint16 nakId = readScriptValue(); - debugScript("O_DISABLENAK nakId %d", nakId); + debugInterpreter("O_DISABLENAK nakId %d", nakId); } -void Script::O_GETMOBNAME() { +void Interpreter::O_GETMOBNAME() { uint16 war = readScriptValue(); - debugScript("O_GETMOBNAME war %d", war); + debugInterpreter("O_GETMOBNAME war %d", war); } -void Script::O_SWAPINVENTORY() { +void Interpreter::O_SWAPINVENTORY() { uint16 heroId = readScriptValue(); - debugScript("O_SWAPINVENTORY heroId %d", heroId); + debugInterpreter("O_SWAPINVENTORY heroId %d", heroId); } -void Script::O_CLEARINVENTORY() { +void Interpreter::O_CLEARINVENTORY() { uint16 heroId = readScriptValue(); - debugScript("O_CLEARINVENTORY heroId %d", heroId); + debugInterpreter("O_CLEARINVENTORY heroId %d", heroId); } -void Script::O_SKIPTEXT() { - debugScript("O_SKIPTEXT"); +void Interpreter::O_SKIPTEXT() { + debugInterpreter("O_SKIPTEXT"); } -void Script::SetVoice(uint32 sampleSlot) { +void Interpreter::SetVoice(uint32 sampleSlot) { // TODO: use sample slot uint16 slot = readScriptValue(); _vm->loadVoice( @@ -1141,227 +1144,227 @@ void Script::SetVoice(uint32 sampleSlot) { Common::String::format( "%03d-%02d.WAV", _currentString, - getFlagValue(Flags::VOICE_H_LINE) + _flags->getFlagValue(Flags::VOICE_H_LINE) ) ); } -void Script::O_SETVOICEH() { +void Interpreter::O_SETVOICEH() { static const uint32 VOICE_H_SLOT = 28; SetVoice(VOICE_H_SLOT); } -void Script::O_SETVOICEA() { +void Interpreter::O_SETVOICEA() { static const uint32 VOICE_A_SLOT = 29; SetVoice(VOICE_A_SLOT); } -void Script::O_SETVOICEB() { +void Interpreter::O_SETVOICEB() { static const uint32 VOICE_B_SLOT = 30; SetVoice(VOICE_B_SLOT); } -void Script::O_SETVOICEC() { +void Interpreter::O_SETVOICEC() { static const uint32 VOICE_C_SLOT = 31; SetVoice(VOICE_C_SLOT); } -void Script::O_SETVOICED() { +void Interpreter::O_SETVOICED() { static const uint32 VOICE_D_SLOT = 32; SetVoice(VOICE_D_SLOT); } -void Script::O_VIEWFLCLOOP() { +void Interpreter::O_VIEWFLCLOOP() { uint16 value = readScriptValue(); - debugScript("O_VIEWFLCLOOP animId %d", value); + debugInterpreter("O_VIEWFLCLOOP animId %d", value); _vm->loadAnim(value, true); } -void Script::O_FLCSPEED() { +void Interpreter::O_FLCSPEED() { uint16 speed = readScriptValue(); - debugScript("O_FLCSPEED speed %d", speed); + debugInterpreter("O_FLCSPEED speed %d", speed); } -void Script::O_OPENINVENTORY() { - debugScript("O_OPENINVENTORY"); +void Interpreter::O_OPENINVENTORY() { + debugInterpreter("O_OPENINVENTORY"); _opcodeNF = 1; // _showInventoryFlag = true } -void Script::O_KRZYWA() { - debugScript("O_KRZYWA"); +void Interpreter::O_KRZYWA() { + debugInterpreter("O_KRZYWA"); } -void Script::O_GETKRZYWA() { - debugScript("O_GETKRZYWA"); - // setFlagValue(Flags::TORX1, krzywa[_krzywaIndex++]) - // setFlagValue(Flags::TORY1, krzywa[_krzywaIndex++]) +void Interpreter::O_GETKRZYWA() { + debugInterpreter("O_GETKRZYWA"); + // _flags->setFlagValue(Flags::TORX1, krzywa[_krzywaIndex++]) + // _flags->setFlagValue(Flags::TORY1, krzywa[_krzywaIndex++]) // Check _krzywaIndex } -void Script::O_GETMOB() { +void Interpreter::O_GETMOB() { Flags::Id flagId = readScriptFlagId(); uint16 mx = readScriptValue(); uint16 my = readScriptValue(); - debugScript("O_GETMOB flagId %d, mx %d, my %d", flagId, mx, my); + debugInterpreter("O_GETMOB flagId %d, mx %d, my %d", flagId, mx, my); // check if current mob pos = (mx, my) } -void Script::O_INPUTLINE() { - debugScript("O_INPUTLINE"); -} - - -void Script::O_BREAK_POINT() { - debugScript("O_BREAK_POINT"); -} - -Script::OpcodeFunc Script::_opcodes[NUM_OPCODES] = { - &Script::O_WAITFOREVER, - &Script::O_BLACKPALETTE, - &Script::O_SETUPPALETTE, - &Script::O_INITROOM, - &Script::O_SETSAMPLE, - &Script::O_FREESAMPLE, - &Script::O_PLAYSAMPLE, - &Script::O_PUTOBJECT, - &Script::O_REMOBJECT, - &Script::O_SHOWANIM, - &Script::O_CHECKANIMEND, - &Script::O_FREEANIM, - &Script::O_CHECKANIMFRAME, - &Script::O_PUTBACKANIM, - &Script::O_REMBACKANIM, - &Script::O_CHECKBACKANIMFRAME, - &Script::O_FREEALLSAMPLES, - &Script::O_SETMUSIC, - &Script::O_STOPMUSIC, - &Script::O__WAIT, - &Script::O_UPDATEOFF, - &Script::O_UPDATEON, - &Script::O_UPDATE , - &Script::O_CLS, - &Script::O__CALL, - &Script::O_RETURN, - &Script::O_GO, - &Script::O_BACKANIMUPDATEOFF, - &Script::O_BACKANIMUPDATEON, - &Script::O_CHANGECURSOR, - &Script::O_CHANGEANIMTYPE, - &Script::O__SETFLAG, - &Script::O_COMPARE, - &Script::O_JUMPZ, - &Script::O_JUMPNZ, - &Script::O_EXIT, - &Script::O_ADDFLAG, - &Script::O_TALKANIM, - &Script::O_SUBFLAG, - &Script::O_SETSTRING, - &Script::O_ANDFLAG, - &Script::O_GETMOBDATA, - &Script::O_ORFLAG, - &Script::O_SETMOBDATA, - &Script::O_XORFLAG, - &Script::O_GETMOBTEXT, - &Script::O_MOVEHERO, - &Script::O_WALKHERO, - &Script::O_SETHERO, - &Script::O_HEROOFF, - &Script::O_HEROON, - &Script::O_CLSTEXT, - &Script::O_CALLTABLE, - &Script::O_CHANGEMOB, - &Script::O_ADDINV, - &Script::O_REMINV, - &Script::O_REPINV, - &Script::O_OBSOLETE_GETACTION, - &Script::O_ADDWALKAREA, - &Script::O_REMWALKAREA, - &Script::O_RESTOREWALKAREA, - &Script::O_WAITFRAME, - &Script::O_SETFRAME, - &Script::O_RUNACTION, - &Script::O_COMPAREHI, - &Script::O_COMPARELO, - &Script::O_PRELOADSET, - &Script::O_FREEPRELOAD, - &Script::O_CHECKINV, - &Script::O_TALKHERO, - &Script::O_WAITTEXT, - &Script::O_SETHEROANIM, - &Script::O_WAITHEROANIM, - &Script::O_GETHERODATA, - &Script::O_GETMOUSEBUTTON, - &Script::O_CHANGEFRAMES, - &Script::O_CHANGEBACKFRAMES, - &Script::O_GETBACKANIMDATA, - &Script::O_GETANIMDATA, - &Script::O_SETBGCODE, - &Script::O_SETBACKFRAME, - &Script::O_GETRND, - &Script::O_TALKBACKANIM, - &Script::O_LOADPATH, - &Script::O_GETCHAR, - &Script::O_SETDFLAG, - &Script::O_CALLDFLAG, - &Script::O_PRINTAT, - &Script::O_ZOOMIN, - &Script::O_ZOOMOUT, - &Script::O_SETSTRINGOFFSET, - &Script::O_GETOBJDATA, - &Script::O_SETOBJDATA, - &Script::O_SWAPOBJECTS, - &Script::O_CHANGEHEROSET, - &Script::O_ADDSTRING, - &Script::O_SUBSTRING, - &Script::O_INITDIALOG, - &Script::O_ENABLEDIALOGOPT, - &Script::O_DISABLEDIALOGOPT, - &Script::O_SHOWDIALOGBOX, - &Script::O_STOPSAMPLE, - &Script::O_BACKANIMRANGE, - &Script::O_CLEARPATH, - &Script::O_SETPATH, - &Script::O_GETHEROX, - &Script::O_GETHEROY, - &Script::O_GETHEROD, - &Script::O_PUSHSTRING, - &Script::O_POPSTRING, - &Script::O_SETFGCODE, - &Script::O_STOPHERO, - &Script::O_ANIMUPDATEOFF, - &Script::O_ANIMUPDATEON, - &Script::O_FREECURSOR, - &Script::O_ADDINVQUIET, - &Script::O_RUNHERO, - &Script::O_SETBACKANIMDATA, - &Script::O_VIEWFLC, - &Script::O_CHECKFLCFRAME, - &Script::O_CHECKFLCEND, - &Script::O_FREEFLC, - &Script::O_TALKHEROSTOP, - &Script::O_HEROCOLOR, - &Script::O_GRABMAPA, - &Script::O_ENABLENAK, - &Script::O_DISABLENAK, - &Script::O_GETMOBNAME, - &Script::O_SWAPINVENTORY, - &Script::O_CLEARINVENTORY, - &Script::O_SKIPTEXT, - &Script::O_SETVOICEH, - &Script::O_SETVOICEA, - &Script::O_SETVOICEB, - &Script::O_SETVOICEC, - &Script::O_VIEWFLCLOOP, - &Script::O_FLCSPEED, - &Script::O_OPENINVENTORY, - &Script::O_KRZYWA, - &Script::O_GETKRZYWA, - &Script::O_GETMOB, - &Script::O_INPUTLINE, - &Script::O_SETVOICED, - &Script::O_BREAK_POINT, +void Interpreter::O_INPUTLINE() { + debugInterpreter("O_INPUTLINE"); +} + + +void Interpreter::O_BREAK_POINT() { + debugInterpreter("O_BREAK_POINT"); +} + +Interpreter::OpcodeFunc Interpreter::_opcodes[NUM_OPCODES] = { + &Interpreter::O_WAITFOREVER, + &Interpreter::O_BLACKPALETTE, + &Interpreter::O_SETUPPALETTE, + &Interpreter::O_INITROOM, + &Interpreter::O_SETSAMPLE, + &Interpreter::O_FREESAMPLE, + &Interpreter::O_PLAYSAMPLE, + &Interpreter::O_PUTOBJECT, + &Interpreter::O_REMOBJECT, + &Interpreter::O_SHOWANIM, + &Interpreter::O_CHECKANIMEND, + &Interpreter::O_FREEANIM, + &Interpreter::O_CHECKANIMFRAME, + &Interpreter::O_PUTBACKANIM, + &Interpreter::O_REMBACKANIM, + &Interpreter::O_CHECKBACKANIMFRAME, + &Interpreter::O_FREEALLSAMPLES, + &Interpreter::O_SETMUSIC, + &Interpreter::O_STOPMUSIC, + &Interpreter::O__WAIT, + &Interpreter::O_UPDATEOFF, + &Interpreter::O_UPDATEON, + &Interpreter::O_UPDATE , + &Interpreter::O_CLS, + &Interpreter::O__CALL, + &Interpreter::O_RETURN, + &Interpreter::O_GO, + &Interpreter::O_BACKANIMUPDATEOFF, + &Interpreter::O_BACKANIMUPDATEON, + &Interpreter::O_CHANGECURSOR, + &Interpreter::O_CHANGEANIMTYPE, + &Interpreter::O__SETFLAG, + &Interpreter::O_COMPARE, + &Interpreter::O_JUMPZ, + &Interpreter::O_JUMPNZ, + &Interpreter::O_EXIT, + &Interpreter::O_ADDFLAG, + &Interpreter::O_TALKANIM, + &Interpreter::O_SUBFLAG, + &Interpreter::O_SETSTRING, + &Interpreter::O_ANDFLAG, + &Interpreter::O_GETMOBDATA, + &Interpreter::O_ORFLAG, + &Interpreter::O_SETMOBDATA, + &Interpreter::O_XORFLAG, + &Interpreter::O_GETMOBTEXT, + &Interpreter::O_MOVEHERO, + &Interpreter::O_WALKHERO, + &Interpreter::O_SETHERO, + &Interpreter::O_HEROOFF, + &Interpreter::O_HEROON, + &Interpreter::O_CLSTEXT, + &Interpreter::O_CALLTABLE, + &Interpreter::O_CHANGEMOB, + &Interpreter::O_ADDINV, + &Interpreter::O_REMINV, + &Interpreter::O_REPINV, + &Interpreter::O_OBSOLETE_GETACTION, + &Interpreter::O_ADDWALKAREA, + &Interpreter::O_REMWALKAREA, + &Interpreter::O_RESTOREWALKAREA, + &Interpreter::O_WAITFRAME, + &Interpreter::O_SETFRAME, + &Interpreter::O_RUNACTION, + &Interpreter::O_COMPAREHI, + &Interpreter::O_COMPARELO, + &Interpreter::O_PRELOADSET, + &Interpreter::O_FREEPRELOAD, + &Interpreter::O_CHECKINV, + &Interpreter::O_TALKHERO, + &Interpreter::O_WAITTEXT, + &Interpreter::O_SETHEROANIM, + &Interpreter::O_WAITHEROANIM, + &Interpreter::O_GETHERODATA, + &Interpreter::O_GETMOUSEBUTTON, + &Interpreter::O_CHANGEFRAMES, + &Interpreter::O_CHANGEBACKFRAMES, + &Interpreter::O_GETBACKANIMDATA, + &Interpreter::O_GETANIMDATA, + &Interpreter::O_SETBGCODE, + &Interpreter::O_SETBACKFRAME, + &Interpreter::O_GETRND, + &Interpreter::O_TALKBACKANIM, + &Interpreter::O_LOADPATH, + &Interpreter::O_GETCHAR, + &Interpreter::O_SETDFLAG, + &Interpreter::O_CALLDFLAG, + &Interpreter::O_PRINTAT, + &Interpreter::O_ZOOMIN, + &Interpreter::O_ZOOMOUT, + &Interpreter::O_SETSTRINGOFFSET, + &Interpreter::O_GETOBJDATA, + &Interpreter::O_SETOBJDATA, + &Interpreter::O_SWAPOBJECTS, + &Interpreter::O_CHANGEHEROSET, + &Interpreter::O_ADDSTRING, + &Interpreter::O_SUBSTRING, + &Interpreter::O_INITDIALOG, + &Interpreter::O_ENABLEDIALOGOPT, + &Interpreter::O_DISABLEDIALOGOPT, + &Interpreter::O_SHOWDIALOGBOX, + &Interpreter::O_STOPSAMPLE, + &Interpreter::O_BACKANIMRANGE, + &Interpreter::O_CLEARPATH, + &Interpreter::O_SETPATH, + &Interpreter::O_GETHEROX, + &Interpreter::O_GETHEROY, + &Interpreter::O_GETHEROD, + &Interpreter::O_PUSHSTRING, + &Interpreter::O_POPSTRING, + &Interpreter::O_SETFGCODE, + &Interpreter::O_STOPHERO, + &Interpreter::O_ANIMUPDATEOFF, + &Interpreter::O_ANIMUPDATEON, + &Interpreter::O_FREECURSOR, + &Interpreter::O_ADDINVQUIET, + &Interpreter::O_RUNHERO, + &Interpreter::O_SETBACKANIMDATA, + &Interpreter::O_VIEWFLC, + &Interpreter::O_CHECKFLCFRAME, + &Interpreter::O_CHECKFLCEND, + &Interpreter::O_FREEFLC, + &Interpreter::O_TALKHEROSTOP, + &Interpreter::O_HEROCOLOR, + &Interpreter::O_GRABMAPA, + &Interpreter::O_ENABLENAK, + &Interpreter::O_DISABLENAK, + &Interpreter::O_GETMOBNAME, + &Interpreter::O_SWAPINVENTORY, + &Interpreter::O_CLEARINVENTORY, + &Interpreter::O_SKIPTEXT, + &Interpreter::O_SETVOICEH, + &Interpreter::O_SETVOICEA, + &Interpreter::O_SETVOICEB, + &Interpreter::O_SETVOICEC, + &Interpreter::O_VIEWFLCLOOP, + &Interpreter::O_FLCSPEED, + &Interpreter::O_OPENINVENTORY, + &Interpreter::O_KRZYWA, + &Interpreter::O_GETKRZYWA, + &Interpreter::O_GETMOB, + &Interpreter::O_INPUTLINE, + &Interpreter::O_SETVOICED, + &Interpreter::O_BREAK_POINT, }; } diff --git a/engines/prince/script.h b/engines/prince/script.h index d9b42baf3932..386951a0c9f5 100644 --- a/engines/prince/script.h +++ b/engines/prince/script.h @@ -24,6 +24,7 @@ #define PRINCE_SCRIPT_H #include "common/random.h" +#include "common/endian.h" #include "audio/mixer.h" @@ -37,25 +38,68 @@ namespace Prince { class PrinceEngine; +namespace Detail { + template T LittleEndianReader(void *data); + template <> inline uint8 LittleEndianReader(void *data) { return *(uint8*)(data); } + template <> inline uint16 LittleEndianReader(void *data) { return READ_LE_UINT16(data); } + template <> inline uint32 LittleEndianReader(void *data) { return READ_LE_UINT32(data); } +} + class Script { public: - Script(PrinceEngine *vm); - virtual ~Script(); + Script(); + ~Script(); bool loadFromStream(Common::SeekableReadStream &stream); - void step(); + template + T read(uint32 address) { + assert((_data + address + sizeof(T)) <= (_data + _dataSize)); + return Detail::LittleEndianReader(&_data[address]); + } + + // Some magic numbers for now, data stored in header + uint32 getRoomTableOffset() { return read(0); } + uint32 getStartGameOffset() { return read(4); } + + const char *getString(uint32 offset) { + return (const char *)(&_data[offset]); + } + +private: + uint8 *_data; + uint32 _dataSize; +}; + +class InterpreterFlags { +public: + InterpreterFlags(); void setFlagValue(Flags::Id flag, uint16 value); uint16 getFlagValue(Flags::Id flag); + void resetAllFlags(); + + static const uint16 FLAG_MASK = 0x8000; + +private: + static const uint16 MAX_FLAGS = 2000; + int16 _flags[MAX_FLAGS]; +}; + +class Interpreter { +public: + Interpreter(PrinceEngine *vm, Script *script, InterpreterFlags *flags); + void stopBg() { _bgOpcodePC = 0; } + void step(); + private: PrinceEngine *_vm; + Script *_script; + InterpreterFlags *_flags; - byte *_code; - uint32 _codeSize; uint32 _currentInstruction; uint32 _bgOpcodePC; @@ -64,13 +108,9 @@ class Script { uint16 _lastOpcode; uint32 _lastInstruction; byte _result; - static const uint16 MAX_FLAGS = 2000; - static const uint16 FLAG_MASK = 0x8000; - int16 _flags[MAX_FLAGS]; - bool _opcodeNF; + bool _opcodeNF; // break interpreter loop - // Stack static const uint32 _STACK_SIZE = 500; uint32 _stack[_STACK_SIZE]; uint8 _stacktop; @@ -83,21 +123,19 @@ class Script { // Helper functions uint32 step(uint32 opcodePC); - void checkPC(uint32 address); - uint8 getCodeByte(uint32 address); - uint8 readScript8bits(); - uint16 readScript16bits(); - uint32 readScript32bits(); - uint16 readScript8or16bits(); + void checkPC(uint32 address); uint16 readScriptValue(); - Flags::Id readScriptFlagId() { return (Flags::Id)readScript16bits(); } + Flags::Id readScriptFlagId(); + + // instantiation not needed here + template T readScript(); - void debugScript(const char *s, ...); + void debugInterpreter(const char *s, ...); void SetVoice(uint32 slot); - typedef void (Script::*OpcodeFunc)(); + typedef void (Interpreter::*OpcodeFunc)(); static OpcodeFunc _opcodes[]; // Keep opcode handlers names as they are in original code @@ -246,6 +284,7 @@ class Script { void O_INPUTLINE(); void O_SETVOICED(); void O_BREAK_POINT(); + }; }