use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Pin method getOffsetBounds.
@Override
public Bounds getOffsetBounds(AttributeSet attrs) {
Direction facing = attrs.getValue(StdAttr.FACING);
BitWidth width = attrs.getValue(StdAttr.WIDTH);
return Probe.getOffsetBounds(facing, width, attrs.getValue(RadixOption.ATTRIBUTE));
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Pin method paintIcon.
//
// graphics methods
//
@Override
public void paintIcon(InstancePainter painter) {
paintIconBase(painter);
BitWidth w = painter.getAttributeValue(StdAttr.WIDTH);
if (!w.equals(BitWidth.ONE)) {
Graphics g = painter.getGraphics();
g.setColor(ICON_WIDTH_COLOR);
g.setFont(ICON_WIDTH_FONT);
GraphicsUtil.drawCenteredText(g, "" + w.getWidth(), 10, 9);
g.setColor(Color.BLACK);
}
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Counter method propagate.
@Override
public void propagate(InstanceState state) {
RegisterData data = (RegisterData) state.getData();
if (data == null) {
data = new RegisterData(state.getAttributeValue(StdAttr.WIDTH));
state.setData(data);
}
BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
Object triggerType = state.getAttributeValue(StdAttr.EDGE_TRIGGER);
int max = state.getAttributeValue(ATTR_MAX).intValue();
Value clock = state.getPortValue(CK);
boolean triggered = data.updateClock(clock, triggerType);
Value newValue;
boolean carry;
if (state.getPortValue(CLR) == Value.TRUE) {
newValue = Value.createKnown(dataWidth, 0);
carry = false;
} else {
boolean ld = state.getPortValue(LD) == Value.TRUE;
boolean en = state.getPortValue(EN) != Value.FALSE;
boolean UpCount = state.getPortValue(UD) != Value.FALSE;
Value oldVal = data.value;
Value newVal;
if (!triggered) {
newVal = oldVal;
} else if (ld) {
Value in = state.getPortValue(IN);
newVal = in;
if (newVal.toIntValue() > max)
newVal = Value.createKnown(dataWidth, newVal.toIntValue() & max);
} else if (!oldVal.isFullyDefined()) {
newVal = oldVal;
} else if (en) {
int goal = (UpCount) ? max : 0;
if (oldVal.toIntValue() == goal) {
Object onGoal = state.getAttributeValue(ATTR_ON_GOAL);
if (onGoal == ON_GOAL_WRAP) {
newVal = Value.createKnown(dataWidth, (UpCount) ? 0 : max);
} else if (onGoal == ON_GOAL_STAY) {
newVal = oldVal;
} else if (onGoal == ON_GOAL_LOAD) {
Value in = state.getPortValue(IN);
newVal = in;
if (newVal.toIntValue() > max)
newVal = Value.createKnown(dataWidth, newVal.toIntValue() & max);
} else if (onGoal == ON_GOAL_CONT) {
newVal = Value.createKnown(dataWidth, (UpCount) ? oldVal.toIntValue() + 1 : oldVal.toIntValue() - 1);
} else {
logger.error("Invalid goal attribute {}", onGoal);
newVal = Value.createKnown(dataWidth, ld ? max : 0);
}
} else {
newVal = Value.createKnown(dataWidth, (UpCount) ? oldVal.toIntValue() + 1 : oldVal.toIntValue() - 1);
}
} else {
newVal = oldVal;
}
newValue = newVal;
carry = newVal.toIntValue() == (UpCount ? max : 0);
/*
* I would want this if I were worried about the carry signal
* outrunning the clock. But the component's delay should be enough
* to take care of it. if (carry) { if (triggerType ==
* StdAttr.TRIG_FALLING) { carry = clock == Value.TRUE; } else {
* carry = clock == Value.FALSE; } }
*/
}
data.value = newValue;
state.setPort(OUT, newValue, DELAY);
state.setPort(CARRY, carry ? Value.TRUE : Value.FALSE, DELAY);
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Counter method DrawDataBlock.
private void DrawDataBlock(InstancePainter painter, int xpos, int ypos, int BitNr, int NrOfBits) {
int RealYpos = ypos + BitNr * 20;
boolean first = BitNr == 0;
boolean last = BitNr == (NrOfBits - 1);
Graphics g = painter.getGraphics();
Font font = g.getFont();
g.setFont(font.deriveFont(7.0f));
GraphicsUtil.switchToWidth(g, 2);
g.drawRect(xpos + 20, RealYpos, SymbolWidth(NrOfBits), 20);
/* Input Line */
if (NrOfBits > 1) {
g.drawLine(xpos + 10, RealYpos + 10, xpos + 20, RealYpos + 10);
g.drawLine(xpos + 5, RealYpos + 5, xpos + 10, RealYpos + 10);
} else {
g.drawLine(xpos, RealYpos + 10, xpos + 20, RealYpos + 10);
}
/* Ouput Line */
if (NrOfBits > 1) {
g.drawLine(xpos + 20 + SymbolWidth(NrOfBits), RealYpos + 10, xpos + 30 + SymbolWidth(NrOfBits), RealYpos + 10);
g.drawLine(xpos + 30 + SymbolWidth(NrOfBits), RealYpos + 10, xpos + 35 + SymbolWidth(NrOfBits), RealYpos + 5);
} else {
g.drawLine(xpos + 20 + SymbolWidth(NrOfBits), RealYpos + 10, xpos + 40 + SymbolWidth(NrOfBits), RealYpos + 10);
}
g.setColor(Color.BLACK);
if (NrOfBits > 1) {
GraphicsUtil.drawText(g, Integer.toString(BitNr), xpos + 30 + SymbolWidth(NrOfBits), RealYpos + 8, GraphicsUtil.H_RIGHT, GraphicsUtil.V_BASELINE);
GraphicsUtil.drawText(g, Integer.toString(BitNr), xpos + 10, RealYpos + 8, GraphicsUtil.H_LEFT, GraphicsUtil.V_BASELINE);
}
g.setFont(font);
GraphicsUtil.drawText(g, "1,6D", xpos + 21, RealYpos + 10, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
int LineWidth = (NrOfBits == 1) ? 2 : 5;
GraphicsUtil.switchToWidth(g, LineWidth);
if (first) {
painter.drawPort(IN);
painter.drawPort(OUT);
if (NrOfBits > 1) {
g.drawLine(xpos, RealYpos, xpos + 5, RealYpos + 5);
g.drawLine(xpos + 35 + SymbolWidth(NrOfBits), RealYpos + 5, xpos + 40 + SymbolWidth(NrOfBits), RealYpos);
g.drawLine(xpos + 5, RealYpos + 5, xpos + 5, RealYpos + 20);
g.drawLine(xpos + 35 + SymbolWidth(NrOfBits), RealYpos + 5, xpos + 35 + SymbolWidth(NrOfBits), RealYpos + 20);
}
} else if (last) {
g.drawLine(xpos + 5, RealYpos, xpos + 5, RealYpos + 5);
g.drawLine(xpos + 35 + SymbolWidth(NrOfBits), RealYpos, xpos + 35 + SymbolWidth(NrOfBits), RealYpos + 5);
} else {
g.drawLine(xpos + 5, RealYpos, xpos + 5, RealYpos + 20);
g.drawLine(xpos + 35 + SymbolWidth(NrOfBits), RealYpos, xpos + 35 + SymbolWidth(NrOfBits), RealYpos + 20);
}
GraphicsUtil.switchToWidth(g, 1);
RegisterData state = (RegisterData) painter.getData();
if (painter.getShowState() && (state != null)) {
/* Here we draw the bit value */
Value val = state.value;
BitWidth widthVal = painter.getAttributeValue(StdAttr.WIDTH);
int width = widthVal == null ? 8 : widthVal.getWidth();
int xcenter = (SymbolWidth(width) / 2) + 10;
String value = "";
if (val.isFullyDefined()) {
g.setColor(Color.LIGHT_GRAY);
value = ((1 << BitNr) & val.toIntValue()) != 0 ? "1" : "0";
} else if (val.isUnknown()) {
g.setColor(Color.BLUE);
value = "?";
} else {
g.setColor(Color.RED);
value = "!";
}
g.fillRect(xpos + xcenter + 16, RealYpos + 4, 8, 16);
if (val.isFullyDefined())
g.setColor(Color.DARK_GRAY);
else
g.setColor(Color.YELLOW);
GraphicsUtil.drawText(g, value, xpos + xcenter + 20, RealYpos + 10, GraphicsUtil.H_CENTER, GraphicsUtil.V_CENTER);
g.setColor(Color.BLACK);
}
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class CounterPoker method paint.
@Override
public void paint(InstancePainter painter) {
Bounds bds = painter.getBounds();
BitWidth dataWidth = painter.getAttributeValue(StdAttr.WIDTH);
int width = dataWidth == null ? 8 : dataWidth.getWidth();
int len = (width + 3) / 4;
int xcenter = Counter.SymbolWidth(width) - 25;
Graphics g = painter.getGraphics();
g.setColor(Color.RED);
g.drawRect(bds.getX() + xcenter - len * 4, bds.getY() + 22, len * 8, 16);
g.setColor(Color.BLACK);
}
Aggregations