From 9b052d0a973971a50b4f0df918489e0fc6dd9fdb Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 18 Jun 2016 00:27:35 +0200 Subject: MACVENTURE: Add untested script engine --- engines/macventure/script.cpp | 174 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 engines/macventure/script.cpp (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp new file mode 100644 index 0000000000..7e594f5a11 --- /dev/null +++ b/engines/macventure/script.cpp @@ -0,0 +1,174 @@ +/* ScummVM - Graphic Adventure Engine +* +* ScummVM is the legal property of its developers, whose names +* are too numerous to list here. Please refer to the COPYRIGHT +* file distributed with this source distribution. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. + +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. + +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +* +*/ + +#include "macventure/macventure.h" +#include "macventure/script.h" +#include "macventure/world.h" +#include "macventure/container.h" + +namespace MacVenture { + +ScriptEngine::ScriptEngine(World * world) { + _world = world; + _scripts = new Container("Shadowgate II/Shadow Filter"); +} + +ScriptEngine::~ScriptEngine() { + if (_scripts) + delete _scripts; +} + +bool ScriptEngine::runControl(ControlAction action, ObjID source, ObjID destination, Common::Point delta) { + //debug(7, "SCRIPT: Running control %d from obj %d into obj %d, at delta (%d, %d)", + // action, source, destination, delta.x, delta.y); + + EngineFrame frame; + frame.action = action; + frame.src = source; + frame.dest = destination; + frame.x = delta.x; + frame.y = delta.y; + frame.haltedInSaves = false; + frame.haltedInFirst = false; + frame.haltedInFamily = false; + _frames.push_back(frame); + debug(7, "SCRIPT: Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)", + _frames.size() - 1, frame.action, frame.src, frame.dest, frame.x, frame.y); + + return resume(true); +} + +bool ScriptEngine::resume(bool execAll) { + debug(7, "SCRIPT: Resume"); + while (_frames.size()) { + bool fail = execFrame(execAll); + if (fail) return true; + } + return false; +} + +void ScriptEngine::reset() { + _frames.clear(); +} + +bool ScriptEngine::execFrame(bool execAll) { + bool doFirst = execAll; + bool doFamily = false; + bool fail; + + EngineFrame *frame = &_frames.front(); + + // Do first dispatch script (script 0) + if (frame->haltedInFirst || doFirst) { // We were stuck or it's the first time + frame->haltedInFirst = false; + if (doFirst) { fail = loadScript(frame, 0); } + else { fail = resumeFunc(frame); } + if (fail) { + frame->haltedInFirst = true; + return true; + } + doFamily = true; + frame->familyIdx = 0; + } + + // Do scripts in the family of player (ObjID 1) + if (frame->haltedInFamily || doFamily) { // We have to do the family or we were stuck here + frame->haltedInFamily = false; + Common::Array family = _world->getFamily(_world->getObjAttr(1, kAttrParentObject), false); + uint32 i = frame->familyIdx; + for (; i < family.size(); i++) { + if (doFamily) { fail = loadScript(frame, family[i]); } + else { fail = resumeFunc(frame); } + if (fail) { // We are stuck, so we don't shift the frame + frame->haltedInFamily = true; + frame->familyIdx = i; + return true; + } + doFamily = true; + } + } + + //Handle saves + /* + + uint highest; + uint high; + if (frame->haltedInSaves) { + frame->haltedInSaves = false; + } + + + do { + highest = 0; + for (uint i = 0; i < frame->haltedInSaves.size) + } + */ + + _frames.remove_at(0); + return false; +} + +bool ScriptEngine::loadScript(EngineFrame * frame, uint32 scriptID) { + frame->scripts.push_back(ScriptAsset(scriptID, _scripts)); + return false; +} + +bool ScriptEngine::resumeFunc(EngineFrame * frame) { + bool fail = runFunc(); + if (fail) return fail; + frame->scripts.remove_at(0); + if (frame->scripts.size()) + return resumeFunc(frame); + return false; +} + +bool ScriptEngine::runFunc() { + debug(7, "SCRIPT: I'm running the function"); + return false; +} + +ScriptAsset::ScriptAsset(ObjID id, Container * container) { + _id = id; + _container = container; + _ip = 0x0; +} + +void ScriptAsset::reset() { + _ip = 0x0; +} + +uint8 ScriptAsset::fecth() { + uint8 ins = _instructions[_ip]; + _ip++; + return ins; +} + +void ScriptAsset::loadInstructions() { + uint32 amount = _container->getItemByteSize(_id); + Common::SeekableReadStream *res = _container->getItem(_id); + for (uint i = 0; i < amount; i++) { + _instructions.push_back(res->readByte()); + } + debug(7, "SCRIPT: Load %d instructions for script %d", amount, _id); +} + +} // End of namespace MacVenture \ No newline at end of file -- cgit v1.2.3 From 96f9910c79849c980a09ff733f4710ba9d414dc9 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 18 Jun 2016 23:14:17 +0200 Subject: MACVENTURE: Add opcodes for script engine --- engines/macventure/script.cpp | 994 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 990 insertions(+), 4 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 7e594f5a11..b0d5ef0011 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -20,6 +20,8 @@ * */ +#include "common/system.h" + #include "macventure/macventure.h" #include "macventure/script.h" #include "macventure/world.h" @@ -27,7 +29,8 @@ namespace MacVenture { -ScriptEngine::ScriptEngine(World * world) { +ScriptEngine::ScriptEngine(MacVentureEngine * engine, World * world) { + _engine = engine; _world = world; _scripts = new Container("Shadowgate II/Shadow Filter"); } @@ -133,7 +136,7 @@ bool ScriptEngine::loadScript(EngineFrame * frame, uint32 scriptID) { } bool ScriptEngine::resumeFunc(EngineFrame * frame) { - bool fail = runFunc(); + bool fail = runFunc(frame); if (fail) return fail; frame->scripts.remove_at(0); if (frame->scripts.size()) @@ -141,11 +144,986 @@ bool ScriptEngine::resumeFunc(EngineFrame * frame) { return false; } -bool ScriptEngine::runFunc() { +bool ScriptEngine::runFunc(EngineFrame *frame) { debug(7, "SCRIPT: I'm running the function"); + ScriptAsset &script = frame->scripts.front(); + EngineState *state = &frame->state; + byte op; + while (script.hasNext()) { + op = script.fetch(); + if (!(op & 0x80)) { + state->push(op); + } else { + switch (op) { + case 0x80: //get attribute + op80GATT(state, frame); + break; + case 0x81: //set attribute + op81SATT(state, frame); + break; + case 0x82: //sum children attribute + op82SUCH(state, frame); + break; + case 0x83: //push selected control + op83PUCT(state, frame); + break; + case 0x84: //push selected object + op84PUOB(state, frame); + break; + case 0x85: //push target + op85PUTA(state, frame); + break; + case 0x86: //push deltax + op86PUDX(state, frame); + break; + case 0x87: //push deltay + op87PUDY(state, frame); + break; + case 0x88: //push immediate.b + op88PUIB(state, frame, &script); + break; + case 0x89: //push immediate + op89PUI(state, frame, &script); + break; + case 0x8a: //get global + op8aGGLO(state, frame); + break; + case 0x8b: //set global + op8bSGLO(state, frame); + break; + case 0x8c: //random + op8cRAND(state, frame); + break; + case 0x8d: //copy + op8dCOPY(state, frame); + break; + case 0x8e: //copyn + op8eCOPYN(state, frame); + break; + case 0x8f: //swap + op8fSWAP(state, frame); + break; + case 0x90: //swapn + op90SWAPN(state, frame); + break; + case 0x91: //pop + op91POP(state, frame); + break; + case 0x92: //copy+1 + op92COPYP(state, frame); + break; + case 0x93: //copy+n + op93COPYPN(state, frame); + break; + case 0x94: //shuffle + op94SHUFF(state, frame); + break; + case 0x95: //sort + op95SORT(state, frame); + break; + case 0x96: //clear stack + op96CLEAR(state, frame); + break; + case 0x97: //get stack size + op97SIZE(state, frame); + break; + case 0x98: //add + op98ADD(state, frame); + break; + case 0x99: //subtract + op99SUB(state, frame); + break; + case 0x9a: //multiply + op9aMUL(state, frame); + break; + case 0x9b: //divide + op9bDIV(state, frame); + break; + case 0x9c: //mod + op9cMOD(state, frame); + break; + case 0x9d: //divmod + op9dDMOD(state, frame); + break; + case 0x9e: //abs + op9eABS(state, frame); + break; + case 0x9f: //neg + op9fNEG(state, frame); + break; + case 0xa0: //and + opa0AND(state, frame); + break; + case 0xa1: //or + opa1OR(state, frame); + break; + case 0xa2: //xor + opa2XOR(state, frame); + break; + case 0xa3: //not + opa3NOT(state, frame); + break; + case 0xa4: //logical and + opa4LAND(state, frame); + break; + case 0xa5: //logical or + opa5LOR(state, frame); + break; + case 0xa6: //logical xor + opa6LXOR(state, frame); + break; + case 0xa7: //logical not + opa7LNOT(state, frame); + break; + case 0xa8: //gt? unsigned + opa8GTU(state, frame); + break; + case 0xa9: //lt? unsigned + opa9LTU(state, frame); + break; + case 0xaa: //gt? signed + opaaGTS(state, frame); + break; + case 0xab: //lt? signed + opabLTS(state, frame); + break; + case 0xac: //eq? + opacEQ(state, frame); + break; + case 0xad: //eq string? + opadEQS(state, frame); + break; + case 0xae: //contains + opaeCONT(state, frame); + break; + case 0xaf: //contains word + opafCONTW(state, frame); + break; + case 0xb0: //bra + opb0BRA(state, frame, &script); + break; + case 0xb1: //bra.b + opb1BRAB(state, frame, &script); + break; + case 0xb2: //beq + opb2BEQ(state, frame, &script); + break; + case 0xb3: //beq.b + opb3BEQB(state, frame, &script); + break; + case 0xb4: //bne + opb4BNE(state, frame, &script); + break; + case 0xb5: //bne.b + opb5BNEB(state, frame, &script); + break; + case 0xb6: //call later + opb6CLAT(state, frame); + break; + case 0xb7: //cancel call + opb7CCA(state, frame); + break; + case 0xb8: //cancel low priority + opb8CLOW(state, frame); + break; + case 0xb9: //cancel high priority + opb9CHI(state, frame); + break; + case 0xba: //cancel priority range + opbaCRAN(state, frame); + break; + case 0xbb: //fork + opbbFORK(state, frame); + break; + case 0xbc: //call + opbcCALL(state, frame, &script); + break; + case 0xbd: //focus object + opbdFOOB(state, frame); + break; + case 0xbe: //swap objects + opbeSWOB(state, frame); + break; + case 0xbf: //snap object + opbfSNOB(state, frame); + break; + case 0xc0: //toggle exits + opc0TEXI(state, frame); + break; + case 0xc1: //print text + opc1PTXT(state, frame); + break; + case 0xc2: //print newline + opc2PNEW(state, frame); + break; + case 0xc3: //print text+nl + opc3PTNE(state, frame); + break; + case 0xc4: //print nl+text+nl + opc4PNTN(state, frame); + break; + case 0xc5: //print number + opc5PNUM(state, frame); + break; + case 0xc6: //push 2 + opc6P2(state, frame); + break; + case 0xc7: //play sound in background + opc7PLBG(state, frame); + break; + case 0xc8: //play sound and wait + opc8PLAW(state, frame); + break; + case 0xc9: //wait for sound to finish? + opc9WAIT(state, frame); + break; + case 0xca: //get current time + opcaTIME(state, frame); + break; + case 0xcb: //get current day + opcbDAY(state, frame); + break; + case 0xcc: //get children + opccCHLD(state, frame); + break; + case 0xcd: //get num children + opcdNCHLD(state, frame); + break; + case 0xce: //get engine version + opceVERS(state, frame); + break; + case 0xcf: //push scenario number + opcfPSCE(state, frame); + break; + case 0xd0: //push 1 + opd0P1(state, frame); + break; + case 0xd1: //get object dimensions + opd1GOBD(state, frame); + break; + case 0xd2: //get overlap percent + opd2GOVP(state, frame); + break; + case 0xd3: //capture children + opd3CAPC(state, frame); + break; + case 0xd4: //release children + opd4RELC(state, frame); + break; + case 0xd5: //show speech dialog + opd5DLOG(state, frame); + return true; + case 0xd6: //activate command + opd6ACMD(state, frame); + break; + case 0xd7: //lose game + opd7LOSE(state, frame); + break; + case 0xd8: //win game + opd8WIN(state, frame); + break; + case 0xd9: //sleep + opd9SLEEP(state, frame); + return true; + case 0xda: //click to continue + opdaCLICK(state, frame); + return true; + case 0xdb: //run queue + opdbROBQ(state, frame); + break; + case 0xdc: //run sound queue + opdcRSQ(state, frame); + break; + case 0xdd: //run text queue + opddRTQ(state, frame); + break; + case 0xde: //update screen + opdeUPSC(state, frame); + break; + case 0xdf: //flash main window + opdfFMAI(state, frame); + return true; + case 0xe0: //cache graphic and object + ope0CHGR(state, frame); + break; + case 0xe1: //cache sound + ope1CHSO(state, frame); + break; + case 0xe2: //muldiv + ope2MDIV(state, frame); + break; + case 0xe3: //update object + ope3UPOB(state, frame); + break; + case 0xe4: //currently playing event? + ope4PLEV(state, frame); + break; + case 0xe5: //wait for event to finish + ope5WEV(state, frame); + break; + case 0xe6: //get fibonacci (joke) + ope6GFIB(state, frame); + break; + case 0xe7: //calc fibonacci + ope7CFIB(state, frame); + break; + default: + op00NOOP(op); + } + } + } return false; } +word ScriptEngine::neg16(word val) { + if (val & 0x8000) + val = -((val ^ 0xFFFF) + 1); + return val; +} + +word ScriptEngine::neg8(word val) { + if (val & 0x80) + val = -((val ^ 0xff) + 1); + return val; +} + +word ScriptEngine::sumChildrenAttr(word obj, word attr, bool recursive) { + word sum = 0; + Common::Array children = _world->getChildren(obj, recursive); + for (Common::Array::const_iterator it = children.begin(); it != children.end(); it++) { + sum += _world->getObjAttr(*it, attr); + } + return sum; +} + +void MacVenture::ScriptEngine::op80GATT(EngineState * state, EngineFrame * frame) { + word obj = state->pop(); + word attr = state->pop(); + state->push(_world->getObjAttr(obj, attr)); +} + +void ScriptEngine::op81SATT(EngineState * state, EngineFrame * frame) { + word obj = state->pop(); + word attr = state->pop(); + word val = neg16(state->pop()); + _world->setObjAttr(obj, attr, val); +} + +void ScriptEngine::op82SUCH(EngineState * state, EngineFrame * frame) { + word obj = state->pop(); + word attr = state->pop(); + word recursive = neg16(state->pop()); + state->push(sumChildrenAttr(obj, attr, recursive)); +} + +void ScriptEngine::op83PUCT(EngineState * state, EngineFrame * frame) { + state->push(frame->action); +} + +void ScriptEngine::op84PUOB(EngineState * state, EngineFrame * frame) { + state->push(frame->src); +} + +void ScriptEngine::op85PUTA(EngineState * state, EngineFrame * frame) { + state->push(frame->dest); +} + +void ScriptEngine::op86PUDX(EngineState * state, EngineFrame * frame) { + state->push(frame->x); +} + +void ScriptEngine::op87PUDY(EngineState * state, EngineFrame * frame) { + state->push(frame->y); +} + +void ScriptEngine::op88PUIB(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { + state->push(asset->fetch()); +} + +void ScriptEngine::op89PUI(EngineState * state, EngineFrame * frame, ScriptAsset * asset) { + word val = asset->fetch(); + val <<= 8; + val = val | asset->fetch(); + state->push(val); +} + +void ScriptEngine::op8aGGLO(EngineState * state, EngineFrame * frame) { + word idx = state->pop(); + state->push(_world->getGlobal(idx)); +} + +void ScriptEngine::op8bSGLO(EngineState * state, EngineFrame * frame) { + word idx = state->pop(); + word val = neg16(state->pop()); + _world->setGlobal(idx, val); + _engine->gameChanged(); +} + +void ScriptEngine::op8cRAND(EngineState * state, EngineFrame * frame) { + word max = state->pop(); + state->push(_engine->randBetween(0, max)); +} + +void ScriptEngine::op8dCOPY(EngineState * state, EngineFrame * frame) { + word val = state->pop(); + state->push(val); + state->push(val); +} + +void ScriptEngine::op8eCOPYN(EngineState * state, EngineFrame * frame) { + word n = state->pop(); + word offs = n - 1; + word val; + while (n) { + val = state->peek(offs); + state->push(val); + } +} + +void ScriptEngine::op8fSWAP(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push(b); + state->push(a); +} + +void ScriptEngine::op90SWAPN(EngineState * state, EngineFrame * frame) { + word idx = state->pop(); + word a = state->peek(idx); + word b = state->peek(0); + state->poke(idx, b); + state->poke(0, a); +} + +void ScriptEngine::op91POP(EngineState * state, EngineFrame * frame) { + state->pop(); +} + +void ScriptEngine::op92COPYP(EngineState * state, EngineFrame * frame) { + word val = state->peek(1); + state->push(val); +} + +void ScriptEngine::op93COPYPN(EngineState * state, EngineFrame * frame) { + word idx = state->pop(); + word val = state->peek(idx); + state->push(val); +} + +void ScriptEngine::op94SHUFF(EngineState * state, EngineFrame * frame) { + word a = state->pop(); + word b = state->pop(); + word c = state->pop(); + state->push(a); + state->push(c); + state->push(b); +} + +void ScriptEngine::op95SORT(EngineState * state, EngineFrame * frame) { + word step = neg16(state->pop()); + word num = neg16(state->pop()); + step %= num; + if (step<0) step += num; + word end = 0; + word start = 0; + for (word i = 1;i= num) start -= num; + if (start == end) + { + end++; + start = end; + } + else + { + word a = state->peek(end); + word b = state->peek(start); + state->poke(end, b); + state->poke(start, a); + } + } +} + +void ScriptEngine::op96CLEAR(EngineState * state, EngineFrame * frame) { + state->clear(); +} + +void ScriptEngine::op97SIZE(EngineState * state, EngineFrame * frame) { + state->push(state->size()); +} + +void ScriptEngine::op98ADD(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push(a + b); +} + +void ScriptEngine::op99SUB(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push(a - b); +} + +void ScriptEngine::op9aMUL(EngineState * state, EngineFrame * frame) { + int16 b = state->pop(); + int16 a = state->pop(); + state->push(a * b); +} + +void ScriptEngine::op9bDIV(EngineState * state, EngineFrame * frame) { + int16 b = state->pop(); + int16 a = state->pop(); + state->push((a / b) | 0); +} + +void ScriptEngine::op9cMOD(EngineState * state, EngineFrame * frame) { + int16 b = state->pop(); + int16 a = state->pop(); + state->push(a % b); +} + +void ScriptEngine::op9dDMOD(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push(a % b); + state->push((a / b) | 0); +} + +void ScriptEngine::op9eABS(EngineState * state, EngineFrame * frame) { + word val = neg16(state->pop()); + if (val<0) val = -val; + state->push(val); +} + +void ScriptEngine::op9fNEG(EngineState * state, EngineFrame * frame) { + word val = -neg16(state->pop()); + state->push(val); +} + +void ScriptEngine::opa0AND(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push(a & b); +} + +void ScriptEngine::opa1OR(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push(a | b); +} + +void ScriptEngine::opa2XOR(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push(a ^ b); +} + +void ScriptEngine::opa3NOT(EngineState * state, EngineFrame * frame) { + word a = state->pop(); + state->push(a ^ 0xFFFF); +} + +void ScriptEngine::opa4LAND(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push((a && b) ? 0xFFFF : 0); +} + +void ScriptEngine::opa5LOR(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push((a || b) ? 0xFFFF : 0); +} + +void ScriptEngine::opa6LXOR(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push((!a != !b) ? 0xFFFF : 0); +} + +void ScriptEngine::opa7LNOT(EngineState * state, EngineFrame * frame) { + word a = state->pop(); + state->push((a == 0) ? 0xFFFF : 0); +} + +void ScriptEngine::opa8GTU(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push((a > b) ? 0xFFFF : 0); +} + +void ScriptEngine::opa9LTU(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push((a < b) ? 0xFFFF : 0); +} + +void ScriptEngine::opaaGTS(EngineState * state, EngineFrame * frame) { + word b = neg16(state->pop()); + word a = neg16(state->pop()); + state->push((a > b) ? 0xFFFF : 0); +} + +void ScriptEngine::opabLTS(EngineState * state, EngineFrame * frame) { + word b = neg16(state->pop()); + word a = neg16(state->pop()); + state->push((a < b) ? 0xFFFF : 0); +} + +void ScriptEngine::opacEQ(EngineState * state, EngineFrame * frame) { + word b = neg16(state->pop()); + word a = neg16(state->pop()); + state->push((a == b) ? 0xFFFF : 0); +} + +void ScriptEngine::opadEQS(EngineState * state, EngineFrame * frame) { + Common::String b = _world->getText(state->pop()); + Common::String a = _world->getText(state->pop()); + state->push((a == b) ? 1 : 0); +} + +void ScriptEngine::opaeCONT(EngineState * state, EngineFrame * frame) { + Common::String needle = _world->getText(state->pop()); + Common::String haystack = _world->getText(state->pop()); + haystack.toLowercase(); + state->push(haystack.contains(needle) ? 1 : 0); +} + +void ScriptEngine::opafCONTW(EngineState * state, EngineFrame * frame) { + Common::String needle = _world->getText(state->pop()); + Common::String haystack = _world->getText(state->pop()); + haystack.toLowercase(); + state->push(haystack.contains(needle) ? 1 : 0); +} + +void ScriptEngine::opb0BRA(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { + word val = asset->fetch(); + val <<= 8; + val = val | asset->fetch(); + val = neg16(val); + asset->branch(val); +} + +void ScriptEngine::opb1BRAB(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { + word val = asset->fetch(); + val = neg8(val); + asset->branch(val); +} + +void ScriptEngine::opb2BEQ(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { + word val = asset->fetch(); + val <<= 8; + val = val | asset->fetch(); + val = neg16(val); + word b = state->pop(); + if (b != 0) asset->branch(val); +} + +void ScriptEngine::opb3BEQB(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { + word val = asset->fetch(); + val = neg8(val); + word b = state->pop(); + if (b != 0) asset->branch(val); +} + +void ScriptEngine::opb4BNE(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { + word val = asset->fetch(); + val <<= 8; + val = val | asset->fetch(); + val = neg16(val); + word b = state->pop(); + if (b == 0) asset->branch(val); +} + +void ScriptEngine::opb5BNEB(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { + word val = asset->fetch(); + val = neg8(val); + word b = state->pop(); + if (b == 0) asset->branch(val); +} + +void ScriptEngine::opb6CLAT(EngineState * state, EngineFrame * frame) { + word rank = state->pop(); + word func = state->pop(); + frame->saves.push_back(FunCall(rank, func)); +} + +void ScriptEngine::opb7CCA(EngineState * state, EngineFrame * frame) { + word func = state->pop(); + for (int i = 0; i < frame->saves.size(); i++) { + if (frame->saves[i].func == func) + frame->saves[i].rank = 0; + } +} + +void ScriptEngine::opb8CLOW(EngineState * state, EngineFrame * frame) { + word hi = state->pop(); + for (int i = 0;isaves.size();i++) + if (frame->saves[i].rank <= hi) + frame->saves[i].rank = 0; +} + +void ScriptEngine::opb9CHI(EngineState * state, EngineFrame * frame) { + word lo = state->pop(); + for (int i = 0;isaves.size();i++) + if (frame->saves[i].rank >= lo) + frame->saves[i].rank = 0; +} + +void ScriptEngine::opbaCRAN(EngineState * state, EngineFrame * frame) { + word hi = state->pop(); + word lo = state->pop(); + for (int i = 0;isaves.size();i++) + if (frame->saves[i].rank >= lo && + frame->saves[i].rank <= hi) + frame->saves[i].rank = 0; +} + +void ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) { + EngineFrame newframe; + newframe.action = (ControlAction)state->pop(); + newframe.src = state->pop(); + newframe.dest = state->pop(); + newframe.x = state->pop(); + newframe.y = state->pop(); + _frames.push_back(newframe); +} + +void ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsset *script) { + word id = state->pop(); + ScriptAsset newfun = ScriptAsset(id, _scripts); + frame->scripts.remove_at(0); + frame->scripts.insert_at(0, newfun); + script = &frame->scripts.front(); +} + +void ScriptEngine::opbdFOOB(EngineState * state, EngineFrame * frame) { + word obj = state->pop(); + _engine->enqueueObject(obj); +} + +void ScriptEngine::opbeSWOB(EngineState * state, EngineFrame * frame) { + op00NOOP(0xbe); +} + +void ScriptEngine::opbfSNOB(EngineState * state, EngineFrame * frame) { + op00NOOP(0xbf); +} + +void ScriptEngine::opc0TEXI(EngineState * state, EngineFrame * frame) { + op00NOOP(0xc0); +} + +void ScriptEngine::opc1PTXT(EngineState * state, EngineFrame * frame) { + word tid = state->pop(); + _engine->enqueueText(kTextPlain, frame->dest, frame->src, tid); +} + +void ScriptEngine::opc2PNEW(EngineState * state, EngineFrame * frame) { + _engine->enqueueText(kTextNewLine, frame->dest, frame->src, 0); +} + +void ScriptEngine::opc3PTNE(EngineState * state, EngineFrame * frame) { + word tid = state->pop(); + _engine->enqueueText(kTextPlain, frame->dest, frame->src, tid); + _engine->enqueueText(kTextNewLine, frame->dest, frame->src, 0); +} + +void ScriptEngine::opc4PNTN(EngineState * state, EngineFrame * frame) { + word tid = state->pop(); + _engine->enqueueText(kTextNewLine, frame->dest, frame->src, 0); + _engine->enqueueText(kTextPlain, frame->dest, frame->src, tid); + _engine->enqueueText(kTextNewLine, frame->dest, frame->src, 0); +} + +void ScriptEngine::opc5PNUM(EngineState * state, EngineFrame * frame) { + word tid = state->pop(); + _engine->enqueueText(kTextNumber, frame->dest, frame->src, tid); +} + +void ScriptEngine::opc6P2(EngineState * state, EngineFrame * frame) { + state->push(2); +} + +void ScriptEngine::opc7PLBG(EngineState * state, EngineFrame * frame) { + state->pop(); + op00NOOP(0xc7); +} + +void ScriptEngine::opc8PLAW(EngineState * state, EngineFrame * frame) { + state->pop(); + op00NOOP(0xc8); +} + +void ScriptEngine::opc9WAIT(EngineState * state, EngineFrame * frame) { + op00NOOP(0xc9); +} + +void ScriptEngine::opcaTIME(EngineState * state, EngineFrame * frame) { + for (int i = 0; i < 6; i++) // Dummy + state->push(0x00); + op00NOOP(0xca); +} + +void ScriptEngine::opcbDAY(EngineState * state, EngineFrame * frame) { + state->push(9); +} + +void ScriptEngine::opccCHLD(EngineState * state, EngineFrame * frame) { + bool recursive = state->pop() != 0; + word obj = state->pop(); + Common::Array children = _world->getChildren(obj, recursive); + for (Common::Array::const_iterator it = children.begin(); it != children.end(); it++) { + state->push(*it); + } + state->push(children.size()); +} + +void ScriptEngine::opcdNCHLD(EngineState * state, EngineFrame * frame) { + bool recursive = state->pop() != 0; + word obj = state->pop(); + Common::Array children = _world->getChildren(obj, recursive); + state->push(children.size()); +} + +void ScriptEngine::opceVERS(EngineState * state, EngineFrame * frame) { + state->push(86); +} + +void ScriptEngine::opcfPSCE(EngineState * state, EngineFrame * frame) { + state->push(0); //Not release +} + +void ScriptEngine::opd0P1(EngineState * state, EngineFrame * frame) { + state->push(1); +} + +void ScriptEngine::opd1GOBD(EngineState * state, EngineFrame * frame) { + word obj = state->pop(); + Common::Rect bounds(0, 0, 1, 1); //= _world->getObjBounds(obj); + state->push(bounds.width()); + state->push(bounds.height()); +} + +void ScriptEngine::opd2GOVP(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push(0);//_world->getOverlapPercent(b, a)); +} + +void ScriptEngine::opd3CAPC(EngineState * state, EngineFrame * frame) { + word obj = state->pop(); + _world->captureChildren(obj); +} + +void ScriptEngine::opd4RELC(EngineState * state, EngineFrame * frame) { + word obj = state->pop(); + _world->releaseChildren(obj); +} + +void ScriptEngine::opd5DLOG(EngineState * state, EngineFrame * frame) { + word txt = state->pop(); + op00NOOP(0xd5); +} + +void ScriptEngine::opd6ACMD(EngineState * state, EngineFrame * frame) { + _engine->activateCommand((ControlReference)state->pop()); +} + +void ScriptEngine::opd7LOSE(EngineState * state, EngineFrame * frame) { + _engine->loseGame(); +} + +void ScriptEngine::opd8WIN(EngineState * state, EngineFrame * frame) { + _engine->winGame(); +} + +void ScriptEngine::opd9SLEEP(EngineState * state, EngineFrame * frame) { + word ticks = state->pop(); + g_system->delayMillis((ticks / 60) * 1000); + _engine->preparedToRun(); +} + +void ScriptEngine::opdaCLICK(EngineState * state, EngineFrame * frame) { + //_engine->updateScreen(false); + //clickToContinue(); + op00NOOP(0xda); +} + +void ScriptEngine::opdbROBQ(EngineState * state, EngineFrame * frame) { + _engine->runObjQueue(); +} + +void ScriptEngine::opdcRSQ(EngineState * state, EngineFrame * frame) { + op00NOOP(0xdc); +} + +void ScriptEngine::opddRTQ(EngineState * state, EngineFrame * frame) { + _engine->printTexts(); +} + +void ScriptEngine::opdeUPSC(EngineState * state, EngineFrame * frame) { + //_engine->updateScreen(false); + op00NOOP(0xde); +} + +void ScriptEngine::opdfFMAI(EngineState * state, EngineFrame * frame) { + word ticks = state->pop(); + g_system->delayMillis((ticks / 60) * 1000); + _engine->revert(); +} + +void ScriptEngine::ope0CHGR(EngineState * state, EngineFrame * frame) { + word txt = state->pop(); + op00NOOP(0xe0); +} + +void ScriptEngine::ope1CHSO(EngineState * state, EngineFrame * frame) { + word txt = state->pop(); + op00NOOP(0xe1); +} + +void ScriptEngine::ope2MDIV(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + a *= b; + word c = state->pop(); + a /= c; + state->push(a | 0); +} + +void ScriptEngine::ope3UPOB(EngineState * state, EngineFrame * frame) { + word obj = state->pop(); + _world->updateObj(obj); +} + +void ScriptEngine::ope4PLEV(EngineState * state, EngineFrame * frame) { + state->push(0); + op00NOOP(0xe4); +} + +void ScriptEngine::ope5WEV(EngineState * state, EngineFrame * frame) { + op00NOOP(0xe5); +} + +void ScriptEngine::ope6GFIB(EngineState * state, EngineFrame * frame) { + state->push(0); + op00NOOP(0xe6); +} + +void ScriptEngine::ope7CFIB(EngineState * state, EngineFrame * frame) { + state->pop(); + op00NOOP(0xe7); +} + +void ScriptEngine::op00NOOP(byte op) { + debug("SCRIPT: Opcode not implemented => %x", op); +} + + + + ScriptAsset::ScriptAsset(ObjID id, Container * container) { _id = id; _container = container; @@ -156,12 +1134,20 @@ void ScriptAsset::reset() { _ip = 0x0; } -uint8 ScriptAsset::fecth() { +uint8 ScriptAsset::fetch() { uint8 ins = _instructions[_ip]; _ip++; return ins; } +bool ScriptAsset::hasNext() { + return _ip < _instructions.size(); +} + +void ScriptAsset::branch(word amount) { + _ip += amount; +} + void ScriptAsset::loadInstructions() { uint32 amount = _container->getItemByteSize(_id); Common::SeekableReadStream *res = _container->getItem(_id); -- cgit v1.2.3 From 60d5ef5c5b875269f29cd817481de7e162f4966a Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 20 Jun 2016 01:30:39 +0200 Subject: MACVENTURE: Begin implementing object queue --- engines/macventure/script.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index b0d5ef0011..5702c9f1ad 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -151,6 +151,7 @@ bool ScriptEngine::runFunc(EngineFrame *frame) { byte op; while (script.hasNext()) { op = script.fetch(); + debug(8, "SCRIPT: I'm running operation %x", op); if (!(op & 0x80)) { state->push(op); } else { @@ -900,7 +901,7 @@ void ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsse void ScriptEngine::opbdFOOB(EngineState * state, EngineFrame * frame) { word obj = state->pop(); - _engine->enqueueObject(obj); + _engine->enqueueObject(kFocusWindow, obj); } void ScriptEngine::opbeSWOB(EngineState * state, EngineFrame * frame) { -- cgit v1.2.3 From 2fbff0e6782759770048c9b9442832e525d001b6 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 20 Jun 2016 08:59:53 +0200 Subject: MACVENTURE: Fix some minor warnings --- engines/macventure/script.cpp | 70 ++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 34 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 5702c9f1ad..715249ca6d 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -337,7 +337,7 @@ bool ScriptEngine::runFunc(EngineFrame *frame) { opbbFORK(state, frame); break; case 0xbc: //call - opbcCALL(state, frame, &script); + opbcCALL(state, frame, script); break; case 0xbd: //focus object opbdFOOB(state, frame); @@ -537,14 +537,14 @@ void ScriptEngine::op87PUDY(EngineState * state, EngineFrame * frame) { state->push(frame->y); } -void ScriptEngine::op88PUIB(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { - state->push(asset->fetch()); +void ScriptEngine::op88PUIB(EngineState * state, EngineFrame * frame, ScriptAsset *script) { + state->push(script->fetch()); } -void ScriptEngine::op89PUI(EngineState * state, EngineFrame * frame, ScriptAsset * asset) { - word val = asset->fetch(); +void ScriptEngine::op89PUI(EngineState * state, EngineFrame * frame, ScriptAsset * script) { + word val = script->fetch(); val <<= 8; - val = val | asset->fetch(); + val = val | script->fetch(); state->push(val); } @@ -798,50 +798,50 @@ void ScriptEngine::opafCONTW(EngineState * state, EngineFrame * frame) { state->push(haystack.contains(needle) ? 1 : 0); } -void ScriptEngine::opb0BRA(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { - word val = asset->fetch(); +void ScriptEngine::opb0BRA(EngineState * state, EngineFrame * frame, ScriptAsset *script) { + word val = script->fetch(); val <<= 8; - val = val | asset->fetch(); + val = val | script->fetch(); val = neg16(val); - asset->branch(val); + script->branch(val); } -void ScriptEngine::opb1BRAB(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { - word val = asset->fetch(); +void ScriptEngine::opb1BRAB(EngineState * state, EngineFrame * frame, ScriptAsset *script) { + word val = script->fetch(); val = neg8(val); - asset->branch(val); + script->branch(val); } -void ScriptEngine::opb2BEQ(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { - word val = asset->fetch(); +void ScriptEngine::opb2BEQ(EngineState * state, EngineFrame * frame, ScriptAsset *script) { + word val = script->fetch(); val <<= 8; - val = val | asset->fetch(); + val = val | script->fetch(); val = neg16(val); word b = state->pop(); - if (b != 0) asset->branch(val); + if (b != 0) script->branch(val); } -void ScriptEngine::opb3BEQB(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { - word val = asset->fetch(); +void ScriptEngine::opb3BEQB(EngineState * state, EngineFrame * frame, ScriptAsset *script) { + word val = script->fetch(); val = neg8(val); word b = state->pop(); - if (b != 0) asset->branch(val); + if (b != 0) script->branch(val); } -void ScriptEngine::opb4BNE(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { - word val = asset->fetch(); +void ScriptEngine::opb4BNE(EngineState * state, EngineFrame * frame, ScriptAsset *script) { + word val = script->fetch(); val <<= 8; - val = val | asset->fetch(); + val = val | script->fetch(); val = neg16(val); word b = state->pop(); - if (b == 0) asset->branch(val); + if (b == 0) script->branch(val); } -void ScriptEngine::opb5BNEB(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { - word val = asset->fetch(); +void ScriptEngine::opb5BNEB(EngineState * state, EngineFrame * frame, ScriptAsset *script) { + word val = script->fetch(); val = neg8(val); word b = state->pop(); - if (b == 0) asset->branch(val); + if (b == 0) script->branch(val); } void ScriptEngine::opb6CLAT(EngineState * state, EngineFrame * frame) { @@ -852,7 +852,7 @@ void ScriptEngine::opb6CLAT(EngineState * state, EngineFrame * frame) { void ScriptEngine::opb7CCA(EngineState * state, EngineFrame * frame) { word func = state->pop(); - for (int i = 0; i < frame->saves.size(); i++) { + for (uint i = 0; i < frame->saves.size(); i++) { if (frame->saves[i].func == func) frame->saves[i].rank = 0; } @@ -860,14 +860,14 @@ void ScriptEngine::opb7CCA(EngineState * state, EngineFrame * frame) { void ScriptEngine::opb8CLOW(EngineState * state, EngineFrame * frame) { word hi = state->pop(); - for (int i = 0;isaves.size();i++) + for (uint i = 0;isaves.size();i++) if (frame->saves[i].rank <= hi) frame->saves[i].rank = 0; } void ScriptEngine::opb9CHI(EngineState * state, EngineFrame * frame) { word lo = state->pop(); - for (int i = 0;isaves.size();i++) + for (uint i = 0;isaves.size();i++) if (frame->saves[i].rank >= lo) frame->saves[i].rank = 0; } @@ -875,7 +875,7 @@ void ScriptEngine::opb9CHI(EngineState * state, EngineFrame * frame) { void ScriptEngine::opbaCRAN(EngineState * state, EngineFrame * frame) { word hi = state->pop(); word lo = state->pop(); - for (int i = 0;isaves.size();i++) + for (uint i = 0;isaves.size();i++) if (frame->saves[i].rank >= lo && frame->saves[i].rank <= hi) frame->saves[i].rank = 0; @@ -891,12 +891,12 @@ void ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) { _frames.push_back(newframe); } -void ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsset *script) { +void ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsset &script) { word id = state->pop(); ScriptAsset newfun = ScriptAsset(id, _scripts); frame->scripts.remove_at(0); frame->scripts.insert_at(0, newfun); - script = &frame->scripts.front(); + script = frame->scripts.front(); } void ScriptEngine::opbdFOOB(EngineState * state, EngineFrame * frame) { @@ -962,7 +962,7 @@ void ScriptEngine::opc9WAIT(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opcaTIME(EngineState * state, EngineFrame * frame) { - for (int i = 0; i < 6; i++) // Dummy + for (uint i = 0; i < 6; i++) // Dummy state->push(0x00); op00NOOP(0xca); } @@ -1005,12 +1005,14 @@ void ScriptEngine::opd1GOBD(EngineState * state, EngineFrame * frame) { Common::Rect bounds(0, 0, 1, 1); //= _world->getObjBounds(obj); state->push(bounds.width()); state->push(bounds.height()); + op00NOOP(0xd1); } void ScriptEngine::opd2GOVP(EngineState * state, EngineFrame * frame) { word b = state->pop(); word a = state->pop(); state->push(0);//_world->getOverlapPercent(b, a)); + op00NOOP(0xd2); } void ScriptEngine::opd3CAPC(EngineState * state, EngineFrame * frame) { -- cgit v1.2.3 From ccc76f2119dcd3b802604294fc1f7bccad645374 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 21 Jun 2016 03:02:14 +0200 Subject: MACVENTURE: Add PPIC0, 1 and 2 decoding --- engines/macventure/script.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 715249ca6d..64f94af16d 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -54,14 +54,14 @@ bool ScriptEngine::runControl(ControlAction action, ObjID source, ObjID destinat frame.haltedInFirst = false; frame.haltedInFamily = false; _frames.push_back(frame); - debug(7, "SCRIPT: Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)", + debug(3, "SCRIPT: Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)", _frames.size() - 1, frame.action, frame.src, frame.dest, frame.x, frame.y); return resume(true); } bool ScriptEngine::resume(bool execAll) { - debug(7, "SCRIPT: Resume"); + debug(3, "SCRIPT: Resume"); while (_frames.size()) { bool fail = execFrame(execAll); if (fail) return true; @@ -145,13 +145,13 @@ bool ScriptEngine::resumeFunc(EngineFrame * frame) { } bool ScriptEngine::runFunc(EngineFrame *frame) { - debug(7, "SCRIPT: I'm running the function"); + debug(3, "SCRIPT: I'm running the function"); ScriptAsset &script = frame->scripts.front(); EngineState *state = &frame->state; byte op; while (script.hasNext()) { op = script.fetch(); - debug(8, "SCRIPT: I'm running operation %x", op); + debug(3, "SCRIPT: I'm running operation %x", op); if (!(op & 0x80)) { state->push(op); } else { @@ -1157,7 +1157,7 @@ void ScriptAsset::loadInstructions() { for (uint i = 0; i < amount; i++) { _instructions.push_back(res->readByte()); } - debug(7, "SCRIPT: Load %d instructions for script %d", amount, _id); + debug(3, "SCRIPT: Load %d instructions for script %d", amount, _id); } } // End of namespace MacVenture \ No newline at end of file -- cgit v1.2.3 From ec7eb7cb5bec5174f7fd3446824280ab44050f5e Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 23 Jun 2016 00:24:39 +0200 Subject: MACVENTURE: Game window object selection and some more opcodes --- engines/macventure/script.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 64f94af16d..f7550360c8 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -905,15 +905,22 @@ void ScriptEngine::opbdFOOB(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opbeSWOB(EngineState * state, EngineFrame * frame) { - op00NOOP(0xbe); + ObjID from = state->pop(); + ObjID to = state->pop(); + _engine->enqueueObject(kUpdateWindow, to); + _world->setObjAttr(to, kAttrContainerOpen, _world->getObjAttr(from, 6)); + _world->setObjAttr(from, kAttrContainerOpen, 0); + Common::Array children = _world->getChildren(from, true); + for (uint i = 0; i < children.size(); i++) + _world->setObjAttr(children[i], 0, to); } void ScriptEngine::opbfSNOB(EngineState * state, EngineFrame * frame) { - op00NOOP(0xbf); + _engine->enqueueObject(kAnimateBack, frame->src); } void ScriptEngine::opc0TEXI(EngineState * state, EngineFrame * frame) { - op00NOOP(0xc0); + _engine->enqueueObject(kHightlightExits, 0); } void ScriptEngine::opc1PTXT(EngineState * state, EngineFrame * frame) { @@ -1049,9 +1056,8 @@ void ScriptEngine::opd9SLEEP(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opdaCLICK(EngineState * state, EngineFrame * frame) { - //_engine->updateScreen(false); - //clickToContinue(); - op00NOOP(0xda); + _engine->updateState(); + //_engine->clickToContinue(); } void ScriptEngine::opdbROBQ(EngineState * state, EngineFrame * frame) { @@ -1067,8 +1073,7 @@ void ScriptEngine::opddRTQ(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opdeUPSC(EngineState * state, EngineFrame * frame) { - //_engine->updateScreen(false); - op00NOOP(0xde); + _engine->updateState(); } void ScriptEngine::opdfFMAI(EngineState * state, EngineFrame * frame) { -- cgit v1.2.3 From ba5ed7fc88a69da782f3df18698837a67a59eb6b Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 23 Jun 2016 23:21:24 +0200 Subject: MACVENTURE: Major push in functionality and rendering --- engines/macventure/script.cpp | 55 ++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 24 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index f7550360c8..bf9339fe76 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -41,9 +41,6 @@ ScriptEngine::~ScriptEngine() { } bool ScriptEngine::runControl(ControlAction action, ObjID source, ObjID destination, Common::Point delta) { - //debug(7, "SCRIPT: Running control %d from obj %d into obj %d, at delta (%d, %d)", - // action, source, destination, delta.x, delta.y); - EngineFrame frame; frame.action = action; frame.src = source; @@ -108,24 +105,37 @@ bool ScriptEngine::execFrame(bool execAll) { } doFamily = true; } - } - - //Handle saves - /* + } - uint highest; - uint high; + // Halted in saves if (frame->haltedInSaves) { - frame->haltedInSaves = false; - } - - - do { - highest = 0; - for (uint i = 0; i < frame->haltedInSaves.size) + frame->haltedInSaves = false; + if (resumeFunc(frame)) { + frame->haltedInSaves = true; + return true; + } } - */ + uint highest = 0; + uint localHigh = 0; + do { // Saved function calls + highest = 0; + for (uint i = 0; i saves.size(); i++) + { + if (highest < frame->saves[i].rank) { + highest = frame->saves[i].rank; + localHigh = i; + } + } + if (highest) { + frame->saves[localHigh].rank = 0; + if (loadScript(frame, frame->saves[localHigh].func)) { + frame->haltedInSaves = true; + return true; + } + } + } while (highest); + _frames.remove_at(0); return false; } @@ -907,7 +917,7 @@ void ScriptEngine::opbdFOOB(EngineState * state, EngineFrame * frame) { void ScriptEngine::opbeSWOB(EngineState * state, EngineFrame * frame) { ObjID from = state->pop(); ObjID to = state->pop(); - _engine->enqueueObject(kUpdateWindow, to); + _engine->enqueueObject(kUpdateWindow, from, to); _world->setObjAttr(to, kAttrContainerOpen, _world->getObjAttr(from, 6)); _world->setObjAttr(from, kAttrContainerOpen, 0); Common::Array children = _world->getChildren(from, true); @@ -1057,7 +1067,7 @@ void ScriptEngine::opd9SLEEP(EngineState * state, EngineFrame * frame) { void ScriptEngine::opdaCLICK(EngineState * state, EngineFrame * frame) { _engine->updateState(); - //_engine->clickToContinue(); + _engine->clickToContinue(); } void ScriptEngine::opdbROBQ(EngineState * state, EngineFrame * frame) { @@ -1083,13 +1093,11 @@ void ScriptEngine::opdfFMAI(EngineState * state, EngineFrame * frame) { } void ScriptEngine::ope0CHGR(EngineState * state, EngineFrame * frame) { - word txt = state->pop(); - op00NOOP(0xe0); + state->pop(); } void ScriptEngine::ope1CHSO(EngineState * state, EngineFrame * frame) { - word txt = state->pop(); - op00NOOP(0xe1); + state->pop(); } void ScriptEngine::ope2MDIV(EngineState * state, EngineFrame * frame) { @@ -1108,7 +1116,6 @@ void ScriptEngine::ope3UPOB(EngineState * state, EngineFrame * frame) { void ScriptEngine::ope4PLEV(EngineState * state, EngineFrame * frame) { state->push(0); - op00NOOP(0xe4); } void ScriptEngine::ope5WEV(EngineState * state, EngineFrame * frame) { -- cgit v1.2.3 From 499ebc0b54c79e89f4ee38628cea1f64cdf40bf2 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 24 Jun 2016 21:00:06 +0200 Subject: MACVENTURE: Script engine fixes --- engines/macventure/script.cpp | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index bf9339fe76..4c00054bb6 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -136,32 +136,37 @@ bool ScriptEngine::execFrame(bool execAll) { } } while (highest); - _frames.remove_at(0); + _frames.pop_front(); return false; } bool ScriptEngine::loadScript(EngineFrame * frame, uint32 scriptID) { - frame->scripts.push_back(ScriptAsset(scriptID, _scripts)); + if (_scripts->getItemByteSize(scriptID) > 0) { + debug(3, "SCRIPT: Loading function %d", scriptID); + // Insert the new script at the front + frame->scripts.push_front(ScriptAsset(scriptID, _scripts)); + return runFunc(frame); + } return false; } bool ScriptEngine::resumeFunc(EngineFrame * frame) { bool fail = runFunc(frame); if (fail) return fail; - frame->scripts.remove_at(0); + frame->scripts.pop_front(); if (frame->scripts.size()) return resumeFunc(frame); return false; } bool ScriptEngine::runFunc(EngineFrame *frame) { - debug(3, "SCRIPT: I'm running the function"); ScriptAsset &script = frame->scripts.front(); + debug(3, "SCRIPT: Executing function %d", script.getId()); EngineState *state = &frame->state; byte op; while (script.hasNext()) { op = script.fetch(); - debug(3, "SCRIPT: I'm running operation %x", op); + debug(3, "SCRIPT: I'm running operation %d", op); if (!(op & 0x80)) { state->push(op); } else { @@ -857,7 +862,7 @@ void ScriptEngine::opb5BNEB(EngineState * state, EngineFrame * frame, ScriptAsse void ScriptEngine::opb6CLAT(EngineState * state, EngineFrame * frame) { word rank = state->pop(); word func = state->pop(); - frame->saves.push_back(FunCall(rank, func)); + frame->saves.push_back(FunCall(func, rank)); } void ScriptEngine::opb7CCA(EngineState * state, EngineFrame * frame) { @@ -904,9 +909,11 @@ void ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) { void ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsset &script) { word id = state->pop(); ScriptAsset newfun = ScriptAsset(id, _scripts); - frame->scripts.remove_at(0); - frame->scripts.insert_at(0, newfun); + ScriptAsset current = script; + loadScript(frame, id); + frame->scripts.pop_front(); script = frame->scripts.front(); + debug(3, "SCRIPT: Return from fuction %d", id); } void ScriptEngine::opbdFOOB(EngineState * state, EngineFrame * frame) { @@ -1019,17 +1026,15 @@ void ScriptEngine::opd0P1(EngineState * state, EngineFrame * frame) { void ScriptEngine::opd1GOBD(EngineState * state, EngineFrame * frame) { word obj = state->pop(); - Common::Rect bounds(0, 0, 1, 1); //= _world->getObjBounds(obj); + Common::Rect bounds = _engine->getObjBounds(obj); state->push(bounds.width()); state->push(bounds.height()); - op00NOOP(0xd1); } void ScriptEngine::opd2GOVP(EngineState * state, EngineFrame * frame) { word b = state->pop(); word a = state->pop(); - state->push(0);//_world->getOverlapPercent(b, a)); - op00NOOP(0xd2); + state->push(_engine->getOverlapPercent(b, a)); } void ScriptEngine::opd3CAPC(EngineState * state, EngineFrame * frame) { @@ -1138,11 +1143,11 @@ void ScriptEngine::op00NOOP(byte op) { - ScriptAsset::ScriptAsset(ObjID id, Container * container) { _id = id; _container = container; _ip = 0x0; + loadInstructions(); } void ScriptAsset::reset() { @@ -1163,6 +1168,10 @@ void ScriptAsset::branch(word amount) { _ip += amount; } +ObjID ScriptAsset::getId() { + return _id; +} + void ScriptAsset::loadInstructions() { uint32 amount = _container->getItemByteSize(_id); Common::SeekableReadStream *res = _container->getItem(_id); -- cgit v1.2.3 From 8dd52b6cce3835950f255f48d13f3d09a7dbe0ff Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 25 Jun 2016 17:38:15 +0200 Subject: MACVENTURE: Complete text decoding --- engines/macventure/script.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 4c00054bb6..2e283e4c15 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -794,21 +794,21 @@ void ScriptEngine::opacEQ(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opadEQS(EngineState * state, EngineFrame * frame) { - Common::String b = _world->getText(state->pop()); - Common::String a = _world->getText(state->pop()); + Common::String b = _world->getText(state->pop(), 0, 0); // HACK, these destinations might be wrong + Common::String a = _world->getText(state->pop(), 0, 0); state->push((a == b) ? 1 : 0); } void ScriptEngine::opaeCONT(EngineState * state, EngineFrame * frame) { - Common::String needle = _world->getText(state->pop()); - Common::String haystack = _world->getText(state->pop()); + Common::String needle = _world->getText(state->pop(), 0, 0); + Common::String haystack = _world->getText(state->pop(), 0, 0); haystack.toLowercase(); state->push(haystack.contains(needle) ? 1 : 0); } void ScriptEngine::opafCONTW(EngineState * state, EngineFrame * frame) { - Common::String needle = _world->getText(state->pop()); - Common::String haystack = _world->getText(state->pop()); + Common::String needle = _world->getText(state->pop(), 0, 0); + Common::String haystack = _world->getText(state->pop(), 0, 0); haystack.toLowercase(); state->push(haystack.contains(needle) ? 1 : 0); } -- cgit v1.2.3 From 764d0ad0fed0dd4e65bd9f6b090fbb803666ba45 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 25 Jun 2016 23:20:28 +0200 Subject: MACVENTURE: Fix small script bug --- engines/macventure/script.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 2e283e4c15..cca144e2d8 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -593,6 +593,7 @@ void ScriptEngine::op8eCOPYN(EngineState * state, EngineFrame * frame) { while (n) { val = state->peek(offs); state->push(val); + n--; } } -- cgit v1.2.3 From 0485483254e9ce94acfd4750122a466984227904 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 28 Jun 2016 20:56:55 +0200 Subject: MACVENTURE: Minor fixes and skull rising --- engines/macventure/script.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index cca144e2d8..cc9474e6d4 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -84,6 +84,7 @@ bool ScriptEngine::execFrame(bool execAll) { else { fail = resumeFunc(frame); } if (fail) { frame->haltedInFirst = true; + _engine->preparedToRun(); return true; } doFamily = true; @@ -101,6 +102,7 @@ bool ScriptEngine::execFrame(bool execAll) { if (fail) { // We are stuck, so we don't shift the frame frame->haltedInFamily = true; frame->familyIdx = i; + _engine->preparedToRun(); return true; } doFamily = true; @@ -112,6 +114,7 @@ bool ScriptEngine::execFrame(bool execAll) { frame->haltedInSaves = false; if (resumeFunc(frame)) { frame->haltedInSaves = true; + _engine->preparedToRun(); return true; } } @@ -131,6 +134,7 @@ bool ScriptEngine::execFrame(bool execAll) { frame->saves[localHigh].rank = 0; if (loadScript(frame, frame->saves[localHigh].func)) { frame->haltedInSaves = true; + _engine->preparedToRun(); return true; } } @@ -352,7 +356,8 @@ bool ScriptEngine::runFunc(EngineFrame *frame) { opbbFORK(state, frame); break; case 0xbc: //call - opbcCALL(state, frame, script); + if (opbcCALL(state, frame, script)) + return true; break; case 0xbd: //focus object opbdFOOB(state, frame); @@ -907,11 +912,12 @@ void ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) { _frames.push_back(newframe); } -void ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsset &script) { +bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsset &script) { word id = state->pop(); ScriptAsset newfun = ScriptAsset(id, _scripts); ScriptAsset current = script; - loadScript(frame, id); + if (loadScript(frame, id)) + return true; frame->scripts.pop_front(); script = frame->scripts.front(); debug(3, "SCRIPT: Return from fuction %d", id); @@ -987,12 +993,23 @@ void ScriptEngine::opc9WAIT(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opcaTIME(EngineState * state, EngineFrame * frame) { - for (uint i = 0; i < 6; i++) // Dummy + for (uint i = 0; i < 3; i++) // We skip year, month and date state->push(0x00); - op00NOOP(0xca); + + uint32 totalPlayTime = _engine->getTotalPlayTime() / 1000; // In seconds + word hours = totalPlayTime / 3600; + totalPlayTime %= 3600; + state->push(hours); + word minutes = totalPlayTime / 60; + totalPlayTime %= 60; + state->push(minutes); + state->push(totalPlayTime); + debug("Saved time: h[%d] m[%d] s[%d]", hours, minutes, totalPlayTime); + } void ScriptEngine::opcbDAY(EngineState * state, EngineFrame * frame) { + // Probaby irrelevant, so we push Day [9] state->push(9); } -- cgit v1.2.3 From a6e1202a0c95c8124536504cf1dee81970ae74bb Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 1 Jul 2016 10:40:13 +0200 Subject: MACVENTURE: Fix object selection fallthrough --- engines/macventure/script.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index cc9474e6d4..cbc47a9148 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -794,8 +794,8 @@ void ScriptEngine::opabLTS(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opacEQ(EngineState * state, EngineFrame * frame) { - word b = neg16(state->pop()); - word a = neg16(state->pop()); + word b = state->pop(); + word a = state->pop(); state->push((a == b) ? 0xFFFF : 0); } -- cgit v1.2.3 From 46a85f02d6086bb14a6635a6af77ba85520a7e39 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 4 Jul 2016 11:45:47 +0200 Subject: MACVENTURE: Add initial text rendering --- engines/macventure/script.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index cbc47a9148..230198bc6c 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -1071,7 +1071,7 @@ void ScriptEngine::opd5DLOG(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opd6ACMD(EngineState * state, EngineFrame * frame) { - _engine->activateCommand((ControlReference)state->pop()); + _engine->activateCommand((ControlType)state->pop()); } void ScriptEngine::opd7LOSE(EngineState * state, EngineFrame * frame) { -- cgit v1.2.3 From b4609642840917fe08d675960ce9f0e4567bd6c9 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 5 Jul 2016 13:06:51 +0200 Subject: MACVENTURE: Add double click --- engines/macventure/script.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 230198bc6c..a86347ba4c 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -353,7 +353,8 @@ bool ScriptEngine::runFunc(EngineFrame *frame) { opbaCRAN(state, frame); break; case 0xbb: //fork - opbbFORK(state, frame); + if (opbbFORK(state, frame)) + return true; break; case 0xbc: //call if (opbcCALL(state, frame, script)) @@ -902,14 +903,20 @@ void ScriptEngine::opbaCRAN(EngineState * state, EngineFrame * frame) { frame->saves[i].rank = 0; } -void ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) { +bool ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) { EngineFrame newframe; newframe.action = (ControlAction)state->pop(); newframe.src = state->pop(); newframe.dest = state->pop(); newframe.x = state->pop(); newframe.y = state->pop(); - _frames.push_back(newframe); + newframe.haltedInFamily = false; + newframe.haltedInFirst = false; + newframe.haltedInSaves = false; + _frames.push_front(newframe); + if (execFrame(true)) { + return true; + } } bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsset &script) { @@ -1071,7 +1078,7 @@ void ScriptEngine::opd5DLOG(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opd6ACMD(EngineState * state, EngineFrame * frame) { - _engine->activateCommand((ControlType)state->pop()); + _engine->activateCommand((ControlAction)state->pop()); } void ScriptEngine::opd7LOSE(EngineState * state, EngineFrame * frame) { -- cgit v1.2.3 From 9905cd24d3335c6dab612b5a8c0e3682856020d9 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 7 Jul 2016 15:06:40 +0200 Subject: MACVENTURE: Tidy up Inventory window system --- engines/macventure/script.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index a86347ba4c..5e8bcd69a2 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -51,14 +51,14 @@ bool ScriptEngine::runControl(ControlAction action, ObjID source, ObjID destinat frame.haltedInFirst = false; frame.haltedInFamily = false; _frames.push_back(frame); - debug(3, "SCRIPT: Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)", + debug(2, "SCRIPT: Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)", _frames.size() - 1, frame.action, frame.src, frame.dest, frame.x, frame.y); return resume(true); } bool ScriptEngine::resume(bool execAll) { - debug(3, "SCRIPT: Resume"); + debug(2, "SCRIPT: Resume"); while (_frames.size()) { bool fail = execFrame(execAll); if (fail) return true; @@ -146,7 +146,7 @@ bool ScriptEngine::execFrame(bool execAll) { bool ScriptEngine::loadScript(EngineFrame * frame, uint32 scriptID) { if (_scripts->getItemByteSize(scriptID) > 0) { - debug(3, "SCRIPT: Loading function %d", scriptID); + debug(2, "SCRIPT: Loading function %d", scriptID); // Insert the new script at the front frame->scripts.push_front(ScriptAsset(scriptID, _scripts)); return runFunc(frame); @@ -165,7 +165,7 @@ bool ScriptEngine::resumeFunc(EngineFrame * frame) { bool ScriptEngine::runFunc(EngineFrame *frame) { ScriptAsset &script = frame->scripts.front(); - debug(3, "SCRIPT: Executing function %d", script.getId()); + debug(2, "SCRIPT: Executing function %d", script.getId()); EngineState *state = &frame->state; byte op; while (script.hasNext()) { @@ -927,7 +927,7 @@ bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsse return true; frame->scripts.pop_front(); script = frame->scripts.front(); - debug(3, "SCRIPT: Return from fuction %d", id); + debug(2, "SCRIPT: Return from fuction %d", id); } void ScriptEngine::opbdFOOB(EngineState * state, EngineFrame * frame) { @@ -1203,7 +1203,7 @@ void ScriptAsset::loadInstructions() { for (uint i = 0; i < amount; i++) { _instructions.push_back(res->readByte()); } - debug(3, "SCRIPT: Load %d instructions for script %d", amount, _id); + debug(2, "SCRIPT: Load %d instructions for script %d", amount, _id); } } // End of namespace MacVenture \ No newline at end of file -- cgit v1.2.3 From 19d732186760bb13be49fb8d5ca4c45de0f77d86 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 12 Jul 2016 11:49:05 +0200 Subject: MACVENTURE: Fix torch drawing problem --- engines/macventure/script.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 5e8bcd69a2..5b86c31e84 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -27,8 +27,8 @@ #include "macventure/world.h" #include "macventure/container.h" -namespace MacVenture { - +namespace MacVenture { + ScriptEngine::ScriptEngine(MacVentureEngine * engine, World * world) { _engine = engine; _world = world; @@ -57,13 +57,13 @@ bool ScriptEngine::runControl(ControlAction action, ObjID source, ObjID destinat return resume(true); } -bool ScriptEngine::resume(bool execAll) { +bool ScriptEngine::resume(bool execAll) { debug(2, "SCRIPT: Resume"); while (_frames.size()) { bool fail = execFrame(execAll); if (fail) return true; } - return false; + return false; } void ScriptEngine::reset() { @@ -107,7 +107,7 @@ bool ScriptEngine::execFrame(bool execAll) { } doFamily = true; } - } + } // Halted in saves if (frame->haltedInSaves) { @@ -139,7 +139,7 @@ bool ScriptEngine::execFrame(bool execAll) { } } } while (highest); - + _frames.pop_front(); return false; } @@ -167,7 +167,7 @@ bool ScriptEngine::runFunc(EngineFrame *frame) { ScriptAsset &script = frame->scripts.front(); debug(2, "SCRIPT: Executing function %d", script.getId()); EngineState *state = &frame->state; - byte op; + byte op; while (script.hasNext()) { op = script.fetch(); debug(3, "SCRIPT: I'm running operation %d", op); @@ -352,7 +352,7 @@ bool ScriptEngine::runFunc(EngineFrame *frame) { case 0xba: //cancel priority range opbaCRAN(state, frame); break; - case 0xbb: //fork + case 0xbb: //fork if (opbbFORK(state, frame)) return true; break; @@ -1012,7 +1012,6 @@ void ScriptEngine::opcaTIME(EngineState * state, EngineFrame * frame) { state->push(minutes); state->push(totalPlayTime); debug("Saved time: h[%d] m[%d] s[%d]", hours, minutes, totalPlayTime); - } void ScriptEngine::opcbDAY(EngineState * state, EngineFrame * frame) { @@ -1056,7 +1055,7 @@ void ScriptEngine::opd1GOBD(EngineState * state, EngineFrame * frame) { state->push(bounds.height()); } -void ScriptEngine::opd2GOVP(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opd2GOVP(EngineState * state, EngineFrame * frame) { word b = state->pop(); word a = state->pop(); state->push(_engine->getOverlapPercent(b, a)); @@ -1168,10 +1167,10 @@ void ScriptEngine::op00NOOP(byte op) { -ScriptAsset::ScriptAsset(ObjID id, Container * container) { +ScriptAsset::ScriptAsset(ObjID id, Container * container) { _id = id; _container = container; - _ip = 0x0; + _ip = 0x0; loadInstructions(); } @@ -1206,4 +1205,4 @@ void ScriptAsset::loadInstructions() { debug(2, "SCRIPT: Load %d instructions for script %d", amount, _id); } -} // End of namespace MacVenture \ No newline at end of file +} // End of namespace MacVenture -- cgit v1.2.3 From 8162483026ec52476a1106e72259c84e5476fd2d Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 14 Jul 2016 00:18:08 +0200 Subject: MACVENTURE: Add text input logic --- engines/macventure/script.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 5b86c31e84..794bbdde60 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -1073,7 +1073,11 @@ void ScriptEngine::opd4RELC(EngineState * state, EngineFrame * frame) { void ScriptEngine::opd5DLOG(EngineState * state, EngineFrame * frame) { word txt = state->pop(); - op00NOOP(0xd5); + if (_engine->showTextEntry(txt, frame->src, frame->dest)) { + state->push(0xFFFF); + } else { + state->push(0x0000); + } } void ScriptEngine::opd6ACMD(EngineState * state, EngineFrame * frame) { -- cgit v1.2.3 From 734b453c86bb20b2cb52c4f695f8a770b97be459 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 15 Jul 2016 23:02:37 +0200 Subject: MACVENTURE: Add text input dialog --- engines/macventure/script.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 794bbdde60..fdb470ca48 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -32,6 +32,7 @@ namespace MacVenture { ScriptEngine::ScriptEngine(MacVentureEngine * engine, World * world) { _engine = engine; _world = world; + // HACK _scripts = new Container("Shadowgate II/Shadow Filter"); } -- cgit v1.2.3 From 014d1b7dcbb27b9db35a02be99338d3525e72349 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 18 Jul 2016 15:26:06 +0200 Subject: MACVENTURE: Fix sign issue --- engines/macventure/script.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index fdb470ca48..36aabae3ed 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -52,14 +52,14 @@ bool ScriptEngine::runControl(ControlAction action, ObjID source, ObjID destinat frame.haltedInFirst = false; frame.haltedInFamily = false; _frames.push_back(frame); - debug(2, "SCRIPT: Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)", + debug(3, "SCRIPT: Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)", _frames.size() - 1, frame.action, frame.src, frame.dest, frame.x, frame.y); return resume(true); } bool ScriptEngine::resume(bool execAll) { - debug(2, "SCRIPT: Resume"); + debug(3, "SCRIPT: Resume"); while (_frames.size()) { bool fail = execFrame(execAll); if (fail) return true; @@ -166,7 +166,6 @@ bool ScriptEngine::resumeFunc(EngineFrame * frame) { bool ScriptEngine::runFunc(EngineFrame *frame) { ScriptAsset &script = frame->scripts.front(); - debug(2, "SCRIPT: Executing function %d", script.getId()); EngineState *state = &frame->state; byte op; while (script.hasNext()) { @@ -772,24 +771,26 @@ void ScriptEngine::opa7LNOT(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opa8GTU(EngineState * state, EngineFrame * frame) { - word b = state->pop(); - word a = state->pop(); + uint16 b = state->pop(); + uint16 a = state->pop(); state->push((a > b) ? 0xFFFF : 0); } void ScriptEngine::opa9LTU(EngineState * state, EngineFrame * frame) { - word b = state->pop(); - word a = state->pop(); + uint16 b = state->pop(); + uint16 a = state->pop(); state->push((a < b) ? 0xFFFF : 0); } void ScriptEngine::opaaGTS(EngineState * state, EngineFrame * frame) { + // HACK !!! May not need the neg16, since word is already a signed int!! word b = neg16(state->pop()); word a = neg16(state->pop()); state->push((a > b) ? 0xFFFF : 0); } void ScriptEngine::opabLTS(EngineState * state, EngineFrame * frame) { + // HACK !!! May not need the neg16, since word is already a signed int!! word b = neg16(state->pop()); word a = neg16(state->pop()); state->push((a < b) ? 0xFFFF : 0); @@ -924,6 +925,7 @@ bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsse word id = state->pop(); ScriptAsset newfun = ScriptAsset(id, _scripts); ScriptAsset current = script; + debug(2, "SCRIPT: Call function: %d", id); if (loadScript(frame, id)) return true; frame->scripts.pop_front(); -- cgit v1.2.3 From f58435a2bcf41153b5a0c0e61548dd350e24cad9 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 27 Jul 2016 21:08:33 +0200 Subject: MACVENTURE: Add dejavu --- engines/macventure/script.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 36aabae3ed..51bfa3382b 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -33,7 +33,7 @@ ScriptEngine::ScriptEngine(MacVentureEngine * engine, World * world) { _engine = engine; _world = world; // HACK - _scripts = new Container("Shadowgate II/Shadow Filter"); + _scripts = new Container(_engine->getFilePath(kFilterPathID)); } ScriptEngine::~ScriptEngine() { -- cgit v1.2.3 From b64622744f480b04dab9603fe0c09fb76e8e25b3 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 1 Aug 2016 12:21:35 +0200 Subject: MACVENTURE: Add infrastructure to support sound system --- engines/macventure/script.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 51bfa3382b..55bb4063bd 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -32,7 +32,6 @@ namespace MacVenture { ScriptEngine::ScriptEngine(MacVentureEngine * engine, World * world) { _engine = engine; _world = world; - // HACK _scripts = new Container(_engine->getFilePath(kFilterPathID)); } @@ -989,17 +988,17 @@ void ScriptEngine::opc6P2(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opc7PLBG(EngineState * state, EngineFrame * frame) { - state->pop(); - op00NOOP(0xc7); + word target = state->pop(); + _engine->enqueueSound(kSoundPlay, target); } void ScriptEngine::opc8PLAW(EngineState * state, EngineFrame * frame) { - state->pop(); - op00NOOP(0xc8); + word target = state->pop(); + _engine->enqueueSound(kSoundPlayAndWait, target); } void ScriptEngine::opc9WAIT(EngineState * state, EngineFrame * frame) { - op00NOOP(0xc9); + _engine->enqueueSound(kSoundWait, 0); } void ScriptEngine::opcaTIME(EngineState * state, EngineFrame * frame) { -- cgit v1.2.3 From 842bff03e0fd949bcac1b3fd4c281d3fc5547ca5 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 1 Aug 2016 13:43:35 +0200 Subject: MACVENTURE: Implement missing instruction --- engines/macventure/script.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 55bb4063bd..6f0a7820b3 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -453,7 +453,8 @@ bool ScriptEngine::runFunc(EngineFrame *frame) { opdbROBQ(state, frame); break; case 0xdc: //run sound queue - opdcRSQ(state, frame); + if (opdcRSQ(state, frame)) + return true; break; case 0xdd: //run text queue opddRTQ(state, frame); @@ -1109,8 +1110,8 @@ void ScriptEngine::opdbROBQ(EngineState * state, EngineFrame * frame) { _engine->runObjQueue(); } -void ScriptEngine::opdcRSQ(EngineState * state, EngineFrame * frame) { - op00NOOP(0xdc); +bool ScriptEngine::opdcRSQ(EngineState * state, EngineFrame * frame) { + return _engine->playSounds(true); } void ScriptEngine::opddRTQ(EngineState * state, EngineFrame * frame) { -- cgit v1.2.3 From 5b63e29d5e2ff4710cf4d417474b607d84317dee Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 4 Aug 2016 10:56:51 +0200 Subject: MACVENTURE: Clean up updateState function --- engines/macventure/script.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 6f0a7820b3..ef1d36cbae 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -453,8 +453,7 @@ bool ScriptEngine::runFunc(EngineFrame *frame) { opdbROBQ(state, frame); break; case 0xdc: //run sound queue - if (opdcRSQ(state, frame)) - return true; + opdcRSQ(state, frame); break; case 0xdd: //run text queue opddRTQ(state, frame); @@ -1102,7 +1101,7 @@ void ScriptEngine::opd9SLEEP(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opdaCLICK(EngineState * state, EngineFrame * frame) { - _engine->updateState(); + _engine->updateState(false); _engine->clickToContinue(); } @@ -1110,8 +1109,8 @@ void ScriptEngine::opdbROBQ(EngineState * state, EngineFrame * frame) { _engine->runObjQueue(); } -bool ScriptEngine::opdcRSQ(EngineState * state, EngineFrame * frame) { - return _engine->playSounds(true); +void ScriptEngine::opdcRSQ(EngineState * state, EngineFrame * frame) { + _engine->playSounds(true); } void ScriptEngine::opddRTQ(EngineState * state, EngineFrame * frame) { @@ -1119,7 +1118,7 @@ void ScriptEngine::opddRTQ(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opdeUPSC(EngineState * state, EngineFrame * frame) { - _engine->updateState(); + _engine->updateState(true); } void ScriptEngine::opdfFMAI(EngineState * state, EngineFrame * frame) { -- cgit v1.2.3 From 8608776768e9926d5be09904232647bff39d7e72 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 7 Aug 2016 17:15:01 +0200 Subject: MACVENTURE: Add debug channels --- engines/macventure/script.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index ef1d36cbae..d191cefa12 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -51,14 +51,14 @@ bool ScriptEngine::runControl(ControlAction action, ObjID source, ObjID destinat frame.haltedInFirst = false; frame.haltedInFamily = false; _frames.push_back(frame); - debug(3, "SCRIPT: Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)", + debugC(3, kMVDebugScript, "SCRIPT: Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)", _frames.size() - 1, frame.action, frame.src, frame.dest, frame.x, frame.y); return resume(true); } bool ScriptEngine::resume(bool execAll) { - debug(3, "SCRIPT: Resume"); + debugC(3, kMVDebugScript, "SCRIPT: Resume"); while (_frames.size()) { bool fail = execFrame(execAll); if (fail) return true; @@ -146,7 +146,7 @@ bool ScriptEngine::execFrame(bool execAll) { bool ScriptEngine::loadScript(EngineFrame * frame, uint32 scriptID) { if (_scripts->getItemByteSize(scriptID) > 0) { - debug(2, "SCRIPT: Loading function %d", scriptID); + debugC(2, kMVDebugScript, "SCRIPT: Loading function %d", scriptID); // Insert the new script at the front frame->scripts.push_front(ScriptAsset(scriptID, _scripts)); return runFunc(frame); @@ -169,7 +169,7 @@ bool ScriptEngine::runFunc(EngineFrame *frame) { byte op; while (script.hasNext()) { op = script.fetch(); - debug(3, "SCRIPT: I'm running operation %d", op); + debugC(3, kMVDebugScript, "SCRIPT: I'm running operation %d", op); if (!(op & 0x80)) { state->push(op); } else { @@ -924,12 +924,12 @@ bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsse word id = state->pop(); ScriptAsset newfun = ScriptAsset(id, _scripts); ScriptAsset current = script; - debug(2, "SCRIPT: Call function: %d", id); + debugC(2, kMVDebugScript, "SCRIPT: Call function: %d", id); if (loadScript(frame, id)) return true; frame->scripts.pop_front(); script = frame->scripts.front(); - debug(2, "SCRIPT: Return from fuction %d", id); + debugC(2, kMVDebugScript, "SCRIPT: Return from fuction %d", id); } void ScriptEngine::opbdFOOB(EngineState * state, EngineFrame * frame) { @@ -1013,7 +1013,7 @@ void ScriptEngine::opcaTIME(EngineState * state, EngineFrame * frame) { totalPlayTime %= 60; state->push(minutes); state->push(totalPlayTime); - debug("Saved time: h[%d] m[%d] s[%d]", hours, minutes, totalPlayTime); + debugC(2, kMVDebugScript, "Saved time: h[%d] m[%d] s[%d]", hours, minutes, totalPlayTime); } void ScriptEngine::opcbDAY(EngineState * state, EngineFrame * frame) { @@ -1168,7 +1168,7 @@ void ScriptEngine::ope7CFIB(EngineState * state, EngineFrame * frame) { } void ScriptEngine::op00NOOP(byte op) { - debug("SCRIPT: Opcode not implemented => %x", op); + warning("SCRIPT: Opcode not implemented => %x", op); } @@ -1208,7 +1208,7 @@ void ScriptAsset::loadInstructions() { for (uint i = 0; i < amount; i++) { _instructions.push_back(res->readByte()); } - debug(2, "SCRIPT: Load %d instructions for script %d", amount, _id); + debugC(2, kMVDebugScript, "SCRIPT: Load %d instructions for script %d", amount, _id); } } // End of namespace MacVenture -- cgit v1.2.3 From 7b9c63b1b919ce042f72b9cd05bde5e84b8edf85 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 12 Aug 2016 10:02:24 +0200 Subject: MACVENTURE: Delete duplicate code --- engines/macventure/script.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index d191cefa12..a051ca8f75 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -1083,7 +1083,7 @@ void ScriptEngine::opd5DLOG(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opd6ACMD(EngineState * state, EngineFrame * frame) { - _engine->activateCommand((ControlAction)state->pop()); + _engine->selectControl((ControlAction)state->pop()); } void ScriptEngine::opd7LOSE(EngineState * state, EngineFrame * frame) { -- cgit v1.2.3 From 44a6f8a1dbdfa271aaa9ccf4b1ecc48e275ca11a Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 13 Aug 2016 16:57:42 +0200 Subject: MACVENTURE: Fix minor memory leaks --- engines/macventure/script.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index a051ca8f75..5aa8e3cc19 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -1208,6 +1208,7 @@ void ScriptAsset::loadInstructions() { for (uint i = 0; i < amount; i++) { _instructions.push_back(res->readByte()); } + delete res; debugC(2, kMVDebugScript, "SCRIPT: Load %d instructions for script %d", amount, _id); } -- cgit v1.2.3 From 09fe00eb2a8f11e274901a4af4e19ec5275ff7e8 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 15 Aug 2016 11:28:30 +0200 Subject: MACVENTURE: Fix indentation and braces --- engines/macventure/script.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 5aa8e3cc19..3dc9509555 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -648,17 +648,13 @@ void ScriptEngine::op95SORT(EngineState * state, EngineFrame * frame) { if (step<0) step += num; word end = 0; word start = 0; - for (word i = 1;i= num) start -= num; - if (start == end) - { + if (start == end) { end++; start = end; - } - else - { + } else { word a = state->peek(end); word b = state->peek(start); state->poke(end, b); -- cgit v1.2.3 From 9c0777efbf5a59df90728087276245208c13988f Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 15 Aug 2016 12:45:21 +0200 Subject: MACVENTURE: Fix some compiler warnings --- engines/macventure/script.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 3dc9509555..c743e49a55 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -119,7 +119,7 @@ bool ScriptEngine::execFrame(bool execAll) { } } - uint highest = 0; + int highest = 0; uint localHigh = 0; do { // Saved function calls highest = 0; @@ -914,6 +914,7 @@ bool ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) { if (execFrame(true)) { return true; } + return false; } bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsset &script) { @@ -926,6 +927,7 @@ bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsse frame->scripts.pop_front(); script = frame->scripts.front(); debugC(2, kMVDebugScript, "SCRIPT: Return from fuction %d", id); + return false; } void ScriptEngine::opbdFOOB(EngineState * state, EngineFrame * frame) { @@ -1072,9 +1074,9 @@ void ScriptEngine::opd4RELC(EngineState * state, EngineFrame * frame) { void ScriptEngine::opd5DLOG(EngineState * state, EngineFrame * frame) { word txt = state->pop(); if (_engine->showTextEntry(txt, frame->src, frame->dest)) { - state->push(0xFFFF); + state->push(0xFF); } else { - state->push(0x0000); + state->push(0x00); } } -- cgit v1.2.3 From 34fdec37b26c7328f07f6251263f1c1afc7d1629 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 16 Aug 2016 12:14:20 +0200 Subject: MACVENTURE: Fix debug messages --- engines/macventure/script.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index c743e49a55..c88ac0bf3e 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -51,14 +51,14 @@ bool ScriptEngine::runControl(ControlAction action, ObjID source, ObjID destinat frame.haltedInFirst = false; frame.haltedInFamily = false; _frames.push_back(frame); - debugC(3, kMVDebugScript, "SCRIPT: Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)", + debugC(3, kMVDebugScript, "Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)", _frames.size() - 1, frame.action, frame.src, frame.dest, frame.x, frame.y); return resume(true); } bool ScriptEngine::resume(bool execAll) { - debugC(3, kMVDebugScript, "SCRIPT: Resume"); + debugC(3, kMVDebugScript, "Resume Script"); while (_frames.size()) { bool fail = execFrame(execAll); if (fail) return true; @@ -146,7 +146,7 @@ bool ScriptEngine::execFrame(bool execAll) { bool ScriptEngine::loadScript(EngineFrame * frame, uint32 scriptID) { if (_scripts->getItemByteSize(scriptID) > 0) { - debugC(2, kMVDebugScript, "SCRIPT: Loading function %d", scriptID); + debugC(2, kMVDebugScript, "Loading function %d", scriptID); // Insert the new script at the front frame->scripts.push_front(ScriptAsset(scriptID, _scripts)); return runFunc(frame); @@ -169,7 +169,7 @@ bool ScriptEngine::runFunc(EngineFrame *frame) { byte op; while (script.hasNext()) { op = script.fetch(); - debugC(3, kMVDebugScript, "SCRIPT: I'm running operation %d", op); + debugC(4, kMVDebugScript, "Running operation %d", op); if (!(op & 0x80)) { state->push(op); } else { @@ -921,12 +921,12 @@ bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsse word id = state->pop(); ScriptAsset newfun = ScriptAsset(id, _scripts); ScriptAsset current = script; - debugC(2, kMVDebugScript, "SCRIPT: Call function: %d", id); + debugC(2, kMVDebugScript, "Call function: %d", id); if (loadScript(frame, id)) return true; frame->scripts.pop_front(); script = frame->scripts.front(); - debugC(2, kMVDebugScript, "SCRIPT: Return from fuction %d", id); + debugC(2, kMVDebugScript, "Return from fuction %d", id); return false; } @@ -1207,7 +1207,7 @@ void ScriptAsset::loadInstructions() { _instructions.push_back(res->readByte()); } delete res; - debugC(2, kMVDebugScript, "SCRIPT: Load %d instructions for script %d", amount, _id); + debugC(2, kMVDebugScript, "Load %d instructions for script %d", amount, _id); } } // End of namespace MacVenture -- cgit v1.2.3 From e5cf0332f2d08c7f6bc45c1f1fd8edaf276ea76d Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 16 Aug 2016 12:45:08 +0200 Subject: MACVENTURE: Break up one-line ifs and fix braces --- engines/macventure/script.cpp | 65 ++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 19 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index c88ac0bf3e..f7e49c68e3 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -61,7 +61,9 @@ bool ScriptEngine::resume(bool execAll) { debugC(3, kMVDebugScript, "Resume Script"); while (_frames.size()) { bool fail = execFrame(execAll); - if (fail) return true; + if (fail) { + return true; + } } return false; } @@ -80,8 +82,11 @@ bool ScriptEngine::execFrame(bool execAll) { // Do first dispatch script (script 0) if (frame->haltedInFirst || doFirst) { // We were stuck or it's the first time frame->haltedInFirst = false; - if (doFirst) { fail = loadScript(frame, 0); } - else { fail = resumeFunc(frame); } + if (doFirst) { + fail = loadScript(frame, 0); + } else { + fail = resumeFunc(frame); + } if (fail) { frame->haltedInFirst = true; _engine->preparedToRun(); @@ -97,7 +102,9 @@ bool ScriptEngine::execFrame(bool execAll) { Common::Array family = _world->getFamily(_world->getObjAttr(1, kAttrParentObject), false); uint32 i = frame->familyIdx; for (; i < family.size(); i++) { - if (doFamily) { fail = loadScript(frame, family[i]); } + if (doFamily) { + fail = loadScript(frame, family[i]); + } else { fail = resumeFunc(frame); } if (fail) { // We are stuck, so we don't shift the frame frame->haltedInFamily = true; @@ -123,8 +130,7 @@ bool ScriptEngine::execFrame(bool execAll) { uint localHigh = 0; do { // Saved function calls highest = 0; - for (uint i = 0; i saves.size(); i++) - { + for (uint i = 0; i saves.size(); i++) { if (highest < frame->saves[i].rank) { highest = frame->saves[i].rank; localHigh = i; @@ -156,7 +162,9 @@ bool ScriptEngine::loadScript(EngineFrame * frame, uint32 scriptID) { bool ScriptEngine::resumeFunc(EngineFrame * frame) { bool fail = runFunc(frame); - if (fail) return fail; + if (fail) { + return fail; + } frame->scripts.pop_front(); if (frame->scripts.size()) return resumeFunc(frame); @@ -645,12 +653,16 @@ void ScriptEngine::op95SORT(EngineState * state, EngineFrame * frame) { word step = neg16(state->pop()); word num = neg16(state->pop()); step %= num; - if (step<0) step += num; + if (step < 0) { + step += num; + } word end = 0; word start = 0; for (word i = 1;i= num) start -= num; + if (start >= num) { + start -= num; + } if (start == end) { end++; start = end; @@ -710,7 +722,9 @@ void ScriptEngine::op9dDMOD(EngineState * state, EngineFrame * frame) { void ScriptEngine::op9eABS(EngineState * state, EngineFrame * frame) { word val = neg16(state->pop()); - if (val<0) val = -val; + if (val < 0) { + val = -val; + } state->push(val); } @@ -837,14 +851,18 @@ void ScriptEngine::opb2BEQ(EngineState * state, EngineFrame * frame, ScriptAsset val = val | script->fetch(); val = neg16(val); word b = state->pop(); - if (b != 0) script->branch(val); + if (b != 0) { + script->branch(val); + } } void ScriptEngine::opb3BEQB(EngineState * state, EngineFrame * frame, ScriptAsset *script) { word val = script->fetch(); val = neg8(val); word b = state->pop(); - if (b != 0) script->branch(val); + if (b != 0) { + script->branch(val); + } } void ScriptEngine::opb4BNE(EngineState * state, EngineFrame * frame, ScriptAsset *script) { @@ -853,14 +871,18 @@ void ScriptEngine::opb4BNE(EngineState * state, EngineFrame * frame, ScriptAsset val = val | script->fetch(); val = neg16(val); word b = state->pop(); - if (b == 0) script->branch(val); + if (b == 0) { + script->branch(val); + } } void ScriptEngine::opb5BNEB(EngineState * state, EngineFrame * frame, ScriptAsset *script) { word val = script->fetch(); val = neg8(val); word b = state->pop(); - if (b == 0) script->branch(val); + if (b == 0) { + script->branch(val); + } } void ScriptEngine::opb6CLAT(EngineState * state, EngineFrame * frame) { @@ -886,18 +908,22 @@ void ScriptEngine::opb8CLOW(EngineState * state, EngineFrame * frame) { void ScriptEngine::opb9CHI(EngineState * state, EngineFrame * frame) { word lo = state->pop(); - for (uint i = 0;isaves.size();i++) - if (frame->saves[i].rank >= lo) + for (uint i = 0;isaves.size();i++) { + if (frame->saves[i].rank >= lo) { frame->saves[i].rank = 0; + } + } } void ScriptEngine::opbaCRAN(EngineState * state, EngineFrame * frame) { word hi = state->pop(); word lo = state->pop(); - for (uint i = 0;isaves.size();i++) + for (uint i = 0;isaves.size();i++) { if (frame->saves[i].rank >= lo && - frame->saves[i].rank <= hi) + frame->saves[i].rank <= hi) { frame->saves[i].rank = 0; + } + } } bool ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) { @@ -942,8 +968,9 @@ void ScriptEngine::opbeSWOB(EngineState * state, EngineFrame * frame) { _world->setObjAttr(to, kAttrContainerOpen, _world->getObjAttr(from, 6)); _world->setObjAttr(from, kAttrContainerOpen, 0); Common::Array children = _world->getChildren(from, true); - for (uint i = 0; i < children.size(); i++) + for (uint i = 0; i < children.size(); i++) { _world->setObjAttr(children[i], 0, to); + } } void ScriptEngine::opbfSNOB(EngineState * state, EngineFrame * frame) { -- cgit v1.2.3 From 19c7bcf9d492dc25ef7458df001accfced21edff Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 17 Aug 2016 14:35:25 +0200 Subject: MACVENTURE: Fix formatting --- engines/macventure/script.cpp | 235 +++++++++++++++++++++--------------------- 1 file changed, 118 insertions(+), 117 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index f7e49c68e3..5f5273c6d7 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -29,7 +29,7 @@ namespace MacVenture { -ScriptEngine::ScriptEngine(MacVentureEngine * engine, World * world) { +ScriptEngine::ScriptEngine(MacVentureEngine *engine, World *world) { _engine = engine; _world = world; _scripts = new Container(_engine->getFilePath(kFilterPathID)); @@ -100,12 +100,12 @@ bool ScriptEngine::execFrame(bool execAll) { if (frame->haltedInFamily || doFamily) { // We have to do the family or we were stuck here frame->haltedInFamily = false; Common::Array family = _world->getFamily(_world->getObjAttr(1, kAttrParentObject), false); - uint32 i = frame->familyIdx; - for (; i < family.size(); i++) { + for (uint32 i = frame->familyIdx; i < family.size(); i++) { if (doFamily) { fail = loadScript(frame, family[i]); + } else { + fail = resumeFunc(frame); } - else { fail = resumeFunc(frame); } if (fail) { // We are stuck, so we don't shift the frame frame->haltedInFamily = true; frame->familyIdx = i; @@ -130,7 +130,7 @@ bool ScriptEngine::execFrame(bool execAll) { uint localHigh = 0; do { // Saved function calls highest = 0; - for (uint i = 0; i saves.size(); i++) { + for (uint i = 0; i < frame->saves.size(); i++) { if (highest < frame->saves[i].rank) { highest = frame->saves[i].rank; localHigh = i; @@ -150,7 +150,7 @@ bool ScriptEngine::execFrame(bool execAll) { return false; } -bool ScriptEngine::loadScript(EngineFrame * frame, uint32 scriptID) { +bool ScriptEngine::loadScript(EngineFrame *frame, uint32 scriptID) { if (_scripts->getItemByteSize(scriptID) > 0) { debugC(2, kMVDebugScript, "Loading function %d", scriptID); // Insert the new script at the front @@ -160,7 +160,7 @@ bool ScriptEngine::loadScript(EngineFrame * frame, uint32 scriptID) { return false; } -bool ScriptEngine::resumeFunc(EngineFrame * frame) { +bool ScriptEngine::resumeFunc(EngineFrame *frame) { bool fail = runFunc(frame); if (fail) { return fail; @@ -525,81 +525,81 @@ word ScriptEngine::sumChildrenAttr(word obj, word attr, bool recursive) { return sum; } -void MacVenture::ScriptEngine::op80GATT(EngineState * state, EngineFrame * frame) { +void MacVenture::ScriptEngine::op80GATT(EngineState *state, EngineFrame *frame) { word obj = state->pop(); word attr = state->pop(); state->push(_world->getObjAttr(obj, attr)); } -void ScriptEngine::op81SATT(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op81SATT(EngineState *state, EngineFrame *frame) { word obj = state->pop(); word attr = state->pop(); word val = neg16(state->pop()); _world->setObjAttr(obj, attr, val); } -void ScriptEngine::op82SUCH(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op82SUCH(EngineState *state, EngineFrame *frame) { word obj = state->pop(); word attr = state->pop(); word recursive = neg16(state->pop()); state->push(sumChildrenAttr(obj, attr, recursive)); } -void ScriptEngine::op83PUCT(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op83PUCT(EngineState *state, EngineFrame *frame) { state->push(frame->action); } -void ScriptEngine::op84PUOB(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op84PUOB(EngineState *state, EngineFrame *frame) { state->push(frame->src); } -void ScriptEngine::op85PUTA(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op85PUTA(EngineState *state, EngineFrame *frame) { state->push(frame->dest); } -void ScriptEngine::op86PUDX(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op86PUDX(EngineState *state, EngineFrame *frame) { state->push(frame->x); } -void ScriptEngine::op87PUDY(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op87PUDY(EngineState *state, EngineFrame *frame) { state->push(frame->y); } -void ScriptEngine::op88PUIB(EngineState * state, EngineFrame * frame, ScriptAsset *script) { +void ScriptEngine::op88PUIB(EngineState *state, EngineFrame *frame, ScriptAsset *script) { state->push(script->fetch()); } -void ScriptEngine::op89PUI(EngineState * state, EngineFrame * frame, ScriptAsset * script) { +void ScriptEngine::op89PUI(EngineState *state, EngineFrame *frame, ScriptAsset *script) { word val = script->fetch(); val <<= 8; val = val | script->fetch(); state->push(val); } -void ScriptEngine::op8aGGLO(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op8aGGLO(EngineState *state, EngineFrame *frame) { word idx = state->pop(); state->push(_world->getGlobal(idx)); } -void ScriptEngine::op8bSGLO(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op8bSGLO(EngineState *state, EngineFrame *frame) { word idx = state->pop(); word val = neg16(state->pop()); _world->setGlobal(idx, val); _engine->gameChanged(); } -void ScriptEngine::op8cRAND(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op8cRAND(EngineState *state, EngineFrame *frame) { word max = state->pop(); state->push(_engine->randBetween(0, max)); } -void ScriptEngine::op8dCOPY(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op8dCOPY(EngineState *state, EngineFrame *frame) { word val = state->pop(); state->push(val); state->push(val); } -void ScriptEngine::op8eCOPYN(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op8eCOPYN(EngineState *state, EngineFrame *frame) { word n = state->pop(); word offs = n - 1; word val; @@ -610,14 +610,14 @@ void ScriptEngine::op8eCOPYN(EngineState * state, EngineFrame * frame) { } } -void ScriptEngine::op8fSWAP(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op8fSWAP(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push(b); state->push(a); } -void ScriptEngine::op90SWAPN(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op90SWAPN(EngineState *state, EngineFrame *frame) { word idx = state->pop(); word a = state->peek(idx); word b = state->peek(0); @@ -625,22 +625,22 @@ void ScriptEngine::op90SWAPN(EngineState * state, EngineFrame * frame) { state->poke(0, a); } -void ScriptEngine::op91POP(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op91POP(EngineState *state, EngineFrame *frame) { state->pop(); } -void ScriptEngine::op92COPYP(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op92COPYP(EngineState *state, EngineFrame *frame) { word val = state->peek(1); state->push(val); } -void ScriptEngine::op93COPYPN(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op93COPYPN(EngineState *state, EngineFrame *frame) { word idx = state->pop(); word val = state->peek(idx); state->push(val); } -void ScriptEngine::op94SHUFF(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op94SHUFF(EngineState *state, EngineFrame *frame) { word a = state->pop(); word b = state->pop(); word c = state->pop(); @@ -649,7 +649,7 @@ void ScriptEngine::op94SHUFF(EngineState * state, EngineFrame * frame) { state->push(b); } -void ScriptEngine::op95SORT(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op95SORT(EngineState *state, EngineFrame *frame) { word step = neg16(state->pop()); word num = neg16(state->pop()); step %= num; @@ -658,7 +658,7 @@ void ScriptEngine::op95SORT(EngineState * state, EngineFrame * frame) { } word end = 0; word start = 0; - for (word i = 1;i= num) { start -= num; @@ -675,52 +675,52 @@ void ScriptEngine::op95SORT(EngineState * state, EngineFrame * frame) { } } -void ScriptEngine::op96CLEAR(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op96CLEAR(EngineState *state, EngineFrame *frame) { state->clear(); } -void ScriptEngine::op97SIZE(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op97SIZE(EngineState *state, EngineFrame *frame) { state->push(state->size()); } -void ScriptEngine::op98ADD(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op98ADD(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push(a + b); } -void ScriptEngine::op99SUB(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op99SUB(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push(a - b); } -void ScriptEngine::op9aMUL(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op9aMUL(EngineState *state, EngineFrame *frame) { int16 b = state->pop(); int16 a = state->pop(); state->push(a * b); } -void ScriptEngine::op9bDIV(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op9bDIV(EngineState *state, EngineFrame *frame) { int16 b = state->pop(); int16 a = state->pop(); state->push((a / b) | 0); } -void ScriptEngine::op9cMOD(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op9cMOD(EngineState *state, EngineFrame *frame) { int16 b = state->pop(); int16 a = state->pop(); state->push(a % b); } -void ScriptEngine::op9dDMOD(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op9dDMOD(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push(a % b); state->push((a / b) | 0); } -void ScriptEngine::op9eABS(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op9eABS(EngineState *state, EngineFrame *frame) { word val = neg16(state->pop()); if (val < 0) { val = -val; @@ -728,110 +728,110 @@ void ScriptEngine::op9eABS(EngineState * state, EngineFrame * frame) { state->push(val); } -void ScriptEngine::op9fNEG(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op9fNEG(EngineState *state, EngineFrame *frame) { word val = -neg16(state->pop()); state->push(val); } -void ScriptEngine::opa0AND(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opa0AND(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push(a & b); } -void ScriptEngine::opa1OR(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opa1OR(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push(a | b); } -void ScriptEngine::opa2XOR(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opa2XOR(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push(a ^ b); } -void ScriptEngine::opa3NOT(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opa3NOT(EngineState *state, EngineFrame *frame) { word a = state->pop(); state->push(a ^ 0xFFFF); } -void ScriptEngine::opa4LAND(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opa4LAND(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push((a && b) ? 0xFFFF : 0); } -void ScriptEngine::opa5LOR(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opa5LOR(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push((a || b) ? 0xFFFF : 0); } -void ScriptEngine::opa6LXOR(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opa6LXOR(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push((!a != !b) ? 0xFFFF : 0); } -void ScriptEngine::opa7LNOT(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opa7LNOT(EngineState *state, EngineFrame *frame) { word a = state->pop(); state->push((a == 0) ? 0xFFFF : 0); } -void ScriptEngine::opa8GTU(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opa8GTU(EngineState *state, EngineFrame *frame) { uint16 b = state->pop(); uint16 a = state->pop(); state->push((a > b) ? 0xFFFF : 0); } -void ScriptEngine::opa9LTU(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opa9LTU(EngineState *state, EngineFrame *frame) { uint16 b = state->pop(); uint16 a = state->pop(); state->push((a < b) ? 0xFFFF : 0); } -void ScriptEngine::opaaGTS(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opaaGTS(EngineState *state, EngineFrame *frame) { // HACK !!! May not need the neg16, since word is already a signed int!! word b = neg16(state->pop()); word a = neg16(state->pop()); state->push((a > b) ? 0xFFFF : 0); } -void ScriptEngine::opabLTS(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opabLTS(EngineState *state, EngineFrame *frame) { // HACK !!! May not need the neg16, since word is already a signed int!! word b = neg16(state->pop()); word a = neg16(state->pop()); state->push((a < b) ? 0xFFFF : 0); } -void ScriptEngine::opacEQ(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opacEQ(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push((a == b) ? 0xFFFF : 0); } -void ScriptEngine::opadEQS(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opadEQS(EngineState *state, EngineFrame *frame) { Common::String b = _world->getText(state->pop(), 0, 0); // HACK, these destinations might be wrong Common::String a = _world->getText(state->pop(), 0, 0); state->push((a == b) ? 1 : 0); } -void ScriptEngine::opaeCONT(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opaeCONT(EngineState *state, EngineFrame *frame) { Common::String needle = _world->getText(state->pop(), 0, 0); Common::String haystack = _world->getText(state->pop(), 0, 0); haystack.toLowercase(); state->push(haystack.contains(needle) ? 1 : 0); } -void ScriptEngine::opafCONTW(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opafCONTW(EngineState *state, EngineFrame *frame) { Common::String needle = _world->getText(state->pop(), 0, 0); Common::String haystack = _world->getText(state->pop(), 0, 0); haystack.toLowercase(); state->push(haystack.contains(needle) ? 1 : 0); } -void ScriptEngine::opb0BRA(EngineState * state, EngineFrame * frame, ScriptAsset *script) { +void ScriptEngine::opb0BRA(EngineState *state, EngineFrame *frame, ScriptAsset *script) { word val = script->fetch(); val <<= 8; val = val | script->fetch(); @@ -839,13 +839,13 @@ void ScriptEngine::opb0BRA(EngineState * state, EngineFrame * frame, ScriptAsset script->branch(val); } -void ScriptEngine::opb1BRAB(EngineState * state, EngineFrame * frame, ScriptAsset *script) { +void ScriptEngine::opb1BRAB(EngineState *state, EngineFrame *frame, ScriptAsset *script) { word val = script->fetch(); val = neg8(val); script->branch(val); } -void ScriptEngine::opb2BEQ(EngineState * state, EngineFrame * frame, ScriptAsset *script) { +void ScriptEngine::opb2BEQ(EngineState *state, EngineFrame *frame, ScriptAsset *script) { word val = script->fetch(); val <<= 8; val = val | script->fetch(); @@ -856,7 +856,7 @@ void ScriptEngine::opb2BEQ(EngineState * state, EngineFrame * frame, ScriptAsset } } -void ScriptEngine::opb3BEQB(EngineState * state, EngineFrame * frame, ScriptAsset *script) { +void ScriptEngine::opb3BEQB(EngineState *state, EngineFrame *frame, ScriptAsset *script) { word val = script->fetch(); val = neg8(val); word b = state->pop(); @@ -865,7 +865,7 @@ void ScriptEngine::opb3BEQB(EngineState * state, EngineFrame * frame, ScriptAsse } } -void ScriptEngine::opb4BNE(EngineState * state, EngineFrame * frame, ScriptAsset *script) { +void ScriptEngine::opb4BNE(EngineState *state, EngineFrame *frame, ScriptAsset *script) { word val = script->fetch(); val <<= 8; val = val | script->fetch(); @@ -876,7 +876,7 @@ void ScriptEngine::opb4BNE(EngineState * state, EngineFrame * frame, ScriptAsset } } -void ScriptEngine::opb5BNEB(EngineState * state, EngineFrame * frame, ScriptAsset *script) { +void ScriptEngine::opb5BNEB(EngineState *state, EngineFrame *frame, ScriptAsset *script) { word val = script->fetch(); val = neg8(val); word b = state->pop(); @@ -885,13 +885,13 @@ void ScriptEngine::opb5BNEB(EngineState * state, EngineFrame * frame, ScriptAsse } } -void ScriptEngine::opb6CLAT(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opb6CLAT(EngineState *state, EngineFrame *frame) { word rank = state->pop(); word func = state->pop(); frame->saves.push_back(FunCall(func, rank)); } -void ScriptEngine::opb7CCA(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opb7CCA(EngineState *state, EngineFrame *frame) { word func = state->pop(); for (uint i = 0; i < frame->saves.size(); i++) { if (frame->saves[i].func == func) @@ -899,26 +899,26 @@ void ScriptEngine::opb7CCA(EngineState * state, EngineFrame * frame) { } } -void ScriptEngine::opb8CLOW(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opb8CLOW(EngineState *state, EngineFrame *frame) { word hi = state->pop(); - for (uint i = 0;isaves.size();i++) + for (uint i = 0; i < frame->saves.size(); i++) if (frame->saves[i].rank <= hi) frame->saves[i].rank = 0; } -void ScriptEngine::opb9CHI(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opb9CHI(EngineState *state, EngineFrame *frame) { word lo = state->pop(); - for (uint i = 0;isaves.size();i++) { + for (uint i = 0; i < frame->saves.size(); i++) { if (frame->saves[i].rank >= lo) { frame->saves[i].rank = 0; } } } -void ScriptEngine::opbaCRAN(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opbaCRAN(EngineState *state, EngineFrame *frame) { word hi = state->pop(); word lo = state->pop(); - for (uint i = 0;isaves.size();i++) { + for (uint i = 0; i < frame->saves.size(); i++) { if (frame->saves[i].rank >= lo && frame->saves[i].rank <= hi) { frame->saves[i].rank = 0; @@ -926,7 +926,7 @@ void ScriptEngine::opbaCRAN(EngineState * state, EngineFrame * frame) { } } -bool ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) { +bool ScriptEngine::opbbFORK(EngineState *state, EngineFrame *frame) { EngineFrame newframe; newframe.action = (ControlAction)state->pop(); newframe.src = state->pop(); @@ -943,7 +943,7 @@ bool ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) { return false; } -bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsset &script) { +bool ScriptEngine::opbcCALL(EngineState *state, EngineFrame *frame, ScriptAsset &script) { word id = state->pop(); ScriptAsset newfun = ScriptAsset(id, _scripts); ScriptAsset current = script; @@ -956,12 +956,12 @@ bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsse return false; } -void ScriptEngine::opbdFOOB(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opbdFOOB(EngineState *state, EngineFrame *frame) { word obj = state->pop(); _engine->enqueueObject(kFocusWindow, obj); } -void ScriptEngine::opbeSWOB(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opbeSWOB(EngineState *state, EngineFrame *frame) { ObjID from = state->pop(); ObjID to = state->pop(); _engine->enqueueObject(kUpdateWindow, from, to); @@ -973,62 +973,63 @@ void ScriptEngine::opbeSWOB(EngineState * state, EngineFrame * frame) { } } -void ScriptEngine::opbfSNOB(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opbfSNOB(EngineState *state, EngineFrame *frame) { _engine->enqueueObject(kAnimateBack, frame->src); } -void ScriptEngine::opc0TEXI(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opc0TEXI(EngineState *state, EngineFrame *frame) { _engine->enqueueObject(kHightlightExits, 0); } -void ScriptEngine::opc1PTXT(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opc1PTXT(EngineState *state, EngineFrame *frame) { word tid = state->pop(); _engine->enqueueText(kTextPlain, frame->dest, frame->src, tid); } -void ScriptEngine::opc2PNEW(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opc2PNEW(EngineState *state, EngineFrame *frame) { _engine->enqueueText(kTextNewLine, frame->dest, frame->src, 0); } -void ScriptEngine::opc3PTNE(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opc3PTNE(EngineState *state, EngineFrame *frame) { word tid = state->pop(); _engine->enqueueText(kTextPlain, frame->dest, frame->src, tid); _engine->enqueueText(kTextNewLine, frame->dest, frame->src, 0); } -void ScriptEngine::opc4PNTN(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opc4PNTN(EngineState *state, EngineFrame *frame) { word tid = state->pop(); _engine->enqueueText(kTextNewLine, frame->dest, frame->src, 0); _engine->enqueueText(kTextPlain, frame->dest, frame->src, tid); _engine->enqueueText(kTextNewLine, frame->dest, frame->src, 0); } -void ScriptEngine::opc5PNUM(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opc5PNUM(EngineState *state, EngineFrame *frame) { word tid = state->pop(); _engine->enqueueText(kTextNumber, frame->dest, frame->src, tid); } -void ScriptEngine::opc6P2(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opc6P2(EngineState *state, EngineFrame *frame) { state->push(2); } -void ScriptEngine::opc7PLBG(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opc7PLBG(EngineState *state, EngineFrame *frame) { word target = state->pop(); _engine->enqueueSound(kSoundPlay, target); } -void ScriptEngine::opc8PLAW(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opc8PLAW(EngineState *state, EngineFrame *frame) { word target = state->pop(); _engine->enqueueSound(kSoundPlayAndWait, target); } -void ScriptEngine::opc9WAIT(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opc9WAIT(EngineState *state, EngineFrame *frame) { _engine->enqueueSound(kSoundWait, 0); } -void ScriptEngine::opcaTIME(EngineState * state, EngineFrame * frame) { - for (uint i = 0; i < 3; i++) // We skip year, month and date +void ScriptEngine::opcaTIME(EngineState *state, EngineFrame *frame) { + for (uint i = 0; i < 3; i++) {// We skip year, month and date state->push(0x00); + } uint32 totalPlayTime = _engine->getTotalPlayTime() / 1000; // In seconds word hours = totalPlayTime / 3600; @@ -1041,12 +1042,12 @@ void ScriptEngine::opcaTIME(EngineState * state, EngineFrame * frame) { debugC(2, kMVDebugScript, "Saved time: h[%d] m[%d] s[%d]", hours, minutes, totalPlayTime); } -void ScriptEngine::opcbDAY(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opcbDAY(EngineState *state, EngineFrame *frame) { // Probaby irrelevant, so we push Day [9] state->push(9); } -void ScriptEngine::opccCHLD(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opccCHLD(EngineState *state, EngineFrame *frame) { bool recursive = state->pop() != 0; word obj = state->pop(); Common::Array children = _world->getChildren(obj, recursive); @@ -1056,49 +1057,49 @@ void ScriptEngine::opccCHLD(EngineState * state, EngineFrame * frame) { state->push(children.size()); } -void ScriptEngine::opcdNCHLD(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opcdNCHLD(EngineState *state, EngineFrame *frame) { bool recursive = state->pop() != 0; word obj = state->pop(); Common::Array children = _world->getChildren(obj, recursive); state->push(children.size()); } -void ScriptEngine::opceVERS(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opceVERS(EngineState *state, EngineFrame *frame) { state->push(86); } -void ScriptEngine::opcfPSCE(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opcfPSCE(EngineState *state, EngineFrame *frame) { state->push(0); //Not release } -void ScriptEngine::opd0P1(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opd0P1(EngineState *state, EngineFrame *frame) { state->push(1); } -void ScriptEngine::opd1GOBD(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opd1GOBD(EngineState *state, EngineFrame *frame) { word obj = state->pop(); Common::Rect bounds = _engine->getObjBounds(obj); state->push(bounds.width()); state->push(bounds.height()); } -void ScriptEngine::opd2GOVP(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opd2GOVP(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push(_engine->getOverlapPercent(b, a)); } -void ScriptEngine::opd3CAPC(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opd3CAPC(EngineState *state, EngineFrame *frame) { word obj = state->pop(); _world->captureChildren(obj); } -void ScriptEngine::opd4RELC(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opd4RELC(EngineState *state, EngineFrame *frame) { word obj = state->pop(); _world->releaseChildren(obj); } -void ScriptEngine::opd5DLOG(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opd5DLOG(EngineState *state, EngineFrame *frame) { word txt = state->pop(); if (_engine->showTextEntry(txt, frame->src, frame->dest)) { state->push(0xFF); @@ -1107,60 +1108,60 @@ void ScriptEngine::opd5DLOG(EngineState * state, EngineFrame * frame) { } } -void ScriptEngine::opd6ACMD(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opd6ACMD(EngineState *state, EngineFrame *frame) { _engine->selectControl((ControlAction)state->pop()); } -void ScriptEngine::opd7LOSE(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opd7LOSE(EngineState *state, EngineFrame *frame) { _engine->loseGame(); } -void ScriptEngine::opd8WIN(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opd8WIN(EngineState *state, EngineFrame *frame) { _engine->winGame(); } -void ScriptEngine::opd9SLEEP(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opd9SLEEP(EngineState *state, EngineFrame *frame) { word ticks = state->pop(); g_system->delayMillis((ticks / 60) * 1000); _engine->preparedToRun(); } -void ScriptEngine::opdaCLICK(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opdaCLICK(EngineState *state, EngineFrame *frame) { _engine->updateState(false); _engine->clickToContinue(); } -void ScriptEngine::opdbROBQ(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opdbROBQ(EngineState *state, EngineFrame *frame) { _engine->runObjQueue(); } -void ScriptEngine::opdcRSQ(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opdcRSQ(EngineState *state, EngineFrame *frame) { _engine->playSounds(true); } -void ScriptEngine::opddRTQ(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opddRTQ(EngineState *state, EngineFrame *frame) { _engine->printTexts(); } -void ScriptEngine::opdeUPSC(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opdeUPSC(EngineState *state, EngineFrame *frame) { _engine->updateState(true); } -void ScriptEngine::opdfFMAI(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opdfFMAI(EngineState *state, EngineFrame *frame) { word ticks = state->pop(); g_system->delayMillis((ticks / 60) * 1000); _engine->revert(); } -void ScriptEngine::ope0CHGR(EngineState * state, EngineFrame * frame) { +void ScriptEngine::ope0CHGR(EngineState *state, EngineFrame *frame) { state->pop(); } -void ScriptEngine::ope1CHSO(EngineState * state, EngineFrame * frame) { +void ScriptEngine::ope1CHSO(EngineState *state, EngineFrame *frame) { state->pop(); } -void ScriptEngine::ope2MDIV(EngineState * state, EngineFrame * frame) { +void ScriptEngine::ope2MDIV(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); a *= b; @@ -1169,25 +1170,25 @@ void ScriptEngine::ope2MDIV(EngineState * state, EngineFrame * frame) { state->push(a | 0); } -void ScriptEngine::ope3UPOB(EngineState * state, EngineFrame * frame) { +void ScriptEngine::ope3UPOB(EngineState *state, EngineFrame *frame) { word obj = state->pop(); _world->updateObj(obj); } -void ScriptEngine::ope4PLEV(EngineState * state, EngineFrame * frame) { +void ScriptEngine::ope4PLEV(EngineState *state, EngineFrame *frame) { state->push(0); } -void ScriptEngine::ope5WEV(EngineState * state, EngineFrame * frame) { +void ScriptEngine::ope5WEV(EngineState *state, EngineFrame *frame) { op00NOOP(0xe5); } -void ScriptEngine::ope6GFIB(EngineState * state, EngineFrame * frame) { +void ScriptEngine::ope6GFIB(EngineState *state, EngineFrame *frame) { state->push(0); op00NOOP(0xe6); } -void ScriptEngine::ope7CFIB(EngineState * state, EngineFrame * frame) { +void ScriptEngine::ope7CFIB(EngineState *state, EngineFrame *frame) { state->pop(); op00NOOP(0xe7); } @@ -1198,7 +1199,7 @@ void ScriptEngine::op00NOOP(byte op) { -ScriptAsset::ScriptAsset(ObjID id, Container * container) { +ScriptAsset::ScriptAsset(ObjID id, Container *container) { _id = id; _container = container; _ip = 0x0; -- cgit v1.2.3 From d8e4d18f7a2226aec3010683de8f40dee3b7e831 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 17 Aug 2016 15:46:00 +0200 Subject: MACVENTURE: Remove leftover comments and document magic constants --- engines/macventure/script.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 5f5273c6d7..f0a3bac4c5 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -1065,11 +1065,11 @@ void ScriptEngine::opcdNCHLD(EngineState *state, EngineFrame *frame) { } void ScriptEngine::opceVERS(EngineState *state, EngineFrame *frame) { - state->push(86); + state->push(86); // Engine version is irrelevant. Like this in the original. } void ScriptEngine::opcfPSCE(EngineState *state, EngineFrame *frame) { - state->push(0); //Not release + state->push(0); // Any value greater than 0 indicates "Release". } void ScriptEngine::opd0P1(EngineState *state, EngineFrame *frame) { -- cgit v1.2.3 From 97af2b6e14ab25e37aa0c3d226c0264ac2a8ec12 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 17 Aug 2016 16:51:10 +0200 Subject: MACVENTURE: Remove word typedef --- engines/macventure/script.cpp | 222 +++++++++++++++++++++--------------------- 1 file changed, 111 insertions(+), 111 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index f0a3bac4c5..e18bf65979 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -504,20 +504,20 @@ bool ScriptEngine::runFunc(EngineFrame *frame) { return false; } -word ScriptEngine::neg16(word val) { +int16 ScriptEngine::neg16(int16 val) { if (val & 0x8000) val = -((val ^ 0xFFFF) + 1); return val; } -word ScriptEngine::neg8(word val) { +int16 ScriptEngine::neg8(int16 val) { if (val & 0x80) val = -((val ^ 0xff) + 1); return val; } -word ScriptEngine::sumChildrenAttr(word obj, word attr, bool recursive) { - word sum = 0; +int16 ScriptEngine::sumChildrenAttr(int16 obj, int16 attr, bool recursive) { + int16 sum = 0; Common::Array children = _world->getChildren(obj, recursive); for (Common::Array::const_iterator it = children.begin(); it != children.end(); it++) { sum += _world->getObjAttr(*it, attr); @@ -526,22 +526,22 @@ word ScriptEngine::sumChildrenAttr(word obj, word attr, bool recursive) { } void MacVenture::ScriptEngine::op80GATT(EngineState *state, EngineFrame *frame) { - word obj = state->pop(); - word attr = state->pop(); + int16 obj = state->pop(); + int16 attr = state->pop(); state->push(_world->getObjAttr(obj, attr)); } void ScriptEngine::op81SATT(EngineState *state, EngineFrame *frame) { - word obj = state->pop(); - word attr = state->pop(); - word val = neg16(state->pop()); + int16 obj = state->pop(); + int16 attr = state->pop(); + int16 val = neg16(state->pop()); _world->setObjAttr(obj, attr, val); } void ScriptEngine::op82SUCH(EngineState *state, EngineFrame *frame) { - word obj = state->pop(); - word attr = state->pop(); - word recursive = neg16(state->pop()); + int16 obj = state->pop(); + int16 attr = state->pop(); + int16 recursive = neg16(state->pop()); state->push(sumChildrenAttr(obj, attr, recursive)); } @@ -570,39 +570,39 @@ void ScriptEngine::op88PUIB(EngineState *state, EngineFrame *frame, ScriptAsset } void ScriptEngine::op89PUI(EngineState *state, EngineFrame *frame, ScriptAsset *script) { - word val = script->fetch(); + int16 val = script->fetch(); val <<= 8; val = val | script->fetch(); state->push(val); } void ScriptEngine::op8aGGLO(EngineState *state, EngineFrame *frame) { - word idx = state->pop(); + int16 idx = state->pop(); state->push(_world->getGlobal(idx)); } void ScriptEngine::op8bSGLO(EngineState *state, EngineFrame *frame) { - word idx = state->pop(); - word val = neg16(state->pop()); + int16 idx = state->pop(); + int16 val = neg16(state->pop()); _world->setGlobal(idx, val); _engine->gameChanged(); } void ScriptEngine::op8cRAND(EngineState *state, EngineFrame *frame) { - word max = state->pop(); + int16 max = state->pop(); state->push(_engine->randBetween(0, max)); } void ScriptEngine::op8dCOPY(EngineState *state, EngineFrame *frame) { - word val = state->pop(); + int16 val = state->pop(); state->push(val); state->push(val); } void ScriptEngine::op8eCOPYN(EngineState *state, EngineFrame *frame) { - word n = state->pop(); - word offs = n - 1; - word val; + int16 n = state->pop(); + int16 offs = n - 1; + int16 val; while (n) { val = state->peek(offs); state->push(val); @@ -611,16 +611,16 @@ void ScriptEngine::op8eCOPYN(EngineState *state, EngineFrame *frame) { } void ScriptEngine::op8fSWAP(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push(b); state->push(a); } void ScriptEngine::op90SWAPN(EngineState *state, EngineFrame *frame) { - word idx = state->pop(); - word a = state->peek(idx); - word b = state->peek(0); + int16 idx = state->pop(); + int16 a = state->peek(idx); + int16 b = state->peek(0); state->poke(idx, b); state->poke(0, a); } @@ -630,35 +630,35 @@ void ScriptEngine::op91POP(EngineState *state, EngineFrame *frame) { } void ScriptEngine::op92COPYP(EngineState *state, EngineFrame *frame) { - word val = state->peek(1); + int16 val = state->peek(1); state->push(val); } void ScriptEngine::op93COPYPN(EngineState *state, EngineFrame *frame) { - word idx = state->pop(); - word val = state->peek(idx); + int16 idx = state->pop(); + int16 val = state->peek(idx); state->push(val); } void ScriptEngine::op94SHUFF(EngineState *state, EngineFrame *frame) { - word a = state->pop(); - word b = state->pop(); - word c = state->pop(); + int16 a = state->pop(); + int16 b = state->pop(); + int16 c = state->pop(); state->push(a); state->push(c); state->push(b); } void ScriptEngine::op95SORT(EngineState *state, EngineFrame *frame) { - word step = neg16(state->pop()); - word num = neg16(state->pop()); + int16 step = neg16(state->pop()); + int16 num = neg16(state->pop()); step %= num; if (step < 0) { step += num; } - word end = 0; - word start = 0; - for (word i = 1; i < num; i++) { + int16 end = 0; + int16 start = 0; + for (int16 i = 1; i < num; i++) { start += step; if (start >= num) { start -= num; @@ -667,8 +667,8 @@ void ScriptEngine::op95SORT(EngineState *state, EngineFrame *frame) { end++; start = end; } else { - word a = state->peek(end); - word b = state->peek(start); + int16 a = state->peek(end); + int16 b = state->peek(start); state->poke(end, b); state->poke(start, a); } @@ -684,14 +684,14 @@ void ScriptEngine::op97SIZE(EngineState *state, EngineFrame *frame) { } void ScriptEngine::op98ADD(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push(a + b); } void ScriptEngine::op99SUB(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push(a - b); } @@ -714,14 +714,14 @@ void ScriptEngine::op9cMOD(EngineState *state, EngineFrame *frame) { } void ScriptEngine::op9dDMOD(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push(a % b); state->push((a / b) | 0); } void ScriptEngine::op9eABS(EngineState *state, EngineFrame *frame) { - word val = neg16(state->pop()); + int16 val = neg16(state->pop()); if (val < 0) { val = -val; } @@ -729,53 +729,53 @@ void ScriptEngine::op9eABS(EngineState *state, EngineFrame *frame) { } void ScriptEngine::op9fNEG(EngineState *state, EngineFrame *frame) { - word val = -neg16(state->pop()); + int16 val = -neg16(state->pop()); state->push(val); } void ScriptEngine::opa0AND(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push(a & b); } void ScriptEngine::opa1OR(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push(a | b); } void ScriptEngine::opa2XOR(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push(a ^ b); } void ScriptEngine::opa3NOT(EngineState *state, EngineFrame *frame) { - word a = state->pop(); + int16 a = state->pop(); state->push(a ^ 0xFFFF); } void ScriptEngine::opa4LAND(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push((a && b) ? 0xFFFF : 0); } void ScriptEngine::opa5LOR(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push((a || b) ? 0xFFFF : 0); } void ScriptEngine::opa6LXOR(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push((!a != !b) ? 0xFFFF : 0); } void ScriptEngine::opa7LNOT(EngineState *state, EngineFrame *frame) { - word a = state->pop(); + int16 a = state->pop(); state->push((a == 0) ? 0xFFFF : 0); } @@ -792,22 +792,22 @@ void ScriptEngine::opa9LTU(EngineState *state, EngineFrame *frame) { } void ScriptEngine::opaaGTS(EngineState *state, EngineFrame *frame) { - // HACK !!! May not need the neg16, since word is already a signed int!! - word b = neg16(state->pop()); - word a = neg16(state->pop()); + // HACK !!! May not need the neg16, since it's already a signed int!! + int16 b = neg16(state->pop()); + int16 a = neg16(state->pop()); state->push((a > b) ? 0xFFFF : 0); } void ScriptEngine::opabLTS(EngineState *state, EngineFrame *frame) { - // HACK !!! May not need the neg16, since word is already a signed int!! - word b = neg16(state->pop()); - word a = neg16(state->pop()); + // HACK !!! May not need the neg16, since it's already a signed int!! + int16 b = neg16(state->pop()); + int16 a = neg16(state->pop()); state->push((a < b) ? 0xFFFF : 0); } void ScriptEngine::opacEQ(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push((a == b) ? 0xFFFF : 0); } @@ -832,7 +832,7 @@ void ScriptEngine::opafCONTW(EngineState *state, EngineFrame *frame) { } void ScriptEngine::opb0BRA(EngineState *state, EngineFrame *frame, ScriptAsset *script) { - word val = script->fetch(); + int16 val = script->fetch(); val <<= 8; val = val | script->fetch(); val = neg16(val); @@ -840,59 +840,59 @@ void ScriptEngine::opb0BRA(EngineState *state, EngineFrame *frame, ScriptAsset * } void ScriptEngine::opb1BRAB(EngineState *state, EngineFrame *frame, ScriptAsset *script) { - word val = script->fetch(); + int16 val = script->fetch(); val = neg8(val); script->branch(val); } void ScriptEngine::opb2BEQ(EngineState *state, EngineFrame *frame, ScriptAsset *script) { - word val = script->fetch(); + int16 val = script->fetch(); val <<= 8; val = val | script->fetch(); val = neg16(val); - word b = state->pop(); + int16 b = state->pop(); if (b != 0) { script->branch(val); } } void ScriptEngine::opb3BEQB(EngineState *state, EngineFrame *frame, ScriptAsset *script) { - word val = script->fetch(); + int16 val = script->fetch(); val = neg8(val); - word b = state->pop(); + int16 b = state->pop(); if (b != 0) { script->branch(val); } } void ScriptEngine::opb4BNE(EngineState *state, EngineFrame *frame, ScriptAsset *script) { - word val = script->fetch(); + int16 val = script->fetch(); val <<= 8; val = val | script->fetch(); val = neg16(val); - word b = state->pop(); + int16 b = state->pop(); if (b == 0) { script->branch(val); } } void ScriptEngine::opb5BNEB(EngineState *state, EngineFrame *frame, ScriptAsset *script) { - word val = script->fetch(); + int16 val = script->fetch(); val = neg8(val); - word b = state->pop(); + int16 b = state->pop(); if (b == 0) { script->branch(val); } } void ScriptEngine::opb6CLAT(EngineState *state, EngineFrame *frame) { - word rank = state->pop(); - word func = state->pop(); + int16 rank = state->pop(); + int16 func = state->pop(); frame->saves.push_back(FunCall(func, rank)); } void ScriptEngine::opb7CCA(EngineState *state, EngineFrame *frame) { - word func = state->pop(); + int16 func = state->pop(); for (uint i = 0; i < frame->saves.size(); i++) { if (frame->saves[i].func == func) frame->saves[i].rank = 0; @@ -900,14 +900,14 @@ void ScriptEngine::opb7CCA(EngineState *state, EngineFrame *frame) { } void ScriptEngine::opb8CLOW(EngineState *state, EngineFrame *frame) { - word hi = state->pop(); + int16 hi = state->pop(); for (uint i = 0; i < frame->saves.size(); i++) if (frame->saves[i].rank <= hi) frame->saves[i].rank = 0; } void ScriptEngine::opb9CHI(EngineState *state, EngineFrame *frame) { - word lo = state->pop(); + int16 lo = state->pop(); for (uint i = 0; i < frame->saves.size(); i++) { if (frame->saves[i].rank >= lo) { frame->saves[i].rank = 0; @@ -916,8 +916,8 @@ void ScriptEngine::opb9CHI(EngineState *state, EngineFrame *frame) { } void ScriptEngine::opbaCRAN(EngineState *state, EngineFrame *frame) { - word hi = state->pop(); - word lo = state->pop(); + int16 hi = state->pop(); + int16 lo = state->pop(); for (uint i = 0; i < frame->saves.size(); i++) { if (frame->saves[i].rank >= lo && frame->saves[i].rank <= hi) { @@ -944,7 +944,7 @@ bool ScriptEngine::opbbFORK(EngineState *state, EngineFrame *frame) { } bool ScriptEngine::opbcCALL(EngineState *state, EngineFrame *frame, ScriptAsset &script) { - word id = state->pop(); + int16 id = state->pop(); ScriptAsset newfun = ScriptAsset(id, _scripts); ScriptAsset current = script; debugC(2, kMVDebugScript, "Call function: %d", id); @@ -957,7 +957,7 @@ bool ScriptEngine::opbcCALL(EngineState *state, EngineFrame *frame, ScriptAsset } void ScriptEngine::opbdFOOB(EngineState *state, EngineFrame *frame) { - word obj = state->pop(); + int16 obj = state->pop(); _engine->enqueueObject(kFocusWindow, obj); } @@ -982,7 +982,7 @@ void ScriptEngine::opc0TEXI(EngineState *state, EngineFrame *frame) { } void ScriptEngine::opc1PTXT(EngineState *state, EngineFrame *frame) { - word tid = state->pop(); + int16 tid = state->pop(); _engine->enqueueText(kTextPlain, frame->dest, frame->src, tid); } @@ -991,20 +991,20 @@ void ScriptEngine::opc2PNEW(EngineState *state, EngineFrame *frame) { } void ScriptEngine::opc3PTNE(EngineState *state, EngineFrame *frame) { - word tid = state->pop(); + int16 tid = state->pop(); _engine->enqueueText(kTextPlain, frame->dest, frame->src, tid); _engine->enqueueText(kTextNewLine, frame->dest, frame->src, 0); } void ScriptEngine::opc4PNTN(EngineState *state, EngineFrame *frame) { - word tid = state->pop(); + int16 tid = state->pop(); _engine->enqueueText(kTextNewLine, frame->dest, frame->src, 0); _engine->enqueueText(kTextPlain, frame->dest, frame->src, tid); _engine->enqueueText(kTextNewLine, frame->dest, frame->src, 0); } void ScriptEngine::opc5PNUM(EngineState *state, EngineFrame *frame) { - word tid = state->pop(); + int16 tid = state->pop(); _engine->enqueueText(kTextNumber, frame->dest, frame->src, tid); } @@ -1013,12 +1013,12 @@ void ScriptEngine::opc6P2(EngineState *state, EngineFrame *frame) { } void ScriptEngine::opc7PLBG(EngineState *state, EngineFrame *frame) { - word target = state->pop(); + int16 target = state->pop(); _engine->enqueueSound(kSoundPlay, target); } void ScriptEngine::opc8PLAW(EngineState *state, EngineFrame *frame) { - word target = state->pop(); + int16 target = state->pop(); _engine->enqueueSound(kSoundPlayAndWait, target); } @@ -1032,10 +1032,10 @@ void ScriptEngine::opcaTIME(EngineState *state, EngineFrame *frame) { } uint32 totalPlayTime = _engine->getTotalPlayTime() / 1000; // In seconds - word hours = totalPlayTime / 3600; + int16 hours = totalPlayTime / 3600; totalPlayTime %= 3600; state->push(hours); - word minutes = totalPlayTime / 60; + int16 minutes = totalPlayTime / 60; totalPlayTime %= 60; state->push(minutes); state->push(totalPlayTime); @@ -1049,7 +1049,7 @@ void ScriptEngine::opcbDAY(EngineState *state, EngineFrame *frame) { void ScriptEngine::opccCHLD(EngineState *state, EngineFrame *frame) { bool recursive = state->pop() != 0; - word obj = state->pop(); + int16 obj = state->pop(); Common::Array children = _world->getChildren(obj, recursive); for (Common::Array::const_iterator it = children.begin(); it != children.end(); it++) { state->push(*it); @@ -1059,7 +1059,7 @@ void ScriptEngine::opccCHLD(EngineState *state, EngineFrame *frame) { void ScriptEngine::opcdNCHLD(EngineState *state, EngineFrame *frame) { bool recursive = state->pop() != 0; - word obj = state->pop(); + int16 obj = state->pop(); Common::Array children = _world->getChildren(obj, recursive); state->push(children.size()); } @@ -1077,30 +1077,30 @@ void ScriptEngine::opd0P1(EngineState *state, EngineFrame *frame) { } void ScriptEngine::opd1GOBD(EngineState *state, EngineFrame *frame) { - word obj = state->pop(); + int16 obj = state->pop(); Common::Rect bounds = _engine->getObjBounds(obj); state->push(bounds.width()); state->push(bounds.height()); } void ScriptEngine::opd2GOVP(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push(_engine->getOverlapPercent(b, a)); } void ScriptEngine::opd3CAPC(EngineState *state, EngineFrame *frame) { - word obj = state->pop(); + int16 obj = state->pop(); _world->captureChildren(obj); } void ScriptEngine::opd4RELC(EngineState *state, EngineFrame *frame) { - word obj = state->pop(); + int16 obj = state->pop(); _world->releaseChildren(obj); } void ScriptEngine::opd5DLOG(EngineState *state, EngineFrame *frame) { - word txt = state->pop(); + int16 txt = state->pop(); if (_engine->showTextEntry(txt, frame->src, frame->dest)) { state->push(0xFF); } else { @@ -1121,7 +1121,7 @@ void ScriptEngine::opd8WIN(EngineState *state, EngineFrame *frame) { } void ScriptEngine::opd9SLEEP(EngineState *state, EngineFrame *frame) { - word ticks = state->pop(); + int16 ticks = state->pop(); g_system->delayMillis((ticks / 60) * 1000); _engine->preparedToRun(); } @@ -1148,7 +1148,7 @@ void ScriptEngine::opdeUPSC(EngineState *state, EngineFrame *frame) { } void ScriptEngine::opdfFMAI(EngineState *state, EngineFrame *frame) { - word ticks = state->pop(); + int16 ticks = state->pop(); g_system->delayMillis((ticks / 60) * 1000); _engine->revert(); } @@ -1162,16 +1162,16 @@ void ScriptEngine::ope1CHSO(EngineState *state, EngineFrame *frame) { } void ScriptEngine::ope2MDIV(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); a *= b; - word c = state->pop(); + int16 c = state->pop(); a /= c; state->push(a | 0); } void ScriptEngine::ope3UPOB(EngineState *state, EngineFrame *frame) { - word obj = state->pop(); + int16 obj = state->pop(); _world->updateObj(obj); } @@ -1220,7 +1220,7 @@ bool ScriptAsset::hasNext() { return _ip < _instructions.size(); } -void ScriptAsset::branch(word amount) { +void ScriptAsset::branch(int16 amount) { _ip += amount; } -- cgit v1.2.3 From 69f2302a1adb9ead458e38a45429477eac2b6ce4 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 17 Aug 2016 17:19:05 +0200 Subject: MACVENTURE: Remove JavaScript constructs --- engines/macventure/script.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'engines/macventure/script.cpp') diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index e18bf65979..d3731489e4 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -525,6 +525,13 @@ int16 ScriptEngine::sumChildrenAttr(int16 obj, int16 attr, bool recursive) { return sum; } +void ScriptEngine::ensureNonzeroDivisor(int16 divisor, byte opcode) { + // TODO Untested, since that occassion rarely comes up. + if (divisor == 0) { + error("SCRIPT: Attempt to divide by 0 in operation %x", opcode); + } +} + void MacVenture::ScriptEngine::op80GATT(EngineState *state, EngineFrame *frame) { int16 obj = state->pop(); int16 attr = state->pop(); @@ -704,7 +711,8 @@ void ScriptEngine::op9aMUL(EngineState *state, EngineFrame *frame) { void ScriptEngine::op9bDIV(EngineState *state, EngineFrame *frame) { int16 b = state->pop(); int16 a = state->pop(); - state->push((a / b) | 0); + ensureNonzeroDivisor(b, 0x9b); + state->push(a / b); } void ScriptEngine::op9cMOD(EngineState *state, EngineFrame *frame) { @@ -716,8 +724,9 @@ void ScriptEngine::op9cMOD(EngineState *state, EngineFrame *frame) { void ScriptEngine::op9dDMOD(EngineState *state, EngineFrame *frame) { int16 b = state->pop(); int16 a = state->pop(); + ensureNonzeroDivisor(b, 0x9d); state->push(a % b); - state->push((a / b) | 0); + state->push(a / b); } void ScriptEngine::op9eABS(EngineState *state, EngineFrame *frame) { @@ -1166,8 +1175,9 @@ void ScriptEngine::ope2MDIV(EngineState *state, EngineFrame *frame) { int16 a = state->pop(); a *= b; int16 c = state->pop(); + ensureNonzeroDivisor(c, 0xe2); a /= c; - state->push(a | 0); + state->push(a); } void ScriptEngine::ope3UPOB(EngineState *state, EngineFrame *frame) { -- cgit v1.2.3