../src/common/Ikari.cpp \
../src/common/Inventory.cpp \
../src/common/Item.cpp \
+../src/common/Script.cpp \
+../src/common/ScriptRunner.cpp \
../src/common/Spell.cpp \
../src/common/Stats.cpp \
../src/common/TargetingMode.cpp
./src/common/Ikari.o \
./src/common/Inventory.o \
./src/common/Item.o \
+./src/common/Script.o \
+./src/common/ScriptRunner.o \
./src/common/Spell.o \
./src/common/Stats.o \
./src/common/TargetingMode.o
./src/common/Ikari.d \
./src/common/Inventory.d \
./src/common/Item.d \
+./src/common/Script.d \
+./src/common/ScriptRunner.d \
./src/common/Spell.d \
./src/common/Stats.d \
./src/common/TargetingMode.d
../src/common/Ikari.cpp \
../src/common/Inventory.cpp \
../src/common/Item.cpp \
+../src/common/Script.cpp \
+../src/common/ScriptRunner.cpp \
../src/common/Spell.cpp \
../src/common/Stats.cpp \
../src/common/TargetingMode.cpp
./src/common/Ikari.o \
./src/common/Inventory.o \
./src/common/Item.o \
+./src/common/Script.o \
+./src/common/ScriptRunner.o \
./src/common/Spell.o \
./src/common/Stats.o \
./src/common/TargetingMode.o
./src/common/Ikari.d \
./src/common/Inventory.d \
./src/common/Item.d \
+./src/common/Script.d \
+./src/common/ScriptRunner.d \
./src/common/Spell.d \
./src/common/Stats.d \
./src/common/TargetingMode.d
--- /dev/null
+/*
+ * Script.cpp
+ *
+ * Created on: Oct 13, 2012
+ * Author: holy
+ */
+
+#include "Script.h"
+
+namespace common {
+
+Script::Script()
+: text(0)
+, textlen(0) {
+
+}
+
+Script::~Script() {
+
+}
+
+}
--- /dev/null
+/*
+ * Script.h
+ *
+ * Created on: Oct 13, 2012
+ * Author: holy
+ */
+
+#ifndef COMMON_SCRIPT_H_
+#define COMMON_SCRIPT_H_
+
+namespace common {
+
+class Script {
+
+public:
+ Script();
+ ~Script();
+
+ enum Code {
+ CODE_MOVE_A0,
+ CODE_MOVE_A1,
+ CODE_MOVE_I0,
+ CODE_MOVE_I1,
+ CODE_MOVE_V0,
+ CODE_MOVE_V1,
+
+ CODE_ADD_I0,
+ CODE_ADD_I1,
+ CODE_ADD_V0,
+ CODE_ADD_V1,
+
+ CODE_RAND_I0,
+ CODE_RAND_I1,
+
+ CODE_SYSCALL,
+ };
+
+public:
+ const unsigned char *text;
+ int textlen;
+
+};
+
+}
+
+#endif /* COMMON_SCRIPT_H_ */
--- /dev/null
+/*
+ * ScriptHost.h
+ *
+ * Created on: Oct 13, 2012
+ * Author: holy
+ */
+
+#ifndef COMMON_SCRIPTHOST_H_
+#define COMMON_SCRIPTHOST_H_
+
+#include "fwd.h"
+
+namespace common {
+
+class ScriptHost {
+
+public:
+ virtual ~ScriptHost() { }
+
+public:
+ virtual void HandleSyscall(ScriptRunner &) = 0;
+
+};
+
+}
+
+#endif /* COMMON_SCRIPTHOST_H_ */
--- /dev/null
+/*
+ * ScriptRunner.cpp
+ *
+ * Created on: Oct 13, 2012
+ * Author: holy
+ */
+
+#include "ScriptRunner.h"
+
+#include "Script.h"
+#include "ScriptHost.h"
+
+#include <cstdlib>
+
+using geometry::Vector;
+
+namespace common {
+
+ScriptRunner::ScriptRunner()
+: host(0)
+, script(0)
+, cursor(0)
+, address0(0)
+, address1(0)
+, integer0(0)
+, integer1(0)
+, vector0(0, 0)
+, vector1(0, 0) {
+
+}
+
+ScriptRunner::~ScriptRunner() {
+
+}
+
+
+bool ScriptRunner::Running() const {
+ return script && cursor < script->textlen;
+}
+
+void ScriptRunner::Run(ScriptHost &h, const Script &s) {
+ host = &h;
+ script = &s;
+ Reset();
+ while (cursor < script->textlen) {
+ unsigned char code(script->text[cursor]);
+ ++cursor;
+ Exec(code);
+ }
+ host = 0;
+ script = 0;
+}
+
+void ScriptRunner::Reset() {
+ cursor = 0;
+ address0 = 0;
+ address1 = 0;
+ integer0 = 0;
+ integer1 = 0;
+ vector0 = Vector<int>(0, 0);
+ vector1 = Vector<int>(0, 0);
+}
+
+void ScriptRunner::Exec(unsigned char code) {
+ switch (code) {
+ case Script::CODE_MOVE_A0:
+ address0 = PopAddress();
+ break;
+ case Script::CODE_MOVE_A1:
+ address1 = PopAddress();
+ break;
+ case Script::CODE_MOVE_I0:
+ integer0 = PopInt();
+ break;
+ case Script::CODE_MOVE_I1:
+ integer1 = PopInt();
+ break;
+ case Script::CODE_MOVE_V0:
+ vector0 = PopVector();
+ break;
+ case Script::CODE_MOVE_V1:
+ vector1 = PopVector();
+ break;
+ case Script::CODE_ADD_I0:
+ integer0 += PopInt();
+ break;
+ case Script::CODE_ADD_I1:
+ integer1 += PopInt();
+ break;
+ case Script::CODE_ADD_V0:
+ vector0 += PopVector();
+ break;
+ case Script::CODE_ADD_V1:
+ vector1 += PopVector();
+ break;
+ case Script::CODE_RAND_I0:
+ integer0 = std::rand();
+ break;
+ case Script::CODE_RAND_I1:
+ integer1 = std::rand();
+ break;
+ case Script::CODE_SYSCALL:
+ host->HandleSyscall(*this);
+ break;
+ }
+}
+
+void *ScriptRunner::PopAddress() {
+ void *const *addr(reinterpret_cast<void *const *>(script->text + cursor));
+ cursor += sizeof(void *);
+ return *addr;
+}
+
+int ScriptRunner::PopInt() {
+ const int *i(reinterpret_cast<const int *>(script->text + cursor));
+ cursor += sizeof(int);
+ return *i;
+}
+
+const Vector<int> &ScriptRunner::PopVector() {
+ const Vector<int> *vec(reinterpret_cast<const Vector<int> *>(script->text + cursor));
+ cursor += sizeof(Vector<int>);
+ return *vec;
+}
+
+}
--- /dev/null
+/*
+ * ScriptRunner.h
+ *
+ * Created on: Oct 13, 2012
+ * Author: holy
+ */
+
+#ifndef COMMON_SCRIPTRUNNER_H_
+#define COMMON_SCRIPTRUNNER_H_
+
+#include "fwd.h"
+#include "../geometry/Vector.h"
+
+namespace common {
+
+class ScriptRunner {
+
+public:
+ ScriptRunner();
+ ~ScriptRunner();
+
+public:
+ void Run(ScriptHost &, const Script &);
+ bool Running() const;
+
+ void *Address0() const { return address0; }
+ void *Address1() const { return address1; }
+ int Integer0() const { return integer0; }
+ int Integer1() const { return integer1; }
+ const geometry::Vector<int> &Vector0() const { return vector0; }
+ const geometry::Vector<int> &Vector1() const { return vector1; }
+
+private:
+ void Reset();
+ void Exec(unsigned char code);
+
+ void *PopAddress();
+ int PopInt();
+ const geometry::Vector<int> &PopVector();
+
+private:
+ ScriptHost *host;
+ const Script *script;
+ int cursor;
+
+ void *address0;
+ void *address1;
+ int integer0;
+ int integer1;
+ geometry::Vector<int> vector0;
+ geometry::Vector<int> vector1;
+
+};
+
+}
+
+#endif /* COMMON_SCRIPTRUNNER_H_ */
class Ikari;
class Inventory;
class Item;
+class Script;
+class ScriptHost;
+class ScriptRunner;
class Spell;
class Stats;
class TargetingMode;