- 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:
Seth J. Morabito committed 2010-01-09 16:53:04 -08:00
1 parent a01090a16e
commit ac88786df7
21 files changed
+465 -446

No files matched your search

@@ -5,8 +5,6 @@ import junit.framework.*;
import com.loomcom.symon.devices.*;
import com.loomcom.symon.exceptions.*;
import java.util.*;
/**
*
*/
@@ -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.MemoryAccessException;
import junit.framework.TestCase;
public class CpuAbsoluteModeTest extends TestCase {
@@ -65,7 +66,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* ORA - Logical Inclusive OR - $0d */
public void test_ORA() {
public void test_ORA() throws MemoryAccessException {
// Set some initial values in memory
bus.write(0x7f00, 0x00);
bus.write(0x7f02, 0x11);
@@ -78,27 +79,27 @@ public class CpuAbsoluteModeTest extends TestCase {
0x0d, 0x04, 0x35, // ORA $3504
0x0d, 0x08, 0x35, // ORA $3508
0x0d, 0x10, 0x12); // ORA $1210
cpu.step();
extracted();
assertEquals(0x00, cpu.getAccumulator());
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
cpu.step();
extracted();
assertEquals(0x11, cpu.getAccumulator());
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
cpu.step();
extracted();
assertEquals(0x33, cpu.getAccumulator());
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
cpu.step();
extracted();
assertEquals(0x77, cpu.getAccumulator());
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
cpu.step();
extracted();
assertEquals(0xff, cpu.getAccumulator());
assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag());
@@ -106,7 +107,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* ASL - Arithmetic Shift Left - $0e */
public void test_ASL() {
public void test_ASL() throws MemoryAccessException {
bus.write(0x7f00, 0x00);
bus.write(0x7f01, 0x01);
bus.write(0x3502, 0x02);
@@ -119,31 +120,31 @@ public class CpuAbsoluteModeTest extends TestCase {
0x0e, 0x03, 0x35, // ASL $3503
0x0e, 0x04, 0x12); // ASL $1204
cpu.step();
extracted();
assertEquals(0x00, bus.read(0x7f00));
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x02, bus.read(0x7f01));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x04, bus.read(0x3502));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x88, bus.read(0x3503));
assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x00, bus.read(0x1204));
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
@@ -152,7 +153,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* JSR - Jump to Subroutine - $20 */
public void test_JSR() {
public void test_JSR() throws MemoryAccessException {
bus.loadProgram(0xea, // NOP
0xea, // NOP
0x20, 0x00, 0x34); // JSR $3400
@@ -173,7 +174,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* BIT - Bit Test - $2c */
public void test_BIT() {
public void test_BIT() throws MemoryAccessException {
bus.write(0x1200, 0xc0);
bus.loadProgram(0xa9, 0x01, // LDA #$01
@@ -227,7 +228,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* AND - Logical AND - $2d */
public void test_AND() {
public void test_AND() throws MemoryAccessException {
bus.write(0x1200, 0x00);
bus.write(0x1201, 0x11);
bus.write(0x1202, 0xff);
@@ -243,12 +244,12 @@ public class CpuAbsoluteModeTest extends TestCase {
0x2d, 0x04, 0x12, // AND $1204
0xa9, 0xff, // LDA #$ff
0x2d, 0x05, 0x12); // AND $1205
cpu.step();
extracted();
assertEquals(0x00, cpu.getAccumulator());
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
cpu.step();
extracted();
assertEquals(0x00, cpu.getAccumulator());
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
@@ -258,12 +259,12 @@ public class CpuAbsoluteModeTest extends TestCase {
assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag());
cpu.step();
extracted();
assertEquals(0x88, cpu.getAccumulator());
assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag());
cpu.step();
extracted();
assertEquals(0x00, cpu.getAccumulator());
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
@@ -276,7 +277,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* ROL - Rotate Shift Left - $2e */
public void test_ROL() {
public void test_ROL() throws MemoryAccessException {
bus.write(0x1200, 0x00);
bus.write(0x1201, 0x01);
@@ -293,13 +294,13 @@ public class CpuAbsoluteModeTest extends TestCase {
0x2e, 0x01, 0x12, // ROL $1201 (m=%01000000, c=1)
0x2e, 0x01, 0x12); // ROL $1201 (m=%10000001, c=0)
cpu.step();
extracted();
assertEquals(0x00, bus.read(0x1200));
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x02, bus.read(0x1201));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
@@ -311,43 +312,43 @@ public class CpuAbsoluteModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x0a, bus.read(0x1201));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x14, bus.read(0x1201));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x28, bus.read(0x1201));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x50, bus.read(0x1201));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0xa0, bus.read(0x1201));
assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x40, bus.read(0x1201));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
assertTrue(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x81, bus.read(0x1201));
assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag());
@@ -356,17 +357,21 @@ public class CpuAbsoluteModeTest extends TestCase {
/* JMP - Jump - $4c */
public void test_JMP() {
public void test_JMP() throws MemoryAccessException {
bus.loadProgram(0x4c, 0x00, 0x34);
cpu.step();
extracted();
assertEquals(0x3400, cpu.getProgramCounter());
// No change to status flags.
assertEquals(0x20, cpu.getProcessorStatus());
}
private void extracted() throws MemoryAccessException {
cpu.step();
}
/* EOR - Exclusive OR - $4d */
public void test_EOR() {
public void test_EOR() throws MemoryAccessException {
bus.write(0x1210, 0x00);
bus.write(0x1211, 0xff);
bus.write(0x1212, 0x33);
@@ -382,17 +387,17 @@ public class CpuAbsoluteModeTest extends TestCase {
assertTrue(cpu.getNegativeFlag());
assertFalse(cpu.getZeroFlag());
cpu.step();
extracted();
assertEquals(0x77, cpu.getAccumulator());
assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getZeroFlag());
cpu.step();
extracted();
assertEquals(0x44, cpu.getAccumulator());
assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getZeroFlag());
cpu.step();
extracted();
assertEquals(0x00, cpu.getAccumulator());
assertFalse(cpu.getNegativeFlag());
assertTrue(cpu.getZeroFlag());
@@ -400,7 +405,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* LSR - Logical Shift Right - $4e */
public void test_LSR() {
public void test_LSR() throws MemoryAccessException {
bus.write(0x1200, 0x00);
bus.write(0x1201, 0x01);
bus.write(0x1202, 0x02);
@@ -416,31 +421,31 @@ public class CpuAbsoluteModeTest extends TestCase {
0x38, // SEC
0x4e, 0x05, 0x12); // LSR $1205
cpu.step();
extracted();
assertEquals(0x00, bus.read(0x1200));
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x00, bus.read(0x1201));
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
assertTrue(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x01, bus.read(0x1202));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x22, bus.read(0x1203));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x40, bus.read(0x1204));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
@@ -456,7 +461,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* ADC - Add with Carry - $6d */
public void test_ADC() {
public void test_ADC() throws MemoryAccessException {
bus.write(0x1210, 0x01);
bus.write(0x1211, 0xff);
@@ -540,7 +545,7 @@ public class CpuAbsoluteModeTest extends TestCase {
assertTrue(cpu.getCarryFlag());
}
public void test_ADC_IncludesCarry() {
public void test_ADC_IncludesCarry() throws MemoryAccessException {
bus.write(0x1210, 0x01);
bus.loadProgram(0xa9, 0x00, // LDA #$00
@@ -554,7 +559,7 @@ public class CpuAbsoluteModeTest extends TestCase {
assertFalse(cpu.getCarryFlag());
}
public void test_ADC_DecimalMode() {
public void test_ADC_DecimalMode() throws MemoryAccessException {
bus.write(0x1210, 0x01);
bus.write(0x1211, 0x99);
@@ -637,7 +642,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* ROR - Rotate Right - $6e */
public void test_ROR() {
public void test_ROR() throws MemoryAccessException {
bus.write(0x1210, 0x00);
bus.write(0x1211, 0x10);
@@ -652,61 +657,61 @@ public class CpuAbsoluteModeTest extends TestCase {
0x6e, 0x11, 0x12, // ROR $1201 (m=%00100000, c=0)
0x6e, 0x11, 0x12); // ROR $1201 (m=%00010000, c=0)
cpu.step();
extracted();
assertEquals(0x00, bus.read(0x1210));
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x08, bus.read(0x1211));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x04, bus.read(0x1211));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x02, bus.read(0x1211));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x01, bus.read(0x1211));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x00, bus.read(0x1211));
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
assertTrue(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x80, bus.read(0x1211));
assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x40, bus.read(0x1211));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x20, bus.read(0x1211));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag());
cpu.step();
extracted();
assertEquals(0x10, bus.read(0x1211));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
@@ -715,10 +720,10 @@ public class CpuAbsoluteModeTest extends TestCase {
/* STY - Store Y Register - $8c */
public void test_STY() {
public void test_STY() throws MemoryAccessException {
cpu.setYRegister(0x00);
bus.loadProgram(0x8c, 0x10, 0x12);
cpu.step();
extracted();
assertEquals(0x00, bus.read(0x1210));
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
@@ -727,7 +732,7 @@ public class CpuAbsoluteModeTest extends TestCase {
cpu.setYRegister(0x0f);
bus.loadProgram(0x8c, 0x10, 0x12);
cpu.step();
extracted();
assertEquals(0x0f, bus.read(0x1210));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
@@ -736,7 +741,7 @@ public class CpuAbsoluteModeTest extends TestCase {
cpu.setYRegister(0x80);
bus.loadProgram(0x8c, 0x10, 0x12);
cpu.step();
extracted();
assertEquals(0x80, bus.read(0x1210));
assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag());
@@ -744,10 +749,10 @@ public class CpuAbsoluteModeTest extends TestCase {
/* STA - Store Accumulator - $8d */
public void test_STA() {
public void test_STA() throws MemoryAccessException {
cpu.setAccumulator(0x00);
bus.loadProgram(0x8d, 0x10, 0x12);
cpu.step();
extracted();
assertEquals(0x00, bus.read(0x1210));
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
@@ -756,7 +761,7 @@ public class CpuAbsoluteModeTest extends TestCase {
cpu.setAccumulator(0x0f);
bus.loadProgram(0x8d, 0x10, 0x12);
cpu.step();
extracted();
assertEquals(0x0f, bus.read(0x1210));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
@@ -765,7 +770,7 @@ public class CpuAbsoluteModeTest extends TestCase {
cpu.setAccumulator(0x80);
bus.loadProgram(0x8d, 0x10, 0x12);
cpu.step();
extracted();
assertEquals(0x80, bus.read(0x1210));
assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag());
@@ -773,10 +778,10 @@ public class CpuAbsoluteModeTest extends TestCase {
/* STX - Store X Register - $8e */
public void test_STX() {
public void test_STX() throws MemoryAccessException {
cpu.setXRegister(0x00);
bus.loadProgram(0x8e, 0x10, 0x12);
cpu.step();
extracted();
assertEquals(0x00, bus.read(0x1210));
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
@@ -785,7 +790,7 @@ public class CpuAbsoluteModeTest extends TestCase {
cpu.setXRegister(0x0f);
bus.loadProgram(0x8e, 0x10, 0x12);
cpu.step();
extracted();
assertEquals(0x0f, bus.read(0x1210));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
@@ -794,7 +799,7 @@ public class CpuAbsoluteModeTest extends TestCase {
cpu.setXRegister(0x80);
bus.loadProgram(0x8e, 0x10, 0x12);
cpu.step();
extracted();
assertEquals(0x80, bus.read(0x1210));
assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag());
@@ -802,7 +807,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* LDA - Load Accumulator - $ad */
public void test_LDA() {
public void test_LDA() throws MemoryAccessException {
bus.write(0x1210, 0x00);
bus.write(0x1211, 0x0f);
bus.write(0x1212, 0x80);
@@ -811,17 +816,17 @@ public class CpuAbsoluteModeTest extends TestCase {
0xad, 0x11, 0x12, // LDA $1211
0xad, 0x12, 0x12); // LDA $1212
cpu.step();
extracted();
assertEquals(0x00, cpu.getAccumulator());
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
cpu.step();
extracted();
assertEquals(0x0f, cpu.getAccumulator());
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
cpu.step();
extracted();
assertEquals(0x80, cpu.getAccumulator());
assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag());
@@ -829,7 +834,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* LDX - Load X Register - $ae */
public void test_LDX() {
public void test_LDX() throws MemoryAccessException {
bus.write(0x1210, 0x00);
bus.write(0x1211, 0x0f);
bus.write(0x1212, 0x80);
@@ -838,17 +843,17 @@ public class CpuAbsoluteModeTest extends TestCase {
0xae, 0x11, 0x12, // LDX $1211
0xae, 0x12, 0x12); // LDX $1212
cpu.step();
extracted();
assertEquals(0x00, cpu.getXRegister());
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
cpu.step();
extracted();
assertEquals(0x0f, cpu.getXRegister());
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
cpu.step();
extracted();
assertEquals(0x80, cpu.getXRegister());
assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag());
@@ -856,7 +861,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* LDY - Load Y Register - $bc */
public void test_LDY() {
public void test_LDY() throws MemoryAccessException {
bus.write(0x1210, 0x00);
bus.write(0x1211, 0x0f);
bus.write(0x1212, 0x80);
@@ -865,17 +870,17 @@ public class CpuAbsoluteModeTest extends TestCase {
0xbc, 0x11, 0x12, // LDY $1211
0xbc, 0x12, 0x12); // LDY $1212
cpu.step();
extracted();
assertEquals(0x00, cpu.getYRegister());
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
cpu.step();
extracted();
assertEquals(0x0f, cpu.getYRegister());
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
cpu.step();
extracted();
assertEquals(0x80, cpu.getYRegister());
assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag());
@@ -883,7 +888,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* CMP - Compare Accumulator - $cd */
public void test_CMP() {
public void test_CMP() throws MemoryAccessException {
bus.write(0x1210, 0x00);
bus.write(0x1211, 0x80);
bus.write(0x1212, 0xff);
@@ -894,17 +899,17 @@ public class CpuAbsoluteModeTest extends TestCase {
0xcd, 0x11, 0x12, // CMP $1211
0xcd, 0x12, 0x12); // CMP $1212
cpu.step();
extracted();
assertTrue(cpu.getCarryFlag()); // m > y
assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag()); // m - y < 0
cpu.step();
extracted();
assertTrue(cpu.getCarryFlag()); // m = y
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); // m - y == 0
cpu.step();
extracted();
assertFalse(cpu.getCarryFlag()); // m < y
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); // m - y > 0
@@ -912,7 +917,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* CPY - Compare Y Register - $cc */
public void test_CPY() {
public void test_CPY() throws MemoryAccessException {
bus.write(0x1210, 0x00);
bus.write(0x1211, 0x80);
bus.write(0x1212, 0xff);
@@ -923,17 +928,17 @@ public class CpuAbsoluteModeTest extends TestCase {
0xcc, 0x11, 0x12, // CPY $1211
0xcc, 0x12, 0x12); // CPY $1212
cpu.step();
extracted();
assertTrue(cpu.getCarryFlag()); // m > y
assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag()); // m - y < 0
cpu.step();
extracted();
assertTrue(cpu.getCarryFlag()); // m = y
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); // m - y == 0
cpu.step();
extracted();
assertFalse(cpu.getCarryFlag()); // m < y
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); // m - y > 0
@@ -941,7 +946,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* DEC - Decrement Memory Location - $ce */
public void test_DEC() {
public void test_DEC() throws MemoryAccessException {
bus.write(0x1210, 0x00);
bus.write(0x1211, 0x01);
bus.write(0x1212, 0x80);
@@ -952,22 +957,22 @@ public class CpuAbsoluteModeTest extends TestCase {
0xce, 0x12, 0x12, // DEC $1212
0xce, 0x13, 0x12); // DEC $1213
cpu.step();
extracted();
assertEquals(0xff, bus.read(0x1210));
assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag());
cpu.step();
extracted();
assertEquals(0x00, bus.read(0x1211));
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
cpu.step();
extracted();
assertEquals(0x7f, bus.read(0x1212));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
cpu.step();
extracted();
assertEquals(0xfe, bus.read(0x1213));
assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag());
@@ -975,7 +980,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* CPX - Compare X Register - $ec */
public void test_CPX() {
public void test_CPX() throws MemoryAccessException {
bus.write(0x1210, 0x00);
bus.write(0x1211, 0x80);
bus.write(0x1212, 0xff);
@@ -986,17 +991,17 @@ public class CpuAbsoluteModeTest extends TestCase {
0xec, 0x11, 0x12, // CPX $1211
0xec, 0x12, 0x12); // CPX $1212
cpu.step();
extracted();
assertTrue(cpu.getCarryFlag()); // m > y
assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag()); // m - y < 0
cpu.step();
extracted();
assertTrue(cpu.getCarryFlag()); // m = y
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); // m - y == 0
cpu.step();
extracted();
assertFalse(cpu.getCarryFlag()); // m < y
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); // m - y > 0
@@ -1004,7 +1009,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* SBC - Subtract with Carry (borrow) - $ed */
public void test_SBC() {
public void test_SBC() throws MemoryAccessException {
bus.write(0x1210, 0x01);
bus.loadProgram(0xa9, 0x00, // LDA #$00
@@ -1057,7 +1062,7 @@ public class CpuAbsoluteModeTest extends TestCase {
assertTrue(cpu.getCarryFlag());
}
public void test_SBC_IncludesNotOfCarry() {
public void test_SBC_IncludesNotOfCarry() throws MemoryAccessException {
bus.write(0x1210, 0x01);
// Subtrace with Carry Flag cleared
@@ -1100,7 +1105,7 @@ public class CpuAbsoluteModeTest extends TestCase {
}
public void test_SBC_DecimalMode() {
public void test_SBC_DecimalMode() throws MemoryAccessException {
bus.write(0x1210, 0x01);
bus.write(0x1220, 0x11);
@@ -1199,7 +1204,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* INC - Increment Memory Location - $ee */
public void test_INC() {
public void test_INC() throws MemoryAccessException {
bus.write(0x1210, 0x00);
bus.write(0x1211, 0x7f);
bus.write(0x1212, 0xff);
@@ -1208,17 +1213,17 @@ public class CpuAbsoluteModeTest extends TestCase {
0xee, 0x11, 0x12, // INC $1211
0xee, 0x12, 0x12); // INC $1212
cpu.step();
extracted();
assertEquals(0x01, bus.read(0x1210));
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
cpu.step();
extracted();
assertEquals(0x80, bus.read(0x1211));
assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag());
cpu.step();
extracted();
assertEquals(0x00, bus.read(0x1212));
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag());
@@ -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.MemoryAccessException;
import junit.framework.TestCase;
public class CpuAbsoluteXModeTest extends TestCase {
@@ -53,7 +54,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* ORA - Logical Inclusive OR - $1d */
public void test_ORA() {
public void test_ORA() throws MemoryAccessException {
// Set some initial values in memory
bus.write(0x2c30, 0x00);
bus.write(0x2c32, 0x11);
@@ -99,7 +100,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* ASL - Arithmetic Shift Left - $1e */
public void test_ASL() {
public void test_ASL() throws MemoryAccessException {
bus.write(0x2c30, 0x00);
bus.write(0x2c31, 0x01);
bus.write(0x2c32, 0x02);
@@ -148,7 +149,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* AND - Logical AND - $3d */
public void test_AND() {
public void test_AND() throws MemoryAccessException {
bus.write(0x1a30, 0x00);
bus.write(0x1a31, 0x11);
bus.write(0x1a32, 0xff);
@@ -208,8 +209,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* ROL - Rotate Shift Left - $3e */
public void test_ROL() {
public void test_ROL() throws MemoryAccessException {
bus.write(0x1070, 0x00);
bus.write(0x1071, 0x01);
@@ -291,7 +291,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* EOR - Exclusive OR - $5d */
public void test_EOR() {
public void test_EOR() throws MemoryAccessException {
bus.write(0xab40, 0x00);
bus.write(0xab41, 0xff);
bus.write(0xab42, 0x33);
@@ -327,7 +327,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* LSR - Logical Shift Right - $5e */
public void test_LSR() {
public void test_LSR() throws MemoryAccessException {
bus.write(0xab30, 0x00);
bus.write(0xab31, 0x01);
bus.write(0xab32, 0x02);
@@ -385,7 +385,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* ADC - Add with Carry - $7d */
public void test_ADC() {
public void test_ADC() throws MemoryAccessException {
bus.write(0xab40, 0x01);
bus.write(0xab41, 0xff);
@@ -471,7 +471,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
assertTrue(cpu.getCarryFlag());
}
public void test_ADC_IncludesCarry() {
public void test_ADC_IncludesCarry() throws MemoryAccessException {
bus.write(0xab40, 0x01);
bus.loadProgram(0xa9, 0x00, // LDA #$00
@@ -488,7 +488,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
assertFalse(cpu.getCarryFlag());
}
public void test_ADC_DecimalMode() {
public void test_ADC_DecimalMode() throws MemoryAccessException {
bus.write(0xab40, 0x01);
bus.write(0xab41, 0x99);
@@ -574,7 +574,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* ROR - Rotate Right - $7e */
public void test_ROR() {
public void test_ROR() throws MemoryAccessException {
bus.write(0xab40, 0x00);
bus.write(0xab41, 0x10);
@@ -655,7 +655,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* STA - Store Accumulator - $9d */
public void test_STA() {
public void test_STA() throws MemoryAccessException {
cpu.setXRegister(0x30);
cpu.setAccumulator(0x00);
@@ -686,7 +686,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* LDY - Load Y Register - $bc */
public void test_LDY() {
public void test_LDY() throws MemoryAccessException {
bus.write(0xab45, 0x00);
bus.write(0xab46, 0x0f);
bus.write(0xab47, 0x80);
@@ -715,7 +715,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* LDA - Load Accumulator - $bd */
public void test_LDA() {
public void test_LDA() throws MemoryAccessException {
bus.write(0xab42, 0x00);
bus.write(0xab43, 0x0f);
bus.write(0xab44, 0x80);
@@ -744,7 +744,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* CMP - Compare Accumulator - $dd */
public void test_CMP() {
public void test_CMP() throws MemoryAccessException {
bus.write(0xab40, 0x00);
bus.write(0xab41, 0x80);
bus.write(0xab42, 0xff);
@@ -775,7 +775,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* DEC - Decrement Memory Location - $de */
public void test_DEC() {
public void test_DEC() throws MemoryAccessException {
bus.write(0xab40, 0x00);
bus.write(0xab41, 0x01);
bus.write(0xab42, 0x80);
@@ -811,7 +811,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* SBC - Subtract with Carry - $fd */
public void test_SBC() {
public void test_SBC() throws MemoryAccessException {
bus.write(0xab40, 0x01);
bus.loadProgram(0xa9, 0x00, // LDA #$00
@@ -869,7 +869,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
assertTrue(cpu.getCarryFlag());
}
public void test_SBC_IncludesNotOfCarry() {
public void test_SBC_IncludesNotOfCarry() throws MemoryAccessException {
bus.write(0xab40, 0x01);
// Subtrace with Carry Flag cleared
@@ -914,7 +914,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
}
public void test_SBC_DecimalMode() {
public void test_SBC_DecimalMode() throws MemoryAccessException {
bus.write(0xab40, 0x01);
bus.write(0xab50, 0x11);
@@ -1020,7 +1020,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* INC - Increment Memory Location - $fe */
public void test_INC() {
public void test_INC() throws MemoryAccessException {
bus.write(0xab30, 0x00);
bus.write(0xab31, 0x7f);
bus.write(0xab32, 0xff);
@@ -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.MemoryAccessException;
import junit.framework.TestCase;
public class CpuAbsoluteYModeTest extends TestCase {
@@ -47,7 +48,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
/* ORA - Logical Inclusive OR - $19 */
public void test_ORA() {
public void test_ORA() throws MemoryAccessException {
// Set some initial values in memory
bus.write(0x2c30, 0x00);
bus.write(0x2c32, 0x11);
@@ -93,7 +94,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
/* AND - Logical AND - $39 */
public void test_AND() {
public void test_AND() throws MemoryAccessException {
bus.write(0x1a30, 0x00);
bus.write(0x1a31, 0x11);
bus.write(0x1a32, 0xff);
@@ -153,7 +154,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
/* EOR - Exclusive OR - $59 */
public void test_EOR() {
public void test_EOR() throws MemoryAccessException {
bus.write(0xab40, 0x00);
bus.write(0xab41, 0xff);
bus.write(0xab42, 0x33);
@@ -189,7 +190,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
/* ADC - Add with Carry - $79 */
public void test_ADC() {
public void test_ADC() throws MemoryAccessException {
bus.write(0xab40, 0x01);
bus.write(0xab41, 0xff);
@@ -275,7 +276,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
assertTrue(cpu.getCarryFlag());
}
public void test_ADC_IncludesCarry() {
public void test_ADC_IncludesCarry() throws MemoryAccessException {
bus.write(0xab40, 0x01);
bus.loadProgram(0xa9, 0x00, // LDA #$00
@@ -292,7 +293,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
assertFalse(cpu.getCarryFlag());
}
public void test_ADC_DecimalMode() {
public void test_ADC_DecimalMode() throws MemoryAccessException {
bus.write(0xab40, 0x01);
bus.write(0xab41, 0x99);
@@ -378,7 +379,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
/* STA - Store Accumulator - $99 */
public void test_STA() {
public void test_STA() throws MemoryAccessException {
cpu.setYRegister(0x30);
cpu.setAccumulator(0x00);
@@ -409,7 +410,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
/* LDX - Load X Register - $be */
public void test_LDX() {
public void test_LDX() throws MemoryAccessException {
bus.write(0xab45, 0x00);
bus.write(0xab46, 0x0f);
bus.write(0xab47, 0x80);
@@ -438,7 +439,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
/* LDA - Load Accumulator - $b9 */
public void test_LDA() {
public void test_LDA() throws MemoryAccessException {
bus.write(0xab42, 0x00);
bus.write(0xab43, 0x0f);
bus.write(0xab44, 0x80);
@@ -467,7 +468,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
/* CMP - Compare Accumulator - $d9 */
public void test_CMP() {
public void test_CMP() throws MemoryAccessException {
bus.write(0xab40, 0x00);
bus.write(0xab41, 0x80);
bus.write(0xab42, 0xff);
@@ -498,7 +499,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
/* SBC - Subtract with Carry - $f9 */
public void test_SBC() {
public void test_SBC() throws MemoryAccessException {
bus.write(0xab40, 0x01);
bus.loadProgram(0xa9, 0x00, // LDA #$00
@@ -556,7 +557,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
assertTrue(cpu.getCarryFlag());
}
public void test_SBC_IncludesNotOfCarry() {
public void test_SBC_IncludesNotOfCarry() throws MemoryAccessException {
bus.write(0xab40, 0x01);
// Subtrace with Carry Flag cleared
@@ -601,7 +602,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
}
public void test_SBC_DecimalMode() {
public void test_SBC_DecimalMode() throws MemoryAccessException {
bus.write(0xab40, 0x01);
bus.write(0xab50, 0x11);
@@ -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 CpuAccumulatorModeTest extends TestCase {
@@ -10,7 +11,7 @@ public class CpuAccumulatorModeTest 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);
@@ -43,7 +44,7 @@ public class CpuAccumulatorModeTest extends TestCase {
/* ASL - Arithmetic Shift Left - $0a */
public void test_ASL() {
public void test_ASL() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x00, // LDA #$00
0x0a, // ASL A
@@ -92,7 +93,7 @@ public class CpuAccumulatorModeTest extends TestCase {
/* ROL - Rotate Left - $2a */
public void test_ROL() {
public void test_ROL() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x00, // LDA #$00
0x2a, // ROL A (m=%00000000, c=0)
0xa9, 0x01, // LDA #$01
@@ -170,7 +171,7 @@ public class CpuAccumulatorModeTest extends TestCase {
/* LSR - Logical Shift Right - $4a */
public void test_LSR() {
public void test_LSR() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x00, // LDA #$00
0x4a, // LSR A
@@ -230,7 +231,7 @@ public class CpuAccumulatorModeTest extends TestCase {
/* ROR - Rotate Right - $6a */
public void test_ROR() {
public void test_ROR() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x00, // LDA #$00
0x6a, // ROR A (m=%00000000, c=0)
0xa9, 0x10, // LDA #$10
@@ -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);
@@ -1,6 +1,7 @@
package com.loomcom.symon;
import com.loomcom.symon.devices.Memory;
import com.loomcom.symon.exceptions.MemoryAccessException;
import com.loomcom.symon.exceptions.MemoryRangeException;
import junit.framework.*;
@@ -10,7 +11,7 @@ public class CpuImpliedModeTest 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);
@@ -68,7 +69,7 @@ public class CpuImpliedModeTest extends TestCase {
/* BRK Tests - 0x00 */
public void test_BRK() {
public void test_BRK() throws MemoryAccessException {
cpu.setCarryFlag();
cpu.setOverflowFlag();
assertEquals(0x20|Cpu.P_CARRY|Cpu.P_OVERFLOW,
@@ -111,7 +112,7 @@ public class CpuImpliedModeTest extends TestCase {
cpu.getProcessorStatus());
}
public void test_BRK_HonorsIrqDisableFlag() {
public void test_BRK_HonorsIrqDisableFlag() throws MemoryAccessException {
cpu.setIrqDisableFlag();
bus.loadProgram(0xea,
@@ -143,7 +144,7 @@ public class CpuImpliedModeTest extends TestCase {
}
/* CLC - Clear Carry Flag - $18 */
public void test_CLC() {
public void test_CLC() throws MemoryAccessException {
cpu.setCarryFlag();
assertTrue(cpu.getCarryFlag());
@@ -154,7 +155,7 @@ public class CpuImpliedModeTest extends TestCase {
}
/* CLD - Clear Decimal Mode Flag - $d8 */
public void test_CLD() {
public void test_CLD() throws MemoryAccessException {
cpu.setDecimalModeFlag();
assertTrue(cpu.getDecimalModeFlag());
@@ -165,7 +166,7 @@ public class CpuImpliedModeTest extends TestCase {
}
/* CLI - Clear Interrupt Disabled Flag - $58 */
public void test_CLI() {
public void test_CLI() throws MemoryAccessException {
cpu.setIrqDisableFlag();
assertTrue(cpu.getIrqDisableFlag());
@@ -176,7 +177,7 @@ public class CpuImpliedModeTest extends TestCase {
}
/* CLV - Clear Overflow Flag - $b8 */
public void test_CLV() {
public void test_CLV() throws MemoryAccessException {
cpu.setOverflowFlag();
assertTrue(cpu.getOverflowFlag());
@@ -188,7 +189,7 @@ public class CpuImpliedModeTest extends TestCase {
/* DEX - Decrement the X register - $ca */
public void test_DEX() {
public void test_DEX() throws MemoryAccessException {
bus.loadProgram(0xca);
cpu.setXRegister(0x02);
cpu.step();
@@ -197,7 +198,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag());
}
public void test_DEX_SetsZeroFlagWhenZero() {
public void test_DEX_SetsZeroFlagWhenZero() throws MemoryAccessException {
bus.loadProgram(0xca);
cpu.setXRegister(0x01);
cpu.step();
@@ -206,7 +207,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag());
}
public void test_DEX_SetsNegativeFlagWhen() {
public void test_DEX_SetsNegativeFlagWhen() throws MemoryAccessException {
bus.loadProgram(0xca);
cpu.step();
assertEquals(0xff, cpu.getXRegister());
@@ -216,7 +217,7 @@ public class CpuImpliedModeTest extends TestCase {
/* DEY - Decrement the Y register - $88 */
public void test_DEY() {
public void test_DEY() throws MemoryAccessException {
bus.loadProgram(0x88);
cpu.setYRegister(0x02);
cpu.step();
@@ -225,7 +226,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag());
}
public void test_DEY_SetsZeroFlagWhenZero() {
public void test_DEY_SetsZeroFlagWhenZero() throws MemoryAccessException {
bus.loadProgram(0x88);
cpu.setYRegister(0x01);
cpu.step();
@@ -234,7 +235,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag());
}
public void test_DEY_SetsNegativeFlagWhen() {
public void test_DEY_SetsNegativeFlagWhen() throws MemoryAccessException {
bus.loadProgram(0x88);
cpu.step();
assertEquals(0xff, cpu.getYRegister());
@@ -244,7 +245,7 @@ public class CpuImpliedModeTest extends TestCase {
/* INX - Increment the X register - $e8 */
public void test_INX() {
public void test_INX() throws MemoryAccessException {
bus.loadProgram(0xe8);
cpu.step();
assertEquals(0x01, cpu.getXRegister());
@@ -252,7 +253,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag());
}
public void test_INX_SetsNegativeFlagWhenNegative() {
public void test_INX_SetsNegativeFlagWhenNegative() throws MemoryAccessException {
bus.loadProgram(0xe8);
cpu.setXRegister(0x7f);
cpu.step();
@@ -261,7 +262,7 @@ public class CpuImpliedModeTest extends TestCase {
assertTrue(cpu.getNegativeFlag());
}
public void test_INX_SetsZeroFlagWhenZero() {
public void test_INX_SetsZeroFlagWhenZero() throws MemoryAccessException {
bus.loadProgram(0xe8);
cpu.setXRegister(0xff);
cpu.step();
@@ -272,7 +273,7 @@ public class CpuImpliedModeTest extends TestCase {
/* INY - Increment the Y register - $c8 */
public void test_INY() {
public void test_INY() throws MemoryAccessException {
bus.loadProgram(0xc8);
cpu.step();
assertEquals(0x01, cpu.getYRegister());
@@ -280,7 +281,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag());
}
public void test_INY_SetsNegativeFlagWhenNegative() {
public void test_INY_SetsNegativeFlagWhenNegative() throws MemoryAccessException {
bus.loadProgram(0xc8);
cpu.setYRegister(0x7f);
cpu.step();
@@ -289,7 +290,7 @@ public class CpuImpliedModeTest extends TestCase {
assertTrue(cpu.getNegativeFlag());
}
public void test_INY_SetsZeroFlagWhenZero() {
public void test_INY_SetsZeroFlagWhenZero() throws MemoryAccessException {
bus.loadProgram(0xc8);
cpu.setYRegister(0xff);
cpu.step();
@@ -300,7 +301,7 @@ public class CpuImpliedModeTest extends TestCase {
/* NOP - No Operation - $ea */
public void test_NOP() {
public void test_NOP() throws MemoryAccessException {
bus.loadProgram(0xea);
cpu.step();
// Should just not change anything except PC
@@ -314,7 +315,7 @@ public class CpuImpliedModeTest extends TestCase {
/* PHA - Push Accumulator - $48 */
public void test_PHA() {
public void test_PHA() throws MemoryAccessException {
bus.loadProgram(0x48);
cpu.setAccumulator(0x3a);
cpu.step();
@@ -324,7 +325,7 @@ public class CpuImpliedModeTest extends TestCase {
/* PHP - Push Processor Status - $08 */
public void test_PHP() {
public void test_PHP() throws MemoryAccessException {
bus.loadProgram(0x08);
cpu.setProcessorStatus(0x27);
cpu.step();
@@ -334,7 +335,7 @@ public class CpuImpliedModeTest extends TestCase {
/* PLA - Pul Accumulator - $68 */
public void test_PLA() {
public void test_PLA() throws MemoryAccessException {
cpu.stackPush(0x32);
bus.loadProgram(0x68);
cpu.step();
@@ -343,7 +344,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getZeroFlag());
}
public void test_PLA_SetsZeroIfAccumulatorIsZero() {
public void test_PLA_SetsZeroIfAccumulatorIsZero() throws MemoryAccessException {
cpu.stackPush(0x00);
bus.loadProgram(0x68);
cpu.step();
@@ -352,7 +353,7 @@ public class CpuImpliedModeTest extends TestCase {
assertTrue(cpu.getZeroFlag());
}
public void test_PLA_SetsNegativeIfAccumulatorIsNegative() {
public void test_PLA_SetsNegativeIfAccumulatorIsNegative() throws MemoryAccessException {
cpu.stackPush(0xff);
bus.loadProgram(0x68);
cpu.step();
@@ -363,7 +364,7 @@ public class CpuImpliedModeTest extends TestCase {
/* PLP - Pull Processor Status - $28 */
public void test_PLP() {
public void test_PLP() throws MemoryAccessException {
cpu.stackPush(0x2f);
bus.loadProgram(0x28);
cpu.step();
@@ -372,7 +373,7 @@ public class CpuImpliedModeTest extends TestCase {
/* RTI - Return from Interrupt - $40 */
public void test_RTI() {
public void test_RTI() throws MemoryAccessException {
cpu.stackPush(0x0f); // PC hi
cpu.stackPush(0x11); // PC lo
cpu.stackPush(0x29); // status
@@ -386,7 +387,7 @@ public class CpuImpliedModeTest extends TestCase {
/* RTS - Return from Subroutine - $60 */
public void test_RTS() {
public void test_RTS() throws MemoryAccessException {
cpu.stackPush(0x0f); // PC hi
cpu.stackPush(0x11); // PC lo
@@ -399,7 +400,7 @@ public class CpuImpliedModeTest extends TestCase {
/* SEC - Set Carry Flag - $38 */
public void test_SEC() {
public void test_SEC() throws MemoryAccessException {
bus.loadProgram(0x38);
cpu.step();
assertTrue(cpu.getCarryFlag());
@@ -407,7 +408,7 @@ public class CpuImpliedModeTest extends TestCase {
/* SED - Set Decimal Mode Flag - $f8 */
public void test_SED() {
public void test_SED() throws MemoryAccessException {
bus.loadProgram(0xf8);
cpu.step();
assertTrue(cpu.getDecimalModeFlag());
@@ -415,7 +416,7 @@ public class CpuImpliedModeTest extends TestCase {
/* SEI - Set Interrupt Disable Flag - $78 */
public void test_SEI() {
public void test_SEI() throws MemoryAccessException {
bus.loadProgram(0x78);
cpu.step();
assertTrue(cpu.getIrqDisableFlag());
@@ -423,7 +424,7 @@ public class CpuImpliedModeTest extends TestCase {
/* TAX - Transfer Accumulator to X Register - $aa */
public void test_TAX() {
public void test_TAX() throws MemoryAccessException {
cpu.setAccumulator(0x32);
bus.loadProgram(0xaa);
cpu.step();
@@ -432,7 +433,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag());
}
public void test_TAX_SetsZeroFlagIfXIsZero() {
public void test_TAX_SetsZeroFlagIfXIsZero() throws MemoryAccessException {
cpu.setAccumulator(0x00);
bus.loadProgram(0xaa);
cpu.step();
@@ -441,7 +442,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag());
}
public void test_TAX_SetsNegativeFlagIfXIsNegative() {
public void test_TAX_SetsNegativeFlagIfXIsNegative() throws MemoryAccessException {
cpu.setAccumulator(0xff);
bus.loadProgram(0xaa);
cpu.step();
@@ -452,7 +453,7 @@ public class CpuImpliedModeTest extends TestCase {
/* TAY - Transfer Accumulator to Y Register - $a8 */
public void test_TAY() {
public void test_TAY() throws MemoryAccessException {
cpu.setAccumulator(0x32);
bus.loadProgram(0xa8);
cpu.step();
@@ -461,7 +462,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag());
}
public void test_TAY_SetsZeroFlagIfYIsZero() {
public void test_TAY_SetsZeroFlagIfYIsZero() throws MemoryAccessException {
cpu.setAccumulator(0x00);
bus.loadProgram(0xa8);
cpu.step();
@@ -470,7 +471,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag());
}
public void test_TAY_SetsNegativeFlagIfYIsNegative() {
public void test_TAY_SetsNegativeFlagIfYIsNegative() throws MemoryAccessException {
cpu.setAccumulator(0xff);
bus.loadProgram(0xa8);
cpu.step();
@@ -481,7 +482,7 @@ public class CpuImpliedModeTest extends TestCase {
/* TSX - Transfer Stack Pointer to X Register - $ba */
public void test_TSX() {
public void test_TSX() throws MemoryAccessException {
cpu.setStackPointer(0x32);
bus.loadProgram(0xba);
cpu.step();
@@ -490,7 +491,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag());
}
public void test_TSX_SetsZeroFlagIfXIsZero() {
public void test_TSX_SetsZeroFlagIfXIsZero() throws MemoryAccessException {
cpu.setStackPointer(0x00);
bus.loadProgram(0xba);
cpu.step();
@@ -499,7 +500,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag());
}
public void test_TSX_SetsNegativeFlagIfXIsNegative() {
public void test_TSX_SetsNegativeFlagIfXIsNegative() throws MemoryAccessException {
cpu.setStackPointer(0xff);
bus.loadProgram(0xba);
cpu.step();
@@ -510,7 +511,7 @@ public class CpuImpliedModeTest extends TestCase {
/* TXA - Transfer X Register to Accumulator - $8a */
public void test_TXA() {
public void test_TXA() throws MemoryAccessException {
cpu.setXRegister(0x32);
bus.loadProgram(0x8a);
cpu.step();
@@ -519,7 +520,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag());
}
public void test_TXA_SetsZeroFlagIfAccumulatorIsZero() {
public void test_TXA_SetsZeroFlagIfAccumulatorIsZero() throws MemoryAccessException {
cpu.setXRegister(0x00);
bus.loadProgram(0x8a);
cpu.step();
@@ -528,7 +529,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag());
}
public void test_TXA_SetsNegativeFlagIfAccumulatorIsNegative() {
public void test_TXA_SetsNegativeFlagIfAccumulatorIsNegative() throws MemoryAccessException {
cpu.setXRegister(0xff);
bus.loadProgram(0x8a);
cpu.step();
@@ -539,7 +540,7 @@ public class CpuImpliedModeTest extends TestCase {
/* TXS - Transfer X Register to Stack Pointer - $9a */
public void test_TXS() {
public void test_TXS() throws MemoryAccessException {
cpu.setXRegister(0x32);
bus.loadProgram(0x9a);
cpu.step();
@@ -548,7 +549,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag());
}
public void test_TXS_DoesNotAffectProcessorStatus() {
public void test_TXS_DoesNotAffectProcessorStatus() throws MemoryAccessException {
cpu.setXRegister(0x00);
bus.loadProgram(0x9a);
cpu.step();
@@ -566,7 +567,7 @@ public class CpuImpliedModeTest extends TestCase {
/* TYA - Transfer Y Register to Accumulator - $98 */
public void test_TYA() {
public void test_TYA() throws MemoryAccessException {
cpu.setYRegister(0x32);
bus.loadProgram(0x98);
cpu.step();
@@ -575,7 +576,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag());
}
public void test_TYA_SetsZeroFlagIfAccumulatorIsZero() {
public void test_TYA_SetsZeroFlagIfAccumulatorIsZero() throws MemoryAccessException {
cpu.setYRegister(0x00);
bus.loadProgram(0x98);
cpu.step();
@@ -584,7 +585,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag());
}
public void test_TYA_SetsNegativeFlagIfAccumulatorIsNegative() {
public void test_TYA_SetsNegativeFlagIfAccumulatorIsNegative() throws MemoryAccessException {
cpu.setYRegister(0xff);
bus.loadProgram(0x98);
cpu.step();
@@ -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.MemoryAccessException;
import junit.framework.TestCase;
public class CpuIndirectModeTest extends TestCase {
@@ -40,7 +41,7 @@ public class CpuIndirectModeTest extends TestCase {
/* JMP - Jump - $6c */
public void test_JMP() {
public void test_JMP() throws MemoryAccessException {
bus.write(0x3400, 0x00);
bus.write(0x3401, 0x54);
bus.loadProgram(0x6c, 0x00, 0x34);
@@ -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.MemoryAccessException;
import junit.framework.TestCase;
public class CpuRelativeModeTest extends TestCase {
@@ -47,7 +48,7 @@ public class CpuRelativeModeTest extends TestCase {
/* BPL - Branch if Positive - 0x10 */
public void test_BPL() {
public void test_BPL() throws MemoryAccessException {
// Positive Offset
bus.loadProgram(0x10, 0x05); // BPL $05 ; *=$0202+$05 ($0207)
cpu.setNegativeFlag();
@@ -76,7 +77,7 @@ public class CpuRelativeModeTest extends TestCase {
/* BMI - Branch if Minus - 0x30 */
public void test_BMI() {
public void test_BMI() throws MemoryAccessException {
// Positive Offset
bus.loadProgram(0x30, 0x05); // BMI $05 ; *=$0202+$05 ($0207)
cpu.setNegativeFlag();
@@ -105,7 +106,7 @@ public class CpuRelativeModeTest extends TestCase {
/* BVC - Branch if Overflow Clear - 0x50 */
public void test_BVC() {
public void test_BVC() throws MemoryAccessException {
// Positive Offset
bus.loadProgram(0x50, 0x05); // BVC $05 ; *=$0202+$05 ($0207)
cpu.setOverflowFlag();
@@ -134,7 +135,7 @@ public class CpuRelativeModeTest extends TestCase {
/* BVS - Branch if Overflow Set - 0x70 */
public void test_BVS() {
public void test_BVS() throws MemoryAccessException {
// Positive Offset
bus.loadProgram(0x70, 0x05); // BVS $05 ; *=$0202+$05 ($0207)
cpu.setOverflowFlag();
@@ -163,7 +164,7 @@ public class CpuRelativeModeTest extends TestCase {
/* BCC - Branch if Carry Clear - 0x90 */
public void test_BCC() {
public void test_BCC() throws MemoryAccessException {
// Positive Offset
bus.loadProgram(0x90, 0x05); // BCC $05 ; *=$0202+$05 ($0207)
cpu.setCarryFlag();
@@ -192,7 +193,7 @@ public class CpuRelativeModeTest extends TestCase {
/* BCS - Branch if Carry Set - 0xb0 */
public void test_BCS() {
public void test_BCS() throws MemoryAccessException {
// Positive Offset
bus.loadProgram(0xb0, 0x05); // BCS $05 ; *=$0202+$05 ($0207)
cpu.setCarryFlag();
@@ -221,7 +222,7 @@ public class CpuRelativeModeTest extends TestCase {
/* BNE - Branch if Not Equal to Zero - 0xd0 */
public void test_BNE() {
public void test_BNE() throws MemoryAccessException {
// Positive Offset
bus.loadProgram(0xd0, 0x05); // BNE $05 ; *=$0202+$05 ($0207)
cpu.setZeroFlag();
@@ -250,7 +251,7 @@ public class CpuRelativeModeTest extends TestCase {
/* BEQ - Branch if Equal to Zero - 0xf0 */
public void test_BEQ() {
public void test_BEQ() throws MemoryAccessException {
// Positive Offset
bus.loadProgram(0xf0, 0x05); // BEQ $05 ; *=$0202+$05 ($0207)
cpu.setZeroFlag();
+7 -9
View File
@@ -22,7 +22,7 @@ public class CpuTest extends TestCase {
return new TestSuite(CpuTest.class);
}
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);
@@ -50,7 +50,7 @@ public class CpuTest extends TestCase {
assertFalse(cpu.getNegativeFlag());
}
public void testStack() {
public void testStack() throws MemoryAccessException {
cpu.stackPush(0x13);
assertEquals(0x13, cpu.stackPop());
@@ -68,7 +68,7 @@ public class CpuTest extends TestCase {
}
public void testStackPush() {
public void testStackPush() throws MemoryAccessException {
assertEquals(0xff, cpu.getStackPointer());
assertEquals(0xff, bus.read(0x1ff));
@@ -112,7 +112,7 @@ public class CpuTest extends TestCase {
assertEquals(0x01, bus.read(0x1fa));
}
public void testStackPushWrapsAroundToStackTop() {
public void testStackPushWrapsAroundToStackTop() throws MemoryAccessException {
cpu.setStackPointer(0x01);
cpu.stackPush(0x01);
@@ -129,7 +129,7 @@ public class CpuTest extends TestCase {
}
public void testStackPop() {
public void testStackPop() throws MemoryAccessException {
bus.write(0x1ff, 0x06);
bus.write(0x1fe, 0x05);
bus.write(0x1fd, 0x04);
@@ -157,7 +157,7 @@ public class CpuTest extends TestCase {
assertEquals(0xff, cpu.getStackPointer());
}
public void testStackPopWrapsAroundToStackBottom() {
public void testStackPopWrapsAroundToStackBottom() throws MemoryAccessException {
bus.write(0x1ff, 0x0f); // top of stack
bus.write(0x100, 0xf0); // bottom of stack
bus.write(0x101, 0xf1);
@@ -178,9 +178,7 @@ public class CpuTest extends TestCase {
assertEquals(0x02, cpu.getStackPointer());
}
public void testStackPeekDoesNotAlterStackPointer() {
int val = 0;
public void testStackPeekDoesNotAlterStackPointer() throws MemoryAccessException {
assertEquals(0xff, cpu.stackPeek());
assertEquals(0xff, cpu.getStackPointer());
@@ -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.MemoryAccessException;
import junit.framework.TestCase;
public class CpuZeroPageModeTest extends TestCase {
@@ -63,7 +64,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* ORA - Logical Inclusive OR - $05 */
public void test_ORA() {
public void test_ORA() throws MemoryAccessException {
// Set some initial values in zero page.
bus.write(0x0000, 0x00);
bus.write(0x0002, 0x11);
@@ -104,7 +105,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* ASL - Arithmetic Shift Left - $06 */
public void test_ASL() {
public void test_ASL() throws MemoryAccessException {
bus.write(0x0000, 0x00);
bus.write(0x0001, 0x01);
bus.write(0x0002, 0x02);
@@ -150,7 +151,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* BIT - Bit Test - $24 */
public void test_BIT() {
public void test_BIT() throws MemoryAccessException {
bus.write(0x0000, 0xc0);
bus.loadProgram(0xa9, 0x01, // LDA #$01
@@ -204,7 +205,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* AND - Logical AND - $25 */
public void test_AND() {
public void test_AND() throws MemoryAccessException {
bus.write(0x0000, 0x00);
bus.write(0x0001, 0x11);
bus.write(0x0002, 0xff);
@@ -253,7 +254,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* ROL - Rotate Shift Left - $26 */
public void test_ROL() {
public void test_ROL() throws MemoryAccessException {
bus.write(0x0000, 0x00);
bus.write(0x0001, 0x01);
@@ -333,7 +334,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* EOR - Exclusive OR - $45 */
public void test_EOR() {
public void test_EOR() throws MemoryAccessException {
bus.write(0x10, 0x00);
bus.write(0x11, 0xff);
bus.write(0x12, 0x33);
@@ -367,7 +368,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* LSR - Logical Shift Right - $46 */
public void test_LSR() {
public void test_LSR() throws MemoryAccessException {
bus.write(0x0000, 0x00);
bus.write(0x0001, 0x01);
bus.write(0x0002, 0x02);
@@ -423,7 +424,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* ADC - Add with Carry - $65 */
public void test_ADC() {
public void test_ADC() throws MemoryAccessException {
bus.write(0x10, 0x01);
bus.write(0x11, 0xff);
@@ -507,7 +508,7 @@ public class CpuZeroPageModeTest extends TestCase {
assertTrue(cpu.getCarryFlag());
}
public void test_ADC_IncludesCarry() {
public void test_ADC_IncludesCarry() throws MemoryAccessException {
bus.write(0x10, 0x01);
bus.loadProgram(0xa9, 0x00, // LDA #$00
@@ -521,7 +522,7 @@ public class CpuZeroPageModeTest extends TestCase {
assertFalse(cpu.getCarryFlag());
}
public void test_ADC_DecimalMode() {
public void test_ADC_DecimalMode() throws MemoryAccessException {
bus.write(0x10, 0x01);
bus.write(0x11, 0x99);
@@ -604,8 +605,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* ROR - Rotate Right - $66 */
public void test_ROR() {
public void test_ROR() throws MemoryAccessException {
bus.write(0x10, 0x00);
bus.write(0x11, 0x10);
@@ -683,7 +683,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* STY - Store Y Register - $84 */
public void test_STY() {
public void test_STY() throws MemoryAccessException {
cpu.setYRegister(0x00);
bus.loadProgram(0x84, 0x10);
cpu.step();
@@ -712,7 +712,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* STA - Store Accumulator - $85 */
public void test_STA() {
public void test_STA() throws MemoryAccessException {
cpu.setAccumulator(0x00);
bus.loadProgram(0x85, 0x10);
cpu.step();
@@ -741,7 +741,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* STX - Store X Register - $86 */
public void test_STX() {
public void test_STX() throws MemoryAccessException {
cpu.setXRegister(0x00);
bus.loadProgram(0x86, 0x10);
cpu.step();
@@ -770,7 +770,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* LDY - Load Y Register - $a4 */
public void test_LDY() {
public void test_LDY() throws MemoryAccessException {
bus.write(0x10, 0x00);
bus.write(0x11, 0x0f);
bus.write(0x12, 0x80);
@@ -797,7 +797,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* LDA - Load Accumulator - $a5 */
public void test_LDA() {
public void test_LDA() throws MemoryAccessException {
bus.write(0x10, 0x00);
bus.write(0x11, 0x0f);
bus.write(0x12, 0x80);
@@ -824,7 +824,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* LDX - Load X Register - $a6 */
public void test_LDX() {
public void test_LDX() throws MemoryAccessException {
bus.write(0x10, 0x00);
bus.write(0x11, 0x0f);
bus.write(0x12, 0x80);
@@ -851,7 +851,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* CPY - Compare Y Register - $c4 */
public void test_CPY() {
public void test_CPY() throws MemoryAccessException {
bus.write(0x10, 0x00);
bus.write(0x11, 0x80);
bus.write(0x12, 0xff);
@@ -880,7 +880,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* CMP - Compare Accumulator - $c5 */
public void test_CMP() {
public void test_CMP() throws MemoryAccessException {
bus.write(0x10, 0x00);
bus.write(0x11, 0x80);
bus.write(0x12, 0xff);
@@ -909,7 +909,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* DEC - Decrement Memory Location - $c6 */
public void test_DEC() {
public void test_DEC() throws MemoryAccessException {
bus.write(0x10, 0x00);
bus.write(0x11, 0x01);
bus.write(0x12, 0x80);
@@ -943,7 +943,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* CPX - Compare X Register - $e4 */
public void test_CPX() {
public void test_CPX() throws MemoryAccessException {
bus.write(0x10, 0x00);
bus.write(0x11, 0x80);
bus.write(0x12, 0xff);
@@ -972,7 +972,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* SBC - Subtract with Carry - $e5 */
public void test_SBC() {
public void test_SBC() throws MemoryAccessException {
bus.write(0x10, 0x01);
bus.loadProgram(0xa9, 0x00, // LDA #$00
@@ -1025,7 +1025,7 @@ public class CpuZeroPageModeTest extends TestCase {
assertTrue(cpu.getCarryFlag());
}
public void test_SBC_IncludesNotOfCarry() {
public void test_SBC_IncludesNotOfCarry() throws MemoryAccessException {
bus.write(0x10, 0x01);
// Subtrace with Carry Flag cleared
@@ -1068,7 +1068,7 @@ public class CpuZeroPageModeTest extends TestCase {
}
public void test_SBC_DecimalMode() {
public void test_SBC_DecimalMode() throws MemoryAccessException {
bus.write(0x10, 0x01);
bus.write(0x20, 0x11);
@@ -1167,7 +1167,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* INC - Increment Memory Location - $e6 */
public void test_INC() {
public void test_INC() throws MemoryAccessException {
bus.write(0x10, 0x00);
bus.write(0x11, 0x7f);
bus.write(0x12, 0xff);
@@ -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.MemoryAccessException;
import junit.framework.TestCase;
public class CpuZeroPageXModeTest extends TestCase {
@@ -57,7 +58,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* ORA - Logical Inclusive OR - $15 */
public void test_ORA() {
public void test_ORA() throws MemoryAccessException {
// Set some initial values in zero page.
bus.write(0x30, 0x00);
bus.write(0x32, 0x11);
@@ -111,7 +112,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* ASL - Arithmetic Shift Left - $16 */
public void test_ASL() {
public void test_ASL() throws MemoryAccessException {
bus.write(0x30, 0x00);
bus.write(0x31, 0x01);
bus.write(0x32, 0x02);
@@ -169,7 +170,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* AND - Logical AND - $35 */
public void test_AND() {
public void test_AND() throws MemoryAccessException {
bus.write(0x30, 0x00);
bus.write(0x31, 0x11);
bus.write(0x32, 0xff);
@@ -229,7 +230,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* ROL - Rotate Shift Left - $36 */
public void test_ROL() {
public void test_ROL() throws MemoryAccessException {
bus.write(0x70, 0x00);
bus.write(0x71, 0x01);
@@ -312,7 +313,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* EOR - Exclusive OR - $55 */
public void test_EOR() {
public void test_EOR() throws MemoryAccessException {
bus.write(0x40, 0x00);
bus.write(0x41, 0xff);
bus.write(0x42, 0x33);
@@ -348,7 +349,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* LSR - Logical Shift Right - $56 */
public void test_LSR() {
public void test_LSR() throws MemoryAccessException {
bus.write(0x30, 0x00);
bus.write(0x31, 0x01);
bus.write(0x32, 0x02);
@@ -406,7 +407,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* ADC - Add with Carry - $75 */
public void test_ADC() {
public void test_ADC() throws MemoryAccessException {
bus.write(0x40, 0x01);
bus.write(0x41, 0xff);
@@ -492,7 +493,7 @@ public class CpuZeroPageXModeTest extends TestCase {
assertTrue(cpu.getCarryFlag());
}
public void test_ADC_IncludesCarry() {
public void test_ADC_IncludesCarry() throws MemoryAccessException {
bus.write(0x40, 0x01);
bus.loadProgram(0xa9, 0x00, // LDA #$00
@@ -509,7 +510,7 @@ public class CpuZeroPageXModeTest extends TestCase {
assertFalse(cpu.getCarryFlag());
}
public void test_ADC_DecimalMode() {
public void test_ADC_DecimalMode() throws MemoryAccessException {
bus.write(0x40, 0x01);
bus.write(0x41, 0x99);
@@ -595,7 +596,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* ROR - Rotate Right - $76 */
public void test_ROR() {
public void test_ROR() throws MemoryAccessException {
bus.write(0x40, 0x00);
bus.write(0x41, 0x10);
@@ -676,7 +677,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* STY - Store Y Register - $94 */
public void test_STY() {
public void test_STY() throws MemoryAccessException {
cpu.setXRegister(0x30);
cpu.setYRegister(0x00);
@@ -707,7 +708,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* STA - Store Accumulator - $95 */
public void test_STA() {
public void test_STA() throws MemoryAccessException {
cpu.setXRegister(0x30);
cpu.setAccumulator(0x00);
@@ -738,7 +739,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* LDY - Load Y Register - $b4 */
public void test_LDY() {
public void test_LDY() throws MemoryAccessException {
bus.write(0x45, 0x00);
bus.write(0x46, 0x0f);
bus.write(0x47, 0x80);
@@ -767,7 +768,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* LDA - Load Accumulator - $b5 */
public void test_LDA() {
public void test_LDA() throws MemoryAccessException {
bus.write(0x42, 0x00);
bus.write(0x43, 0x0f);
bus.write(0x44, 0x80);
@@ -796,7 +797,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* CMP - Compare Accumulator - $d5 */
public void test_CMP() {
public void test_CMP() throws MemoryAccessException {
bus.write(0x40, 0x00);
bus.write(0x41, 0x80);
bus.write(0x42, 0xff);
@@ -827,7 +828,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* DEC - Decrement Memory Location - $d6 */
public void test_DEC() {
public void test_DEC() throws MemoryAccessException {
bus.write(0x40, 0x00);
bus.write(0x41, 0x01);
bus.write(0x42, 0x80);
@@ -863,7 +864,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* SBC - Subtract with Carry - $f5 */
public void test_SBC() {
public void test_SBC() throws MemoryAccessException {
bus.write(0x40, 0x01);
bus.loadProgram(0xa9, 0x00, // LDA #$00
@@ -921,7 +922,7 @@ public class CpuZeroPageXModeTest extends TestCase {
assertTrue(cpu.getCarryFlag());
}
public void test_SBC_IncludesNotOfCarry() {
public void test_SBC_IncludesNotOfCarry() throws MemoryAccessException {
bus.write(0x40, 0x01);
// Subtrace with Carry Flag cleared
@@ -966,7 +967,7 @@ public class CpuZeroPageXModeTest extends TestCase {
}
public void test_SBC_DecimalMode() {
public void test_SBC_DecimalMode() throws MemoryAccessException {
bus.write(0x40, 0x01);
bus.write(0x50, 0x11);
@@ -1072,7 +1073,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* INC - Increment Memory Location - $f6 */
public void test_INC() {
public void test_INC() throws MemoryAccessException {
bus.write(0x30, 0x00);
bus.write(0x31, 0x7f);
bus.write(0x32, 0xff);
@@ -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.MemoryAccessException;
import junit.framework.TestCase;
public class CpuZeroPageYModeTest extends TestCase {
@@ -41,7 +42,7 @@ public class CpuZeroPageYModeTest extends TestCase {
/* STX - Store X Register - $96 */
public void test_STX() {
public void test_STX() throws MemoryAccessException {
cpu.setYRegister(0x30);
cpu.setXRegister(0x00);
bus.loadProgram(0x96, 0x10); // STX $10,Y
@@ -71,7 +72,7 @@ public class CpuZeroPageYModeTest extends TestCase {
/* LDX - Load X Register - $b6 */
public void test_LDX() {
public void test_LDX() throws MemoryAccessException {
bus.write(0x40, 0x00);
bus.write(0x41, 0x0f);
bus.write(0x42, 0x80);
@@ -2,9 +2,6 @@ package com.loomcom.symon;
import junit.framework.*;
import java.util.HashMap;
import java.util.Map;
import com.loomcom.symon.exceptions.*;
/**