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()
const
{
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)
const
{
61
if
(index >= kScriptStackSize)
62
error
(
"ScriptStack::peek(%d) Stack underflow"
, index);
63
else
if
(index < 0)
64
error
(
"ScriptStack::peek(%d) Stack overflow"
, index);
65
return
_stack[index];
66
}
67
inline
void
poke(int16 index, int16 value) {
68
if
(index >= kScriptStackSize)
69
error
(
"ScriptStack::poke(%d) Stack underflow"
, index);
70
else
if
(index < 0)
71
error
(
"ScriptStack::poke(%d) Stack overflow"
, index);
72
_stack[index] = value;
73
}
74
inline
void
alloc(int16 count) { _stackPos -= count; }
75
inline
void
free(int16 count) { _stackPos += count; }
76
inline
int16 getStackPos()
const
{
return
_stackPos; }
77
inline
void
setStackPos(int16 stackPtr) {
78
if
(stackPtr > kScriptStackSize)
79
error
(
"ScriptStack::setStackPos(%d) Stack underflow"
, stackPtr);
80
else
if
(stackPtr < 0)
81
error
(
"ScriptStack::setStackPos(%d) Stack overflow"
, stackPtr);
82
_stackPos = stackPtr;
83
}
84
inline
int16 *getStackPtr() {
return
&_stack[_stackPos]; }
85
protected
:
86
int16 _stack[kScriptStackSize];
87
int16 _stackPos;
88
};
89
90
class
ScriptInterpreter
{
91
public
:
92
ScriptInterpreter
(
MadeEngine
*vm);
93
~ScriptInterpreter
();
94
int16 runScript(int16 scriptObjectIndex, int16 argc = 0, int16 *argv =
nullptr
);
95
#ifdef DUMP_SCRIPTS
96
void
dumpScript(int16 objectIndex,
int
*opcodeStats,
int
*externStats);
97
void
dumpObject(int16 objectIndex);
98
void
dumpAllScripts();
99
#endif
100
protected
:
101
MadeEngine
*_vm;
102
103
ScriptStack
_stack;
104
int16 _entryStackPos, _localStackPos;
105
int16 _runningScriptObjectIndex;
106
const
byte
*_codeBase, *_codeIp;
107
bool
_running;
108
109
ScriptFunctions
*_functions;
110
111
byte
readByte();
112
int16 readInt16();
113
114
typedef
void (
ScriptInterpreter
::*CommandProc)();
115
struct
CommandEntry
{
116
CommandProc proc;
117
const
char
*desc;
118
#ifdef DUMP_SCRIPTS
119
const
char
*sig;
120
#endif
121
};
122
123
const
CommandEntry
*_commands;
124
int16 _commandsMax;
125
126
void
cmd_branchTrue();
127
void
cmd_branchFalse();
128
void
cmd_branch();
129
void
cmd_true();
130
void
cmd_false();
131
void
cmd_push();
132
void
cmd_not();
133
void
cmd_add();
134
void
cmd_sub();
135
void
cmd_mul();
136
void
cmd_div();
137
void
cmd_mod();
138
void
cmd_band();
139
void
cmd_bor();
140
void
cmd_bnot();
141
void
cmd_lt();
142
void
cmd_eq();
143
void
cmd_gt();
144
void
cmd_loadConstant();
145
void
cmd_loadVariable();
146
void
cmd_getObjectProperty();
147
void
cmd_setObjectProperty();
148
void
cmd_set();
149
void
cmd_print();
150
void
cmd_terpri();
151
void
cmd_printNumber();
152
void
cmd_vref();
153
void
cmd_vset();
154
void
cmd_vsize();
155
void
cmd_exit();
156
void
cmd_return();
157
void
cmd_call();
158
void
cmd_svar();
159
void
cmd_sset();
160
void
cmd_split();
161
void
cmd_snlit();
162
void
cmd_yorn();
163
void
cmd_save();
164
void
cmd_restore();
165
void
cmd_arg();
166
void
cmd_aset();
167
void
cmd_tmp();
168
void
cmd_tset();
169
void
cmd_tspace();
170
void
cmd_class();
171
void
cmd_objectp();
172
void
cmd_vectorp();
173
void
cmd_restart();
174
void
cmd_rand();
175
void
cmd_randomize();
176
void
cmd_send();
177
void
cmd_extend();
178
void
cmd_catch();
179
void
cmd_cdone();
180
void
cmd_throw();
181
void
cmd_functionp();
182
void
cmd_le();
183
void
cmd_ge();
184
void
cmd_varx();
185
void
cmd_setx();
186
187
};
188
189
}
// End of namespace Made
190
191
#endif
/* MADE_SCRIPT_H */
Made::MadeEngine
Definition:
made.h:69
Made::ScriptFunctions
Definition:
scriptfuncs.h:38
Made::ScriptInterpreter
Definition:
script.h:90
Made::ScriptStack
Definition:
script.h:40
error
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Made
Definition:
console.h:27
Made::ScriptInterpreter::CommandEntry
Definition:
script.h:115
engines
made
script.h
Generated on Sun Nov 22 2026 09:35:02 for ScummVM API documentation by
1.9.4