Search in sources :

Example 31 with ElementAttributes

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

the class ComparatorTest method testCompSigned64Bit.

public void testCompSigned64Bit() throws Exception {
    ObservableValue a = new ObservableValue("a", 64);
    ObservableValue b = new ObservableValue("b", 64);
    Model model = new Model();
    Comparator node = new Comparator(new ElementAttributes().setBits(64).set(Keys.SIGNED, true));
    node.setInputs(ovs(a, b));
    model.add(node);
    TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputs(node.getOutputs());
    // gr eq kl
    sc.check(0, 0, 0, 1, 0);
    sc.check(0, -2, 1, 0, 0);
    sc.check(-2, 0, 0, 0, 1);
    sc.check(-1, -2, 1, 0, 0);
    sc.check(-2, -1, 0, 0, 1);
    sc.check(0x8000000000000000L, 0, 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)

Example 32 with ElementAttributes

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

the class ComparatorTest method testCompUnsigned.

public void testCompUnsigned() throws Exception {
    ObservableValue a = new ObservableValue("a", 4);
    ObservableValue b = new ObservableValue("b", 4);
    Model model = new Model();
    Comparator node = new Comparator(new ElementAttributes().setBits(4).set(Keys.SIGNED, false));
    node.setInputs(ovs(a, b));
    model.add(node);
    TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputs(node.getOutputs());
    sc.check(0, 0, 0, 1, 0);
    sc.check(1, 0, 1, 0, 0);
    sc.check(1, 2, 0, 0, 1);
    sc.check(14, 2, 1, 0, 0);
}
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 33 with ElementAttributes

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

the class AndTest method testAnd.

public void testAnd() throws Exception {
    ObservableValue a = new ObservableValue("a", 1);
    ObservableValue b = new ObservableValue("b", 1);
    Model model = new Model();
    FanIn out = model.add(new And(new ElementAttributes().setBits(1)));
    out.setInputs(ovs(a, b));
    TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputs(out.getOutputs());
    sc.check(0, 0, 0);
    sc.check(1, 0, 0);
    sc.check(0, 1, 0);
    sc.check(1, 1, 1);
    sc.check(1, 0, 0);
    sc.check(0, 1, 0);
}
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 34 with ElementAttributes

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

the class DelayTest method testDelayVar.

public void testDelayVar() throws Exception {
    for (int delayTime = 0; delayTime < 5; delayTime++) {
        ObservableValue in = new ObservableValue("in", 1);
        Model model = new Model();
        Delay delay = model.add(new Delay(new ElementAttributes().set(Keys.DELAY_TIME, delayTime)));
        delay.setInputs(in.asList());
        assertEquals(1, delay.getOutputs().size());
        ObservableValue out = delay.getOutputs().get(0);
        model.init();
        in.setValue(0);
        model.doStep();
        assertEquals(0, out.getValue());
        in.setValue(1);
        for (int i = 1; i < delayTime; i++) {
            assertTrue(model.needsUpdate());
            model.doMicroStep(false);
            assertEquals(0, out.getValue());
        }
        assertTrue(model.needsUpdate());
        model.doMicroStep(false);
        assertEquals(1, out.getValue());
        assertFalse(model.needsUpdate());
    }
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) Delay(de.neemann.digital.core.wiring.Delay)

Example 35 with ElementAttributes

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

the class Main method createAndStartModel.

private boolean createAndStartModel(boolean globalRunClock, ModelEvent updateEvent, ModelModifier modelModifier) {
    try {
        circuitComponent.removeHighLighted();
        long time = System.currentTimeMillis();
        modelCreator = new ModelCreator(circuitComponent.getCircuit(), library);
        if (model != null) {
            modelSync.access(() -> model.close());
            circuitComponent.getCircuit().clearState();
            model = null;
        }
        model = modelCreator.createModel(true);
        time = System.currentTimeMillis() - time;
        LOGGER.debug("model creation: " + time + " ms");
        model.setWindowPosManager(windowPosManager);
        statusLabel.setText(Lang.get("msg_N_nodes", model.size()));
        realTimeClockRunning = false;
        modelSync = null;
        if (globalRunClock) {
            int threadRunnerCount = 0;
            for (Clock c : model.getClocks()) if (c.getFrequency() > 0) {
                if (modelSync == null)
                    modelSync = new LockSync();
                final RealTimeClock realTimeClock = new RealTimeClock(model, c, timerExecutor, this, modelSync, this);
                model.addObserver(realTimeClock);
                if (realTimeClock.isThreadRunner())
                    threadRunnerCount++;
                realTimeClockRunning = true;
            }
            if (threadRunnerCount > 1)
                throw new RuntimeException(Lang.get("err_moreThanOneFastClock"));
        }
        if (modelSync == null)
            modelSync = NoSync.INST;
        circuitComponent.setModeAndReset(true, modelSync);
        if (realTimeClockRunning) {
            // if clock is running, enable automatic update of gui
            GuiModelObserver gmo = new GuiModelObserver(circuitComponent, updateEvent);
            modelCreator.connectToGui(gmo);
            model.addObserver(gmo);
        } else
            // all repainting is initiated by user actions!
            modelCreator.connectToGui(null);
        doStep.setEnabled(false);
        runToBreakAction.setEnabled(!realTimeClockRunning && model.isFastRunModel());
        ElementAttributes settings = circuitComponent.getCircuit().getAttributes();
        if (settings.get(Keys.SHOW_DATA_TABLE) || windowPosManager.isVisible("probe"))
            showMeasurementDialog(updateEvent);
        if (settings.get(Keys.SHOW_DATA_GRAPH) || windowPosManager.isVisible("dataSet"))
            showMeasurementGraph(updateEvent);
        if (settings.get(Keys.SHOW_DATA_GRAPH_MICRO))
            showMeasurementGraph(ModelEvent.MICROSTEP);
        if (modelModifier != null)
            modelModifier.preInit(model);
        model.init();
        return true;
    } catch (NodeException | PinException | RuntimeException | ElementNotFoundException e) {
        if (model != null)
            showErrorAndStopModel(Lang.get("msg_errorCreatingModel"), e);
        else
            showErrorWithoutARunningModel(Lang.get("msg_errorCreatingModel"), e);
    }
    return false;
}
Also used : RealTimeClock(de.neemann.digital.draw.model.RealTimeClock) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) ElementNotFoundException(de.neemann.digital.draw.library.ElementNotFoundException) RealTimeClock(de.neemann.digital.draw.model.RealTimeClock) Clock(de.neemann.digital.core.wiring.Clock) ModelCreator(de.neemann.digital.draw.model.ModelCreator) LockSync(de.neemann.digital.gui.sync.LockSync)

Aggregations

ElementAttributes (de.neemann.digital.core.element.ElementAttributes)87 ObservableValue (de.neemann.digital.core.ObservableValue)73 TestExecuter (de.neemann.digital.TestExecuter)61 Model (de.neemann.digital.core.Model)52 ObservableValues (de.neemann.digital.core.ObservableValues)16 BitsException (de.neemann.digital.core.BitsException)3 FanIn (de.neemann.digital.core.basic.FanIn)3 NodeException (de.neemann.digital.core.NodeException)2 Delay (de.neemann.digital.core.wiring.Delay)2 Circuit (de.neemann.digital.draw.elements.Circuit)2 And (de.neemann.digital.core.basic.And)1 Not (de.neemann.digital.core.basic.Not)1 Or (de.neemann.digital.core.basic.Or)1 Element (de.neemann.digital.core.element.Element)1 Key (de.neemann.digital.core.element.Key)1 FlipflopD (de.neemann.digital.core.flipflops.FlipflopD)1 FlipflopJK (de.neemann.digital.core.flipflops.FlipflopJK)1 Clock (de.neemann.digital.core.wiring.Clock)1 VisualElement (de.neemann.digital.draw.elements.VisualElement)1 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)1