347#if !USE_COMPUTED_GOTOS
349#if PRVMSLOWINTERPRETER
352 if (prog->break_statement >= 0)
353 if ((st - cached_statements) == prog->break_statement)
355 prog->xstatement = st - cached_statements;
366 OPC->vector[0] =
OPA->vector[0] +
OPB->vector[0];
367 OPC->vector[1] =
OPA->vector[1] +
OPB->vector[1];
368 OPC->vector[2] =
OPA->vector[2] +
OPB->vector[2];
374 OPC->vector[0] =
OPA->vector[0] -
OPB->vector[0];
375 OPC->vector[1] =
OPA->vector[1] -
OPB->vector[1];
376 OPC->vector[2] =
OPA->vector[2] -
OPB->vector[2];
382 OPC->_float =
OPA->vector[0]*
OPB->vector[0] +
OPA->vector[1]*
OPB->vector[1] +
OPA->vector[2]*
OPB->vector[2];
385 tempfloat =
OPA->_float;
386 OPC->vector[0] = tempfloat *
OPB->vector[0];
387 OPC->vector[1] = tempfloat *
OPB->vector[1];
388 OPC->vector[2] = tempfloat *
OPB->vector[2];
391 tempfloat =
OPB->_float;
392 OPC->vector[0] = tempfloat *
OPA->vector[0];
393 OPC->vector[1] = tempfloat *
OPA->vector[1];
394 OPC->vector[2] = tempfloat *
OPA->vector[2];
397 if(
OPB->_float == 0.0f )
400 VM_Warning(prog,
"Attempted division of %f by zero\n",
OPA->_float);
416 OPC->_float =
OPA->_float >=
OPB->_float;
419 OPC->_float =
OPA->_float <=
OPB->_float;
437 OPC->_float = !
OPA->vector[0] && !
OPA->vector[1] && !
OPA->vector[2];
443 OPC->_float = !
OPA->function;
446 OPC->_float = (
OPA->edict == 0);
449 OPC->_float =
OPA->_float ==
OPB->_float;
452 OPC->_float = (
OPA->vector[0] ==
OPB->vector[0]) && (
OPA->vector[1] ==
OPB->vector[1]) && (
OPA->vector[2] ==
OPB->vector[2]);
461 OPC->_float =
OPA->function ==
OPB->function;
464 OPC->_float =
OPA->_float !=
OPB->_float;
467 OPC->_float = (
OPA->vector[0] !=
OPB->vector[0]) || (
OPA->vector[1] !=
OPB->vector[1]) || (
OPA->vector[2] !=
OPB->vector[2]);
476 OPC->_float =
OPA->function !=
OPB->function;
496 OPB->ivector[0] =
OPA->ivector[0];
497 OPB->ivector[1] =
OPA->ivector[1];
498 OPB->ivector[2] =
OPA->ivector[2];
506 if ((
ofs =
addr - cached_vmentity1start) < cached_entityfieldsarea_entityfields)
511 else if ((
ofs =
addr - cached_vmglobal1) < cached_vmglobals_1)
516 else if ((
ofs =
addr - cached_vmentity0start) < cached_entityfields)
518 if (!cached_allowworldwrites)
529 prog->error_cmd(
"%s attempted to write to an out of bounds address %"PRVM_PRIu"+%"PRVM_PRIi"", prog->name,
OPB->_uint,
OPC->_int);
532 ptr->_int =
OPA->_int;
536 if ((
ofs =
addr - cached_vmentity1start) < cached_entityfieldsarea_entityfields)
541 else if ((
ofs =
addr - cached_vmglobal1) < cached_vmglobals_1)
546 else if ((
ofs =
addr - cached_vmentity0start) < cached_entityfields)
548 if (!cached_allowworldwrites)
559 prog->error_cmd(
"%s attempted to write to an out of bounds address %"PRVM_PRIu"+%"PRVM_PRIi"", prog->name,
OPB->_uint,
OPC->_int);
568 ptr->_int =
OPA->_int;
572 if ((
ofs =
addr - cached_vmentity1start) < cached_entityfieldsarea_entityfields_2)
577 else if ((
ofs =
addr - cached_vmglobal1) < cached_vmglobals_3)
582 else if ((
ofs =
addr - cached_vmentity0start) < cached_entityfields_2)
584 if (!cached_allowworldwrites)
595 prog->error_cmd(
"%s attempted to write to an out of bounds address %"PRVM_PRIu"+%"PRVM_PRIi"", prog->name,
OPB->_uint,
OPC->_int);
598 ptr->ivector[0] =
OPA->ivector[0];
599 ptr->ivector[1] =
OPA->ivector[1];
600 ptr->ivector[2] =
OPA->ivector[2];
607 prog->error_cmd(
"%s attempted to address an out of bounds edict number", prog->name);
610 if (
OPB->_uint >= cached_entityfields)
613 prog->error_cmd(
"%s attempted to address an invalid field (%"PRVM_PRIu") in an edict", prog->name,
OPB->_uint);
617 if (
OPA->edict == 0 && !cached_allowworldwrites)
620 prog->error_cmd(
"Forbidden assignment to world (edictnum 0) in %s", prog->name);
624 OPC->_int = cached_vmentity0start +
OPA->edict * cached_entityfields +
OPB->_int;
635 prog->error_cmd(
"%s attempted to read an out of bounds edict number", prog->name);
638 if (
OPB->_uint >= cached_entityfields)
641 prog->error_cmd(
"%s attempted to read an invalid field in an edict (%"PRVM_PRIu")", prog->name,
OPB->_uint);
651 prog->error_cmd(
"%s attempted to read an out of bounds edict number", prog->name);
654 if (
OPB->_uint >= cached_entityfields)
657 prog->error_cmd(
"%s attempted to read an invalid field in an edict (%"PRVM_PRIu")", prog->name,
OPB->_uint);
674 prog->error_cmd(
"%s attempted to read an out of bounds edict number", prog->name);
677 if (
OPB->_uint >= cached_entityfields_2)
680 prog->error_cmd(
"%s attempted to read an invalid field in an edict (%"PRVM_PRIu")", prog->name,
OPB->_uint);
685 OPC->ivector[0] = ptr->ivector[0];
686 OPC->ivector[1] = ptr->ivector[1];
687 OPC->ivector[2] = ptr->ivector[2];
701 st += st->operand[1] - 1;
706 prog->xstatement = st - cached_statements;
708 prog->error_cmd(
"%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
728 st += st->operand[1] - 1;
733 prog->xstatement = st - cached_statements;
735 prog->error_cmd(
"%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
742 st += st->operand[0] - 1;
747 prog->xstatement = st - cached_statements;
749 prog->error_cmd(
"%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
762#ifdef PRVMTIMEPROFILING
764 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
769 prog->xstatement = st - cached_statements;
773 prog->error_cmd(
"NULL function in %s", prog->name);
776 if(!
OPA->function ||
OPA->function < 0 ||
OPA->function >= prog->numfunctions)
779 prog->error_cmd(
"%s attempted CALL outside the program", prog->name);
783 enterfunc = &prog->functions[
OPA->function];
787 if (enterfunc->first_statement < 0)
790 int builtinnumber = -enterfunc->first_statement;
791 prog->xfunction->builtinsprofile++;
792 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
794 prog->builtins[builtinnumber](prog);
795#ifdef PRVMTIMEPROFILING
797 enterfunc->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
798 prog->xfunction->tbprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
808 if (prog->trace != cachedpr_trace)
809 goto chooseexecprogram;
812 prog->error_cmd(
"No such builtin #%i in %s. This program is corrupt or incompatible with DarkPlaces (or this version of it)", builtinnumber, prog->name);
821#ifdef PRVMTIMEPROFILING
823 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
827 prog->xstatement = st - cached_statements;
829 prog->globals.ip[
OFS_RETURN ] = prog->globals.ip[st->operand[0] ];
830 prog->globals.ip[
OFS_RETURN+1] = prog->globals.ip[st->operand[0]+1];
831 prog->globals.ip[
OFS_RETURN+2] = prog->globals.ip[st->operand[0]+2];
835 if (prog->depth <= exitdepth)
850 prog->xstatement = st - cached_statements;
851 prog->error_cmd(
"OP_STATE not supported by %s", prog->name);
888 if(
OPB->_float == 0.0f )
891 VM_Warning(prog,
"Attempted division of '%f %f %f' by zero\n",
OPA->vector[0],
OPA->vector[1],
OPA->vector[2]);
900 tempfloat =
OPB->_float;
901 OPC->vector[0] =
OPA->vector[0] / tempfloat;
902 OPC->vector[1] =
OPA->vector[1] / tempfloat;
903 OPC->vector[2] =
OPA->vector[2] / tempfloat;
920 if(
OPB->_float == 0.0f )
936 VM_Warning(prog,
"Attempted division of %f by zero\n",
OPA->_float);
1050 if (
OPB->_int < 0 ||
OPB->_int + 4 > pr_edictareasize)
1053 prog->error_cmd(
"%s attempted to write to an out of bounds edict", prog->name);
1058 ptr->_int =
OPA->_int;
1062 if (
OPA->edict < 0 ||
OPA->edict >= prog->max_edicts)
1065 prog->error_cmd(
"%s attempted to read an out of bounds edict number", prog->name);
1068 if (
OPB->_int < 0 ||
OPB->_int >= progs->entityfields.ip)
1071 prog->error_cmd(
"%s attempted to read an invalid field in an edict", prog->name);
1085 if (
OPB->_int < 0 ||
OPB->_int >= prog->numglobals)
1088 prog->error_cmd(
"%s attempted to write to an invalid indexed global", prog->name);
1091 prog->globals.ip[
OPB->_int] =
OPA->_int;
1094 if (
OPB->_int < 0 ||
OPB->_int + 2 >= prog->numglobals)
1097 prog->error_cmd(
"%s attempted to write to an invalid indexed global", prog->name);
1100 prog->globals.ip[
OPB->_int ] =
OPA->ivector[0];
1101 prog->globals.ip[
OPB->_int+1] =
OPA->ivector[1];
1102 prog->globals.ip[
OPB->_int+2] =
OPA->ivector[2];
1110 prog->error_cmd(
"%s attempted to address an out of bounds global", prog->name);
1113 OPC->_int = prog->globals.ip[
i];
1122 if (
OPA->_int < 0 ||
OPA->_int >= prog->numglobals)
1125 prog->error_cmd(
"%s attempted to read an invalid indexed global", prog->name);
1128 OPC->_int = prog->globals.ip[
OPA->_int];
1132 if (
OPA->_int < 0 ||
OPA->_int + 2 >= prog->numglobals)
1135 prog->error_cmd(
"%s attempted to read an invalid indexed global", prog->name);
1138 OPC->ivector[0] = prog->globals.ip[
OPA->_int ];
1139 OPC->ivector[1] = prog->globals.ip[
OPA->_int+1];
1140 OPC->ivector[2] = prog->globals.ip[
OPA->_int+2];
1144 if ((
unsigned int)
OPA->_int < (
unsigned int)st->operand[2] || (
unsigned int)
OPA->_int >= (
unsigned int)st->operand[1])
1147 prog->error_cmd(
"Progs boundcheck failed in %s, value is < %"PRVM_PRIi" or >= %"PRVM_PRIi"", prog->name,
OPC->_int,
OPB->_int);
1164 ofs = st->operand[0] +
OPB->_int;
1165 if (
ofs >= cached_vmglobals)
1168 prog->error_cmd(
"%s attempted to read from an out of bounds address %u+%"PRVM_PRIi"", prog->name, (
unsigned int)st->operand[0],
OPB->_int);
1175 ofs = st->operand[0] +
OPB->_int;
1176 if (
ofs >= cached_vmglobals)
1179 prog->error_cmd(
"%s attempted to read from an out of bounds address %u+%"PRVM_PRIi"", prog->name, (
unsigned int)st->operand[0],
OPB->_int);
1192 ofs = st->operand[0] +
OPB->_int;
1193 if (
ofs >= cached_vmglobals_2)
1196 prog->error_cmd(
"%s attempted to read from an out of bounds address %u+%"PRVM_PRIi"", prog->name, (
unsigned int)st->operand[0],
OPB->_int);
1210 if ((
ofs =
addr - cached_vmentity0start) < cached_entityfieldsarea)
1223 prog->error_cmd(
"%s attempted to read from an out of bounds address %u+%"PRVM_PRIi"", prog->name, (
unsigned int)
OPA->_int,
OPB->_int);
1226 OPC->_int = ptr->_int;
1230 if ((
ofs =
addr - cached_vmentity0start) < cached_entityfieldsarea)
1243 prog->error_cmd(
"%s attempted to read from an out of bounds address %u+%"PRVM_PRIi"", prog->name, (
unsigned int)
OPA->_int,
OPB->_int);
1248 OPC->_int = ptr->_int;
1252 if ((
ofs =
addr - cached_vmentity0start) < cached_entityfieldsarea_2)
1265 prog->error_cmd(
"%s attempted to read from an out of bounds address %u+%"PRVM_PRIi"", prog->name, (
unsigned int)
OPA->_int,
OPB->_int);
1268 OPC->ivector[0] = ptr->ivector[0];
1269 OPC->ivector[1] = ptr->ivector[1];
1270 OPC->ivector[2] = ptr->ivector[2];
1285 if(
OPB->_uint != 0 )
1300#if !USE_COMPUTED_GOTOS
1303 prog->error_cmd(
"Bad opcode %i in %s. This program is corrupt or incompatible with DarkPlaces (or this version of it)", st->op, prog->name);
1306#if PRVMSLOWINTERPRETER
1308 if (prog->watch_global_type !=
ev_void)
1311 prog->xstatement = st - cached_statements;
1312 PRVM_Watchpoint(prog, 0,
"Global watchpoint hit", prog->watch_global_type, &prog->watch_global_value,
g);
1314 if (prog->watch_field_type !=
ev_void && prog->watch_edict < prog->max_edicts)
1317 prog->xstatement = st - cached_statements;
1318 PRVM_Watchpoint(prog, 0,
"Entityfield watchpoint hit", prog->watch_field_type, &prog->watch_edictfield_value,
g);