- Continued refactoring of address decoding.
- Device read and write may now throw MemoryAccessException, and appropriate throws clauses have been added throughout the code.
This commit is contained in:
1 parent
a01090a16e
commit
ac88786df7
21 files changed
+465
-446
No files matched your search
@@ -1,7 +1,8 @@
|
||||
package com.loomcom.symon;
|
||||
|
||||
import com.loomcom.symon.devices.Memory;
|
||||
import com.loomcom.symon.exceptions.MemoryRangeException;
|
||||
import com.loomcom.symon.exceptions.*;
|
||||
|
||||
import junit.framework.*;
|
||||
|
||||
public class CpuImmediateModeTest extends TestCase {
|
||||
@@ -10,7 +11,7 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
protected Bus bus;
|
||||
protected Memory mem;
|
||||
|
||||
public void setUp() throws MemoryRangeException {
|
||||
public void setUp() throws MemoryRangeException, MemoryAccessException {
|
||||
this.cpu = new Cpu();
|
||||
this.bus = new Bus(0x0000, 0xffff);
|
||||
this.mem = new Memory(0x0000, 0x10000);
|
||||
@@ -51,7 +52,7 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
|
||||
/* ORA Immediate Mode Tests - 0x09 */
|
||||
|
||||
public void test_ORA() {
|
||||
public void test_ORA() throws MemoryAccessException {
|
||||
bus.loadProgram(0x09, 0x00, // ORA #$00
|
||||
0x09, 0x11, // ORA #$11
|
||||
0x09, 0x22, // ORA #$22
|
||||
@@ -73,25 +74,25 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
assertEquals(0xff, cpu.getAccumulator());
|
||||
}
|
||||
|
||||
public void test_ORA_SetsZeroFlagIfResultIsZero() {
|
||||
public void test_ORA_SetsZeroFlagIfResultIsZero() throws MemoryAccessException {
|
||||
bus.loadProgram(0x09, 0x00); // ORA #$00
|
||||
cpu.step();
|
||||
assertTrue(cpu.getZeroFlag());
|
||||
}
|
||||
|
||||
public void test_ORA_DoesNotSetZeroFlagIfResultNotZero() {
|
||||
public void test_ORA_DoesNotSetZeroFlagIfResultNotZero() throws MemoryAccessException {
|
||||
bus.loadProgram(0x09, 0x01); // ORA #$01
|
||||
cpu.step();
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
}
|
||||
|
||||
public void test_ORA_SetsNegativeFlagIfResultIsNegative() {
|
||||
public void test_ORA_SetsNegativeFlagIfResultIsNegative() throws MemoryAccessException {
|
||||
bus.loadProgram(0x09, 0x80); // ORA #$80
|
||||
cpu.step();
|
||||
assertTrue(cpu.getNegativeFlag());
|
||||
}
|
||||
|
||||
public void test_ORA_DoesNotSetNegativeFlagIfResultNotNegative() {
|
||||
public void test_ORA_DoesNotSetNegativeFlagIfResultNotNegative() throws MemoryAccessException {
|
||||
bus.loadProgram(0x09, 0x7f); // ORA #$7F
|
||||
cpu.step();
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
@@ -99,7 +100,7 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
|
||||
/* AND Immediate Mode Tests - 0x29 */
|
||||
|
||||
public void test_AND() {
|
||||
public void test_AND() throws MemoryAccessException {
|
||||
bus.loadProgram(0x29, 0x00, // AND #$00
|
||||
0x29, 0x11, // AND #$11
|
||||
0xa9, 0xaa, // LDA #$AA
|
||||
@@ -122,28 +123,28 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
assertEquals(0x00, cpu.getAccumulator());
|
||||
}
|
||||
|
||||
public void test_AND_SetsZeroFlagIfResultIsZero() {
|
||||
public void test_AND_SetsZeroFlagIfResultIsZero() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa9, 0x88, // LDA #$88
|
||||
0x29, 0x11); // AND #$11
|
||||
cpu.step(2);
|
||||
assertTrue(cpu.getZeroFlag());
|
||||
}
|
||||
|
||||
public void test_AND_DoesNotSetZeroFlagIfResultNotZero() {
|
||||
public void test_AND_DoesNotSetZeroFlagIfResultNotZero() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa9, 0x88, // LDA #$88
|
||||
0x29, 0xf1); // AND #$F1
|
||||
cpu.step(2);
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
}
|
||||
|
||||
public void test_AND_SetsNegativeFlagIfResultIsNegative() {
|
||||
public void test_AND_SetsNegativeFlagIfResultIsNegative() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa9, 0x88, // LDA #$88
|
||||
0x29, 0xf0); // AND #$F0
|
||||
cpu.step(2);
|
||||
assertTrue(cpu.getNegativeFlag());
|
||||
}
|
||||
|
||||
public void test_AND_DoesNotSetNegativeFlagIfResultNotNegative() {
|
||||
public void test_AND_DoesNotSetNegativeFlagIfResultNotNegative() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa9, 0x88, // LDA #$88
|
||||
0x29, 0x0f); // AND #$0F
|
||||
cpu.step(2);
|
||||
@@ -152,7 +153,7 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
|
||||
/* EOR Immediate Mode Tests - 0x49 */
|
||||
|
||||
public void test_EOR() {
|
||||
public void test_EOR() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa9, 0x88, // LDA #$88
|
||||
0x49, 0x00, // EOR #$00
|
||||
0x49, 0xff, // EOR #$ff
|
||||
@@ -167,7 +168,7 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
assertEquals(0x44, cpu.getAccumulator());
|
||||
}
|
||||
|
||||
public void test_EOR_SetsArithmeticFlags() {
|
||||
public void test_EOR_SetsArithmeticFlags() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa9, 0x77, // LDA #$77
|
||||
0x49, 0x77, // EOR #$77
|
||||
0x49, 0xff); // EOR #$ff
|
||||
@@ -184,7 +185,7 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
|
||||
/* ADC Immediate Mode Tests - 0x69 */
|
||||
|
||||
public void test_ADC() {
|
||||
public void test_ADC() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa9, 0x00, // LDA #$00
|
||||
0x69, 0x01); // ADC #$01
|
||||
cpu.step(2);
|
||||
@@ -265,7 +266,7 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
assertTrue(cpu.getCarryFlag());
|
||||
}
|
||||
|
||||
public void test_ADC_IncludesCarry() {
|
||||
public void test_ADC_IncludesCarry() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa9, 0x00, // LDA #$01
|
||||
0x38, // SEC
|
||||
0x69, 0x01); // ADC #$01
|
||||
@@ -277,7 +278,7 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
assertFalse(cpu.getCarryFlag());
|
||||
}
|
||||
|
||||
public void test_ADC_DecimalMode() {
|
||||
public void test_ADC_DecimalMode() throws MemoryAccessException {
|
||||
bus.loadProgram(0xf8, // SED
|
||||
0xa9, 0x01, // LDA #$01
|
||||
0x69, 0x01); // ADC #$01
|
||||
@@ -357,31 +358,31 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
|
||||
/* LDY Immediate Mode Tests - 0xa0 */
|
||||
|
||||
public void test_LDY_SetsYRegister() {
|
||||
public void test_LDY_SetsYRegister() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa0, 0x12); // LDY #$12
|
||||
cpu.step();
|
||||
assertEquals(0x12, cpu.getYRegister());
|
||||
}
|
||||
|
||||
public void test_LDY_SetsZeroFlagIfArgIsZero() {
|
||||
public void test_LDY_SetsZeroFlagIfArgIsZero() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa0, 0x00); // LDY #$00
|
||||
cpu.step();
|
||||
assertTrue(cpu.getZeroFlag());
|
||||
}
|
||||
|
||||
public void test_LDY_DoesNotSetZeroFlagIfResultNotZero() {
|
||||
public void test_LDY_DoesNotSetZeroFlagIfResultNotZero() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa0, 0x12); // LDY #$12
|
||||
cpu.step();
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
}
|
||||
|
||||
public void test_LDY_SetsNegativeFlagIfResultIsNegative() {
|
||||
public void test_LDY_SetsNegativeFlagIfResultIsNegative() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa0, 0x80); // LDY #$80
|
||||
cpu.step();
|
||||
assertTrue(cpu.getNegativeFlag());
|
||||
}
|
||||
|
||||
public void test_LDY_DoesNotSetNegativeFlagIfResultNotNegative() {
|
||||
public void test_LDY_DoesNotSetNegativeFlagIfResultNotNegative() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa0, 0x7f); // LDY #$7F
|
||||
cpu.step();
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
@@ -389,31 +390,31 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
|
||||
/* LDX Immediate Mode Tests - 0xa2 */
|
||||
|
||||
public void test_LDX_SetsXRegister() {
|
||||
public void test_LDX_SetsXRegister() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa2, 0x12); // LDX #$12
|
||||
cpu.step();
|
||||
assertEquals(0x12, cpu.getXRegister());
|
||||
}
|
||||
|
||||
public void test_LDX_SetsZeroFlagIfResultIsZero() {
|
||||
public void test_LDX_SetsZeroFlagIfResultIsZero() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa2, 0x00); // LDX #$00
|
||||
cpu.step();
|
||||
assertTrue(cpu.getZeroFlag());
|
||||
}
|
||||
|
||||
public void test_LDX_DoesNotSetZeroFlagIfResultNotZero() {
|
||||
public void test_LDX_DoesNotSetZeroFlagIfResultNotZero() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa2, 0x12); // LDX #$12
|
||||
cpu.step();
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
}
|
||||
|
||||
public void test_LDX_SetsNegativeFlagIfResultIsNegative() {
|
||||
public void test_LDX_SetsNegativeFlagIfResultIsNegative() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa2, 0x80); // LDX #$80
|
||||
cpu.step();
|
||||
assertTrue(cpu.getNegativeFlag());
|
||||
}
|
||||
|
||||
public void test_LDX_DoesNotSetNegativeFlagIfResultNotNegative() {
|
||||
public void test_LDX_DoesNotSetNegativeFlagIfResultNotNegative() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa2, 0x7f); // LDX #$7F
|
||||
cpu.step();
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
@@ -421,31 +422,31 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
|
||||
/* LDA Immediate Mode Tests - 0xa9 */
|
||||
|
||||
public void test_LDA_SetsAccumulator() {
|
||||
public void test_LDA_SetsAccumulator() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa9, 0x12); // LDA #$12
|
||||
cpu.step();
|
||||
assertEquals(0x12, cpu.getAccumulator());
|
||||
}
|
||||
|
||||
public void test_LDA_SetsZeroFlagIfResultIsZero() {
|
||||
public void test_LDA_SetsZeroFlagIfResultIsZero() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa9, 0x00); // LDA #$00
|
||||
cpu.step();
|
||||
assertTrue(cpu.getZeroFlag());
|
||||
}
|
||||
|
||||
public void test_LDA_DoesNotSetZeroFlagIfResultNotZero() {
|
||||
public void test_LDA_DoesNotSetZeroFlagIfResultNotZero() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa9, 0x12); // LDA #$12
|
||||
cpu.step();
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
}
|
||||
|
||||
public void test_LDA_SetsNegativeFlagIfResultIsNegative() {
|
||||
public void test_LDA_SetsNegativeFlagIfResultIsNegative() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa9, 0x80); // LDA #$80
|
||||
cpu.step();
|
||||
assertTrue(cpu.getNegativeFlag());
|
||||
}
|
||||
|
||||
public void test_LDA_DoesNotSetNegativeFlagIfResultNotNegative() {
|
||||
public void test_LDA_DoesNotSetNegativeFlagIfResultNotNegative() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa9, 0x7f); // LDA #$7F
|
||||
cpu.step();
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
@@ -453,7 +454,7 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
|
||||
/* CPY Immediate Mode Tests - 0xc0 */
|
||||
|
||||
public void test_CPY_SetsZeroAndCarryFlagsIfNumbersSame() {
|
||||
public void test_CPY_SetsZeroAndCarryFlagsIfNumbersSame() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa0, 0x00, // LDY #$00
|
||||
0xc0, 0x00); // CPY #$00
|
||||
cpu.step(2);
|
||||
@@ -486,7 +487,7 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
}
|
||||
|
||||
public void test_CPY_SetsCarryFlagIfYGreaterThanMemory() {
|
||||
public void test_CPY_SetsCarryFlagIfYGreaterThanMemory() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa0, 0x0a, // LDY #$0A
|
||||
0xc0, 0x08); // CPY #$08
|
||||
cpu.step(2);
|
||||
@@ -505,7 +506,7 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
assertTrue(cpu.getNegativeFlag());
|
||||
}
|
||||
|
||||
public void test_CPY_DoesNotSetCarryFlagIfYLessThanThanMemory() {
|
||||
public void test_CPY_DoesNotSetCarryFlagIfYLessThanThanMemory() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa0, 0x08, // LDY #$08
|
||||
0xc0, 0x0a); // CPY #$0A
|
||||
cpu.step(2);
|
||||
@@ -524,7 +525,7 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
|
||||
/* CMP Immediate Mode Tests - 0xc9 */
|
||||
|
||||
public void test_CMP_SetsZeroAndCarryFlagsIfNumbersSame() {
|
||||
public void test_CMP_SetsZeroAndCarryFlagsIfNumbersSame() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa9, 0x00, // LDA #$00
|
||||
0xc9, 0x00); // CMP #$00
|
||||
cpu.step(2);
|
||||
@@ -557,7 +558,7 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
}
|
||||
|
||||
public void test_CMP_SetsCarryFlagIfYGreaterThanMemory() {
|
||||
public void test_CMP_SetsCarryFlagIfYGreaterThanMemory() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa9, 0x0a, // LDA #$0A
|
||||
0xc9, 0x08); // CMP #$08
|
||||
cpu.step(2);
|
||||
@@ -576,7 +577,7 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
assertTrue(cpu.getNegativeFlag());
|
||||
}
|
||||
|
||||
public void test_CMP_DoesNotSetCarryFlagIfYGreaterThanMemory() {
|
||||
public void test_CMP_DoesNotSetCarryFlagIfYGreaterThanMemory() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa9, 0x08, // LDA #$08
|
||||
0xc9, 0x0a); // CMP #$0A
|
||||
cpu.step(2);
|
||||
@@ -595,7 +596,7 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
|
||||
/* CPX Immediate Mode Tests - 0xe0 */
|
||||
|
||||
public void test_CPX_SetsZeroAndCarryFlagsIfNumbersSame() {
|
||||
public void test_CPX_SetsZeroAndCarryFlagsIfNumbersSame() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa2, 0x00, // LDX #$00
|
||||
0xe0, 0x00); // CPX #$00
|
||||
cpu.step(2);
|
||||
@@ -628,7 +629,7 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
}
|
||||
|
||||
public void test_CPX_SetsCarryFlagIfYGreaterThanMemory() {
|
||||
public void test_CPX_SetsCarryFlagIfYGreaterThanMemory() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa2, 0x0a, // LDX #$0A
|
||||
0xe0, 0x08); // CPX #$08
|
||||
cpu.step(2);
|
||||
@@ -647,7 +648,7 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
assertTrue(cpu.getNegativeFlag());
|
||||
}
|
||||
|
||||
public void test_CPX_DoesNotSetCarryFlagIfYGreaterThanMemory() {
|
||||
public void test_CPX_DoesNotSetCarryFlagIfYGreaterThanMemory() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa2, 0x08, // LDX #$08
|
||||
0xe0, 0x0a); // CPX #$0A
|
||||
cpu.step(2);
|
||||
@@ -666,7 +667,7 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
|
||||
/* SBC Immediate Mode Tests - 0xe9 */
|
||||
|
||||
public void test_SBC() {
|
||||
public void test_SBC() throws MemoryAccessException {
|
||||
bus.loadProgram(0xa9, 0x00, // LDA #$00
|
||||
0xe9, 0x01); // SBC #$01
|
||||
cpu.step(2);
|
||||
@@ -717,7 +718,7 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
assertTrue(cpu.getCarryFlag());
|
||||
}
|
||||
|
||||
public void test_SBC_IncludesNotOfCarry() {
|
||||
public void test_SBC_IncludesNotOfCarry() throws MemoryAccessException {
|
||||
// Subtrace with Carry Flag cleared
|
||||
bus.loadProgram(0x18, // CLC
|
||||
0xa9, 0x05, // LDA #$00
|
||||
@@ -758,7 +759,7 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
public void test_SBC_DecimalMode() {
|
||||
public void test_SBC_DecimalMode() throws MemoryAccessException {
|
||||
bus.loadProgram(0xf8,
|
||||
0xa9, 0x00,
|
||||
0xe9, 0x01);
|
||||
|
||||
Reference in new issue
Block a user