]> git.xonotic.org Git - xonotic/darkplaces.git/blob - prvm_execprogram.h
okay, fix the latest fix :P
[xonotic/darkplaces.git] / prvm_execprogram.h
1
2 // This code isn't #ifdef/#define protectable, don't try.
3
4                 while (1)
5                 {
6                         st++;
7
8 #if PRVMTRACE
9                         PRVM_PrintStatement(st);
10 #endif
11 #if PRVMSTATEMENTPROFILING
12                         prog->statement_profile[st - prog->statements]++;
13 #endif
14
15                         switch (st->op)
16                         {
17                         case OP_ADD_F:
18                                 OPC->_float = OPA->_float + OPB->_float;
19                                 break;
20                         case OP_ADD_V:
21                                 OPC->vector[0] = OPA->vector[0] + OPB->vector[0];
22                                 OPC->vector[1] = OPA->vector[1] + OPB->vector[1];
23                                 OPC->vector[2] = OPA->vector[2] + OPB->vector[2];
24                                 break;
25                         case OP_SUB_F:
26                                 OPC->_float = OPA->_float - OPB->_float;
27                                 break;
28                         case OP_SUB_V:
29                                 OPC->vector[0] = OPA->vector[0] - OPB->vector[0];
30                                 OPC->vector[1] = OPA->vector[1] - OPB->vector[1];
31                                 OPC->vector[2] = OPA->vector[2] - OPB->vector[2];
32                                 break;
33                         case OP_MUL_F:
34                                 OPC->_float = OPA->_float * OPB->_float;
35                                 break;
36                         case OP_MUL_V:
37                                 OPC->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2];
38                                 break;
39                         case OP_MUL_FV:
40                                 OPC->vector[0] = OPA->_float * OPB->vector[0];
41                                 OPC->vector[1] = OPA->_float * OPB->vector[1];
42                                 OPC->vector[2] = OPA->_float * OPB->vector[2];
43                                 break;
44                         case OP_MUL_VF:
45                                 OPC->vector[0] = OPB->_float * OPA->vector[0];
46                                 OPC->vector[1] = OPB->_float * OPA->vector[1];
47                                 OPC->vector[2] = OPB->_float * OPA->vector[2];
48                                 break;
49                         case OP_DIV_F:
50                                 if( OPB->_float != 0.0f )
51                                 {
52                                         OPC->_float = OPA->_float / OPB->_float;
53                                 }
54                                 else
55                                 {
56                                         if( developer.integer >= 1 )
57                                         {
58                                                 prog->xfunction->profile += (st - startst);
59                                                 startst = st;
60                                                 prog->xstatement = st - prog->statements;
61                                                 VM_Warning( "Attempted division by zero in %s\n", PRVM_NAME );
62                                         }
63                                         OPC->_float = 0.0f;
64                                 }
65                                 break;
66                         case OP_BITAND:
67                                 OPC->_float = (int)OPA->_float & (int)OPB->_float;
68                                 break;
69                         case OP_BITOR:
70                                 OPC->_float = (int)OPA->_float | (int)OPB->_float;
71                                 break;
72                         case OP_GE:
73                                 OPC->_float = OPA->_float >= OPB->_float;
74                                 break;
75                         case OP_LE:
76                                 OPC->_float = OPA->_float <= OPB->_float;
77                                 break;
78                         case OP_GT:
79                                 OPC->_float = OPA->_float > OPB->_float;
80                                 break;
81                         case OP_LT:
82                                 OPC->_float = OPA->_float < OPB->_float;
83                                 break;
84                         case OP_AND:
85                                 OPC->_float = FLOAT_IS_TRUE_FOR_INT(OPA->_int) && FLOAT_IS_TRUE_FOR_INT(OBA->_int); // TODO change this back to float, and add AND_I to be used by fteqcc for anything not a float
86                                 break;
87                         case OP_OR:
88                                 OPC->_float = FLOAT_IS_TRUE_FOR_INT(OPA->_int) || FLOAT_IS_TRUE_FOR_INT(OBA->_int); // TODO change this back to float, and add OR_I to be used by fteqcc for anything not a float
89                                 break;
90                         case OP_NOT_F:
91                                 OPC->_float = !FLOAT_IS_TRUE_FOR_INT(OPA->_int);
92                                 break;
93                         case OP_NOT_V:
94                                 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
95                                 break;
96                         case OP_NOT_S:
97                                 OPC->_float = !OPA->string || !*PRVM_GetString(OPA->string);
98                                 break;
99                         case OP_NOT_FNC:
100                                 OPC->_float = !OPA->function;
101                                 break;
102                         case OP_NOT_ENT:
103                                 OPC->_float = (OPA->edict == 0);
104                                 break;
105                         case OP_EQ_F:
106                                 OPC->_float = OPA->_float == OPB->_float;
107                                 break;
108                         case OP_EQ_V:
109                                 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
110                                 break;
111                         case OP_EQ_S:
112                                 OPC->_float = !strcmp(PRVM_GetString(OPA->string),PRVM_GetString(OPB->string));
113                                 break;
114                         case OP_EQ_E:
115                                 OPC->_float = OPA->_int == OPB->_int;
116                                 break;
117                         case OP_EQ_FNC:
118                                 OPC->_float = OPA->function == OPB->function;
119                                 break;
120                         case OP_NE_F:
121                                 OPC->_float = OPA->_float != OPB->_float;
122                                 break;
123                         case OP_NE_V:
124                                 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
125                                 break;
126                         case OP_NE_S:
127                                 OPC->_float = strcmp(PRVM_GetString(OPA->string),PRVM_GetString(OPB->string));
128                                 break;
129                         case OP_NE_E:
130                                 OPC->_float = OPA->_int != OPB->_int;
131                                 break;
132                         case OP_NE_FNC:
133                                 OPC->_float = OPA->function != OPB->function;
134                                 break;
135
136                 //==================
137                         case OP_STORE_F:
138                         case OP_STORE_ENT:
139                         case OP_STORE_FLD:              // integers
140                         case OP_STORE_S:
141                         case OP_STORE_FNC:              // pointers
142                                 OPB->_int = OPA->_int;
143                                 break;
144                         case OP_STORE_V:
145                                 OPB->ivector[0] = OPA->ivector[0];
146                                 OPB->ivector[1] = OPA->ivector[1];
147                                 OPB->ivector[2] = OPA->ivector[2];
148                                 break;
149
150                         case OP_STOREP_F:
151                         case OP_STOREP_ENT:
152                         case OP_STOREP_FLD:             // integers
153                         case OP_STOREP_S:
154                         case OP_STOREP_FNC:             // pointers
155 #if PRVMBOUNDSCHECK
156                                 if (OPB->_int < 0 || OPB->_int + 4 > prog->edictareasize)
157                                 {
158                                         prog->xfunction->profile += (st - startst);
159                                         prog->xstatement = st - prog->statements;
160                                         PRVM_ERROR("%s attempted to write to an out of bounds edict (%i)", PRVM_NAME, OPB->_int);
161                                         goto cleanup;
162                                 }
163 #endif
164                                 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
165                                 ptr->_int = OPA->_int;
166                                 break;
167                         case OP_STOREP_V:
168 #if PRVMBOUNDSCHECK
169                                 if (OPB->_int < 0 || OPB->_int + 12 > prog->edictareasize)
170                                 {
171                                         prog->xfunction->profile += (st - startst);
172                                         prog->xstatement = st - prog->statements;
173                                         PRVM_ERROR("%s attempted to write to an out of bounds edict (%i)", PRVM_NAME, OPB->_int);
174                                         goto cleanup;
175                                 }
176 #endif
177                                 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
178                                 ptr->ivector[0] = OPA->ivector[0];
179                                 ptr->ivector[1] = OPA->ivector[1];
180                                 ptr->ivector[2] = OPA->ivector[2];
181                                 break;
182
183                         case OP_ADDRESS:
184 #if PRVMBOUNDSCHECK
185                                 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
186                                 {
187                                         prog->xfunction->profile += (st - startst);
188                                         prog->xstatement = st - prog->statements;
189                                         PRVM_ERROR ("%s Progs attempted to address an out of bounds edict number", PRVM_NAME);
190                                         goto cleanup;
191                                 }
192                                 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
193                                 {
194                                         prog->xfunction->profile += (st - startst);
195                                         prog->xstatement = st - prog->statements;
196                                         PRVM_ERROR("%s attempted to address an invalid field (%i) in an edict", PRVM_NAME, OPB->_int);
197                                         goto cleanup;
198                                 }
199 #endif
200                                 if (OPA->edict == 0 && !prog->allowworldwrites)
201                                 {
202                                         prog->xfunction->profile += (st - startst);
203                                         prog->xstatement = st - prog->statements;
204                                         PRVM_ERROR("forbidden assignment to null/world entity in %s", PRVM_NAME);
205                                         goto cleanup;
206                                 }
207                                 ed = PRVM_PROG_TO_EDICT(OPA->edict);
208                                 OPC->_int = (unsigned char *)((int *)ed->fields.vp + OPB->_int) - (unsigned char *)prog->edictsfields;
209                                 break;
210
211                         case OP_LOAD_F:
212                         case OP_LOAD_FLD:
213                         case OP_LOAD_ENT:
214                         case OP_LOAD_S:
215                         case OP_LOAD_FNC:
216 #if PRVMBOUNDSCHECK
217                                 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
218                                 {
219                                         prog->xfunction->profile += (st - startst);
220                                         prog->xstatement = st - prog->statements;
221                                         PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
222                                         goto cleanup;
223                                 }
224                                 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
225                                 {
226                                         prog->xfunction->profile += (st - startst);
227                                         prog->xstatement = st - prog->statements;
228                                         PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)", PRVM_NAME, OPB->_int);
229                                         goto cleanup;
230                                 }
231 #endif
232                                 ed = PRVM_PROG_TO_EDICT(OPA->edict);
233                                 OPC->_int = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->_int;
234                                 break;
235
236                         case OP_LOAD_V:
237 #if PRVMBOUNDSCHECK
238                                 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
239                                 {
240                                         prog->xfunction->profile += (st - startst);
241                                         prog->xstatement = st - prog->statements;
242                                         PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
243                                         goto cleanup;
244                                 }
245                                 if (OPB->_int < 0 || OPB->_int + 2 >= prog->progs->entityfields)
246                                 {
247                                         prog->xfunction->profile += (st - startst);
248                                         prog->xstatement = st - prog->statements;
249                                         PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)", PRVM_NAME, OPB->_int);
250                                         goto cleanup;
251                                 }
252 #endif
253                                 ed = PRVM_PROG_TO_EDICT(OPA->edict);
254                                 OPC->ivector[0] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[0];
255                                 OPC->ivector[1] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[1];
256                                 OPC->ivector[2] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[2];
257                                 break;
258
259                 //==================
260
261                         case OP_IFNOT:
262                                 if(!FLOAT_IS_TRUE_FOR_INT(OPA->_int))
263                                 // TODO add an "int-if", and change this one to OPA->_float
264                                 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
265                                 // and entity, string, field values can never have that value
266                                 {
267                                         prog->xfunction->profile += (st - startst);
268                                         st += st->b - 1;        // offset the s++
269                                         startst = st;
270                                         // no bounds check needed, it is done when loading progs
271 #if PRVMRUNAWAYCHECK
272                                         if (++jumpcount == 10000000)
273                                         {
274                                                 prog->xstatement = st - prog->statements;
275                                                 PRVM_Profile(1<<30, 1000000);
276                                                 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
277                                         }
278 #endif
279                                 }
280                                 break;
281
282                         case OP_IF:
283                                 if(FLOAT_IS_TRUE_FOR_INT(OPA->_int))
284                                 // TODO add an "int-if", and change this one, as well as the FLOAT_IS_TRUE_FOR_INT usages, to OPA->_float
285                                 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
286                                 // and entity, string, field values can never have that value
287                                 {
288                                         prog->xfunction->profile += (st - startst);
289                                         st += st->b - 1;        // offset the s++
290                                         startst = st;
291                                         // no bounds check needed, it is done when loading progs
292 #if PRVMRUNAWAYCHECK
293                                         if (++jumpcount == 10000000)
294                                         {
295                                                 prog->xstatement = st - prog->statements;
296                                                 PRVM_Profile(1<<30, 1000000);
297                                                 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
298                                         }
299 #endif
300                                 }
301                                 break;
302
303                         case OP_GOTO:
304                                 prog->xfunction->profile += (st - startst);
305                                 st += st->a - 1;        // offset the s++
306                                 startst = st;
307                                 // no bounds check needed, it is done when loading progs
308 #if PRVMRUNAWAYCHECK
309                                 if (++jumpcount == 10000000)
310                                 {
311                                         prog->xstatement = st - prog->statements;
312                                         PRVM_Profile(1<<30, 1000000);
313                                         PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
314                                 }
315 #endif
316                                 break;
317
318                         case OP_CALL0:
319                         case OP_CALL1:
320                         case OP_CALL2:
321                         case OP_CALL3:
322                         case OP_CALL4:
323                         case OP_CALL5:
324                         case OP_CALL6:
325                         case OP_CALL7:
326                         case OP_CALL8:
327                                 prog->xfunction->profile += (st - startst);
328                                 startst = st;
329                                 prog->xstatement = st - prog->statements;
330                                 prog->argc = st->op - OP_CALL0;
331                                 if (!OPA->function)
332                                         PRVM_ERROR("NULL function in %s", PRVM_NAME);
333
334 #if PRVMBOUNDSCHECK
335                                 if(!OPA->function || OPA->function >= (unsigned int)prog->progs->numfunctions)
336                                 {
337                                         prog->xfunction->profile += (st - startst);
338                                         prog->xstatement = st - prog->statements; // we better stay on the previously executed statement
339                                         PRVM_ERROR("%s CALL outside the program", PRVM_NAME);
340                                         goto cleanup;
341                                 }
342 #endif
343
344                                 newf = &prog->functions[OPA->function];
345                                 newf->callcount++;
346
347                                 if (newf->first_statement < 0)
348                                 {
349                                         // negative statements are built in functions
350                                         int builtinnumber = -newf->first_statement;
351                                         prog->xfunction->builtinsprofile++;
352                                         if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
353                                                 prog->builtins[builtinnumber]();
354                                         else
355                                                 PRVM_ERROR("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, PRVM_NAME);
356                                 }
357                                 else
358                                         st = prog->statements + PRVM_EnterFunction(newf);
359                                 startst = st;
360                                 break;
361
362                         case OP_DONE:
363                         case OP_RETURN:
364                                 prog->xfunction->profile += (st - startst);
365                                 prog->xstatement = st - prog->statements;
366
367                                 prog->globals.generic[OFS_RETURN] = prog->globals.generic[(unsigned short) st->a];
368                                 prog->globals.generic[OFS_RETURN+1] = prog->globals.generic[(unsigned short) st->a+1];
369                                 prog->globals.generic[OFS_RETURN+2] = prog->globals.generic[(unsigned short) st->a+2];
370
371                                 st = prog->statements + PRVM_LeaveFunction();
372                                 startst = st;
373                                 if (prog->depth <= exitdepth)
374                                         goto cleanup; // all done
375                                 if (prog->trace != cachedpr_trace)
376                                         goto chooseexecprogram;
377                                 break;
378
379                         case OP_STATE:
380                                 if(prog->flag & PRVM_OP_STATE)
381                                 {
382                                         ed = PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict);
383                                         PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.nextthink)->_float = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.time)->_float + 0.1;
384                                         PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.frame)->_float = OPA->_float;
385                                         PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.think)->function = OPB->function;
386                                 }
387                                 else
388                                 {
389                                         prog->xfunction->profile += (st - startst);
390                                         prog->xstatement = st - prog->statements;
391                                         PRVM_ERROR("OP_STATE not supported by %s", PRVM_NAME);
392                                 }
393                                 break;
394
395 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
396 /*
397                         case OP_ADD_I:
398                                 OPC->_int = OPA->_int + OPB->_int;
399                                 break;
400                         case OP_ADD_IF:
401                                 OPC->_int = OPA->_int + (int) OPB->_float;
402                                 break;
403                         case OP_ADD_FI:
404                                 OPC->_float = OPA->_float + (float) OPB->_int;
405                                 break;
406                         case OP_SUB_I:
407                                 OPC->_int = OPA->_int - OPB->_int;
408                                 break;
409                         case OP_SUB_IF:
410                                 OPC->_int = OPA->_int - (int) OPB->_float;
411                                 break;
412                         case OP_SUB_FI:
413                                 OPC->_float = OPA->_float - (float) OPB->_int;
414                                 break;
415                         case OP_MUL_I:
416                                 OPC->_int = OPA->_int * OPB->_int;
417                                 break;
418                         case OP_MUL_IF:
419                                 OPC->_int = OPA->_int * (int) OPB->_float;
420                                 break;
421                         case OP_MUL_FI:
422                                 OPC->_float = OPA->_float * (float) OPB->_int;
423                                 break;
424                         case OP_MUL_VI:
425                                 OPC->vector[0] = (float) OPB->_int * OPA->vector[0];
426                                 OPC->vector[1] = (float) OPB->_int * OPA->vector[1];
427                                 OPC->vector[2] = (float) OPB->_int * OPA->vector[2];
428                                 break;
429                         case OP_DIV_VF:
430                                 {
431                                         float temp = 1.0f / OPB->_float;
432                                         OPC->vector[0] = temp * OPA->vector[0];
433                                         OPC->vector[1] = temp * OPA->vector[1];
434                                         OPC->vector[2] = temp * OPA->vector[2];
435                                 }
436                                 break;
437                         case OP_DIV_I:
438                                 OPC->_int = OPA->_int / OPB->_int;
439                                 break;
440                         case OP_DIV_IF:
441                                 OPC->_int = OPA->_int / (int) OPB->_float;
442                                 break;
443                         case OP_DIV_FI:
444                                 OPC->_float = OPA->_float / (float) OPB->_int;
445                                 break;
446                         case OP_CONV_IF:
447                                 OPC->_float = OPA->_int;
448                                 break;
449                         case OP_CONV_FI:
450                                 OPC->_int = OPA->_float;
451                                 break;
452                         case OP_BITAND_I:
453                                 OPC->_int = OPA->_int & OPB->_int;
454                                 break;
455                         case OP_BITOR_I:
456                                 OPC->_int = OPA->_int | OPB->_int;
457                                 break;
458                         case OP_BITAND_IF:
459                                 OPC->_int = OPA->_int & (int)OPB->_float;
460                                 break;
461                         case OP_BITOR_IF:
462                                 OPC->_int = OPA->_int | (int)OPB->_float;
463                                 break;
464                         case OP_BITAND_FI:
465                                 OPC->_float = (int)OPA->_float & OPB->_int;
466                                 break;
467                         case OP_BITOR_FI:
468                                 OPC->_float = (int)OPA->_float | OPB->_int;
469                                 break;
470                         case OP_GE_I:
471                                 OPC->_float = OPA->_int >= OPB->_int;
472                                 break;
473                         case OP_LE_I:
474                                 OPC->_float = OPA->_int <= OPB->_int;
475                                 break;
476                         case OP_GT_I:
477                                 OPC->_float = OPA->_int > OPB->_int;
478                                 break;
479                         case OP_LT_I:
480                                 OPC->_float = OPA->_int < OPB->_int;
481                                 break;
482                         case OP_AND_I:
483                                 OPC->_float = OPA->_int && OPB->_int;
484                                 break;
485                         case OP_OR_I:
486                                 OPC->_float = OPA->_int || OPB->_int;
487                                 break;
488                         case OP_GE_IF:
489                                 OPC->_float = (float)OPA->_int >= OPB->_float;
490                                 break;
491                         case OP_LE_IF:
492                                 OPC->_float = (float)OPA->_int <= OPB->_float;
493                                 break;
494                         case OP_GT_IF:
495                                 OPC->_float = (float)OPA->_int > OPB->_float;
496                                 break;
497                         case OP_LT_IF:
498                                 OPC->_float = (float)OPA->_int < OPB->_float;
499                                 break;
500                         case OP_AND_IF:
501                                 OPC->_float = (float)OPA->_int && OPB->_float;
502                                 break;
503                         case OP_OR_IF:
504                                 OPC->_float = (float)OPA->_int || OPB->_float;
505                                 break;
506                         case OP_GE_FI:
507                                 OPC->_float = OPA->_float >= (float)OPB->_int;
508                                 break;
509                         case OP_LE_FI:
510                                 OPC->_float = OPA->_float <= (float)OPB->_int;
511                                 break;
512                         case OP_GT_FI:
513                                 OPC->_float = OPA->_float > (float)OPB->_int;
514                                 break;
515                         case OP_LT_FI:
516                                 OPC->_float = OPA->_float < (float)OPB->_int;
517                                 break;
518                         case OP_AND_FI:
519                                 OPC->_float = OPA->_float && (float)OPB->_int;
520                                 break;
521                         case OP_OR_FI:
522                                 OPC->_float = OPA->_float || (float)OPB->_int;
523                                 break;
524                         case OP_NOT_I:
525                                 OPC->_float = !OPA->_int;
526                                 break;
527                         case OP_EQ_I:
528                                 OPC->_float = OPA->_int == OPB->_int;
529                                 break;
530                         case OP_EQ_IF:
531                                 OPC->_float = (float)OPA->_int == OPB->_float;
532                                 break;
533                         case OP_EQ_FI:
534                                 OPC->_float = OPA->_float == (float)OPB->_int;
535                                 break;
536                         case OP_NE_I:
537                                 OPC->_float = OPA->_int != OPB->_int;
538                                 break;
539                         case OP_NE_IF:
540                                 OPC->_float = (float)OPA->_int != OPB->_float;
541                                 break;
542                         case OP_NE_FI:
543                                 OPC->_float = OPA->_float != (float)OPB->_int;
544                                 break;
545                         case OP_STORE_I:
546                                 OPB->_int = OPA->_int;
547                                 break;
548                         case OP_STOREP_I:
549 #if PRBOUNDSCHECK
550                                 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
551                                 {
552                                         prog->xfunction->profile += (st - startst);
553                                         prog->xstatement = st - prog->statements;
554                                         PRVM_ERROR ("%s Progs attempted to write to an out of bounds edict", PRVM_NAME);
555                                         goto cleanup;
556                                 }
557 #endif
558                                 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
559                                 ptr->_int = OPA->_int;
560                                 break;
561                         case OP_LOAD_I:
562 #if PRBOUNDSCHECK
563                                 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
564                                 {
565                                         prog->xfunction->profile += (st - startst);
566                                         prog->xstatement = st - prog->statements;
567                                         PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
568                                         goto cleanup;
569                                 }
570                                 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
571                                 {
572                                         prog->xfunction->profile += (st - startst);
573                                         prog->xstatement = st - prog->statements;
574                                         PRVM_ERROR ("%s Progs attempted to read an invalid field in an edict", PRVM_NAME);
575                                         goto cleanup;
576                                 }
577 #endif
578                                 ed = PRVM_PROG_TO_EDICT(OPA->edict);
579                                 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
580                                 break;
581
582                         case OP_GSTOREP_I:
583                         case OP_GSTOREP_F:
584                         case OP_GSTOREP_ENT:
585                         case OP_GSTOREP_FLD:            // integers
586                         case OP_GSTOREP_S:
587                         case OP_GSTOREP_FNC:            // pointers
588 #if PRBOUNDSCHECK
589                                 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
590                                 {
591                                         prog->xfunction->profile += (st - startst);
592                                         prog->xstatement = st - prog->statements;
593                                         PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
594                                         goto cleanup;
595                                 }
596 #endif
597                                 pr_iglobals[OPB->_int] = OPA->_int;
598                                 break;
599                         case OP_GSTOREP_V:
600 #if PRBOUNDSCHECK
601                                 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
602                                 {
603                                         prog->xfunction->profile += (st - startst);
604                                         prog->xstatement = st - prog->statements;
605                                         PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
606                                         goto cleanup;
607                                 }
608 #endif
609                                 pr_iglobals[OPB->_int  ] = OPA->ivector[0];
610                                 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
611                                 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
612                                 break;
613
614                         case OP_GADDRESS:
615                                 i = OPA->_int + (int) OPB->_float;
616 #if PRBOUNDSCHECK
617                                 if (i < 0 || i >= pr_globaldefs)
618                                 {
619                                         prog->xfunction->profile += (st - startst);
620                                         prog->xstatement = st - prog->statements;
621                                         PRVM_ERROR ("%s Progs attempted to address an out of bounds global", PRVM_NAME);
622                                         goto cleanup;
623                                 }
624 #endif
625                                 OPC->_int = pr_iglobals[i];
626                                 break;
627
628                         case OP_GLOAD_I:
629                         case OP_GLOAD_F:
630                         case OP_GLOAD_FLD:
631                         case OP_GLOAD_ENT:
632                         case OP_GLOAD_S:
633                         case OP_GLOAD_FNC:
634 #if PRBOUNDSCHECK
635                                 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
636                                 {
637                                         prog->xfunction->profile += (st - startst);
638                                         prog->xstatement = st - prog->statements;
639                                         PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
640                                         goto cleanup;
641                                 }
642 #endif
643                                 OPC->_int = pr_iglobals[OPA->_int];
644                                 break;
645
646                         case OP_GLOAD_V:
647 #if PRBOUNDSCHECK
648                                 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
649                                 {
650                                         prog->xfunction->profile += (st - startst);
651                                         prog->xstatement = st - prog->statements;
652                                         PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
653                                         goto cleanup;
654                                 }
655 #endif
656                                 OPC->ivector[0] = pr_iglobals[OPA->_int  ];
657                                 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
658                                 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
659                                 break;
660
661                         case OP_BOUNDCHECK:
662                                 if (OPA->_int < 0 || OPA->_int >= st->b)
663                                 {
664                                         prog->xfunction->profile += (st - startst);
665                                         prog->xstatement = st - prog->statements;
666                                         PRVM_ERROR ("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", PRVM_NAME, st->b, st->c);
667                                         goto cleanup;
668                                 }
669                                 break;
670
671 */
672
673                         default:
674                                 prog->xfunction->profile += (st - startst);
675                                 prog->xstatement = st - prog->statements;
676                                 PRVM_ERROR ("Bad opcode %i in %s", st->op, PRVM_NAME);
677                                 goto cleanup;
678                         }
679                 }
680