2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
21 // this file is shared by quake and qcc
26 typedef unsigned int func_t;
29 typedef enum etype_e {ev_void, ev_string, ev_float, ev_vector, ev_entity, ev_field, ev_function, ev_pointer} etype_t;
34 #define OFS_PARM0 4 // leave 3 ofs for each parm to hold vectors
42 #define RESERVED_OFS 28
123 // TODO: actually support Hexen 2?
125 OP_MULSTORE_F, //66 redundant, for h2 compat
126 OP_MULSTORE_VF, //67 redundant, for h2 compat
130 OP_DIVSTORE_F, //70 redundant, for h2 compat
133 OP_ADDSTORE_F, //72 redundant, for h2 compat
134 OP_ADDSTORE_V, //73 redundant, for h2 compat
138 OP_SUBSTORE_F, //76 redundant, for h2 compat
139 OP_SUBSTORE_V, //77 redundant, for h2 compat
143 OP_FETCH_GBL_F, //80 has built-in bounds check
144 OP_FETCH_GBL_V, //81 has built-in bounds check
145 OP_FETCH_GBL_S, //82 has built-in bounds check
146 OP_FETCH_GBL_E, //83 has built-in bounds check
147 OP_FETCH_GBL_FNC,//84 has built-in bounds check
152 OP_THINKTIME, //87 shortcut for OPA.nextthink=time+OPB
154 OP_BITSETSTORE_F, //88 redundant, for h2 compat
155 OP_BITSETSTOREP_F, //89
156 OP_BITCLRSTORE_F, //90
157 OP_BITCLRSTOREP_F, //91
159 OP_RAND0, //92 OPC = random()
160 OP_RAND1, //93 OPC = random()*OPA
161 OP_RAND2, //94 OPC = random()*(OPB-OPA)+OPA
162 OP_RANDV0, //95 //3d/box versions of the above.
166 OP_SWITCH_F, //98 switchref=OPA; PC += OPB --- the jump allows the jump table (such as it is) to be inserted after the block.
172 OP_CASE, //103 if (OPA===switchref) PC += OPB
173 OP_CASERANGE, //104 if (OPA<=switchref&&switchref<=OPB) PC += OPC
175 //hexen2 calling convention (-TH2 requires us to remap OP_CALLX to these on load, -TFTE just uses these directly.)
176 OP_CALL1H, //OFS_PARM0=OPB
177 OP_CALL2H, //OFS_PARM0,1=OPB,OPC
178 OP_CALL3H, //no extra args
309 OP_UNUSED, //used to be OP_STOREP_P, which is now emulated with OP_STOREP_I, fteqcc nor fte generated it
310 OP_PUSH, //push 4octets onto the local-stack (which is ALWAYS poped on function return). Returns a pointer.
311 OP_POP, //pop those ones that were pushed (don't over do it). Needs assembler.
316 OP_IF_F, //compares as an actual float, instead of treating -0 as positive.
319 OP_STOREF_V, //3 elements...
320 OP_STOREF_F, //1 fpu element...
321 OP_STOREF_S, //1 string reference
322 OP_STOREF_I, //1 non-string reference/int
327 typedef struct statement16_s
333 typedef struct statement32_s
340 typedef struct ddef16_s
342 unsigned short type; // if DEF_SAVEGLOBAL bit is set
343 // the variable needs to be saved in savegames
348 typedef struct ddef32_s
350 unsigned int type; // if DEF_SAVEGLOBAL bit is set
351 // the variable needs to be saved in savegames
356 #define DEF_SAVEGLOBAL (1<<15)
360 typedef struct dfunction_s
362 int first_statement; // negative numbers are builtins
364 int locals; // total ints of parms + locals
366 int profile; // runtime
369 int s_file; // source file defined in
372 unsigned char parm_size[MAX_PARMS];
376 typedef struct mfunction_s
378 int first_statement; // negative numbers are builtins
380 int locals; // total ints of parms + locals
382 // these are doubles so that they can count up to 54bits or so rather than 32bit
383 double tprofile; // realtime in this function
384 double tbprofile; // realtime in builtins called by this function (NOTE: builtins also have a tprofile!)
385 double profile; // runtime
386 double builtinsprofile; // cost of builtin functions called by this function
387 double callcount; // times the functions has been called since the last profile call
388 double totaltime; // total execution time of this function DIRECTLY FROM THE ENGINE
389 double tprofile_total; // runtime (NOTE: tbprofile_total makes no real sense, so not accumulating that)
390 double profile_total; // runtime
391 double builtinsprofile_total; // cost of builtin functions called by this function
395 int s_file; // source file defined in
398 unsigned char parm_size[MAX_PARMS];
402 typedef struct mstatement_s
405 int operand[3]; // always a global or -1 for unused
406 int jumpabsolute; // only used by IF, IFNOT, GOTO
411 #define PROG_VERSION 6
412 typedef struct dprograms_s
415 int crc; // check of header file
417 unsigned int ofs_statements;
418 unsigned int numstatements; // statement 0 is an error
420 unsigned int ofs_globaldefs;
421 unsigned int numglobaldefs;
423 unsigned int ofs_fielddefs;
424 unsigned int numfielddefs;
426 unsigned int ofs_functions;
427 unsigned int numfunctions; // function 0 is an empty
429 unsigned int ofs_strings;
430 unsigned int numstrings; // first string is a null string
432 unsigned int ofs_globals;
433 unsigned int numglobals;
435 unsigned int entityfields;
439 typedef struct dprograms_v7_s
440 { //extended header written by fteqcc.
441 dprograms_t v6; //for easier casting.
443 //debug / version 7 extensions
444 unsigned int ofsfiles; //ignored. deprecated, should be 0. source files can instead be embedded by simply treating the .dat as a zip.
445 unsigned int ofslinenums; //ignored. alternative to external .lno files.
446 unsigned int ofsbodylessfuncs; //unsupported. function names imported from other modules. must be 0.
447 unsigned int numbodylessfuncs; //unsupported. must be 0.
449 unsigned int ofs_types; //unsupported+deprecated. rich type info. must be 0.
450 unsigned int numtypes; //unsupported+deprecated. rich type info. must be 0.
451 unsigned int blockscompressed; //unsupported. per-block compression. must be 0.
453 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.
454 #define PROG_SECONDARYVERSION16 ((('1'<<0)|('F'<<8)|('T'<<16)|('E'<<24))^(('P'<<0)|('R'<<8)|('O'<<16)|('G'<<24))) //regular 16bit statements.
455 #define PROG_SECONDARYVERSION32 ((('1'<<0)|('F'<<8)|('T'<<16)|('E'<<24))^(('3'<<0)|('2'<<8)|('B'<<16)|(' '<<24))) //statements+globaldefs+fielddefs extended to 32bit.