1 /*
2  * pr_comp.h
3  * PROGS structures: This file is shared by Hexen II and HCC
4  *
5  * $Id: pr_comp.h 5028 2013-01-02 20:24:48Z sezero $
6  *
7  * Copyright (C) 1996-1997  Id Software, Inc.
8  * Copyright (C) 1997-1998  Raven Software Corp.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or (at
13  * your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  * See the GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
24  */
25 
26 #ifndef __PR_COMP_H
27 #define __PR_COMP_H
28 
29 typedef int	func_t;
30 typedef int	string_t;
31 
32 typedef enum
33 {
34 	ev_bad = -1,
35 	ev_void = 0,
36 	ev_string,
37 	ev_float,
38 	ev_vector,
39 	ev_entity,
40 	ev_field,
41 	ev_function,
42 	ev_pointer
43 } etype_t;
44 
45 #define	OFS_NULL		0
46 #define	OFS_RETURN		1
47 #define	OFS_PARM0		4	// leave 3 ofs for each parm to hold vectors
48 #define	OFS_PARM1		7
49 #define	OFS_PARM2		10
50 #define	OFS_PARM3		13
51 #define	OFS_PARM4		16
52 #define	OFS_PARM5		19
53 #define	OFS_PARM6		22
54 #define	OFS_PARM7		25
55 #define	RESERVED_OFS	28
56 
57 #define	IMMEDIATE_NAME	"I+"		/* was "IMMEDIATE" in qcc */
58 
59 enum
60 {
61 	OP_DONE,
62 	OP_MUL_F,
63 	OP_MUL_V,
64 	OP_MUL_FV,
65 	OP_MUL_VF,
66 	OP_DIV_F,
67 	OP_ADD_F,
68 	OP_ADD_V,
69 	OP_SUB_F,
70 	OP_SUB_V,
71 
72 	OP_EQ_F,
73 	OP_EQ_V,
74 	OP_EQ_S,
75 	OP_EQ_E,
76 	OP_EQ_FNC,
77 
78 	OP_NE_F,
79 	OP_NE_V,
80 	OP_NE_S,
81 	OP_NE_E,
82 	OP_NE_FNC,
83 
84 	OP_LE,
85 	OP_GE,
86 	OP_LT,
87 	OP_GT,
88 
89 	OP_LOAD_F,
90 	OP_LOAD_V,
91 	OP_LOAD_S,
92 	OP_LOAD_ENT,
93 	OP_LOAD_FLD,
94 	OP_LOAD_FNC,
95 
96 	OP_ADDRESS,
97 
98 	OP_STORE_F,
99 	OP_STORE_V,
100 	OP_STORE_S,
101 	OP_STORE_ENT,
102 	OP_STORE_FLD,
103 	OP_STORE_FNC,
104 
105 	OP_STOREP_F,
106 	OP_STOREP_V,
107 	OP_STOREP_S,
108 	OP_STOREP_ENT,
109 	OP_STOREP_FLD,
110 	OP_STOREP_FNC,
111 
112 	OP_RETURN,
113 	OP_NOT_F,
114 	OP_NOT_V,
115 	OP_NOT_S,
116 	OP_NOT_ENT,
117 	OP_NOT_FNC,
118 	OP_IF,
119 	OP_IFNOT,
120 	OP_CALL0,
121 	OP_CALL1,
122 	OP_CALL2,
123 	OP_CALL3,
124 	OP_CALL4,
125 	OP_CALL5,
126 	OP_CALL6,
127 	OP_CALL7,
128 	OP_CALL8,
129 	OP_STATE,
130 	OP_GOTO,
131 	OP_AND,
132 	OP_OR,
133 
134 	OP_BITAND,
135 	OP_BITOR,
136 
137 	OP_MULSTORE_F,
138 	OP_MULSTORE_V,
139 	OP_MULSTOREP_F,
140 	OP_MULSTOREP_V,
141 
142 	OP_DIVSTORE_F,
143 	OP_DIVSTOREP_F,
144 
145 	OP_ADDSTORE_F,
146 	OP_ADDSTORE_V,
147 	OP_ADDSTOREP_F,
148 	OP_ADDSTOREP_V,
149 
150 	OP_SUBSTORE_F,
151 	OP_SUBSTORE_V,
152 	OP_SUBSTOREP_F,
153 	OP_SUBSTOREP_V,
154 
155 	OP_FETCH_GBL_F,
156 	OP_FETCH_GBL_V,
157 	OP_FETCH_GBL_S,
158 	OP_FETCH_GBL_E,
159 	OP_FETCH_GBL_FNC,
160 
161 	OP_CSTATE,
162 	OP_CWSTATE,
163 
164 	OP_THINKTIME,
165 
166 	OP_BITSET,
167 	OP_BITSETP,
168 	OP_BITCLR,
169 	OP_BITCLRP,
170 
171 	OP_RAND0,
172 	OP_RAND1,
173 	OP_RAND2,
174 	OP_RANDV0,
175 	OP_RANDV1,
176 	OP_RANDV2,
177 
178 	OP_SWITCH_F,
179 	OP_SWITCH_V,
180 	OP_SWITCH_S,
181 	OP_SWITCH_E,
182 	OP_SWITCH_FNC,
183 
184 	OP_CASE,
185 	OP_CASERANGE
186 };
187 
188 typedef struct statement_v6_s
189 {
190 	unsigned short	op;
191 	short	a, b, c;
192 } dstatement_v6_t;
193 
194 typedef struct statement_v7_s
195 {
196 	unsigned short	pad;
197 	unsigned short	op;
198 	int	a, b, c;
199 } dstatement_v7_t;
200 
201 typedef struct
202 {
203 	unsigned short	type;	// if DEF_SAVEGLOBAL bit is set
204 				// the variable needs to be saved in savegames
205 	unsigned short	ofs;
206 	int		s_name;
207 } ddef_v6_t;
208 
209 typedef struct
210 {
211 	unsigned short	pad;
212 	unsigned short	type;	// if DEF_SAVEGLOBAL bit is set
213 				// the variable needs to be saved in savegames
214 	int		ofs;
215 	int		s_name;
216 } ddef_v7_t;
217 
218 COMPILE_TIME_ASSERT(dstatement_v6_t, sizeof(dstatement_v6_t) == 8);
219 COMPILE_TIME_ASSERT(dstatement_v7_t, sizeof(dstatement_v7_t) == 16);
220 COMPILE_TIME_ASSERT(ddef_v6_t, sizeof(ddef_v6_t) == 8);
221 COMPILE_TIME_ASSERT(ddef_v7_t, sizeof(ddef_v7_t) == 12);
222 
223 #define	DEF_SAVEGLOBAL	(1<<15)
224 
225 #define	MAX_PARMS	8
226 
227 typedef struct
228 {
229 	int		first_statement;	// negative numbers are builtins
230 	int		parm_start;
231 	int		locals;			// total ints of parms + locals
232 
233 	int		profile;		// runtime
234 
235 	int		s_name;
236 	int		s_file;			// source file defined in
237 
238 	int		numparms;
239 	byte	parm_size[MAX_PARMS];
240 } dfunction_t;
241 
242 
243 #define	PROG_VERSION_V6		6
244 #define	PROG_VERSION_V7		7
245 
246 // process the progs internally as version 7:
247 #define	PROG_VERSION		(PROG_VERSION_V7)
248 typedef ddef_v7_t	ddef_t;
249 typedef dstatement_v7_t	dstatement_t;
250 
251 typedef struct
252 {
253 	int		version;
254 	int		crc;		// check of header file
255 
256 	int		ofs_statements;
257 	int		numstatements;	// statement 0 is an error
258 
259 	int		ofs_globaldefs;
260 	int		numglobaldefs;
261 
262 	int		ofs_fielddefs;
263 	int		numfielddefs;
264 
265 	int		ofs_functions;
266 	int		numfunctions;	// function 0 is an empty
267 
268 	int		ofs_strings;
269 	int		numstrings;	// first string is a null string
270 
271 	int		ofs_globals;
272 	int		numglobals;
273 
274 	int		entityfields;
275 } dprograms_t;
276 
277 #endif	/* __PR_COMP_H */
278 
279