summaryrefslogtreecommitdiff
path: root/src/binding.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/binding.c')
-rw-r--r--src/binding.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/binding.c b/src/binding.c
new file mode 100644
index 0000000..1680a1b
--- /dev/null
+++ b/src/binding.c
@@ -0,0 +1,45 @@
+#include "binding.h"
+#include <stdio.h>
+
+
+int has_key(uint64_t keys[static KEYS_SIZE], int code)
+{
+ return (keys[code/64] & 1ULL << code % 64) > 0;
+}
+
+void set_key(uint64_t keys[static KEYS_SIZE], int code)
+{
+ keys[code/64] |= 1ULL << (code % 64);
+}
+
+void clear_key(uint64_t keys[static KEYS_SIZE], int code)
+{
+ keys[code/64] &= ~(1ULL << code % 64);
+}
+
+int is_keys_subset_of(uint64_t a[static KEYS_SIZE], uint64_t b[static KEYS_SIZE])
+{
+ for (size_t i = 0; i < KEYS_SIZE; i++)
+ {
+ if ((a[i] & b[i]) != a[i])
+ {
+ return 0;
+ }
+ }
+ return 1;
+}
+
+void print_keys(uint64_t keys[static KEYS_SIZE])
+{
+ for (size_t i = 0; i < KEYS_SIZE; i++)
+ {
+ for (size_t j = 0; j < 64; j++)
+ {
+ if (keys[i] & 1ULL<<j)
+ {
+ printf("%d ", i * 64 + j);
+ }
+ }
+ }
+ putchar('\n');
+}