summaryrefslogtreecommitdiff
path: root/gate.c
diff options
context:
space:
mode:
Diffstat (limited to 'gate.c')
-rw-r--r--gate.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/gate.c b/gate.c
index fb5ff41..67d9c08 100644
--- a/gate.c
+++ b/gate.c
@@ -125,6 +125,38 @@ gate_dump(void) {
emit_info("Gates:\n");
for (i = 0; i < gate_count; i++) {
- emit_info("gate '%s'\n", gates[i].name);
+ emit_info("gate '%s': %s\n", gates[i].name, gates[i].output == LOGIC_HIGH ? "HIGH" : "LOW");
}
}
+
+int
+gate_set_input(char *name, enum BINARY value) {
+ struct gate *g = NULL;
+
+ if (NULL == (g = gate_get_input_by_name(name))) {
+ emit_error("No such input %s", name);
+ return 1;
+ }
+
+ g->output = value;
+
+ return 0;
+}
+
+void gate_update() {
+ size_t i = 0;
+ struct gate *g = NULL;
+ enum BINARY in1 = LOGIC_LOW;
+ enum BINARY in2 = LOGIC_LOW;
+
+ /* FIXME should be input->output flow path */
+ /* FIXME data flow doesn't matter yet because gate chaining isn't allowed */
+
+ for (i = 0; i < gate_count; i++) {
+ g = &gates[i];
+ in1 = g->in1->output;
+ in2 = g->in2->output;
+ g->output = (g->operation)(in1, in2);
+ }
+}
+