X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=pr_comp.h;h=d1643b628e15be619dc3b02115222b0e4c2852ce;hp=20801b84c9dda98aea68db85a2b2b3911419dbd9;hb=HEAD;hpb=46a24b411ef2bee4eb2a08da15d38a61b484f471 diff --git a/pr_comp.h b/pr_comp.h index 20801b84..f69b6320 100644 --- a/pr_comp.h +++ b/pr_comp.h @@ -120,22 +120,93 @@ typedef enum opcode_e OP_BITAND, OP_BITOR, - OP_STORE_I = 113, - - OP_ADD_I = 116, + // 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_LOAD_I = 126, OP_STOREP_I, + OP_STOREP_IF, + OP_STOREP_FI, - OP_BITAND_I = 130, + OP_BITAND_I, OP_BITOR_I, OP_MUL_I, @@ -143,13 +214,41 @@ typedef enum opcode_e OP_EQ_I, OP_NE_I, - OP_NOT_I = 138, + OP_IFNOT_S, + + OP_IF_S, + + OP_NOT_I, OP_DIV_VF, - - OP_STORE_P = 152, - OP_LE_I = 161, + 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, @@ -167,10 +266,16 @@ typedef enum opcode_e OP_EQ_IF, OP_EQ_FI, - OP_MUL_IF = 179, + OP_ADD_SF, + OP_SUB_S, + OP_STOREP_C, + OP_LOADP_C, + + OP_MUL_IF, OP_MUL_FI, OP_MUL_VI, - OP_DIV_IF = 183, + OP_MUL_IV, + OP_DIV_IF, OP_DIV_FI, OP_BITAND_IF, OP_BITOR_IF, @@ -200,65 +305,86 @@ typedef enum opcode_e OP_GLOAD_S, OP_GLOAD_FNC, OP_BOUNDCHECK, - OP_GLOAD_V = 216 + + 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; - +// Statements (16 bit format) - 8 bytes each typedef struct statement16_s { - unsigned short op; - signed short a,b,c; + uint16_t op; + int16_t a, b, c; } dstatement16_t; + +// Statements (32 bit format) - 16 bytes each typedef struct statement32_s { - unsigned int op; - signed int a,b,c; + uint32_t op; + int32_t a, b, c; } dstatement32_t; +// Global and fielddefs (16 bit format) - 8 bytes each typedef struct ddef16_s { - unsigned short type; // if DEF_SAVEGLOBGAL bit is set - // the variable needs to be saved in savegames - unsigned short ofs; - int s_name; + uint16_t type; // if DEF_SAVEGLOBAL bit is set + // the variable needs to be saved in savegames + uint16_t ofs; + int32_t s_name; } -ddef16_t; +ddef16_t, dfield16_t; + +// Global and fielddefs (32 bit format) - 12 bytes each typedef struct ddef32_s { - unsigned int type; // if DEF_SAVEGLOBGAL bit is set - // the variable needs to be saved in savegames - unsigned int ofs; - int s_name; + uint32_t type; // if DEF_SAVEGLOBAL bit is set + // the variable needs to be saved in savegames + uint32_t ofs; + int32_t s_name; } -ddef32_t, mdef_t; +ddef32_t, dfield32_t, mdef_t; + #define DEF_SAVEGLOBAL (1<<15) #define MAX_PARMS 8 +// Functions - 36 bytes each typedef struct dfunction_s { - int first_statement; // negative numbers are builtins - int parm_start; - int locals; // total ints of parms + locals + int32_t first_statement; // negative numbers are builtins + int32_t parm_start; // first local + int32_t locals; // total ints of parms + locals - int profile; // runtime + int32_t profile; // runtime - int s_name; - int s_file; // source file defined in + int32_t s_name; // function name + int32_t s_file; // source file defined in - int numparms; - unsigned char parm_size[MAX_PARMS]; + int32_t numparms; // number of args + uint8_t parm_size[MAX_PARMS]; // and size } dfunction_t; typedef struct mfunction_s { - int first_statement; // negative numbers are builtins - int parm_start; - int locals; // total ints of parms + locals + int32_t first_statement; // negative numbers are builtins + int32_t parm_start; + int32_t 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 @@ -272,11 +398,11 @@ typedef struct mfunction_s double builtinsprofile_total; // cost of builtin functions called by this function int recursion; - int s_name; - int s_file; // source file defined in + int32_t s_name; + int32_t s_file; // source file defined in - int numparms; - unsigned char parm_size[MAX_PARMS]; + int32_t numparms; + uint8_t parm_size[MAX_PARMS]; } mfunction_t; @@ -288,32 +414,33 @@ typedef struct mstatement_s } mstatement_t; - +// Header - 64 bytes #define PROG_VERSION 6 typedef struct dprograms_s { - int version; - int crc; // check of header file + int32_t version; // Version (usually 6) + int32_t crc; // CRC-16 of header file. Last 2 bytes are skipped - unsigned int ofs_statements; - unsigned int numstatements; // statement 0 is an error + // Sizes of and offsets to each section + uint32_t ofs_statements; + uint32_t numstatements; // statement 0 is an error - unsigned int ofs_globaldefs; - unsigned int numglobaldefs; + uint32_t ofs_globaldefs; + uint32_t numglobaldefs; - unsigned int ofs_fielddefs; - unsigned int numfielddefs; + uint32_t ofs_fielddefs; + uint32_t numfielddefs; - unsigned int ofs_functions; - unsigned int numfunctions; // function 0 is an empty + uint32_t ofs_functions; + uint32_t numfunctions; // function 0 is an empty - unsigned int ofs_strings; - unsigned int numstrings; // first string is a null string + uint32_t ofs_strings; + uint32_t numstrings; // first string is a null string - unsigned int ofs_globals; - unsigned int numglobals; + uint32_t ofs_globals; + uint32_t numglobals; - unsigned int entityfields; + uint32_t entityfields; } dprograms_t; @@ -322,16 +449,16 @@ typedef struct dprograms_v7_s 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. + uint32_t ofsfiles; //ignored. deprecated, should be 0. source files can instead be embedded by simply treating the .dat as a zip. + uint32_t ofslinenums; //ignored. alternative to external .lno files. + uint32_t ofsbodylessfuncs; //unsupported. function names imported from other modules. must be 0. + uint32_t 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. + uint32_t ofs_types; //unsupported+deprecated. rich type info. must be 0. + uint32_t numtypes; //unsupported+deprecated. rich type info. must be 0. + uint32_t 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. + 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. #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. }