use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class GateFunctions method computeExactlyOne.
static Value computeExactlyOne(Value[] inputs, int numInputs) {
int width = inputs[0].getWidth();
Value[] ret = new Value[width];
for (int i = 0; i < width; i++) {
int count = 0;
for (int j = 0; j < numInputs; j++) {
Value v = inputs[j].get(i);
if (v == Value.TRUE) {
count++;
} else if (v == Value.FALSE) {
// do nothing
;
} else {
count = -1;
break;
}
}
if (count < 0) {
ret[i] = Value.ERROR;
} else if (count == 1) {
ret[i] = Value.TRUE;
} else {
ret[i] = Value.FALSE;
}
}
return Value.create(ret);
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class RGBLed method propagate.
@Override
public void propagate(InstanceState state) {
int summary = 0;
for (int i = 0; i < 3; i++) {
Value val = state.getPortValue(i);
if (val == Value.TRUE)
summary |= 1 << i;
}
Object value = Integer.valueOf(summary);
InstanceDataSingleton data = (InstanceDataSingleton) state.getData();
if (data == null) {
state.setData(new InstanceDataSingleton(value));
} else {
data.setValue(value);
}
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class SevenSegment method propagate.
@Override
public void propagate(InstanceState state) {
int summary = 0;
for (int i = 0; i < 8; i++) {
Value val = state.getPortValue(i);
if (val == Value.TRUE)
summary |= 1 << i;
}
Object value = Integer.valueOf(summary);
InstanceDataSingleton data = (InstanceDataSingleton) state.getData();
if (data == null) {
state.setData(new InstanceDataSingleton(value));
} else {
data.setValue(value);
}
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class Tty method propagate.
@Override
public void propagate(InstanceState circState) {
Object trigger = circState.getAttributeValue(StdAttr.EDGE_TRIGGER);
TtyState state = getTtyState(circState);
Value clear = circState.getPortValue(CLR);
Value clock = circState.getPortValue(CK);
Value enable = circState.getPortValue(WE);
Value in = circState.getPortValue(IN);
synchronized (state) {
Value lastClock = state.setLastClock(clock);
if (clear == Value.TRUE) {
state.clear();
} else if (enable != Value.FALSE) {
boolean go;
if (trigger == StdAttr.TRIG_FALLING) {
go = lastClock == Value.TRUE && clock == Value.FALSE;
} else {
go = lastClock == Value.FALSE && clock == Value.TRUE;
}
if (go)
state.add(in.isFullyDefined() ? (char) in.toIntValue() : '?');
}
}
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class Button method paintInstance.
@Override
public void paintInstance(InstancePainter painter) {
Bounds bds = painter.getBounds();
int x = bds.getX();
int y = bds.getY();
int w = bds.getWidth();
int h = bds.getHeight();
Value val;
if (painter.getShowState()) {
InstanceDataSingleton data = (InstanceDataSingleton) painter.getData();
val = data == null ? Value.FALSE : (Value) data.getValue();
} else {
val = Value.FALSE;
}
Color color = painter.getAttributeValue(Io.ATTR_COLOR);
if (!painter.shouldDrawColor()) {
int hue = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
color = new Color(hue, hue, hue);
}
Graphics g = painter.getGraphics();
int depress;
if (val == Value.TRUE) {
x += DEPTH;
y += DEPTH;
Object labelLoc = painter.getAttributeValue(Io.ATTR_LABEL_LOC);
if (labelLoc == Io.LABEL_CENTER || labelLoc == Direction.NORTH || labelLoc == Direction.WEST) {
depress = DEPTH;
} else {
depress = 0;
}
Object facing = painter.getAttributeValue(StdAttr.FACING);
if (facing == Direction.NORTH || facing == Direction.WEST) {
Location p = painter.getLocation();
int px = p.getX();
int py = p.getY();
GraphicsUtil.switchToWidth(g, Wire.WIDTH);
g.setColor(Value.TRUE_COLOR);
if (facing == Direction.NORTH)
g.drawLine(px, py, px, py + 10);
else
g.drawLine(px, py, px + 10, py);
GraphicsUtil.switchToWidth(g, 1);
}
g.setColor(color);
g.fillRect(x, y, w - DEPTH, h - DEPTH);
g.setColor(Color.BLACK);
g.drawRect(x, y, w - DEPTH, h - DEPTH);
} else {
depress = 0;
int[] xp = new int[] { x, x + w - DEPTH, x + w, x + w, x + DEPTH, x };
int[] yp = new int[] { y, y, y + DEPTH, y + h, y + h, y + h - DEPTH };
g.setColor(color.darker());
g.fillPolygon(xp, yp, xp.length);
g.setColor(color);
g.fillRect(x, y, w - DEPTH, h - DEPTH);
g.setColor(Color.BLACK);
g.drawRect(x, y, w - DEPTH, h - DEPTH);
g.drawLine(x + w - DEPTH, y + h - DEPTH, x + w, y + h);
g.drawPolygon(xp, yp, xp.length);
}
g.translate(depress, depress);
painter.drawLabel();
g.translate(-depress, -depress);
painter.drawPorts();
}
Aggregations