Skip to content

Commit

Permalink
WAGE: Unstub processIf()
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Dec 27, 2015
1 parent e11aef1 commit 60ce5fa
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
78 changes: 77 additions & 1 deletion engines/wage/script.cpp
Expand Up @@ -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() {
Expand Down
3 changes: 3 additions & 0 deletions engines/wage/script.h
Expand Up @@ -134,6 +134,9 @@ class Script {
Operand *readStringOperand();
const char *readOperator();
void processIf();
void skipBlock();
void skipIf();
bool eval(Operand *lhs, const char *op, Operand *rhs);
void processMove();
void processLet();

Expand Down

0 comments on commit 60ce5fa

Please sign in to comment.