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