ScummVM API documentation
script.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef MADE_SCRIPT_H
23 #define MADE_SCRIPT_H
24 
25 #include "common/textconsole.h"
26 
27 namespace Made {
28 
29 // Define this to dump all game scripts and a usage statistic of all
30 // opcodes/extended functions instead of running the actual game.
31 // Then run ScummVM with debuglevel 1.
32 //#define DUMP_SCRIPTS
33 
34 class MadeEngine;
35 class ScriptFunctions;
36 
37 const int kScriptStackSize = 1000;
38 const int kScriptStackLimit = kScriptStackSize + 1;
39 
40 class ScriptStack {
41 public:
42  ScriptStack() {
43  for (int16 i = 0; i < kScriptStackSize; i++)
44  _stack[i] = 0;
45  _stackPos = kScriptStackSize;
46  }
47  ~ScriptStack() {}
48  inline int16 top() { return _stack[_stackPos]; }
49  inline int16 pop() {
50  if (_stackPos == kScriptStackSize)
51  error("ScriptStack::pop() Stack underflow");
52  return _stack[_stackPos++];
53  }
54  inline void push(int16 value = 0) {
55  if (_stackPos == 0)
56  error("ScriptStack::push() Stack overflow");
57  _stack[--_stackPos] = value;
58  }
59  inline void setTop(int16 value) { _stack[_stackPos] = value; }
60  inline int16 peek(int16 index) { return _stack[index]; }
61  inline void poke(int16 index, int16 value) { _stack[index] = value; }
62  inline void alloc(int16 count) { _stackPos -= count; }
63  inline void free(int16 count) { _stackPos += count; }
64  inline int16 getStackPos() const { return _stackPos; }
65  inline void setStackPos(int16 stackPtr) { _stackPos = stackPtr; }
66  inline int16 *getStackPtr() { return &_stack[_stackPos]; }
67 protected:
68  int16 _stack[kScriptStackSize];
69  int16 _stackPos;
70 };
71 
73 public:
76  void runScript(int16 scriptObjectIndex);
77  void dumpScript(int16 objectIndex, int *opcodeStats, int *externStats);
78  void dumpAllScripts();
79 protected:
80  MadeEngine *_vm;
81 
82  ScriptStack _stack;
83  int16 _localStackPos;
84  int16 _runningScriptObjectIndex;
85  byte *_codeBase, *_codeIp;
86 
87  ScriptFunctions *_functions;
88 
89  byte readByte();
90  int16 readInt16();
91 
92  typedef void (ScriptInterpreter::*CommandProc)();
93  struct CommandEntry {
94  CommandProc proc;
95  const char *desc;
96 #ifdef DUMP_SCRIPTS
97  const char *sig;
98 #endif
99  };
100 
101  const CommandEntry *_commands;
102  int16 _commandsMax;
103 
104  void cmd_branchTrue();
105  void cmd_branchFalse();
106  void cmd_branch();
107  void cmd_true();
108  void cmd_false();
109  void cmd_push();
110  void cmd_not();
111  void cmd_add();
112  void cmd_sub();
113  void cmd_mul();
114  void cmd_div();
115  void cmd_mod();
116  void cmd_band();
117  void cmd_bor();
118  void cmd_bnot();
119  void cmd_lt();
120  void cmd_eq();
121  void cmd_gt();
122  void cmd_loadConstant();
123  void cmd_loadVariable();
124  void cmd_getObjectProperty();
125  void cmd_setObjectProperty();
126  void cmd_set();
127  void cmd_print();
128  void cmd_terpri();
129  void cmd_printNumber();
130  void cmd_vref();
131  void cmd_vset();
132  void cmd_vsize();
133  void cmd_exit();
134  void cmd_return();
135  void cmd_call();
136  void cmd_svar();
137  void cmd_sset();
138  void cmd_split();
139  void cmd_snlit();
140  void cmd_yorn();
141  void cmd_save();
142  void cmd_restore();
143  void cmd_arg();
144  void cmd_aset();
145  void cmd_tmp();
146  void cmd_tset();
147  void cmd_tspace();
148  void cmd_class();
149  void cmd_objectp();
150  void cmd_vectorp();
151  void cmd_restart();
152  void cmd_rand();
153  void cmd_randomize();
154  void cmd_send();
155  void cmd_extend();
156  void cmd_catch();
157  void cmd_cdone();
158  void cmd_throw();
159  void cmd_functionp();
160  void cmd_le();
161  void cmd_ge();
162  void cmd_varx();
163  void cmd_setx();
164 
165 };
166 
167 } // End of namespace Made
168 
169 #endif /* MADE_H */
Definition: script.h:93
Definition: made.h:68
Definition: script.h:72
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: console.h:27
Definition: scriptfuncs.h:42
Definition: script.h:40