]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - pr_comp.h
pr_comp: Add the rest of FTEQW's opcodes
[xonotic/darkplaces.git] / pr_comp.h
index 45cc9f13b538254245620e93a4454c917e41edd4..d1ad4b7b8d31f535ba7ddff06318c7d126202d1f 100644 (file)
--- a/pr_comp.h
+++ b/pr_comp.h
@@ -42,7 +42,7 @@ typedef enum etype_e {ev_void, ev_string, ev_float, ev_vector, ev_entity, ev_fie
 #define        RESERVED_OFS    28
 
 
-enum opcode_e
+typedef enum opcode_e
 {
        OP_DONE,
        OP_MUL_F,
@@ -118,25 +118,241 @@ enum opcode_e
        OP_OR,
 
        OP_BITAND,
-       OP_BITOR
-};
+       OP_BITOR,
+
+       // TODO: actually support Hexen 2?
+       
+       OP_MULSTORE_F,  //66 redundant, for h2 compat
+       OP_MULSTORE_VF, //67 redundant, for h2 compat
+       OP_MULSTOREP_F, //68
+       OP_MULSTOREP_VF,//69
+
+       OP_DIVSTORE_F,  //70 redundant, for h2 compat
+       OP_DIVSTOREP_F, //71
+
+       OP_ADDSTORE_F,  //72 redundant, for h2 compat
+       OP_ADDSTORE_V,  //73 redundant, for h2 compat
+       OP_ADDSTOREP_F, //74
+       OP_ADDSTOREP_V, //75
+
+       OP_SUBSTORE_F,  //76 redundant, for h2 compat
+       OP_SUBSTORE_V,  //77 redundant, for h2 compat
+       OP_SUBSTOREP_F, //78
+       OP_SUBSTOREP_V, //79
+
+       OP_FETCH_GBL_F, //80 has built-in bounds check
+       OP_FETCH_GBL_V, //81 has built-in bounds check
+       OP_FETCH_GBL_S, //82 has built-in bounds check
+       OP_FETCH_GBL_E, //83 has built-in bounds check
+       OP_FETCH_GBL_FNC,//84 has built-in bounds check
+
+       OP_CSTATE,              //85
+       OP_CWSTATE,             //86
+
+       OP_THINKTIME,   //87 shortcut for OPA.nextthink=time+OPB
+
+       OP_BITSETSTORE_F,       //88 redundant, for h2 compat
+       OP_BITSETSTOREP_F,      //89
+       OP_BITCLRSTORE_F,       //90
+       OP_BITCLRSTOREP_F,      //91
+
+       OP_RAND0,               //92    OPC = random()
+       OP_RAND1,               //93    OPC = random()*OPA
+       OP_RAND2,               //94    OPC = random()*(OPB-OPA)+OPA
+       OP_RANDV0,              //95    //3d/box versions of the above.
+       OP_RANDV1,              //96
+       OP_RANDV2,              //97
+
+       OP_SWITCH_F,    //98    switchref=OPA; PC += OPB   --- the jump allows the jump table (such as it is) to be inserted after the block.
+       OP_SWITCH_V,    //99
+       OP_SWITCH_S,    //100
+       OP_SWITCH_E,    //101
+       OP_SWITCH_FNC,  //102
+
+       OP_CASE,                //103   if (OPA===switchref) PC += OPB
+       OP_CASERANGE,   //104   if (OPA<=switchref&&switchref<=OPB) PC += OPC
+
+       //hexen2 calling convention (-TH2 requires us to remap OP_CALLX to these on load, -TFTE just uses these directly.)
+       OP_CALL1H,      //OFS_PARM0=OPB
+       OP_CALL2H,      //OFS_PARM0,1=OPB,OPC
+       OP_CALL3H,      //no extra args
+       OP_CALL4H,
+       OP_CALL5H,
+       OP_CALL6H,
+       OP_CALL7H,
+       OP_CALL8H,
+
+       OP_STORE_I,
+       OP_STORE_IF,
+       OP_STORE_FI,
+
+       OP_ADD_I,
+       OP_ADD_FI,
+       OP_ADD_IF,
+
+       OP_SUB_I,
+       OP_SUB_FI,
+       OP_SUB_IF,
+
+       OP_CONV_IF,
+       OP_CONV_FI,
+       
+       OP_LOADP_IF,
+       OP_LOADP_FI,
+
+       OP_LOAD_I,
+
+       OP_STOREP_I,
+       OP_STOREP_IF,
+       OP_STOREP_FI,
+
+       OP_BITAND_I,
+       OP_BITOR_I,
+
+       OP_MUL_I,
+       OP_DIV_I,
+       OP_EQ_I,
+       OP_NE_I,
+
+       OP_IFNOT_S,
+
+       OP_IF_S,
+
+       OP_NOT_I,
+
+       OP_DIV_VF,
+
+       OP_BITXOR_I,
+       OP_RSHIFT_I,
+       OP_LSHIFT_I,
+
+       OP_GLOBALADDRESS,
+       OP_ADD_PIW,
+
+       OP_LOADA_F,
+       OP_LOADA_V,     
+       OP_LOADA_S,
+       OP_LOADA_ENT,
+       OP_LOADA_FLD,
+       OP_LOADA_FNC,
+       OP_LOADA_I,
+
+       OP_STORE_P,
+       OP_LOAD_P,
+
+       OP_LOADP_F,
+       OP_LOADP_V,     
+       OP_LOADP_S,
+       OP_LOADP_ENT,
+       OP_LOADP_FLD,
+       OP_LOADP_FNC,
+       OP_LOADP_I,
+
+       OP_LE_I,
+       OP_GE_I,
+       OP_LT_I,
+       OP_GT_I,
+       
+       OP_LE_IF,
+       OP_GE_IF,
+       OP_LT_IF,
+       OP_GT_IF,
+
+       OP_LE_FI,
+       OP_GE_FI,
+       OP_LT_FI,
+       OP_GT_FI,
+
+       OP_EQ_IF,
+       OP_EQ_FI,
+
+       OP_ADD_SF,
+       OP_SUB_S,
+       OP_STOREP_C,
+       OP_LOADP_C,
+
+       OP_MUL_IF,
+       OP_MUL_FI,
+       OP_MUL_VI,
+       OP_MUL_IV,
+       OP_DIV_IF,
+       OP_DIV_FI,
+       OP_BITAND_IF,
+       OP_BITOR_IF,
+       OP_BITAND_FI,
+       OP_BITOR_FI,
+       OP_AND_I,
+       OP_OR_I,
+       OP_AND_IF,
+       OP_OR_IF,
+       OP_AND_FI,
+       OP_OR_FI,
+       OP_NE_IF,
+       OP_NE_FI,
+
+       OP_GSTOREP_I,
+       OP_GSTOREP_F,
+       OP_GSTOREP_ENT,
+       OP_GSTOREP_FLD,
+       OP_GSTOREP_S,
+       OP_GSTOREP_FNC,         
+       OP_GSTOREP_V,
+       OP_GADDRESS,
+       OP_GLOAD_I,
+       OP_GLOAD_F,
+       OP_GLOAD_FLD,
+       OP_GLOAD_ENT,
+       OP_GLOAD_S,
+       OP_GLOAD_FNC,
+       OP_BOUNDCHECK,
+
+       OP_UNUSED,      //used to be OP_STOREP_P, which is now emulated with OP_STOREP_I, fteqcc nor fte generated it
+       OP_PUSH,        //push 4octets onto the local-stack (which is ALWAYS poped on function return). Returns a pointer.
+       OP_POP,         //pop those ones that were pushed (don't over do it). Needs assembler.
+       OP_SWITCH_I,
+
+       OP_GLOAD_V,
+
+       OP_IF_F,                //compares as an actual float, instead of treating -0 as positive.
+       OP_IFNOT_F,
+
+       OP_STOREF_V,    //3 elements...
+       OP_STOREF_F,    //1 fpu element...
+       OP_STOREF_S,    //1 string reference
+       OP_STOREF_I,    //1 non-string reference/int
+}
+opcode_t;
 
 
-typedef struct statement_s
+typedef struct statement16_s
 {
        unsigned short  op;
        signed short    a,b,c;
 }
