use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class BitSelector method propagate.
@Override
public void propagate(InstanceState state) {
Value data = state.getPortValue(1);
Value select = state.getPortValue(2);
BitWidth groupBits = state.getAttributeValue(GROUP_ATTR);
Value group;
if (!select.isFullyDefined()) {
group = Value.createUnknown(groupBits);
} else {
int shift = select.toIntValue() * groupBits.getWidth();
if (shift >= data.getWidth()) {
group = Value.createKnown(groupBits, 0);
} else if (groupBits.getWidth() == 1) {
group = data.get(shift);
} else {
Value[] bits = new Value[groupBits.getWidth()];
for (int i = 0; i < bits.length; i++) {
if (shift + i >= data.getWidth()) {
bits[i] = Value.FALSE;
} else {
bits[i] = data.get(shift + i);
}
}
group = Value.create(bits);
}
}
state.setPort(0, group, Plexers.DELAY);
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class Decoder method propagate.
@Override
public void propagate(InstanceState state) {
// get attributes
BitWidth data = BitWidth.ONE;
BitWidth select = state.getAttributeValue(Plexers.ATTR_SELECT);
Boolean threeState = state.getAttributeValue(Plexers.ATTR_TRISTATE);
boolean enable = state.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
int outputs = 1 << select.getWidth();
// determine default output values
// the default output
Value others;
if (threeState.booleanValue()) {
others = Value.UNKNOWN;
} else {
others = Value.FALSE;
}
// determine selected output value
// the special output
int outIndex = -1;
Value out = null;
Value en = enable ? state.getPortValue(outputs + 1) : Value.TRUE;
if (en == Value.FALSE) {
Object opt = state.getAttributeValue(Plexers.ATTR_DISABLED);
Value base = opt == Plexers.DISABLED_ZERO ? Value.FALSE : Value.UNKNOWN;
others = Value.repeat(base, data.getWidth());
} else if (en == Value.ERROR && state.isPortConnected(outputs + 1)) {
others = Value.createError(data);
} else {
Value sel = state.getPortValue(outputs);
if (sel.isFullyDefined()) {
outIndex = sel.toIntValue();
out = Value.TRUE;
} else if (sel.isErrorValue()) {
others = Value.createError(data);
} else {
others = Value.createUnknown(data);
}
}
// now propagate them
for (int i = 0; i < outputs; i++) {
state.setPort(i, i == outIndex ? out : others, Plexers.DELAY);
}
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class TtyState method setLastClock.
public Value setLastClock(Value newClock) {
Value ret = lastClock;
lastClock = newClock;
return ret;
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class AbstractFlipFlop method propagate.
@Override
public void propagate(InstanceState state) {
// boolean changed = false;
StateData data = (StateData) state.getData();
if (data == null) {
// changed = true;
data = new StateData();
state.setData(data);
}
int n = getPorts().size() - STD_PORTS;
Object triggerType = state.getAttributeValue(triggerAttribute);
boolean triggered = data.updateClock(state.getPortValue(n), triggerType);
if (state.getPortValue(n + 3) == Value.TRUE) {
// clear requested
// changed |= data.curValue != Value.FALSE;
data.curValue = Value.FALSE;
} else if (state.getPortValue(n + 4) == Value.TRUE) {
// preset
// requested
// changed |= data.curValue != Value.TRUE;
data.curValue = Value.TRUE;
} else if (triggered) /* && state.getPortValue(n + 5) != Value.FALSE */
{
// Clock has triggered and flip-flop is enabled: Update the state
Value[] inputs = new Value[n];
for (int i = 0; i < n; i++) {
inputs[i] = state.getPortValue(i);
}
Value newVal = computeValue(inputs, data.curValue);
if (newVal == Value.TRUE || newVal == Value.FALSE) {
// changed |= data.curValue != newVal;
data.curValue = newVal;
}
}
state.setPort(n + 1, data.curValue, Memory.DELAY);
state.setPort(n + 2, data.curValue.not(), Memory.DELAY);
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class TclComponent method propagate.
/**
* This creates a new TCL process executing the TCL content file.
* Communication is done through a socket
*
* @param state
*/
@Override
public void propagate(InstanceState state) {
/*
* The ComponentData is the persistent thing through logisim usage. It
* doesn't change when you move the component when InstanceComponent
* does.
*/
TclComponentData tclComponentData = TclComponentData.get(state);
tclComponentData.getTclWrapper().start();
/*
* Here we may miss the first clock if the TCL process is not soon fast
* enought You may change this behavior, but blocking here seemed bad to
* me
*/
if (tclComponentData.isConnected()) {
/* Send port values to the TCL wrapper */
for (Port p : state.getInstance().getPorts()) {
int index = state.getPortIndex(p);
Value val = state.getPortValue(index);
String message = p.getType() + ":" + p.getToolTip() + ":" + val.toBinaryString() + ":" + index;
tclComponentData.send(message);
}
/*
* If it is a new tick, ask the console to force the sti in the
* console and set them in Logisim in return. If it is not a new
* tick, simply send the updated obs to the console.
*/
if (tclComponentData.isNewTick()) {
tclComponentData.send("sync_force");
getPortsFromServer(state, tclComponentData);
} else {
tclComponentData.send("sync_examine");
String server_response;
/* Ignore all messages until "sync" is recieved */
while ((server_response = tclComponentData.receive()) != null && server_response.length() > 0 && !server_response.equals("sync")) ;
}
}
}
Aggregations