use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Decoder method paintGhost.
@Override
public void paintGhost(InstancePainter painter) {
Direction facing = painter.getAttributeValue(StdAttr.FACING);
BitWidth select = painter.getAttributeValue(Plexers.ATTR_SELECT);
Bounds bds = painter.getBounds();
if (select.getWidth() == 1) {
if (facing == Direction.EAST || facing == Direction.WEST) {
Plexers.drawTrapezoid(painter.getGraphics(), Bounds.create(bds.getX(), bds.getY() + 5, bds.getWidth(), bds.getHeight() - 10), facing.reverse(), 10);
} else {
Plexers.drawTrapezoid(painter.getGraphics(), Bounds.create(bds.getX() + 5, bds.getY(), bds.getWidth() - 10, bds.getHeight()), facing.reverse(), 10);
}
} else {
Plexers.drawTrapezoid(painter.getGraphics(), bds, facing.reverse(), 20);
}
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class RamAttributes method setValue.
@Override
public <V> void setValue(Attribute<V> attr, V value) {
if (attr == Mem.ADDR_ATTR) {
BitWidth newAddr = (BitWidth) value;
if (addrBits == newAddr) {
return;
}
addrBits = newAddr;
contents.setDimensions(addrBits.getWidth(), dataBits.getWidth(), false);
fireAttributeValueChanged(attr, value, null);
} else if (attr == Mem.DATA_ATTR) {
BitWidth newData = (BitWidth) value;
if (dataBits == newData) {
return;
}
dataBits = newData;
contents.setDimensions(addrBits.getWidth(), dataBits.getWidth(), false);
fireAttributeValueChanged(attr, value, null);
} else if (attr == Ram.CONTENTS_ATTR) {
MemContents newContents = (MemContents) value;
if (contents.equals(newContents)) {
return;
}
if ((newContents.getLogLength() != addrBits.getWidth()) || (newContents.getValueWidth() != dataBits.getWidth())) {
newContents.setDimensions(addrBits.getWidth(), dataBits.getWidth(), false);
}
contents = newContents;
fireAttributeValueChanged(attr, value, null);
} else if (attr == StdAttr.LABEL) {
String NewLabel = (String) value;
if (Label.equals(NewLabel)) {
return;
}
@SuppressWarnings("unchecked") V Oldlabel = (V) Label;
Label = NewLabel;
fireAttributeValueChanged(attr, value, Oldlabel);
} else if (attr == StdAttr.TRIGGER) {
AttributeOption newTrigger = (AttributeOption) value;
if (Trigger.equals(newTrigger)) {
return;
}
Trigger = newTrigger;
fireAttributeValueChanged(attr, value, null);
} else if (attr == ATTR_DBUS) {
AttributeOption NewStyle = (AttributeOption) value;
if (BusStyle.equals(NewStyle)) {
return;
}
BusStyle = NewStyle;
fireAttributeValueChanged(attr, value, null);
} else if (attr == StdAttr.LABEL_FONT) {
Font NewFont = (Font) value;
if (LabelFont.equals(NewFont)) {
return;
}
LabelFont = NewFont;
fireAttributeValueChanged(attr, value, null);
} else if (attr == StdAttr.LABEL_VISIBILITY) {
Boolean newVis = (Boolean) value;
if (LabelVisable.equals(newVis))
return;
LabelVisable = newVis;
fireAttributeValueChanged(attr, value, null);
} else if (attr == ATTR_ByteEnables) {
AttributeOption NewBE = (AttributeOption) value;
if (ByteEnables.equals(NewBE)) {
return;
}
if (dataBits.getWidth() < 9) {
NewBE = BUS_WITHOUT_BYTEENABLES;
}
ByteEnables = NewBE;
fireAttributeValueChanged(attr, value, null);
}
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class RamState method attributeValueChanged.
@Override
public void attributeValueChanged(AttributeEvent e) {
AttributeSet attrs = e.getSource();
BitWidth addrBits = attrs.getValue(Mem.ADDR_ATTR);
BitWidth dataBits = attrs.getValue(Mem.DATA_ATTR);
getContents().setDimensions(addrBits.getWidth(), dataBits.getWidth(), false);
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Random method propagate.
@Override
public void propagate(InstanceState state) {
StateData data = (StateData) state.getData();
if (data == null) {
data = new StateData(state.getAttributeValue(ATTR_SEED));
state.setData(data);
}
BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
Object triggerType = state.getAttributeValue(StdAttr.EDGE_TRIGGER);
boolean triggered = data.updateClock(state.getPortValue(CK), triggerType);
if (state.getPortValue(RST) == Value.TRUE) {
data.reset(state.getAttributeValue(ATTR_SEED));
} else if (triggered && state.getPortValue(NXT) != Value.FALSE) {
data.step();
}
state.setPort(OUT, Value.createKnown(dataWidth, data.value), 4);
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Demultiplexer method getOffsetBounds.
@Override
public Bounds getOffsetBounds(AttributeSet attrs) {
Direction facing = attrs.getValue(StdAttr.FACING);
BitWidth select = attrs.getValue(Plexers.ATTR_SELECT);
int outputs = 1 << select.getWidth();
Bounds bds;
if (outputs == 2) {
bds = Bounds.create(0, -25, 30, 50);
} else {
bds = Bounds.create(0, -(outputs / 2) * 10 - 10, 40, outputs * 10 + 20);
}
return bds.rotate(Direction.EAST, facing, 0, 0);
}
Aggregations