First work toward moving to a Swing UI for the simulator.
No files matched your search
@@ -0,0 +1,69 @@
|
||||
package com.loomcom.symon.ui;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
|
||||
import com.grahamedgecombe.jterminal.JTerminal;
|
||||
|
||||
/**
|
||||
* The Console is a simulated 80 column x 24 row VT-100 terminal attached to
|
||||
* the ACIA of the system. It provides basic keyboard I/O to Symon.
|
||||
*/
|
||||
|
||||
public class Console extends JTerminal implements KeyListener, MouseListener {
|
||||
|
||||
// TODO: Pass in io threads, read and write to ACIA.
|
||||
public Console() {
|
||||
super();
|
||||
addKeyListener(this);
|
||||
addMouseListener(this);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
getModel().clear();
|
||||
getModel().setCursorColumn(0);
|
||||
getModel().setCursorRow(0);
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void keyTyped(KeyEvent keyEvent) {
|
||||
keyEvent.consume();
|
||||
}
|
||||
|
||||
public void keyPressed(KeyEvent keyEvent) {
|
||||
int keyCode = keyEvent.getKeyCode();
|
||||
int modifiersMask = keyEvent.getModifiers();
|
||||
int modifiersExMask = keyEvent.getModifiersEx();
|
||||
|
||||
System.out.println("Key Pressed #" + keyEvent.getKeyCode() + " : " +
|
||||
KeyEvent.getKeyText(keyCode) + " MASK : " +
|
||||
modifiersMask + " EXT MASK : " +
|
||||
modifiersExMask
|
||||
);
|
||||
|
||||
keyEvent.consume();
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent keyEvent) {
|
||||
keyEvent.consume();
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent mouseEvent) {
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent mouseEvent) {
|
||||
requestFocus();
|
||||
mouseEvent.consume();
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent mouseEvent) {
|
||||
}
|
||||
|
||||
public void mouseEntered(MouseEvent mouseEvent) {
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent mouseEvent) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.loomcom.symon.ui;
|
||||
|
||||
import com.loomcom.symon.Cpu;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class StatusPane extends JPanel {
|
||||
|
||||
// The CPU to ask for state information.
|
||||
private final Cpu cpu;
|
||||
|
||||
private final ImageIcon carryOn;
|
||||
private final ImageIcon carryOff;
|
||||
private final ImageIcon zeroOn;
|
||||
private final ImageIcon zeroOff;
|
||||
private final ImageIcon irqOn;
|
||||
private final ImageIcon irqOff;
|
||||
private final ImageIcon decimalOn;
|
||||
private final ImageIcon decimalOff;
|
||||
private final ImageIcon breakOn;
|
||||
private final ImageIcon breakOff;
|
||||
private final ImageIcon overflowOn;
|
||||
private final ImageIcon overflowOff;
|
||||
private final ImageIcon negativeOn;
|
||||
private final ImageIcon negativeOff;
|
||||
|
||||
private final JLabel carryFlagLabel;
|
||||
private final JLabel zeroFlagLabel;
|
||||
private final JLabel irqDisableFlagLabel;
|
||||
private final JLabel decimalModeFlagLabel;
|
||||
private final JLabel breakFlagLabel;
|
||||
private final JLabel overflowFlagLabel;
|
||||
private final JLabel negativeFlagLabel;
|
||||
|
||||
private final JLabel opcodeLabel;
|
||||
private final JLabel pcLabel;
|
||||
private final JLabel aLabel;
|
||||
private final JLabel xLabel;
|
||||
private final JLabel yLabel;
|
||||
private final JLabel stepCountLabel;
|
||||
|
||||
private static final int WIDTH = 134;
|
||||
private static final int HEIGHT = 27;
|
||||
|
||||
public StatusPane(Cpu cpu) {
|
||||
super();
|
||||
|
||||
this.cpu = cpu;
|
||||
|
||||
Dimension dimensions = new Dimension(WIDTH, HEIGHT);
|
||||
|
||||
setMinimumSize(dimensions);
|
||||
setPreferredSize(dimensions);
|
||||
setMaximumSize(dimensions);
|
||||
|
||||
carryOn = new ImageIcon(this.getClass().getResource("images/C_on.png"));
|
||||
carryOff = new ImageIcon(this.getClass().getResource("images/C_off.png"));
|
||||
zeroOn = new ImageIcon(this.getClass().getResource("images/Z_on.png"));
|
||||
zeroOff = new ImageIcon(this.getClass().getResource("images/Z_off.png"));
|
||||
irqOn = new ImageIcon(this.getClass().getResource("images/I_on.png"));
|
||||
irqOff = new ImageIcon(this.getClass().getResource("images/I_off.png"));
|
||||
decimalOn = new ImageIcon(this.getClass().getResource("images/D_on.png"));
|
||||
decimalOff = new ImageIcon(this.getClass().getResource("images/D_off.png"));
|
||||
breakOn = new ImageIcon(this.getClass().getResource("images/B_on.png"));
|
||||
breakOff = new ImageIcon(this.getClass().getResource("images/B_off.png"));
|
||||
overflowOn = new ImageIcon(this.getClass().getResource("images/O_on.png"));
|
||||
overflowOff = new ImageIcon(this.getClass().getResource("images/O_off.png"));
|
||||
negativeOn = new ImageIcon(this.getClass().getResource("images/N_on.png"));
|
||||
negativeOff = new ImageIcon(this.getClass().getResource("images/N_off.png"));
|
||||
|
||||
// Initialize all to off
|
||||
carryFlagLabel = new JLabel(carryOff, JLabel.CENTER);
|
||||
zeroFlagLabel = new JLabel(zeroOff, JLabel.CENTER);
|
||||
irqDisableFlagLabel = new JLabel(irqOff, JLabel.CENTER);
|
||||
decimalModeFlagLabel = new JLabel(decimalOff, JLabel.CENTER);
|
||||
breakFlagLabel = new JLabel(breakOff, JLabel.CENTER);
|
||||
overflowFlagLabel = new JLabel(overflowOff, JLabel.CENTER);
|
||||
negativeFlagLabel = new JLabel(negativeOff, JLabel.CENTER);
|
||||
|
||||
// Create and add register and address labels
|
||||
|
||||
this.opcodeLabel = new JLabel();
|
||||
this.pcLabel = new JLabel();
|
||||
this.aLabel = new JLabel();
|
||||
this.xLabel = new JLabel();
|
||||
this.yLabel = new JLabel();
|
||||
this.stepCountLabel = new JLabel();
|
||||
|
||||
this.opcodeLabel.setMinimumSize(new Dimension(100, 20));
|
||||
this.pcLabel.setMinimumSize(new Dimension(80, 20));
|
||||
this.aLabel.setMinimumSize(new Dimension(60, 20));
|
||||
this.xLabel.setMinimumSize(new Dimension(60, 20));
|
||||
this.yLabel.setMinimumSize(new Dimension(60, 20));
|
||||
this.stepCountLabel.setMinimumSize(new Dimension(120, 20));
|
||||
|
||||
this.opcodeLabel.setPreferredSize(new Dimension(100, 20));
|
||||
this.pcLabel.setPreferredSize(new Dimension(80, 20));
|
||||
this.aLabel.setPreferredSize(new Dimension(60, 20));
|
||||
this.xLabel.setPreferredSize(new Dimension(60, 20));
|
||||
this.yLabel.setPreferredSize(new Dimension(60, 20));
|
||||
this.stepCountLabel.setPreferredSize(new Dimension(120, 20));
|
||||
|
||||
this.setLayout(new FlowLayout());
|
||||
|
||||
this.add(negativeFlagLabel);
|
||||
this.add(overflowFlagLabel);
|
||||
this.add(breakFlagLabel);
|
||||
this.add(decimalModeFlagLabel);
|
||||
this.add(irqDisableFlagLabel);
|
||||
this.add(zeroFlagLabel);
|
||||
this.add(carryFlagLabel);
|
||||
|
||||
this.add(opcodeLabel);
|
||||
this.add(pcLabel);
|
||||
this.add(aLabel);
|
||||
this.add(xLabel);
|
||||
this.add(yLabel);
|
||||
this.add(stepCountLabel);
|
||||
|
||||
updateState();
|
||||
}
|
||||
|
||||
public void updateState() {
|
||||
// Update the Processor Status Flag display
|
||||
int state = this.cpu.getProcessorStatus();
|
||||
|
||||
carryFlagLabel.setIcon(iconForFlag(state, 0));
|
||||
zeroFlagLabel.setIcon(iconForFlag(state, 1));
|
||||
irqDisableFlagLabel.setIcon(iconForFlag(state, 2));
|
||||
decimalModeFlagLabel.setIcon(iconForFlag(state, 3));
|
||||
breakFlagLabel.setIcon(iconForFlag(state, 4));
|
||||
overflowFlagLabel.setIcon(iconForFlag(state, 6));
|
||||
negativeFlagLabel.setIcon(iconForFlag(state, 7));
|
||||
|
||||
// Update the register and address displays
|
||||
opcodeLabel.setText(cpu.getOpcodeStatus());
|
||||
pcLabel.setText(cpu.getProgramCounterStatus());
|
||||
aLabel.setText(cpu.getARegisterStatus());
|
||||
xLabel.setText(cpu.getXRegisterStatus());
|
||||
yLabel.setText(cpu.getYRegisterStatus());
|
||||
stepCountLabel.setText(Long.toString(cpu.getStepCounter()));
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
private ImageIcon iconForFlag(int state, int flagIndex) {
|
||||
ImageIcon imageIcon = null;
|
||||
|
||||
if ((((state & 0xff) >> flagIndex) & 0x01) == 1) {
|
||||
switch (flagIndex) {
|
||||
case 0:
|
||||
imageIcon = carryOn;
|
||||
break;
|
||||
case 1:
|
||||
imageIcon = zeroOn;
|
||||
break;
|
||||
case 2:
|
||||
imageIcon = irqOn;
|
||||
break;
|
||||
case 3:
|
||||
imageIcon = decimalOn;
|
||||
break;
|
||||
case 4:
|
||||
imageIcon = breakOn;
|
||||
break;
|
||||
case 6:
|
||||
imageIcon = overflowOn;
|
||||
break;
|
||||
case 7:
|
||||
imageIcon = negativeOn;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (flagIndex) {
|
||||
case 0:
|
||||
imageIcon = carryOff;
|
||||
break;
|
||||
case 1:
|
||||
imageIcon = zeroOff;
|
||||
break;
|
||||
case 2:
|
||||
imageIcon = irqOff;
|
||||
break;
|
||||
case 3:
|
||||
imageIcon = decimalOff;
|
||||
break;
|
||||
case 4:
|
||||
imageIcon = breakOff;
|
||||
break;
|
||||
case 6:
|
||||
imageIcon = overflowOff;
|
||||
break;
|
||||
case 7:
|
||||
imageIcon = negativeOff;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return imageIcon;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.loomcom.symon.ui;
|
||||
|
||||
import com.loomcom.symon.MainWindow;
|
||||
|
||||
/**
|
||||
* Update the console and status display. All direct manipulation of the
|
||||
* main UI should go through this class. When not called from the Swing
|
||||
* event dispatch thread, these methods should be called using
|
||||
* SwingUtilities.invokeLater.
|
||||
*/
|
||||
public class UiUpdater {
|
||||
private final Console console;
|
||||
private final MainWindow mainWindow;
|
||||
private final StatusPane statusPane;
|
||||
|
||||
private final StringBuffer data;
|
||||
|
||||
public UiUpdater(MainWindow mainWindow) {
|
||||
this.mainWindow = mainWindow;
|
||||
this.console = mainWindow.getConsole();
|
||||
this.statusPane = mainWindow.getStatusPane();
|
||||
this.data = new StringBuffer();
|
||||
}
|
||||
|
||||
public void consoleWrite(int i) {
|
||||
data.append((char) i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback called by the simulator before exiting its run method.
|
||||
*/
|
||||
public void simulatorDidStop() {
|
||||
mainWindow.getStepButton().setEnabled(true);
|
||||
mainWindow.getLoadButton().setEnabled(true);
|
||||
mainWindow.getRunButton().setText("Run");
|
||||
updateUi();
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback called by the simulator when entering its run method.
|
||||
*/
|
||||
public void simulatorDidStart() {
|
||||
// Don't allow step while the simulator is running
|
||||
mainWindow.getStepButton().setEnabled(false);
|
||||
mainWindow.getLoadButton().setEnabled(false);
|
||||
// Toggle the state of the run button
|
||||
mainWindow.getRunButton().setText("Stop");
|
||||
updateUi();
|
||||
}
|
||||
|
||||
public void updateUi() {
|
||||
// Update the console with any text
|
||||
if (data.length() > 0) {
|
||||
console.getModel().print(data.toString());
|
||||
console.repaint();
|
||||
// Clear the buffer
|
||||
data.delete(0, data.length());
|
||||
}
|
||||
|
||||
// Update the status UI.
|
||||
statusPane.updateState();
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 191 B |
|
After Width: | Height: | Size: 191 B |
|
After Width: | Height: | Size: 196 B |
|
After Width: | Height: | Size: 196 B |
|
After Width: | Height: | Size: 192 B |
|
After Width: | Height: | Size: 192 B |
|
After Width: | Height: | Size: 183 B |
|
After Width: | Height: | Size: 183 B |
|
After Width: | Height: | Size: 198 B |
|
After Width: | Height: | Size: 198 B |
|
After Width: | Height: | Size: 192 B |
|
After Width: | Height: | Size: 192 B |
|
After Width: | Height: | Size: 198 B |
|
After Width: | Height: | Size: 198 B |