Search in sources :

Example 46 with MemoryDasm

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

the class DataTableModelLabels method setData.

/**
 * Set the memory data to use
 *
 * @param data the memory data
 */
public void setData(MemoryDasm[] data) {
    this.data = data;
    data2.clear();
    for (MemoryDasm mem : data) {
        if ((mem.dasmLocation != null && !"".equals(mem.dasmLocation)) || (mem.userLocation != null && !"".equals(mem.userLocation)))
            data2.add(mem);
    }
}
Also used : MemoryDasm(sw_emulator.software.MemoryDasm)

Example 47 with MemoryDasm

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

the class CpuDasm method addConstants.

/**
 * Add constants to the source
 *
 * @return the constants
 */
protected String addConstants() {
    String label;
    String tmp;
    StringBuilder result = new StringBuilder();
    for (MemoryDasm mem : memory) {
        if (mem.isInside && !mem.isGarbage)
            continue;
        // for garbage inside, only if there is a user label makes it outs
        if (mem.isGarbage && mem.userLocation != null && !"".equals(mem.userLocation)) {
            // look for block comment
            if (mem.userBlockComment != null && !"".equals(mem.userBlockComment)) {
                assembler.setBlockComment(result, mem);
            }
            label = mem.userLocation;
            if (option.assembler == Assembler.Name.KICK) {
                if (mem.address <= 0xFF)
                    tmp = ".label " + label + " = $" + ByteToExe(mem.address);
                else
                    tmp = ".label " + label + " = $" + ShortToExe(mem.address);
            } else {
                if (mem.address <= 0xFF)
                    tmp = label + " = $" + ByteToExe(mem.address);
                else
                    tmp = label + " = $" + ShortToExe(mem.address);
            }
            result.append(tmp).append(getInstrCSpacesTabs(tmp.length()));
            assembler.setComment(result, mem);
            continue;
        }
        // look for block comment
        if (mem.userBlockComment != null && !"".equals(mem.userBlockComment)) {
            assembler.setBlockComment(result, mem);
        }
        // look for constant
        label = null;
        if (mem.userLocation != null && !"".equals(mem.userLocation))
            label = mem.userLocation;
        else if (mem.dasmLocation != null && !"".equals(mem.dasmLocation))
            label = mem.dasmLocation;
        if (label != null) {
            if (option.assembler == Assembler.Name.KICK) {
                if (mem.address <= 0xFF)
                    tmp = ".label " + label + " = $" + ByteToExe(mem.address);
                else
                    tmp = ".label " + label + " = $" + ShortToExe(mem.address);
            } else {
                if (mem.address <= 0xFF)
                    tmp = label + " = $" + ByteToExe(mem.address);
                else
                    tmp = label + " = $" + ShortToExe(mem.address);
            }
            result.append(tmp).append(getInstrCSpacesTabs(tmp.length()));
            assembler.setComment(result, mem);
        }
    }
    return result.append("\n").toString();
}
Also used : MemoryDasm(sw_emulator.software.MemoryDasm)

Example 48 with MemoryDasm

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

the class M6510Dasm method cdasm.

/**
 * Comment and Disassemble a region of the buffer
 *
 * @param buffer the buffer containing the code
 * @param start the start position in buffer
 * @param end the end position in buffer
 * @param pc the programn counter for start position
 * @return a string rapresentation of disassemble with comment
 */
