Search in sources :

Example 46 with ObservableValue

use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.

the class Net method interconnect.

/**
 * Do the interconnection.
 * All inputs and outputs in the net are connected together.
 * If there is no output an exception is thrown.
 * If there is one single output, all input {@link ObservableValue}s are set to this output
 * If there are more then one output a {@link DataBus} is created.
 * <p>
 * At the end all wires get a reference to the {@link ObservableValue} the represent
 *
 * @param m           the model is needed to create the {@link DataBus}
 * @param attachWires if true, the values are attached to the wires
 * @throws PinException PinException
 */
public void interconnect(Model m, boolean attachWires) throws PinException {
    ArrayList<Pin> inputs = new ArrayList<>();
    ArrayList<Pin> outputs = new ArrayList<>();
    for (Pin p : pins) {
        if (p.getDirection() == Pin.Direction.input)
            inputs.add(p);
        else
            outputs.add(p);
    }
    if (outputs.size() == 0)
        throw new PinException(Lang.get("err_noOutConnectedToWire", this.toString()), this);
    ObservableValue value = null;
    if (outputs.size() == 1 && outputs.get(0).getPullResistor() == PinDescription.PullResistor.none) {
        value = outputs.get(0).getValue();
    } else {
        value = new DataBus(this, m, outputs).getReadableOutput();
    }
    if (value == null)
        throw new PinException(Lang.get("err_output_N_notDefined", outputs.get(0)), this);
    for (Pin i : inputs) i.setValue(value);
    for (// set also the reader for bidirectional pins
    Pin o : // set also the reader for bidirectional pins
    outputs) o.setReaderValue(value);
    if (wires != null && attachWires)
        for (Wire w : wires) w.setValue(value);
}
Also used : Pin(de.neemann.digital.draw.elements.Pin) ArrayList(java.util.ArrayList) ObservableValue(de.neemann.digital.core.ObservableValue) PinException(de.neemann.digital.draw.elements.PinException) DataBus(de.neemann.digital.core.wiring.bus.DataBus) Wire(de.neemann.digital.draw.elements.Wire)

Example 47 with ObservableValue

use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.

the class SplitterMixTest method test2.

public void test2() throws Exception {
    ObservableValue a = new ObservableValue("a", 8);
    ObservableValue b = new ObservableValue("b", 8);
    Splitter splitter = new Splitter(new ElementAttributes().set(Keys.INPUT_SPLIT, "8,8").set(Keys.OUTPUT_SPLIT, "12,4"));
    splitter.setInputs(ovs(a, b));
    assertEquals(1, a.observerCount());
    assertEquals(2, b.observerCount());
    ObservableValues outputs = splitter.getOutputs();
    assertEquals(2, outputs.size());
    TestExecuter sc = new TestExecuter().setInputs(a, b).setOutputsOf(splitter);
    sc.check(0x00, 0x00, 0x000, 0x0);
    sc.check(0x01, 0x00, 0x001, 0x0);
    sc.check(0x10, 0x00, 0x010, 0x0);
    sc.check(0x00, 0x01, 0x100, 0x0);
    sc.check(0x00, 0x10, 0x000, 0x1);
    sc.check(0x0f, 0x00, 0x00f, 0x0);
    sc.check(0xf0, 0x00, 0x0f0, 0x0);
    sc.check(0x00, 0x0f, 0xf00, 0x0);
    sc.check(0x00, 0xf0, 0x000, 0xf);
    sc.check(0xbc, 0xda, 0xabc, 0xd);
}
Also used : ObservableValues(de.neemann.digital.core.ObservableValues) ObservableValue(de.neemann.digital.core.ObservableValue) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 48 with ObservableValue

use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.

the class SplitterMixTest method test1.

