ScummVM API documentation
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Modules
Pages
code.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
* Based on the original sources
22
* Faery Tale II -- The Halls of the Dead
23
* (c) 1993-1996 The Wyrmkeep Entertainment Co.
24
*/
25
26
#ifndef SAGA2_CODE_H
27
#define SAGA2_CODE_H
28
29
namespace
Saga2
{
30
31
// types of operations for code generation
32
// note that the macros listed below depend on the ordering of this
33
// table to determine things like unary-op, binary-op, etc.
34
35
enum
op_types {
36
kOpUndefined = 0,
37
38
// internal operations
39
40
kOpNextblock,
// continue execution at next block
41
kOpDup,
// duplicate 16-bit value on stack
42
kOpDrop,
// drop 16-bit value on stack
43
44
// primary values
45
46
kOpZero,
// push a zero on the stack
47
kOpOne,
// push a one on the stack
48
kOpConstint,
// constant integer
49
kOpConstid,
// constant id reference
50
kOpStrlit,
// string literal
51
kOpSym,
// symbol address
52
kOpSymref,
// symbol contents
53
kOpClassref,
// reference to "this"
54
kOpDeref,
// dereference of an ID
55
56
// references within this module
57
58
kOpGetflag,
// read from flag bit (mode)
59
kOpGetbyte,
// read from byte field (mode)
60
kOpGetint,
// read from integer field (mode)
61
kOpGetstr,
// read from string field (mode)
62
kOpGetid,
// read from id field (mode)
63
64
kOpPutflag,
// put to flag bit (mode)
65
kOpPutbyte,
// put to byte field (mode)
66
kOpPutint,
// put to integer field (mode)
67
kOpPutstr,
// put to string field (mode)
68
kOpPutid,
// put to id field (mode)
69
70
kOpPea,
// push effective address onto stack
71
72
// 'void' versions consume their arguments
73
74
kOpPutflagV,
// put to flag bit (mode)
75
kOpPutbyteV,
// put to byte field (mode)
76
kOpPutintV,
// put to integer field (mode)
77
kOpPutstrV,
// put to string field (mode)
78
kOpPutidV,
// put to id field (mode)
79
80
// function call
81
82
kOpCallNear,
// call function in same segment
83
kOpCallFar,
// call function in other segment
84
kOpCcall,
// call C function
85
kOpCcallV,
// call C function ()
86
kOpCallMember,
// call member function
87
kOpCallMemberV,
// call member function ()
88
89
kOpEnter,
// enter a function
90
kOpReturn,
// return from function
91
kOpReturn_v,
// return nothing from function
92
93
// branches
94
95
kOpJmp,
96
kOpJmpTrueV,
// test arg and consume
97
kOpJmpFalseV,
// test arg and consume
98
kOpJmpTrue,
// test arg and don't consume
99
kOpJmpDalse,
// test arg and don't consume
100
kOpJmpSwitch,
// switch statement (integer)
101
kOpJmpStrswitch,
// switch statement (string)
102
kOpJmpRandom,
// random jump
103
104
// unary operators
105
106
kOpNegate,
107
kOpNot,
108
kOpCompl,
109
110
kOpIncV,
// increment, don't push
111
kOpDecV,
// decrement, don't push
112
kOpPostinc,
113
kOpPostdec,
114
115
// arithmetic
116
117
kOpAdd,
118
kOpSub,
119
kOpMul,
120
kOpDiv,
121
kOpMod,
122
123
// conditional
124
125
kOpConditional,
126
kOpComma,
127
128
// comparison
129
130
kOpEq,
131
kOpNe,
132
kOpGt,
133
kOpLt,
134
kOpGe,
135
kOpLe,
136
137
// string comparison
138
139
kOpStrEq,
140
kOpStrNe,
141
kOpStrGt,
142
kOpStrLt,
143
kOpStrGe,
144
kOpStrLe,
145
146
// shift
147
148
kOpRsh,
149
kOpLsh,
150
151
// bitwise
152
153
kOpAnd,
154
kOpOr,
155
kOpXor,
156
157
// logical
158
159
kOpLand,
160
kOpLor,
161
kOpLxor,
162
163
// string functions
164
165
kOpStrcat,
// string concatenation
166
kOpStrformat,
// string formatting
167
168
// assignment operators -- none of these are actually compiled into
169
// code (they become get/put type operations)
170
171
kOpAssign,
172
// none of these are even used currently...
173
kOpAsplus,
174
kOpAsminus,
175
kOpAstimes,
176
kOpAsdiv,
177
kOpAsmod,
178
kOpAsrshift,
179
kOpAslshift,
180
kOpAsand,
181
kOpAsor,
182
183
// Special ops
184
185
kOpSpeak,
186
kOpDialogBegin,
187
kOpDialogEnd,
188
kOpReply,
189
kOpAnimate,
190
191
// New opcodes
192
193
kOpJmp_seedrandom,
// seeded random jump
194
kOpSymrefX,
// get the export number of the symbol
195
196
kOpLast
/* about 90 so far */
197
};
198
199
// addressing modes for get and put
200
201
enum
addr_types {
202
203
// Offset reference to the thread structure
204
205
skAddrThread = 0,
206
207
// Offset reference to the stack
208
209
skAddrStack,
210
211
// Implicit reference to the currently executing segment
212
213
skAddrNear,
214
215
// Implicit reference to data segment
216
217
skAddrData,
218
219
// This addressing mode references any external segment
220
// using a 16-bit segment number and a 16-bit segment offset
221
// which immediately follow the instruction.
222
223
skAddrFar,
224
225
// This addressing mode is used for segment-array addressing
226
// it's a 16-bit segment followed by a 16-bit object number,
227
// followed by a (byte or bit) offset within the object
228
229
skAddrArray,
230
231
// This addressing mode uses a 16-bit segment number
232
// and a 16-bit offset which have been put on the stack.
233
234
// skAddrIndirect, // use SEG:offset on stack
235
// skAddrIndirectIndex, // use SEG:index:offset on stack
236
237
// This addressing mode is used for dereferencing objects.
238
// It consists of an _embedded_ address for retrieving the
239
// object number, followed by a 16-bit segment number for
240
// the dereferenced objects, followed by a 16-bit index
241
// into the dereferenced object.
242
243
// REM: We also need a "far deref" for computing the
244
// dereferenced object's segment number.
245
246
skAddrDeref,
247
248
// Addressing mode used for class member functions. It
249
// specified that the address is relative to whatever
250
// object the 1st argument is referrring to.
251
252
skAddrThis
// relative to arg 1
253
};
254
255
#define IS_CONST(x) ((x) >= kOpConstint && (x) <= kOpConststr)
256
#define IS_ADDRESS(x) ((x) == kOpSym)
257
#define IS_UNOP(x) ((x) >= kOpNegate && (x) <= kOpPostdec)
258
259
#define IS_BINOP(x) ((x) >= kOpAdd && (x) <= kOpStrcat)
260
#define IS_ASOP(x) ((x) >= kOpAssign && (x) <= kOpAsor)
261
262
// #define IS_UNOP2(x) ((x) == kOpGetarray || (x) == kOpPutarray)
263
// #define CONST(op) ((op) >= kOpConstflag && (op) <= kOpConststr)
264
265
// Flags for special statements
266
267
#define SPEAKF_NOANIMATE (1<<0) // speaker should animate
268
#define SPEAKF_ASYNC (1<<1) // async speech.
269
270
#define REPLYF_ONCE (1<<0) // 'once' flag
271
#define REPLYF_SUMMARY (1<<1) // response is only a summary
272
#define REPLYF_CONDITION (1<<2) // response has a condition
273
274
#define ANIMATEF_REPEAT (1<<0)
275
276
// BasicBlock describes a block of generated code
277
278
#ifdef COMPILE_H
279
280
typedef
struct
_BasicBlock {
281
struct
_BasicBlock *next;
// pointer to next block
282
283
short
label;
// label for this block
284
285
struct
_BasicBlock *from[2],
// where we could have come from
286
*jumpto,
// where to go if jump
287
*fallto;
// where to go if fall through
288
289
struct
_Statement *first_st,
// statement list for this bblock
290
*last_st;
// it's a circular list
291
292
ENode *test_expr;
// test expression for jump
293
char
in_flags,
// flags for entering this block
294
jump_type;
// where to go after this block
295
296
uint16 start_offset,
// offset in module of this block
297
jump_offset;
// offset of module of jump at end
298
299
int16 source_file,
// source line of statement
300
source_line;
// source file of statement
301
} BasicBlock;
302
303
// Various flags for the block
304
305
#define BBLOCK_CLABEL (1<<0)
/* bblock begins with a 'C' label */
306
#define BBLOCK_INTLABEL (1<<1)
/* bblock begins with internal label */
307
#define BBLOCK_FIRST (1<<2)
/* first bblock in the function */
308
#define BBLOCK_MANY (1<<3)
/* many guys jump to here */
309
#define BBLOCK_CASE (1<<4)
/* case stmts might not have 'from' ptr */
310
311
// Jump types
312
313
enum
jump_types {
314
kJumpNever = 0,
/* never jump */
315
kJumpFalse,
/* jump on expression if false */
316
kJumpTrue,
/* jump on expression if true */
317
kJumpAlways,
/* jump always */
318
kJumpCjump,
/* 'c' goto stm, jumpto is a label # */
319
kJumpReturn,
/* block ends with a 'return' statement */
320
kJumpSwitch,
/* jumps to lots of places */
321
};
322
#endif
323
/*
324
// Module describes all the code associated with a particular
325
// compilation unit.
326
327
struct Module {
328
uint16 exportCount, // number of symbols exported
329
importCount; // number of symbols imported
330
uint16 exportOffset, // start of export table
331
importOffset; // start of import table
332
333
// Q: Should ModuleName be somewhere else, like in the main program?
334
335
uint16 staticSize; // size of static data
336
uint16 stringOffset; // unused in this version
337
// int16 moduleName; // offset to name of module
338
339
// Followed by list of exports
340
// Followed by list of imports
341
// Followed by symbol names, each NULL-terminated
342
// Followed by actual code blocks
343
344
};
345
346
// Exports: Each Export contains the offset to find the name of
347
// the object. After that is the offset to find the object itself.
348
349
// The first Export is always the module entry point
350
351
struct ModuleExport { // an exported symbol
352
uint16 symbolOffset, // offset in module of symbol name
353
objectOffset; // where to find object
354
};
355
356
// Imports: Each Import contains the offset to find the name of
357
// the object. After that is a blank pointer, which will be filled
358
// in with the real address of the object. When addressing the
359
// imported object, the code in this module will refer to this
360
// ModuleImport entry, and indirectly locate the referenced object.
361
362
struct ModuleImport { // a module xref
363
uint16 symbolOffset; // where, from here, to find name
364
void *objectPointer; // NULL pointer, filled in on load
365
};
366
*/
367
368
}
// end of namespace Saga2
369
370
#endif
Saga2
Definition:
actor.h:32
engines
saga2
code.h
Generated on Wed Apr 9 2025 09:20:01 for ScummVM API documentation by
1.8.13