use of brunonova.drmips.simulator.CPU in project drmips by brunonova.
the class DrMIPSActivity method refreshAssembledCodeTableValues.
/**
* Refreshes the assembled code table highlights.
*/
private void refreshAssembledCodeTableValues() {
TableRow row;
CPU cpu = getCPU();
for (int i = 0; i < cpu.getInstructionMemory().getNumberOfInstructions(); i++) {
row = (TableRow) tblAssembledCode.getChildAt(i + 1);
// Highlight instructions being executed
if (i == cpu.getPC().getCurrentInstructionIndex())
row.setBackgroundColor(Util.getThemeColor(this, getCPU().isPipeline() ? R.attr.ifColor : R.attr.instColor));
else if (cpu.isPipeline()) {
if (i == cpu.getIfIdReg().getCurrentInstructionIndex())
row.setBackgroundColor(Util.getThemeColor(this, R.attr.idColor));
else if (i == cpu.getIdExReg().getCurrentInstructionIndex())
row.setBackgroundColor(Util.getThemeColor(this, R.attr.exColor));
else if (i == cpu.getExMemReg().getCurrentInstructionIndex())
row.setBackgroundColor(Util.getThemeColor(this, R.attr.memColor));
else if (i == cpu.getMemWbReg().getCurrentInstructionIndex())
row.setBackgroundColor(Util.getThemeColor(this, R.attr.wbColor));
else
// remove background color
row.setBackgroundResource(0);
} else
// remove background color
row.setBackgroundResource(0);
}
tblAssembledCode.requestLayout();
}
use of brunonova.drmips.simulator.CPU in project drmips by brunonova.
the class DrMIPSActivity method refreshExecTableValues.
/**
* Refreshes the values of the exec table.
*/
private void refreshExecTableValues() {
CPU cpu = getCPU();
((TextView) tblExecRow.getChildAt(0)).setText(getInstructionInIndex(cpu.getPC().getCurrentInstructionIndex()));
if (cpu.isPipeline()) {
((TextView) tblExecRow.getChildAt(1)).setText(getInstructionInIndex(cpu.getIfIdReg().getCurrentInstructionIndex()));
((TextView) tblExecRow.getChildAt(2)).setText(getInstructionInIndex(cpu.getIdExReg().getCurrentInstructionIndex()));
((TextView) tblExecRow.getChildAt(3)).setText(getInstructionInIndex(cpu.getExMemReg().getCurrentInstructionIndex()));
((TextView) tblExecRow.getChildAt(4)).setText(getInstructionInIndex(cpu.getMemWbReg().getCurrentInstructionIndex()));
}
}
use of brunonova.drmips.simulator.CPU in project drmips by brunonova.
the class DrMIPSActivity method refreshDataMemoryTable.
/**
* Refreshes both the rows and values of the data memory table.
*/
private void refreshDataMemoryTable() {
while (// remove all rows except header
tblDataMemory.getChildCount() > 1) tblDataMemory.removeViewAt(1);
CPU cpu = getCPU();
if (cpu.hasDataMemory()) {
TableRow row;
TextView address, value;
for (int i = 0; i < cpu.getDataMemory().getMemorySize(); i++) {
row = new TableRow(this);
row.setOnLongClickListener(dataMemoryRowOnLongClickListener);
address = new TextView(this);
address.setTextAppearance(this, android.R.style.TextAppearance_Medium);
address.setTypeface(Typeface.MONOSPACE);
value = new TextView(this);
value.setTextAppearance(this, android.R.style.TextAppearance_Medium);
value.setTypeface(Typeface.MONOSPACE);
value.setGravity(Gravity.RIGHT);
row.addView(address);
row.addView(value);
tblDataMemory.addView(row);
}
// refresh values
refreshDataMemoryTableValues();
}
}
use of brunonova.drmips.simulator.CPU in project drmips by brunonova.
the class DrMIPSActivity method refreshAssembledCodeTable.
/**
* Refreshes the contents of the code table.
*/
private void refreshAssembledCodeTable() {
while (// remove all rows except header
tblAssembledCode.getChildCount() > 1) tblAssembledCode.removeViewAt(1);
AssembledInstruction instruction;
TableRow row;
TextView address, assembled, code;
String codeLine;
CPU cpu = getCPU();
for (int i = 0; i < cpu.getInstructionMemory().getNumberOfInstructions(); i++) {
instruction = cpu.getInstructionMemory().getInstruction(i);
row = new TableRow(this);
row.setOnClickListener(assembledCodeRowOnClickListener);
address = new TextView(this);
address.setText(Util.formatDataAccordingToFormat(new Data(Data.DATA_SIZE, i * (Data.DATA_SIZE / 8)), cmbAssembledCodeFormat.getSelectedItemPosition()) + " ");
address.setTextAppearance(this, android.R.style.TextAppearance_Medium);
address.setTypeface(Typeface.MONOSPACE);
assembled = new TextView(this);
assembled.setText(Util.formatDataAccordingToFormat(new Data(Data.DATA_SIZE, instruction.getData().getValue()), cmbAssembledCodeFormat.getSelectedItemPosition()) + " ");
assembled.setTextAppearance(this, android.R.style.TextAppearance_Medium);
assembled.setTypeface(Typeface.MONOSPACE);
code = new TextView(this);
codeLine = instruction.getLineNumber() + ": ";
for (String label : instruction.getLabels()) codeLine += label + ": ";
codeLine += instruction.getCodeLine();
code.setText(codeLine);
code.setTextAppearance(this, android.R.style.TextAppearance_Medium);
code.setTypeface(Typeface.MONOSPACE);
row.addView(address);
row.addView(assembled);
row.addView(code);
tblAssembledCode.addView(row);
}
refreshAssembledCodeTableValues();
}
use of brunonova.drmips.simulator.CPU in project drmips by brunonova.
the class DrMIPSActivity method refreshDataMemoryTableValues.
/**
* Refreshes the values of the registers table.
*/
public void refreshDataMemoryTableValues() {
CPU cpu = getCPU();
if (cpu.hasDataMemory()) {
TextView address, value;
TableRow row;
for (int i = 0; i < cpu.getDataMemory().getMemorySize(); i++) {
row = (TableRow) tblDataMemory.getChildAt(i + 1);
address = (TextView) row.getChildAt(0);
value = (TextView) row.getChildAt(1);
address.setText(Util.formatDataAccordingToFormat(new Data(Data.DATA_SIZE, i * (Data.DATA_SIZE / 8)), cmbDataMemoryFormat.getSelectedItemPosition()) + " ");
value.setText(Util.formatDataAccordingToFormat(new Data(Data.DATA_SIZE, cpu.getDataMemory().getDataInIndex(i)), cmbDataMemoryFormat.getSelectedItemPosition()));
// Highlight memory positions being accessed
int index = cpu.getDataMemory().getAddress().getValue() / (Data.DATA_SIZE / 8);
boolean read = cpu.getDataMemory().getMemRead().getValue() == 1;
boolean write = cpu.getDataMemory().getMemWrite().getValue() == 1;
if (write && i == index) {
if (read)
row.setBackgroundColor(Util.getThemeColor(this, R.attr.rwColor));
else
row.setBackgroundColor(Util.getThemeColor(this, R.attr.writeColor));
} else if (read && i == index)
row.setBackgroundColor(Util.getThemeColor(this, R.attr.readColor));
else
// remove background color
row.setBackgroundResource(0);
}
tblDataMemory.requestLayout();
}
}
Aggregations