Search in sources :

Example 6 with MemoryDasm

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;
        }
    }
}
Also used : MemoryDasm(sw_emulator.software.MemoryDasm)

Example 7 with MemoryDasm

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);
}
Also used : MemoryDasm(sw_emulator.software.MemoryDasm)

Example 8 with MemoryDasm

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);
}
Also used : MemoryDasm(sw_emulator.software.MemoryDasm)

Example 9 with MemoryDasm

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);
        }
    }
}
Also used : MemoryDasm(sw_emulator.software.MemoryDasm)

Example 10 with MemoryDasm

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);
        }
    }
}
Also used : MemoryDasm(sw_emulator.software.MemoryDasm)

Aggregations

MemoryDasm (sw_emulator.software.MemoryDasm)50 IOException (java.io.IOException)7 AWTException (java.awt.AWTException)6 JScrollPane (javax.swing.JScrollPane)6 JTable (javax.swing.JTable)5 BadLocationException (javax.swing.text.BadLocationException)5 Vector (java.util.Vector)4 Font (java.awt.Font)2 ActionEvent (java.awt.event.ActionEvent)2 MouseEvent (java.awt.event.MouseEvent)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 AbstractAction (javax.swing.AbstractAction)2 ActionMap (javax.swing.ActionMap)2 InputMap (javax.swing.InputMap)2 JTableHeader (javax.swing.table.JTableHeader)2 TableModel (javax.swing.table.TableModel)2 Rectangle (java.awt.Rectangle)1 Robot (java.awt.Robot)1 Clipboard (java.awt.datatransfer.Clipboard)1