public String cdasm(byte[] buffer, int start, int end, long pc) {
    // local temp string
    String tmp;
    // local temp string
    String tmp2;
    // memory dasm
    MemoryDasm mem;
    // memory related
    MemoryDasm memRel;
    // memory related of second kind
    MemoryDasm memRel2;
    // actual position in buffer
    int pos = start;
    // true if we are decoding an instruction
    boolean isCode = true;
    // true if we were decoding garbage
    boolean wasGarbage = false;
    result.setLength(0);
    result.append(addConstants());
    this.pos = pos;
    this.pc = pc;
    while (pos <= end | pos < start) {
        // verify also that don't circle in the buffer
        mem = memory[(int) pc];
        isCode = ((mem.isCode || (!mem.isData && option.useAsCode)) && !mem.isGarbage);
        if (isCode) {
            assembler.flush(result);
            // must put the org if we start from an garbage area
            if (wasGarbage) {
                wasGarbage = false;
                assembler.setOrg(result, (int) pc);
            }
            // add block if user declare it
            if (mem.userBlockComment != null && !"".equals(mem.userBlockComment)) {
                assembler.setBlockComment(result, mem);
            }
            // else if (mem.dasmLocation!=null && !"".equals(mem.dasmLocation)) result.append(mem.dasmLocation).append(":\n");
            if ((mem.userLocation != null && !"".equals(mem.userLocation)) || (mem.dasmLocation != null && !"".equals(mem.dasmLocation))) {
                assembler.setLabel(result, mem);
                result.append("\n");
            }
            // this is an instruction
            tmp = dasm(buffer);
            tmp2 = ShortToExe((int) pc) + "  " + ByteToExe(Unsigned.done(buffer[pos]));
            if (this.pc - pc == 2) {
                if (pos + 1 < buffer.length)
                    tmp2 += " " + ByteToExe(Unsigned.done(buffer[pos + 1]));
                else
                    tmp2 += " ??";
            }
            if (this.pc - pc == 3) {
                if (pos + 2 < buffer.length)
                    tmp2 += " " + ByteToExe(Unsigned.done(buffer[pos + 1])) + " " + ByteToExe(Unsigned.done(buffer[pos + 2]));
                else
                    tmp2 += " ?????";
            }
            for (// insert spaces
            int i = tmp2.length(); // insert spaces
            i < 17; // insert spaces
            i++) tmp2 += " ";
            tmp = tmp2 + tmp;
            tmp2 = "";
            for (// insert spaces
            int i = tmp.length(); // insert spaces
            i < 43; // insert spaces
            i++) tmp2 += " ";
            result.append(tmp).append(tmp2);
            tmp2 = dcom();
            // if there is a user comment, then use it
            if (mem.userComment != null)
                result.append(" ").append(mem.userComment).append("\n");
            else
                result.append(" ").append(tmp2).append("\n");
            // always add a carriage return after a RTS, RTI or JMP
            if (iType == M_JMP || iType == M_RTS || iType == M_RTI)
                result.append("\n");
            if (pc >= 0) {
                // rememeber this dasm automatic comment
                if (!"".equals(tmp2))
                    mem.dasmComment = tmp2;
                else
                    mem.dasmComment = null;
            }
            pos = this.pos;
            pc = this.pc;
        } else if (mem.isGarbage) {
            assembler.flush(result);
            wasGarbage = true;
            pos++;
            pc++;
            this.pos = pos;
            this.pc = pc;
        } else {
            // must put the org if we start from an garbage area
            if (wasGarbage) {
                wasGarbage = false;
                assembler.setOrg(result, (int) pc);
            }
            memRel = mem.related != -1 ? memory[mem.related & 0xFFFF] : null;
            if (memRel != null)
                memRel2 = memRel.related != -1 ? memory[memRel.related & 0xFFFF] : null;
            else
                memRel2 = null;
            assembler.putValue(result, mem, memRel, memRel2);
            pos++;
            pc++;
            this.pos = pos;
            this.pc = pc;
        }
    }
    assembler.flush(result);
    return result.toString();
}
Also used : MemoryDasm(sw_emulator.software.MemoryDasm)

Example 49 with MemoryDasm

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

the class M6510Dasm method csdasm.

/**
 * Comment and Disassemble a region of the buffer as source
 *
 * @param buffer the buffer containing the code
 * @param start the start position in buffer
 * @param end the end position in buffer
 * @param pc the programn counter for start position
 * @return a string rapresentation of disasemble with comment
 */
