aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorAlyssa Milburn2011-07-03 18:19:32 +0200
committerAlyssa Milburn2011-07-03 18:19:32 +0200
commita1e9cecd39bbd3541cc8e9cd69cca4578151b8d9 (patch)
treec17abb6a0943f8720c45861324dd93d11ad762c5 /engines
parent57d4bad11cffc77a1d9b1269b6e9c471fe0e8374 (diff)
downloadscummvm-rg350-a1e9cecd39bbd3541cc8e9cd69cca4578151b8d9.tar.gz
scummvm-rg350-a1e9cecd39bbd3541cc8e9cd69cca4578151b8d9.tar.bz2
scummvm-rg350-a1e9cecd39bbd3541cc8e9cd69cca4578151b8d9.zip
MOHAWK: Implement the remaining LBCode arithmetic operators.
Diffstat (limited to 'engines')
-rw-r--r--engines/mohawk/livingbooks_code.cpp49
1 files changed, 48 insertions, 1 deletions
diff --git a/engines/mohawk/livingbooks_code.cpp b/engines/mohawk/livingbooks_code.cpp
index 83b801ed6b..e9ef2516e2 100644
--- a/engines/mohawk/livingbooks_code.cpp
+++ b/engines/mohawk/livingbooks_code.cpp
@@ -405,8 +405,55 @@ void LBCode::parseArithmetic1() {
}
void LBCode::parseArithmetic2() {
- // FIXME: other math operators
parseMain();
+
+ while (true) {
+ byte op = _currToken;
+ switch (op) {
+ case kTokenMultiply:
+ debugN(" * ");
+ break;
+ case kTokenDivide:
+ debugN(" / ");
+ break;
+ case kTokenIntDivide:
+ debugN(" div ");
+ break;
+ case kTokenModulo:
+ debugN(" %% ");
+ break;
+ default:
+ return;
+ }
+
+ nextToken();
+ parseMain();
+
+ LBValue val2 = _stack.pop();
+ LBValue val1 = _stack.pop();
+ LBValue result;
+ // TODO: cope with non-integers
+ if (op == kTokenMultiply) {
+ result = val1.toInt() * val2.toInt();
+ } else if (val2.toInt() == 0) {
+ result = 1;
+ } else {
+ switch (op) {
+ case kTokenDivide:
+ // TODO: fp divide
+ result = val1.toInt() / val2.toInt();
+ break;
+ case kTokenIntDivide:
+ result = val1.toInt() / val2.toInt();
+ break;
+ case kTokenModulo:
+ result = val1.toInt() % val2.toInt();
+ break;
+ }
+ }
+
+ _stack.push(result);
+ }
}
void LBCode::parseMain() {