public void test1() throws Exception {
    ObservableValue a = new ObservableValue("a", 8);
    ObservableValue b = new ObservableValue("b", 8);
    Splitter splitter = new Splitter(new ElementAttributes().set(Keys.INPUT_SPLIT, "8,8").set(Keys.OUTPUT_SPLIT, "4,12"));
    splitter.setInputs(ovs(a, b));
    assertEquals(2, a.observerCount());
    assertEquals(1, b.observerCount());
    ObservableValues outputs = splitter.getOutputs();
    assertEquals(2, outputs.size());
    TestExecuter sc = new TestExecuter().setInputs(a, b).setOutputsOf(splitter);
    sc.check(0x00, 0x00, 0x0, 0x000);
    sc.check(0x01, 0x00, 0x1, 0x000);
    sc.check(0x10, 0x00, 0x0, 0x001);
    sc.check(0x00, 0x01, 0x0, 0x010);
    sc.check(0x00, 0x10, 0x0, 0x100);
    sc.check(0x0f, 0x00, 0xf, 0x000);
    sc.check(0xf0, 0x00, 0x0, 0x00f);
    sc.check(0x00, 0x0f, 0x0, 0x0f0);
    sc.check(0x00, 0xf0, 0x0, 0xf00);
    sc.check(0xc0, 0xab, 0x0, 0xabc);
}
Also used : ObservableValues(de.neemann.digital.core.ObservableValues) ObservableValue(de.neemann.digital.core.ObservableValue) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 49 with ObservableValue

use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.

the class SplitterMixTest method test3.

public void test3() throws Exception {
    ObservableValue a = new ObservableValue("a", 4);
    ObservableValue b = new ObservableValue("b", 4);
    ObservableValue c = new ObservableValue("c", 4);
    Splitter splitter = new Splitter(new ElementAttributes().set(Keys.INPUT_SPLIT, "4,4,4").set(Keys.OUTPUT_SPLIT, "2,8,2"));
    splitter.setInputs(ovs(a, b, c));
    assertEquals(2, a.observerCount());
    assertEquals(1, b.observerCount());
    assertEquals(2, c.observerCount());
    ObservableValues outputs = splitter.getOutputs();
    assertEquals(3, outputs.size());
    TestExecuter sc = new TestExecuter().setInputs(a, b, c).setOutputsOf(splitter);
    sc.check(0x0, 0x0, 0x0, 0x0, 0x00, 0x0);
    sc.check(0xf, 0x0, 0x0, 0x3, 0x03, 0x0);
    sc.check(0x0, 0xf, 0x0, 0x0, 0x3c, 0x0);
    sc.check(0x0, 0x0, 0xf, 0x0, 0xc0, 0x3);
    sc.check(0xf, 0xf, 0xf, 0x3, 0xff, 0x3);
}
Also used : ObservableValues(de.neemann.digital.core.ObservableValues) ObservableValue(de.neemann.digital.core.ObservableValue) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 50 with ObservableValue

use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.

the class AddTest method testAdd31.

public void testAdd31() throws Exception {
    ObservableValue a = new ObservableValue("a", 31);
    ObservableValue b = new ObservableValue("b", 31);
    ObservableValue c = new ObservableValue("c", 1);
    Model model = new Model();
    Add node = new Add(new ElementAttributes().setBits(31));
    node.setInputs(ovs(a, b, c));
    model.add(node);
    TestExecuter sc = new TestExecuter(model).setInputs(a, b, c).setOutputs(node.getOutputs());
    sc.check(-1, 0, 1, 0, 1);
    sc.check(-1, 1, 0, 0, 1);
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Aggregations

ObservableValue (de.neemann.digital.core.ObservableValue)88 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)73 TestExecuter (de.neemann.digital.TestExecuter)61 Model (de.neemann.digital.core.Model)56 ObservableValues (de.neemann.digital.core.ObservableValues)17 NodeException (de.neemann.digital.core.NodeException)5 ArrayList (java.util.ArrayList)4 BitsException (de.neemann.digital.core.BitsException)3 FanIn (de.neemann.digital.core.basic.FanIn)3 Signal (de.neemann.digital.core.Signal)2 Element (de.neemann.digital.core.element.Element)2 Clock (de.neemann.digital.core.wiring.Clock)2 Delay (de.neemann.digital.core.wiring.Delay)2 DataBus (de.neemann.digital.core.wiring.bus.DataBus)2 IOState (de.neemann.digital.draw.elements.IOState)2 CircuitComponent (de.neemann.digital.gui.components.CircuitComponent)2 Sync (de.neemann.digital.gui.sync.Sync)2 BurnException (de.neemann.digital.core.BurnException)1 Node (de.neemann.digital.core.Node)1 NodeWithoutDelay (de.neemann.digital.core.NodeWithoutDelay)1