use of sw_emulator.software.MemoryDasm in project jc64 by ice00.
the class JDisassemblerFrame method refactor.
/**
* Refactor labels
*/
private void refactor() {
if (project == null) {
JOptionPane.showMessageDialog(this, "Open a project before usinmg this function");
return;
}
String oldPrefix = JOptionPane.showInputDialog(this, "Insert the prefix of labels to refactor:");
if (oldPrefix == null || "".equals(oldPrefix)) {
JOptionPane.showMessageDialog(this, "No prefix: abort operation");
return;
}
String newPrefix = JOptionPane.showInputDialog(this, "Insert the prefix of labels to have:");
if (newPrefix == null || "".equals(newPrefix)) {
JOptionPane.showMessageDialog(this, "No prefix: abort operation");
return;
}
String result;
String error;
for (MemoryDasm mem : project.memory) {
if (mem.userLocation != null && !"".equals(mem.userLocation) && mem.userLocation.startsWith(oldPrefix)) {
result = mem.userLocation.replaceFirst(oldPrefix, newPrefix);
error = errorLabel(result);
if (error != null) {
JOptionPane.showMessageDialog(this, error, "Error", JOptionPane.ERROR_MESSAGE);
return;
}
mem.userLocation = result;
}
}
}
use of sw_emulator.software.MemoryDasm in project jc64 by ice00.
the class CpuDasm method getLabel.
/**
* Get the label or memory location ($)
*
* @param addr the address of the label
* @return the label or memory location ($)
*/
protected String getLabel(long addr) {
if (addr < 0 || addr > 0xffff)
return "$????";
MemoryDasm mem = memory[(int) addr];
try {
if (mem.type == '+') {
// / this is a memory in table label
int pos = mem.address - mem.related;
MemoryDasm mem2 = memory[mem.related];
if (mem2.userLocation != null && !"".equals(mem2.userLocation))
return mem2.userLocation + "+" + pos;
if (mem2.dasmLocation != null && !"".equals(mem2.dasmLocation))
return mem2.dasmLocation + "+" + pos;
return "$" + ShortToExe((int) mem.related) + "+" + pos;
}
if (mem.type == '^') {
// / this is a memory in table label
int rel = (mem.related >> 16) & 0xFFFF;
int pos = mem.address - rel;
MemoryDasm mem2 = memory[rel];
if (mem2.userLocation != null && !"".equals(mem2.userLocation))
return mem2.userLocation + "+" + pos;
if (mem2.dasmLocation != null && !"".equals(mem2.dasmLocation))
return mem2.dasmLocation + "+" + pos;
return "$" + ShortToExe(rel) + "+" + pos;
}
if (mem.type == '-') {
// / this is a memory in table label
int pos = mem.address - mem.related;
MemoryDasm mem2 = memory[mem.related];
if (mem2.userLocation != null && !"".equals(mem2.userLocation))
return mem2.userLocation + pos;
if (mem2.dasmLocation != null && !"".equals(mem2.dasmLocation))
return mem2.dasmLocation + pos;
return "$" + ShortToExe((int) mem.related) + pos;
}
} catch (Exception e) {
return "$xxxx";
}
if (mem.userLocation != null && !"".equals(mem.userLocation))
return mem.userLocation;
if (mem.dasmLocation != null && !"".equals(mem.dasmLocation))
return mem.dasmLocation;
return "$" + ShortToExe((int) addr);
}
use of sw_emulator.software.MemoryDasm in project jc64 by ice00.
the class CpuDasm method getLabelZero.
/**
* Get the label or memory location ($) of zero page
*
* @param addr the address of the label
* @return the label or memory location ($)
*/
protected String getLabelZero(long addr) {
if (addr < 0 || addr > 0xffff)
return "$??";
MemoryDasm mem = memory[(int) addr];
if (mem.type == '+') {
// / this is a memory in table label
int pos = mem.address - mem.related;
MemoryDasm mem2 = memory[mem.related];
if (mem2.userLocation != null && !"".equals(mem2.userLocation))
return mem2.userLocation + "+" + pos;
if (mem2.dasmLocation != null && !"".equals(mem2.dasmLocation))
return mem2.dasmLocation + "+" + pos;
return "$" + ByteToExe((int) mem.related) + "+" + pos;
}
if (mem.type == '^') {
// / this is a memory in table label
int rel = mem.related >> 16;
int pos = mem.address - rel;
MemoryDasm mem2 = memory[rel];
if (mem2.userLocation != null && !"".equals(mem2.userLocation))
return mem2.userLocation + "+" + pos;
if (mem2.dasmLocation != null && !"".equals(mem2.dasmLocation))
return mem2.dasmLocation + "+" + pos;
return "$" + ByteToExe(rel) + "+" + pos;
}
if (mem.type == '-') {
// / this is a memory in table label
int pos = mem.address - mem.related;
MemoryDasm mem2 = memory[mem.related];
if (mem2.userLocation != null && !"".equals(mem2.userLocation))
return mem2.userLocation + pos;
if (mem2.dasmLocation != null && !"".equals(mem2.dasmLocation))
return mem2.dasmLocation + pos;
return "$" + ByteToExe((int) mem.related) + pos;
}
if (mem.userLocation != null && !"".equals(mem.userLocation))
return mem.userLocation;
if (mem.dasmLocation != null && !"".equals(mem.dasmLocation))
return mem.dasmLocation;
return "$" + ByteToExe((int) addr);
}
use of sw_emulator.software.MemoryDasm in project jc64 by ice00.
the class CpuDasm method setLabelPlus.
/**
* Set the label for plus relative address if this is the case
*
* @param addr tha address where to point
* @param offset the offset to add
*/
protected void setLabelPlus(long addr, int offset) {
if (addr < 0 || addr + offset > 0xffff)
return;
MemoryDasm mem = memory[(int) addr + offset];
if (mem.isInside) {
// set as relative + unless it is already set (even by user)
if (mem.dasmLocation != null && (mem.type != '+') && (mem.type != '-')) {
mem.type = '+';
mem.related = (int) addr;
setLabel(addr);
}
}
}
use of sw_emulator.software.MemoryDasm in project jc64 by ice00.
the class CpuDasm method setLabelMinus.
/**
* Set the label for minus relative address if this is the case
*
* @param addr tha address where to point
* @param offset the offset to sub
*/
protected void setLabelMinus(long addr, int offset) {
if (addr < 0 || addr + offset > 0xffff)
return;
MemoryDasm mem = memory[(int) addr - offset];
if (mem.isInside && mem.type != '+') {
if (mem.dasmLocation != null) {
mem.type = '-';
mem.related = (int) addr;
setLabel(addr);
}
}
}
Aggregations