use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class ShiftRegister method getData.
private ShiftRegisterData getData(InstanceState state) {
BitWidth width = state.getAttributeValue(StdAttr.WIDTH);
Integer lenObj = state.getAttributeValue(ATTR_LENGTH);
int length = lenObj == null ? 8 : lenObj.intValue();
ShiftRegisterData data = (ShiftRegisterData) state.getData();
if (data == null) {
data = new ShiftRegisterData(width, length);
state.setData(data);
} else {
data.setDimensions(width, length);
}
return data;
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class ShiftRegisterData method setDimensions.
public void setDimensions(BitWidth newWidth, int newLength) {
Value[] v = vs;
BitWidth oldWidth = width;
int oldW = oldWidth.getWidth();
int newW = newWidth.getWidth();
if (v.length != newLength) {
Value[] newV = new Value[newLength];
int j = vsPos;
int copy = Math.min(newLength, v.length);
for (int i = 0; i < copy; i++) {
newV[i] = v[j];
j++;
if (j == v.length)
j = 0;
}
Arrays.fill(newV, copy, newLength, Value.createKnown(newWidth, 0));
v = newV;
vsPos = 0;
vs = newV;
}
if (oldW != newW) {
for (int i = 0; i < v.length; i++) {
Value vi = v[i];
if (vi.getWidth() != newW) {
v[i] = vi.extendWidth(newW, Value.FALSE);
}
}
width = newWidth;
}
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class ShiftRegisterPoker method paint.
@Override
public void paint(InstancePainter painter) {
int loc = this.loc;
if (loc < 0)
return;
BitWidth widObj = painter.getAttributeValue(StdAttr.WIDTH);
Bounds bds = painter.getInstance().getBounds();
int len = (widObj.getWidth() + 3) / 4;
int boxXpos = ((ShiftRegister.SymbolWidth - 30) / 2 + 30) - (len * 4) + bds.getX() + 10;
int y = bds.getY() + 82 + loc * 20;
Graphics g = painter.getGraphics();
g.setColor(Color.RED);
g.drawRect(boxXpos, y, 2 + len * 8, 16);
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class BitSelector method updatePorts.
private void updatePorts(Instance instance) {
Direction facing = instance.getAttributeValue(StdAttr.FACING);
BitWidth data = instance.getAttributeValue(StdAttr.WIDTH);
BitWidth group = instance.getAttributeValue(GROUP_ATTR);
int groups = (data.getWidth() + group.getWidth() - 1) / group.getWidth() - 1;
int selectBits = 1;
if (groups > 0) {
while (groups != 1) {
groups >>= 1;
selectBits++;
}
}
BitWidth select = BitWidth.create(selectBits);
Location inPt;
Location selPt;
if (facing == Direction.WEST) {
inPt = Location.create(30, 0);
selPt = Location.create(10, 10);
} else if (facing == Direction.NORTH) {
inPt = Location.create(0, 30);
selPt = Location.create(-10, 10);
} else if (facing == Direction.SOUTH) {
inPt = Location.create(0, -30);
selPt = Location.create(-10, -10);
} else {
inPt = Location.create(-30, 0);
selPt = Location.create(-10, 10);
}
Port[] ps = new Port[3];
ps[0] = new Port(0, 0, Port.OUTPUT, group.getWidth());
ps[1] = new Port(inPt.getX(), inPt.getY(), Port.INPUT, data.getWidth());
ps[2] = new Port(selPt.getX(), selPt.getY(), Port.INPUT, select.getWidth());
ps[0].setToolTip(Strings.getter("bitSelectorOutputTip"));
ps[1].setToolTip(Strings.getter("bitSelectorDataTip"));
ps[2].setToolTip(Strings.getter("bitSelectorSelectTip"));
instance.setPorts(ps);
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Decoder method getOffsetBounds.
@Override
public Bounds getOffsetBounds(AttributeSet attrs) {
Direction facing = attrs.getValue(StdAttr.FACING);
Object selectLoc = attrs.getValue(Plexers.ATTR_SELECT_LOC);
BitWidth select = attrs.getValue(Plexers.ATTR_SELECT);
int outputs = 1 << select.getWidth();
Bounds bds;
boolean reversed = facing == Direction.WEST || facing == Direction.NORTH;
if (selectLoc == Plexers.SELECT_TOP_RIGHT)
reversed = !reversed;
if (outputs == 2) {
int y = reversed ? 0 : -40;
bds = Bounds.create(-20, y - 5, 30, 40 + 10);
} else {
int x = -20;
int y = reversed ? -10 : -(outputs * 10 + 10);
bds = Bounds.create(x, y, 40, outputs * 10 + 20);
}
return bds.rotate(Direction.EAST, facing, 0, 0);
}
Aggregations