Generalized WireObserver to LogicObserver
[Mograsim.git] / net.mograsim.logic.core / src / net / mograsim / logic / core / components / TriStateBuffer.java
index f4f1b49..1f8f85a 100644 (file)
@@ -1,51 +1,51 @@
-package net.mograsim.logic.core.components;
-
-import java.util.List;
-
-import net.mograsim.logic.core.timeline.Timeline;
-import net.mograsim.logic.core.types.Bit;
-import net.mograsim.logic.core.wires.Wire.ReadEnd;
-import net.mograsim.logic.core.wires.Wire.ReadWriteEnd;
-
-public class TriStateBuffer extends BasicComponent
-{
-       ReadEnd in, enable;
-       ReadWriteEnd out;
-
-       public TriStateBuffer(Timeline timeline, int processTime, ReadEnd in, ReadWriteEnd out, ReadEnd enable)
-       {
-               super(timeline, processTime);
-               if (in.length() != out.length())
-                       throw new IllegalArgumentException(
-                                       "Tri-state output must have the same amount of bits as the input. Input: " + in.length() + " Output: " + out.length());
-               if (enable.length() != 1)
-                       throw new IllegalArgumentException("Tri-state enable must have exactly one bit, not " + enable.length() + ".");
-               this.in = in;
-               in.addObserver(this);
-               this.enable = enable;
-               enable.addObserver(this);
-               this.out = out;
-       }
-
-       @Override
-       protected void compute()
-       {
-               if (enable.getValue() == Bit.ONE)
-                       out.feedSignals(in.getValues());
-               else
-                       out.clearSignals();
-       }
-
-       @Override
-       public List<ReadEnd> getAllInputs()
-       {
-               return List.of(in, enable);
-       }
-
-       @Override
-       public List<ReadWriteEnd> getAllOutputs()
-       {
-               return List.of(out);
-       }
-
-}
+package net.mograsim.logic.core.components;\r
+\r
+import java.util.List;\r
+\r
+import net.mograsim.logic.core.timeline.Timeline;\r
+import net.mograsim.logic.core.types.Bit;\r
+import net.mograsim.logic.core.wires.Wire.ReadEnd;\r
+import net.mograsim.logic.core.wires.Wire.ReadWriteEnd;\r
+\r
+public class TriStateBuffer extends BasicComponent\r
+{\r
+       ReadEnd in, enable;\r
+       ReadWriteEnd out;\r
+\r
+       public TriStateBuffer(Timeline timeline, int processTime, ReadEnd in, ReadWriteEnd out, ReadEnd enable)\r
+       {\r
+               super(timeline, processTime);\r
+               if (in.length() != out.length())\r
+                       throw new IllegalArgumentException(\r
+                                       "Tri-state output must have the same amount of bits as the input. Input: " + in.length() + " Output: " + out.length());\r
+               if (enable.length() != 1)\r
+                       throw new IllegalArgumentException("Tri-state enable must have exactly one bit, not " + enable.length() + ".");\r
+               this.in = in;\r
+               in.registerObserver(this);\r
+               this.enable = enable;\r
+               enable.registerObserver(this);\r
+               this.out = out;\r
+       }\r
+\r
+       @Override\r
+       protected void compute()\r
+       {\r
+               if (enable.getValue() == Bit.ONE)\r
+                       out.feedSignals(in.getValues());\r
+               else\r
+                       out.clearSignals();\r
+       }\r
+\r
+       @Override\r
+       public List<ReadEnd> getAllInputs()\r
+       {\r
+               return List.of(in, enable);\r
+       }\r
+\r
+       @Override\r
+       public List<ReadWriteEnd> getAllOutputs()\r
+       {\r
+               return List.of(out);\r
+       }\r
+\r
+}\r