public String csdasm(byte[] buffer, int start, int end, long pc) {
    // local temp string
    String tmp;
    // local temp string
    String tmp2;
    // memory dasm
    MemoryDasm mem;
    // memory related
    MemoryDasm memRel;
    // memory related of second kind
    MemoryDasm memRel2;
    // actual position in buffer
    int pos = start;
    // true if we are decoding an instruction
    boolean isCode = true;
    // true if we were decoding garbage
    boolean wasGarbage = false;
    result.setLength(0);
    result.append(addConstants());
    this.pos = pos;
    this.pc = pc;
    while (pos <= end | pos < start) {
        // verify also that don't circle in the buffer
        mem = memory[(int) pc];
        isCode = ((mem.isCode || (!mem.isData && option.useAsCode)) && !mem.isGarbage);
        if (isCode) {
            assembler.flush(result);
            // must put the org if we start from an garbage area
            if (wasGarbage) {
                wasGarbage = false;
                assembler.setOrg(result, (int) pc);
            }
            // add block if user declare it
            if (mem.userBlockComment != null && !"".equals(mem.userBlockComment)) {
                assembler.setBlockComment(result, mem);
            }
            if ((mem.userLocation != null && !"".equals(mem.userLocation)) || (mem.dasmLocation != null && !"".equals(mem.dasmLocation))) {
                assembler.setLabel(result, mem);
                if (option.labelOnSepLine)
                    result.append("\n");
            }
            // this is an instruction
            tmp = dasm(buffer);
            result.append(getInstrSpacesTabs(mem)).append(tmp).append(getInstrCSpacesTabs(tmp.length()));
            tmp2 = dcom();
            // if there is a user comment, then use it
            assembler.setComment(result, mem);
            // always add a carriage return after a RTS, RTI or JMP
            if (iType == M_JMP || iType == M_RTS || iType == M_RTI)
                result.append("\n");
            if (pc >= 0) {
                // rememeber this dasm automatic comment
                if (!"".equals(tmp2))
                    mem.dasmComment = tmp2;
                else
                    mem.dasmComment = null;
            }
            pos = this.pos;
            pc = this.pc;
        } else if (mem.isGarbage) {
            assembler.flush(result);
            wasGarbage = true;
            pos++;
            pc++;
            this.pos = pos;
            this.pc = pc;
        } else {
            // must put the org if we start from an garbage area
            if (wasGarbage) {
                wasGarbage = false;
                assembler.setOrg(result, (int) pc);
            }
            memRel = mem.related != -1 ? memory[mem.related & 0xFFFF] : null;
            if (memRel != null)
                memRel2 = memRel.related != -1 ? memory[memRel.related & 0xFFFF] : null;
            else
                memRel2 = null;
            assembler.putValue(result, mem, memRel, memRel2);
            pos++;
            pc++;
            this.pos = pos;
            this.pc = pc;
        }
    }
    assembler.flush(result);
    return result.toString();
}
Also used : MemoryDasm(sw_emulator.software.MemoryDasm)

Example 50 with MemoryDasm

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

the class Z80Dasm method cdasm.

/**
 * Comment and Disassemble a region of the buffer
 *
 * @param buffer the buffer containing the code
 * @param start the start position in buffer
 * @param end the end position in buffer
 * @param pc the programn counter for start position
 * @return a string rapresentation of disassemble with comment
 */
