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