1 
2 // this file is shared by quake and qcc
3 
4 typedef int	func_t;
5 typedef int	string_t;
6 
7 typedef enum {ev_void, ev_string, ev_float, ev_vector, ev_entity, ev_field, ev_function, ev_pointer, ev_bad = -1} etype_t;
8 
9 
10 #define	OFS_NULL		0
11 #define	OFS_RETURN		1
12 #define	OFS_PARM0		4		// leave 3 ofs for each parm to hold vectors
13 #define	OFS_PARM1		7
14 #define	OFS_PARM2		10
15 #define	OFS_PARM3		13
16 #define	OFS_PARM4		16
17 #define	OFS_PARM5		19
18 #define	OFS_PARM6		22
19 #define	OFS_PARM7		25
20 #define	RESERVED_OFS	28
21 
22 
23 // indices into op table
24 enum {
25 	OP_DONE,
26 	OP_MUL_F,
27 	OP_MUL_V,
28 	OP_MUL_FV,
29 	OP_MUL_VF,
30 	OP_DIV_F,
31 	OP_ADD_F,
32 	OP_ADD_V,
33 	OP_ADD_EF,
34 	OP_ADD_FE,
35 
36 	OP_SUB_F,
37 	OP_SUB_V,
38 
39 	OP_EQ_F,
40 	OP_EQ_V,
41 	OP_EQ_S,
42 	OP_EQ_E,
43 	OP_EQ_FNC,
44 
45 	OP_NE_F,
46 	OP_NE_V,
47 	OP_NE_S,
48 	OP_NE_E,
49 	OP_NE_FNC,
50 
51 	OP_LE,
52 	OP_GE,
53 	OP_LT,
54 	OP_GT,
55 
56 	OP_LOAD_F,
57 	OP_LOAD_V,
58 	OP_LOAD_S,
59 	OP_LOAD_ENT,
60 	OP_LOAD_FLD,
61 	OP_LOAD_FNC,
62 
63 	OP_ADDRESS,
64 
65 	OP_STORE_F,
66 	OP_STORE_V,
67 	OP_STORE_S,
68 	OP_STORE_ENT,
69 	OP_STORE_FLD,
70 	OP_STORE_FNC,
71 
72 	OP_STOREP_F,
73 	OP_STOREP_V,
74 	OP_STOREP_S,
75 	OP_STOREP_ENT,
76 	OP_STOREP_FLD,
77 	OP_STOREP_FNC,
78 
79 	OP_RETURN,
80 	OP_NOT_F,
81 	OP_NOT_V,
82 	OP_NOT_S,
83 	OP_NOT_ENT,
84 	OP_NOT_FNC,
85 	OP_IF,
86 	OP_IFNOT,
87 	OP_CALL0,
88 	OP_CALL1,
89 	OP_CALL2,
90 	OP_CALL3,
91 	OP_CALL4,
92 	OP_CALL5,
93 	OP_CALL6,
94 	OP_CALL7,
95 	OP_CALL8,
96 	OP_STATE,
97 	OP_GOTO,
98 	OP_AND,
99 	OP_OR,
100 
101 	OP_BITAND,
102 	OP_BITOR,
103 
104 	OP_ARRAY_F,
105 	OP_ARRAY_S,
106 	OP_ARRAY_V
107 };
108 
109 // actual opcodes
110 enum {
111 	OP2_DONE,
112 	OP2_MUL_F,
113 	OP2_MUL_V,
114 	OP2_MUL_FV,
115 	OP2_MUL_VF,
116 	OP2_DIV_F,
117 	OP2_ADD_F,
118 	OP2_ADD_V,
119 	OP2_SUB_F,
120 	OP2_SUB_V,
121 
122 	OP2_EQ_F,
123 	OP2_EQ_V,
124 	OP2_EQ_S,
125 	OP2_EQ_E,
126 	OP2_EQ_FNC,
127 
128 	OP2_NE_F,
129 	OP2_NE_V,
130 	OP2_NE_S,
131 	OP2_NE_E,
132 	OP2_NE_FNC,
133 
134 	OP2_LE,
135 	OP2_GE,
136 	OP2_LT,
137 	OP2_GT,
138 
139 	OP2_LOAD_F,
140 	OP2_LOAD_V,
141 	OP2_LOAD_S,
142 	OP2_LOAD_ENT,
143 	OP2_LOAD_FLD,
144 	OP2_LOAD_FNC,
145 
146 	OP2_ADDRESS,
147 
148 	OP2_STORE_F,
149 	OP2_STORE_V,
150 	OP2_STORE_S,
151 	OP2_STORE_ENT,
152 	OP2_STORE_FLD,
153 	OP2_STORE_FNC,
154 
155 	OP2_STOREP_F,
156 	OP2_STOREP_V,
157 	OP2_STOREP_S,
158 	OP2_STOREP_ENT,
159 	OP2_STOREP_FLD,
160 	OP2_STOREP_FNC,
161 
162 	OP2_RETURN,
163 	OP2_NOT_F,
164 	OP2_NOT_V,
165 	OP2_NOT_S,
166 	OP2_NOT_ENT,
167 	OP2_NOT_FNC,
168 	OP2_IF,
169 	OP2_IFNOT,
170 	OP2_CALL0,
171 	OP2_CALL1,
172 	OP2_CALL2,
173 	OP2_CALL3,
174 	OP2_CALL4,
175 	OP2_CALL5,
176 	OP2_CALL6,
177 	OP2_CALL7,
178 	OP2_CALL8,
179 	OP2_STATE,
180 	OP2_GOTO,
181 	OP2_AND,
182 	OP2_OR,
183 
184 	OP2_BITAND,
185 	OP2_BITOR
186 };
187 
188 typedef struct statement_s
189 {
190 	unsigned short	op;
191 	short	a,b,c;
192 } dstatement_t;
193 
194 typedef struct
195 {
196 	unsigned short	type;		// if DEF_SAVEGLOBGAL bit is set
197 								// the variable needs to be saved in savegames
198 	unsigned short	ofs;
199 	int			s_name;
200 } ddef_t;
201 #define	DEF_SAVEGLOBGAL	(1<<15)
202 
203 #define	MAX_PARMS	8
204 
205 typedef struct
206 {
207 	int		first_statement;	// negative numbers are builtins
208 	int		parm_start;
209 	int		locals;				// total ints of parms + locals
210 
211 	int		profile;		// runtime
212 
213 	int		s_name;
214 	int		s_file;			// source file defined in
215 
216 	int		numparms;
217 	byte	parm_size[MAX_PARMS];
218 } dfunction_t;
219 
220 
221 #define	PROG_VERSION	6
222 typedef struct
223 {
224 	int		version;
225 	int		crc;			// check of header file
226 
227 	int		ofs_statements;
228 	int		numstatements;	// statement 0 is an error
229 
230 	int		ofs_globaldefs;
231 	int		numglobaldefs;
232 
233 	int		ofs_fielddefs;
234 	int		numfielddefs;
235 
236 	int		ofs_functions;
237 	int		numfunctions;	// function 0 is an empty
238 
239 	int		ofs_strings;
240 	int		numstrings;		// first string is a null string
241 
242 	int		ofs_globals;
243 	int		numglobals;
244 
245 	int		entityfields;
246 } dprograms_t;
247 
248