1 2 // this file is shared by quake and qcc 3 4 typedef int func_t; 5 typedef int string_t; 6 7 typedef enum {ev_void, ev_string, ev_float, ev_vector, ev_entity, ev_field, ev_function, ev_pointer, ev_int, ev_bad = -1} etype_t; 8 9 10 #define OFS_NULL 0 11 #define OFS_RETURN 1 12 #define OFS_PARM0 4 // leave 3 ofs for each parm to hold vectors 13 #define OFS_PARM1 7 14 #define OFS_PARM2 10 15 #define OFS_PARM3 13 16 #define OFS_PARM4 16 17 #define OFS_PARM5 19 18 #define OFS_PARM6 22 19 #define OFS_PARM7 25 20 #define RESERVED_OFS 28 21 22 23 // indices into op table 24 enum { 25 OP_DONE, 26 OP_MUL_F, 27 OP_MUL_V, 28 OP_MUL_FV, 29 OP_MUL_VF, 30 OP_DIV_F, 31 OP_ADD_F, 32 OP_ADD_V, 33 34 OP_SUB_F, 35 OP_SUB_V, 36 37 OP_EQ_F, 38 OP_EQ_V, 39 OP_EQ_S, 40 OP_EQ_E, 41 OP_EQ_FNC, 42 43 OP_NE_F, 44 OP_NE_V, 45 OP_NE_S, 46 OP_NE_E, 47 OP_NE_FNC, 48 49 OP_LE, 50 OP_GE, 51 OP_LT, 52 OP_GT, 53 54 OP_LOAD_F, 55 OP_LOAD_V, 56 OP_LOAD_S, 57 OP_LOAD_ENT, 58 OP_LOAD_FLD, 59 OP_LOAD_FNC, 60 61 OP_ADDRESS, 62 63 OP_STORE_F, 64 OP_STORE_V, 65 OP_STORE_S, 66 OP_STORE_ENT, 67 OP_STORE_FLD, 68 OP_STORE_FNC, 69 70 OP_STOREP_F, 71 OP_STOREP_V, 72 OP_STOREP_S, 73 OP_STOREP_ENT, 74 OP_STOREP_FLD, 75 OP_STOREP_FNC, 76 77 OP_RETURN, 78 OP_NOT_F, 79 OP_NOT_V, 80 OP_NOT_S, 81 OP_NOT_ENT, 82 OP_NOT_FNC, 83 OP_IF, 84 OP_IFNOT, 85 86 OP_STATE, 87 OP_GOTO, 88 89 OP_AND, 90 OP_AND_EF, 91 OP_AND_FE, 92 OP_AND_EE, 93 94 OP_OR, 95 OP_OR_EF, 96 OP_OR_FE, 97 OP_OR_EE, 98 99 OP_BITAND, 100 OP_BITOR, 101 102 OP_ARRAY_F, 103 OP_ARRAY_EF, 104 OP_ARRAY_S, 105 OP_ARRAY_E, 106 OP_ARRAY_SS, 107 OP_ARRAY_V, 108 OP_ARRAY_FLD, 109 OP_ARRAY_FNC, 110 OP_ADD_STORE_F, 111 OP_ADD_STORE_V, 112 OP_ADD_STOREP_F, 113 OP_ADD_STOREP_V, 114 115 OP_SUB_STORE_F, 116 OP_SUB_STORE_V, 117 OP_SUB_STOREP_F, 118 OP_SUB_STOREP_V, 119 120 OP_MUL_STORE_F, 121 OP_MUL_STOREP_F, 122 123 OP_DIV_STORE_F, 124 OP_DIV_STOREP_F, 125 126 OP_AND_STORE_F, 127 OP_AND_STOREP_F, 128 129 OP_OR_STORE_F, 130 OP_OR_STOREP_F, 131 132 OP_INC_F, 133 OP_DEC_F 134 }; 135 136 // actual opcodes 137 enum { 138 OP2_DONE, 139 OP2_MUL_F, 140 OP2_MUL_V, 141 OP2_MUL_FV, 142 OP2_MUL_VF, 143 OP2_DIV_F, 144 OP2_ADD_F, 145 OP2_ADD_V, 146 OP2_SUB_F, 147 OP2_SUB_V, 148 149 OP2_EQ_F, 150 OP2_EQ_V, 151 OP2_EQ_S, 152 OP2_EQ_E, 153 OP2_EQ_FNC, 154 155 OP2_NE_F, 156 OP2_NE_V, 157 OP2_NE_S, 158 OP2_NE_E, 159 OP2_NE_FNC, 160 161 OP2_LE, 162 OP2_GE, 163 OP2_LT, 164 OP2_GT, 165 166 OP2_LOAD_F, 167 OP2_LOAD_V, 168 OP2_LOAD_S, 169 OP2_LOAD_ENT, 170 OP2_LOAD_FLD, 171 OP2_LOAD_FNC, 172 173 OP2_ADDRESS, 174 175 OP2_STORE_F, 176 OP2_STORE_V, 177 OP2_STORE_S, 178 OP2_STORE_ENT, 179 OP2_STORE_FLD, 180 OP2_STORE_FNC, 181 182 OP2_STOREP_F, 183 OP2_STOREP_V, 184 OP2_STOREP_S, 185 OP2_STOREP_ENT, 186 OP2_STOREP_FLD, 187 OP2_STOREP_FNC, 188 189 OP2_RETURN, 190 OP2_NOT_F, 191 OP2_NOT_V, 192 OP2_NOT_S, 193 OP2_NOT_ENT, 194 OP2_NOT_FNC, 195 OP2_IF, 196 OP2_IFNOT, 197 OP2_CALL0, 198 OP2_CALL1, 199 OP2_CALL2, 200 OP2_CALL3, 201 OP2_CALL4, 202 OP2_CALL5, 203 OP2_CALL6, 204 OP2_CALL7, 205 OP2_CALL8, 206 OP2_STATE, 207 OP2_GOTO, 208 OP2_AND, 209 OP2_OR, 210 211 OP2_BITAND, 212 OP2_BITOR 213 }; 214 215 typedef struct statement_s 216 { 217 unsigned short op; 218 short a,b,c; 219 } dstatement_t; 220 221 typedef struct 222 { 223 unsigned short type; // if DEF_SAVEGLOBAL bit is set 224 // the variable needs to be saved in savegames 225 unsigned short ofs; 226 int s_name; 227 } ddef_t; 228 229 #define DEF_SAVEGLOBAL (1<<15) 230 231 #define MAX_PARMS 8 232 233 typedef struct 234 { 235 int first_statement; // negative numbers are builtins 236 int parm_start; 237 int locals; // total ints of parms + locals 238 239 int profile; // runtime 240 241 int s_name; 242 int s_file; // source file defined in 243 244 int numparms; 245 byte parm_size[MAX_PARMS]; 246 } dfunction_t; 247 248 249 #define PROG_VERSION 6 250 typedef struct 251 { 252 int version; 253 int crc; // check of header file 254 255 int ofs_statements; 256 int numstatements; // statement 0 is an error 257 258 int ofs_globaldefs; 259 int numglobaldefs; 260 261 int ofs_fielddefs; 262 int numfielddefs; 263 264 int ofs_functions; 265 int numfunctions; // function 0 is an empty 266 267 int ofs_strings; 268 int numstrings; // first string is a null string 269 270 int ofs_globals; 271 int numglobals; 272 273 int entityfields; 274 } dprograms_t; 275 276