Search in sources :

Example 36 with Port

use of com.cburch.logisim.instance.Port 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")) ;
        }
    }
}
Also used : Port(com.cburch.logisim.instance.Port) Value(com.cburch.logisim.data.Value)

Example 37 with Port

use of com.cburch.logisim.instance.Port in project logisim-evolution by reds-heig.

the class TclComponent method paintInstance.

/**
 * This was taken from VHDL component
 *
 * @param painter
 */
@Override
public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    FontMetrics metric = g.getFontMetrics();
    Bounds bds = painter.getBounds();
    int x0 = bds.getX() + (bds.getWidth() / 2);
    int y0 = bds.getY() + metric.getHeight() + 12;
    GraphicsUtil.drawText(g, StringUtil.resizeString(getDisplayName(), metric, WIDTH), x0, y0, GraphicsUtil.H_CENTER, GraphicsUtil.V_BOTTOM);
    String glbLabel = painter.getAttributeValue(StdAttr.LABEL);
    if (glbLabel != null) {
        Font font = g.getFont();
        g.setFont(painter.getAttributeValue(StdAttr.LABEL_FONT));
        GraphicsUtil.drawCenteredText(g, glbLabel, bds.getX() + bds.getWidth() / 2, bds.getY() - g.getFont().getSize());
        g.setFont(font);
    }
    g.setColor(Color.GRAY);
    g.setFont(g.getFont().deriveFont((float) 10));
    metric = g.getFontMetrics();
    int i = 0;
    for (Port p : inputs) {
        GraphicsUtil.drawText(g, StringUtil.resizeString(p.getToolTip(), metric, (WIDTH / 2) - X_PADDING), bds.getX() + 5, bds.getY() + HEIGHT - 2 + (i++ * PORT_GAP), GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
    }
    i = 0;
    for (Port p : outputs) {
        GraphicsUtil.drawText(g, StringUtil.resizeString(p.getToolTip(), metric, (WIDTH / 2) - X_PADDING), bds.getX() + WIDTH - 5, bds.getY() + HEIGHT - 2 + (i++ * PORT_GAP), GraphicsUtil.H_RIGHT, GraphicsUtil.V_CENTER);
    }
    painter.drawBounds();
    painter.drawPorts();
}
Also used : Graphics(java.awt.Graphics) FontMetrics(java.awt.FontMetrics) Bounds(com.cburch.logisim.data.Bounds) Port(com.cburch.logisim.instance.Port) Font(java.awt.Font)

Example 38 with Port

use of com.cburch.logisim.instance.Port 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;
}
Also used : Port(com.cburch.logisim.instance.Port) Value(com.cburch.logisim.data.Value)

Example 39 with Port

use of com.cburch.logisim.instance.Port in project logisim-evolution by reds-heig.

the class Multiplexer method updatePorts.

