X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Fcomponents%2FSplitter.java;h=a6165d9df9658f3876a40f0554f59cf7b40c7b54;hb=ecc651406020231ff0ebc8d1bfc6f916693f69c6;hp=9eb5b2c04f7a40ffec936dd15bf7c43a6d5f21cb;hpb=67c1d352795802dae0c045cedeed82c883819d4e;p=Mograsim.git diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/Splitter.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/Splitter.java index 9eb5b2c0..a6165d9d 100644 --- a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/Splitter.java +++ b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/Splitter.java @@ -1,59 +1,60 @@ -package net.mograsim.logic.core.components; - -import java.util.List; - -import net.mograsim.logic.core.timeline.Timeline; -import net.mograsim.logic.core.types.BitVector; -import net.mograsim.logic.core.wires.WireObserver; -import net.mograsim.logic.core.wires.Wire.ReadEnd; -import net.mograsim.logic.core.wires.Wire.ReadWriteEnd; - -public class Splitter extends Component implements WireObserver -{ - private ReadEnd input; - private ReadWriteEnd[] outputs; - - public Splitter(Timeline timeline, ReadEnd input, ReadWriteEnd... outputs) - { - super(timeline); - this.input = input; - this.outputs = outputs; - input.addObserver(this); - int length = 0; - for (ReadEnd out : outputs) - length += out.length(); - - if (input.length() != length) - throw new IllegalArgumentException( - "The input of splitting one into n WireArrays must have length = a1.length() + a2.length() + ... + an.length()."); - } - - protected void compute() - { - BitVector inputBits = input.getValues(); - int startIndex = 0; - for (int i = 0; i < outputs.length; i++) - { - outputs[i].feedSignals(inputBits.subVector(startIndex, startIndex + outputs[i].length())); - startIndex += outputs[i].length(); - } - } - - @Override - public void update(ReadEnd initiator, BitVector oldValues) - { - compute(); - } - - @Override - public List getAllInputs() - { - return List.of(input); - } - - @Override - public List getAllOutputs() - { - return List.of(outputs); - } -} +package net.mograsim.logic.core.components; + +import java.util.List; + +import net.mograsim.logic.core.LogicObservable; +import net.mograsim.logic.core.LogicObserver; +import net.mograsim.logic.core.timeline.Timeline; +import net.mograsim.logic.core.types.BitVector; +import net.mograsim.logic.core.wires.Wire.ReadEnd; +import net.mograsim.logic.core.wires.Wire.ReadWriteEnd; + +public class Splitter extends Component implements LogicObserver +{ + private ReadEnd input; + private ReadWriteEnd[] outputs; + + public Splitter(Timeline timeline, ReadEnd input, ReadWriteEnd... outputs) + { + super(timeline); + this.input = input; + this.outputs = outputs; + input.registerObserver(this); + int length = 0; + for (ReadEnd out : outputs) + length += out.length(); + + if (input.length() != length) + throw new IllegalArgumentException( + "The input of splitting one into n WireArrays must have length = a1.length() + a2.length() + ... + an.length()."); + } + + protected void compute() + { + BitVector inputBits = input.getValues(); + int startIndex = 0; + for (int i = 0; i < outputs.length; i++) + { + outputs[i].feedSignals(inputBits.subVector(startIndex, startIndex + outputs[i].length())); + startIndex += outputs[i].length(); + } + } + + @Override + public void update(LogicObservable initiator) + { + compute(); + } + + @Override + public List getAllInputs() + { + return List.of(input); + } + + @Override + public List getAllOutputs() + { + return List.of(outputs); + } +}