use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.
the class Gal22v10JEDECExporter method writeTo.
@Override
public void writeTo(OutputStream out) throws FuseMapFillerException, IOException, PinMapException {
for (String in : builder.getInputs()) {
int i = pinMap.getInputFor(in);
if (i == 13)
filler.addVariable(21, new Variable(in));
else
filler.addVariable((i - 1) * 2, new Variable(in));
}
for (String o : builder.getOutputs()) {
int i = 23 - pinMap.getOutputFor(o);
filler.addVariableReverse(i * 2 + 1, new Variable(o));
}
for (String o : builder.getOutputs()) {
int olmc = 23 - pinMap.getOutputFor(o);
int offs = OE_FUSE_NUM_BY_OLMC[olmc];
// turn on OE
for (int j = 0; j < 44; j++) map.setFuse(offs + j);
// set olmc to active high
map.setFuse(S0 + olmc * 2);
if (builder.getCombinatorial().containsKey(o)) {
map.setFuse(S1 + olmc * 2);
filler.fillExpression(offs + 44, builder.getCombinatorial().get(o), PRODUCTS_BY_OLMC[olmc]);
} else if (builder.getRegistered().containsKey(o)) {
filler.fillExpression(offs + 44, builder.getRegistered().get(o), PRODUCTS_BY_OLMC[olmc]);
} else
throw new FuseMapFillerException("variable " + o + " not found!");
}
try (JedecWriter w = new JedecWriter(out)) {
w.println("Digital GAL22v10 assembler*").write(map);
}
}
use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.
the class FuseMapFiller method fillExpression.
/**
* Fills an expression to the fuse map
*
* @param offs number of first fuse of first product term to use
* @param exp the expression
* @param productTerms the number of product terms available
* @throws FuseMapFillerException EquationHandlerException
*/
public void fillExpression(int offs, Expression exp, int productTerms) throws FuseMapFillerException {
ArrayList<Expression> terms;
if (exp instanceof Operation.Or) {
Operation.Or or = (Operation.Or) exp;
terms = or.getExpressions();
} else {
terms = new ArrayList<>();
terms.add(exp);
}
if (terms.size() > productTerms)
throw new FuseMapFillerException("only " + productTerms + " product terms supported but " + terms.size() + " needed!");
int fusesInTerm = varsConnectedToMap * 2;
for (Expression e : terms) {
for (int i = 0; i < fusesInTerm; i++) fuseMap.setFuse(offs + i, true);
ArrayList<Expression> ands;
if (e instanceof Operation.And) {
ands = ((Operation.And) e).getExpressions();
} else {
ands = new ArrayList<>();
ands.add(e);
}
for (Expression v : ands) {
Variable var;
boolean invert = false;
if (v instanceof Variable)
var = (Variable) v;
else if (v instanceof Not) {
Expression n = ((Not) v).getExpression();
if (n instanceof Variable) {
var = (Variable) n;
invert = true;
} else {
throw new FuseMapFillerException("NOT does not contain a variable!");
}
} else
throw new FuseMapFillerException("only VAR or NOT VAR allowed!");
MapEntry entry = varMap.get(var);
if (entry == null)
throw new FuseMapFillerException("VAR " + var + " not found in term list!");
int fuse = entry.getFuse(invert);
fuseMap.setFuse(offs + fuse, false);
}
offs += fusesInTerm;
}
}
use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.
the class Gal16v8JEDECExporter method writeTo.
@Override
public void writeTo(OutputStream out) throws FuseMapFillerException, IOException, PinMapException {
boolean registered = !builder.getRegistered().isEmpty();
init(registered);
for (String in : builder.getInputs()) {
int i = pinMap.getInputFor(in) - 2;
filler.addVariable(i * 2, new Variable(in));
}
for (String o : builder.getOutputs()) {
int i = 19 - pinMap.getOutputFor(o);
filler.addVariable(i * 2 + 1, new Variable(o));
}
for (String o : builder.getOutputs()) {
int olmc = 19 - pinMap.getOutputFor(o);
int offs = olmc * 256;
// set XOR to compensate inverted driver
map.setFuse(XOR + olmc);
if (builder.getCombinatorial().containsKey(o)) {
if (registered) {
// turn on OE
for (int j = 0; j < 32; j++) map.setFuse(offs + j);
filler.fillExpression(offs + 32, builder.getCombinatorial().get(o), 7);
} else {
map.setFuse(AC1 + olmc, false);
filler.fillExpression(offs, builder.getCombinatorial().get(o), 8);
}
} else if (builder.getRegistered().containsKey(o)) {
// turn on register
map.setFuse(AC1 + olmc, false);
filler.fillExpression(offs, builder.getRegistered().get(o), 8);
} else
throw new FuseMapFillerException("variable " + o + " not found!");
}
try (JedecWriter w = new JedecWriter(out)) {
w.println("Digital GAL16v8 assembler*").write(map);
}
}
use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.
the class FormatToTable method format.
@Override
public String format(Expression expression) throws FormatterException, ExpressionException {
StringBuilder sb = new StringBuilder();
ContextFiller cf = new ContextFiller(expression);
formatHead(sb, cf.getVarCount());
for (Variable v : cf) sb.append(formatVariable(v));
sb.append(formatResultVariable());
sb.append("\n");
formatTableStart(sb);
for (int i = 0; i < cf.getRowCount(); i++) {
cf.setContextTo(i);
for (Variable v : cf) sb.append(formatValue(cf.get(v)));
sb.append(formatResult(expression.calculate(cf)));
sb.append("\n");
}
formatEnd(sb);
return sb.toString();
}
use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.
the class ReorderInputs method reorder.
/**
* Creates a new table matching the actual state of the items
*
* @return the new table
* @throws ExpressionException ExpressionException
*/
public TruthTable reorder() throws ExpressionException {
ArrayList<Variable> newVars = new ArrayList<>();
ArrayList<Variable> deletedVars = new ArrayList<>();
deletedVars.addAll(table.getVars());
for (String name : names) {
Variable found = null;
for (Variable v : deletedVars) if (v.getIdentifier().equals(name)) {
found = v;
break;
}
if (found != null) {
newVars.add(found);
deletedVars.remove(found);
}
}
if (newVars.size() < 2)
throw new ExpressionException(Lang.get("err_tableBecomesToSmall"));
TruthTable newTable = new TruthTable(newVars);
for (int j = 0; j < table.getResultCount(); j++) newTable.addResult(table.getResultName(j));
ContextFiller fc = new ContextFiller(newTable.getVars());
for (Variable v : deletedVars) fc.set(v, false);
for (int row = 0; row < newTable.getRows(); row++) {
fc.setContextTo(row);
for (int t = 0; t < newTable.getResultCount(); t++) newTable.setByContext(t, fc, table.getByContext(t, fc));
}
return newTable;
}
Aggregations