From 60ce5fa557a82f120065d18d135e282352688c51 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 23 Dec 2015 00:57:15 +0100 Subject: WAGE: Unstub processIf() --- engines/wage/script.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++++++++- engines/wage/script.h | 3 ++ 2 files changed, 80 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/wage/script.cpp b/engines/wage/script.cpp index 432b226996..355c5da0f8 100644 --- a/engines/wage/script.cpp +++ b/engines/wage/script.cpp @@ -411,7 +411,83 @@ const char *Script::readOperator() { } void Script::processIf() { - warning("STUB: processIf"); + int logicalOp = 0; // 0 => initial, 1 => and, 2 => or + bool result = true; + bool done = false; + + do { + Operand *lhs = readOperand(); + const char *op = readOperator(); + Operand *rhs = readOperand(); + + bool condResult = eval(lhs, op, rhs); + + if (logicalOp == 1) { + result = (result && condResult); + } else if (logicalOp == 2) { + result = (result || condResult); + } else { // logicalOp == 0 + result = condResult; + } + + byte logical = _data->readByte(); + + if (logical == 0x84) { + logicalOp = 1; // and + } else if (logical == 0x85) { + logicalOp = 2; // or + } else if (logical == 0xFE) { + done = true; // then + } + } while (!done); + + if (result == false) { + skipBlock(); + } +} + +void Script::skipIf() { + do { + readOperand(); + readOperator(); + readOperand(); + } while (_data->readByte() != 0xFE); +} + +void Script::skipBlock() { + int nesting = 1; + + while (true) { + byte op = _data->readByte(); + + if (_data->eos()) + return; + + if (op == 0x80) { // IF + nesting++; + skipIf(); + } else if (op == 0x88 || op == 0x87) { // END or EXIT + _data->seek(-1, SEEK_CUR); // We need to reread it higher + nesting--; + if (nesting == 0) { + _data->readByte(); // skiping + return; + } + } else switch (op) { + case 0x8B: // PRINT + case 0x8C: // SOUND + case 0x8E: // LET + case 0x95: // MENU + while (_data->readByte() != 0xFD) + ; + } + } +} + +bool Script::eval(Operand *lhs, const char *op, Operand *rhs) { + warning("STUB: eval"); + + return false; } void Script::processMove() { diff --git a/engines/wage/script.h b/engines/wage/script.h index 97d52f07b4..7ac8356b18 100644 --- a/engines/wage/script.h +++ b/engines/wage/script.h @@ -134,6 +134,9 @@ private: Operand *readStringOperand(); const char *readOperator(); void processIf(); + void skipBlock(); + void skipIf(); + bool eval(Operand *lhs, const char *op, Operand *rhs); void processMove(); void processLet(); -- cgit v1.2.3