Search in sources :

Example 1 with ExtendedALU

use of brunonova.drmips.simulator.components.ExtendedALU in project drmips by brunonova.

the class DlgComponentDescription method setContents.

private void setContents(Dialog dialog, View rootView) {
    String title;
    Bundle args = getArguments();
    if (!args.containsKey("id"))
        return;
    DrMIPSActivity activity = (DrMIPSActivity) getActivity();
    Component component = activity.getCPU().getComponent(args.getString("id"));
    boolean performanceMode = args.getBoolean("performanceMode", false);
    int datapathFormat = args.getInt("datapathFormat", DrMIPS.DEFAULT_DATAPATH_DATA_FORMAT);
    // Title
    int nameId = activity.getResources().getIdentifier(component.getNameKey(), "string", activity.getPackageName());
    if (nameId != 0)
        title = activity.getString(nameId);
    else
        title = component.getDefaultName();
    title += " (" + component.getId() + ")";
    if (component instanceof Synchronous)
        title += " - " + activity.getString(R.string.synchronous);
    dialog.setTitle(title);
    // Description
    TextView lblComponentDescription = (TextView) rootView.findViewById(R.id.lblComponentDescription);
    String desc = component.getCustomDescription(getResources().getConfiguration().locale.toString());
    if (desc == null) {
        int descId = activity.getResources().getIdentifier(component.getDescriptionKey(), "string", activity.getPackageName());
        if (descId != 0)
            desc = activity.getString(descId);
        else
            desc = component.getDefaultDescription();
    }
    // ALU operation if ALU
    if (!performanceMode && component instanceof ALU) {
        ALU alu = (ALU) component;
        desc += "\n" + getResources().getString(R.string.operation) + ": " + alu.getOperationName();
        // HI and LO registers if extended ALU
        if (!performanceMode && component instanceof ExtendedALU) {
            ExtendedALU ext_alu = (ExtendedALU) alu;
            desc += "\nHI: " + Util.formatDataAccordingToFormat(ext_alu.getHI(), datapathFormat);
            desc += "\nLO: " + Util.formatDataAccordingToFormat(ext_alu.getLO(), datapathFormat);
        }
    }
    lblComponentDescription.setText(desc);
    // Latency
    TextView lblLatency = (TextView) rootView.findViewById(R.id.lblComponentLatency);
    if (performanceMode) {
        lblLatency.setVisibility(View.VISIBLE);
        lblLatency.setText(getResources().getString(R.string.latency) + ": " + component.getLatency() + " " + CPU.LATENCY_UNIT + " (" + getResources().getString(R.string.long_press_to_change) + ")");
    } else
        lblLatency.setVisibility(View.GONE);
    // Inputs
    TableLayout tblInputs = (TableLayout) rootView.findViewById(R.id.tblComponentInputs);
    tblInputs.removeAllViews();
    TableRow row;
    TextView lblId, lblValue;
    for (Input in : component.getInputs()) {
        if (in.isConnected()) {
            row = new TableRow(activity);
            lblId = new TextView(activity);
            lblValue = new TextView(activity);
            lblId.setText(in.getId() + ":");
            lblValue.setGravity(Gravity.RIGHT);
            if (performanceMode) {
                lblValue.setText(in.getAccumulatedLatency() + " " + CPU.LATENCY_UNIT);
            } else
                lblValue.setText(Util.formatDataAccordingToFormat(in.getData(), datapathFormat));
            row.addView(lblId);
            row.addView(lblValue);
            if (performanceMode && in.isInCriticalPath()) {
                lblId.setTextColor(getResources().getColor(R.color.red));
                lblValue.setTextColor(getResources().getColor(R.color.red));
            } else if (in.isInControlPath()) {
                lblId.setTextColor(getResources().getColor(R.color.control));
                lblValue.setTextColor(getResources().getColor(R.color.control));
            }
            tblInputs.addView(row);
        }
    }
    // Outputs
    TableLayout tblOutputs = (TableLayout) rootView.findViewById(R.id.tblComponentOutputs);
    tblOutputs.removeAllViews();
    for (Output out : component.getOutputs()) {
        if (out.isConnected()) {
            row = new TableRow(activity);
            lblId = new TextView(activity);
            lblValue = new TextView(activity);
            lblId.setText(out.getId() + ":");
            lblValue.setGravity(Gravity.RIGHT);
            if (performanceMode)
                lblValue.setText(component.getAccumulatedLatency() + " " + CPU.LATENCY_UNIT);
            else
                lblValue.setText(Util.formatDataAccordingToFormat(out.getData(), datapathFormat));
            row.addView(lblId);
            row.addView(lblValue);
            if (performanceMode && out.isInCriticalPath()) {
                lblId.setTextColor(getResources().getColor(R.color.red));
                lblValue.setTextColor(getResources().getColor(R.color.red));
            } else if (out.isInControlPath()) {
                lblId.setTextColor(getResources().getColor(R.color.control));
                lblValue.setTextColor(getResources().getColor(R.color.control));
            }
            tblOutputs.addView(row);
        }
    }
}
Also used : Bundle(android.os.Bundle) ALU(brunonova.drmips.simulator.components.ALU) ExtendedALU(brunonova.drmips.simulator.components.ExtendedALU) ExtendedALU(brunonova.drmips.simulator.components.ExtendedALU) DrMIPSActivity(brunonova.drmips.android.DrMIPSActivity) SuppressLint(android.annotation.SuppressLint) TableRow(android.widget.TableRow) TextView(android.widget.TextView) TableLayout(android.widget.TableLayout)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Bundle (android.os.Bundle)1 TableLayout (android.widget.TableLayout)1 TableRow (android.widget.TableRow)1 TextView (android.widget.TextView)1 DrMIPSActivity (brunonova.drmips.android.DrMIPSActivity)1 ALU (brunonova.drmips.simulator.components.ALU)1 ExtendedALU (brunonova.drmips.simulator.components.ExtendedALU)1