diff options
author | Walter van Niftrik | 2017-08-10 13:15:26 +0200 |
---|---|---|
committer | Walter van Niftrik | 2019-07-17 08:41:34 +0200 |
commit | f4f4d6119f4db550bcf7201788fd92adfa1915d0 (patch) | |
tree | 7f5e7160c519154b96841ef66e52591e7f371e4d /engines/adl | |
parent | 39e4fdb98c27f97ffffcfba8b6579697a4c809d2 (diff) | |
download | scummvm-rg350-f4f4d6119f4db550bcf7201788fd92adfa1915d0.tar.gz scummvm-rg350-f4f4d6119f4db550bcf7201788fd92adfa1915d0.tar.bz2 scummvm-rg350-f4f4d6119f4db550bcf7201788fd92adfa1915d0.zip |
ADL: Remove opcode counts from script interface
Diffstat (limited to 'engines/adl')
-rw-r--r-- | engines/adl/adl.cpp | 67 | ||||
-rw-r--r-- | engines/adl/adl.h | 18 |
2 files changed, 63 insertions, 22 deletions
diff --git a/engines/adl/adl.cpp b/engines/adl/adl.cpp index f8d61e563d..2379ecdb8f 100644 --- a/engines/adl/adl.cpp +++ b/engines/adl/adl.cpp @@ -44,6 +44,33 @@ namespace Adl { +class ScriptEnv_6502 : public ScriptEnv { +public: + ScriptEnv_6502(const Command &cmd, byte room, byte verb, byte noun) : + ScriptEnv(cmd, room, verb, noun), + _remCond(cmd.numCond), + _remAct(cmd.numAct) { } + +private: + kOpType getOpType() const { + if (_remCond > 0) + return kOpTypeCond; + if (_remAct > 0) + return kOpTypeAct; + return kOpTypeDone; + } + + void next(uint numArgs) { + _ip += numArgs + 1; + if (_remCond > 0) + --_remCond; + else if (_remAct > 0) + --_remAct; + } + + byte _remCond, _remAct; +}; + AdlEngine::~AdlEngine() { delete _display; delete _graphics; @@ -404,8 +431,8 @@ bool AdlEngine::isInputValid(const Commands &commands, byte verb, byte noun, boo is_any = false; for (cmd = commands.begin(); cmd != commands.end(); ++cmd) { - ScriptEnv env(*cmd, _state.room, verb, noun); - if (matchCommand(env)) { + Common::ScopedPtr<ScriptEnv> env(createScriptEnv(*cmd, _state.room, verb, noun)); + if (matchCommand(*env)) { if (cmd->verb == IDI_ANY || cmd->noun == IDI_ANY) is_any = true; return true; @@ -961,15 +988,15 @@ bool AdlEngine::canSaveGameStateCurrently() { // "SAVE GAME". This prevents saving via the GMM in situations where // it wouldn't otherwise be possible to do so. for (cmd = _roomData.commands.begin(); cmd != _roomData.commands.end(); ++cmd) { - ScriptEnv env(*cmd, _state.room, _saveVerb, _saveNoun); - if (matchCommand(env)) - return env.op() == IDO_ACT_SAVE; + Common::ScopedPtr<ScriptEnv> env(createScriptEnv(*cmd, _state.room, _saveVerb, _saveNoun)); + if (matchCommand(*env)) + return env->op() == IDO_ACT_SAVE; } for (cmd = _roomCommands.begin(); cmd != _roomCommands.end(); ++cmd) { - ScriptEnv env(*cmd, _state.room, _saveVerb, _saveNoun); - if (matchCommand(env)) - return env.op() == IDO_ACT_SAVE; + Common::ScopedPtr<ScriptEnv> env(createScriptEnv(*cmd, _state.room, _saveVerb, _saveNoun)); + if (matchCommand(*env)) + return env->op() == IDO_ACT_SAVE; } return false; @@ -1346,7 +1373,7 @@ bool AdlEngine::matchCommand(ScriptEnv &env) const { (void)op_debug("\t&& SAID(%s, %s)", verbStr(env.getCommand().verb).c_str(), nounStr(env.getCommand().noun).c_str()); } - for (uint i = 0; i < env.getCondCount(); ++i) { + while (env.getOpType() == ScriptEnv::kOpTypeCond) { byte op = env.op(); if (op >= _condOpcodes.size() || !_condOpcodes[op] || !_condOpcodes[op]->isValid()) @@ -1360,7 +1387,7 @@ bool AdlEngine::matchCommand(ScriptEnv &env) const { return false; } - env.skip(numArgs + 1); + env.next(numArgs); } return true; @@ -1370,7 +1397,7 @@ void AdlEngine::doActions(ScriptEnv &env) { if (DebugMan.isDebugChannelEnabled(kDebugChannelScript)) (void)op_debug("THEN"); - for (uint i = 0; i < env.getActCount(); ++i) { + while (env.getOpType() == ScriptEnv::kOpTypeAct) { byte op = env.op(); if (op >= _actOpcodes.size() || !_actOpcodes[op] || !_actOpcodes[op]->isValid()) @@ -1384,7 +1411,7 @@ void AdlEngine::doActions(ScriptEnv &env) { return; } - env.skip(numArgs + 1); + env.next(numArgs); } if (DebugMan.isDebugChannelEnabled(kDebugChannelScript)) @@ -1395,9 +1422,9 @@ bool AdlEngine::doOneCommand(const Commands &commands, byte verb, byte noun) { Commands::const_iterator cmd; for (cmd = commands.begin(); cmd != commands.end(); ++cmd) { - ScriptEnv env(*cmd, _state.room, verb, noun); - if (matchCommand(env)) { - doActions(env); + Common::ScopedPtr<ScriptEnv> env(createScriptEnv(*cmd, _state.room, verb, noun)); + if (matchCommand(*env)) { + doActions(*env); return true; } @@ -1414,9 +1441,9 @@ void AdlEngine::doAllCommands(const Commands &commands, byte verb, byte noun) { Commands::const_iterator cmd; for (cmd = commands.begin(); cmd != commands.end(); ++cmd) { - ScriptEnv env(*cmd, _state.room, verb, noun); - if (matchCommand(env)) { - doActions(env); + Common::ScopedPtr<ScriptEnv> env(createScriptEnv(*cmd, _state.room, verb, noun)); + if (matchCommand(*env)) { + doActions(*env); // The original long jumps on restart, so we need to abort here if (_isRestarting) return; @@ -1429,6 +1456,10 @@ void AdlEngine::doAllCommands(const Commands &commands, byte verb, byte noun) { } } +ScriptEnv *AdlEngine::createScriptEnv(const Command &cmd, byte room, byte verb, byte noun) { + return new ScriptEnv_6502(cmd, room, verb, noun); +} + Common::String AdlEngine::toAscii(const Common::String &str) { Common::String ascii = Console::toAscii(str); if (ascii.lastChar() == '\r') diff --git a/engines/adl/adl.h b/engines/adl/adl.h index b7a2ff583f..7ab21d9bec 100644 --- a/engines/adl/adl.h +++ b/engines/adl/adl.h @@ -117,10 +117,19 @@ public: ScriptEnv(const Command &cmd, byte room, byte verb, byte noun) : _cmd(cmd), _room(room), _verb(verb), _noun(noun), _ip(0) { } + virtual ~ScriptEnv() { } + + enum kOpType { + kOpTypeDone, + kOpTypeCond, + kOpTypeAct + }; + byte op() const { return _cmd.script[_ip]; } + virtual kOpType getOpType() const = 0; // We keep this 1-based for easier comparison with the original engine byte arg(uint i) const { return _cmd.script[_ip + i]; } - void skip(uint i) { _ip += i; } + virtual void next(uint numArgs) = 0; bool isMatch() const { return (_cmd.room == IDI_ANY || _cmd.room == _room) && @@ -128,15 +137,15 @@ public: (_cmd.noun == IDI_ANY || _cmd.noun == _noun); } - byte getCondCount() const { return _cmd.numCond; } - byte getActCount() const { return _cmd.numAct; } byte getNoun() const { return _noun; } const Command &getCommand() const { return _cmd; } +protected: + byte _ip; + private: const Command &_cmd; const byte _room, _verb, _noun; - byte _ip; }; enum { @@ -353,6 +362,7 @@ protected: void doActions(ScriptEnv &env); bool doOneCommand(const Commands &commands, byte verb, byte noun); void doAllCommands(const Commands &commands, byte verb, byte noun); + virtual ScriptEnv *createScriptEnv(const Command &cmd, byte room, byte verb, byte noun); // Debug functions static Common::String toAscii(const Common::String &str); |