Search in sources :

Example 1 with DrMIPSActivity

use of brunonova.drmips.android.DrMIPSActivity in project drmips by brunonova.

the class DlgSave method onClick.

@Override
public void onClick(DialogInterface dialog, int which) {
    switch(which) {
        case // OK
        AlertDialog.BUTTON_POSITIVE:
            String path = txtFilename.getText().toString().trim();
            if (!path.isEmpty()) {
                // append extension if missing
                if (!path.contains("."))
                    path += ".asm";
                File file = new File(DrMIPS.getApplication().getCodeDir().getAbsolutePath() + File.separator + path);
                DrMIPSActivity activity = (DrMIPSActivity) getActivity();
                if (!file.exists()) {
                    // new file
                    activity.saveFile(file);
                } else {
                    // file exists
                    DlgConfirmReplace.newInstance(file.getPath()).show(getFragmentManager(), "confirm-replace-dialog");
                }
            }
            break;
        case // Cancel
        AlertDialog.BUTTON_NEGATIVE:
            dismiss();
            break;
    }
}
Also used : File(java.io.File) DrMIPSActivity(brunonova.drmips.android.DrMIPSActivity)

Example 2 with DrMIPSActivity

use of brunonova.drmips.android.DrMIPSActivity in project drmips by brunonova.

the class DlgStatistics method onCreateDialog.

@SuppressLint("InflateParams")
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);
    CPU cpu = ((DrMIPSActivity) getActivity()).getCPU();
    View layout = getActivity().getLayoutInflater().inflate(R.layout.statistics_dialog, null);
    ((TextView) layout.findViewById(R.id.lblClockPeriodVal)).setText(cpu.getClockPeriod() + " " + CPU.LATENCY_UNIT);
    ((TextView) layout.findViewById(R.id.lblClockFrequencyVal)).setText(cpu.getClockFrequencyInAdequateUnit());
    ((TextView) layout.findViewById(R.id.lblExecutedCyclesVal)).setText(cpu.getNumberOfExecutedCycles() + "");
    ((TextView) layout.findViewById(R.id.lblExecutionTimeVal)).setText(cpu.getExecutionTime() + " " + CPU.LATENCY_UNIT);
    ((TextView) layout.findViewById(R.id.lblExecutedInstructionsVal)).setText(cpu.getNumberOfExecutedInstructions() + "");
    ((TextView) layout.findViewById(R.id.lblCPIVal)).setText(cpu.getCPIAsString());
    ((TextView) layout.findViewById(R.id.lblForwardsVal)).setText(cpu.getNumberOfForwards() + "");
    ((TextView) layout.findViewById(R.id.lblStallsVal)).setText(cpu.getNumberOfStalls() + "");
    return new AlertDialog.Builder(getActivity()).setTitle(R.string.statistics).setView(layout).setPositiveButton(android.R.string.ok, this).create();
}
Also used : CPU(brunonova.drmips.simulator.CPU) TextView(android.widget.TextView) DrMIPSActivity(brunonova.drmips.android.DrMIPSActivity) TextView(android.widget.TextView) View(android.view.View) SuppressLint(android.annotation.SuppressLint)

Example 3 with DrMIPSActivity

use of brunonova.drmips.android.DrMIPSActivity 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)

Example 4 with DrMIPSActivity

use of brunonova.drmips.android.DrMIPSActivity in project drmips by brunonova.

the class DlgEditDataMemory method onClick.

@Override
public void onClick(DialogInterface dialog, int which) {
    switch(which) {
        case // OK
        AlertDialog.BUTTON_POSITIVE:
            String value = txtDataMemoryValue.getText().toString().trim();
            int val;
            if (!value.isEmpty()) {
                try {
                    Bundle args = getArguments();
                    DrMIPSActivity activity = (DrMIPSActivity) getActivity();
                    int index = args.getInt("index");
                    if (index >= 0 && index < activity.getCPU().getDataMemory().getMemorySize()) {
                        val = Integer.parseInt(value);
                        activity.getCPU().getDataMemory().setDataInIndex(index, val);
                        activity.refreshDataMemoryTableValues();
                        if (activity.getDatapath() != null)
                            activity.getDatapath().refresh();
                    }
                } catch (NumberFormatException ex) {
                    Toast.makeText(getActivity(), R.string.invalid_value, Toast.LENGTH_SHORT).show();
                }
            }
            break;
        case // Cancel
        AlertDialog.BUTTON_NEGATIVE:
            dismiss();
            break;
    }
}
Also used : Bundle(android.os.Bundle) DrMIPSActivity(brunonova.drmips.android.DrMIPSActivity)

Example 5 with DrMIPSActivity

use of brunonova.drmips.android.DrMIPSActivity in project drmips by brunonova.

the class DlgConfirmReplace method onClick.

@Override
public void onClick(DialogInterface dialog, int which) {
    switch(which) {
        case // OK
        AlertDialog.BUTTON_POSITIVE:
            Bundle args = getArguments();
            DrMIPSActivity activity = (DrMIPSActivity) getActivity();
            String path = args.getString("path");
            if (path != null) {
                activity.saveFile(new File(path));
            }
            break;
        case // Cancel
        AlertDialog.BUTTON_NEGATIVE:
            dismiss();
            break;
    }
}
Also used : Bundle(android.os.Bundle) DrMIPSActivity(brunonova.drmips.android.DrMIPSActivity) File(java.io.File)

Aggregations

DrMIPSActivity (brunonova.drmips.android.DrMIPSActivity)12 Bundle (android.os.Bundle)9 File (java.io.File)5 TextView (android.widget.TextView)3 SuppressLint (android.annotation.SuppressLint)2 TableLayout (android.widget.TableLayout)2 TableRow (android.widget.TableRow)2 CPU (brunonova.drmips.simulator.CPU)2 Component (brunonova.drmips.simulator.Component)2 AlertDialog (android.app.AlertDialog)1 View (android.view.View)1 EditText (android.widget.EditText)1 Instruction (brunonova.drmips.simulator.Instruction)1 PseudoInstruction (brunonova.drmips.simulator.PseudoInstruction)1 ALU (brunonova.drmips.simulator.components.ALU)1 ExtendedALU (brunonova.drmips.simulator.components.ExtendedALU)1