private void updatePorts(Instance instance) {
    Direction dir = instance.getAttributeValue(StdAttr.FACING);
    Object selectLoc = instance.getAttributeValue(Plexers.ATTR_SELECT_LOC);
    BitWidth data = instance.getAttributeValue(StdAttr.WIDTH);
    BitWidth select = instance.getAttributeValue(Plexers.ATTR_SELECT);
    boolean enable = instance.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int selMult = selectLoc == Plexers.SELECT_BOTTOM_LEFT ? 1 : -1;
    int inputs = 1 << select.getWidth();
    Port[] ps = new Port[inputs + (enable ? 3 : 2)];
    Location sel;
    if (inputs == 2) {
        Location end0;
        Location end1;
        if (dir == Direction.WEST) {
            end0 = Location.create(30, -10);
            end1 = Location.create(30, 10);
            sel = Location.create(20, selMult * 20);
        } else if (dir == Direction.NORTH) {
            end0 = Location.create(-10, 30);
            end1 = Location.create(10, 30);
            sel = Location.create(selMult * -20, 20);
        } else if (dir == Direction.SOUTH) {
            end0 = Location.create(-10, -30);
            end1 = Location.create(10, -30);
            sel = Location.create(selMult * -20, -20);
        } else {
            end0 = Location.create(-30, -10);
            end1 = Location.create(-30, 10);
            sel = Location.create(-20, selMult * 20);
        }
        ps[0] = new Port(end0.getX(), end0.getY(), Port.INPUT, data.getWidth());
        ps[1] = new Port(end1.getX(), end1.getY(), Port.INPUT, data.getWidth());
    } else {
        int dx = -(inputs / 2) * 10;
        int ddx = 10;
        int dy = -(inputs / 2) * 10;
        int ddy = 10;
        if (dir == Direction.WEST) {
            dx = 40;
            ddx = 0;
            sel = Location.create(20, selMult * (dy + 10 * inputs));
        } else if (dir == Direction.NORTH) {
            dy = 40;
            ddy = 0;
            sel = Location.create(selMult * dx, 20);
        } else if (dir == Direction.SOUTH) {
            dy = -40;
            ddy = 0;
            sel = Location.create(selMult * dx, -20);
        } else {
            dx = -40;
            ddx = 0;
            sel = Location.create(-20, selMult * (dy + 10 * inputs));
        }
        for (int i = 0; i < inputs; i++) {
            ps[i] = new Port(dx, dy, Port.INPUT, data.getWidth());
            dx += ddx;
            dy += ddy;
        }
    }
    Location en = sel.translate(dir, 10);
    ps[inputs] = new Port(sel.getX(), sel.getY(), Port.INPUT, select.getWidth());
    if (enable) {
        ps[inputs + 1] = new Port(en.getX(), en.getY(), Port.INPUT, BitWidth.ONE);
    }
    ps[ps.length - 1] = new Port(0, 0, Port.OUTPUT, data.getWidth());
    for (int i = 0; i < inputs; i++) {
        ps[i].setToolTip(Strings.getter("multiplexerInTip", "" + i));
    }
    ps[inputs].setToolTip(Strings.getter("multiplexerSelectTip"));
    if (enable) {
        ps[inputs + 1].setToolTip(Strings.getter("multiplexerEnableTip"));
    }
    ps[ps.length - 1].setToolTip(Strings.getter("multiplexerOutTip"));
    instance.setPorts(ps);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Port(com.cburch.logisim.instance.Port) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 40 with Port

use of com.cburch.logisim.instance.Port in project logisim-evolution by reds-heig.

the class Rom method configurePorts.

@Override
void configurePorts(Instance instance) {
    Port[] ps = new Port[MEM_INPUTS];
    ps[ADDR] = new Port(0, 10, Port.INPUT, ADDR_ATTR);
    ps[ADDR].setToolTip(Strings.getter("memAddrTip"));
    int ypos = (instance.getAttributeValue(Mem.DATA_ATTR).getWidth() == 1) ? getControlHeight(instance.getAttributeSet()) + 10 : getControlHeight(instance.getAttributeSet());
    ps[DATA] = new Port(SymbolWidth + 40, ypos, Port.OUTPUT, DATA_ATTR);
    ps[DATA].setToolTip(Strings.getter("memDataTip"));
    instance.setPorts(ps);
}
Also used : Port(com.cburch.logisim.instance.Port)

Aggregations

Port (com.cburch.logisim.instance.Port)40 BitWidth (com.cburch.logisim.data.BitWidth)12 Direction (com.cburch.logisim.data.Direction)10 Location (com.cburch.logisim.data.Location)9 Bounds (com.cburch.logisim.data.Bounds)6 Value (com.cburch.logisim.data.Value)3 Font (java.awt.Font)3 FontMetrics (java.awt.FontMetrics)3 Graphics (java.awt.Graphics)3 IOException (java.io.IOException)2 Component (com.cburch.logisim.comp.Component)1 AttributeSet (com.cburch.logisim.data.AttributeSet)1 Instance (com.cburch.logisim.instance.Instance)1 InstanceState (com.cburch.logisim.instance.InstanceState)1 VhdlContent (com.cburch.logisim.std.hdl.VhdlContent)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintWriter (java.io.PrintWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1