Search in sources :

Example 16 with MemoryDasm

use of sw_emulator.software.MemoryDasm in project jc64 by ice00.

the class JDisassemblerFrame method addBlock.

/**
 * Add a block for comment
 *
 * @param row the row to use
 */
private void addBlock(int row) {
    if (row < 0) {
        JOptionPane.showMessageDialog(this, "No row selected", "Warning", JOptionPane.WARNING_MESSAGE);
        return;
    }
    MemoryDasm mem = project.memory[row];
    JTextArea area = new JTextArea(20, 40);
    area.setText(mem.userBlockComment);
    area.setFont(new Font("monospaced", Font.PLAIN, 12));
    JScrollPane scrollPane = new JScrollPane(area);
    /*   area.addAncestorListener(new AncestorListener() {
    @Override
    public void ancestorRemoved(AncestorEvent event) {}

    @Override
    public void ancestorMoved(AncestorEvent event) {}

    @Override
    public void ancestorAdded(AncestorEvent event) {
       System.err.println(event.getComponent().requestFocusInWindow());
    }
    });*/
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            try {
                Robot robot = new Robot();
                int i = 2;
                while (i-- > 0) {
                    robot.keyPress(KeyEvent.VK_TAB);
                    robot.delay(100);
                    robot.keyRelease(KeyEvent.VK_TAB);
                }
            } catch (AWTException e) {
                System.out.println("Failed to use Robot, got exception: " + e.getMessage());
            }
        }
    });
    if (JOptionPane.showConfirmDialog(null, scrollPane, "Add a multi lines block comment", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
        mem.userBlockComment = area.getText();
        if ("".equals(mem.userBlockComment))
            mem.userBlockComment = null;
        dataTableModelMemory.fireTableDataChanged();
        jTableMemory.setRowSelectionInterval(row, row);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) JTextArea(javax.swing.JTextArea) MemoryDasm(sw_emulator.software.MemoryDasm) Robot(java.awt.Robot) Font(java.awt.Font) AWTException(java.awt.AWTException)

Example 17 with MemoryDasm

use of sw_emulator.software.MemoryDasm in project jc64 by ice00.

the class JDisassemblerFrame method memPlus.

/**
 * Mark the memory as address +
 */
private void memPlus() {
    int row = jTableMemory.getSelectedRow();
    if (row < 0) {
        JOptionPane.showMessageDialog(this, "No row selected", "Warning", JOptionPane.WARNING_MESSAGE);
        return;
    }
    Vector cols = new Vector();
    cols.add("ADDR");
    cols.add("DASM");
    cols.add("USER");
    Vector rows = new Vector();
    Vector data;
    int value = project.memory[row].copy & 0xFF;
    MemoryDasm mem = project.memory[row];
    MemoryDasm memory;
    int addr;
    for (int i = 1; i < 256; i++) {
        addr = mem.address - i;
        if (addr < 0)
            continue;
        memory = project.memory[addr];
        data = new Vector();
        data.add(Shared.ShortToExe(memory.address));
        data.add(memory.dasmLocation);
        data.add(memory.userLocation);
        rows.add(data);
    }
    JTable table = new JTable(rows, cols);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    if (JOptionPane.showConfirmDialog(null, new JScrollPane(table), "Select the address to use as + in table", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
        int rowS = table.getSelectedRow();
        if (rowS < 0) {
            if (project.memory[row].type == '+' || project.memory[row].type == '^') {
                if (JOptionPane.showConfirmDialog(this, "Did you want to delete the current address association?", "No selection were done, so:", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                    // + and < ?
                    if (project.memory[row].type == '^') {
                        project.memory[row].type = '>';
                        project.memory[row].related &= 0xFFFF;
                    } else {
                        project.memory[row].type = ' ';
                        project.memory[row].related = -1;
                    }
                    // delete an automatic label if present, otherwise in code instruction it will be recreated if label is no more used
                    project.memory[row].dasmLocation = null;
                }
            } else
                JOptionPane.showMessageDialog(this, "No row selected", "Warning", JOptionPane.WARNING_MESSAGE);
            return;
        } else {
            if (project.memory[row].type == '>') {
                project.memory[row].type = '^';
                project.memory[row].related = project.memory[row].related + (Integer.parseInt((String) table.getValueAt(rowS, 0), 16) << 16);
            } else {
                project.memory[row].type = '+';
                project.memory[row].related = Integer.parseInt((String) table.getValueAt(rowS, 0), 16);
            }
        }
        dataTableModelMemory.fireTableDataChanged();
        jTableMemory.setRowSelectionInterval(row, row);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) MemoryDasm(sw_emulator.software.MemoryDasm) JTable(javax.swing.JTable) Vector(java.util.Vector)

Example 18 with MemoryDasm

use of sw_emulator.software.MemoryDasm in project jc64 by ice00.

the class JDisassemblerFrame method gotoMem.

/**
 * Got memory from preview
 *
 * @param modifier the key modifier of mouse click
 */
private void gotoMem(int modifier) {
    try {
        // get starting position of clicked point
        int pos = Utilities.getRowStart(rSyntaxTextAreaDis, rSyntaxTextAreaDis.getCaretPosition());
        int addr = searchAddress(rSyntaxTextAreaDis.getDocument().getText(pos, option.maxLabelLength));
        if (addr == -1)
            return;
        // scroll to that point
        // /jTableMemory.scrollRectToVisible(jTableMemory.getCellRect(addr,0, true));
        Shared.scrollToCenter(jTableMemory, addr, 0);
        if ((modifier & InputEvent.SHIFT_DOWN_MASK) == InputEvent.SHIFT_DOWN_MASK) {
            int row = jTableMemory.getSelectedRow();
            if (row == -1)
                jTableMemory.setRowSelectionInterval(addr, addr);
            else {
                if (row < addr) {
                    MemoryDasm mem = project.memory[addr];
                    if (// go to end of instruction
                    mem.isCode)
                        // go to end of instruction
                        jTableMemory.setRowSelectionInterval(row, addr + M6510Dasm.tableSize[mem.copy & 0xff] - 1);
                    else
                        jTableMemory.setRowSelectionInterval(row, addr);
                } else
                    jTableMemory.setRowSelectionInterval(addr, row);
            }
        } else
            // select this row
            jTableMemory.setRowSelectionInterval(addr, addr);
    } catch (Exception e) {
        System.err.println(e);
    }
}
Also used : MemoryDasm(sw_emulator.software.MemoryDasm) BadLocationException(javax.swing.text.BadLocationException) AWTException(java.awt.AWTException) IOException(java.io.IOException)

Example 19 with MemoryDasm

use of sw_emulator.software.MemoryDasm in project jc64 by ice00.

the class JDisassemblerFrame method markAsData.

/**
 * Mark user selection as data
 *
 * @param dataType the type of date
 */
private void markAsData(DataType dataType) {
    MemoryDasm mem;
    int[] rows = jTableMemory.getSelectedRows();
    switch(dataType) {
        case ZERO_TEXT:
            if (rows.length <= 1) {
                JOptionPane.showMessageDialog(this, "Too few elements", "Warning", JOptionPane.WARNING_MESSAGE);
                break;
            }
            // we must find area that terminate with a 0
            int pos;
            boolean fount = false;
            for (pos = 1; pos < rows.length; pos++) {
                if (project.memory[rows[pos]].copy == 0) {
                    fount = true;
                    break;
                }
            }
            // look if the area is crossing a zero terminated one
            if (!fount && rows[pos - 1] < 0xFFFF && project.memory[rows[pos - 1] + 1].dataType == DataType.ZERO_TEXT) {
                pos--;
                fount = true;
            }
            if (fount) {
                int lastRow = rows[pos];
                for (int i = pos; i >= 0; i--) {
                    if (lastRow - rows[i] > 1)
                        break;
                    lastRow = rows[i];
                    setMem(project.memory[rows[i]], dataType, rows[i]);
                }
                pos++;
                while (pos > 0 && pos < rows.length) {
                    pos = searchMoreZero(rows, pos);
                }
            } else
                JOptionPane.showMessageDialog(this, "This area is not zero terminated", "Warning", JOptionPane.WARNING_MESSAGE);
            break;
        case NUM_TEXT:
            if (rows.length == 0)
                break;
            boolean over = false;
            boolean few = false;
            int num = project.memory[rows[0]].copy;
            if (num >= rows.length)
                few = true;
            if (project.memory[rows[0]].dataType == DataType.NUM_TEXT)
                over = true;
            int lastRow = rows[0];
            if (num > 0 && !few) {
                for (pos = 1; pos < num; pos++) {
                    if (project.memory[rows[pos]].dataType == DataType.NUM_TEXT) {
                        over = true;
                        break;
                    }
                    if (rows[pos] - lastRow > 1) {
                        few = true;
                        break;
                    }
                    lastRow = rows[pos];
                }
            } else
                pos = 0;
            if (over) {
                JOptionPane.showMessageDialog(this, "Overlapping area for text definition", "Warning", JOptionPane.WARNING_MESSAGE);
                break;
            }
            if (few) {
                JOptionPane.showMessageDialog(this, "Too few elements for a string of " + num + " chars", "Warning", JOptionPane.WARNING_MESSAGE);
                break;
            }
            if (pos > 0) {
                for (int i = 0; i <= pos; i++) {
                    setMem(project.memory[rows[i]], dataType, rows[i]);
                }
            }
            break;
        case HIGH_TEXT:
            if (rows.length <= 1) {
                JOptionPane.showMessageDialog(this, "Too few elements", "Warning", JOptionPane.WARNING_MESSAGE);
                break;
            }
            if ((project.memory[rows[0]].copy & 0x80) != 0) {
                JOptionPane.showMessageDialog(this, "Area can not start with high bit", "Warning", JOptionPane.WARNING_MESSAGE);
                break;
            }
            fount = false;
            for (pos = 1; pos < rows.length; pos++) {
                if ((project.memory[rows[pos]].copy & 0x80) != 0) {
                    fount = true;
                    break;
                }
            }
            // look if the area is crossing a high terminated one
            if (!fount && rows[pos - 1] < 0xFFFF && project.memory[rows[pos - 1] + 1].dataType == DataType.HIGH_TEXT) {
                pos--;
                fount = true;
            }
            if (fount) {
                lastRow = rows[pos];
                for (int i = pos; i >= 0; i--) {
                    if (lastRow - rows[i] > 1)
                        break;
                    lastRow = rows[i];
                    setMem(project.memory[rows[i]], dataType, rows[i]);
                }
            } else
                JOptionPane.showMessageDialog(this, "This area is not high bit terminated", "Warning", JOptionPane.WARNING_MESSAGE);
            break;
        case SHIFT_TEXT:
            // we must find area that are not with bit 0 at 1
            for (pos = 0; pos < rows.length; pos++) {
                if ((project.memory[rows[pos]].copy & 0x01) != 0)
                    break;
            }
            if (pos == 0) {
                JOptionPane.showMessageDialog(this, "This area start with wrong low bit", "Warning", JOptionPane.WARNING_MESSAGE);
            } else {
                lastRow = rows[pos - 1];
                for (int i = pos - 1; i >= 0; i--) {
                    if (lastRow - rows[i] > 1)
                        break;
                    lastRow = rows[i];
                    setMem(project.memory[rows[i]], dataType, rows[i]);
                }
            }
            break;
        default:
            for (int i = 0; i < rows.length; i++) {
                setMem(project.memory[rows[i]], dataType, rows[i]);
            }
            break;
    }
    dataTableModelMemory.fireTableDataChanged();
    jTableMemory.clearSelection();
    for (int i = 0; i < rows.length; i++) {
        jTableMemory.addRowSelectionInterval(rows[i], rows[i]);
    }
}
Also used : MemoryDasm(sw_emulator.software.MemoryDasm)

Example 20 with MemoryDasm

use of sw_emulator.software.MemoryDasm in project jc64 by ice00.

the class JDisassemblerFrame method memLow.

/**
 * Assign a reference to memory as #<
 */
private void memLow() {
    int row = jTableMemory.getSelectedRow();
    if (row < 0) {
        JOptionPane.showMessageDialog(this, "No row selected", "Warning", JOptionPane.WARNING_MESSAGE);
        return;
    }
    Vector cols = new Vector();
    cols.add("ADDR");
    cols.add("DASM");
    cols.add("USER");
    cols.add("REL");
    Vector rows = new Vector();
    Vector data;
    int value = project.memory[row].copy & 0xFF;
    for (MemoryDasm memory : project.memory) {
        if ((memory.address & 0xFF) == value) {
            if (!memory.isInside && memory.userLocation == null)
                continue;
            data = new Vector();
            data.add(Shared.ShortToExe(memory.address));
            data.add(memory.dasmLocation);
            data.add(memory.userLocation);
            String res = "";
            if (memory.type == '+') {
                // / this is a memory in table label
                int pos = memory.address - memory.related;
                MemoryDasm mem2 = project.memory[memory.related];
                if (mem2.userLocation != null && !"".equals(mem2.userLocation))
                    res = mem2.userLocation + "+" + pos;
                else if (mem2.dasmLocation != null && !"".equals(mem2.dasmLocation))
                    res = mem2.dasmLocation + "+" + pos;
                else
                    res = "$" + Shared.ShortToExe((int) memory.related) + "+" + pos;
            }
            if (memory.type == '^') {
                // / this is a memory in table label
                int rel = (memory.related >> 16) & 0xFFFF;
                int pos = memory.address - rel;
                MemoryDasm mem2 = project.memory[rel];
                if (mem2.userLocation != null && !"".equals(mem2.userLocation))
                    res = mem2.userLocation + "+" + pos;
                else if (mem2.dasmLocation != null && !"".equals(mem2.dasmLocation))
                    res = mem2.dasmLocation + "+" + pos;
                else
                    res = "$" + Shared.ShortToExe(rel) + "+" + pos;
            }
            if (memory.type == '-') {
                // / this is a memory in table label
                int pos = memory.address - memory.related;
                MemoryDasm mem2 = project.memory[memory.related];
                if (mem2.userLocation != null && !"".equals(mem2.userLocation))
                    res = mem2.userLocation + pos;
                else if (mem2.dasmLocation != null && !"".equals(mem2.dasmLocation))
                    res = mem2.dasmLocation + pos;
                else
                    res = "$" + Shared.ShortToExe((int) memory.related) + pos;
            }
            data.add(res);
            rows.add(data);
        }
    }
    JTable table = new JTable(rows, cols);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.getColumnModel().getColumn(0).setPreferredWidth(18);
    if (JOptionPane.showConfirmDialog(null, new JScrollPane(table), "Select the address to use as #<", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
        int rowS = table.getSelectedRow();
        if (rowS < 0) {
            if (project.memory[row].type == '>' || project.memory[row].type == '<' || project.memory[row].type == '^') {
                if (JOptionPane.showConfirmDialog(this, "Did you want to delete the current address association?", "No selection were done, so:", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                    project.memory[row].type = ' ';
                    project.memory[row].related = -1;
                }
            } else
                JOptionPane.showMessageDialog(this, "No row selected", "Warning", JOptionPane.WARNING_MESSAGE);
            return;
        } else {
            project.memory[row].related = Integer.parseInt((String) table.getValueAt(rowS, 0), 16);
            project.memory[row].type = '<';
        }
        dataTableModelMemory.fireTableDataChanged();
        jTableMemory.setRowSelectionInterval(row, row);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) MemoryDasm(sw_emulator.software.MemoryDasm) JTable(javax.swing.JTable) Vector(java.util.Vector)

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