Search in sources :

Example 6 with DrMIPSActivity

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

the class DlgCodeHelp method setContents.

private void setContents(View rootView) {
    DrMIPSActivity activity = (DrMIPSActivity) getActivity();
    TableLayout tblInstructions = (TableLayout) rootView.findViewById(R.id.tblInstructions);
    TableLayout tblPseudos = (TableLayout) rootView.findViewById(R.id.tblPseudos);
    TableRow row;
    TextView inst, desc;
    tblInstructions.removeAllViews();
    tblPseudos.removeAllViews();
    CPU cpu = activity.getCPU();
    for (Instruction i : cpu.getInstructionSet().getInstructions()) {
        row = new TableRow(activity);
        inst = new TextView(activity);
        inst.setText(i.getUsage() + " ");
        row.addView(inst);
        desc = new TextView(activity);
        desc.setText("# " + (i.hasDescription() ? i.getDescription() : "-"));
        row.addView(desc);
        tblInstructions.addView(row);
    }
    for (PseudoInstruction i : cpu.getInstructionSet().getPseudoInstructions()) {
        row = new TableRow(activity);
        inst = new TextView(activity);
        inst.setText(i.getUsage() + " ");
        row.addView(inst);
        desc = new TextView(activity);
        desc.setText("# " + (i.hasDescription() ? i.getDescription() : "-"));
        row.addView(desc);
        tblPseudos.addView(row);
    }
}
Also used : PseudoInstruction(brunonova.drmips.simulator.PseudoInstruction) TableRow(android.widget.TableRow) CPU(brunonova.drmips.simulator.CPU) TextView(android.widget.TextView) PseudoInstruction(brunonova.drmips.simulator.PseudoInstruction) Instruction(brunonova.drmips.simulator.Instruction) DrMIPSActivity(brunonova.drmips.android.DrMIPSActivity) TableLayout(android.widget.TableLayout)

Example 7 with DrMIPSActivity

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

the class DlgConfirmDelete 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");
            File file;
            if (path != null && (file = new File(path)).exists()) {
                if (file.delete()) {
                    Toast.makeText(getActivity(), R.string.file_deleted, Toast.LENGTH_SHORT).show();
                    activity.newFile();
                } else
                    Toast.makeText(getActivity(), R.string.error_deleting_file, Toast.LENGTH_SHORT).show();
            }
            break;
        case // Cancel
        AlertDialog.BUTTON_NEGATIVE:
            dismiss();
            break;
    }
}
Also used : Bundle(android.os.Bundle) DrMIPSActivity(brunonova.drmips.android.DrMIPSActivity) File(java.io.File)

Example 8 with DrMIPSActivity

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

the class DlgOpen method onClick.

@Override
public void onClick(DialogInterface dialog, int which) {
    Bundle args = getArguments();
    DrMIPSActivity activity = (DrMIPSActivity) getActivity();
    String[] files = args.containsKey("files") ? args.getStringArray("files") : new String[] {};
    if (files != null && which >= 0 && which < files.length) {
        String name = files[which];
        File file = new File(DrMIPS.getApplication().getCodeDir() + File.separator + name);
        activity.openFile(file);
    }
    dialog.dismiss();
}
Also used : Bundle(android.os.Bundle) DrMIPSActivity(brunonova.drmips.android.DrMIPSActivity) File(java.io.File)

Example 9 with DrMIPSActivity

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

the class DlgOpenCPU method onClick.

@Override
public void onClick(DialogInterface dialog, int which) {
    Bundle args = getArguments();
    DrMIPSActivity activity = (DrMIPSActivity) getActivity();
    String[] files = args.containsKey("files") ? args.getStringArray("files") : new String[] {};
    if (files != null && which >= 0 && which < files.length) {
        String name = files[which];
        File file = new File(DrMIPS.getApplication().getCPUDir() + File.separator + name);
        try {
            activity.loadCPU(file);
            activity.setCurrentTab("tabDatapath");
        } catch (Throwable ex) {
            Toast.makeText(getActivity(), getString(R.string.invalid_file) + "\n" + ex.getClass().getName() + " (" + ex.getMessage() + ")", Toast.LENGTH_LONG).show();
            Log.e(getActivity().getClass().getName(), "error loading CPU \"" + file.getName() + "\"", ex);
        }
    }
    dialog.dismiss();
}
Also used : Bundle(android.os.Bundle) DrMIPSActivity(brunonova.drmips.android.DrMIPSActivity) File(java.io.File)

Example 10 with DrMIPSActivity

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

the class DlgEditRegister method onClick.

@Override
public void onClick(DialogInterface dialog, int which) {
    switch(which) {
        case //OK
        AlertDialog.BUTTON_POSITIVE:
            String value = txtRegisterValue.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().getRegBank().getNumberOfRegisters()) {
                        val = Integer.parseInt(value);
                        activity.setRegisterValue(index, val);
                        activity.refreshRegistersTableValues();
                    }
                } 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)

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