Search in sources :

Example 36 with ObservableValue

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

the class TestTrans method testTrans.

public void testTrans() throws Exception {
    Model model = new ToBreakRunner("dig/test/transp/transtest3.dig").getModel();
    assertEquals(2, model.getInputs().size());
    assertEquals(1, model.getOutputs().size());
    assertEquals(1, model.getNodes().size());
    Node node = model.getNodes().get(0);
    assertTrue(node instanceof XOr);
    XOr xor = (XOr) node;
    // The models inputs are the xor input values!
    // All the intermediate transparent stuff is removed!
    ArrayList<ObservableValue> ins = new ArrayList<>();
    for (Signal s : model.getInputs()) ins.add(s.getValue());
    assertTrue(ins.contains(xor.getInputs().get(0)));
    assertTrue(ins.contains(xor.getInputs().get(1)));
}
Also used : Signal(de.neemann.digital.core.Signal) Node(de.neemann.digital.core.Node) Model(de.neemann.digital.core.Model) ObservableValue(de.neemann.digital.core.ObservableValue) ArrayList(java.util.ArrayList) XOr(de.neemann.digital.core.basic.XOr)

Example 37 with ObservableValue

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

the class CircuitComponent method actualToDefault.

/**
 * Makes actual input values to the default value
 */
public void actualToDefault() {
    if (!isLocked()) {
        Modifications.Builder builder = new Modifications.Builder(Lang.get("menu_actualToDefault"));
        for (VisualElement ve : circuit.getElements()) if (ve.equalsDescription(In.DESCRIPTION)) {
            ObservableValue ov = ((InputShape) ve.getShape()).getObservableValue();
            if (ov != null) {
                InValue newValue = new InValue(ov);
                InValue oldValue = ve.getElementAttributes().get(Keys.INPUT_DEFAULT);
                if (!newValue.equals(oldValue))
                    builder.add(new ModifyAttribute<>(ve, Keys.INPUT_DEFAULT, newValue));
            }
        }
        modify(builder.build());
    }
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) InValue(de.neemann.digital.core.io.InValue)

Example 38 with ObservableValue

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

the class FlipFlopsTest method testFlipFlopJKMS.

public void testFlipFlopJKMS() throws Exception {
    ObservableValue j = new ObservableValue("j", 1);
    ObservableValue k = new ObservableValue("k", 1);
    ObservableValue c = new ObservableValue("c", 1);
    ElementAttributes attr = new ElementAttributes().setBits(1);
    Model model = new Model();
    FanIn nor3 = model.add(new NOr(attr));
    FanIn nor4 = model.add(new NOr(attr));
    FanIn a1 = model.add(new And(attr));
    a1.setInputs(ovs(j, c, nor4.getOutput()));
    FanIn a2 = model.add(new And(attr));
    a2.setInputs(ovs(k, c, nor3.getOutput()));
    Not not = model.add(new Not(attr));
    not.setInputs(c.asList());
    FanIn nor1 = model.add(new NOr(attr));
    FanIn nor2 = model.add(new NOr(attr));
    nor1.setInputs(ovs(a1.getOutput(), nor2.getOutput()));
    nor2.setInputs(ovs(a2.getOutput(), nor1.getOutput()));
    FanIn a3 = model.add(new And(attr));
    a3.setInputs(ovs(nor1.getOutput(), not.getOutputs().get(0)));
    FanIn a4 = model.add(new And(attr));
    a4.setInputs(ovs(nor2.getOutput(), not.getOutputs().get(0)));
    nor3.setInputs(ovs(a3.getOutput(), nor4.getOutput()));
    nor4.setInputs(ovs(a4.getOutput(), nor3.getOutput()));
    TestExecuter sc = new TestExecuter(model, true).setInputs(c, j, k).setOutputs(nor3.getOutput(), nor4.getOutput());
    // undefined
    sc.checkZ(0, 1, 0, IGNORE, IGNORE);
    // undefined
    sc.checkZ(1, 1, 0, IGNORE, IGNORE);
    sc.check(0, 1, 0, 1, 0);
    sc.check(0, 0, 0, 1, 0);
    sc.check(1, 0, 0, 1, 0);
    sc.check(0, 1, 0, 1, 0);
    sc.check(1, 1, 0, 1, 0);
    sc.check(0, 0, 0, 1, 0);
    sc.check(1, 0, 0, 1, 0);
    sc.check(0, 0, 1, 1, 0);
    sc.check(1, 0, 1, 1, 0);
    sc.check(0, 0, 1, 0, 1);
    sc.check(0, 1, 1, 0, 1);
    sc.check(1, 1, 1, 0, 1);
    sc.check(0, 1, 1, 1, 0);
    sc.check(1, 1, 1, 1, 0);
    sc.check(0, 1, 1, 0, 1);
    sc.check(1, 1, 1, 0, 1);
    sc.check(0, 1, 1, 1, 0);
    sc.check(1, 1, 1, 1, 0);
    sc.check(0, 1, 1, 0, 1);
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) ElementAttributes(de.neemann.digital.core.element.ElementAttributes)

Example 39 with ObservableValue

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

the class FlipFlopsTest method testFlipFlopNAnd.

public void testFlipFlopNAnd() throws Exception {
    ObservableValue r = new ObservableValue("r", 1);
    ObservableValue s = new ObservableValue("s", 1);
    Model model = new Model();
    FanIn a1 = model.add(new NAnd(new ElementAttributes().setBits(1)));
    FanIn a2 = model.add(new NAnd(new ElementAttributes().setBits(1)));
    a1.setInputs(ovs(r, a2.getOutput()));
    a2.setInputs(ovs(s, a1.getOutput()));
    TestExecuter sc = new TestExecuter(model).setInputs(r, s).setOutputs(a1.getOutput(), a2.getOutput());
    sc.check(1, 0, 0, 1);
    sc.check(1, 1, 0, 1);
    sc.check(0, 1, 1, 0);
    sc.check(1, 1, 1, 0);
    sc.check(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)

Example 40 with ObservableValue

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

the class FlipFlopsTest method testFlipFlopNOr.

public void testFlipFlopNOr() throws Exception {
    ObservableValue r = new ObservableValue("r", 1);
    ObservableValue s = new ObservableValue("s", 1);
    Model model = new Model();
    FanIn a1 = model.add(new NOr(new ElementAttributes().setBits(1)));
    FanIn a2 = model.add(new NOr(new ElementAttributes().setBits(1)));
    a1.setInputs(ovs(r, a2.getOutput()));
    a2.setInputs(ovs(s, a1.getOutput()));
    TestExecuter sc = new TestExecuter(model, true).setInputs(r, s).setOutputs(a1.getOutput(), a2.getOutput());
    sc.check(0, 1, 1, 0);
    sc.check(0, 0, 1, 0);
    sc.check(1, 0, 0, 1);
    sc.check(0, 0, 0, 1);
    sc.check(0, 1, 1, 0);
    // verbotener Zustand!!
    sc.check(1, 1, 0, 0);
    // gehe aus verbotenem Zustand raus!!!
    r.setValue(0);
    s.setValue(0);
    // geht nur mit noise!
    model.doStep(true);
    assertTrue(// endzustand ist undefiniert!
    (a1.getOutput().getValue() == 1 && a2.getOutput().getValue() == 0) || (a1.getOutput().getValue() == 0 && a2.getOutput().getValue() == 1));
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) ElementAttributes(de.neemann.digital.core.element.ElementAttributes)

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