use of sw_emulator.software.MemoryDasm in project jc64 by ice00.
the class JDisassemblerFrame method disassembly.
/**
* Disassembly the memory
*
* @param storeUndo true if we store for the undo the compiled project
*/
private void disassembly(boolean storeUndo) {
if (project == null) {
disassembly.source = "";
disassembly.disassembly = "";
} else {
disassembly.dissassembly(project.fileType, project.inB, option, project.memory, project.constant, project.mpr, project.relocates, project.patches, project.chip, project.targetType, false);
disassembly.dissassembly(project.fileType, project.inB, option, project.memory, project.constant, project.mpr, project.relocates, project.patches, project.chip, project.targetType, true);
}
int lineS = 0;
int lineD = 0;
try {
lineS = rSyntaxTextAreaSource.getLineOfOffset(rSyntaxTextAreaSource.getCaretPosition());
lineD = rSyntaxTextAreaDis.getLineOfOffset(rSyntaxTextAreaDis.getCaretPosition());
} catch (BadLocationException ex) {
System.err.println(ex);
}
rSyntaxTextAreaSource.setText(disassembly.source);
try {
rSyntaxTextAreaSource.setCaretPosition(rSyntaxTextAreaSource.getDocument().getDefaultRootElement().getElement(lineS).getStartOffset());
rSyntaxTextAreaSource.requestFocusInWindow();
} catch (Exception ex) {
System.err.println(ex);
}
rSyntaxTextAreaDis.setText(disassembly.disassembly);
try {
rSyntaxTextAreaDis.setCaretPosition(rSyntaxTextAreaDis.getDocument().getDefaultRootElement().getElement(lineD).getStartOffset());
rSyntaxTextAreaDis.requestFocusInWindow();
} catch (Exception ex) {
System.err.println(ex);
}
memoryTableCellRenderer.setDisassembly(disassembly);
// repositionate in memory if option is on
if (option.repositionate)
gotoMem(0);
DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
if (storeUndo)
undo.store(df.format(new Date()), project);
// update perc based onto the work done by renaming the labels
int total = 0;
int done = 0;
for (MemoryDasm mem : project.memory) {
if (!mem.isInside || mem.isGarbage)
continue;
// look for relative locations
if (mem.type == '+' || mem.type == '-') {
MemoryDasm memr = project.memory[mem.related];
if (mem.userLocation != null && !"".equals(mem.userLocation)) {
total++;
done++;
}
continue;
}
// look for locations
if (mem.userLocation != null && !"".equals(mem.userLocation)) {
total++;
done++;
} else {
if (mem.dasmLocation != null && !"".equals(mem.dasmLocation)) {
total++;
}
}
}
if (total != 0)
jPanelPerc.setPerc((float) done / (float) total);
else
jPanelPerc.setPerc(0);
}
use of sw_emulator.software.MemoryDasm in project jc64 by ice00.
the class JDisassemblerFrame method memHighLow.
/**
* Assign two references to memory as #> and #<
*/
private void memHighLow() {
int row = jTableMemory.getSelectedRow();
if (row < 0) {
JOptionPane.showMessageDialog(this, "No row selected", "Warning", JOptionPane.WARNING_MESSAGE);
return;
}
int[] rows = jTableMemory.getSelectedRows();
if (rows.length == 1) {
JOptionPane.showMessageDialog(this, "Two rows must be selected", "Warning", JOptionPane.WARNING_MESSAGE);
return;
}
MemoryDasm low, high;
int address;
for (int i = 0; i < rows.length; i += 2) {
if (i == rows.length - 1)
break;
low = project.memory[rows[i + 1]];
high = project.memory[rows[i]];
address = (low.copy & 0xFF) + ((high.copy & 0xFF) << 8);
low.related = address;
low.type = '<';
high.related = address;
if (high.type == '+')
high.type = '^';
else
high.type = '>';
}
dataTableModelMemory.fireTableDataChanged();
jTableMemory.setRowSelectionInterval(rows[0], rows[rows.length - 1]);
}
use of sw_emulator.software.MemoryDasm in project jc64 by ice00.
the class JDisassemblerFrame method searchAddress.
/**
* Search for a memory address (even as label) from the initial passed string
*
* @param initial the initial buffer to search for
* @return the address or -1 if not find
*/
protected int searchAddress(String initial) {
int addr = -1;
try {
// get the first word of the string
String str = initial;
str = str.contains(" ") ? str.split(" ")[0] : str;
if (str.length() == 4)
addr = Integer.decode("0x" + str);
else {
str = str.contains(":") ? str.split(":")[0] : str;
for (MemoryDasm memory : project.memory) {
if (str.equals(memory.dasmLocation) || str.equals(memory.userLocation)) {
addr = memory.address;
break;
}
}
}
} catch (Exception e) {
System.err.println(e);
}
return addr;
}
use of sw_emulator.software.MemoryDasm in project jc64 by ice00.
the class JWizardDialog method apply.
/**
* Apply the selected table to relative relation in memory
*
* @param prefix prefix for label
* @param digit digit to use
* @param uppercase uppercase digit
* @param start the starting digit
* @param rowLow row low position
* @param rowHigh roh high position
* @param size size to use for table
*/
private void apply(String prefix, int digit, boolean uppercase, int start, int rowLow, int rowHigh, int size) {
if (hasError(rowLow, rowHigh, size))
return;
int address;
MemoryDasm mem;
String label;
for (int i = 0; i < size; i++) {
address = (memory[rowLow + i].copy & 0xFF) + (memory[rowHigh + i].copy & 0xFF) * 256;
mem = memory[address];
memory[rowLow + i].related = address;
memory[rowLow + i].type = '<';
memory[rowHigh + i].related = address;
memory[rowHigh + i].type = '>';
if (prefix != null && !"".equals(prefix)) {
label = Integer.toHexString(i + start);
if (label.length() == 1 && digit == 2)
label = "0" + label;
if (uppercase)
label = label.toUpperCase();
else
label = label.toLowerCase();
label = prefix + label;
memory[address].userLocation = label;
}
}
if (option.pedantic)
JOptionPane.showMessageDialog(this, "Table relation applied into memory");
jTableLow.getSelectionModel().removeSelectionInterval(rowLow, rowLow);
jTableHigh.getSelectionModel().removeSelectionInterval(rowHigh, rowHigh);
popolate(-1, -1);
}
use of sw_emulator.software.MemoryDasm in project jc64 by ice00.
the class JWizardDialog method simulate.
/**
* Simulate label creation
*
* @param prefix prefix for label
* @param digit digit to use
* @param uppercase uppercase digit
* @param start the starting digit
* @param rowLow low row position
* @param rowHigh high row position
* @param size the size of table
*/
private void simulate(String prefix, int digit, boolean uppercase, int start, int rowLow, int rowHigh, int size) {
int address;
MemoryDasm mem;
String label;
if (prefix == null || "".equals(prefix)) {
for (int i = 0; i < size; i++) {
address = (memory[rowLow + i].copy & 0xFF) + (memory[rowHigh + i].copy & 0xFF) * 256;
memory[rowLow + i].related = address;
memory[rowLow + i].type = '<';
memory[rowHigh + i].related = address;
memory[rowHigh + i].type = '>';
}
return;
}
TableModel model = jTable.getModel();
int row = -1;
for (int i = 0; i < size; i++) {
if (i % 8 == 0)
row++;
address = (memory[rowLow + i].copy & 0xFF) + (memory[rowHigh + i].copy & 0xFF) * 256;
mem = memory[address];
if (prefix != null && !"".equals(prefix)) {
label = Integer.toHexString(i + start);
if (label.length() == 1 && digit == 2)
label = "0" + label;
if (uppercase)
label = label.toUpperCase();
else
label = label.toLowerCase();
label = prefix + label;
if (label.contains(" ")) {
JOptionPane.showMessageDialog(this, "Label must not contain spaces", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (label.length() > option.maxLabelLength) {
JOptionPane.showMessageDialog(this, "Label too long. Max allowed=" + option.maxLabelLength, "Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (label.length() < 2) {
JOptionPane.showMessageDialog(this, "Label too short. Min allowed=2", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
// see if the label is already defined
for (MemoryDasm memory : project.memory) {
if (label.equals(memory.dasmLocation) || label.equals(memory.userLocation)) {
JOptionPane.showMessageDialog(this, "This label is already used into the source", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
}
// see if label is as constant
for (int ii = 0; ii < Constant.COLS; ii++) {
for (int j = 0; j < Constant.ROWS; j++) {
if (label.equals(project.constant.table[ii][j])) {
JOptionPane.showMessageDialog(this, "This label is already used as constant", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
}
}
String tmp = label.toUpperCase();
for (String val : M6510Dasm.mnemonics) {
if (tmp.equals(val)) {
JOptionPane.showMessageDialog(this, "This label is an opcode, cannot be defined", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
}
if (label.startsWith("W") && label.length() == 5) {
JOptionPane.showMessageDialog(this, "Label cannot be like Wxxxx as they are reserverd", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
} else {
if (mem.userLocation != null && !"".equals(mem.userLocation))
label = mem.userLocation;
else if (mem.dasmLocation != null && !"".equals(mem.dasmLocation))
label = mem.dasmLocation;
else
label = "$" + Shared.ShortToExe((int) address);
}
model.setValueAt(label, row, i % 8);
}
}
Aggregations