use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class Button method propagate.
@Override
public void propagate(InstanceState state) {
InstanceDataSingleton data = (InstanceDataSingleton) state.getData();
Value val = data == null ? Value.FALSE : (Value) data.getValue();
state.setPort(0, val, 1);
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class DotMatrix method paintInstance.
@Override
public void paintInstance(InstancePainter painter) {
Color onColor = painter.getAttributeValue(Io.ATTR_ON_COLOR);
Color offColor = painter.getAttributeValue(Io.ATTR_OFF_COLOR);
boolean drawSquare = painter.getAttributeValue(ATTR_DOT_SHAPE) == SHAPE_SQUARE;
State data = getState(painter);
long ticks = painter.getTickCount();
Bounds bds = painter.getBounds();
boolean showState = painter.getShowState();
Graphics g = painter.getGraphics();
int rows = data.rows;
int cols = data.cols;
for (int j = 0; j < rows; j++) {
for (int i = 0; i < cols; i++) {
int x = bds.getX() + 10 * i;
int y = bds.getY() + 10 * j;
if (showState) {
Value val = data.get(j, i, ticks);
Color c;
if (val == Value.TRUE)
c = onColor;
else if (val == Value.FALSE)
c = offColor;
else
c = Value.ERROR_COLOR;
g.setColor(c);
if (drawSquare)
g.fillRect(x, y, 10, 10);
else
g.fillOval(x + 1, y + 1, 8, 8);
} else {
g.setColor(Color.GRAY);
g.fillOval(x + 1, y + 1, 8, 8);
}
}
}
g.setColor(Color.BLACK);
GraphicsUtil.switchToWidth(g, 2);
g.drawRect(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
GraphicsUtil.switchToWidth(g, 1);
painter.drawPorts();
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class HexDigit method propagate.
@Override
public void propagate(InstanceState state) {
int summary = 0;
Value baseVal = state.getPortValue(0);
if (baseVal == null)
baseVal = Value.createUnknown(BitWidth.create(4));
// each nibble is one segment, in top-down, left-to-right
int segs;
// order: middle three nibbles are the three horizontal segments
switch(baseVal.toIntValue()) {
case 0:
segs = 0x1110111;
break;
case 1:
segs = 0x0000011;
break;
case 2:
segs = 0x0111110;
break;
case 3:
segs = 0x0011111;
break;
case 4:
segs = 0x1001011;
break;
case 5:
segs = 0x1011101;
break;
case 6:
segs = 0x1111101;
break;
case 7:
segs = 0x0010011;
break;
case 8:
segs = 0x1111111;
break;
case 9:
segs = 0x1011011;
break;
case 10:
segs = 0x1111011;
break;
case 11:
segs = 0x1101101;
break;
case 12:
segs = 0x1110100;
break;
case 13:
segs = 0x0101111;
break;
case 14:
segs = 0x1111100;
break;
case 15:
segs = 0x1111000;
break;
default:
segs = 0x0001000;
// a dash '-'
break;
}
if ((segs & 0x1) != 0)
// vertical seg in bottom right
summary |= 4;
if ((segs & 0x10) != 0)
// vertical seg in top right
summary |= 2;
if ((segs & 0x100) != 0)
// horizontal seg at bottom
summary |= 8;
if ((segs & 0x1000) != 0)
// horizontal seg at middle
summary |= 64;
if ((segs & 0x10000) != 0)
// horizontal seg at top
summary |= 1;
if ((segs & 0x100000) != 0)
// vertical seg at bottom left
summary |= 16;
if ((segs & 0x1000000) != 0)
// vertical seg at top left
summary |= 32;
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 Keyboard method propagate.
@Override
public void propagate(InstanceState circState) {
Object trigger = circState.getAttributeValue(StdAttr.EDGE_TRIGGER);
KeyboardData state = getKeyboardState(circState);
Value clear = circState.getPortValue(CLR);
Value clock = circState.getPortValue(CK);
Value enable = circState.getPortValue(RE);
char c;
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.dequeue();
}
c = state.getChar(0);
}
Value out = Value.createKnown(BitWidth.create(7), c & 0x7F);
circState.setPort(OUT, out, DELAY0);
circState.setPort(AVL, c != '\0' ? Value.TRUE : Value.FALSE, DELAY1);
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class Adder method computeSum.
static Value[] computeSum(BitWidth width, Value a, Value b, Value c_in) {
int w = width.getWidth();
if (c_in == Value.UNKNOWN || c_in == Value.NIL)
c_in = Value.FALSE;
if (a.isFullyDefined() && b.isFullyDefined() && c_in.isFullyDefined()) {
if (w >= 32) {
long mask = (1L << w) - 1;
long ax = (long) a.toIntValue() & mask;
long bx = (long) b.toIntValue() & mask;
long cx = (long) c_in.toIntValue() & mask;
long sum = ax + bx + cx;
return new Value[] { Value.createKnown(width, (int) sum), ((sum >> w) & 1) == 0 ? Value.FALSE : Value.TRUE };
} else {
int sum = a.toIntValue() + b.toIntValue() + c_in.toIntValue();
return new Value[] { Value.createKnown(width, sum), ((sum >> w) & 1) == 0 ? Value.FALSE : Value.TRUE };
}
} else {
Value[] bits = new Value[w];
Value carry = c_in;
for (int i = 0; i < w; i++) {
if (carry == Value.ERROR) {
bits[i] = Value.ERROR;
} else if (carry == Value.UNKNOWN) {
bits[i] = Value.UNKNOWN;
} else {
Value ab = a.get(i);
Value bb = b.get(i);
if (ab == Value.ERROR || bb == Value.ERROR) {
bits[i] = Value.ERROR;
carry = Value.ERROR;
} else if (ab == Value.UNKNOWN || bb == Value.UNKNOWN) {
bits[i] = Value.UNKNOWN;
carry = Value.UNKNOWN;
} else {
int sum = (ab == Value.TRUE ? 1 : 0) + (bb == Value.TRUE ? 1 : 0) + (carry == Value.TRUE ? 1 : 0);
bits[i] = (sum & 1) == 1 ? Value.TRUE : Value.FALSE;
carry = (sum >= 2) ? Value.TRUE : Value.FALSE;
}
}
}
return new Value[] { Value.create(bits), carry };
}
}
Aggregations