@Override
public String cdasm(byte[] buffer, int start, int end, long pc) {
    // local temp string
    String tmp;
    // local temp string
    String tmp2;
    // memory dasm
    MemoryDasm mem;
    // memory related
    MemoryDasm memRel;
    // memory related of second kind
    MemoryDasm memRel2;
    // actual position in buffer
    int pos = start;
    // true if we are decoding an instruction
    boolean isCode = true;
    // true if we were decoding garbage
    boolean wasGarbage = false;
    result.setLength(0);
    result.append(addConstants());
    this.pos = pos;
    this.pc = pc;
    while (pos <= end | pos < start) {
        // verify also that don't circle in the buffer
        mem = memory[(int) pc];
        isCode = ((mem.isCode || (!mem.isData && option.useAsCode)) && !mem.isGarbage);
        if (isCode) {
            assembler.flush(result);
            // must put the org if we start from an garbage area
            if (wasGarbage) {
                wasGarbage = false;
                assembler.setOrg(result, (int) pc);
            }
            // add block if user declare it
            if (mem.userBlockComment != null && !"".equals(mem.userBlockComment)) {
                assembler.setBlockComment(result, mem);
            }
            // else if (mem.dasmLocation!=null && !"".equals(mem.dasmLocation)) result.append(mem.dasmLocation).append(":\n");
            if ((mem.userLocation != null && !"".equals(mem.userLocation)) || (mem.dasmLocation != null && !"".equals(mem.dasmLocation))) {
                assembler.setLabel(result, mem);
                result.append("\n");
            }
            // this is an instruction
            tmp = dasm(buffer);
            tmp2 = ShortToExe((int) pc) + "  " + ByteToExe(Unsigned.done(buffer[pos]));
            if (this.pc - pc == 2) {
                if (pos + 1 < buffer.length)
                    tmp2 += " " + ByteToExe(Unsigned.done(buffer[pos + 1]));
                else
                    tmp2 += " ??";
            }
            if (this.pc - pc == 3) {
                if (pos + 2 < buffer.length)
                    tmp2 += " " + ByteToExe(Unsigned.done(buffer[pos + 1])) + " " + ByteToExe(Unsigned.done(buffer[pos + 2]));
                else
                    tmp2 += " ?????";
            }
            if (this.pc - pc == 4) {
                if (pos + 3 < buffer.length)
                    tmp2 += " " + ByteToExe(Unsigned.done(buffer[pos + 1])) + " " + ByteToExe(Unsigned.done(buffer[pos + 2])) + " " + ByteToExe(Unsigned.done(buffer[pos + 3]));
                else
                    tmp2 += " ???????";
            }
            for (// insert spaces
            int i = tmp2.length(); // insert spaces
            i < 21; // insert spaces
            i++) tmp2 += " ";
            tmp = tmp2 + tmp;
            tmp2 = "";
            for (// insert spaces
            int i = tmp.length(); // insert spaces
            i < 43; // insert spaces
            i++) tmp2 += " ";
            result.append(tmp).append(tmp2);
            tmp2 = dcom();
            // if there is a user comment, then use it
            if (mem.userComment != null)
                result.append(" ").append(mem.userComment).append("\n");
            else
                result.append(" ").append(tmp2).append("\n");
            // always add a carriage return after a RTS, RTI or JMP
            if (iType == M_RET || iType == M_RETI || iType == M_RETN)
                result.append("\n");
            if (pc >= 0) {
                // rememeber this dasm automatic comment
                if (!"".equals(tmp2))
                    mem.dasmComment = tmp2;
                else
                    mem.dasmComment = null;
            }
            pos = this.pos;
            pc = this.pc;
        } else if (mem.isGarbage) {
            assembler.flush(result);
            wasGarbage = true;
            pos++;
            pc++;
            this.pos = pos;
            this.pc = pc;
        } else {
            // must put the org if we start from an garbage area
            if (wasGarbage) {
                wasGarbage = false;
                assembler.setOrg(result, (int) pc);
            }
            memRel = mem.related != -1 ? memory[mem.related & 0xFFFF] : null;
            if (memRel != null)
                memRel2 = memRel.related != -1 ? memory[memRel.related & 0xFFFF] : null;
            else
                memRel2 = null;
            assembler.putValue(result, mem, memRel, memRel2);
            pos++;
            pc++;
            this.pos = pos;
            this.pc = pc;
        }
    }
    assembler.flush(result);
    return result.toString();
}
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