Search in sources :

Example 21 with Model

use of de.neemann.digital.core.Model 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)

Example 22 with Model

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

the class ModelCreator method createModel.

/**
 * Creates the model.
 *
 * @param attachWires if true the wires are attached to the values
 * @return the model
 * @throws PinException  PinException
 * @throws NodeException NodeException
 */
public Model createModel(boolean attachWires) throws PinException, NodeException {
    Model m = new Model();
    for (Net n : netList) n.interconnect(m, attachWires);
    for (ModelEntry e : entries) e.applyInputs();
    for (ModelEntry e : entries) e.getElement().registerNodes(m);
    for (ModelEntry e : entries) {
        e.getElement().init(m);
        e.getVisualElement().getShape().registerModel(this, m, e);
    }
    ROMManger romManager = circuit.getAttributes().get(Keys.ROMMANAGER);
    romManager.applyTo(m);
    return m;
}
Also used : Model(de.neemann.digital.core.Model) ROMManger(de.neemann.digital.core.memory.rom.ROMManger)

Example 23 with Model

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

the class CycleDetectorTest method testCyclesOk.

public void testCyclesOk() throws Exception {
    for (String name : nameTableCombinatorial) {
        try {
            Model model = new ToBreakRunner("../../main/dig/combinatorial/" + name, false).getModel();
            new ModelAnalyser(model).analyse();
        } catch (CycleDetector.CycleException e) {
            fail("cycle detected in " + name);
        }
    }
}
Also used : Model(de.neemann.digital.core.Model) ToBreakRunner(de.neemann.digital.integration.ToBreakRunner)

Example 24 with Model

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

the class ModelAnalyserTest method testAnalyzer.

public void testAnalyzer() throws Exception {
    Model model = new ToBreakRunner("dig/analyze/analyzeTest.dig").getModel();
    TruthTable tt = new ModelAnalyser(model).analyse();
    assertEquals(4, tt.getRows());
    assertEquals(3, tt.getCols());
    // circuit is XOr:
    assertEquals(0, tt.getValue(0, 2));
    assertEquals(1, tt.getValue(1, 2));
    assertEquals(1, tt.getValue(2, 2));
    assertEquals(0, tt.getValue(3, 2));
    assertEquals("A\tB\tY\t\n" + "0\t0\t0\t\n" + "0\t1\t1\t\n" + "1\t0\t1\t\n" + "1\t1\t0\t\n", tt.toString());
}
Also used : Model(de.neemann.digital.core.Model) ToBreakRunner(de.neemann.digital.integration.ToBreakRunner)

Example 25 with Model

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

the class ModelAnalyserTest method testAnalyzerMultiBit.

public void testAnalyzerMultiBit() throws Exception {
    Model model = new ToBreakRunner("dig/analyze/multiBitCounter.dig", false).getModel();
    TruthTable tt = new ModelAnalyser(model).analyse();
    checkTable(tt.getResult("Q0n+1"), one, zero, one, zero);
    checkTable(tt.getResult("Q1n+1"), zero, one, one, zero);
    assertEquals("Y1", tt.getResultName(2));
    assertEquals("Y0", tt.getResultName(3));
    final BoolTable y1 = tt.getResult(2);
    final BoolTable y0 = tt.getResult(3);
    for (int i = 0; i < 4; i++) {
        assertEquals((i & 1) > 0, y0.get(i).invert().bool());
        assertEquals((i & 2) > 0, y1.get(i).invert().bool());
    }
}
Also used : BoolTable(de.neemann.digital.analyse.quinemc.BoolTable) Model(de.neemann.digital.core.Model) ToBreakRunner(de.neemann.digital.integration.ToBreakRunner)

Aggregations

Model (de.neemann.digital.core.Model)85 ObservableValue (de.neemann.digital.core.ObservableValue)56 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)52 TestExecuter (de.neemann.digital.TestExecuter)49 ToBreakRunner (de.neemann.digital.integration.ToBreakRunner)16 ValueTable (de.neemann.digital.data.ValueTable)6 Signal (de.neemann.digital.core.Signal)4 ModelCreator (de.neemann.digital.draw.model.ModelCreator)4 ObservableValues (de.neemann.digital.core.ObservableValues)3 Expression (de.neemann.digital.analyse.expression.Expression)2 BoolTable (de.neemann.digital.analyse.quinemc.BoolTable)2 Node (de.neemann.digital.core.Node)2 Delay (de.neemann.digital.core.wiring.Delay)2 Circuit (de.neemann.digital.draw.elements.Circuit)2 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)2 ShapeFactory (de.neemann.digital.draw.shapes.ShapeFactory)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Variable (de.neemann.digital.analyse.expression.Variable)1 Parser (de.neemann.digital.analyse.parser.Parser)1