Search in sources :

Example 21 with ObservableValue

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

the class ROMTest method testROM.

public void testROM() throws Exception {
    ObservableValue addr = new ObservableValue("addr", 3);
    ObservableValue sel = new ObservableValue("sel", 1);
    Model model = new Model();
    DataField data = new DataField(8);
    data.setData(3, 17);
    data.setData(7, 200);
    ROM out = model.add(new ROM(new ElementAttributes().setBits(8).set(Keys.ADDR_BITS, 3).set(Keys.DATA, data)));
    out.setInputs(ovs(addr, sel));
    TestExecuter sc = new TestExecuter(model).setInputs(addr, sel).setOutputs(out.getOutputs());
    sc.check(0, 1, 0);
    sc.check(1, 1, 0);
    sc.check(2, 1, 0);
    sc.check(3, 1, 17);
    sc.check(4, 1, 0);
    sc.check(5, 1, 0);
    sc.check(6, 1, 0);
// try {  ToDo HighZ
// sc.check(6, 0, 0);
// assertTrue(false);
// } catch (HighZException e) {
// assertTrue(true);
// }
}
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)

Example 22 with ObservableValue

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

the class RegisterFileTest method testRegisterFile.

public void testRegisterFile() throws Exception {
    ObservableValue ra = new ObservableValue("ra", 2);
    ObservableValue rb = new ObservableValue("rb", 2);
    ObservableValue rw = new ObservableValue("rw", 2);
    ObservableValue in = new ObservableValue("in", 4);
    ObservableValue we = new ObservableValue("we", 1);
    ObservableValue clk = new ObservableValue("clk", 1);
    Model model = new Model();
    RegisterFile out = model.add(new RegisterFile(new ElementAttributes().set(Keys.ADDR_BITS, 2).setBits(4)));
    out.setInputs(ovs(in, we, rw, clk, ra, rb));
    TestExecuter sc = new TestExecuter(model).setInputs(clk, in, we, rw, ra, rb).setOutputs(out.getOutputs());
    // c  in we rw ra rb da db
    sc.check(0, 0, 0, 0, 0, 0, 0, 0);
    sc.check(1, 7, 1, 1, 0, 0, 0, 0);
    sc.check(0, 0, 0, 0, 1, 1, 7, 7);
    sc.check(1, 5, 1, 2, 1, 1, 7, 7);
    sc.check(0, 0, 0, 0, 1, 2, 7, 5);
}
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)

Example 23 with ObservableValue

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

the class BitSelectorTest method testBitSel.

public void testBitSel() throws Exception {
    Model model = new Model();
    ObservableValue d = new ObservableValue("d", 4);
    ObservableValue sel = new ObservableValue("sel", 2);
    BitSelector out = model.add(new BitSelector(new ElementAttributes().set(Keys.SELECTOR_BITS, 2)));
    out.setInputs(ovs(d, sel));
    TestExecuter te = new TestExecuter(model).setInputs(d, sel).setOutputs(out.getOutputs());
    te.check(5, 0, 1);
    te.check(5, 1, 0);
    te.check(5, 2, 1);
    te.check(5, 3, 0);
    te.check(10, 0, 0);
    te.check(10, 1, 1);
    te.check(10, 2, 0);
    te.check(10, 3, 1);
}
Also used : Model(de.neemann.digital.core.Model) ObservableValue(de.neemann.digital.core.ObservableValue) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 24 with ObservableValue

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

the class DataBusTest method testSimple.

public void testSimple() throws PinException, NodeException {
    ObservableValue a = new ObservableValue("a", 4).setToHighZ();
    ObservableValue b = new ObservableValue("b", 4).setToHighZ();
    Model m = new Model();
    ObservableValue out = new DataBus(null, m, a, b).getReadableOutput();
    a.setValue(1);
    assertEquals(1, out.getValue());
    a.setToHighZ();
    b.setValue(2);
    assertEquals(2, out.getValue());
    b.setToHighZ();
    // try {  ToDo HighZ
    // out.getValue();
    // assertTrue(false);
    // } catch (HighZException e) {
    // assertTrue(true);
    // }
    a.setValue(1);
    b.setValue(1);
    m.doStep();
    a.setValue(0);
    b.setValue(0);
    m.doStep();
    a.setValue(1);
    b.setValue(0);
    try {
        m.doStep();
        assertTrue(true);
    } catch (BurnException e) {
        assertTrue(true);
    }
}
Also used : BurnException(de.neemann.digital.core.BurnException) ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) DataBus(de.neemann.digital.core.wiring.bus.DataBus)

Example 25 with ObservableValue

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

the class InputShape method applyStateMonitor.

@Override
public Interactor applyStateMonitor(IOState ioState, Observer guiObserver) {
    this.ioState = ioState;
    ioState.getOutput(0).addObserverToValue(guiObserver);
    return new Interactor() {

        @Override
        public boolean clicked(CircuitComponent cc, Point pos, IOState ioState, Element element, Sync modelSync) {
            ObservableValue value = ioState.getOutput(0);
            if (value.getBits() == 1) {
                modelSync.access(() -> {
                    if (isHighZ) {
                        if (value.isHighZ())
                            value.setValue(0);
                        else if (value.getValue() == 0)
                            value.setValue(1);
                        else
                            value.setToHighZ();
                    } else
                        value.setValue(1 - value.getValue());
                });
                return true;
            } else {
                if (dialog == null || !dialog.isVisible()) {
                    Model model = ((In) element).getModel();
                    dialog = new SingleValueDialog(model.getWindowPosManager().getMainFrame(), pos, label, value, isHighZ, cc, model, modelSync);
                    dialog.setVisible(true);
                } else
                    dialog.requestFocus();
                return false;
            }
        }
    };
}
Also used : CircuitComponent(de.neemann.digital.gui.components.CircuitComponent) In(de.neemann.digital.core.io.In) IOState(de.neemann.digital.draw.elements.IOState) Element(de.neemann.digital.core.element.Element) ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) Sync(de.neemann.digital.gui.sync.Sync) SingleValueDialog(de.neemann.digital.gui.components.SingleValueDialog)

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