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
326 // Statements (16 bit format) - 8 bytes each
327 typedef struct statement16_s
334 // Statements (32 bit format) - 16 bytes each
335 typedef struct statement32_s
342 // Global and fielddefs (16 bit format) - 8 bytes each
343 typedef struct ddef16_s
345 uint16_t type; // if DEF_SAVEGLOBAL bit is set
346 // the variable needs to be saved in savegames
350 ddef16_t, dfield16_t;
352 // Global and fielddefs (32 bit format) - 12 bytes each
353 typedef struct ddef32_s
355 uint32_t type; // if DEF_SAVEGLOBAL bit is set
356 // the variable needs to be saved in savegames
360 ddef32_t, dfield32_t, mdef_t;
362 #define DEF_SAVEGLOBAL (1<<15)
366 // Functions - 36 bytes each
367 typedef struct dfunction_s
369 int32_t first_statement; // negative numbers are builtins
370 int32_t parm_start; // first local
371 int32_t locals; // total ints of parms + locals
373 int32_t profile; // runtime
375 int32_t s_name; // function name
376 int32_t s_file; // source file defined in
378 int32_t numparms; // number of args
379 uint8_t parm_size[MAX_PARMS]; // and size
383 typedef struct mfunction_s
385 int32_t first_statement; // negative numbers are builtins
387 int32_t locals; // total ints of parms + locals
389 // these are doubles so that they can count up to 54bits or so rather than 32bit
390 double tprofile; // realtime in this function
391 double tbprofile; // realtime in builtins called by this function (NOTE: builtins also have a tprofile!)
392 double profile; // runtime
393 double builtinsprofile; // cost of builtin functions called by this function
394 double callcount; // times the functions has been called since the last profile call
395 double totaltime; // total execution time of this function DIRECTLY FROM THE ENGINE
396 double tprofile_total; // runtime (NOTE: tbprofile_total makes no real sense, so not accumulating that)
397 double profile_total; // runtime
398 double builtinsprofile_total; // cost of builtin functions called by this function
402 int32_t s_file; // source file defined in
405 uint8_t parm_size[MAX_PARMS];
409 typedef struct mstatement_s
412 int operand[3]; // always a global or -1 for unused
413 int jumpabsolute; // only used by IF, IFNOT, GOTO
418 #define PROG_VERSION 6
419 typedef struct dprograms_s
421 int32_t version; // Version (usually 6)
422 int32_t crc; // CRC-16 of header file. Last 2 bytes are skipped
424 // Sizes of and offsets to each section
425 uint32_t ofs_statements;
426 uint32_t numstatements; // statement 0 is an error
428 uint32_t ofs_globaldefs;
429 uint32_t numglobaldefs;
431 uint32_t ofs_fielddefs;
432 uint32_t numfielddefs;
434 uint32_t ofs_functions;
435 uint32_t numfunctions; // function 0 is an empty
437 uint32_t ofs_strings;
438 uint32_t numstrings; // first string is a null string
440 uint32_t ofs_globals;
443 uint32_t entityfields;
447 typedef struct dprograms_v7_s
448 { //extended header written by fteqcc.
449 dprograms_t v6; //for easier casting.
451 //debug / version 7 extensions
452 uint32_t ofsfiles; //ignored. deprecated, should be 0. source files can instead be embedded by simply treating the .dat as a zip.
453 uint32_t ofslinenums; //ignored. alternative to external .lno files.
454 uint32_t ofsbodylessfuncs; //unsupported. function names imported from other modules. must be 0.
455 uint32_t numbodylessfuncs; //unsupported. must be 0.
457 uint32_t ofs_types; //unsupported+deprecated. rich type info. must be 0.
458 uint32_t numtypes; //unsupported+deprecated. rich type info. must be 0.
459 uint32_t blockscompressed; //unsupported. per-block compression. must be 0.
461 int32_t secondaryversion; //if not known then its kkqwsv's v7, qfcc's v7, or uhexen2's v7, or something. abandon all hope when not recognised.
462 #define PROG_SECONDARYVERSION16 ((('1'<<0)|('F'<<8)|('T'<<16)|('E'<<24))^(('P'<<0)|('R'<<8)|('O'<<16)|('G'<<24))) //regular 16bit statements.
463 #define PROG_SECONDARYVERSION32 ((('1'<<0)|('F'<<8)|('T'<<16)|('E'<<24))^(('3'<<0)|('2'<<8)|('B'<<16)|(' '<<24))) //statements+globaldefs+fielddefs extended to 32bit.