From 2dc9d118efb64de6ea54a5a9eb4474f8e5ef3145 Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Thu, 29 Feb 2024 01:50:44 +0100 Subject: Initial commit --- src/instset.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/instset.c (limited to 'src/instset.c') diff --git a/src/instset.c b/src/instset.c new file mode 100644 index 0000000..1333ffb --- /dev/null +++ b/src/instset.c @@ -0,0 +1,56 @@ +#include +#include "types.h" +#include "instset.h" + +sbool +si_isInst(sbyte inst) +{ + return inst < SINST_COUNT; +} + +static sbool +isBetween(sbyte inst, sbyte lo, sbyte hi) +{ + assert(si_isInst(inst)); + assert(lo < SINST_COUNT); + assert(hi < SINST_COUNT); + + if (inst < lo) { + return SFALSE; + } + + if (inst > hi) { + return SFALSE; + } + + return STRUE; +} + +sbool +si_isMod(sbyte inst) +{ + assert(si_isInst(inst)); + return isBetween(inst, SNOP0, SNOP3); +} + +sbool +si_isKey(sbyte inst) +{ + assert(si_isInst(inst)); + return isBetween(inst, SKEYA, SKEYP); +} + +sbool +si_isLock(sbyte inst) +{ + assert(si_isInst(inst)); + return isBetween(inst, SLOKA, SLOKP); +} + +sbool +si_keyLockMatch(sbyte key, sbyte lock) +{ + assert(si_isKey(key)); + assert(si_isInst(lock)); + return (key - SKEYA) == (lock - SLOKA); +} -- cgit v1.2.1