use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class TclComponentData method isNewTick.
public boolean isNewTick() {
boolean newTick = false;
boolean found = false;
for (Port p : instanceState.getInstance().getPorts()) {
if (p.getToolTip().equals("sysclk_i")) {
Value val = instanceState.getPortValue(instanceState.getPortIndex(p));
newTick = (val != prevClockValue);
if (newTick) {
prevClockValue = val;
}
found = true;
break;
}
}
if (!found) {
throw new UnsupportedOperationException("Could not find the 'sysclock' in the TCL component");
}
return newTick;
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class Multiplexer method propagate.
@Override
public void propagate(InstanceState state) {
BitWidth data = state.getAttributeValue(StdAttr.WIDTH);
BitWidth select = state.getAttributeValue(Plexers.ATTR_SELECT);
boolean enable = state.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
int inputs = 1 << select.getWidth();
Value en = enable ? state.getPortValue(inputs + 1) : Value.TRUE;
Value out;
if (en == Value.FALSE) {
Object opt = state.getAttributeValue(Plexers.ATTR_DISABLED);
Value base = opt == Plexers.DISABLED_ZERO ? Value.FALSE : Value.UNKNOWN;
out = Value.repeat(base, data.getWidth());
} else if (en == Value.ERROR && state.isPortConnected(inputs + 1)) {
out = Value.createError(data);
} else {
Value sel = state.getPortValue(inputs);
if (sel.isFullyDefined()) {
out = state.getPortValue(sel.toIntValue());
} else if (sel.isErrorValue()) {
out = Value.createError(data);
} else {
out = Value.createUnknown(data);
}
}
state.setPort(inputs + (enable ? 2 : 1), out, Plexers.DELAY);
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class Rom method propagate.
@Override
public void propagate(InstanceState state) {
MemState myState = getState(state);
BitWidth dataBits = state.getAttributeValue(DATA_ATTR);
Value addrValue = state.getPortValue(ADDR);
int addr = addrValue.toIntValue();
if (!addrValue.isFullyDefined() || addr < 0)
return;
if (addr != myState.getCurrent()) {
myState.setCurrent(addr);
myState.scrollToShow(addr);
}
int val = myState.getContents().get(addr);
state.setPort(DATA, Value.createKnown(dataBits, val), DELAY);
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class Ram method propagate.
@Override
public void propagate(InstanceState state) {
RamState myState = (RamState) getState(state);
Object trigger = state.getAttributeValue(StdAttr.TRIGGER);
Object bus = state.getAttributeValue(RamAttributes.ATTR_DBUS);
boolean asynch = trigger.equals(StdAttr.TRIG_HIGH) || trigger.equals(StdAttr.TRIG_LOW);
boolean edge = false;
if (!asynch) {
edge = myState.setClock(state.getPortValue(CLK), trigger);
}
boolean triggered = asynch || edge;
boolean separate = bus == null ? false : bus.equals(RamAttributes.BUS_SEP);
boolean outputEnabled = (!asynch || trigger.equals(StdAttr.TRIG_HIGH)) ? state.getPortValue(OE) != Value.FALSE : state.getPortValue(OE) == Value.FALSE;
BitWidth dataBits = state.getAttributeValue(DATA_ATTR);
/* Set the outputs in tri-state in case of combined bus */
if ((!separate && !outputEnabled) || (separate && asynch && !outputEnabled)) {
state.setPort(DATA, Value.createUnknown(dataBits), DELAY);
}
if (!triggered && !asynch && outputEnabled) {
state.setPort(DATA, Value.createKnown(dataBits, myState.GetCurrentData()), DELAY);
}
if (triggered) {
Object be = state.getAttributeValue(RamAttributes.ATTR_ByteEnables);
boolean byteEnables = be == null ? false : be.equals(RamAttributes.BUS_WITH_BYTEENABLES);
int NrOfByteEnables = GetNrOfByteEnables(state.getAttributeSet());
int ByteEnableIndex = ByteEnableIndex(state.getAttributeSet());
boolean shouldStore = (!asynch || trigger.equals(StdAttr.TRIG_HIGH)) ? state.getPortValue(WE) != Value.FALSE : state.getPortValue(WE) == Value.FALSE;
Value addrValue = state.getPortValue(ADDR);
int addr = addrValue.toIntValue();
if (!addrValue.isFullyDefined() || addr < 0) {
return;
}
if (addr != myState.getCurrent()) {
myState.setCurrent(addr);
myState.scrollToShow(addr);
}
if (shouldStore) {
int dataValue = state.getPortValue(!separate ? DATA : (asynch) ? ADIN : SDIN).toIntValue();
int memValue = myState.getContents().get(addr);
if (byteEnables) {
int mask = 0xFF << (NrOfByteEnables - 1) * 8;
for (int i = 0; i < NrOfByteEnables; i++) {
Value bitvalue = state.getPortValue(ByteEnableIndex + i);
boolean disabled = bitvalue == null ? false : bitvalue.equals(Value.FALSE);
if (disabled) {
dataValue &= ~mask;
dataValue |= (memValue & mask);
}
mask >>= 8;
}
}
myState.getContents().set(addr, dataValue);
}
int val = myState.getContents().get(addr);
int currentValue = myState.GetCurrentData();
if (byteEnables) {
int mask = 0xFF << (NrOfByteEnables - 1) * 8;
for (int i = 0; i < NrOfByteEnables; i++) {
Value bitvalue = state.getPortValue(ByteEnableIndex + i);
boolean disabled = bitvalue == null ? false : bitvalue.equals(Value.FALSE);
if (disabled) {
val &= ~mask;
val |= (currentValue & mask);
}
mask >>= 8;
}
}
myState.SetCurrentData(val);
if (outputEnabled) {
state.setPort(DATA, Value.createKnown(dataBits, val), DELAY);
}
}
}
Aggregations