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);
}
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);
}
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);
}
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());
}
}
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;
}
Aggregations