2011-01-12 19:11:27 +00:00
|
|
|
/* 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.
|
|
|
|
*
|
2021-12-26 17:47:58 +00:00
|
|
|
* 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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2014-02-18 01:34:22 +00:00
|
|
|
*
|
2011-01-12 19:11:27 +00:00
|
|
|
* 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.
|
2014-02-18 01:34:22 +00:00
|
|
|
*
|
2011-01-12 19:11:27 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-12-26 17:47:58 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-01-12 19:11:27 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MOHAWK_LIVINGBOOKS_CODE_H
|
|
|
|
#define MOHAWK_LIVINGBOOKS_CODE_H
|
|
|
|
|
2011-11-26 22:43:54 +00:00
|
|
|
#include "common/ptr.h"
|
2011-04-06 22:30:09 +00:00
|
|
|
#include "common/rect.h"
|
|
|
|
#include "common/stack.h"
|
2011-01-12 19:11:27 +00:00
|
|
|
#include "common/substream.h"
|
|
|
|
|
|
|
|
namespace Mohawk {
|
|
|
|
|
|
|
|
class MohawkEngine_LivingBooks;
|
|
|
|
class LBItem;
|
2011-11-26 22:50:45 +00:00
|
|
|
class LBXObject;
|
2011-11-26 22:43:54 +00:00
|
|
|
struct LBList;
|
2011-01-12 19:11:27 +00:00
|
|
|
|
|
|
|
enum LBValueType {
|
|
|
|
kLBValueString,
|
2011-04-06 22:30:09 +00:00
|
|
|
kLBValueInteger,
|
|
|
|
kLBValueReal,
|
|
|
|
kLBValuePoint,
|
|
|
|
kLBValueRect,
|
2011-11-26 22:43:54 +00:00
|
|
|
kLBValueItemPtr,
|
2011-11-26 22:50:45 +00:00
|
|
|
kLBValueLBX,
|
2011-11-26 22:43:54 +00:00
|
|
|
kLBValueList
|
2011-01-12 19:11:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct LBValue {
|
2011-04-06 22:30:09 +00:00
|
|
|
LBValue() {
|
|
|
|
type = kLBValueInteger;
|
|
|
|
integer = 0;
|
|
|
|
}
|
|
|
|
LBValue(int val) {
|
|
|
|
type = kLBValueInteger;
|
|
|
|
integer = val;
|
|
|
|
}
|
|
|
|
LBValue(const Common::String &str) {
|
|
|
|
type = kLBValueString;
|
|
|
|
string = str;
|
|
|
|
}
|
2011-04-07 21:05:22 +00:00
|
|
|
LBValue(const Common::Point &p) {
|
|
|
|
type = kLBValuePoint;
|
|
|
|
point = p;
|
|
|
|
}
|
|
|
|
LBValue(const Common::Rect &r) {
|
|
|
|
type = kLBValueRect;
|
|
|
|
rect = r;
|
|
|
|
}
|
2011-04-06 22:30:09 +00:00
|
|
|
LBValue(LBItem *itm) {
|
|
|
|
type = kLBValueItemPtr;
|
|
|
|
item = itm;
|
|
|
|
}
|
2011-11-26 22:50:45 +00:00
|
|
|
LBValue(Common::SharedPtr<LBXObject> l) {
|
|
|
|
type = kLBValueLBX;
|
|
|
|
lbx = l;
|
|
|
|
}
|
2011-11-26 22:43:54 +00:00
|
|
|
LBValue(Common::SharedPtr<LBList> l) {
|
|
|
|
type = kLBValueList;
|
|
|
|
list = l;
|
|
|
|
}
|
2011-04-06 22:30:09 +00:00
|
|
|
LBValue(const LBValue &val) {
|
2021-03-14 21:19:56 +00:00
|
|
|
copy(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void copy(const LBValue &val) {
|
2011-04-06 22:30:09 +00:00
|
|
|
type = val.type;
|
|
|
|
switch (type) {
|
|
|
|
case kLBValueString:
|
|
|
|
string = val.string;
|
|
|
|
break;
|
|
|
|
case kLBValueInteger:
|
|
|
|
integer = val.integer;
|
|
|
|
break;
|
|
|
|
case kLBValueReal:
|
|
|
|
real = val.real;
|
|
|
|
break;
|
|
|
|
case kLBValuePoint:
|
|
|
|
point = val.point;
|
|
|
|
break;
|
|
|
|
case kLBValueRect:
|
|
|
|
rect = val.rect;
|
|
|
|
break;
|
|
|
|
case kLBValueItemPtr:
|
|
|
|
item = val.item;
|
|
|
|
break;
|
2011-11-26 22:50:45 +00:00
|
|
|
case kLBValueLBX:
|
|
|
|
lbx = val.lbx;
|
|
|
|
break;
|
2011-11-26 22:43:54 +00:00
|
|
|
case kLBValueList:
|
|
|
|
list = val.list;
|
|
|
|
break;
|
2019-12-02 00:16:10 +00:00
|
|
|
default:
|
|
|
|
break;
|
2011-04-06 22:30:09 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-12 19:11:27 +00:00
|
|
|
|
2021-03-14 21:19:56 +00:00
|
|
|
LBValue &operator=(const LBValue &other);
|
|
|
|
|
2011-01-12 19:11:27 +00:00
|
|
|
LBValueType type;
|
|
|
|
Common::String string;
|
|
|
|
int integer;
|
2011-04-06 22:30:09 +00:00
|
|
|
double real;
|
|
|
|
Common::Point point;
|
|
|
|
Common::Rect rect;
|
|
|
|
LBItem *item;
|
2011-11-26 22:50:45 +00:00
|
|
|
Common::SharedPtr<LBXObject> lbx;
|
2011-11-26 22:43:54 +00:00
|
|
|
Common::SharedPtr<LBList> list;
|
2011-01-12 19:11:27 +00:00
|
|
|
|
|
|
|
bool operator==(const LBValue &x) const;
|
|
|
|
bool operator!=(const LBValue &x) const;
|
2011-04-06 22:30:09 +00:00
|
|
|
|
|
|
|
bool isNumeric() const;
|
|
|
|
bool isZero() const;
|
|
|
|
|
2011-04-07 21:05:22 +00:00
|
|
|
Common::String toString() const;
|
2011-04-06 22:30:09 +00:00
|
|
|
int toInt() const;
|
|
|
|
double toDouble() const;
|
2011-04-07 21:05:22 +00:00
|
|
|
Common::Point toPoint() const;
|
|
|
|
Common::Rect toRect() const;
|
2011-01-12 19:11:27 +00:00
|
|
|
};
|
|
|
|
|
2011-11-26 22:43:54 +00:00
|
|
|
struct LBList {
|
|
|
|
Common::Array<LBValue> array;
|
|
|
|
};
|
|
|
|
|
2011-01-12 19:11:27 +00:00
|
|
|
enum {
|
2021-05-05 21:29:56 +00:00
|
|
|
kLBCodeLiteralInteger = 0x1,
|
|
|
|
kLBCodeLiteralIntegerLE = 0x11
|
2011-01-12 19:11:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2011-04-06 22:30:09 +00:00
|
|
|
kTokenIdentifier = 0x1,
|
|
|
|
kTokenLiteral = 0x5,
|
|
|
|
kTokenString = 0x6,
|
|
|
|
kTokenEndOfStatement = 0x7,
|
|
|
|
kTokenEndOfFile = 0x8,
|
|
|
|
kTokenConcat = 0xb,
|
|
|
|
kTokenSingleQuote = 0xc, // ??
|
|
|
|
kTokenDoubleQuote = 0xd, // ??
|
|
|
|
kTokenMultiply = 0xe,
|
|
|
|
kTokenOpenBracket = 0xf,
|
|
|
|
kTokenCloseBracket = 0x10,
|
|
|
|
kTokenMinus = 0x11,
|
|
|
|
kTokenMinusMinus = 0x12,
|
|
|
|
kTokenPlusEquals = 0x13,
|
|
|
|
kTokenPlus = 0x14,
|
|
|
|
kTokenPlusPlus = 0x15,
|
|
|
|
kTokenEquals = 0x16,
|
|
|
|
kTokenMinusEquals = 0x17,
|
|
|
|
kTokenMultiplyEquals = 0x18,
|
|
|
|
kTokenDivideEquals = 0x19,
|
|
|
|
kTokenListStart = 0x1a,
|
|
|
|
kTokenListEnd = 0x1b,
|
|
|
|
kTokenColon = 0x1c, // ??
|
|
|
|
kTokenLessThan = 0x1d,
|
|
|
|
kTokenGreaterThan = 0x1e,
|
|
|
|
kTokenAndEquals = 0x1f,
|
|
|
|
kTokenDotOperator = 0x20,
|
|
|
|
kTokenDivide = 0x21,
|
|
|
|
kTokenAssign = 0x22,
|
|
|
|
kTokenLessThanEq = 0x23,
|
|
|
|
kTokenGreaterThanEq = 0x24,
|
|
|
|
kTokenNotEq = 0x25,
|
|
|
|
kTokenQuote = 0x27, // ??
|
|
|
|
kTokenAnd = 0x2a,
|
|
|
|
kTokenComma = 0x2c,
|
|
|
|
kTokenConstMode = 0x31,
|
|
|
|
kTokenIntDivide = 0x32,
|
|
|
|
kTokenModulo = 0x34,
|
|
|
|
kTokenNot = 0x35,
|
|
|
|
kTokenOr = 0x37,
|
|
|
|
kTokenTrue = 0x39,
|
|
|
|
kTokenFalse = 0x3a,
|
|
|
|
kTokenConstDataType = 0x3b, // ??
|
|
|
|
kTokenConstItemType = 0x3c, // ??
|
|
|
|
kTokenConstEventId = 0x42,
|
|
|
|
kTokenConstScriptOpcode = 0x43, // ??
|
|
|
|
kTokenConstScriptParam = 0x44, // ??
|
2013-04-18 22:32:49 +00:00
|
|
|
kTokenEval = 0x4b,
|
2011-04-06 22:30:09 +00:00
|
|
|
kTokenGeneralCommand = 0x4d,
|
|
|
|
kTokenItemCommand = 0x4e,
|
|
|
|
kTokenNotifyCommand = 0x4f,
|
|
|
|
// 0x5e?!
|
|
|
|
kTokenKeycode = 0x5f,
|
|
|
|
|
|
|
|
// v5 only:
|
|
|
|
kTokenLocal = 0x61,
|
|
|
|
kTokenPropListCommand = 0x70,
|
|
|
|
kTokenRectCommand = 0x71
|
2011-01-12 19:11:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class LBCode {
|
|
|
|
public:
|
2011-04-09 19:01:27 +00:00
|
|
|
LBCode(MohawkEngine_LivingBooks *vm, uint16 baseId);
|
2011-01-12 19:11:27 +00:00
|
|
|
~LBCode();
|
|
|
|
|
2011-04-06 22:30:09 +00:00
|
|
|
LBValue runCode(LBItem *src, uint32 offset);
|
2011-07-01 22:16:55 +00:00
|
|
|
uint parseCode(const Common::String &source);
|
2011-01-12 19:11:27 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
MohawkEngine_LivingBooks *_vm;
|
|
|
|
|
2011-04-06 22:30:09 +00:00
|
|
|
uint32 _size;
|
|
|
|
byte *_data;
|
|
|
|
Common::HashMap<uint16, Common::String> _strings;
|
|
|
|
|
|
|
|
uint32 _currOffset;
|
|
|
|
LBItem *_currSource;
|
|
|
|
|
|
|
|
Common::Stack<LBValue> _stack;
|
|
|
|
byte _currToken;
|
|
|
|
LBValue _currValue;
|
2011-01-12 19:11:27 +00:00
|
|
|
|
2011-04-06 22:30:09 +00:00
|
|
|
void nextToken();
|
2011-01-12 19:11:27 +00:00
|
|
|
|
2011-04-06 22:30:09 +00:00
|
|
|
LBValue runCode(byte terminator);
|
|
|
|
void parseStatement();
|
|
|
|
void parseComparisons();
|
|
|
|
void parseConcat();
|
|
|
|
void parseArithmetic1();
|
|
|
|
void parseArithmetic2();
|
|
|
|
void parseMain();
|
|
|
|
|
2011-12-01 23:01:06 +00:00
|
|
|
LBValue *getIndexedVar(Common::String varname, const Common::Array<LBValue> &index);
|
2011-07-01 22:04:24 +00:00
|
|
|
LBItem *resolveItem(const LBValue &value);
|
2011-04-06 22:30:09 +00:00
|
|
|
Common::Array<LBValue> readParams();
|
2011-04-07 21:08:55 +00:00
|
|
|
Common::Rect getRectFromParams(const Common::Array<LBValue> ¶ms);
|
|
|
|
|
2011-04-06 22:30:09 +00:00
|
|
|
void runGeneralCommand();
|
|
|
|
void runItemCommand();
|
|
|
|
void runNotifyCommand();
|
|
|
|
|
2011-07-01 22:16:55 +00:00
|
|
|
uint nextFreeString();
|
2013-04-18 22:48:41 +00:00
|
|
|
bool parseCodeSymbol(Common::String name, uint &pos, Common::Array<byte> &code, bool useAllAliases);
|
2011-07-01 22:16:55 +00:00
|
|
|
|
2011-04-06 22:30:09 +00:00
|
|
|
public:
|
|
|
|
void cmdUnimplemented(const Common::Array<LBValue> ¶ms);
|
2011-07-01 22:23:04 +00:00
|
|
|
void cmdEval(const Common::Array<LBValue> ¶ms);
|
|
|
|
void cmdRandom(const Common::Array<LBValue> ¶ms);
|
2011-07-07 14:20:01 +00:00
|
|
|
void cmdStringLen(const Common::Array<LBValue> ¶ms);
|
|
|
|
void cmdSubstring(const Common::Array<LBValue> ¶ms);
|
2011-11-26 23:11:34 +00:00
|
|
|
void cmdMax(const Common::Array<LBValue> ¶ms);
|
|
|
|
void cmdMin(const Common::Array<LBValue> ¶ms);
|
|
|
|
void cmdAbs(const Common::Array<LBValue> ¶ms);
|
2011-04-07 21:08:55 +00:00
|
|
|
void cmdGetRect(const Common::Array<LBValue> ¶ms);
|
2011-11-20 15:31:27 +00:00
|
|
|
void cmdMakePoint(const Common::Array<LBValue> ¶ms);
|
2011-04-07 21:08:55 +00:00
|
|
|
void cmdTopLeft(const Common::Array<LBValue> ¶ms);
|
|
|
|
void cmdBottomRight(const Common::Array<LBValue> ¶ms);
|
2011-12-01 22:52:47 +00:00
|
|
|
void cmdMousePos(const Common::Array<LBValue> ¶ms);
|
2011-04-07 21:08:55 +00:00
|
|
|
void cmdTop(const Common::Array<LBValue> ¶ms);
|
|
|
|
void cmdLeft(const Common::Array<LBValue> ¶ms);
|
|
|
|
void cmdBottom(const Common::Array<LBValue> ¶ms);
|
|
|
|
void cmdRight(const Common::Array<LBValue> ¶ms);
|
2015-07-03 15:42:48 +00:00
|
|
|
void cmdXPos(const Common::Array<LBValue> ¶ms);
|
|
|
|
void cmdYPos(const Common::Array<LBValue> ¶ms);
|
2015-07-03 15:31:40 +00:00
|
|
|
void cmdWidth(const Common::Array<LBValue> ¶ms);
|
|
|
|
void cmdHeight(const Common::Array<LBValue> ¶ms);
|
2011-12-01 22:59:15 +00:00
|
|
|
void cmdMove(const Common::Array<LBValue> ¶ms);
|
2011-05-13 21:03:47 +00:00
|
|
|
void cmdSetDragParams(const Common::Array<LBValue> ¶ms);
|
2011-11-26 22:43:54 +00:00
|
|
|
void cmdNewList(const Common::Array<LBValue> ¶ms);
|
2011-12-01 23:05:45 +00:00
|
|
|
void cmdAdd(const Common::Array<LBValue> ¶ms);
|
|
|
|
void cmdAddAt(const Common::Array<LBValue> ¶ms);
|
|
|
|
void cmdSetAt(const Common::Array<LBValue> ¶ms);
|
2011-11-26 22:43:54 +00:00
|
|
|
void cmdListLen(const Common::Array<LBValue> ¶ms);
|
|
|
|
void cmdDeleteAt(const Common::Array<LBValue> ¶ms);
|
2011-12-08 22:15:48 +00:00
|
|
|
void cmdSetProperty(const Common::Array<LBValue> ¶ms);
|
|
|
|
void cmdGetProperty(const Common::Array<LBValue> ¶ms);
|
2015-07-03 15:38:00 +00:00
|
|
|
void cmdDeleteVar(const Common::Array<LBValue> ¶ms);
|
2011-12-01 23:06:58 +00:00
|
|
|
void cmdExec(const Common::Array<LBValue> ¶ms);
|
|
|
|
void cmdReturn(const Common::Array<LBValue> ¶ms);
|
2011-04-06 22:30:09 +00:00
|
|
|
void cmdSetPlayParams(const Common::Array<LBValue> ¶ms);
|
|
|
|
void cmdSetKeyEvent(const Common::Array<LBValue> ¶ms);
|
|
|
|
void cmdSetHitTest(const Common::Array<LBValue> ¶ms);
|
2011-11-26 22:50:45 +00:00
|
|
|
void cmdLBXCreate(const Common::Array<LBValue> ¶ms);
|
|
|
|
void cmdLBXFunc(const Common::Array<LBValue> ¶ms);
|
2011-04-06 22:30:09 +00:00
|
|
|
void cmdKey(const Common::Array<LBValue> ¶ms);
|
|
|
|
|
2011-12-08 22:23:35 +00:00
|
|
|
void itemClone(const Common::Array<LBValue> ¶ms);
|
2011-04-06 22:30:09 +00:00
|
|
|
void itemIsPlaying(const Common::Array<LBValue> ¶ms);
|
2011-12-01 23:03:01 +00:00
|
|
|
void itemIsLoaded(const Common::Array<LBValue> ¶ms);
|
2011-07-01 22:23:04 +00:00
|
|
|
void itemMoveTo(const Common::Array<LBValue> ¶ms);
|
|
|
|
void itemSeek(const Common::Array<LBValue> ¶ms);
|
2011-11-27 20:01:46 +00:00
|
|
|
void itemSeekToFrame(const Common::Array<LBValue> ¶ms);
|
2011-07-01 22:23:04 +00:00
|
|
|
void itemSetParent(const Common::Array<LBValue> ¶ms);
|
2011-01-12 19:11:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End of namespace Mohawk
|
|
|
|
|
|
|
|
#endif
|