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;
}
}
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();
}
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);
}
}
}
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;
}
}
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;
}
}
Aggregations