aboutsummaryrefslogtreecommitdiff
path: root/src/instset.c
diff options
context:
space:
mode:
authorPaul Oliver <contact@pauloliver.dev>2024-02-29 01:50:44 +0100
committerPaul Oliver <contact@pauloliver.dev>2024-02-29 01:50:44 +0100
commit2dc9d118efb64de6ea54a5a9eb4474f8e5ef3145 (patch)
tree74039957b10390da4875d676303a781bd0792e45 /src/instset.c
Initial commit
Diffstat (limited to 'src/instset.c')
-rw-r--r--src/instset.c56
1 files changed, 56 insertions, 0 deletions
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 <assert.h>
+#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);
+}