summaryrefslogtreecommitdiff
path: root/gate.c
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2017-12-28 14:09:34 +1300
committerDavid Phillips <david@sighup.nz>2017-12-28 14:09:34 +1300
commite3ee67bfda0e8f4aa91992a196adb283f812475e (patch)
tree9c1f5629c77b7fd5535920d71adc033599d69e57 /gate.c
parente1a691b2b04b383f052d16931f5c34d6bc9d9e22 (diff)
downloadhence-e3ee67bfda0e8f4aa91992a196adb283f812475e.tar.xz
Strip out wire+node concepts, rely only on gates
Diffstat (limited to 'gate.c')
-rw-r--r--gate.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/gate.c b/gate.c
new file mode 100644
index 0000000..0d4337a
--- /dev/null
+++ b/gate.c
@@ -0,0 +1,46 @@
+#include <string.h>
+
+#include "gate.h"
+#include "error.h"
+
+#define GATE_MAX 1024
+
+static size_t gate_count;
+static struct gate gates[GATE_MAX];
+
+int
+gate_count_guard(void) {
+ if (gate_count >= GATE_MAX) {
+ emit_error("Internal: too many gates\n");
+ }
+ return 1;
+}
+
+int
+gate_add(struct gate *in1, struct gate *in2) {
+ struct gate g = {0};
+
+ if (gate_count_guard()) {
+ return 1;
+ }
+
+ g.in1 = in1;
+ g.in2 = in2;
+
+ gates[gate_count++] = g;
+
+ return 0;
+}
+
+int
+tick(void) {
+ /* FIXME */
+ return 1;
+}
+
+void
+gate_init(void) {
+ gate_count = 0;
+ memset(gates, 0, sizeof(gates));
+}
+