-dstatement_t;
+dstatement16_t;
+typedef struct statement32_s
+{
+       unsigned int    op;
+       signed int      a,b,c;
+}
+dstatement32_t;
 
-typedef struct ddef_s
+typedef struct ddef16_s
 {
-       unsigned short  type;           // if DEF_SAVEGLOBGAL bit is set
+       unsigned short  type;           // if DEF_SAVEGLOBAL bit is set
                                                                // the variable needs to be saved in savegames
        unsigned short  ofs;
        int                     s_name;
 }
-ddef_t;
+ddef16_t;
+typedef struct ddef32_s
+{
+       unsigned int    type;           // if DEF_SAVEGLOBAL bit is set
+                                                               // the variable needs to be saved in savegames
+       unsigned int    ofs;
+       int                     s_name;
+}
+ddef32_t, mdef_t;
 #define        DEF_SAVEGLOBAL  (1<<15)
 
 #define        MAX_PARMS       8
@@ -164,10 +380,13 @@ typedef struct mfunction_s
        int             locals;                         // total ints of parms + locals
 
        // these are doubles so that they can count up to 54bits or so rather than 32bit
+       double  tprofile;           // realtime in this function
+       double  tbprofile;          // realtime in builtins called by this function (NOTE: builtins also have a tprofile!)
        double  profile;                // runtime
        double  builtinsprofile; // cost of builtin functions called by this function
        double  callcount; // times the functions has been called since the last profile call
        double  totaltime; // total execution time of this function DIRECTLY FROM THE ENGINE
