From f228b6873676674d076e893ef7cf3fff3cfba009 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Wed, 31 Jan 2018 05:23:48 +0000 Subject: [PATCH] CON: Add if statements if(var(var)){a,b}(e). Inspired by x86 assembly, these stand for "above" and "below", and perform unsigned versions of greater-than and less-than, respectively. Useful for testing array bounds. git-svn-id: https://svn.eduke32.com/eduke32@6640 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/duke3d/src/gamedef.cpp | 20 ++++++++++ source/duke3d/src/gamedef.h | 8 ++++ source/duke3d/src/gameexec.cpp | 56 ++++++++++++++++++++++++++ source/duke3d/src/m32def.cpp | 12 ++++++ source/duke3d/src/m32def.h | 8 ++++ source/duke3d/src/m32exec.cpp | 72 ++++++++++++++++++++++++++++++++++ 6 files changed, 176 insertions(+) diff --git a/source/duke3d/src/gamedef.cpp b/source/duke3d/src/gamedef.cpp index e0e4e4d2b..e350f5186 100644 --- a/source/duke3d/src/gamedef.cpp +++ b/source/duke3d/src/gamedef.cpp @@ -308,7 +308,11 @@ static tokenmap_t const vm_keywords[] = { "ifspritepal", CON_IFSPRITEPAL }, { "ifsquished", CON_IFSQUISHED }, { "ifstrength", CON_IFSTRENGTH }, + { "ifvara", CON_IFVARA }, + { "ifvarae", CON_IFVARAE }, { "ifvarand", CON_IFVARAND }, + { "ifvarb", CON_IFVARB }, + { "ifvarbe", CON_IFVARBE }, { "ifvarboth", CON_IFVARBOTH }, { "ifvare", CON_IFVARE }, { "ifvareither", CON_IFVAREITHER }, @@ -318,7 +322,11 @@ static tokenmap_t const vm_keywords[] = { "ifvarle", CON_IFVARLE }, { "ifvarn", CON_IFVARN }, { "ifvaror", CON_IFVAROR }, + { "ifvarvara", CON_IFVARVARA }, + { "ifvarvarae", CON_IFVARVARAE }, { "ifvarvarand", CON_IFVARVARAND }, + { "ifvarvarb", CON_IFVARVARB }, + { "ifvarvarbe", CON_IFVARVARBE }, { "ifvarvarboth", CON_IFVARVARBOTH }, { "ifvarvare", CON_IFVARVARE }, { "ifvarvareither", CON_IFVARVAREITHER }, @@ -534,6 +542,10 @@ static tokenmap_t const vm_keywords[] = { "and", CON_ANDVARVAR }, { "or", CON_ORVARVAR }, { "xor", CON_XORVARVAR }, + { "ifa", CON_IFVARVARA }, + { "ifae", CON_IFVARVARAE }, + { "ifb", CON_IFVARVARB }, + { "ifbe", CON_IFVARVARBE }, { "ifl", CON_IFVARVARL }, { "ifle", CON_IFVARVARLE }, { "ifg", CON_IFVARVARG }, @@ -4638,6 +4650,10 @@ DO_DEFSTATE: case CON_IFVARVARE: case CON_IFVARVARLE: case CON_IFVARVARGE: + case CON_IFVARVARA: + case CON_IFVARVARB: + case CON_IFVARVARAE: + case CON_IFVARVARBE: case CON_IFVARVARBOTH: case CON_IFVARVARN: case CON_IFVARVARAND: @@ -4688,6 +4704,10 @@ DO_DEFSTATE: case CON_IFVARLE: case CON_IFVARG: case CON_IFVARGE: + case CON_IFVARA: + case CON_IFVARAE: + case CON_IFVARB: + case CON_IFVARBE: case CON_IFVARE: case CON_IFVARN: case CON_IFVARAND: diff --git a/source/duke3d/src/gamedef.h b/source/duke3d/src/gamedef.h index 1d9c8c439..447a75db5 100644 --- a/source/duke3d/src/gamedef.h +++ b/source/duke3d/src/gamedef.h @@ -1214,6 +1214,14 @@ enum ScriptKeywords_t CON_DIVRU, // 413 CON_SWAPTRACKSLOT, // 414 CON_PRELOADTRACKSLOTFORSWAP, // 415 + CON_IFVARA, // 416 + CON_IFVARVARA, // 417 + CON_IFVARAE, // 418 + CON_IFVARVARAE, // 419 + CON_IFVARB, // 420 + CON_IFVARVARB, // 421 + CON_IFVARBE, // 422 + CON_IFVARVARBE, // 423 CON_END }; // KEEPINSYNC with the keyword list in lunatic/con_lang.lua diff --git a/source/duke3d/src/gameexec.cpp b/source/duke3d/src/gameexec.cpp index 77578cc55..07ad97e61 100644 --- a/source/duke3d/src/gameexec.cpp +++ b/source/duke3d/src/gameexec.cpp @@ -5205,6 +5205,38 @@ finish_qsprintf: VM_CONDITIONAL(tw); continue; + case CON_IFVARVARA: + insptr++; + tw = Gv_GetVarX(*insptr++); + tw = ((uint32_t)tw > (uint32_t)Gv_GetVarX(*insptr++)); + insptr--; + VM_CONDITIONAL(tw); + continue; + + case CON_IFVARVARAE: + insptr++; + tw = Gv_GetVarX(*insptr++); + tw = ((uint32_t)tw >= (uint32_t)Gv_GetVarX(*insptr++)); + insptr--; + VM_CONDITIONAL(tw); + continue; + + case CON_IFVARVARB: + insptr++; + tw = Gv_GetVarX(*insptr++); + tw = ((uint32_t)tw < (uint32_t)Gv_GetVarX(*insptr++)); + insptr--; + VM_CONDITIONAL(tw); + continue; + + case CON_IFVARVARBE: + insptr++; + tw = Gv_GetVarX(*insptr++); + tw = ((uint32_t)tw <= (uint32_t)Gv_GetVarX(*insptr++)); + insptr--; + VM_CONDITIONAL(tw); + continue; + case CON_IFVARN: insptr++; tw = Gv_GetVarX(*insptr++); @@ -5474,6 +5506,30 @@ finish_qsprintf: VM_CONDITIONAL(tw <= *insptr); continue; + case CON_IFVARA: + insptr++; + tw = Gv_GetVarX(*insptr++); + VM_CONDITIONAL((uint32_t)tw > (uint32_t)*insptr); + continue; + + case CON_IFVARAE: + insptr++; + tw = Gv_GetVarX(*insptr++); + VM_CONDITIONAL((uint32_t)tw >= (uint32_t)*insptr); + continue; + + case CON_IFVARB: + insptr++; + tw = Gv_GetVarX(*insptr++); + VM_CONDITIONAL((uint32_t)tw < (uint32_t)*insptr); + continue; + + case CON_IFVARBE: + insptr++; + tw = Gv_GetVarX(*insptr++); + VM_CONDITIONAL((uint32_t)tw <= (uint32_t)*insptr); + continue; + case CON_IFPHEALTHL: insptr++; VM_CONDITIONAL(sprite[pPlayer->i].extra < *insptr); diff --git a/source/duke3d/src/m32def.cpp b/source/duke3d/src/m32def.cpp index 486d8f4ea..c135007c9 100644 --- a/source/duke3d/src/m32def.cpp +++ b/source/duke3d/src/m32def.cpp @@ -163,6 +163,10 @@ const tokenmap_t altkeyw[] = { "and", CON_ANDVARVAR }, { "or", CON_ORVARVAR }, { "xor", CON_XORVARVAR }, + { "ifa", CON_IFVARVARA }, + { "ifae", CON_IFVARVARAE }, + { "ifb", CON_IFVARVARB }, + { "ifbe", CON_IFVARVARBE }, { "ifl", CON_IFVARVARL }, { "ifle", CON_IFVARVARLE }, { "ifg", CON_IFVARVARG }, @@ -263,6 +267,10 @@ const char *keyw[] = "ifvarle", "ifvarg", "ifvarge", + "ifvara", + "ifvarae", + "ifvarb", + "ifvarbe", "ifvare", "ifvarn", "ifvarand", @@ -277,6 +285,10 @@ const char *keyw[] = "ifvarvarle", "ifvarvarg", "ifvarvarge", + "ifvarvara", + "ifvarvarae", + "ifvarvarb", + "ifvarvarbe", "ifvarvare", "ifvarvarn", "ifvarvarand", diff --git a/source/duke3d/src/m32def.h b/source/duke3d/src/m32def.h index 5c8be0c3d..86a4259b8 100644 --- a/source/duke3d/src/m32def.h +++ b/source/duke3d/src/m32def.h @@ -390,6 +390,10 @@ enum ScriptKeywords_t CON_IFVARLE, CON_IFVARG, CON_IFVARGE, + CON_IFVARA, + CON_IFVARAE, + CON_IFVARB, + CON_IFVARBE, CON_IFVARE, CON_IFVARN, CON_IFVARAND, @@ -405,6 +409,10 @@ enum ScriptKeywords_t CON_IFVARVARLE, CON_IFVARVARG, CON_IFVARVARGE, + CON_IFVARVARA, + CON_IFVARVARAE, + CON_IFVARVARB, + CON_IFVARVARBE, CON_IFVARVARE, CON_IFVARVARN, CON_IFVARVARAND, diff --git a/source/duke3d/src/m32exec.cpp b/source/duke3d/src/m32exec.cpp index 61d40ebf4..012d0a86d 100644 --- a/source/duke3d/src/m32exec.cpp +++ b/source/duke3d/src/m32exec.cpp @@ -1096,6 +1096,46 @@ skip_check: } continue; + case CON_IFVARVARA: + insptr++; + { + int32_t j = Gv_GetVarX(*insptr++); + j = ((uint32_t)j > (uint32_t)Gv_GetVarX(*insptr++)); + insptr--; + VM_DoConditional(j); + } + continue; + + case CON_IFVARVARAE: + insptr++; + { + int32_t j = Gv_GetVarX(*insptr++); + j = ((uint32_t)j >= (uint32_t)Gv_GetVarX(*insptr++)); + insptr--; + VM_DoConditional(j); + } + continue; + + case CON_IFVARVARB: + insptr++; + { + int32_t j = Gv_GetVarX(*insptr++); + j = ((uint32_t)j < (uint32_t)Gv_GetVarX(*insptr++)); + insptr--; + VM_DoConditional(j); + } + continue; + + case CON_IFVARVARBE: + insptr++; + { + int32_t j = Gv_GetVarX(*insptr++); + j = ((uint32_t)j <= (uint32_t)Gv_GetVarX(*insptr++)); + insptr--; + VM_DoConditional(j); + } + continue; + case CON_IFVARE: insptr++; { @@ -1527,6 +1567,38 @@ badindex: } continue; + case CON_IFVARA: + insptr++; + { + int32_t j=Gv_GetVarX(*insptr++); + VM_DoConditional((uint32_t)j > (uint32_t)*insptr); + } + continue; + + case CON_IFVARAE: + insptr++; + { + int32_t j=Gv_GetVarX(*insptr++); + VM_DoConditional((uint32_t)j >= (uint32_t)*insptr); + } + continue; + + case CON_IFVARB: + insptr++; + { + int32_t j=Gv_GetVarX(*insptr++); + VM_DoConditional((uint32_t)j < (uint32_t)*insptr); + } + continue; + + case CON_IFVARBE: + insptr++; + { + int32_t j=Gv_GetVarX(*insptr++); + VM_DoConditional((uint32_t)j <= (uint32_t)*insptr); + } + continue; + case CON_IFRND: VM_DoConditional(rnd(Gv_GetVarX(*(++insptr)))); continue;