From 742e3a1027814d7c975e701a71649dc5eb4f5805 Mon Sep 17 00:00:00 2001 From: Seth Morabito Date: Tue, 12 Aug 2014 15:06:08 -0700 Subject: [PATCH] Split PIA into PIA/VIA6522 --- .../java/com/loomcom/symon/devices/Pia.java | 38 ++------ .../com/loomcom/symon/devices/Via6522.java | 90 +++++++++++++++++++ .../loomcom/symon/machines/SymonMachine.java | 8 +- 3 files changed, 98 insertions(+), 38 deletions(-) create mode 100644 src/main/java/com/loomcom/symon/devices/Via6522.java diff --git a/src/main/java/com/loomcom/symon/devices/Pia.java b/src/main/java/com/loomcom/symon/devices/Pia.java index 6660932..3777482 100644 --- a/src/main/java/com/loomcom/symon/devices/Pia.java +++ b/src/main/java/com/loomcom/symon/devices/Pia.java @@ -23,45 +23,19 @@ package com.loomcom.symon.devices; -import com.loomcom.symon.exceptions.MemoryAccessException; import com.loomcom.symon.exceptions.MemoryRangeException; -public class Pia extends Device { - public static final int PIA_SIZE = 16; +public abstract class Pia extends Device { - private static final int ORB = 0; - private static final int ORA = 1; - private static final int DDRB = 2; - private static final int DDRA = 3; - private static final int T1C_L = 4; - private static final int T1C_H = 5; - private static final int T1L_L = 6; - private static final int T1L_H = 7; - private static final int T2C_L = 8; - private static final int T2C_H = 9; - private static final int SR = 10; - private static final int ACR = 11; - private static final int PCR = 12; - private static final int IFR = 13; - private static final int IER = 14; - private static final int ORA_H = 15; + private final String name; - public Pia(int address) throws MemoryRangeException { - super(address, address + PIA_SIZE - 1, "PIA"); - } - - @Override - public void write(int address, int data) throws MemoryAccessException { - ; // No-Op - } - - @Override - public int read(int address) throws MemoryAccessException { - return 0; + public Pia(int startAddress, int endAddress, String name) throws MemoryRangeException { + super(startAddress, endAddress, name); + this.name = name; } @Override public String toString() { - return null; + return name; } } diff --git a/src/main/java/com/loomcom/symon/devices/Via6522.java b/src/main/java/com/loomcom/symon/devices/Via6522.java new file mode 100644 index 0000000..bbd12ca --- /dev/null +++ b/src/main/java/com/loomcom/symon/devices/Via6522.java @@ -0,0 +1,90 @@ +package com.loomcom.symon.devices; + +import com.loomcom.symon.exceptions.MemoryAccessException; +import com.loomcom.symon.exceptions.MemoryRangeException; + +/** + * Very basic implementation of a MOS 6522 VIA. + * + * TODO: Implement timers as threads. + */ +public class Via6522 extends Pia { + public static final int VIA_SIZE = 16; + + enum Register { + ORB, ORA, DDRB, DDRA, T1C_L, T1C_H, T1L_L, T1L_H, + T2C_L, T2C_H, SR, ACR, PCR, IFR, IER, ORA_H + } + + // Ports A and B + private char[] portData = {0, 0}; + private char[] portDirections = {0, 0}; + + public Via6522(int address) throws MemoryRangeException { + super(address, address + VIA_SIZE - 1, "MOS 6522 VIA"); + } + + @Override + public void write(int address, int data) throws MemoryAccessException { + Register[] registers = Register.values(); + + if (address >= registers.length) { + throw new MemoryAccessException("Unknown register: " + address); + } + + Register r = registers[address]; + + switch (r) { + case ORA: + case ORB: + case DDRA: + case DDRB: + case T1C_L: + case T1C_H: + case T1L_L: + case T1L_H: + case T2C_L: + case T2C_H: + case SR: + case ACR: + case PCR: + case IFR: + case IER: + case ORA_H: + default: + } + } + + @Override + public int read(int address) throws MemoryAccessException { + Register[] registers = Register.values(); + + if (address >= registers.length) { + throw new MemoryAccessException("Unknown register: " + address); + } + + Register r = registers[address]; + + switch (r) { + case ORA: + case ORB: + case DDRA: + case DDRB: + case T1C_L: + case T1C_H: + case T1L_L: + case T1L_H: + case T2C_L: + case T2C_H: + case SR: + case ACR: + case PCR: + case IFR: + case IER: + case ORA_H: + default: + } + + return 0; + } +} diff --git a/src/main/java/com/loomcom/symon/machines/SymonMachine.java b/src/main/java/com/loomcom/symon/machines/SymonMachine.java index 09668f6..f63ce9d 100644 --- a/src/main/java/com/loomcom/symon/machines/SymonMachine.java +++ b/src/main/java/com/loomcom/symon/machines/SymonMachine.java @@ -26,11 +26,7 @@ package com.loomcom.symon.machines; import com.loomcom.symon.Bus; import com.loomcom.symon.Cpu; -import com.loomcom.symon.devices.Acia; -import com.loomcom.symon.devices.Acia6551; -import com.loomcom.symon.devices.Crtc; -import com.loomcom.symon.devices.Memory; -import com.loomcom.symon.devices.Pia; +import com.loomcom.symon.devices.*; import com.loomcom.symon.exceptions.MemoryRangeException; import java.io.File; import java.util.logging.Logger; @@ -78,7 +74,7 @@ public class SymonMachine implements Machine { this.bus = new Bus(BUS_BOTTOM, BUS_TOP); this.cpu = new Cpu(); this.ram = new Memory(MEMORY_BASE, MEMORY_BASE + MEMORY_SIZE - 1, false); - this.pia = new Pia(PIA_BASE); + this.pia = new Via6522(PIA_BASE); this.acia = new Acia6551(ACIA_BASE); this.crtc = new Crtc(CRTC_BASE, ram);