aboutsummaryrefslogtreecommitdiff
path: root/src/instset.c
blob: 1333ffb5e52621a7cce5892dabe03c5dbc74663a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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);
}