Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.Value


    }
    componentData.put(comp, data);
  }

  public Value getValue(Location pt) {
    Value ret = values.get(pt);
    if (ret != null) return ret;

    BitWidth wid = circuit.getWidth(pt);
    return Value.createUnknown(wid);
  }
View Full Code Here


    }

    BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
    Object triggerType = state.getAttributeValue(StdAttr.EDGE_TRIGGER);
    int max = state.getAttributeValue(ATTR_MAX).intValue();
    Value clock = state.getPort(CK);
    boolean triggered = data.updateClock(clock, triggerType);

    Value newValue;
    boolean carry;
    if (state.getPort(CLR) == Value.TRUE) {
      newValue = Value.createKnown(dataWidth, 0);
      carry = false;
    } else {
      boolean ld = state.getPort(LD) == Value.TRUE;
      boolean ct = state.getPort(CT) != Value.FALSE;
      int oldVal = data.value;
      int newVal;
      if (!triggered) {
        newVal = oldVal;
      } else if (ct) { // trigger, enable = 1: should increment or decrement
        int goal = ld ? 0 : max;
        if (oldVal == goal) {
          Object onGoal = state.getAttributeValue(ATTR_ON_GOAL);
          if (onGoal == ON_GOAL_WRAP) {
            newVal = ld ? max : 0;
          } else if (onGoal == ON_GOAL_STAY) {
            newVal = oldVal;
          } else if (onGoal == ON_GOAL_LOAD) {
            Value in = state.getPort(IN);
            newVal = in.isFullyDefined() ? in.toIntValue() : 0;
            if (newVal > max) newVal &= max;
          } else if (onGoal == ON_GOAL_CONT) {
            newVal = ld ? oldVal - 1 : oldVal + 1;
          } else {
            System.err.println("Invalid goal attribute " + onGoal); //OK
            newVal = ld ? max : 0;
          }
        } else {
          newVal = ld ? oldVal - 1 : oldVal + 1;
        }
      } else if (ld) { // trigger, enable = 0, load = 1: should load
        Value in = state.getPort(IN);
        newVal = in.isFullyDefined() ? in.toIntValue() : 0;
        if (newVal > max) newVal &= max;
      } else { // trigger, enable = 0, load = 0: no change
        newVal = oldVal;
      }
      newValue = Value.createKnown(dataWidth, newVal);
View Full Code Here

  }

  @Override
  public void propagate(InstanceState state) {
    InstanceDataSingleton data = (InstanceDataSingleton) state.getData();
    Value val = data == null ? Value.FALSE : (Value) data.getValue();
    state.setPort(0, val, 1);
  }
View Full Code Here

    Boolean threeState = state.getAttributeValue(Plexers.ATTR_TRISTATE);
    boolean enable = state.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int outputs = 1 << select.getWidth();
   
    // determine default output values
    Value others; // the default output
    if (threeState.booleanValue()) {
      others = Value.UNKNOWN;
    } else {
      others = Value.FALSE;
    }

    // determine selected output value
    int outIndex = -1; // the special output
    Value out = null;
    Value en = enable ? state.getPort(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.getPort(outputs);
      if (sel.isFullyDefined()) {
        outIndex = sel.toIntValue();
        out = Value.TRUE;
      } else if (sel.isErrorValue()) {
        others = Value.createError(data);
      } else {
        others = Value.createUnknown(data);
      }
    }
View Full Code Here

    int x = bds.getX();
    int y = bds.getY();
    int w = bds.getWidth();
    int h = bds.getHeight();

    Value val;
    if (painter.getShowState()) {
      InstanceDataSingleton data = (InstanceDataSingleton) painter.getData();
      val = data == null ? Value.FALSE : (Value) data.getValue();
    } else {
      val = Value.FALSE;
View Full Code Here

      drawAnd(g, x0, y0, 130, 90);
      drawOr(g, x0, y0, 220, 60);
    }

    private void drawWires(Graphics g, int x0, int y0) {
      Value upperNot = upper.not();
      Value lowerNot = lower.not();
      Value upperAnd = upperNot.and(lower);
      Value lowerAnd = lowerNot.and(upper);
      Value out = upperAnd.or(lowerAnd);
      int x;
      int y;
     
      g.setColor(upper.getColor());
      x = toX(x0, 20);
      y = toY(y0, 10);
      g.fillOval(x - 7, y - 7, 14, 14);
      g.drawLine(toX(x0, 0), y, toX(x0, 40), y);
      g.drawLine(x, y, x, toY(y0, 70));
      y = toY(y0, 70);
      g.drawLine(x, y, toX(x0, 80), y);
      g.setColor(upperNot.getColor());
      y = toY(y0, 10);
      g.drawLine(toX(x0, 70), y, toX(x0, 80), y);
     
      g.setColor(lower.getColor());
      x = toX(x0, 30);
      y = toY(y0, 110);
      g.fillOval(x - 7, y - 7, 14, 14);
      g.drawLine(toX(x0, 0), y, toX(x0, 40), y);
      g.drawLine(x, y, x, toY(y0, 50));
      y = toY(y0, 50);
      g.drawLine(x, y, toX(x0, 80), y);
      g.setColor(lowerNot.getColor());
      y = toY(y0, 110);
      g.drawLine(toX(x0, 70), y, toX(x0, 80), y);
     
      g.setColor(upperAnd.getColor());
      x = toX(x0, 150);
      y = toY(y0, 30);
      g.drawLine(toX(x0, 130), y, x, y);
      g.drawLine(x, y, x, toY(y0, 45));
      y = toY(y0, 45);
      g.drawLine(x, y, toX(x0, 174), y);
      g.setColor(lowerAnd.getColor());
      y = toY(y0, 90);
      g.drawLine(toX(x0, 130), y, x, y);
      g.drawLine(x, y, x, toY(y0, 75));
      y = toY(y0, 75);
      g.drawLine(x, y, toX(x0, 174), y);
     
      g.setColor(out.getColor());
      y = toY(y0, 60);
      g.drawLine(toX(x0, 220), y, toX(x0, 240), y);
    }
View Full Code Here

    Propagator prop = circState.getPropagator();
    while (true) {
      ArrayList<Value> curOutputs = new ArrayList<Value>();
      for (Instance pin : outputPins) {
        InstanceState pinState = circState.getInstanceState(pin);
        Value val = Pin.FACTORY.getValue(pinState);
        if (pin == haltPin) {
          halted |= val.equals(Value.TRUE);
        } else if (showTable) {
          curOutputs.add(val);
        }
      }
      if (showTable) {
View Full Code Here

    boolean shouldPrint = false;
    if (prevOutputs == null) {
      shouldPrint = true;
    } else {
      for (int i = 0; i < curOutputs.size(); i++) {
        Value a = prevOutputs.get(i);
        Value b = curOutputs.get(i);
        if (!a.equals(b)) {
          shouldPrint = true;
          break;
        }
      }
View Full Code Here

class GateFunctions {
  private GateFunctions() { }
 
  static Value computeOr(Value[] inputs, int numInputs) {
    Value ret = inputs[0];
    for (int i = 1; i < numInputs; i++) {
      ret = ret.or(inputs[i]);
    }
    return ret;
  }
View Full Code Here

    }
    return ret;
  }
 
  static Value computeAnd(Value[] inputs, int numInputs) {
    Value ret = inputs[0];
    for (int i = 1; i < numInputs; i++) {
      ret = ret.and(inputs[i]);
    }
    return ret;
  }
View Full Code Here

TOP

Related Classes of com.cburch.logisim.data.Value

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.