use of de.neemann.digital.data.Value in project Digital by hneemann.
the class ValueTest method testSimple.
public void testSimple() throws Exception {
Value v = new Value("X");
assertEquals(Value.Type.DONTCARE, v.getType());
v = new Value("Z");
assertEquals(Value.Type.HIGHZ, v.getType());
v = new Value("C");
assertEquals(Value.Type.CLOCK, v.getType());
assertEquals(1, v.getValue());
v = new Value("8");
assertEquals(Value.Type.NORMAL, v.getType());
assertEquals(8, v.getValue());
}
use of de.neemann.digital.data.Value in project Digital by hneemann.
the class LineListenerResolveDontCare method add.
@Override
public void add(Value[] row) {
ArrayList<Integer> dcIndex = null;
for (TestExecutor.TestSignal in : inputs) {
if (row[in.getIndex()].getType() == Value.Type.DONTCARE) {
if (dcIndex == null)
dcIndex = new ArrayList<>();
dcIndex.add(in.getIndex());
}
}
if (dcIndex == null)
parent.add(row);
else {
int count = 1 << dcIndex.size();
for (int n = 0; n < count; n++) {
int mask = 1;
for (int in : dcIndex) {
boolean val = (n & mask) != 0;
row[in] = new Value(val ? 1 : 0);
mask *= 2;
}
parent.add(row);
}
}
}
use of de.neemann.digital.data.Value in project Digital by hneemann.
the class TestCaseDescription method testData.
/**
* Runs a 4 bit counter build from JK flip flops 16 ticks.
* The 4 output signals are recoded in a DataSet.
*
* @throws Exception
*/
public void testData() throws Exception {
ToBreakRunner toBreakRunner = new ToBreakRunner("dig/data.dig").runToBreak(29);
// check recorded data
ValueTable dataSet = toBreakRunner.getModel().getObserver(ValueTableObserver.class).getLogData();
assertEquals(29, dataSet.getRows());
int i = 0;
for (Value[] ds : dataSet) {
// clock
assertEquals((~i) & 1, ds[0].getValue());
int s = i / 2 + 1;
// q_0
assertEquals(s & 1, ds[1].getValue());
// q_1
assertEquals((s >> 1) & 1, ds[2].getValue());
// q_2
assertEquals((s >> 2) & 1, ds[3].getValue());
// q_3
assertEquals((s >> 3) & 1, ds[4].getValue());
i++;
}
// try to write data to graphics instance
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new Export(toBreakRunner.getCircuit(), (out) -> new GraphicsImage(out, "PNG", 1)).export(baos);
assertTrue(baos.size() > 15000);
// export data to CSV
StringWriter w = new StringWriter();
dataSet.saveCSV(new BufferedWriter(w));
assertEquals("\"step\",\"C\",\"q_0n\",\"q_1n\",\"q_2n\",\"q_3n\"\n" + "\"0\",\"1\",\"1\",\"0\",\"0\",\"0\"\n" + "\"1\",\"0\",\"1\",\"0\",\"0\",\"0\"\n" + "\"2\",\"1\",\"0\",\"1\",\"0\",\"0\"\n" + "\"3\",\"0\",\"0\",\"1\",\"0\",\"0\"\n" + "\"4\",\"1\",\"1\",\"1\",\"0\",\"0\"\n" + "\"5\",\"0\",\"1\",\"1\",\"0\",\"0\"\n" + "\"6\",\"1\",\"0\",\"0\",\"1\",\"0\"\n" + "\"7\",\"0\",\"0\",\"0\",\"1\",\"0\"\n" + "\"8\",\"1\",\"1\",\"0\",\"1\",\"0\"\n" + "\"9\",\"0\",\"1\",\"0\",\"1\",\"0\"\n" + "\"10\",\"1\",\"0\",\"1\",\"1\",\"0\"\n" + "\"11\",\"0\",\"0\",\"1\",\"1\",\"0\"\n" + "\"12\",\"1\",\"1\",\"1\",\"1\",\"0\"\n" + "\"13\",\"0\",\"1\",\"1\",\"1\",\"0\"\n" + "\"14\",\"1\",\"0\",\"0\",\"0\",\"1\"\n" + "\"15\",\"0\",\"0\",\"0\",\"0\",\"1\"\n" + "\"16\",\"1\",\"1\",\"0\",\"0\",\"1\"\n" + "\"17\",\"0\",\"1\",\"0\",\"0\",\"1\"\n" + "\"18\",\"1\",\"0\",\"1\",\"0\",\"1\"\n" + "\"19\",\"0\",\"0\",\"1\",\"0\",\"1\"\n" + "\"20\",\"1\",\"1\",\"1\",\"0\",\"1\"\n" + "\"21\",\"0\",\"1\",\"1\",\"0\",\"1\"\n" + "\"22\",\"1\",\"0\",\"0\",\"1\",\"1\"\n" + "\"23\",\"0\",\"0\",\"0\",\"1\",\"1\"\n" + "\"24\",\"1\",\"1\",\"0\",\"1\",\"1\"\n" + "\"25\",\"0\",\"1\",\"0\",\"1\",\"1\"\n" + "\"26\",\"1\",\"0\",\"1\",\"1\",\"1\"\n" + "\"27\",\"0\",\"0\",\"1\",\"1\",\"1\"\n" + "\"28\",\"1\",\"1\",\"1\",\"1\",\"1\"\n", w.toString());
}
use of de.neemann.digital.data.Value in project Digital by hneemann.
the class Parser method parseSingleRow.
private LineEmitter parseSingleRow() throws IOException, ParserException {
LineEmitterSimple line = null;
while (true) {
Tokenizer.Token token = tok.next();
if (line == null)
line = new LineEmitterSimple(names.size(), tok.getLine());
switch(token) {
case NUMBER:
Value num = new Value(convToLong(tok.getIdent()));
line.add((vals, context) -> vals.add(num));
break;
case BITS:
expect(Tokenizer.Token.OPEN);
int bitCount = (int) parseInt();
expect(Tokenizer.Token.COMMA);
Expression exp = parseExpression();
line.add(new ValueAppenderBits(bitCount, exp));
expect(Tokenizer.Token.CLOSE);
break;
case IDENT:
try {
final Value value = new Value(tok.getIdent().toUpperCase());
line.add((vals, context) -> vals.add(value));
} catch (Bits.NumberFormatException e) {
throw new ParserException(Lang.get("err_notANumber_N0_inLine_N1", tok.getIdent(), tok.getLine()));
}
break;
case OPEN:
exp = parseExpression();
line.add((vals, context) -> vals.add(new Value((int) exp.value(context))));
expect(Tokenizer.Token.CLOSE);
break;
case EOF:
case EOL:
return line;
default:
throw newUnexpectedToken(token);
}
}
}
use of de.neemann.digital.data.Value in project Digital by hneemann.
the class ValueAppenderBits method appendValues.
@Override
public void appendValues(ArrayList<Value> values, Context context) throws ParserException {
long value = expression.value(context);
long mask = 1L << (bitCount - 1);
for (int i = 0; i < bitCount; i++) {
boolean v = (value & mask) != 0;
values.add(new Value(v ? 1 : 0));
mask >>= 1;
}
}
Aggregations