mirror of
https://github.com/sethm/symon.git
synced 2024-06-03 07:29:30 +00:00
Renamed AddressDecoder to Bus
This commit is contained in:
parent
0e212e71e5
commit
6f678af3df
|
@ -1,8 +1,9 @@
|
|||
package com.loomcom.lm6502;
|
||||
|
||||
import java.util.*;
|
||||
import com.loomcom.lm6502.devices.*;
|
||||
|
||||
public class AddressDecoder {
|
||||
public class Bus {
|
||||
|
||||
private int bottom = 0x0000;
|
||||
private int top = 0xffff;
|
||||
|
@ -12,11 +13,11 @@ public class AddressDecoder {
|
|||
*/
|
||||
private List<Device> devices;
|
||||
|
||||
public AddressDecoder(int size) {
|
||||
public Bus(int size) {
|
||||
this(0, size - 1);
|
||||
}
|
||||
|
||||
public AddressDecoder(int bottom, int top) {
|
||||
public Bus(int bottom, int top) {
|
||||
this.devices = new ArrayList(8);
|
||||
this.bottom = bottom;
|
||||
this.top = top;
|
||||
|
@ -90,4 +91,4 @@ public class AddressDecoder {
|
|||
// Expose a copy of the device list, not the original
|
||||
return new ArrayList(devices);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,10 +18,10 @@ public class Simulator {
|
|||
Cpu m_cpu;
|
||||
|
||||
/**
|
||||
* The Address Decoder responsible for routing memory
|
||||
* read/write requests to the correct IO devices.
|
||||
* The Bus responsible for routing memory read/write requests to the
|
||||
* correct IO devices.
|
||||
*/
|
||||
AddressDecoder m_adc;
|
||||
Bus m_bus;
|
||||
|
||||
public Simulator() {
|
||||
m_cpu = new Cpu(this);
|
||||
|
@ -45,4 +45,4 @@ public class Simulator {
|
|||
|
||||
public void write(int address, int value) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
package com.loomcom.lm6502;
|
||||
package com.loomcom.lm6502.devices;
|
||||
|
||||
import com.loomcom.lm6502.*;
|
||||
|
||||
/**
|
||||
* A memory-mapped IO Device.
|
||||
|
@ -45,4 +47,4 @@ public abstract class Device {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,125 +0,0 @@
|
|||
package com.loomcom.lm6502;
|
||||
|
||||
import junit.framework.*;
|
||||
|
||||
import com.loomcom.lm6502.devices.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class AddressDecoderTest extends TestCase {
|
||||
|
||||
public AddressDecoderTest(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(AddressDecoderTest.class);
|
||||
}
|
||||
|
||||
public void testCreatingWithTopAndBottom() {
|
||||
AddressDecoder ad = null;
|
||||
|
||||
ad = new AddressDecoder(0x00, 0xff);
|
||||
assertEquals(0x00, ad.bottom());
|
||||
assertEquals(0xff, ad.top());
|
||||
|
||||
ad = new AddressDecoder(0x20, 0xea);
|
||||
assertEquals(0x20, ad.bottom());
|
||||
assertEquals(0xea, ad.top());
|
||||
}
|
||||
|
||||
public void testCreatingWithSize() {
|
||||
AddressDecoder ad = null;
|
||||
|
||||
ad = new AddressDecoder(256);
|
||||
assertEquals(0x00, ad.bottom());
|
||||
assertEquals(0xff, ad.top());
|
||||
|
||||
ad = new AddressDecoder(4096);
|
||||
assertEquals(0x000, ad.bottom());
|
||||
assertEquals(0xfff, ad.top());
|
||||
|
||||
ad = new AddressDecoder(65536);
|
||||
assertEquals(0x0000, ad.bottom());
|
||||
assertEquals(0xffff, ad.top());
|
||||
}
|
||||
|
||||
public void testAddDevice() throws MemoryRangeException {
|
||||
Device memory = new Memory(0x0000, 0x0100, null, true);
|
||||
Device rom = new Memory(0x0100, 0x0200, null, false);
|
||||
|
||||
AddressDecoder ad = new AddressDecoder(0x0000, 0xffff);
|
||||
|
||||
assertEquals(0, ad.getDevices().size());
|
||||
ad.addDevice(memory);
|
||||
assertEquals(1, ad.getDevices().size());
|
||||
ad.addDevice(rom);
|
||||
assertEquals(2, ad.getDevices().size());
|
||||
}
|
||||
|
||||
public void testOverlappingDevicesShouldFail() throws MemoryRangeException {
|
||||
Device memory = new Memory(0x0000, 0x0100, null, true);
|
||||
Device rom = new Memory(0x00ff, 0x0200, null, false);
|
||||
|
||||
AddressDecoder ad = new AddressDecoder(0x0000, 0xffff);
|
||||
|
||||
ad.addDevice(memory);
|
||||
|
||||
try {
|
||||
ad.addDevice(rom);
|
||||
fail("Should have thrown a MemoryRangeException.");
|
||||
} catch (MemoryRangeException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testIsCompleteWithFirstDeviceNotStartingAtBottom() throws MemoryRangeException {
|
||||
Device memory = new Memory(0x00ff, 0xff00, null, true);
|
||||
|
||||
AddressDecoder ad = new AddressDecoder(0x0000, 0xffff);
|
||||
assertFalse("Address space was unexpectedly complete!", ad.isComplete());
|
||||
ad.addDevice(memory);
|
||||
assertFalse("Address space was unexpectedly complete!", ad.isComplete());
|
||||
}
|
||||
|
||||
public void testIsCompleteWithOneDevice() throws MemoryRangeException {
|
||||
Device memory = new Memory(0x0000, 0x10000, null, true);
|
||||
|
||||
AddressDecoder ad = new AddressDecoder(0x0000, 0xffff);
|
||||
assertFalse("Address space was unexpectedly complete!", ad.isComplete());
|
||||
ad.addDevice(memory);
|
||||
assertTrue("Address space should have been complete!", ad.isComplete());
|
||||
}
|
||||
|
||||
public void testIsCompleteWithTwoDevices() throws MemoryRangeException {
|
||||
Device memory = new Memory(0x0000, 0x8000, null, true);
|
||||
Device rom = new Memory(0x8000, 0x8000, null, false);
|
||||
|
||||
AddressDecoder ad = new AddressDecoder(0x0000, 0xffff);
|
||||
assertFalse("Address space was unexpectedly complete!", ad.isComplete());
|
||||
ad.addDevice(memory);
|
||||
assertFalse("Address space was unexpectedly complete!", ad.isComplete());
|
||||
ad.addDevice(rom);
|
||||
assertTrue("Address space should have been complete!", ad.isComplete());
|
||||
}
|
||||
|
||||
public void testIsCompleteWithThreeDevices() throws MemoryRangeException {
|
||||
Device memory = new Memory(0x0000, 0x8000, null, true);
|
||||
Device rom1 = new Memory(0x8000, 0x4000, null, false);
|
||||
Device rom2 = new Memory(0xC000, 0x4000, null, false);
|
||||
|
||||
AddressDecoder ad = new AddressDecoder(0x0000, 0xffff);
|
||||
assertFalse("Address space was unexpectedly complete!", ad.isComplete());
|
||||
ad.addDevice(memory);
|
||||
assertFalse("Address space was unexpectedly complete!", ad.isComplete());
|
||||
ad.addDevice(rom1);
|
||||
assertFalse("Address space was unexpectedly complete!", ad.isComplete());
|
||||
ad.addDevice(rom2);
|
||||
assertTrue("Address space should have been complete!", ad.isComplete());
|
||||
}
|
||||
|
||||
}
|
124
src/test/java/com/loomcom/lm6502/BusTest.java
Normal file
124
src/test/java/com/loomcom/lm6502/BusTest.java
Normal file
|
@ -0,0 +1,124 @@
|
|||
package com.loomcom.lm6502;
|
||||
|
||||
import junit.framework.*;
|
||||
|
||||
import com.loomcom.lm6502.devices.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class BusTest extends TestCase {
|
||||
|
||||
public BusTest(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(BusTest.class);
|
||||
}
|
||||
|
||||
public void testCreatingWithTopAndBottom() {
|
||||
Bus b = null;
|
||||
|
||||
b = new Bus(0x00, 0xff);
|
||||
assertEquals(0x00, b.bottom());
|
||||
assertEquals(0xff, b.top());
|
||||
|
||||
b = new Bus(0x20, 0xea);
|
||||
assertEquals(0x20, b.bottom());
|
||||
assertEquals(0xea, b.top());
|
||||
}
|
||||
|
||||
public void testCreatingWithSize() {
|
||||
Bus b = null;
|
||||
|
||||
b = new Bus(256);
|
||||
assertEquals(0x00, b.bottom());
|
||||
assertEquals(0xff, b.top());
|
||||
|
||||
b = new Bus(4096);
|
||||
assertEquals(0x000, b.bottom());
|
||||
assertEquals(0xfff, b.top());
|
||||
|
||||
b = new Bus(65536);
|
||||
assertEquals(0x0000, b.bottom());
|
||||
assertEquals(0xffff, b.top());
|
||||
}
|
||||
|
||||
public void testAddDevice() throws MemoryRangeException {
|
||||
Device memory = new Memory(0x0000, 0x0100, null, true);
|
||||
Device rom = new Memory(0x0100, 0x0200, null, false);
|
||||
|
||||
Bus b = new Bus(0x0000, 0xffff);
|
||||
|
||||
assertEquals(0, b.getDevices().size());
|
||||
b.addDevice(memory);
|
||||
assertEquals(1, b.getDevices().size());
|
||||
b.addDevice(rom);
|
||||
assertEquals(2, b.getDevices().size());
|
||||
}
|
||||
|
||||
public void testOverlappingDevicesShouldFail() throws MemoryRangeException {
|
||||
Device memory = new Memory(0x0000, 0x0100, null, true);
|
||||
Device rom = new Memory(0x00ff, 0x0200, null, false);
|
||||
|
||||
Bus b = new Bus(0x0000, 0xffff);
|
||||
|
||||
b.addDevice(memory);
|
||||
|
||||
try {
|
||||
b.addDevice(rom);
|
||||
fail("Should have thrown a MemoryRangeException.");
|
||||
} catch (MemoryRangeException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testIsCompleteWithFirstDeviceNotStartingAtBottom() throws MemoryRangeException {
|
||||
Device memory = new Memory(0x00ff, 0xff00, null, true);
|
||||
|
||||
Bus b = new Bus(0x0000, 0xffff);
|
||||
assertFalse("Address space was unexpectedly complete!", b.isComplete());
|
||||
b.addDevice(memory);
|
||||
assertFalse("Address space was unexpectedly complete!", b.isComplete());
|
||||
}
|
||||
|
||||
public void testIsCompleteWithOneDevice() throws MemoryRangeException {
|
||||
Device memory = new Memory(0x0000, 0x10000, null, true);
|
||||
|
||||
Bus b = new Bus(0x0000, 0xffff);
|
||||
assertFalse("Address space was unexpectedly complete!", b.isComplete());
|
||||
b.addDevice(memory);
|
||||
assertTrue("Address space should have been complete!", b.isComplete());
|
||||
}
|
||||
|
||||
public void testIsCompleteWithTwoDevices() throws MemoryRangeException {
|
||||
Device memory = new Memory(0x0000, 0x8000, null, true);
|
||||
Device rom = new Memory(0x8000, 0x8000, null, false);
|
||||
|
||||
Bus b = new Bus(0x0000, 0xffff);
|
||||
assertFalse("Address space was unexpectedly complete!", b.isComplete());
|
||||
b.addDevice(memory);
|
||||
assertFalse("Address space was unexpectedly complete!", b.isComplete());
|
||||
b.addDevice(rom);
|
||||
assertTrue("Address space should have been complete!", b.isComplete());
|
||||
}
|
||||
|
||||
public void testIsCompleteWithThreeDevices() throws MemoryRangeException {
|
||||
Device memory = new Memory(0x0000, 0x8000, null, true);
|
||||
Device rom1 = new Memory(0x8000, 0x4000, null, false);
|
||||
Device rom2 = new Memory(0xC000, 0x4000, null, false);
|
||||
|
||||
Bus b = new Bus(0x0000, 0xffff);
|
||||
assertFalse("Address space was unexpectedly complete!", b.isComplete());
|
||||
b.addDevice(memory);
|
||||
assertFalse("Address space was unexpectedly complete!", b.isComplete());
|
||||
b.addDevice(rom1);
|
||||
assertFalse("Address space was unexpectedly complete!", b.isComplete());
|
||||
b.addDevice(rom2);
|
||||
assertTrue("Address space should have been complete!", b.isComplete());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user