+       double  tprofile_total;         // runtime (NOTE: tbprofile_total makes no real sense, so not accumulating that)
        double  profile_total;          // runtime
        double  builtinsprofile_total; // cost of builtin functions called by this function
        int     recursion;
@@ -180,6 +399,14 @@ typedef struct mfunction_s
 }
 mfunction_t;
 
+typedef struct mstatement_s
+{
+       opcode_t        op;
+       int                     operand[3]; // always a global or -1 for unused
+       int                     jumpabsolute; // only used by IF, IFNOT, GOTO
+}
+mstatement_t;
+
 
 #define        PROG_VERSION    6
 typedef struct dprograms_s
@@ -187,27 +414,47 @@ typedef struct dprograms_s
        int             version;
        int             crc;                    // check of header file
 
-       int             ofs_statements;
-       int             numstatements;  // statement 0 is an error
+       unsigned int            ofs_statements;
+       unsigned int            numstatements;  // statement 0 is an error
 
-       int             ofs_globaldefs;
-       int             numglobaldefs;
+       unsigned int            ofs_globaldefs;
+       unsigned int            numglobaldefs;
 
-       int             ofs_fielddefs;
-       int             numfielddefs;
+       unsigned int            ofs_fielddefs;
+       unsigned int            numfielddefs;
 
-       int             ofs_functions;
-       int             numfunctions;   // function 0 is an empty
+       unsigned int            ofs_functions;
+       unsigned int            numfunctions;   // function 0 is an empty
 
-       int             ofs_strings;
-       int             numstrings;             // first string is a null string
+       unsigned int            ofs_strings;
+       unsigned int            numstrings;             // first string is a null string
 
-       int             ofs_globals;
-       int             numglobals;
+       unsigned int            ofs_globals;
+       unsigned int            numglobals;
 
-       int             entityfields;
+       unsigned int            entityfields;
 }
 dprograms_t;
 
+typedef struct dprograms_v7_s
+{      //extended header written by fteqcc.
+       dprograms_t     v6;     //for easier casting.
+
+       //debug / version 7 extensions
+       unsigned int    ofsfiles;                       //ignored. deprecated, should be 0. source files can instead be embedded by simply treating the .dat as a zip.
+       unsigned int    ofslinenums;            //ignored. alternative to external .lno files.
+       unsigned int    ofsbodylessfuncs;       //unsupported. function names imported from other modules. must be 0.
+       unsigned int    numbodylessfuncs;       //unsupported. must be 0.
+
+       unsigned int    ofs_types;                      //unsupported+deprecated. rich type info. must be 0.
+       unsigned int    numtypes;                       //unsupported+deprecated. rich type info. must be 0.
+       unsigned int    blockscompressed;       //unsupported. per-block compression. must be 0.
+
+       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.
+#define PROG_SECONDARYVERSION16 ((('1'<<0)|('F'<<8)|('T'<<16)|('E'<<24))^(('P'<<0)|('R'<<8)|('O'<<16)|('G'<<24)))      //regular 16bit statements.
+#define PROG_SECONDARYVERSION32 ((('1'<<0)|('F'<<8)|('T'<<16)|('E'<<24))^(('3'<<0)|('2'<<8)|('B'<<16)|(' '<<24)))      //statements+globaldefs+fielddefs extended to 32bit.
+}
+dprograms_v7_t;
+
 #endif