]> de.git.xonotic.org Git - voretournament/voretournament.git/blob - misc/mediasource/extra/fteqcc-src/pr_comp.h
fteqcc source
[voretournament/voretournament.git] / misc / mediasource / extra / fteqcc-src / pr_comp.h
1 // this file is shared by the execution and compiler
2
3 /*i'm part way through making this work
4 I've given up now that I can't work out a way to load pointers.
5 Setting them should be fine.
6 */
7 #ifndef __PR_COMP_H__
8 #define __PR_COMP_H__
9
10
11 /*this distinction is made as the execution uses c pointers while compiler uses pointers from the start of the string table of the current progs*/
12 #ifdef COMPILER
13 typedef int QCC_string_t;
14 #else
15 //typedef char *string_t;
16 #endif
17
18 //typedef enum {ev_void, ev_string, ev_float, ev_vector, ev_entity, ev_field, ev_function, ev_pointer, ev_integer, ev_struct, ev_union} etype_t;
19 //                              0                       1               2                       3                       4               5                       6                               7                       8               9                       10
20
21 #define OFS_NULL                0
22 #define OFS_RETURN              1
23 #define OFS_PARM0               4               // leave 3 ofs for each parm to hold vectors
24 #define OFS_PARM1               7
25 #define OFS_PARM2               10
26 #define OFS_PARM3               13
27 #define OFS_PARM4               16
28 #define OFS_PARM5               19
29 #define OFS_PARM6               22
30 #define OFS_PARM7               25
31 #define RESERVED_OFS    28
32
33
34 enum {
35         OP_DONE,        //0
36         OP_MUL_F,
37         OP_MUL_V,
38         OP_MUL_FV,
39         OP_MUL_VF,
40         OP_DIV_F,
41         OP_ADD_F,
42         OP_ADD_V,
43         OP_SUB_F,
44         OP_SUB_V,
45         
46         OP_EQ_F,        //10
47         OP_EQ_V,
48         OP_EQ_S,
49         OP_EQ_E,
50         OP_EQ_FNC,
51         
52         OP_NE_F,
53         OP_NE_V,
54         OP_NE_S,
55         OP_NE_E,
56         OP_NE_FNC,
57         
58         OP_LE,  //20
59         OP_GE,
60         OP_LT,
61         OP_GT,
62
63         OP_LOAD_F,
64         OP_LOAD_V,
65         OP_LOAD_S,
66         OP_LOAD_ENT,
67         OP_LOAD_FLD,
68         OP_LOAD_FNC,
69
70         OP_ADDRESS,     //30
71
72         OP_STORE_F,
73         OP_STORE_V,
74         OP_STORE_S,
75         OP_STORE_ENT,
76         OP_STORE_FLD,
77         OP_STORE_FNC,
78
79         OP_STOREP_F,
80         OP_STOREP_V,
81         OP_STOREP_S,
82         OP_STOREP_ENT,  //40
83         OP_STOREP_FLD,
84         OP_STOREP_FNC,
85
86         OP_RETURN,
87         OP_NOT_F,
88         OP_NOT_V,
89         OP_NOT_S,
90         OP_NOT_ENT,
91         OP_NOT_FNC,
92         OP_IF,
93         OP_IFNOT,               //50
94         OP_CALL0,               //careful... hexen2 and q1 have different calling conventions
95         OP_CALL1,               //remap hexen2 calls to OP_CALL2H
96         OP_CALL2,
97         OP_CALL3,
98         OP_CALL4,
99         OP_CALL5,
100         OP_CALL6,
101         OP_CALL7,
102         OP_CALL8,
103         OP_STATE,               //60
104         OP_GOTO,
105         OP_AND,
106         OP_OR,
107         
108         OP_BITAND,
109         OP_BITOR,
110
111         
112         //these following ones are Hexen 2 constants.
113         
114         OP_MULSTORE_F,
115         OP_MULSTORE_V,
116         OP_MULSTOREP_F,
117         OP_MULSTOREP_V,
118
119         OP_DIVSTORE_F,  //70
120         OP_DIVSTOREP_F,
121
122         OP_ADDSTORE_F,
123         OP_ADDSTORE_V,
124         OP_ADDSTOREP_F,
125         OP_ADDSTOREP_V,
126
127         OP_SUBSTORE_F,
128         OP_SUBSTORE_V,
129         OP_SUBSTOREP_F,
130         OP_SUBSTOREP_V,
131
132         OP_FETCH_GBL_F, //80
133         OP_FETCH_GBL_V,
134         OP_FETCH_GBL_S,
135         OP_FETCH_GBL_E,
136         OP_FETCH_GBL_FNC,
137
138         OP_CSTATE,
139         OP_CWSTATE,
140
141         OP_THINKTIME,
142
143         OP_BITSET,
144         OP_BITSETP,
145         OP_BITCLR,              //90
146         OP_BITCLRP,
147
148         OP_RAND0,
149         OP_RAND1,
150         OP_RAND2,
151         OP_RANDV0,
152         OP_RANDV1,
153         OP_RANDV2,
154
155         OP_SWITCH_F,
156         OP_SWITCH_V,
157         OP_SWITCH_S,    //100
158         OP_SWITCH_E,
159         OP_SWITCH_FNC,
160
161         OP_CASE,
162         OP_CASERANGE,
163
164
165
166
167
168         //the rest are added
169         //mostly they are various different ways of adding two vars with conversions.
170
171         OP_CALL1H,
172         OP_CALL2H,
173         OP_CALL3H,
174         OP_CALL4H,
175         OP_CALL5H,
176         OP_CALL6H,              //110
177         OP_CALL7H,
178         OP_CALL8H,
179
180
181         OP_STORE_I,
182         OP_STORE_IF,
183         OP_STORE_FI,
184         
185         OP_ADD_I,
186         OP_ADD_FI,
187         OP_ADD_IF,              //110
188   
189         OP_SUB_I,
190         OP_SUB_FI,
191         OP_SUB_IF,
192
193         OP_CONV_ITOF,
194         OP_CONV_FTOI,
195         OP_CP_ITOF,
196         OP_CP_FTOI,
197         OP_LOAD_I,
198         OP_STOREP_I,
199         OP_STOREP_IF,   //120
200         OP_STOREP_FI,
201
202         OP_BITAND_I,
203         OP_BITOR_I,
204
205         OP_MUL_I,
206         OP_DIV_I,
207         OP_EQ_I,
208         OP_NE_I,
209
210         OP_IFNOT_S,
211         OP_IF_S,
212
213         OP_NOT_I,               //130
214
215         OP_DIV_VF,
216
217         OP_XOR_I,
218         OP_RSHIFT_I,
219         OP_LSHIFT_I,
220
221         OP_GLOBALADDRESS,
222         OP_POINTER_ADD, //32 bit pointers
223
224         OP_LOADA_F,
225         OP_LOADA_V,     
226         OP_LOADA_S,
227         OP_LOADA_ENT,   //140
228         OP_LOADA_FLD,           
229         OP_LOADA_FNC,
230         OP_LOADA_I,
231
232         OP_STORE_P,     //152... erm.. wait...
233         OP_LOAD_P,
234
235         OP_LOADP_F,
236         OP_LOADP_V,     
237         OP_LOADP_S,
238         OP_LOADP_ENT,
239         OP_LOADP_FLD,   //150
240         OP_LOADP_FNC,
241         OP_LOADP_I,
242
243         OP_LE_I,
244         OP_GE_I,
245         OP_LT_I,
246         OP_GT_I,
247
248         OP_LE_IF,
249         OP_GE_IF,
250         OP_LT_IF,
251         OP_GT_IF,               //160
252
253         OP_LE_FI,
254         OP_GE_FI,
255         OP_LT_FI,
256         OP_GT_FI,
257
258         OP_EQ_IF,
259         OP_EQ_FI,
260
261         //-------------------------------------
262         //string manipulation.
263         OP_ADD_SF,      //(char*)c = (char*)a + (float)b
264         OP_SUB_S,       //(float)c = (char*)a - (char*)b
265         OP_STOREP_C,//(float)c = *(char*)b = (float)a
266         OP_LOADP_C,     //(float)c = *(char*)                                   //170
267         //-------------------------------------
268
269
270         OP_MUL_IF,
271         OP_MUL_FI,
272         OP_MUL_VI,
273         OP_MUL_IV,
274         OP_DIV_IF,
275         OP_DIV_FI,
276         OP_BITAND_IF,
277         OP_BITOR_IF,
278         OP_BITAND_FI,
279         OP_BITOR_FI,            //180
280         OP_AND_I,
281         OP_OR_I,
282         OP_AND_IF,
283         OP_OR_IF,
284         OP_AND_FI,
285         OP_OR_FI,
286         OP_NE_IF,
287         OP_NE_FI,
288
289 //erm... FTEQCC doesn't make use of these... These are for DP.
290         OP_GSTOREP_I,
291         OP_GSTOREP_F,           //190
292         OP_GSTOREP_ENT,
293         OP_GSTOREP_FLD,         // integers
294         OP_GSTOREP_S,
295         OP_GSTOREP_FNC,         // pointers
296         OP_GSTOREP_V,
297         OP_GADDRESS,
298         OP_GLOAD_I,
299         OP_GLOAD_F,
300         OP_GLOAD_FLD,
301         OP_GLOAD_ENT,           //200
302         OP_GLOAD_S,
303         OP_GLOAD_FNC,
304         OP_BOUNDCHECK,
305
306 //back to ones that we do use.
307         OP_STOREP_P,
308         OP_PUSH,        //push 4octets onto the local-stack (which is ALWAYS poped on function return). Returns a pointer.
309         OP_POP,         //pop those ones that were pushed (don't over do it). Needs assembler.
310
311         OP_SWITCH_I,//hmm.
312         OP_GLOAD_V,
313
314         OP_IF_F,
315         OP_IFNOT_F,
316
317         OP_NUMREALOPS,
318
319         /*
320         These ops are emulated out, always, and are only present in the compiler.
321         */
322
323         OP_BITSET_I,
324         OP_BITSETP_I,
325
326         OP_MULSTORE_I,
327         OP_DIVSTORE_I,
328         OP_ADDSTORE_I,
329         OP_SUBSTORE_I,
330         OP_MULSTOREP_I,
331         OP_DIVSTOREP_I,
332         OP_ADDSTOREP_I,
333         OP_SUBSTOREP_I,
334
335         OP_MULSTORE_IF,
336         OP_MULSTOREP_IF,
337         OP_DIVSTORE_IF,
338         OP_DIVSTOREP_IF,
339         OP_ADDSTORE_IF,
340         OP_ADDSTOREP_IF,
341         OP_SUBSTORE_IF,
342         OP_SUBSTOREP_IF,
343
344         OP_MULSTORE_FI,
345         OP_MULSTOREP_FI,
346         OP_DIVSTORE_FI,
347         OP_DIVSTOREP_FI,
348         OP_ADDSTORE_FI,
349         OP_ADDSTOREP_FI,
350         OP_SUBSTORE_FI,
351         OP_SUBSTOREP_FI,
352
353         OP_NUMOPS
354 };
355
356
357 #ifndef COMPILER
358 typedef struct statement16_s
359 {
360         unsigned short  op;
361         unsigned short  a,b,c;
362 } dstatement16_t;
363 typedef struct statement32_s
364 {
365         unsigned int    op;
366         unsigned int    a,b,c;
367 } dstatement32_t;
368 #else
369 typedef struct QCC_statement16_s
370 {
371         unsigned short  op;
372         unsigned short  a,b,c;
373 } QCC_dstatement16_t;
374 typedef struct QCC_statement32_s
375 {
376         unsigned int    op;
377         unsigned int    a,b,c;
378 } QCC_dstatement32_t;
379 #define QCC_dstatement_t QCC_dstatement32_t
380 #endif
381
382 //these should be the same except the string type
383 #ifndef COMPILER
384 typedef struct ddef16_s
385 {
386         unsigned short  type;           // if DEF_SAVEGLOBAL bit is set
387                                                                 // the variable needs to be saved in savegames
388         unsigned short  ofs;
389         string_t                s_name;
390 } ddef16_t;
391
392 typedef struct ddef32_s
393 {
394         unsigned int    type;           // if DEF_SAVEGLOBAL bit is set
395                                                                 // the variable needs to be saved in savegames
396         unsigned int    ofs;
397         string_t                s_name;
398 } ddef32_t;
399
400 typedef struct fdef_s
401 {
402         unsigned int    type;           // if DEF_SAVEGLOBAL bit is set
403                                                                 // the variable needs to be saved in savegames
404         unsigned int    ofs;
405         unsigned int    progsofs;       //used at loading time, so maching field offsets (unions/members) are positioned at the same runtime offset.
406         char *          name;
407 } fdef_t;
408
409 typedef void *ddefXX_t;
410 #else
411 typedef struct QCC_ddef16_s
412 {
413         unsigned short  type;           // if DEF_SAVEGLOBAL bit is set
414                                                                 // the variable needs to be saved in savegames
415         unsigned short  ofs;
416         QCC_string_t            s_name;
417 } QCC_ddef16_t;
418
419 typedef struct QCC_ddef32_s
420 {
421         unsigned int    type;           // if DEF_SAVEGLOBAL bit is set
422                                                                 // the variable needs to be saved in savegames
423         unsigned int    ofs;
424         QCC_string_t            s_name;
425 } QCC_ddef32_t;
426
427 #define QCC_ddef_t QCC_ddef32_t
428 #endif
429
430 #define DEF_SAVEGLOBAL          (1<<15)
431 #define DEF_SHARED              (1<<14)
432
433 #define MAX_PARMS       8
434
435 #ifndef COMPILER
436 typedef struct
437 {
438         int             first_statement;        // negative numbers are builtins
439         int             parm_start;
440         int             locals;                         // total ints of parms + locals
441         
442         int             profile;                // runtime
443         
444         string_t        s_name;
445         string_t        s_file;                 // source file defined in
446         
447         int             numparms;
448         qbyte   parm_size[MAX_PARMS];
449 } dfunction_t;
450 #else
451 typedef struct
452 {
453         unsigned int            first_statement;        // negative numbers are builtins
454         unsigned int            parm_start;
455         int             locals;                         // total ints of parms + locals
456         
457         int             profile;                // runtime
458         
459         QCC_string_t    s_name;
460         QCC_string_t    s_file;                 // source file defined in
461         
462         int             numparms;
463         qbyte   parm_size[MAX_PARMS];
464 } QCC_dfunction_t;
465 #endif
466
467
468 #define PROG_VERSION    6
469 #define PROG_KKQWSVVERSION 7
470 #define PROG_EXTENDEDVERSION    7
471 #define PROG_SECONDARYVERSION16 (*(int*)"1FTE" ^ *(int*)"PROG") //something unlikly and still meaningful (to me)
472 #define PROG_SECONDARYVERSION32 (*(int*)"1FTE" ^ *(int*)"32B ") //something unlikly and still meaningful (to me)
473 typedef struct
474 {
475         int             version;
476         int             crc;                    // check of header file
477         
478         unsigned int            ofs_statements; //comp 1
479         unsigned int            numstatements;  // statement 0 is an error
480
481         unsigned int            ofs_globaldefs; //comp 2
482         unsigned int            numglobaldefs;
483         
484         unsigned int            ofs_fielddefs;  //comp 4
485         unsigned int            numfielddefs;
486         
487         unsigned int            ofs_functions;  //comp 8
488         unsigned int            numfunctions;   // function 0 is an empty
489         
490         unsigned int            ofs_strings;    //comp 16
491         unsigned int            numstrings;             // first string is a null string
492
493         unsigned int            ofs_globals;    //comp 32
494         unsigned int            numglobals;
495         
496         unsigned int            entityfields;
497
498         //debug / version 7 extensions
499         unsigned int            ofsfiles;       //non list format. no comp
500         unsigned int            ofslinenums;    //numstatements big     //comp 64
501         unsigned int            ofsbodylessfuncs;       //no comp
502         unsigned int            numbodylessfuncs;
503
504         unsigned int    ofs_types;      //comp 128
505         unsigned int    numtypes;
506         unsigned int    blockscompressed;
507
508         int     secondaryversion;       //Constant - to say that any version 7 progs are actually ours, not someone else's alterations.
509 } dprograms_t;
510 #define standard_dprograms_t_size ((int)&((dprograms_t*)NULL)->ofsfiles)
511
512 #endif
513
514
515
516
517
518 typedef struct {
519         char filename[128];
520         int size;
521         int compsize;
522         int compmethod;
523         int ofs;
524 } includeddatafile_t;
525
526
527
528
529 typedef struct typeinfo_s
530 {
531         etype_t type;
532
533         int             next;
534         int             aux_type;
535         int             num_parms;
536
537         int             ofs;    //inside a structure.
538         int             size;
539         char    *name;
540 } typeinfo_t;