Whitespace and indentation canonicalization. That's what I get for using two editors.
This commit is contained in:
1 parent
d54ad18b17
commit
8bcd8a4a75
18 files changed
+5249
-5250
No files matched your search
@@ -12,114 +12,114 @@ import java.util.*;
|
||||
*/
|
||||
public class BusTest extends TestCase {
|
||||
|
||||
public BusTest(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
public BusTest(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(BusTest.class);
|
||||
}
|
||||
public static Test suite() {
|
||||
return new TestSuite(BusTest.class);
|
||||
}
|
||||
|
||||
public void testCreatingWithStartAndEndAddresses() {
|
||||
Bus b = null;
|
||||
public void testCreatingWithStartAndEndAddresses() {
|
||||
Bus b = null;
|
||||
|
||||
b = new Bus(0x00, 0xff);
|
||||
assertEquals(0x00, b.startAddress());
|
||||
assertEquals(0xff, b.endAddress());
|
||||
b = new Bus(0x00, 0xff);
|
||||
assertEquals(0x00, b.startAddress());
|
||||
assertEquals(0xff, b.endAddress());
|
||||
|
||||
b = new Bus(0x20, 0xea);
|
||||
assertEquals(0x20, b.startAddress());
|
||||
assertEquals(0xea, b.endAddress());
|
||||
}
|
||||
b = new Bus(0x20, 0xea);
|
||||
assertEquals(0x20, b.startAddress());
|
||||
assertEquals(0xea, b.endAddress());
|
||||
}
|
||||
|
||||
public void testCreatingWithSize() {
|
||||
Bus b = null;
|
||||
public void testCreatingWithSize() {
|
||||
Bus b = null;
|
||||
|
||||
b = new Bus(256);
|
||||
assertEquals(0x00, b.startAddress());
|
||||
assertEquals(0xff, b.endAddress());
|
||||
b = new Bus(256);
|
||||
assertEquals(0x00, b.startAddress());
|
||||
assertEquals(0xff, b.endAddress());
|
||||
|
||||
b = new Bus(4096);
|
||||
assertEquals(0x000, b.startAddress());
|
||||
assertEquals(0xfff, b.endAddress());
|
||||
b = new Bus(4096);
|
||||
assertEquals(0x000, b.startAddress());
|
||||
assertEquals(0xfff, b.endAddress());
|
||||
|
||||
b = new Bus(65536);
|
||||
assertEquals(0x0000, b.startAddress());
|
||||
assertEquals(0xffff, b.endAddress());
|
||||
}
|
||||
b = new Bus(65536);
|
||||
assertEquals(0x0000, b.startAddress());
|
||||
assertEquals(0xffff, b.endAddress());
|
||||
}
|
||||
|
||||
public void testAddDevice() throws MemoryRangeException {
|
||||
Device memory = new Memory(0x0000, 0x0100, true);
|
||||
Device rom = new Memory(0x0100, 0x0200, false);
|
||||
public void testAddDevice() throws MemoryRangeException {
|
||||
Device memory = new Memory(0x0000, 0x0100, true);
|
||||
Device rom = new Memory(0x0100, 0x0200, false);
|
||||
|
||||
Bus b = new Bus(0x0000, 0xffff);
|
||||
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());
|
||||
}
|
||||
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, true);
|
||||
Device rom = new Memory(0x00ff, 0x0200, false);
|
||||
public void testOverlappingDevicesShouldFail() throws MemoryRangeException {
|
||||
Device memory = new Memory(0x0000, 0x0100, true);
|
||||
Device rom = new Memory(0x00ff, 0x0200, false);
|
||||
|
||||
Bus b = new Bus(0x0000, 0xffff);
|
||||
Bus b = new Bus(0x0000, 0xffff);
|
||||
|
||||
b.addDevice(memory);
|
||||
b.addDevice(memory);
|
||||
|
||||
try {
|
||||
b.addDevice(rom);
|
||||
fail("Should have thrown a MemoryRangeException.");
|
||||
} catch (MemoryRangeException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
try {
|
||||
b.addDevice(rom);
|
||||
fail("Should have thrown a MemoryRangeException.");
|
||||
} catch (MemoryRangeException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testIsCompleteWithFirstDeviceNotStartingAtStartAddress() throws MemoryRangeException {
|
||||
Device memory = new Memory(0x00ff, 0xff00, true);
|
||||
public void testIsCompleteWithFirstDeviceNotStartingAtStartAddress() throws MemoryRangeException {
|
||||
Device memory = new Memory(0x00ff, 0xff00, 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());
|
||||
}
|
||||
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, true);
|
||||
public void testIsCompleteWithOneDevice() throws MemoryRangeException {
|
||||
Device memory = new Memory(0x0000, 0x10000, 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());
|
||||
}
|
||||
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, true);
|
||||
Device rom = new Memory(0x8000, 0x8000, false);
|
||||
public void testIsCompleteWithTwoDevices() throws MemoryRangeException {
|
||||
Device memory = new Memory(0x0000, 0x8000, true);
|
||||
Device rom = new Memory(0x8000, 0x8000, 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());
|
||||
}
|
||||
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, true);
|
||||
Device rom1 = new Memory(0x8000, 0x4000, false);
|
||||
Device rom2 = new Memory(0xC000, 0x4000, false);
|
||||
public void testIsCompleteWithThreeDevices() throws MemoryRangeException {
|
||||
Device memory = new Memory(0x0000, 0x8000, true);
|
||||
Device rom1 = new Memory(0x8000, 0x4000, false);
|
||||
Device rom2 = new Memory(0xC000, 0x4000, 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());
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -10,349 +10,349 @@ import com.loomcom.symon.exceptions.*;
|
||||
*/
|
||||
public class CpuTest extends TestCase {
|
||||
|
||||
private Cpu cpu;
|
||||
private Bus bus;
|
||||
private Memory mem;
|
||||
|
||||
public CpuTest(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(CpuTest.class);
|
||||
}
|
||||
|
||||
public void setUp() throws MemoryRangeException {
|
||||
this.cpu = new Cpu();
|
||||
this.bus = new Bus(0x0000, 0xffff);
|
||||
this.mem = new Memory(0x0000, 0x10000);
|
||||
bus.addCpu(cpu);
|
||||
bus.addDevice(mem);
|
||||
|
||||
// All test programs start at 0x0200;
|
||||
bus.write(0xfffc, 0x00);
|
||||
bus.write(0xfffd, 0x02);
|
||||
|
||||
cpu.reset();
|
||||
}
|
||||
|
||||
public void testReset() {
|
||||
assertEquals(0, cpu.getAccumulator());
|
||||
assertEquals(0, cpu.getXRegister());
|
||||
assertEquals(0, cpu.getYRegister());
|
||||
assertEquals(0x0200, cpu.getProgramCounter());
|
||||
assertFalse(cpu.getCarryFlag());
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getIrqDisableFlag());
|
||||
assertFalse(cpu.getDecimalModeFlag());
|
||||
assertFalse(cpu.getBreakFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
}
|
||||
|
||||
public void testStack() {
|
||||
|
||||
cpu.stackPush(0x13);
|
||||
assertEquals(0x13, cpu.stackPop());
|
||||
|
||||
cpu.stackPush(0x12);
|
||||
assertEquals(0x12, cpu.stackPop());
|
||||
|
||||
for (int i = 0x00; i <= 0xff; i++) {
|
||||
cpu.stackPush(i);
|
||||
}
|
||||
|
||||
for (int i = 0xff; i >= 0x00; i--) {
|
||||
assertEquals(i, cpu.stackPop());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testStackPush() {
|
||||
assertEquals(0xff, cpu.getStackPointer());
|
||||
assertEquals(0xff, bus.read(0x1ff));
|
||||
|
||||
cpu.stackPush(0x06);
|
||||
assertEquals(0xfe, cpu.getStackPointer());
|
||||
assertEquals(0x06, bus.read(0x1ff));
|
||||
|
||||
cpu.stackPush(0x05);
|
||||
assertEquals(0xfd, cpu.getStackPointer());
|
||||
assertEquals(0x06, bus.read(0x1ff));
|
||||
assertEquals(0x05, bus.read(0x1fe));
|
||||
|
||||
cpu.stackPush(0x04);
|
||||
assertEquals(0xfc, cpu.getStackPointer());
|
||||
assertEquals(0x06, bus.read(0x1ff));
|
||||
assertEquals(0x05, bus.read(0x1fe));
|
||||
assertEquals(0x04, bus.read(0x1fd));
|
||||
|
||||
cpu.stackPush(0x03);
|
||||
assertEquals(0xfb, cpu.getStackPointer());
|
||||
assertEquals(0x06, bus.read(0x1ff));
|
||||
assertEquals(0x05, bus.read(0x1fe));
|
||||
assertEquals(0x04, bus.read(0x1fd));
|
||||
assertEquals(0x03, bus.read(0x1fc));
|
||||
|
||||
cpu.stackPush(0x02);
|
||||
assertEquals(0xfa, cpu.getStackPointer());
|
||||
assertEquals(0x06, bus.read(0x1ff));
|
||||
assertEquals(0x05, bus.read(0x1fe));
|
||||
assertEquals(0x04, bus.read(0x1fd));
|
||||
assertEquals(0x03, bus.read(0x1fc));
|
||||
assertEquals(0x02, bus.read(0x1fb));
|
||||
|
||||
cpu.stackPush(0x01);
|
||||
assertEquals(0xf9, cpu.getStackPointer());
|
||||
assertEquals(0x06, bus.read(0x1ff));
|
||||
assertEquals(0x05, bus.read(0x1fe));
|
||||
assertEquals(0x04, bus.read(0x1fd));
|
||||
assertEquals(0x03, bus.read(0x1fc));
|
||||
assertEquals(0x02, bus.read(0x1fb));
|
||||
assertEquals(0x01, bus.read(0x1fa));
|
||||
}
|
||||
|
||||
public void testStackPushWrapsAroundToStackTop() {
|
||||
cpu.setStackPointer(0x01);
|
||||
|
||||
cpu.stackPush(0x01);
|
||||
assertEquals(0x01, bus.read(0x101));
|
||||
assertEquals(0x00, cpu.getStackPointer());
|
||||
|
||||
cpu.stackPush(0x02);
|
||||
assertEquals(0x02, bus.read(0x100));
|
||||
assertEquals(0xff, cpu.getStackPointer());
|
||||
|
||||
cpu.stackPush(0x03);
|
||||
assertEquals(0x03, bus.read(0x1ff));
|
||||
assertEquals(0xfe, cpu.getStackPointer());
|
||||
}
|
||||
|
||||
|
||||
public void testStackPop() {
|
||||
bus.write(0x1ff, 0x06);
|
||||
bus.write(0x1fe, 0x05);
|
||||
bus.write(0x1fd, 0x04);
|
||||
bus.write(0x1fc, 0x03);
|
||||
bus.write(0x1fb, 0x02);
|
||||
bus.write(0x1fa, 0x01);
|
||||
cpu.setStackPointer(0xf9);
|
||||
|
||||
assertEquals(0x01, cpu.stackPop());
|
||||
assertEquals(0xfa, cpu.getStackPointer());
|
||||
|
||||
assertEquals(0x02, cpu.stackPop());
|
||||
assertEquals(0xfb, cpu.getStackPointer());
|
||||
|
||||
assertEquals(0x03, cpu.stackPop());
|
||||
assertEquals(0xfc, cpu.getStackPointer());
|
||||
|
||||
assertEquals(0x04, cpu.stackPop());
|
||||
assertEquals(0xfd, cpu.getStackPointer());
|
||||
|
||||
assertEquals(0x05, cpu.stackPop());
|
||||
assertEquals(0xfe, cpu.getStackPointer());
|
||||
|
||||
assertEquals(0x06, cpu.stackPop());
|
||||
assertEquals(0xff, cpu.getStackPointer());
|
||||
}
|
||||
|
||||
public void testStackPopWrapsAroundToStackBottom() {
|
||||
bus.write(0x1ff, 0x0f); // top of stack
|
||||
bus.write(0x100, 0xf0); // bottom of stack
|
||||
bus.write(0x101, 0xf1);
|
||||
bus.write(0x102, 0xf2);
|
||||
|
||||
cpu.setStackPointer(0xfe);
|
||||
|
||||
assertEquals(0x0f, cpu.stackPop());
|
||||
assertEquals(0xff, cpu.getStackPointer());
|
||||
|
||||
assertEquals(0xf0, cpu.stackPop());
|
||||
assertEquals(0x00, cpu.getStackPointer());
|
||||
|
||||
assertEquals(0xf1, cpu.stackPop());
|
||||
assertEquals(0x01, cpu.getStackPointer());
|
||||
|
||||
assertEquals(0xf2, cpu.stackPop());
|
||||
assertEquals(0x02, cpu.getStackPointer());
|
||||
}
|
||||
|
||||
public void testStackPeekDoesNotAlterStackPointer() {
|
||||
int val = 0;
|
||||
|
||||
assertEquals(0xff, cpu.stackPeek());
|
||||
assertEquals(0xff, cpu.getStackPointer());
|
||||
|
||||
cpu.stackPush(0x01);
|
||||
assertEquals(0x01, cpu.stackPeek());
|
||||
assertEquals(0xfe, cpu.getStackPointer());
|
||||
|
||||
cpu.stackPush(0x02);
|
||||
assertEquals(0x02, cpu.stackPeek());
|
||||
assertEquals(0xfd, cpu.getStackPointer());
|
||||
|
||||
cpu.stackPush(0x03);
|
||||
assertEquals(0x03, cpu.stackPeek());
|
||||
assertEquals(0xfc, cpu.getStackPointer());
|
||||
|
||||
cpu.stackPush(0x04);
|
||||
assertEquals(0x04, cpu.stackPeek());
|
||||
assertEquals(0xfb, cpu.getStackPointer());
|
||||
assertEquals(0x04, cpu.stackPeek());
|
||||
assertEquals(0xfb, cpu.getStackPointer());
|
||||
assertEquals(0x04, cpu.stackPeek());
|
||||
assertEquals(0xfb, cpu.getStackPointer());
|
||||
}
|
||||
|
||||
public void testGetProcessorStatus() {
|
||||
// By default, no flags are set. Remember, bit 5
|
||||
// is always '1'.
|
||||
assertEquals(0x20, cpu.getProcessorStatus());
|
||||
cpu.setCarryFlag();
|
||||
assertEquals(0x21, cpu.getProcessorStatus());
|
||||
cpu.setZeroFlag();
|
||||
assertEquals(0x23, cpu.getProcessorStatus());
|
||||
cpu.setIrqDisableFlag();
|
||||
assertEquals(0x27, cpu.getProcessorStatus());
|
||||
cpu.setDecimalModeFlag();
|
||||
assertEquals(0x2f, cpu.getProcessorStatus());
|
||||
cpu.setBreakFlag();
|
||||
assertEquals(0x3f, cpu.getProcessorStatus());
|
||||
cpu.setOverflowFlag();
|
||||
assertEquals(0x7f, cpu.getProcessorStatus());
|
||||
cpu.setNegativeFlag();
|
||||
assertEquals(0xff, cpu.getProcessorStatus());
|
||||
|
||||
cpu.clearCarryFlag();
|
||||
assertEquals(0xfe, cpu.getProcessorStatus());
|
||||
cpu.clearZeroFlag();
|
||||
assertEquals(0xfc, cpu.getProcessorStatus());
|
||||
cpu.clearIrqDisableFlag();
|
||||
assertEquals(0xf8, cpu.getProcessorStatus());
|
||||
cpu.clearDecimalModeFlag();
|
||||
assertEquals(0xf0, cpu.getProcessorStatus());
|
||||
cpu.clearBreakFlag();
|
||||
assertEquals(0xe0, cpu.getProcessorStatus());
|
||||
cpu.clearOverflowFlag();
|
||||
assertEquals(0xa0, cpu.getProcessorStatus());
|
||||
cpu.clearNegativeFlag();
|
||||
assertEquals(0x20, cpu.getProcessorStatus());
|
||||
}
|
||||
|
||||
public void testSetProcessorStatus() {
|
||||
// Default
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getIrqDisableFlag());
|
||||
assertFalse(cpu.getDecimalModeFlag());
|
||||
assertFalse(cpu.getBreakFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
|
||||
cpu.setProcessorStatus(0x20|Cpu.P_CARRY);
|
||||
|
||||
assertTrue(cpu.getCarryFlag());
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getIrqDisableFlag());
|
||||
assertFalse(cpu.getDecimalModeFlag());
|
||||
assertFalse(cpu.getBreakFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
|
||||
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE);
|
||||
|
||||
assertTrue(cpu.getCarryFlag());
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getIrqDisableFlag());
|
||||
assertFalse(cpu.getDecimalModeFlag());
|
||||
assertFalse(cpu.getBreakFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
assertTrue(cpu.getNegativeFlag());
|
||||
|
||||
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE|Cpu.P_ZERO);
|
||||
|
||||
assertTrue(cpu.getCarryFlag());
|
||||
assertTrue(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getIrqDisableFlag());
|
||||
assertFalse(cpu.getDecimalModeFlag());
|
||||
assertFalse(cpu.getBreakFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
assertTrue(cpu.getNegativeFlag());
|
||||
|
||||
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE|Cpu.P_ZERO|
|
||||
Cpu.P_OVERFLOW);
|
||||
|
||||
assertTrue(cpu.getCarryFlag());
|
||||
assertTrue(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getIrqDisableFlag());
|
||||
assertFalse(cpu.getDecimalModeFlag());
|
||||
assertFalse(cpu.getBreakFlag());
|
||||
assertTrue(cpu.getOverflowFlag());
|
||||
assertTrue(cpu.getNegativeFlag());
|
||||
|
||||
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE|Cpu.P_ZERO|
|
||||
Cpu.P_OVERFLOW|Cpu.P_BREAK);
|
||||
|
||||
assertTrue(cpu.getCarryFlag());
|
||||
assertTrue(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getIrqDisableFlag());
|
||||
assertFalse(cpu.getDecimalModeFlag());
|
||||
assertTrue(cpu.getBreakFlag());
|
||||
assertTrue(cpu.getOverflowFlag());
|
||||
assertTrue(cpu.getNegativeFlag());
|
||||
|
||||
|
||||
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE|Cpu.P_ZERO|
|
||||
Cpu.P_OVERFLOW|Cpu.P_BREAK|Cpu.P_DECIMAL);
|
||||
|
||||
assertTrue(cpu.getCarryFlag());
|
||||
assertTrue(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getIrqDisableFlag());
|
||||
assertTrue(cpu.getDecimalModeFlag());
|
||||
assertTrue(cpu.getBreakFlag());
|
||||
assertTrue(cpu.getOverflowFlag());
|
||||
assertTrue(cpu.getNegativeFlag());
|
||||
|
||||
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE|Cpu.P_ZERO|
|
||||
Cpu.P_OVERFLOW|Cpu.P_BREAK|Cpu.P_DECIMAL|
|
||||
Cpu.P_IRQ_DISABLE);
|
||||
|
||||
assertTrue(cpu.getCarryFlag());
|
||||
assertTrue(cpu.getZeroFlag());
|
||||
assertTrue(cpu.getIrqDisableFlag());
|
||||
assertTrue(cpu.getDecimalModeFlag());
|
||||
assertTrue(cpu.getBreakFlag());
|
||||
assertTrue(cpu.getOverflowFlag());
|
||||
assertTrue(cpu.getNegativeFlag());
|
||||
|
||||
cpu.setProcessorStatus(0x20);
|
||||
|
||||
assertFalse(cpu.getCarryFlag());
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getIrqDisableFlag());
|
||||
assertFalse(cpu.getDecimalModeFlag());
|
||||
assertFalse(cpu.getBreakFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
|
||||
cpu.setProcessorStatus(0x00);
|
||||
|
||||
assertFalse(cpu.getCarryFlag());
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getIrqDisableFlag());
|
||||
assertFalse(cpu.getDecimalModeFlag());
|
||||
assertFalse(cpu.getBreakFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
}
|
||||
|
||||
public void testAddress() {
|
||||
assertEquals(0xf1ea, cpu.address(0xea, 0xf1));
|
||||
assertEquals(0x00ea, cpu.address(0xea, 0x00));
|
||||
assertEquals(0xf100, cpu.address(0x00, 0xf1));
|
||||
assertEquals(0x1234, cpu.address(0x34, 0x12));
|
||||
assertEquals(0xffff, cpu.address(0xff, 0xff));
|
||||
}
|
||||
private Cpu cpu;
|
||||
private Bus bus;
|
||||
private Memory mem;
|
||||
|
||||
public CpuTest(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(CpuTest.class);
|
||||
}
|
||||
|
||||
public void setUp() throws MemoryRangeException {
|
||||
this.cpu = new Cpu();
|
||||
this.bus = new Bus(0x0000, 0xffff);
|
||||
this.mem = new Memory(0x0000, 0x10000);
|
||||
bus.addCpu(cpu);
|
||||
bus.addDevice(mem);
|
||||
|
||||
// All test programs start at 0x0200;
|
||||
bus.write(0xfffc, 0x00);
|
||||
bus.write(0xfffd, 0x02);
|
||||
|
||||
cpu.reset();
|
||||
}
|
||||
|
||||
public void testReset() {
|
||||
assertEquals(0, cpu.getAccumulator());
|
||||
assertEquals(0, cpu.getXRegister());
|
||||
assertEquals(0, cpu.getYRegister());
|
||||
assertEquals(0x0200, cpu.getProgramCounter());
|
||||
assertFalse(cpu.getCarryFlag());
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getIrqDisableFlag());
|
||||
assertFalse(cpu.getDecimalModeFlag());
|
||||
assertFalse(cpu.getBreakFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
}
|
||||
|
||||
public void testStack() {
|
||||
|
||||
cpu.stackPush(0x13);
|
||||
assertEquals(0x13, cpu.stackPop());
|
||||
|
||||
cpu.stackPush(0x12);
|
||||
assertEquals(0x12, cpu.stackPop());
|
||||
|
||||
for (int i = 0x00; i <= 0xff; i++) {
|
||||
cpu.stackPush(i);
|
||||
}
|
||||
|
||||
for (int i = 0xff; i >= 0x00; i--) {
|
||||
assertEquals(i, cpu.stackPop());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testStackPush() {
|
||||
assertEquals(0xff, cpu.getStackPointer());
|
||||
assertEquals(0xff, bus.read(0x1ff));
|
||||
|
||||
cpu.stackPush(0x06);
|
||||
assertEquals(0xfe, cpu.getStackPointer());
|
||||
assertEquals(0x06, bus.read(0x1ff));
|
||||
|
||||
cpu.stackPush(0x05);
|
||||
assertEquals(0xfd, cpu.getStackPointer());
|
||||
assertEquals(0x06, bus.read(0x1ff));
|
||||
assertEquals(0x05, bus.read(0x1fe));
|
||||
|
||||
cpu.stackPush(0x04);
|
||||
assertEquals(0xfc, cpu.getStackPointer());
|
||||
assertEquals(0x06, bus.read(0x1ff));
|
||||
assertEquals(0x05, bus.read(0x1fe));
|
||||
assertEquals(0x04, bus.read(0x1fd));
|
||||
|
||||
cpu.stackPush(0x03);
|
||||
assertEquals(0xfb, cpu.getStackPointer());
|
||||
assertEquals(0x06, bus.read(0x1ff));
|
||||
assertEquals(0x05, bus.read(0x1fe));
|
||||
assertEquals(0x04, bus.read(0x1fd));
|
||||
assertEquals(0x03, bus.read(0x1fc));
|
||||
|
||||
cpu.stackPush(0x02);
|
||||
assertEquals(0xfa, cpu.getStackPointer());
|
||||
assertEquals(0x06, bus.read(0x1ff));
|
||||
assertEquals(0x05, bus.read(0x1fe));
|
||||
assertEquals(0x04, bus.read(0x1fd));
|
||||
assertEquals(0x03, bus.read(0x1fc));
|
||||
assertEquals(0x02, bus.read(0x1fb));
|
||||
|
||||
cpu.stackPush(0x01);
|
||||
assertEquals(0xf9, cpu.getStackPointer());
|
||||
assertEquals(0x06, bus.read(0x1ff));
|
||||
assertEquals(0x05, bus.read(0x1fe));
|
||||
assertEquals(0x04, bus.read(0x1fd));
|
||||
assertEquals(0x03, bus.read(0x1fc));
|
||||
assertEquals(0x02, bus.read(0x1fb));
|
||||
assertEquals(0x01, bus.read(0x1fa));
|
||||
}
|
||||
|
||||
public void testStackPushWrapsAroundToStackTop() {
|
||||
cpu.setStackPointer(0x01);
|
||||
|
||||
cpu.stackPush(0x01);
|
||||
assertEquals(0x01, bus.read(0x101));
|
||||
assertEquals(0x00, cpu.getStackPointer());
|
||||
|
||||
cpu.stackPush(0x02);
|
||||
assertEquals(0x02, bus.read(0x100));
|
||||
assertEquals(0xff, cpu.getStackPointer());
|
||||
|
||||
cpu.stackPush(0x03);
|
||||
assertEquals(0x03, bus.read(0x1ff));
|
||||
assertEquals(0xfe, cpu.getStackPointer());
|
||||
}
|
||||
|
||||
|
||||
public void testStackPop() {
|
||||
bus.write(0x1ff, 0x06);
|
||||
bus.write(0x1fe, 0x05);
|
||||
bus.write(0x1fd, 0x04);
|
||||
bus.write(0x1fc, 0x03);
|
||||
bus.write(0x1fb, 0x02);
|
||||
bus.write(0x1fa, 0x01);
|
||||
cpu.setStackPointer(0xf9);
|
||||
|
||||
assertEquals(0x01, cpu.stackPop());
|
||||
assertEquals(0xfa, cpu.getStackPointer());
|
||||
|
||||
assertEquals(0x02, cpu.stackPop());
|
||||
assertEquals(0xfb, cpu.getStackPointer());
|
||||
|
||||
assertEquals(0x03, cpu.stackPop());
|
||||
assertEquals(0xfc, cpu.getStackPointer());
|
||||
|
||||
assertEquals(0x04, cpu.stackPop());
|
||||
assertEquals(0xfd, cpu.getStackPointer());
|
||||
|
||||
assertEquals(0x05, cpu.stackPop());
|
||||
assertEquals(0xfe, cpu.getStackPointer());
|
||||
|
||||
assertEquals(0x06, cpu.stackPop());
|
||||
assertEquals(0xff, cpu.getStackPointer());
|
||||
}
|
||||
|
||||
public void testStackPopWrapsAroundToStackBottom() {
|
||||
bus.write(0x1ff, 0x0f); // top of stack
|
||||
bus.write(0x100, 0xf0); // bottom of stack
|
||||
bus.write(0x101, 0xf1);
|
||||
bus.write(0x102, 0xf2);
|
||||
|
||||
cpu.setStackPointer(0xfe);
|
||||
|
||||
assertEquals(0x0f, cpu.stackPop());
|
||||
assertEquals(0xff, cpu.getStackPointer());
|
||||
|
||||
assertEquals(0xf0, cpu.stackPop());
|
||||
assertEquals(0x00, cpu.getStackPointer());
|
||||
|
||||
assertEquals(0xf1, cpu.stackPop());
|
||||
assertEquals(0x01, cpu.getStackPointer());
|
||||
|
||||
assertEquals(0xf2, cpu.stackPop());
|
||||
assertEquals(0x02, cpu.getStackPointer());
|
||||
}
|
||||
|
||||
public void testStackPeekDoesNotAlterStackPointer() {
|
||||
int val = 0;
|
||||
|
||||
assertEquals(0xff, cpu.stackPeek());
|
||||
assertEquals(0xff, cpu.getStackPointer());
|
||||
|
||||
cpu.stackPush(0x01);
|
||||
assertEquals(0x01, cpu.stackPeek());
|
||||
assertEquals(0xfe, cpu.getStackPointer());
|
||||
|
||||
cpu.stackPush(0x02);
|
||||
assertEquals(0x02, cpu.stackPeek());
|
||||
assertEquals(0xfd, cpu.getStackPointer());
|
||||
|
||||
cpu.stackPush(0x03);
|
||||
assertEquals(0x03, cpu.stackPeek());
|
||||
assertEquals(0xfc, cpu.getStackPointer());
|
||||
|
||||
cpu.stackPush(0x04);
|
||||
assertEquals(0x04, cpu.stackPeek());
|
||||
assertEquals(0xfb, cpu.getStackPointer());
|
||||
assertEquals(0x04, cpu.stackPeek());
|
||||
assertEquals(0xfb, cpu.getStackPointer());
|
||||
assertEquals(0x04, cpu.stackPeek());
|
||||
assertEquals(0xfb, cpu.getStackPointer());
|
||||
}
|
||||
|
||||
public void testGetProcessorStatus() {
|
||||
// By default, no flags are set. Remember, bit 5
|
||||
// is always '1'.
|
||||
assertEquals(0x20, cpu.getProcessorStatus());
|
||||
cpu.setCarryFlag();
|
||||
assertEquals(0x21, cpu.getProcessorStatus());
|
||||
cpu.setZeroFlag();
|
||||
assertEquals(0x23, cpu.getProcessorStatus());
|
||||
cpu.setIrqDisableFlag();
|
||||
assertEquals(0x27, cpu.getProcessorStatus());
|
||||
cpu.setDecimalModeFlag();
|
||||
assertEquals(0x2f, cpu.getProcessorStatus());
|
||||
cpu.setBreakFlag();
|
||||
assertEquals(0x3f, cpu.getProcessorStatus());
|
||||
cpu.setOverflowFlag();
|
||||
assertEquals(0x7f, cpu.getProcessorStatus());
|
||||
cpu.setNegativeFlag();
|
||||
assertEquals(0xff, cpu.getProcessorStatus());
|
||||
|
||||
cpu.clearCarryFlag();
|
||||
assertEquals(0xfe, cpu.getProcessorStatus());
|
||||
cpu.clearZeroFlag();
|
||||
assertEquals(0xfc, cpu.getProcessorStatus());
|
||||
cpu.clearIrqDisableFlag();
|
||||
assertEquals(0xf8, cpu.getProcessorStatus());
|
||||
cpu.clearDecimalModeFlag();
|
||||
assertEquals(0xf0, cpu.getProcessorStatus());
|
||||
cpu.clearBreakFlag();
|
||||
assertEquals(0xe0, cpu.getProcessorStatus());
|
||||
cpu.clearOverflowFlag();
|
||||
assertEquals(0xa0, cpu.getProcessorStatus());
|
||||
cpu.clearNegativeFlag();
|
||||
assertEquals(0x20, cpu.getProcessorStatus());
|
||||
}
|
||||
|
||||
public void testSetProcessorStatus() {
|
||||
// Default
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getIrqDisableFlag());
|
||||
assertFalse(cpu.getDecimalModeFlag());
|
||||
assertFalse(cpu.getBreakFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
|
||||
cpu.setProcessorStatus(0x20|Cpu.P_CARRY);
|
||||
|
||||
assertTrue(cpu.getCarryFlag());
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getIrqDisableFlag());
|
||||
assertFalse(cpu.getDecimalModeFlag());
|
||||
assertFalse(cpu.getBreakFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
|
||||
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE);
|
||||
|
||||
assertTrue(cpu.getCarryFlag());
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getIrqDisableFlag());
|
||||
assertFalse(cpu.getDecimalModeFlag());
|
||||
assertFalse(cpu.getBreakFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
assertTrue(cpu.getNegativeFlag());
|
||||
|
||||
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE|Cpu.P_ZERO);
|
||||
|
||||
assertTrue(cpu.getCarryFlag());
|
||||
assertTrue(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getIrqDisableFlag());
|
||||
assertFalse(cpu.getDecimalModeFlag());
|
||||
assertFalse(cpu.getBreakFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
assertTrue(cpu.getNegativeFlag());
|
||||
|
||||
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE|Cpu.P_ZERO|
|
||||
Cpu.P_OVERFLOW);
|
||||
|
||||
assertTrue(cpu.getCarryFlag());
|
||||
assertTrue(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getIrqDisableFlag());
|
||||
assertFalse(cpu.getDecimalModeFlag());
|
||||
assertFalse(cpu.getBreakFlag());
|
||||
assertTrue(cpu.getOverflowFlag());
|
||||
assertTrue(cpu.getNegativeFlag());
|
||||
|
||||
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE|Cpu.P_ZERO|
|
||||
Cpu.P_OVERFLOW|Cpu.P_BREAK);
|
||||
|
||||
assertTrue(cpu.getCarryFlag());
|
||||
assertTrue(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getIrqDisableFlag());
|
||||
assertFalse(cpu.getDecimalModeFlag());
|
||||
assertTrue(cpu.getBreakFlag());
|
||||
assertTrue(cpu.getOverflowFlag());
|
||||
assertTrue(cpu.getNegativeFlag());
|
||||
|
||||
|
||||
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE|Cpu.P_ZERO|
|
||||
Cpu.P_OVERFLOW|Cpu.P_BREAK|Cpu.P_DECIMAL);
|
||||
|
||||
assertTrue(cpu.getCarryFlag());
|
||||
assertTrue(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getIrqDisableFlag());
|
||||
assertTrue(cpu.getDecimalModeFlag());
|
||||
assertTrue(cpu.getBreakFlag());
|
||||
assertTrue(cpu.getOverflowFlag());
|
||||
assertTrue(cpu.getNegativeFlag());
|
||||
|
||||
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE|Cpu.P_ZERO|
|
||||
Cpu.P_OVERFLOW|Cpu.P_BREAK|Cpu.P_DECIMAL|
|
||||
Cpu.P_IRQ_DISABLE);
|
||||
|
||||
assertTrue(cpu.getCarryFlag());
|
||||
assertTrue(cpu.getZeroFlag());
|
||||
assertTrue(cpu.getIrqDisableFlag());
|
||||
assertTrue(cpu.getDecimalModeFlag());
|
||||
assertTrue(cpu.getBreakFlag());
|
||||
assertTrue(cpu.getOverflowFlag());
|
||||
assertTrue(cpu.getNegativeFlag());
|
||||
|
||||
cpu.setProcessorStatus(0x20);
|
||||
|
||||
assertFalse(cpu.getCarryFlag());
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getIrqDisableFlag());
|
||||
assertFalse(cpu.getDecimalModeFlag());
|
||||
assertFalse(cpu.getBreakFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
|
||||
cpu.setProcessorStatus(0x00);
|
||||
|
||||
assertFalse(cpu.getCarryFlag());
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getIrqDisableFlag());
|
||||
assertFalse(cpu.getDecimalModeFlag());
|
||||
assertFalse(cpu.getBreakFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
}
|
||||
|
||||
public void testAddress() {
|
||||
assertEquals(0xf1ea, cpu.address(0xea, 0xf1));
|
||||
assertEquals(0x00ea, cpu.address(0xea, 0x00));
|
||||
assertEquals(0xf100, cpu.address(0x00, 0xf1));
|
||||
assertEquals(0x1234, cpu.address(0x34, 0x12));
|
||||
assertEquals(0xffff, cpu.address(0xff, 0xff));
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -12,129 +12,129 @@ import com.loomcom.symon.exceptions.*;
|
||||
*/
|
||||
public class MemoryRangeTest extends TestCase {
|
||||
|
||||
public MemoryRangeTest(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
public MemoryRangeTest(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(MemoryRangeTest.class);
|
||||
}
|
||||
public static Test suite() {
|
||||
return new TestSuite(MemoryRangeTest.class);
|
||||
}
|
||||
|
||||
public void testConstructorThrowsWhenInvalid() {
|
||||
// All of these should raise MemoryRangeException
|
||||
doInvalidMemoryRangeTest(0, -1);
|
||||
doInvalidMemoryRangeTest(-1, 0);
|
||||
doInvalidMemoryRangeTest(0, 0);
|
||||
doInvalidMemoryRangeTest(1, 1);
|
||||
doInvalidMemoryRangeTest(1, 0);
|
||||
doInvalidMemoryRangeTest(2, 1);
|
||||
}
|
||||
public void testConstructorThrowsWhenInvalid() {
|
||||
// All of these should raise MemoryRangeException
|
||||
doInvalidMemoryRangeTest(0, -1);
|
||||
doInvalidMemoryRangeTest(-1, 0);
|
||||
doInvalidMemoryRangeTest(0, 0);
|
||||
doInvalidMemoryRangeTest(1, 1);
|
||||
doInvalidMemoryRangeTest(1, 0);
|
||||
doInvalidMemoryRangeTest(2, 1);
|
||||
}
|
||||
|
||||
public void testConstructorShouldNotThrow() throws MemoryRangeException {
|
||||
// None of these should throw.
|
||||
new MemoryRange(0, 1);
|
||||
new MemoryRange(0, 2);
|
||||
new MemoryRange(1, 2);
|
||||
new MemoryRange(2, 10);
|
||||
}
|
||||
public void testConstructorShouldNotThrow() throws MemoryRangeException {
|
||||
// None of these should throw.
|
||||
new MemoryRange(0, 1);
|
||||
new MemoryRange(0, 2);
|
||||
new MemoryRange(1, 2);
|
||||
new MemoryRange(2, 10);
|
||||
}
|
||||
|
||||
public void testStartAddress() throws MemoryRangeException {
|
||||
MemoryRange r = new MemoryRange(0x101, 0x202);
|
||||
assertEquals(0x101, r.startAddress());
|
||||
}
|
||||
public void testStartAddress() throws MemoryRangeException {
|
||||
MemoryRange r = new MemoryRange(0x101, 0x202);
|
||||
assertEquals(0x101, r.startAddress());
|
||||
}
|
||||
|
||||
public void testEndAddress() throws MemoryRangeException {
|
||||
MemoryRange r = new MemoryRange(0x101, 0x202);
|
||||
assertEquals(0x202, r.endAddress());
|
||||
}
|
||||
public void testEndAddress() throws MemoryRangeException {
|
||||
MemoryRange r = new MemoryRange(0x101, 0x202);
|
||||
assertEquals(0x202, r.endAddress());
|
||||
}
|
||||
|
||||
public void testOverlaps() throws MemoryRangeException {
|
||||
MemoryRange a = new MemoryRange(0x0100, 0x01ff);
|
||||
MemoryRange b = new MemoryRange(0x0200, 0x02ff);
|
||||
public void testOverlaps() throws MemoryRangeException {
|
||||
MemoryRange a = new MemoryRange(0x0100, 0x01ff);
|
||||
MemoryRange b = new MemoryRange(0x0200, 0x02ff);
|
||||
|
||||
MemoryRange c = new MemoryRange(0x01a0, 0x01af); // inside a
|
||||
MemoryRange d = new MemoryRange(0x00ff, 0x01a0); // overlaps a
|
||||
MemoryRange e = new MemoryRange(0x01a0, 0x02ff); // overlaps a
|
||||
MemoryRange c = new MemoryRange(0x01a0, 0x01af); // inside a
|
||||
MemoryRange d = new MemoryRange(0x00ff, 0x01a0); // overlaps a
|
||||
MemoryRange e = new MemoryRange(0x01a0, 0x02ff); // overlaps a
|
||||
|
||||
MemoryRange f = new MemoryRange(0x02a0, 0x02af); // inside b
|
||||
MemoryRange g = new MemoryRange(0x01ff, 0x02a0); // overlaps b
|
||||
MemoryRange h = new MemoryRange(0x02a0, 0x03ff); // overlaps b
|
||||
MemoryRange f = new MemoryRange(0x02a0, 0x02af); // inside b
|
||||
MemoryRange g = new MemoryRange(0x01ff, 0x02a0); // overlaps b
|
||||
MemoryRange h = new MemoryRange(0x02a0, 0x03ff); // overlaps b
|
||||
|
||||
assertFalse(a.overlaps(b));
|
||||
assertFalse(b.overlaps(a));
|
||||
assertFalse(a.overlaps(b));
|
||||
assertFalse(b.overlaps(a));
|
||||
|
||||
assertTrue(a.overlaps(c));
|
||||
assertTrue(c.overlaps(a));
|
||||
assertTrue(a.overlaps(c));
|
||||
assertTrue(c.overlaps(a));
|
||||
|
||||
assertTrue(a.overlaps(d));
|
||||
assertTrue(d.overlaps(a));
|
||||
assertTrue(a.overlaps(d));
|
||||
assertTrue(d.overlaps(a));
|
||||
|
||||
assertTrue(a.overlaps(e));
|
||||
assertTrue(e.overlaps(a));
|
||||
assertTrue(a.overlaps(e));
|
||||
assertTrue(e.overlaps(a));
|
||||
|
||||
assertTrue(b.overlaps(f));
|
||||
assertTrue(f.overlaps(b));
|
||||
assertTrue(b.overlaps(f));
|
||||
assertTrue(f.overlaps(b));
|
||||
|
||||
assertTrue(b.overlaps(g));
|
||||
assertTrue(g.overlaps(b));
|
||||
assertTrue(b.overlaps(g));
|
||||
assertTrue(g.overlaps(b));
|
||||
|
||||
assertTrue(b.overlaps(h));
|
||||
assertTrue(h.overlaps(b));
|
||||
}
|
||||
assertTrue(b.overlaps(h));
|
||||
assertTrue(h.overlaps(b));
|
||||
}
|
||||
|
||||
public void testToString() throws MemoryRangeException {
|
||||
MemoryRange a = new MemoryRange(0x0abf, 0xff00);
|
||||
assertEquals("@0x0abf-0xff00", a.toString());
|
||||
public void testToString() throws MemoryRangeException {
|
||||
MemoryRange a = new MemoryRange(0x0abf, 0xff00);
|
||||
assertEquals("@0x0abf-0xff00", a.toString());
|
||||
|
||||
MemoryRange b = new MemoryRange(0, 255);
|
||||
assertEquals("@0x0000-0x00ff", b.toString());
|
||||
MemoryRange b = new MemoryRange(0, 255);
|
||||
assertEquals("@0x0000-0x00ff", b.toString());
|
||||
|
||||
MemoryRange c = new MemoryRange(0, 65535);
|
||||
assertEquals("@0x0000-0xffff", c.toString());
|
||||
}
|
||||
MemoryRange c = new MemoryRange(0, 65535);
|
||||
assertEquals("@0x0000-0xffff", c.toString());
|
||||
}
|
||||
|
||||
public void testIncluded() throws MemoryRangeException {
|
||||
MemoryRange a = new MemoryRange(0x0100, 0x0fff);
|
||||
public void testIncluded() throws MemoryRangeException {
|
||||
MemoryRange a = new MemoryRange(0x0100, 0x0fff);
|
||||
|
||||
assertFalse(a.includes(0x0000));
|
||||
assertFalse(a.includes(0x00ff));
|
||||
assertTrue(a.includes(0x0100));
|
||||
assertTrue(a.includes(0x0fff));
|
||||
assertFalse(a.includes(0x1000));
|
||||
assertFalse(a.includes(0xffff));
|
||||
}
|
||||
assertFalse(a.includes(0x0000));
|
||||
assertFalse(a.includes(0x00ff));
|
||||
assertTrue(a.includes(0x0100));
|
||||
assertTrue(a.includes(0x0fff));
|
||||
assertFalse(a.includes(0x1000));
|
||||
assertFalse(a.includes(0xffff));
|
||||
}
|
||||
|
||||
public void testCompareTo() throws MemoryRangeException {
|
||||
MemoryRange a = new MemoryRange(0x0000, 0x0100);
|
||||
MemoryRange b = new MemoryRange(0x0200, 0x0300);
|
||||
MemoryRange c = new MemoryRange(0x0200, 0x0300);
|
||||
// a < b
|
||||
assertTrue(a.compareTo(b) == -1);
|
||||
// b > a
|
||||
assertTrue(b.compareTo(a) == 1);
|
||||
// Identity
|
||||
assertTrue(a.compareTo(a) == 0);
|
||||
assertTrue(b.compareTo(b) == 0);
|
||||
// Equality
|
||||
assertTrue(b.compareTo(c) == 0);
|
||||
assertTrue(c.compareTo(b) == 0);
|
||||
// Null
|
||||
try {
|
||||
a.compareTo(null);
|
||||
fail("Should have thrown NullPointerException");
|
||||
} catch (NullPointerException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
public void testCompareTo() throws MemoryRangeException {
|
||||
MemoryRange a = new MemoryRange(0x0000, 0x0100);
|
||||
MemoryRange b = new MemoryRange(0x0200, 0x0300);
|
||||
MemoryRange c = new MemoryRange(0x0200, 0x0300);
|
||||
// a < b
|
||||
assertTrue(a.compareTo(b) == -1);
|
||||
// b > a
|
||||
assertTrue(b.compareTo(a) == 1);
|
||||
// Identity
|
||||
assertTrue(a.compareTo(a) == 0);
|
||||
assertTrue(b.compareTo(b) == 0);
|
||||
// Equality
|
||||
assertTrue(b.compareTo(c) == 0);
|
||||
assertTrue(c.compareTo(b) == 0);
|
||||
// Null
|
||||
try {
|
||||
a.compareTo(null);
|
||||
fail("Should have thrown NullPointerException");
|
||||
} catch (NullPointerException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
// Helper method.
|
||||
public void doInvalidMemoryRangeTest(int start, int end) {
|
||||
try {
|
||||
new MemoryRange(start, end);
|
||||
fail("MemoryRangeException should have been thrown.");
|
||||
} catch (MemoryRangeException e) {
|
||||
// Expected.
|
||||
}
|
||||
}
|
||||
// Helper method.
|
||||
public void doInvalidMemoryRangeTest(int start, int end) {
|
||||
try {
|
||||
new MemoryRange(start, end);
|
||||
fail("MemoryRangeException should have been thrown.");
|
||||
} catch (MemoryRangeException e) {
|
||||
// Expected.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,26 +8,26 @@ import junit.framework.TestSuite;
|
||||
* Unit test for the j6502 Simulator class.
|
||||
*/
|
||||
public class SimulatorTest extends TestCase {
|
||||
/**
|
||||
* Create the test case
|
||||
*
|
||||
* @param testName name of the test case
|
||||
*/
|
||||
public SimulatorTest(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
/**
|
||||
* Create the test case
|
||||
*
|
||||
* @param testName name of the test case
|
||||
*/
|
||||
public SimulatorTest(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the suite of tests being tested
|
||||
*/
|
||||
public static Test suite() {
|
||||
return new TestSuite(SimulatorTest.class);
|
||||
}
|
||||
/**
|
||||
* @return the suite of tests being tested
|
||||
*/
|
||||
public static Test suite() {
|
||||
return new TestSuite(SimulatorTest.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rigourous Test :-)
|
||||
*/
|
||||
public void testSimulator() {
|
||||
assertTrue(true);
|
||||
}
|
||||
/**
|
||||
* Rigourous Test :-)
|
||||
*/
|
||||
public void testSimulator() {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user