1
0
mirror of https://github.com/sethm/symon.git synced 2024-06-01 08:41:32 +00:00

enforce that the address range of devices falls within the address range of the bus. Turned out that the CPU tests instantiate memory with the last parameter as memory size, not end address (fixed now). Also make sure that the address lookup array takes the offset caused by non-zero starting addresses into account.

This commit is contained in:
Maik Merten 2014-07-25 21:24:16 +02:00
parent d7f8045b61
commit 52f4e9a00f
16 changed files with 30 additions and 22 deletions

View File

@ -76,8 +76,7 @@ public class Bus {
}
private void buildDeviceAddressArray() {
// TODO: Find out why +2 and not +1 is needed here
int size = (this.endAddress - this.startAddress) + 2;
int size = (this.endAddress - this.startAddress) + 1;
deviceAddressArray = new Device[size];
List<Integer> priorities = new ArrayList<Integer>(deviceMap.keySet());
@ -88,7 +87,7 @@ public class Bus {
for(Device device : deviceSet) {
MemoryRange range = device.getMemoryRange();
for(int address = range.startAddress; address <= range.endAddress; ++address) {
deviceAddressArray[address] = device;
deviceAddressArray[address - this.startAddress] = device;
}
}
}
@ -101,7 +100,16 @@ public class Bus {
* @param device
* @param priority
*/
public void addDevice(Device device, int priority) {
public void addDevice(Device device, int priority) throws MemoryRangeException {
MemoryRange range = device.getMemoryRange();
if(range.startAddress() < this.startAddress || range.startAddress() > this.endAddress) {
throw new MemoryRangeException("start address of device " + device.getName() + " does not fall within the address range of the bus");
}
if(range.endAddress() < this.startAddress || range.endAddress() > this.endAddress) {
throw new MemoryRangeException("end address of device " + device.getName() + " does not fall within the address range of the bus");
}
SortedSet<Device> deviceSet = deviceMap.get(priority);
if(deviceSet == null) {
@ -152,7 +160,7 @@ public class Bus {
}
for(int address = startAddress; address <= endAddress; ++address) {
if(deviceAddressArray[address] == null) {
if(deviceAddressArray[address - startAddress] == null) {
return false;
}
}
@ -161,7 +169,7 @@ public class Bus {
}
public int read(int address) throws MemoryAccessException {
Device d = deviceAddressArray[address];
Device d = deviceAddressArray[address - this.startAddress];
if(d != null) {
MemoryRange range = d.getMemoryRange();
int devAddr = address - range.startAddress();
@ -172,7 +180,7 @@ public class Bus {
}
public void write(int address, int value) throws MemoryAccessException {
Device d = deviceAddressArray[address];
Device d = deviceAddressArray[address - this.startAddress];
if(d != null) {
MemoryRange range = d.getMemoryRange();
int devAddr = address - range.startAddress();

View File

@ -14,7 +14,7 @@ public class CpuAbsoluteModeTest extends TestCase {
protected void setUp() throws Exception {
this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000);
this.mem = new Memory(0x0000, 0xffff);
bus.addCpu(cpu);
bus.addDevice(mem);

View File

@ -14,7 +14,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
protected void setUp() throws Exception {
this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000);
this.mem = new Memory(0x0000, 0xffff);
bus.addCpu(cpu);
bus.addDevice(mem);

View File

@ -14,7 +14,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
protected void setUp() throws Exception {
this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000);
this.mem = new Memory(0x0000, 0xffff);
bus.addCpu(cpu);
bus.addDevice(mem);

View File

@ -14,7 +14,7 @@ public class CpuAccumulatorModeTest extends TestCase {
public void setUp() throws MemoryRangeException, MemoryAccessException {
this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000);
this.mem = new Memory(0x0000, 0xffff);
bus.addCpu(cpu);
bus.addDevice(mem);

View File

@ -14,7 +14,7 @@ public class CpuImmediateModeTest extends TestCase {
public void setUp() throws MemoryRangeException, MemoryAccessException {
this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000);
this.mem = new Memory(0x0000, 0xffff);
bus.addCpu(cpu);
bus.addDevice(mem);

View File

@ -17,7 +17,7 @@ public class CpuImpliedModeTest {
public void setUp() throws MemoryRangeException, MemoryAccessException {
this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000);
this.mem = new Memory(0x0000, 0xffff);
bus.addCpu(cpu);
bus.addDevice(mem);

View File

@ -16,7 +16,7 @@ public class CpuIndexedIndirectModeTest {
public void runBeforeEveryTest() throws Exception {
this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000);
this.mem = new Memory(0x0000, 0xffff);
bus.addCpu(cpu);
bus.addDevice(mem);

View File

@ -16,7 +16,7 @@ public class CpuIndirectIndexedModeTest {
public void runBeforeEveryTest() throws Exception {
this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000);
this.mem = new Memory(0x0000, 0xffff);
bus.addCpu(cpu);
bus.addDevice(mem);

View File

@ -14,7 +14,7 @@ public class CpuIndirectModeTest extends TestCase {
protected void setUp() throws Exception {
this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000);
this.mem = new Memory(0x0000, 0xffff);
bus.addCpu(cpu);
bus.addDevice(mem);

View File

@ -13,7 +13,7 @@ public class CpuIndirectXModeTest extends TestCase {
protected void setUp() throws Exception {
this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000);
this.mem = new Memory(0x0000, 0xffff);
bus.addCpu(cpu);
bus.addDevice(mem);

View File

@ -14,7 +14,7 @@ public class CpuRelativeModeTest extends TestCase {
protected void setUp() throws Exception {
this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000);
this.mem = new Memory(0x0000, 0xffff);
bus.addCpu(cpu);
bus.addDevice(mem);

View File

@ -25,7 +25,7 @@ public class CpuTest extends TestCase {
public void setUp() throws MemoryRangeException, MemoryAccessException {
this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000);
this.mem = new Memory(0x0000, 0xffff);
bus.addCpu(cpu);
bus.addDevice(mem);

View File

@ -14,7 +14,7 @@ public class CpuZeroPageModeTest extends TestCase {
protected void setUp() throws Exception {
this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000);
this.mem = new Memory(0x0000, 0xffff);
bus.addCpu(cpu);
bus.addDevice(mem);

View File

@ -14,7 +14,7 @@ public class CpuZeroPageXModeTest extends TestCase {
protected void setUp() throws Exception {
this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000);
this.mem = new Memory(0x0000, 0xffff);
bus.addCpu(cpu);
bus.addDevice(mem);

View File

@ -14,7 +14,7 @@ public class CpuZeroPageYModeTest extends TestCase {
protected void setUp() throws Exception {
this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000);
this.mem = new Memory(0x0000, 0xffff);
bus.addCpu(cpu);
bus.addDevice(mem);