]> git.xonotic.org Git - xonotic/darkplaces.git/blob - pr_comp.h
prvm: Initial experimental implementation of support for 32-bit progs offsets
[xonotic/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 typedef 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         OP_STORE_I = 113,
124
125         OP_ADD_I = 116,
126         OP_ADD_FI,
127         OP_ADD_IF,
128
129         OP_SUB_I,
130         OP_SUB_FI,
131         OP_SUB_IF,
132         OP_CONV_IF,
133         OP_CONV_FI,
134
135         OP_LOAD_I = 126,
136         OP_STOREP_I,
137
138         OP_BITAND_I = 130,
139         OP_BITOR_I,
140
141         OP_MUL_I,
142         OP_DIV_I,
143         OP_EQ_I,
144         OP_NE_I,
145
146         OP_NOT_I = 138,
147
148         OP_DIV_VF,
149         
150         OP_STORE_P = 152,
151
152         OP_LE_I = 161,
153         OP_GE_I,
154         OP_LT_I,
155         OP_GT_I,
156         
157         OP_LE_IF,
158         OP_GE_IF,
159         OP_LT_IF,
160         OP_GT_IF,
161
162         OP_LE_FI,
163         OP_GE_FI,
164         OP_LT_FI,
165         OP_GT_FI,
166
167         OP_EQ_IF,
168         OP_EQ_FI,
169
170         OP_MUL_IF = 179,
171         OP_MUL_FI,
172         OP_MUL_VI,
173         OP_DIV_IF = 183,
174         OP_DIV_FI,
175         OP_BITAND_IF,
176         OP_BITOR_IF,
177         OP_BITAND_FI,
178         OP_BITOR_FI,
179         OP_AND_I,
180         OP_OR_I,
181         OP_AND_IF,
182         OP_OR_IF,
183         OP_AND_FI,
184         OP_OR_FI,
185         OP_NE_IF,
186         OP_NE_FI,
187
188         OP_GSTOREP_I,
189         OP_GSTOREP_F,
190         OP_GSTOREP_ENT,
191         OP_GSTOREP_FLD,
192         OP_GSTOREP_S,
193         OP_GSTOREP_FNC,         
194         OP_GSTOREP_V,
195         OP_GADDRESS,
196         OP_GLOAD_I,
197         OP_GLOAD_F,
198         OP_GLOAD_FLD,
199         OP_GLOAD_ENT,
200         OP_GLOAD_S,
201         OP_GLOAD_FNC,
202         OP_BOUNDCHECK,
203         OP_GLOAD_V = 216
204 }
205 opcode_t;
206
207
208 typedef struct statement16_s
209 {
210         unsigned short  op;
211         signed short    a,b,c;
212 }
213 dstatement16_t;
214 typedef struct statement32_s
215 {
216         unsigned int    op;
217         signed int      a,b,c;
218 }
219 dstatement32_t;
220
221 typedef struct ddef16_s
222 {
223         unsigned short  type;           // if DEF_SAVEGLOBGAL bit is set
224                                                                 // the variable needs to be saved in savegames
225         unsigned short  ofs;
226         int                     s_name;
227 }
228 ddef16_t;
229 typedef struct ddef32_s
230 {
231         unsigned int    type;           // if DEF_SAVEGLOBGAL bit is set
232                                                                 // the variable needs to be saved in savegames
233         unsigned int    ofs;
234         int                     s_name;
235 }
236 ddef32_t, mdef_t;
237 #define DEF_SAVEGLOBAL  (1<<15)
238
239 #define MAX_PARMS       8
240
241 typedef struct dfunction_s
242 {
243         int             first_statement;        // negative numbers are builtins
244         int             parm_start;
245         int             locals;                         // total ints of parms + locals
246
247         int             profile;                // runtime
248
249         int             s_name;
250         int             s_file;                 // source file defined in
251
252         int             numparms;
253         unsigned char   parm_size[MAX_PARMS];
254 }
255 dfunction_t;
256
257 typedef struct mfunction_s
258 {
259         int             first_statement;        // negative numbers are builtins
260         int             parm_start;
261         int             locals;                         // total ints of parms + locals
262
263         // these are doubles so that they can count up to 54bits or so rather than 32bit
264         double  tprofile;           // realtime in this function
265         double  tbprofile;          // realtime in builtins called by this function (NOTE: builtins also have a tprofile!)
266         double  profile;                // runtime
267         double  builtinsprofile; // cost of builtin functions called by this function
268         double  callcount; // times the functions has been called since the last profile call
269         double  totaltime; // total execution time of this function DIRECTLY FROM THE ENGINE
270         double  tprofile_total;         // runtime (NOTE: tbprofile_total makes no real sense, so not accumulating that)
271         double  profile_total;          // runtime
272         double  builtinsprofile_total; // cost of builtin functions called by this function
273         int     recursion;
274
275         int             s_name;
276         int             s_file;                 // source file defined in
277
278         int             numparms;
279         unsigned char   parm_size[MAX_PARMS];
280 }
281 mfunction_t;
282
283 typedef struct mstatement_s
284 {
285         opcode_t        op;
286         int                     operand[3]; // always a global or -1 for unused
287         int                     jumpabsolute; // only used by IF, IFNOT, GOTO
288 }
289 mstatement_t;
290
291
292 #define PROG_VERSION    6
293 typedef struct dprograms_s
294 {
295         int             version;
296         int             crc;                    // check of header file
297
298         unsigned int            ofs_statements;
299         unsigned int            numstatements;  // statement 0 is an error
300
301         unsigned int            ofs_globaldefs;
302         unsigned int            numglobaldefs;
303
304         unsigned int            ofs_fielddefs;
305         unsigned int            numfielddefs;
306
307         unsigned int            ofs_functions;
308         unsigned int            numfunctions;   // function 0 is an empty
309
310         unsigned int            ofs_strings;
311         unsigned int            numstrings;             // first string is a null string
312
313         unsigned int            ofs_globals;
314         unsigned int            numglobals;
315
316         unsigned int            entityfields;
317 }
318 dprograms_t;
319
320 typedef struct dprograms_v7_s
321 {       //extended header written by fteqcc.
322         dprograms_t     v6;     //for easier casting.
323
324         //debug / version 7 extensions
325         unsigned int    ofsfiles;                       //ignored. deprecated, should be 0. source files can instead be embedded by simply treating the .dat as a zip.
326         unsigned int    ofslinenums;            //ignored. alternative to external .lno files.
327         unsigned int    ofsbodylessfuncs;       //unsupported. function names imported from other modules. must be 0.
328         unsigned int    numbodylessfuncs;       //unsupported. must be 0.
329
330         unsigned int    ofs_types;                      //unsupported+deprecated. rich type info. must be 0.
331         unsigned int    numtypes;                       //unsupported+deprecated. rich type info. must be 0.
332         unsigned int    blockscompressed;       //unsupported. per-block compression. must be 0.
333
334         int     secondaryversion;                               //if not known then its kkqwsv's v7, qfcc's v7, or uhexen2's v7, or something. abandon all hope when not recognised.
335 #define PROG_SECONDARYVERSION16 ((('1'<<0)|('F'<<8)|('T'<<16)|('E'<<24))^(('P'<<0)|('R'<<8)|('O'<<16)|('G'<<24)))       //regular 16bit statements.
336 #define PROG_SECONDARYVERSION32 ((('1'<<0)|('F'<<8)|('T'<<16)|('E'<<24))^(('3'<<0)|('2'<<8)|('B'<<16)|(' '<<24)))       //statements+globaldefs+fielddefs extended to 32bit.
337 }
338 dprograms_v7_t;
339
340 #endif
341