]> icculus.org git repositories - divverent/darkplaces.git/blob - pr_comp.h
Merge branch 'master' into dp1
[divverent/darkplaces.git] / pr_comp.h
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20
21 // this file is shared by quake and qcc
22
23 #ifndef PR_COMP_H
24 #define PR_COMP_H
25
26 typedef unsigned int    func_t;
27 typedef int     string_t;
28
29 typedef enum etype_e {ev_void, ev_string, ev_float, ev_vector, ev_entity, ev_field, ev_function, ev_pointer} etype_t;
30
31
32 #define OFS_NULL                0
33 #define OFS_RETURN              1
34 #define OFS_PARM0               4               // leave 3 ofs for each parm to hold vectors
35 #define OFS_PARM1               7
36 #define OFS_PARM2               10
37 #define OFS_PARM3               13
38 #define OFS_PARM4               16
39 #define OFS_PARM5               19
40 #define OFS_PARM6               22
41 #define OFS_PARM7               25
42 #define RESERVED_OFS    28
43
44
45 enum opcode_e
46 {
47         OP_DONE,
48         OP_MUL_F,
49         OP_MUL_V,
50         OP_MUL_FV,
51         OP_MUL_VF,
52         OP_DIV_F,
53         OP_ADD_F,
54         OP_ADD_V,
55         OP_SUB_F,
56         OP_SUB_V,
57
58         OP_EQ_F,
59         OP_EQ_V,
60         OP_EQ_S,
61         OP_EQ_E,
62         OP_EQ_FNC,
63
64         OP_NE_F,
65         OP_NE_V,
66         OP_NE_S,
67         OP_NE_E,
68         OP_NE_FNC,
69
70         OP_LE,
71         OP_GE,
72         OP_LT,
73         OP_GT,
74
75         OP_LOAD_F,
76         OP_LOAD_V,
77         OP_LOAD_S,
78         OP_LOAD_ENT,
79         OP_LOAD_FLD,
80         OP_LOAD_FNC,
81
82         OP_ADDRESS,
83
84         OP_STORE_F,
85         OP_STORE_V,
86         OP_STORE_S,
87         OP_STORE_ENT,
88         OP_STORE_FLD,
89         OP_STORE_FNC,
90
91         OP_STOREP_F,
92         OP_STOREP_V,
93         OP_STOREP_S,
94         OP_STOREP_ENT,
95         OP_STOREP_FLD,
96         OP_STOREP_FNC,
97
98         OP_RETURN,
99         OP_NOT_F,
100         OP_NOT_V,
101         OP_NOT_S,
102         OP_NOT_ENT,
103         OP_NOT_FNC,
104         OP_IF,
105         OP_IFNOT,
106         OP_CALL0,
107         OP_CALL1,
108         OP_CALL2,
109         OP_CALL3,
110         OP_CALL4,
111         OP_CALL5,
112         OP_CALL6,
113         OP_CALL7,
114         OP_CALL8,
115         OP_STATE,
116         OP_GOTO,
117         OP_AND,
118         OP_OR,
119
120         OP_BITAND,
121         OP_BITOR,
122
123
124
125
126         //these following ones are Hexen 2 constants.
127
128         OP_MULSTORE_F,
129         OP_MULSTORE_V,
130         OP_MULSTOREP_F,
131         OP_MULSTOREP_V,
132
133         OP_DIVSTORE_F,  //70
134         OP_DIVSTOREP_F,
135
136         OP_ADDSTORE_F,
137         OP_ADDSTORE_V,
138         OP_ADDSTOREP_F,
139         OP_ADDSTOREP_V,
140
141         OP_SUBSTORE_F,
142         OP_SUBSTORE_V,
143         OP_SUBSTOREP_F,
144         OP_SUBSTOREP_V,
145
146         OP_FETCH_GBL_F, //80
147         OP_FETCH_GBL_V,
148         OP_FETCH_GBL_S,
149         OP_FETCH_GBL_E,
150         OP_FETCH_GBL_FNC,
151
152         OP_CSTATE,
153         OP_CWSTATE,
154
155         OP_THINKTIME,
156
157         OP_BITSET,
158         OP_BITSETP,
159         OP_BITCLR,              //90
160         OP_BITCLRP,
161
162         OP_RAND0,
163         OP_RAND1,
164         OP_RAND2,
165         OP_RANDV0,
166         OP_RANDV1,
167         OP_RANDV2,
168
169         OP_SWITCH_F,
170         OP_SWITCH_V,
171         OP_SWITCH_S,    //100
172         OP_SWITCH_E,
173         OP_SWITCH_FNC,
174
175         OP_CASE,
176         OP_CASERANGE,
177
178
179
180
181
182         //the rest are added
183         //mostly they are various different ways of adding two vars with conversions.
184
185         OP_CALL1H,
186         OP_CALL2H,
187         OP_CALL3H,
188         OP_CALL4H,
189         OP_CALL5H,
190         OP_CALL6H,              //110
191         OP_CALL7H,
192         OP_CALL8H,
193
194
195         OP_STORE_I,
196         OP_STORE_IF,
197         OP_STORE_FI,
198
199         OP_ADD_I,
200         OP_ADD_FI,
201         OP_ADD_IF,              //110
202
203         OP_SUB_I,
204         OP_SUB_FI,
205         OP_SUB_IF,
206
207         OP_CONV_ITOF,
208         OP_CONV_FTOI,
209         OP_CP_ITOF,
210         OP_CP_FTOI,
211         OP_LOAD_I,
212         OP_STOREP_I,
213         OP_STOREP_IF,   //120
214         OP_STOREP_FI,
215
216         OP_BITAND_I,
217         OP_BITOR_I,
218
219         OP_MUL_I,
220         OP_DIV_I,
221         OP_EQ_I,
222         OP_NE_I,
223
224         OP_IFNOTS,
225         OP_IFS,
226
227         OP_NOT_I,               //130
228
229         OP_DIV_VF,
230
231         OP_XOR_I,
232         OP_RSHIFT_I,
233         OP_LSHIFT_I,
234
235         OP_GLOBALADDRESS,
236         OP_POINTER_ADD, //32 bit pointers
237
238         OP_LOADA_F,
239         OP_LOADA_V,
240         OP_LOADA_S,
241         OP_LOADA_ENT,   //140
242         OP_LOADA_FLD,
243         OP_LOADA_FNC,
244         OP_LOADA_I,
245
246         OP_STORE_P,
247         OP_LOAD_P,
248
249         OP_LOADP_F,
250         OP_LOADP_V,
251         OP_LOADP_S,
252         OP_LOADP_ENT,
253         OP_LOADP_FLD,   //150
254         OP_LOADP_FNC,
255         OP_LOADP_I,
256
257         OP_LE_I,
258         OP_GE_I,
259         OP_LT_I,
260         OP_GT_I,
261
262         OP_LE_IF,
263         OP_GE_IF,
264         OP_LT_IF,
265         OP_GT_IF,               //160
266
267         OP_LE_FI,
268         OP_GE_FI,
269         OP_LT_FI,
270         OP_GT_FI,
271
272         OP_EQ_IF,
273         OP_EQ_FI,
274
275         //-------------------------------------
276         //string manipulation.
277         OP_ADD_SF,      //(char*)c = (char*)a + (float)b
278         OP_SUB_S,       //(float)c = (char*)a - (char*)b
279         OP_STOREP_C,//(float)c = *(char*)b = (float)a
280         OP_LOADP_C,     //(float)c = *(char*)                                   //170
281         //-------------------------------------
282
283
284         OP_MUL_IF,
285         OP_MUL_FI,
286         OP_MUL_VI,
287         OP_MUL_IV,
288         OP_DIV_IF,
289         OP_DIV_FI,
290         OP_BITAND_IF,
291         OP_BITOR_IF,
292         OP_BITAND_FI,
293         OP_BITOR_FI,            //180
294         OP_AND_I,
295         OP_OR_I,
296         OP_AND_IF,
297         OP_OR_IF,
298         OP_AND_FI,
299         OP_OR_FI,
300         OP_NE_IF,
301         OP_NE_FI,
302
303 //erm... FTEQCC doesn't make use of these... These are for DP.
304         OP_GSTOREP_I,
305         OP_GSTOREP_F,           //190
306         OP_GSTOREP_ENT,
307         OP_GSTOREP_FLD,         // integers
308         OP_GSTOREP_S,
309         OP_GSTOREP_FNC,         // pointers
310         OP_GSTOREP_V,
311         OP_GADDRESS,
312         OP_GLOAD_I,
313         OP_GLOAD_F,
314         OP_GLOAD_FLD,
315         OP_GLOAD_ENT,           //200
316         OP_GLOAD_S,
317         OP_GLOAD_FNC,
318         OP_BOUNDCHECK,
319
320 //back to ones that we do use.
321         OP_STOREP_P,
322         OP_PUSH,        //push 4octets onto the local-stack (which is ALWAYS poped on function return). Returns a pointer.
323         OP_POP,         //pop those ones that were pushed (don't over do it). Needs assembler.
324
325         OP_SWITCH_I,
326         OP_GLOAD_V,
327
328 //extensions for fixing stuff
329         OP_IF_F,
330         OP_IFNOT_F,
331         
332         OP_NUMOPS
333 };
334
335
336 typedef struct statement_s
337 {
338         unsigned short  op;
339         signed short    a,b,c;
340 }
341 dstatement_t;
342
343 typedef struct ddef_s
344 {
345         unsigned short  type;           // if DEF_SAVEGLOBGAL bit is set
346                                                                 // the variable needs to be saved in savegames
347         unsigned short  ofs;
348         int                     s_name;
349 }
350 ddef_t;
351 #define DEF_SAVEGLOBAL  (1<<15)
352
353 #define MAX_PARMS       8
354
355 typedef struct dfunction_s
356 {
357         int             first_statement;        // negative numbers are builtins
358         int             parm_start;
359         int             locals;                         // total ints of parms + locals
360
361         int             profile;                // runtime
362
363         int             s_name;
364         int             s_file;                 // source file defined in
365
366         int             numparms;
367         unsigned char   parm_size[MAX_PARMS];
368 }
369 dfunction_t;
370
371 typedef struct mfunction_s
372 {
373         int             first_statement;        // negative numbers are builtins
374         int             parm_start;
375         int             locals;                         // total ints of parms + locals
376
377         // these are doubles so that they can count up to 54bits or so rather than 32bit
378         double  profile;                // runtime
379         double  builtinsprofile; // cost of builtin functions called by this function
380         double  callcount; // times the functions has been called since the last profile call
381         double  totaltime; // total execution time of this function DIRECTLY FROM THE ENGINE
382
383         int             s_name;
384         int             s_file;                 // source file defined in
385
386         int             numparms;
387         unsigned char   parm_size[MAX_PARMS];
388 }
389 mfunction_t;
390
391
392 #define PROG_VERSION    6
393 #define PROG_EXTENDED   7
394 typedef struct dprograms_s
395 {
396         int             version;
397         int             crc;                    // check of header file
398
399         int             ofs_statements;
400         int             numstatements;  // statement 0 is an error
401
402         int             ofs_globaldefs;
403         int             numglobaldefs;
404
405         int             ofs_fielddefs;
406         int             numfielddefs;
407
408         int             ofs_functions;
409         int             numfunctions;   // function 0 is an empty
410
411         int             ofs_strings;
412         int             numstrings;             // first string is a null string
413
414         int             ofs_globals;
415         int             numglobals;
416
417         int             entityfields;
418 }
419 dprograms_t;
420
421 #endif
422