Add disassembled instructions to breakpoints
This commit is contained in:
1 parent
6b5976be8f
commit
634ea933f1
12 files changed
+460
-410
No files matched your search
@@ -23,7 +23,8 @@
|
||||
|
||||
package com.loomcom.symon.ui;
|
||||
|
||||
import com.loomcom.symon.util.HexUtil;
|
||||
import com.loomcom.symon.Breakpoints;
|
||||
import com.loomcom.symon.util.Utils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -31,8 +32,6 @@ import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.SortedSet;
|
||||
|
||||
/**
|
||||
* Simple window to enter breakpoints.
|
||||
@@ -45,45 +44,9 @@ public class BreakpointsWindow extends JFrame {
|
||||
private static final String EMPTY_STRING = "";
|
||||
|
||||
private JFrame mainWindow;
|
||||
private SortedSet<Integer> breakpoints;
|
||||
private Breakpoints breakpoints;
|
||||
|
||||
/**
|
||||
* Simple ListModel to back the list of breakpoints.
|
||||
*/
|
||||
private class BreakpointsListModel extends AbstractListModel<String> {
|
||||
private SortedSet<Integer> breakpoints;
|
||||
|
||||
public BreakpointsListModel(SortedSet<Integer> breakpoints) {
|
||||
this.breakpoints = breakpoints;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return breakpoints.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementAt(int index) {
|
||||
ArrayList<Integer> values = new ArrayList<>(breakpoints);
|
||||
return "$" + HexUtil.wordToHex(values.get(index));
|
||||
}
|
||||
|
||||
public void addElement(Integer breakpoint) {
|
||||
breakpoints.add(breakpoint);
|
||||
ArrayList<Integer> values = new ArrayList<>(breakpoints);
|
||||
int index = values.indexOf(breakpoint);
|
||||
fireIntervalAdded(this, index, index);
|
||||
}
|
||||
|
||||
public void removeElement(int index) {
|
||||
ArrayList<Integer> values = new ArrayList<>(breakpoints);
|
||||
Integer breakpoint = values.get(index);
|
||||
breakpoints.remove(breakpoint);
|
||||
fireIntervalRemoved(this, index, index);
|
||||
}
|
||||
}
|
||||
|
||||
public BreakpointsWindow(SortedSet<Integer> breakpoints,
|
||||
public BreakpointsWindow(Breakpoints breakpoints,
|
||||
JFrame mainWindow) {
|
||||
this.breakpoints = breakpoints;
|
||||
this.mainWindow = mainWindow;
|
||||
@@ -103,30 +66,26 @@ public class BreakpointsWindow extends JFrame {
|
||||
JButton removeButton = new JButton("Del");
|
||||
removeButton.setEnabled(false);
|
||||
|
||||
JTextField addTextField = new JTextField(5);
|
||||
JTextField addTextField = new JTextField(4);
|
||||
|
||||
BreakpointsListModel listModel = new BreakpointsListModel(breakpoints);
|
||||
JList<String> breakpointsList = new JList<>(listModel);
|
||||
breakpointsList.setFont(new Font("Monospace", Font.PLAIN, 14));
|
||||
breakpointsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
JTable breakpointsTable = new JTable(breakpoints);
|
||||
breakpointsTable.setShowGrid(true);
|
||||
breakpointsTable.setGridColor(Color.LIGHT_GRAY);
|
||||
breakpointsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
breakpointsTable.getSelectionModel().addListSelectionListener(e -> {
|
||||
if (e.getFirstIndex() > -1) {
|
||||
removeButton.setEnabled(true);
|
||||
} else {
|
||||
removeButton.setEnabled(false);
|
||||
}
|
||||
});
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane(breakpointsList);
|
||||
JScrollPane scrollPane = new JScrollPane(breakpointsTable);
|
||||
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
|
||||
breakpointsPanel.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
|
||||
breakpointsList.addListSelectionListener(le -> {
|
||||
int idx = breakpointsList.getSelectedIndex();
|
||||
|
||||
if (idx == -1) {
|
||||
removeButton.setEnabled(false);
|
||||
} else {
|
||||
removeButton.setEnabled(true);
|
||||
}
|
||||
});
|
||||
|
||||
ActionListener addBreakpointListener = e -> {
|
||||
int value = -1;
|
||||
|
||||
@@ -147,9 +106,9 @@ public class BreakpointsWindow extends JFrame {
|
||||
return;
|
||||
}
|
||||
|
||||
listModel.addElement(value);
|
||||
breakpoints.addBreakpoint(value);
|
||||
|
||||
logger.debug("Added breakpoint ${}", HexUtil.wordToHex(value));
|
||||
logger.debug("Added breakpoint ${}", Utils.wordToHex(value));
|
||||
|
||||
addTextField.setText(EMPTY_STRING);
|
||||
};
|
||||
@@ -157,7 +116,7 @@ public class BreakpointsWindow extends JFrame {
|
||||
addButton.addActionListener(addBreakpointListener);
|
||||
addTextField.addActionListener(addBreakpointListener);
|
||||
|
||||
removeButton.addActionListener(e -> listModel.removeElement(breakpointsList.getSelectedIndex()));
|
||||
removeButton.addActionListener(e -> breakpoints.removeBreakpointAtIndex(breakpointsTable.getSelectedRow()));
|
||||
|
||||
controlPanel.add(addTextField);
|
||||
controlPanel.add(addButton);
|
||||
|
||||
@@ -25,7 +25,7 @@ package com.loomcom.symon.ui;
|
||||
|
||||
import com.loomcom.symon.Bus;
|
||||
import com.loomcom.symon.exceptions.MemoryAccessException;
|
||||
import com.loomcom.symon.util.HexUtil;
|
||||
import com.loomcom.symon.util.Utils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -107,7 +107,7 @@ public class MemoryWindow extends JFrame implements ActionListener {
|
||||
|
||||
previousPageButton.setEnabled(pageNumber > 0x00);
|
||||
nextPageButton.setEnabled(pageNumber < 0xff);
|
||||
pageNumberTextField.setText(HexUtil.byteToHex(pageNumber));
|
||||
pageNumberTextField.setText(Utils.byteToHex(pageNumber));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -328,13 +328,13 @@ public class MemoryWindow extends JFrame implements ActionListener {
|
||||
public Object getValueAt(int row, int column) {
|
||||
try {
|
||||
if (column == 0) {
|
||||
return HexUtil.wordToHex(fullAddress(row, 1));
|
||||
return Utils.wordToHex(fullAddress(row, 1));
|
||||
} else if (column < 9) {
|
||||
// Display hex value of the data
|
||||
return HexUtil.byteToHex(bus.read(fullAddress(row, column)));
|
||||
return Utils.byteToHex(bus.read(fullAddress(row, column)));
|
||||
} else {
|
||||
// Display the ASCII equivalent (if printable)
|
||||
return HexUtil.byteToAscii(bus.read(fullAddress(row, column - 8)));
|
||||
return Utils.byteToAscii(bus.read(fullAddress(row, column - 8)));
|
||||
}
|
||||
} catch (MemoryAccessException ex) {
|
||||
return "??";
|
||||
|
||||
@@ -24,14 +24,13 @@
|
||||
package com.loomcom.symon.ui;
|
||||
|
||||
import com.loomcom.symon.Cpu;
|
||||
import com.loomcom.symon.CpuState;
|
||||
import com.loomcom.symon.machines.Machine;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.EtchedBorder;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* UI component that displays the current state of the simulated CPU.
|
||||
@@ -277,7 +276,7 @@ public class StatusPanel extends JPanel {
|
||||
*/
|
||||
public void updateState() {
|
||||
Cpu cpu = machine.getCpu();
|
||||
Cpu.CpuState cpuState = cpu.getCpuState();
|
||||
CpuState cpuState = cpu.getCpuState();
|
||||
|
||||
// Update the Processor Status Flag display
|
||||
int status = cpuState.getStatusFlag();
|
||||
@@ -293,7 +292,7 @@ public class StatusPanel extends JPanel {
|
||||
// Update the register and address displays
|
||||
|
||||
// We always want to show the NEXT instruction that will be executed
|
||||
opcodeField.setText(cpu.getCpuState().disassembleNextOp());
|
||||
opcodeField.setText(cpu.disassembleNextOp());
|
||||
pcField.setText(cpu.getProgramCounterStatus());
|
||||
spField.setText(cpu.getStackPointerStatus());
|
||||
aField.setText(cpu.getAccumulatorStatus());
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
package com.loomcom.symon.ui;
|
||||
|
||||
import com.loomcom.symon.Cpu;
|
||||
import com.loomcom.symon.CpuState;
|
||||
import com.loomcom.symon.util.FifoRingBuffer;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -36,7 +36,7 @@ import java.awt.*;
|
||||
*/
|
||||
public class TraceLog extends JFrame {
|
||||
|
||||
private final FifoRingBuffer<Cpu.CpuState> traceLog;
|
||||
private final FifoRingBuffer<CpuState> traceLog;
|
||||
private final JTextArea traceLogTextArea;
|
||||
|
||||
private static final Dimension MIN_SIZE = new Dimension(320, 200);
|
||||
@@ -71,7 +71,7 @@ public class TraceLog extends JFrame {
|
||||
StringBuilder logString = new StringBuilder();
|
||||
|
||||
synchronized(traceLog) {
|
||||
for (Cpu.CpuState state : traceLog) {
|
||||
for (CpuState state : traceLog) {
|
||||
logString.append(state.toTraceEvent());
|
||||
}
|
||||
}
|
||||
@@ -99,9 +99,9 @@ public class TraceLog extends JFrame {
|
||||
*
|
||||
* @param state The CPU State to append.
|
||||
*/
|
||||
public void append(Cpu.CpuState state) {
|
||||
public void append(CpuState state) {
|
||||
synchronized(traceLog) {
|
||||
traceLog.push(new Cpu.CpuState(state));
|
||||
traceLog.push(new CpuState(state));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user