Implement UI for the VIA/PIA
This commit is contained in:
2 files changed
+51
-10
No files matched your search
@@ -25,6 +25,7 @@ package com.loomcom.symon.devices;
|
||||
|
||||
import com.loomcom.symon.exceptions.MemoryAccessException;
|
||||
import com.loomcom.symon.exceptions.MemoryRangeException;
|
||||
import com.loomcom.symon.util.Utils;
|
||||
|
||||
/**
|
||||
* Skeleton for future implementation of a MOS 6522 VIA.
|
||||
@@ -56,6 +57,8 @@ public class Via6522 extends Pia {
|
||||
|
||||
public Via6522(int address) throws MemoryRangeException {
|
||||
super(address, address + VIA_SIZE - 1, "MOS 6522 VIA");
|
||||
outputRegisterA = outputRegisterB = 0;
|
||||
dataDirectionA = dataDirectionB = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,11 +76,11 @@ public class Via6522 extends Pia {
|
||||
@Override
|
||||
public int read(int address, boolean cpuAccess) throws MemoryAccessException {
|
||||
return switch (address) {
|
||||
case IOB_REG -> pbRead(cpuAccess);
|
||||
case IOA_REG -> paRead(cpuAccess);
|
||||
case IOB_REG -> pbRead();
|
||||
case IOA_REG -> paRead();
|
||||
case DDRB_REG -> dataDirectionB;
|
||||
case DDRA_REG -> dataDirectionA;
|
||||
case IOANH_REG -> paRead(cpuAccess);
|
||||
case IOANH_REG -> paRead();
|
||||
default -> throw new MemoryAccessException("No Register or Not Implemented!");
|
||||
};
|
||||
}
|
||||
@@ -90,20 +93,21 @@ public class Via6522 extends Pia {
|
||||
inputRegisterA = data & 0xFF;
|
||||
}
|
||||
|
||||
public int getOutputRegisterB() {
|
||||
return outputRegisterB;
|
||||
|
||||
public String getPBStatus() {
|
||||
return "%" + Utils.byteToBin(pbRead());
|
||||
}
|
||||
|
||||
public int getOutputRegisterA() {
|
||||
return outputRegisterA;
|
||||
public String getPAStatus() {
|
||||
return "%" + Utils.byteToBin(paRead());
|
||||
}
|
||||
|
||||
private int pbRead(boolean cpuAccess) {
|
||||
private int pbRead() {
|
||||
// Return bits of output register where DDRB is 1 and input register where DDRB is 0
|
||||
return (outputRegisterB & dataDirectionB) | (inputRegisterB & ~dataDirectionB);
|
||||
}
|
||||
|
||||
private int paRead(boolean cpuAccess) {
|
||||
private int paRead() {
|
||||
// Return bits of output register where DDRB is 1 and input register where DDRB is 0
|
||||
return (outputRegisterA & dataDirectionA) | (inputRegisterA & ~dataDirectionA);
|
||||
}
|
||||
|
||||
@@ -26,12 +26,13 @@ package com.loomcom.symon.ui;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
import com.loomcom.symon.Cpu;
|
||||
import com.loomcom.symon.CpuState;
|
||||
import com.loomcom.symon.devices.Pia;
|
||||
import com.loomcom.symon.devices.Via6522;
|
||||
import com.loomcom.symon.machines.Machine;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.EtchedBorder;
|
||||
import javax.swing.plaf.metal.MetalTextFieldUI;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
@@ -71,6 +72,8 @@ public class StatusPanel extends JPanel {
|
||||
private JTextField aField;
|
||||
private JTextField xField;
|
||||
private JTextField yField;
|
||||
private JTextField piaBField;
|
||||
private JTextField piaAField;
|
||||
|
||||
private final Machine machine;
|
||||
|
||||
@@ -153,6 +156,10 @@ public class StatusPanel extends JPanel {
|
||||
JLabel xLabel = makeLabel("X");
|
||||
JLabel yLabel = makeLabel("Y");
|
||||
|
||||
// PIA/VIA labels
|
||||
JLabel piaBLabel = makeLabel("PB");
|
||||
JLabel piaALabel = makeLabel("PA");
|
||||
|
||||
statusFlagsLabel.setToolTipText("6502 Processor Status Flags");
|
||||
opcodeLabel.setToolTipText("Instruction Register");
|
||||
pcLabel.setToolTipText("Program Counter");
|
||||
@@ -165,6 +172,9 @@ public class StatusPanel extends JPanel {
|
||||
xField = makeTextField(SMALL_TEXT_FIELD_SIZE, true);
|
||||
yField = makeTextField(SMALL_TEXT_FIELD_SIZE, true);
|
||||
|
||||
piaBField = makeTextField(LARGE_TEXT_FIELD_SIZE, false);
|
||||
piaAField = makeTextField(LARGE_TEXT_FIELD_SIZE, false);
|
||||
|
||||
// Make fields editable
|
||||
pcField.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
@@ -287,6 +297,25 @@ public class StatusPanel extends JPanel {
|
||||
add(xField, constraints);
|
||||
constraints.gridx = 1;
|
||||
add(yField, constraints);
|
||||
|
||||
constraints.insets = new Insets(5, 0, 0, 0);
|
||||
constraints.gridx = 0;
|
||||
constraints.gridwidth = 2;
|
||||
constraints.gridy = 10;
|
||||
add(piaBLabel, constraints);
|
||||
|
||||
constraints.insets = new Insets(2, 2, 2, 2);
|
||||
constraints.gridy = 11;
|
||||
add(piaBField, constraints);
|
||||
|
||||
constraints.insets = new Insets(5, 0, 0, 0);
|
||||
constraints.gridy = 12;
|
||||
add(piaALabel, constraints);
|
||||
|
||||
constraints.insets = new Insets(2, 2, 2, 2);
|
||||
constraints.gridy = 13;
|
||||
add(piaAField, constraints);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -296,6 +325,8 @@ public class StatusPanel extends JPanel {
|
||||
Cpu cpu = machine.getCpu();
|
||||
CpuState cpuState = cpu.getCpuState();
|
||||
|
||||
Pia pia = machine.getPia();
|
||||
|
||||
// Update the Processor Status Flag display
|
||||
int status = cpuState.getStatusFlag();
|
||||
|
||||
@@ -317,6 +348,12 @@ public class StatusPanel extends JPanel {
|
||||
xField.setText(cpu.getXRegisterStatus());
|
||||
yField.setText(cpu.getYRegisterStatus());
|
||||
|
||||
// Update the Pia Variables
|
||||
if (pia instanceof Via6522) {
|
||||
piaBField.setText(((Via6522) pia).getPBStatus());
|
||||
piaAField.setText(((Via6522) pia).getPAStatus());
|
||||
}
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user