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  * Additional copyright for this file:
8  * Copyright (C) 1994-1998 Revolution Software Ltd.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  */
24 
25 #ifndef SWORD2_INTERPRETER_H
26 #define SWORD2_INTERPRETER_H
27 
28 #include "common/endian.h"
29 
30 namespace Sword2 {
31 
32 // Interpreter return codes
33 
34 enum {
35 	IR_STOP		= 0,	// Quit for a cycle
36 	IR_CONT		= 1,	// Continue as normal
37 	IR_TERMINATE	= 2,	// Return without updating the offset
38 	IR_REPEAT	= 3,	// Return; offset at start of function call
39 	IR_GOSUB	= 4	// Return with updated offset
40 };
41 
42 // Get parameter fix so that the playstation version can handle words not on
43 // word boundaries
44 
45 #define Read8ip(var)		{ var = code[ip]; ip++; }
46 #define Read16ip(var)		{ var = (int16)READ_LE_UINT16(code + ip); ip += 2; }
47 #define Read32ip(var)		{ var = (int32)READ_LE_UINT32(code + ip); ip += 4; }
48 #define Read32ipLeaveip(var)	{ var = (int32)READ_LE_UINT32(code + ip); }
49 
50 enum {
51 	// Compiled tokens
52 
53 	CP_END_SCRIPT			= 0,
54 	CP_PUSH_LOCAL_VAR32		= 1,	// Push a local variable on to the stack
55 	CP_PUSH_GLOBAL_VAR32		= 2,	// Push a global variable
56 	CP_POP_LOCAL_VAR32		= 3,	// Pop a local variable from the stack
57 	CP_CALL_MCODE			= 4,	// Call a machine code function
58 	CP_PUSH_LOCAL_ADDR		= 5,	// Push the address of a local variable
59 	CP_PUSH_INT32			= 6,	// Adjust the stack after calling an fn function
60 	CP_SKIPONFALSE			= 7,	// Skip if the bottom value on the stack is false
61 	CP_SKIPALWAYS			= 8,	// Skip a block of code
62 	CP_SWITCH			= 9,	// Switch on last stack value
63 	CP_ADDNPOP_LOCAL_VAR32		= 10,	// Add to a local varible
64 	CP_SUBNPOP_LOCAL_VAR32		= 11,	// Subtract from a local variable
65 	CP_SKIPONTRUE			= 12,	// Skip if the bottom value on the stack is true
66 	CP_POP_GLOBAL_VAR32		= 13,	// Pop a global variable
67 	CP_ADDNPOP_GLOBAL_VAR32		= 14,	// Add to a global variable
68 	CP_SUBNPOP_GLOBAL_VAR32		= 15,	// Subtract from a global variable
69 	CP_DEBUGON			= 16,	// Turn debugging on
70 	CP_DEBUGOFF			= 17,	// Turn debugging off
71 	CP_QUIT				= 18,	// Quit for a cycle
72 	CP_TERMINATE			= 19,	// Quit script completely
73 
74 	// Operators
75 
76 	OP_ISEQUAL			= 20,	// '=='
77 	OP_PLUS				= 21,	// '+'
78 	OP_MINUS			= 22,	// '-'
79 	OP_TIMES			= 23,	// '*'
80 	OP_DIVIDE			= 24,	// '/'
81 	OP_NOTEQUAL			= 25,	// '=='
82 	OP_ANDAND			= 26,	// '&&'
83 	OP_GTTHAN			= 27,	// '>'
84 	OP_LSTHAN			= 28,	// '<'
85 
86 	// More tokens, mixed types
87 
88 	CP_JUMP_ON_RETURNED		= 29,	// Use table of jumps with value returned from fn_mcode
89 	CP_TEMP_TEXT_PROCESS		= 30,	// A dummy text process command for me
90 	CP_SAVE_MCODE_START		= 31,	// Save the mcode code start for restarting when necessary
91 	CP_RESTART_SCRIPT		= 32,	// Start the script from the beginning
92 	CP_PUSH_STRING			= 33,	// Push a pointer to a string on the stack
93 	CP_PUSH_DEREFERENCED_STRUCTURE	= 34,	// Push the address of a structure thing
94 	OP_GTTHANE			= 35,	// >=
95 	OP_LSTHANE			= 36,	// <=
96 	OP_OROR				= 37	// || or OR
97 };
98 
99 } // End of namespace Sword2
100 
101 #endif
102