- 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

+3 -3
View File
@@ -98,7 +98,7 @@ public class Bus {
return true; return true;
} }
public int read(int address) { public int read(int address) throws MemoryAccessException {
for (Device d : devices) { for (Device d : devices) {
MemoryRange range = d.getMemoryRange(); MemoryRange range = d.getMemoryRange();
if (range.includes(address)) { if (range.includes(address)) {
@@ -111,7 +111,7 @@ public class Bus {
throw new RuntimeException("Read failed! Device not found."); throw new RuntimeException("Read failed! Device not found.");
} }
public void write(int address, int value) { public void write(int address, int value) throws MemoryAccessException {
for (Device d : devices) { for (Device d : devices) {
MemoryRange range = d.getMemoryRange(); MemoryRange range = d.getMemoryRange();
if (range.includes(address)) { if (range.includes(address)) {
@@ -134,7 +134,7 @@ public class Bus {
return cpu; return cpu;
} }
public void loadProgram(int... program) { public void loadProgram(int... program) throws MemoryAccessException {
int address = getCpu().getProgramCounter(); int address = getCpu().getProgramCounter();
int i = 0; int i = 0;
for (int d : program) { for (int d : program) {
@@ -30,6 +30,14 @@ public class CommandParser {
} }
} }
public void setSimulator(Simulator sim) {
this.simulator = sim;
}
public Simulator getSimulator() {
return this.simulator;
}
/** /**
* Dispatch the command. * Dispatch the command.
*/ */
+116 -117
View File
@@ -1,6 +1,7 @@
package com.loomcom.symon; package com.loomcom.symon;
import java.util.Arrays; import com.loomcom.symon.InstructionTable;
import com.loomcom.symon.exceptions.MemoryAccessException;
/** /**
* Main 6502 CPU Simulation. * Main 6502 CPU Simulation.
@@ -46,7 +47,6 @@ public class Cpu implements InstructionTable {
/* Scratch space for addressing mode and effective address /* Scratch space for addressing mode and effective address
* calculations */ * calculations */
private int irOpCode; // Bits 0-2 of IR: [X|X|X| | | | | ]
private int irAddressMode; // Bits 3-5 of IR: [ | | |X|X|X| | ] private int irAddressMode; // Bits 3-5 of IR: [ | | |X|X|X| | ]
private int irOpMode; // Bits 6-7 of IR: [ | | | | | |X|X] private int irOpMode; // Bits 6-7 of IR: [ | | | | | |X|X]
private int effectiveAddress; private int effectiveAddress;
@@ -93,7 +93,7 @@ public class Cpu implements InstructionTable {
/** /**
* Reset the CPU to known initial values. * Reset the CPU to known initial values.
*/ */
public void reset() { public void reset() throws MemoryAccessException {
// Registers // Registers
sp = 0xff; sp = 0xff;
@@ -114,7 +114,7 @@ public class Cpu implements InstructionTable {
opTrap = false; opTrap = false;
} }
public void step(int num) { public void step(int num) throws MemoryAccessException {
for (int i = 0; i < num; i++) { for (int i = 0; i < num; i++) {
step(); step();
} }
@@ -123,26 +123,25 @@ public class Cpu implements InstructionTable {
/** /**
* Performs an individual machine cycle. * Performs an individual machine cycle.
*/ */
public void step() { public void step() throws MemoryAccessException {
// Store the address from which the IR was read, for debugging // Store the address from which the IR was read, for debugging
addr = pc; addr = pc;
// Fetch memory location for this instruction. // Fetch memory location for this instruction.
ir = bus.read(pc); ir = bus.read(pc);
irOpCode = (ir >> 5) & 0x07;
irAddressMode = (ir >> 2) & 0x07; irAddressMode = (ir >> 2) & 0x07;
irOpMode = ir & 0x03; irOpMode = ir & 0x03;
// Increment PC // Increment PC
incrementPC(); incrementPC();
// Clear the illegal opcode trap. // Clear the illegal opcode trap.
clearOpTrap(); clearOpTrap();
// Decode the instruction and operands // Decode the instruction and operands
instSize = Cpu.instructionSizes[ir]; instSize = Cpu.instructionSizes[ir];
for (int i = 0; i < instSize-1; i++) { for (int i = 0; i < instSize-1; i++) {
operands[i] = bus.read(pc); args[i] = bus.read(pc);
// Increment PC after reading // Increment PC after reading
incrementPC(); incrementPC();
} }
@@ -162,36 +161,36 @@ public class Cpu implements InstructionTable {
switch(irAddressMode) { switch(irAddressMode) {
case 0: // (Zero Page,X) case 0: // (Zero Page,X)
// TODO: UNIT TESTS // TODO: UNIT TESTS
effectiveAddress = bus.read(zpxAddress(operands[0])); effectiveAddress = bus.read(zpxAddress(args[0]));
effectiveData = bus.read(effectiveAddress); effectiveData = bus.read(effectiveAddress);
break; break;
case 1: // Zero Page case 1: // Zero Page
effectiveAddress = operands[0]; effectiveAddress = args[0];
effectiveData = bus.read(effectiveAddress); effectiveData = bus.read(effectiveAddress);
break; break;
case 2: // #Immediate case 2: // #Immediate
effectiveAddress = -1; effectiveAddress = -1;
effectiveData = operands[0]; effectiveData = args[0];
break; break;
case 3: // Absolute case 3: // Absolute
effectiveAddress = address(operands[0], operands[1]); effectiveAddress = address(args[0], args[1]);
effectiveData = bus.read(effectiveAddress); effectiveData = bus.read(effectiveAddress);
break; break;
case 4: // (Zero Page),Y case 4: // (Zero Page),Y
// TODO: UNIT TESTS // TODO: UNIT TESTS
effectiveAddress = yAddress(bus.read(operands[0]), getYRegister()); effectiveAddress = yAddress(bus.read(args[0]), getYRegister());
effectiveData = bus.read(effectiveAddress); effectiveData = bus.read(effectiveAddress);
break; break;
case 5: // Zero Page, X case 5: // Zero Page, X
effectiveAddress = zpxAddress(operands[0]); effectiveAddress = zpxAddress(args[0]);
effectiveData = bus.read(effectiveAddress); effectiveData = bus.read(effectiveAddress);
break; break;
case 6: // Absolute, Y case 6: // Absolute, Y
effectiveAddress = yAddress(operands[0], operands[1]); effectiveAddress = yAddress(args[0], args[1]);
effectiveData = bus.read(effectiveAddress); effectiveData = bus.read(effectiveAddress);
break; break;
case 7: // Absolute, X case 7: // Absolute, X
effectiveAddress = xAddress(operands[0], operands[1]); effectiveAddress = xAddress(args[0], args[1]);
effectiveData = bus.read(effectiveAddress); effectiveData = bus.read(effectiveAddress);
break; break;
} }
@@ -200,24 +199,24 @@ public class Cpu implements InstructionTable {
case 2: case 2:
switch(irAddressMode) { switch(irAddressMode) {
case 0: // #Immediate case 0: // #Immediate
efectiveAddress = -1; effectiveAddress = -1;
effectiveData = operands[0]; effectiveData = args[0];
break; break;
case 1: // Zero Page case 1: // Zero Page
effectiveAddress = operands[0]; effectiveAddress = args[0];
effectiveData = bus.read(effectiveeAddress); effectiveData = bus.read(effectiveAddress);
break; break;
case 2: // Accumulator - ignored case 2: // Accumulator - ignored
break; break;
case 3: // Absolute case 3: // Absolute
effectiveAddress = address(operands[0], operands[1]); effectiveAddress = address(args[0], args[1]);
effectiveData = bus.read(effectiveAddress); effectiveData = bus.read(effectiveAddress);
break; break;
case 5: // Zero Page,X / Zero Page,Y case 5: // Zero Page,X / Zero Page,Y
if (ir == 0x96 || ir == 0xb6) { if (ir == 0x96 || ir == 0xb6) {
effectiveAddress = zpyAddress(operands[0]); effectiveAddress = zpyAddress(args[0]);
} else { } else {
effectiveAddress = zpxAddress(operands[0]); effectiveAddress = zpxAddress(args[0]);
} }
effectiveData = bus.read(effectiveAddress); effectiveData = bus.read(effectiveAddress);
case 7: // Absolute,X / Absolute,Y case 7: // Absolute,X / Absolute,Y
@@ -252,7 +251,7 @@ public class Cpu implements InstructionTable {
break; break;
case 0x10: // BPL - Branch if Positive - Relative case 0x10: // BPL - Branch if Positive - Relative
if (!getNegativeFlag()) { if (!getNegativeFlag()) {
pc = relAddress(operands[0]); pc = relAddress(args[0]);
} }
break; break;
case 0x18: // CLC - Clear Carry Flag - Implied case 0x18: // CLC - Clear Carry Flag - Implied
@@ -261,14 +260,14 @@ public class Cpu implements InstructionTable {
case 0x20: // JSR - Jump to Subroutine - Implied case 0x20: // JSR - Jump to Subroutine - Implied
stackPush((pc-1 >> 8) & 0xff); // PC high byte stackPush((pc-1 >> 8) & 0xff); // PC high byte
stackPush(pc-1 & 0xff); // PC low byte stackPush(pc-1 & 0xff); // PC low byte
pc = address(operands[0], operands[1]); pc = address(args[0], args[1]);
break; break;
case 0x28: // PLP - Pull Processor Status - Implied case 0x28: // PLP - Pull Processor Status - Implied
setProcessorStatus(stackPop()); setProcessorStatus(stackPop());
break; break;
case 0x30: // BMI - Branch if Minus - Relative case 0x30: // BMI - Branch if Minus - Relative
if (getNegativeFlag()) { if (getNegativeFlag()) {
pc = relAddress(operands[0]); pc = relAddress(args[0]);
} }
break; break;
case 0x38: // SEC - Set Carry Flag - Implied case 0x38: // SEC - Set Carry Flag - Implied
@@ -285,7 +284,7 @@ public class Cpu implements InstructionTable {
break; break;
case 0x50: // BVC - Branch if Overflow Clear - Relative case 0x50: // BVC - Branch if Overflow Clear - Relative
if (!getOverflowFlag()) { if (!getOverflowFlag()) {
pc = relAddress(operands[0]); pc = relAddress(args[0]);
} }
break; break;
case 0x58: // CLI - Clear Interrupt Disable - Implied case 0x58: // CLI - Clear Interrupt Disable - Implied
@@ -302,7 +301,7 @@ public class Cpu implements InstructionTable {
break; break;
case 0x70: // BVS - Branch if Overflow Set - Relative case 0x70: // BVS - Branch if Overflow Set - Relative
if (getOverflowFlag()) { if (getOverflowFlag()) {
pc = relAddress(operands[0]); pc = relAddress(args[0]);
} }
break; break;
case 0x78: // SEI - Set Interrupt Disable - Implied case 0x78: // SEI - Set Interrupt Disable - Implied
@@ -318,7 +317,7 @@ public class Cpu implements InstructionTable {
break; break;
case 0x90: // BCC - Branch if Carry Clear - Relative case 0x90: // BCC - Branch if Carry Clear - Relative
if (!getCarryFlag()) { if (!getCarryFlag()) {
pc = relAddress(operands[0]); pc = relAddress(args[0]);
} }
break; break;
case 0x98: // TYA - Transfer Y to Accumulator - Implied case 0x98: // TYA - Transfer Y to Accumulator - Implied
@@ -338,7 +337,7 @@ public class Cpu implements InstructionTable {
break; break;
case 0xb0: // BCS - Branch if Carry Set - Relative case 0xb0: // BCS - Branch if Carry Set - Relative
if (getCarryFlag()) { if (getCarryFlag()) {
pc = relAddress(operands[0]); pc = relAddress(args[0]);
} }
break; break;
case 0xb8: // CLV - Clear Overflow Flag - Implied case 0xb8: // CLV - Clear Overflow Flag - Implied
@@ -358,7 +357,7 @@ public class Cpu implements InstructionTable {
break; break;
case 0xd0: // BNE - Branch if Not Equal to Zero - Relative case 0xd0: // BNE - Branch if Not Equal to Zero - Relative
if (!getZeroFlag()) { if (!getZeroFlag()) {
pc = relAddress(operands[0]); pc = relAddress(args[0]);
} }
break; break;
case 0xd8: // CLD - Clear Decimal Mode - Implied case 0xd8: // CLD - Clear Decimal Mode - Implied
@@ -373,7 +372,7 @@ public class Cpu implements InstructionTable {
break; break;
case 0xf0: // BEQ - Branch if Equal to Zero - Relative case 0xf0: // BEQ - Branch if Equal to Zero - Relative
if (getZeroFlag()) { if (getZeroFlag()) {
pc = relAddress(operands[0]); pc = relAddress(args[0]);
} }
break; break;
case 0xf8: // SED - Set Decimal Flag - Implied case 0xf8: // SED - Set Decimal Flag - Implied
@@ -382,10 +381,10 @@ public class Cpu implements InstructionTable {
/** JMP *****************************************************************/ /** JMP *****************************************************************/
case 0x4c: // JMP - Absolute case 0x4c: // JMP - Absolute
pc = address(operands[0], operands[1]); pc = address(args[0], args[1]);
break; break;
case 0x6c: // JMP - Indirect case 0x6c: // JMP - Indirect
lo = address(operands[0], operands[1]); // Address of low byte lo = address(args[0], args[1]); // Address of low byte
hi = lo+1; // Address of high byte hi = lo+1; // Address of high byte
pc = address(bus.read(lo), bus.read(hi)); pc = address(bus.read(lo), bus.read(hi));
/* TODO: For accuracy, allow a flag to enable broken behavior /* TODO: For accuracy, allow a flag to enable broken behavior
@@ -423,41 +422,41 @@ public class Cpu implements InstructionTable {
setArithmeticFlags(a); setArithmeticFlags(a);
break; break;
case 0x06: // ASL - Zero Page case 0x06: // ASL - Zero Page
j = bus.read(operands[0]); j = bus.read(args[0]);
k = asl(j); k = asl(j);
bus.write(operands[0], k); bus.write(args[0], k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
case 0x0e: // ASL - Absolute case 0x0e: // ASL - Absolute
j = bus.read(address(operands[0], operands[1])); j = bus.read(address(args[0], args[1]));
k = asl(j); k = asl(j);
bus.write(address(operands[0], operands[1]), k); bus.write(address(args[0], args[1]), k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
case 0x16: // ASL - Zero Page,X case 0x16: // ASL - Zero Page,X
j = bus.read(zpxAddress(operands[0])); j = bus.read(zpxAddress(args[0]));
k = asl(j); k = asl(j);
bus.write(zpxAddress(operands[0]), k); bus.write(zpxAddress(args[0]), k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
case 0x1e: // ASL - Absolute,X case 0x1e: // ASL - Absolute,X
j = bus.read(xAddress(operands[0], operands[1])); j = bus.read(xAddress(args[0], args[1]));
k = asl(j); k = asl(j);
bus.write(xAddress(operands[0], operands[1]), k); bus.write(xAddress(args[0], args[1]), k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
/** BIT - Bit Test ******************************************************/ /** BIT - Bit Test ******************************************************/
case 0x24: // BIT - Zero Page case 0x24: // BIT - Zero Page
j = bus.read(operands[0]); j = bus.read(args[0]);
k = a & j; k = a & j;
setZeroFlag(k == 0); setZeroFlag(k == 0);
setNegativeFlag((k & 0x80) != 0); setNegativeFlag((k & 0x80) != 0);
setOverflowFlag((k & 0x40) != 0); setOverflowFlag((k & 0x40) != 0);
break; break;
case 0x2c: // BIT - Absolute case 0x2c: // BIT - Absolute
j = bus.read(address(operands[0], operands[1])); j = bus.read(address(args[0], args[1]));
k = a & j; k = a & j;
setZeroFlag(k == 0); setZeroFlag(k == 0);
setNegativeFlag((k & 0x80) != 0); setNegativeFlag((k & 0x80) != 0);
@@ -469,33 +468,33 @@ public class Cpu implements InstructionTable {
case 0x21: // AND - (Zero Page,X) case 0x21: // AND - (Zero Page,X)
break; break;
case 0x25: // AND - Zero Page case 0x25: // AND - Zero Page
j = bus.read(operands[0]); j = bus.read(args[0]);
a &= j; a &= j;
setArithmeticFlags(a); setArithmeticFlags(a);
break; break;
case 0x29: // AND - #Immediate case 0x29: // AND - #Immediate
a &= operands[0]; a &= args[0];
setArithmeticFlags(a); setArithmeticFlags(a);
break; break;
case 0x2d: // AND - Absolute case 0x2d: // AND - Absolute
j = bus.read(address(operands[0], operands[1])); j = bus.read(address(args[0], args[1]));
a &= j; a &= j;
setArithmeticFlags(a); setArithmeticFlags(a);
break; break;
case 0x31: // AND - (Zero Page),Y case 0x31: // AND - (Zero Page),Y
break; break;
case 0x35: // AND - Zero Page,X case 0x35: // AND - Zero Page,X
j = bus.read(zpxAddress(operands[0])); j = bus.read(zpxAddress(args[0]));
a &= j; a &= j;
setArithmeticFlags(a); setArithmeticFlags(a);
break; break;
case 0x39: // AND - Absolute,Y case 0x39: // AND - Absolute,Y
j = bus.read(yAddress(operands[0], operands[1])); j = bus.read(yAddress(args[0], args[1]));
a &= j; a &= j;
setArithmeticFlags(a); setArithmeticFlags(a);
break; break;
case 0x3d: // AND - Absolute,X case 0x3d: // AND - Absolute,X
j = bus.read(xAddress(operands[0], operands[1])); j = bus.read(xAddress(args[0], args[1]));
a &= j; a &= j;
setArithmeticFlags(a); setArithmeticFlags(a);
break; break;
@@ -503,9 +502,9 @@ public class Cpu implements InstructionTable {
/** ROL - Rotate Left ***************************************************/ /** ROL - Rotate Left ***************************************************/
case 0x26: // ROL - Zero Page case 0x26: // ROL - Zero Page
j = bus.read(operands[0]); j = bus.read(args[0]);
k = rol(j); k = rol(j);
bus.write(operands[0], k); bus.write(args[0], k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
case 0x2a: // ROL - Accumulator case 0x2a: // ROL - Accumulator
@@ -513,21 +512,21 @@ public class Cpu implements InstructionTable {
setArithmeticFlags(a); setArithmeticFlags(a);
break; break;
case 0x2e: // ROL - Absolute case 0x2e: // ROL - Absolute
j = bus.read(address(operands[0], operands[1])); j = bus.read(address(args[0], args[1]));
k = rol(j); k = rol(j);
bus.write(address(operands[0], operands[1]), k); bus.write(address(args[0], args[1]), k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
case 0x36: // ROL - Zero Page,X case 0x36: // ROL - Zero Page,X
j = bus.read(zpxAddress(operands[0])); j = bus.read(zpxAddress(args[0]));
k = rol(j); k = rol(j);
bus.write(zpxAddress(operands[0]), k); bus.write(zpxAddress(args[0]), k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
case 0x3e: // ROL - Absolute,X case 0x3e: // ROL - Absolute,X
j = bus.read(xAddress(operands[0], operands[1])); j = bus.read(xAddress(args[0], args[1]));
k = rol(j); k = rol(j);
bus.write(xAddress(operands[0], operands[1]), k); bus.write(xAddress(args[0], args[1]), k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
@@ -548,8 +547,8 @@ public class Cpu implements InstructionTable {
/** LSR - Logical Shift Right *******************************************/ /** LSR - Logical Shift Right *******************************************/
case 0x46: // LSR - Zero Page case 0x46: // LSR - Zero Page
k = lsr(bus.read(operands[0])); k = lsr(bus.read(args[0]));
bus.write(operands[0], k); bus.write(args[0], k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
case 0x4a: // LSR - Accumulator case 0x4a: // LSR - Accumulator
@@ -557,18 +556,18 @@ public class Cpu implements InstructionTable {
setArithmeticFlags(a); setArithmeticFlags(a);
break; break;
case 0x4e: // LSR - Absolute case 0x4e: // LSR - Absolute
k = lsr(bus.read(address(operands[0], operands[1]))); k = lsr(bus.read(address(args[0], args[1])));
bus.write(address(operands[0], operands[1]), k); bus.write(address(args[0], args[1]), k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
case 0x56: // LSR - Zero Page,X case 0x56: // LSR - Zero Page,X
k = lsr(bus.read(zpxAddress(operands[0]))); k = lsr(bus.read(zpxAddress(args[0])));
bus.write(zpxAddress(operands[0]), k); bus.write(zpxAddress(args[0]), k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
case 0x5e: // LSR - Absolute,X case 0x5e: // LSR - Absolute,X
k = lsr(bus.read(xAddress(operands[0], operands[1]))); k = lsr(bus.read(xAddress(args[0], args[1])));
bus.write(xAddress(operands[0], operands[1]), k); bus.write(xAddress(args[0], args[1]), k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
@@ -592,9 +591,9 @@ public class Cpu implements InstructionTable {
/** ROR - Rotate Right **************************************************/ /** ROR - Rotate Right **************************************************/
case 0x66: // ROR - Zero Page case 0x66: // ROR - Zero Page
j = bus.read(operands[0]); j = bus.read(args[0]);
k = ror(j); k = ror(j);
bus.write(operands[0], k); bus.write(args[0], k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
case 0x6a: // ROR - Accumulator case 0x6a: // ROR - Accumulator
@@ -602,21 +601,21 @@ public class Cpu implements InstructionTable {
setArithmeticFlags(a); setArithmeticFlags(a);
break; break;
case 0x6e: // ROR - Absolute case 0x6e: // ROR - Absolute
j = bus.read(address(operands[0], operands[1])); j = bus.read(address(args[0], args[1]));
k = ror(j); k = ror(j);
bus.write(address(operands[0], operands[1]), k); bus.write(address(args[0], args[1]), k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
case 0x76: // ROR - Zero Page,X case 0x76: // ROR - Zero Page,X
j = bus.read(zpxAddress(operands[0])); j = bus.read(zpxAddress(args[0]));
k = ror(j); k = ror(j);
bus.write(zpxAddress(operands[0]), k); bus.write(zpxAddress(args[0]), k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
case 0x7e: // ROR - Absolute,X case 0x7e: // ROR - Absolute,X
j = bus.read(xAddress(operands[0], operands[1])); j = bus.read(xAddress(args[0], args[1]));
k = ror(j); k = ror(j);
bus.write(xAddress(operands[0], operands[1]), k); bus.write(xAddress(args[0], args[1]), k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
@@ -636,76 +635,76 @@ public class Cpu implements InstructionTable {
/** STY - Store Y Register **********************************************/ /** STY - Store Y Register **********************************************/
case 0x84: // STY - Store Y Register - Zero Page case 0x84: // STY - Store Y Register - Zero Page
bus.write(operands[0], y); bus.write(args[0], y);
setArithmeticFlags(y); setArithmeticFlags(y);
break; break;
case 0x8c: // STY - Store Y Register - Absolute case 0x8c: // STY - Store Y Register - Absolute
bus.write(address(operands[0], operands[1]), y); bus.write(address(args[0], args[1]), y);
setArithmeticFlags(y); setArithmeticFlags(y);
break; break;
case 0x94: // STY - Store Y Register - Zero Page,X case 0x94: // STY - Store Y Register - Zero Page,X
bus.write(zpxAddress(operands[0]), y); bus.write(zpxAddress(args[0]), y);
setArithmeticFlags(y); setArithmeticFlags(y);
break; break;
/** STX - Store X Register **********************************************/ /** STX - Store X Register **********************************************/
case 0x86: // STX - Zero Page case 0x86: // STX - Zero Page
bus.write(operands[0], x); bus.write(args[0], x);
setArithmeticFlags(x); setArithmeticFlags(x);
break; break;
case 0x8e: // STX - Absolute case 0x8e: // STX - Absolute
bus.write(address(operands[0], operands[1]), x); bus.write(address(args[0], args[1]), x);
setArithmeticFlags(x); setArithmeticFlags(x);
break; break;
case 0x96: // STX - Zero Page,Y case 0x96: // STX - Zero Page,Y
bus.write(zpyAddress(operands[0]), x); bus.write(zpyAddress(args[0]), x);
setArithmeticFlags(x); setArithmeticFlags(x);
break; break;
/** LDY - Load Y Register ***********************************************/ /** LDY - Load Y Register ***********************************************/
case 0xa0: // LDY - Immediate case 0xa0: // LDY - Immediate
y = operands[0]; y = args[0];
setArithmeticFlags(y); setArithmeticFlags(y);
break; break;
case 0xa4: // LDY - Zero Page case 0xa4: // LDY - Zero Page
y = bus.read(operands[0]); y = bus.read(args[0]);
setArithmeticFlags(y); setArithmeticFlags(y);
break; break;
case 0xac: // LDY - Absolute case 0xac: // LDY - Absolute
y = bus.read(address(operands[0], operands[1])); y = bus.read(address(args[0], args[1]));
setArithmeticFlags(y); setArithmeticFlags(y);
break; break;
case 0xb4: // LDY - Zero Page,X case 0xb4: // LDY - Zero Page,X
y = bus.read(zpxAddress(operands[0])); y = bus.read(zpxAddress(args[0]));
setArithmeticFlags(y); setArithmeticFlags(y);
break; break;
case 0xbc: // LDY - Absolute,X case 0xbc: // LDY - Absolute,X
y = bus.read(xAddress(operands[0], operands[1])); y = bus.read(xAddress(args[0], args[1]));
setArithmeticFlags(y); setArithmeticFlags(y);
break; break;
/** LDX - Load X Register ***********************************************/ /** LDX - Load X Register ***********************************************/
case 0xa2: // LDX - Immediate case 0xa2: // LDX - Immediate
x = operands[0]; x = args[0];
setArithmeticFlags(x); setArithmeticFlags(x);
break; break;
case 0xa6: // LDX - Zero Page case 0xa6: // LDX - Zero Page
x = bus.read(operands[0]); x = bus.read(args[0]);
setArithmeticFlags(x); setArithmeticFlags(x);
break; break;
case 0xae: // LDX - Absolute case 0xae: // LDX - Absolute
x = bus.read(address(operands[0], operands[1])); x = bus.read(address(args[0], args[1]));
setArithmeticFlags(x); setArithmeticFlags(x);
break; break;
case 0xb6: // LDX - Zero Page,Y case 0xb6: // LDX - Zero Page,Y
x = bus.read(zpyAddress(operands[0])); x = bus.read(zpyAddress(args[0]));
setArithmeticFlags(x); setArithmeticFlags(x);
break; break;
case 0xbe: // LDX - Absolute,Y case 0xbe: // LDX - Absolute,Y
x = bus.read(yAddress(operands[0], operands[1])); x = bus.read(yAddress(args[0], args[1]));
setArithmeticFlags(x); setArithmeticFlags(x);
break; break;
@@ -726,13 +725,13 @@ public class Cpu implements InstructionTable {
/** CPY - Compare Y Register ********************************************/ /** CPY - Compare Y Register ********************************************/
case 0xc0: // CPY - Immediate case 0xc0: // CPY - Immediate
cmp(y, operands[0]); cmp(y, args[0]);
break; break;
case 0xc4: // CPY - Zero Page case 0xc4: // CPY - Zero Page
cmp(y, bus.read(operands[0])); cmp(y, bus.read(args[0]));
break; break;
case 0xcc: // CPY - Absolute case 0xcc: // CPY - Absolute
cmp(y, bus.read(address(operands[0], operands[1]))); cmp(y, bus.read(address(args[0], args[1])));
break; break;
@@ -751,40 +750,40 @@ public class Cpu implements InstructionTable {
/** DEC - Decrement Memory **********************************************/ /** DEC - Decrement Memory **********************************************/
case 0xc6: // DEC - Zero Page case 0xc6: // DEC - Zero Page
j = bus.read(operands[0]); j = bus.read(args[0]);
k = --j & 0xff; k = --j & 0xff;
bus.write(operands[0], k); bus.write(args[0], k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
case 0xce: // DEC - Absolute case 0xce: // DEC - Absolute
j = bus.read(address(operands[0], operands[1])); j = bus.read(address(args[0], args[1]));
k = --j & 0xff; k = --j & 0xff;
bus.write(address(operands[0], operands[1]), k); bus.write(address(args[0], args[1]), k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
case 0xd6: // DEC - Zero Page, X case 0xd6: // DEC - Zero Page, X
j = bus.read(zpxAddress(operands[0])); j = bus.read(zpxAddress(args[0]));
k = --j & 0xff; k = --j & 0xff;
bus.write(zpxAddress(operands[0]), k); bus.write(zpxAddress(args[0]), k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
case 0xde: // DEC - Absolute,X case 0xde: // DEC - Absolute,X
j = bus.read(xAddress(operands[0], operands[1])); j = bus.read(xAddress(args[0], args[1]));
k = --j & 0xff; k = --j & 0xff;
bus.write(xAddress(operands[0], operands[1]), k); bus.write(xAddress(args[0], args[1]), k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
/** CPX - Compare X Register ********************************************/ /** CPX - Compare X Register ********************************************/
case 0xe0: // CPX - Immediate case 0xe0: // CPX - Immediate
cmp(x, operands[0]); cmp(x, args[0]);
break; break;
case 0xe4: // CPX - Zero Page case 0xe4: // CPX - Zero Page
cmp(x, bus.read(operands[0])); cmp(x, bus.read(args[0]));
break; break;
case 0xec: // CPX - Absolute case 0xec: // CPX - Absolute
cmp(x, bus.read(address(operands[0], operands[1]))); cmp(x, bus.read(address(args[0], args[1])));
break; break;
@@ -807,27 +806,27 @@ public class Cpu implements InstructionTable {
/** INC - Increment Memory **********************************************/ /** INC - Increment Memory **********************************************/
case 0xe6: // INC - Zero Page case 0xe6: // INC - Zero Page
j = bus.read(operands[0]); j = bus.read(args[0]);
k = ++j & 0xff; k = ++j & 0xff;
bus.write(operands[0], k); bus.write(args[0], k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
case 0xee: // INC - Absolute case 0xee: // INC - Absolute
j = bus.read(address(operands[0], operands[1])); j = bus.read(address(args[0], args[1]));
k = ++j & 0xff; k = ++j & 0xff;
bus.write(address(operands[0], operands[1]), k); bus.write(address(args[0], args[1]), k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
case 0xf6: // INC - Zero Page,X case 0xf6: // INC - Zero Page,X
j = bus.read(zpxAddress(operands[0])); j = bus.read(zpxAddress(args[0]));
k = ++j & 0xff; k = ++j & 0xff;
bus.write(zpxAddress(operands[0]), k); bus.write(zpxAddress(args[0]), k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
case 0xfe: // INC - Absolute,X case 0xfe: // INC - Absolute,X
j = bus.read(xAddress(operands[0], operands[1])); j = bus.read(xAddress(args[0], args[1]));
k = ++j & 0xff; k = ++j & 0xff;
bus.write(xAddress(operands[0], operands[1]), k); bus.write(xAddress(args[0], args[1]), k);
setArithmeticFlags(k); setArithmeticFlags(k);
break; break;
@@ -1478,7 +1477,7 @@ public class Cpu implements InstructionTable {
* Returns a string representing the CPU state. * Returns a string representing the CPU state.
*/ */
public String toString() { public String toString() {
String opcode = opcode(ir, operands[0], operands[1]); String opcode = opcode(ir, args[0], args[1]);
StringBuffer sb = new StringBuffer(String.format("$%04X", addr) + StringBuffer sb = new StringBuffer(String.format("$%04X", addr) +
" "); " ");
sb.append(String.format("%-14s", opcode)); sb.append(String.format("%-14s", opcode));
@@ -1494,7 +1493,7 @@ public class Cpu implements InstructionTable {
* Push an item onto the stack, and decrement the stack counter. * Push an item onto the stack, and decrement the stack counter.
* Silently fails to push onto the stack if SP is * Silently fails to push onto the stack if SP is
*/ */
void stackPush(int data) { void stackPush(int data) throws MemoryAccessException {
bus.write(0x100+sp, data); bus.write(0x100+sp, data);
if (sp == 0) if (sp == 0)
@@ -1507,7 +1506,7 @@ public class Cpu implements InstructionTable {
/** /**
* Pre-increment the stack pointer, and return the top of the stack. * Pre-increment the stack pointer, and return the top of the stack.
*/ */
int stackPop() { int stackPop() throws MemoryAccessException {
if (sp == 0xff) if (sp == 0xff)
sp = 0x00; sp = 0x00;
else else
@@ -1521,7 +1520,7 @@ public class Cpu implements InstructionTable {
/** /**
* Peek at the value currently at the top of the stack * Peek at the value currently at the top of the stack
*/ */
int stackPeek() { int stackPeek() throws MemoryAccessException {
return bus.read(0x100+sp+1); return bus.read(0x100+sp+1);
} }
@@ -10,7 +10,7 @@ import com.loomcom.symon.exceptions.*;
public class Profiler implements InstructionTable { public class Profiler implements InstructionTable {
public static void main(String[] args) { public static void main(String[] args) throws MemoryAccessException {
// new Profiler().profileMemoryReads(); // new Profiler().profileMemoryReads();
// new Profiler().dumpOpCodes(); // new Profiler().dumpOpCodes();
new Profiler().profileProgram(); new Profiler().profileProgram();
@@ -31,7 +31,7 @@ public class Profiler implements InstructionTable {
} }
} }
public void profileProgram() { public void profileProgram() throws MemoryAccessException {
Bus bus = new Bus(0, 65535); Bus bus = new Bus(0, 65535);
Cpu cpu = new Cpu(); Cpu cpu = new Cpu();
@@ -96,7 +96,6 @@ public class Profiler implements InstructionTable {
sum += diff; sum += diff;
} }
long average = sum / iters;
long totalSteps = steps * iters; long totalSteps = steps * iters;
long avgStep = sum / totalSteps; long avgStep = sum / totalSteps;
@@ -108,7 +107,7 @@ public class Profiler implements InstructionTable {
avgStep + " ns "); avgStep + " ns ");
} }
public void profileMemoryReads() { public void profileMemoryReads() throws MemoryAccessException {
// Create a bus. // Create a bus.
Bus b = new Bus(0, 65535); Bus b = new Bus(0, 65535);
@@ -46,7 +46,7 @@ public class Simulator {
public void write(int address, int value) { public void write(int address, int value) {
} }
public void loadProgram(int address, int[] program) { public void loadProgram(int address, int[] program) throws MemoryAccessException {
// Reset interrupt vector // Reset interrupt vector
int hi = (address&0xff00)>>>8; int hi = (address&0xff00)>>>8;
int lo = address&0x00ff; int lo = address&0x00ff;
@@ -63,7 +63,7 @@ public class Simulator {
* A test method. * A test method.
*/ */
public void runTest() { public void runTest() throws MemoryAccessException {
int[] program = { int[] program = {
0xa9, // LDA #$FF 0xa9, // LDA #$FF
0xff, 0xff,
@@ -103,7 +103,7 @@ public class Simulator {
/** /**
* Main simulator routine. * Main simulator routine.
*/ */
public static void main(String[] args) { public static void main(String[] args) throws MemoryAccessException {
try { try {
new Simulator().runTest(); new Simulator().runTest();
} catch (MemoryRangeException ex) { } catch (MemoryRangeException ex) {
@@ -29,14 +29,18 @@ public abstract class Device implements Comparable<Device> {
} }
/* Methods required to be implemented by inheriting classes. */ /* Methods required to be implemented by inheriting classes. */
public abstract void write(int address, int data); public abstract void write(int address, int data) throws MemoryAccessException;
public abstract int read(int address); public abstract int read(int address) throws MemoryAccessException;
public abstract String toString(); public abstract String toString();
public void setBus(Bus bus) { public void setBus(Bus bus) {
this.bus = bus; this.bus = bus;
} }
public Bus getBus() {
return this.bus;
}
public MemoryRange getMemoryRange() { public MemoryRange getMemoryRange() {
return memoryRange; return memoryRange;
} }
@@ -2,7 +2,6 @@ package com.loomcom.symon.devices;
import java.util.*; import java.util.*;
import com.loomcom.symon.*;
import com.loomcom.symon.exceptions.*; import com.loomcom.symon.exceptions.*;
public class Memory extends Device { public class Memory extends Device {
@@ -24,11 +23,15 @@ public class Memory extends Device {
this(address, size, false); this(address, size, false);
} }
public void write(int address, int data) { public void write(int address, int data) throws MemoryAccessException {
this.mem[address] = data; if (readOnly) {
throw new MemoryAccessException("Cannot write to read-only memory at address " + address);
} else {
this.mem[address] = data;
}
} }
public int read(int address) { public int read(int address) throws MemoryAccessException {
return this.mem[address]; return this.mem[address];
} }
@@ -5,8 +5,6 @@ import junit.framework.*;
import com.loomcom.symon.devices.*; import com.loomcom.symon.devices.*;
import com.loomcom.symon.exceptions.*; import com.loomcom.symon.exceptions.*;
import java.util.*;
/** /**
* *
*/ */
@@ -1,7 +1,8 @@
package com.loomcom.symon; package com.loomcom.symon;
import com.loomcom.symon.devices.Memory; import com.loomcom.symon.devices.Memory;
import com.loomcom.symon.exceptions.MemoryRangeException; import com.loomcom.symon.exceptions.MemoryAccessException;
import junit.framework.TestCase; import junit.framework.TestCase;
public class CpuAbsoluteModeTest extends TestCase { public class CpuAbsoluteModeTest extends TestCase {
@@ -65,7 +66,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* ORA - Logical Inclusive OR - $0d */ /* ORA - Logical Inclusive OR - $0d */
public void test_ORA() { public void test_ORA() throws MemoryAccessException {
// Set some initial values in memory // Set some initial values in memory
bus.write(0x7f00, 0x00); bus.write(0x7f00, 0x00);
bus.write(0x7f02, 0x11); bus.write(0x7f02, 0x11);
@@ -78,27 +79,27 @@ public class CpuAbsoluteModeTest extends TestCase {
0x0d, 0x04, 0x35, // ORA $3504 0x0d, 0x04, 0x35, // ORA $3504
0x0d, 0x08, 0x35, // ORA $3508 0x0d, 0x08, 0x35, // ORA $3508
0x0d, 0x10, 0x12); // ORA $1210 0x0d, 0x10, 0x12); // ORA $1210
cpu.step(); extracted();
assertEquals(0x00, cpu.getAccumulator()); assertEquals(0x00, cpu.getAccumulator());
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
cpu.step(); extracted();
assertEquals(0x11, cpu.getAccumulator()); assertEquals(0x11, cpu.getAccumulator());
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
cpu.step(); extracted();
assertEquals(0x33, cpu.getAccumulator()); assertEquals(0x33, cpu.getAccumulator());
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
cpu.step(); extracted();
assertEquals(0x77, cpu.getAccumulator()); assertEquals(0x77, cpu.getAccumulator());
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
cpu.step(); extracted();
assertEquals(0xff, cpu.getAccumulator()); assertEquals(0xff, cpu.getAccumulator());
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
@@ -106,7 +107,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* ASL - Arithmetic Shift Left - $0e */ /* ASL - Arithmetic Shift Left - $0e */
public void test_ASL() { public void test_ASL() throws MemoryAccessException {
bus.write(0x7f00, 0x00); bus.write(0x7f00, 0x00);
bus.write(0x7f01, 0x01); bus.write(0x7f01, 0x01);
bus.write(0x3502, 0x02); bus.write(0x3502, 0x02);
@@ -119,31 +120,31 @@ public class CpuAbsoluteModeTest extends TestCase {
0x0e, 0x03, 0x35, // ASL $3503 0x0e, 0x03, 0x35, // ASL $3503
0x0e, 0x04, 0x12); // ASL $1204 0x0e, 0x04, 0x12); // ASL $1204
cpu.step(); extracted();
assertEquals(0x00, bus.read(0x7f00)); assertEquals(0x00, bus.read(0x7f00));
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x02, bus.read(0x7f01)); assertEquals(0x02, bus.read(0x7f01));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x04, bus.read(0x3502)); assertEquals(0x04, bus.read(0x3502));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x88, bus.read(0x3503)); assertEquals(0x88, bus.read(0x3503));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x00, bus.read(0x1204)); assertEquals(0x00, bus.read(0x1204));
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
@@ -152,7 +153,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* JSR - Jump to Subroutine - $20 */ /* JSR - Jump to Subroutine - $20 */
public void test_JSR() { public void test_JSR() throws MemoryAccessException {
bus.loadProgram(0xea, // NOP bus.loadProgram(0xea, // NOP
0xea, // NOP 0xea, // NOP
0x20, 0x00, 0x34); // JSR $3400 0x20, 0x00, 0x34); // JSR $3400
@@ -173,7 +174,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* BIT - Bit Test - $2c */ /* BIT - Bit Test - $2c */
public void test_BIT() { public void test_BIT() throws MemoryAccessException {
bus.write(0x1200, 0xc0); bus.write(0x1200, 0xc0);
bus.loadProgram(0xa9, 0x01, // LDA #$01 bus.loadProgram(0xa9, 0x01, // LDA #$01
@@ -227,7 +228,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* AND - Logical AND - $2d */ /* AND - Logical AND - $2d */
public void test_AND() { public void test_AND() throws MemoryAccessException {
bus.write(0x1200, 0x00); bus.write(0x1200, 0x00);
bus.write(0x1201, 0x11); bus.write(0x1201, 0x11);
bus.write(0x1202, 0xff); bus.write(0x1202, 0xff);
@@ -243,12 +244,12 @@ public class CpuAbsoluteModeTest extends TestCase {
0x2d, 0x04, 0x12, // AND $1204 0x2d, 0x04, 0x12, // AND $1204
0xa9, 0xff, // LDA #$ff 0xa9, 0xff, // LDA #$ff
0x2d, 0x05, 0x12); // AND $1205 0x2d, 0x05, 0x12); // AND $1205
cpu.step(); extracted();
assertEquals(0x00, cpu.getAccumulator()); assertEquals(0x00, cpu.getAccumulator());
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
cpu.step(); extracted();
assertEquals(0x00, cpu.getAccumulator()); assertEquals(0x00, cpu.getAccumulator());
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
@@ -258,12 +259,12 @@ public class CpuAbsoluteModeTest extends TestCase {
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
cpu.step(); extracted();
assertEquals(0x88, cpu.getAccumulator()); assertEquals(0x88, cpu.getAccumulator());
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
cpu.step(); extracted();
assertEquals(0x00, cpu.getAccumulator()); assertEquals(0x00, cpu.getAccumulator());
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
@@ -276,7 +277,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* ROL - Rotate Shift Left - $2e */ /* ROL - Rotate Shift Left - $2e */
public void test_ROL() { public void test_ROL() throws MemoryAccessException {
bus.write(0x1200, 0x00); bus.write(0x1200, 0x00);
bus.write(0x1201, 0x01); 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=%01000000, c=1)
0x2e, 0x01, 0x12); // ROL $1201 (m=%10000001, c=0) 0x2e, 0x01, 0x12); // ROL $1201 (m=%10000001, c=0)
cpu.step(); extracted();
assertEquals(0x00, bus.read(0x1200)); assertEquals(0x00, bus.read(0x1200));
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x02, bus.read(0x1201)); assertEquals(0x02, bus.read(0x1201));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
@@ -311,43 +312,43 @@ public class CpuAbsoluteModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x0a, bus.read(0x1201)); assertEquals(0x0a, bus.read(0x1201));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x14, bus.read(0x1201)); assertEquals(0x14, bus.read(0x1201));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x28, bus.read(0x1201)); assertEquals(0x28, bus.read(0x1201));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x50, bus.read(0x1201)); assertEquals(0x50, bus.read(0x1201));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0xa0, bus.read(0x1201)); assertEquals(0xa0, bus.read(0x1201));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x40, bus.read(0x1201)); assertEquals(0x40, bus.read(0x1201));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertTrue(cpu.getCarryFlag()); assertTrue(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x81, bus.read(0x1201)); assertEquals(0x81, bus.read(0x1201));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
@@ -356,17 +357,21 @@ public class CpuAbsoluteModeTest extends TestCase {
/* JMP - Jump - $4c */ /* JMP - Jump - $4c */
public void test_JMP() { public void test_JMP() throws MemoryAccessException {
bus.loadProgram(0x4c, 0x00, 0x34); bus.loadProgram(0x4c, 0x00, 0x34);
cpu.step(); extracted();
assertEquals(0x3400, cpu.getProgramCounter()); assertEquals(0x3400, cpu.getProgramCounter());
// No change to status flags. // No change to status flags.
assertEquals(0x20, cpu.getProcessorStatus()); assertEquals(0x20, cpu.getProcessorStatus());
} }
private void extracted() throws MemoryAccessException {
cpu.step();
}
/* EOR - Exclusive OR - $4d */ /* EOR - Exclusive OR - $4d */
public void test_EOR() { public void test_EOR() throws MemoryAccessException {
bus.write(0x1210, 0x00); bus.write(0x1210, 0x00);
bus.write(0x1211, 0xff); bus.write(0x1211, 0xff);
bus.write(0x1212, 0x33); bus.write(0x1212, 0x33);
@@ -382,17 +387,17 @@ public class CpuAbsoluteModeTest extends TestCase {
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
cpu.step(); extracted();
assertEquals(0x77, cpu.getAccumulator()); assertEquals(0x77, cpu.getAccumulator());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
cpu.step(); extracted();
assertEquals(0x44, cpu.getAccumulator()); assertEquals(0x44, cpu.getAccumulator());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
cpu.step(); extracted();
assertEquals(0x00, cpu.getAccumulator()); assertEquals(0x00, cpu.getAccumulator());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
@@ -400,7 +405,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* LSR - Logical Shift Right - $4e */ /* LSR - Logical Shift Right - $4e */
public void test_LSR() { public void test_LSR() throws MemoryAccessException {
bus.write(0x1200, 0x00); bus.write(0x1200, 0x00);
bus.write(0x1201, 0x01); bus.write(0x1201, 0x01);
bus.write(0x1202, 0x02); bus.write(0x1202, 0x02);
@@ -416,31 +421,31 @@ public class CpuAbsoluteModeTest extends TestCase {
0x38, // SEC 0x38, // SEC
0x4e, 0x05, 0x12); // LSR $1205 0x4e, 0x05, 0x12); // LSR $1205
cpu.step(); extracted();
assertEquals(0x00, bus.read(0x1200)); assertEquals(0x00, bus.read(0x1200));
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x00, bus.read(0x1201)); assertEquals(0x00, bus.read(0x1201));
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertTrue(cpu.getCarryFlag()); assertTrue(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x01, bus.read(0x1202)); assertEquals(0x01, bus.read(0x1202));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x22, bus.read(0x1203)); assertEquals(0x22, bus.read(0x1203));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x40, bus.read(0x1204)); assertEquals(0x40, bus.read(0x1204));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
@@ -456,7 +461,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* ADC - Add with Carry - $6d */ /* ADC - Add with Carry - $6d */
public void test_ADC() { public void test_ADC() throws MemoryAccessException {
bus.write(0x1210, 0x01); bus.write(0x1210, 0x01);
bus.write(0x1211, 0xff); bus.write(0x1211, 0xff);
@@ -540,7 +545,7 @@ public class CpuAbsoluteModeTest extends TestCase {
assertTrue(cpu.getCarryFlag()); assertTrue(cpu.getCarryFlag());
} }
public void test_ADC_IncludesCarry() { public void test_ADC_IncludesCarry() throws MemoryAccessException {
bus.write(0x1210, 0x01); bus.write(0x1210, 0x01);
bus.loadProgram(0xa9, 0x00, // LDA #$00 bus.loadProgram(0xa9, 0x00, // LDA #$00
@@ -554,7 +559,7 @@ public class CpuAbsoluteModeTest extends TestCase {
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
} }
public void test_ADC_DecimalMode() { public void test_ADC_DecimalMode() throws MemoryAccessException {
bus.write(0x1210, 0x01); bus.write(0x1210, 0x01);
bus.write(0x1211, 0x99); bus.write(0x1211, 0x99);
@@ -637,7 +642,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* ROR - Rotate Right - $6e */ /* ROR - Rotate Right - $6e */
public void test_ROR() { public void test_ROR() throws MemoryAccessException {
bus.write(0x1210, 0x00); bus.write(0x1210, 0x00);
bus.write(0x1211, 0x10); 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=%00100000, c=0)
0x6e, 0x11, 0x12); // ROR $1201 (m=%00010000, c=0) 0x6e, 0x11, 0x12); // ROR $1201 (m=%00010000, c=0)
cpu.step(); extracted();
assertEquals(0x00, bus.read(0x1210)); assertEquals(0x00, bus.read(0x1210));
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x08, bus.read(0x1211)); assertEquals(0x08, bus.read(0x1211));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x04, bus.read(0x1211)); assertEquals(0x04, bus.read(0x1211));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x02, bus.read(0x1211)); assertEquals(0x02, bus.read(0x1211));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x01, bus.read(0x1211)); assertEquals(0x01, bus.read(0x1211));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x00, bus.read(0x1211)); assertEquals(0x00, bus.read(0x1211));
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertTrue(cpu.getCarryFlag()); assertTrue(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x80, bus.read(0x1211)); assertEquals(0x80, bus.read(0x1211));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x40, bus.read(0x1211)); assertEquals(0x40, bus.read(0x1211));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x20, bus.read(0x1211)); assertEquals(0x20, bus.read(0x1211));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
cpu.step(); extracted();
assertEquals(0x10, bus.read(0x1211)); assertEquals(0x10, bus.read(0x1211));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
@@ -715,10 +720,10 @@ public class CpuAbsoluteModeTest extends TestCase {
/* STY - Store Y Register - $8c */ /* STY - Store Y Register - $8c */
public void test_STY() { public void test_STY() throws MemoryAccessException {
cpu.setYRegister(0x00); cpu.setYRegister(0x00);
bus.loadProgram(0x8c, 0x10, 0x12); bus.loadProgram(0x8c, 0x10, 0x12);
cpu.step(); extracted();
assertEquals(0x00, bus.read(0x1210)); assertEquals(0x00, bus.read(0x1210));
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
@@ -727,7 +732,7 @@ public class CpuAbsoluteModeTest extends TestCase {
cpu.setYRegister(0x0f); cpu.setYRegister(0x0f);
bus.loadProgram(0x8c, 0x10, 0x12); bus.loadProgram(0x8c, 0x10, 0x12);
cpu.step(); extracted();
assertEquals(0x0f, bus.read(0x1210)); assertEquals(0x0f, bus.read(0x1210));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
@@ -736,7 +741,7 @@ public class CpuAbsoluteModeTest extends TestCase {
cpu.setYRegister(0x80); cpu.setYRegister(0x80);
bus.loadProgram(0x8c, 0x10, 0x12); bus.loadProgram(0x8c, 0x10, 0x12);
cpu.step(); extracted();
assertEquals(0x80, bus.read(0x1210)); assertEquals(0x80, bus.read(0x1210));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
@@ -744,10 +749,10 @@ public class CpuAbsoluteModeTest extends TestCase {
/* STA - Store Accumulator - $8d */ /* STA - Store Accumulator - $8d */
public void test_STA() { public void test_STA() throws MemoryAccessException {
cpu.setAccumulator(0x00); cpu.setAccumulator(0x00);
bus.loadProgram(0x8d, 0x10, 0x12); bus.loadProgram(0x8d, 0x10, 0x12);
cpu.step(); extracted();
assertEquals(0x00, bus.read(0x1210)); assertEquals(0x00, bus.read(0x1210));
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
@@ -756,7 +761,7 @@ public class CpuAbsoluteModeTest extends TestCase {
cpu.setAccumulator(0x0f); cpu.setAccumulator(0x0f);
bus.loadProgram(0x8d, 0x10, 0x12); bus.loadProgram(0x8d, 0x10, 0x12);
cpu.step(); extracted();
assertEquals(0x0f, bus.read(0x1210)); assertEquals(0x0f, bus.read(0x1210));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
@@ -765,7 +770,7 @@ public class CpuAbsoluteModeTest extends TestCase {
cpu.setAccumulator(0x80); cpu.setAccumulator(0x80);
bus.loadProgram(0x8d, 0x10, 0x12); bus.loadProgram(0x8d, 0x10, 0x12);
cpu.step(); extracted();
assertEquals(0x80, bus.read(0x1210)); assertEquals(0x80, bus.read(0x1210));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
@@ -773,10 +778,10 @@ public class CpuAbsoluteModeTest extends TestCase {
/* STX - Store X Register - $8e */ /* STX - Store X Register - $8e */
public void test_STX() { public void test_STX() throws MemoryAccessException {
cpu.setXRegister(0x00); cpu.setXRegister(0x00);
bus.loadProgram(0x8e, 0x10, 0x12); bus.loadProgram(0x8e, 0x10, 0x12);
cpu.step(); extracted();
assertEquals(0x00, bus.read(0x1210)); assertEquals(0x00, bus.read(0x1210));
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
@@ -785,7 +790,7 @@ public class CpuAbsoluteModeTest extends TestCase {
cpu.setXRegister(0x0f); cpu.setXRegister(0x0f);
bus.loadProgram(0x8e, 0x10, 0x12); bus.loadProgram(0x8e, 0x10, 0x12);
cpu.step(); extracted();
assertEquals(0x0f, bus.read(0x1210)); assertEquals(0x0f, bus.read(0x1210));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
@@ -794,7 +799,7 @@ public class CpuAbsoluteModeTest extends TestCase {
cpu.setXRegister(0x80); cpu.setXRegister(0x80);
bus.loadProgram(0x8e, 0x10, 0x12); bus.loadProgram(0x8e, 0x10, 0x12);
cpu.step(); extracted();
assertEquals(0x80, bus.read(0x1210)); assertEquals(0x80, bus.read(0x1210));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
@@ -802,7 +807,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* LDA - Load Accumulator - $ad */ /* LDA - Load Accumulator - $ad */
public void test_LDA() { public void test_LDA() throws MemoryAccessException {
bus.write(0x1210, 0x00); bus.write(0x1210, 0x00);
bus.write(0x1211, 0x0f); bus.write(0x1211, 0x0f);
bus.write(0x1212, 0x80); bus.write(0x1212, 0x80);
@@ -811,17 +816,17 @@ public class CpuAbsoluteModeTest extends TestCase {
0xad, 0x11, 0x12, // LDA $1211 0xad, 0x11, 0x12, // LDA $1211
0xad, 0x12, 0x12); // LDA $1212 0xad, 0x12, 0x12); // LDA $1212
cpu.step(); extracted();
assertEquals(0x00, cpu.getAccumulator()); assertEquals(0x00, cpu.getAccumulator());
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
cpu.step(); extracted();
assertEquals(0x0f, cpu.getAccumulator()); assertEquals(0x0f, cpu.getAccumulator());
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
cpu.step(); extracted();
assertEquals(0x80, cpu.getAccumulator()); assertEquals(0x80, cpu.getAccumulator());
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
@@ -829,7 +834,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* LDX - Load X Register - $ae */ /* LDX - Load X Register - $ae */
public void test_LDX() { public void test_LDX() throws MemoryAccessException {
bus.write(0x1210, 0x00); bus.write(0x1210, 0x00);
bus.write(0x1211, 0x0f); bus.write(0x1211, 0x0f);
bus.write(0x1212, 0x80); bus.write(0x1212, 0x80);
@@ -838,17 +843,17 @@ public class CpuAbsoluteModeTest extends TestCase {
0xae, 0x11, 0x12, // LDX $1211 0xae, 0x11, 0x12, // LDX $1211
0xae, 0x12, 0x12); // LDX $1212 0xae, 0x12, 0x12); // LDX $1212
cpu.step(); extracted();
assertEquals(0x00, cpu.getXRegister()); assertEquals(0x00, cpu.getXRegister());
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
cpu.step(); extracted();
assertEquals(0x0f, cpu.getXRegister()); assertEquals(0x0f, cpu.getXRegister());
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
cpu.step(); extracted();
assertEquals(0x80, cpu.getXRegister()); assertEquals(0x80, cpu.getXRegister());
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
@@ -856,7 +861,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* LDY - Load Y Register - $bc */ /* LDY - Load Y Register - $bc */
public void test_LDY() { public void test_LDY() throws MemoryAccessException {
bus.write(0x1210, 0x00); bus.write(0x1210, 0x00);
bus.write(0x1211, 0x0f); bus.write(0x1211, 0x0f);
bus.write(0x1212, 0x80); bus.write(0x1212, 0x80);
@@ -865,17 +870,17 @@ public class CpuAbsoluteModeTest extends TestCase {
0xbc, 0x11, 0x12, // LDY $1211 0xbc, 0x11, 0x12, // LDY $1211
0xbc, 0x12, 0x12); // LDY $1212 0xbc, 0x12, 0x12); // LDY $1212
cpu.step(); extracted();
assertEquals(0x00, cpu.getYRegister()); assertEquals(0x00, cpu.getYRegister());
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
cpu.step(); extracted();
assertEquals(0x0f, cpu.getYRegister()); assertEquals(0x0f, cpu.getYRegister());
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
cpu.step(); extracted();
assertEquals(0x80, cpu.getYRegister()); assertEquals(0x80, cpu.getYRegister());
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
@@ -883,7 +888,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* CMP - Compare Accumulator - $cd */ /* CMP - Compare Accumulator - $cd */
public void test_CMP() { public void test_CMP() throws MemoryAccessException {
bus.write(0x1210, 0x00); bus.write(0x1210, 0x00);
bus.write(0x1211, 0x80); bus.write(0x1211, 0x80);
bus.write(0x1212, 0xff); bus.write(0x1212, 0xff);
@@ -894,17 +899,17 @@ public class CpuAbsoluteModeTest extends TestCase {
0xcd, 0x11, 0x12, // CMP $1211 0xcd, 0x11, 0x12, // CMP $1211
0xcd, 0x12, 0x12); // CMP $1212 0xcd, 0x12, 0x12); // CMP $1212
cpu.step(); extracted();
assertTrue(cpu.getCarryFlag()); // m > y assertTrue(cpu.getCarryFlag()); // m > y
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag()); // m - y < 0 assertTrue(cpu.getNegativeFlag()); // m - y < 0
cpu.step(); extracted();
assertTrue(cpu.getCarryFlag()); // m = y assertTrue(cpu.getCarryFlag()); // m = y
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); // m - y == 0 assertFalse(cpu.getNegativeFlag()); // m - y == 0
cpu.step(); extracted();
assertFalse(cpu.getCarryFlag()); // m < y assertFalse(cpu.getCarryFlag()); // m < y
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); // m - y > 0 assertFalse(cpu.getNegativeFlag()); // m - y > 0
@@ -912,7 +917,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* CPY - Compare Y Register - $cc */ /* CPY - Compare Y Register - $cc */
public void test_CPY() { public void test_CPY() throws MemoryAccessException {
bus.write(0x1210, 0x00); bus.write(0x1210, 0x00);
bus.write(0x1211, 0x80); bus.write(0x1211, 0x80);
bus.write(0x1212, 0xff); bus.write(0x1212, 0xff);
@@ -923,17 +928,17 @@ public class CpuAbsoluteModeTest extends TestCase {
0xcc, 0x11, 0x12, // CPY $1211 0xcc, 0x11, 0x12, // CPY $1211
0xcc, 0x12, 0x12); // CPY $1212 0xcc, 0x12, 0x12); // CPY $1212
cpu.step(); extracted();
assertTrue(cpu.getCarryFlag()); // m > y assertTrue(cpu.getCarryFlag()); // m > y
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag()); // m - y < 0 assertTrue(cpu.getNegativeFlag()); // m - y < 0
cpu.step(); extracted();
assertTrue(cpu.getCarryFlag()); // m = y assertTrue(cpu.getCarryFlag()); // m = y
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); // m - y == 0 assertFalse(cpu.getNegativeFlag()); // m - y == 0
cpu.step(); extracted();
assertFalse(cpu.getCarryFlag()); // m < y assertFalse(cpu.getCarryFlag()); // m < y
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); // m - y > 0 assertFalse(cpu.getNegativeFlag()); // m - y > 0
@@ -941,7 +946,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* DEC - Decrement Memory Location - $ce */ /* DEC - Decrement Memory Location - $ce */
public void test_DEC() { public void test_DEC() throws MemoryAccessException {
bus.write(0x1210, 0x00); bus.write(0x1210, 0x00);
bus.write(0x1211, 0x01); bus.write(0x1211, 0x01);
bus.write(0x1212, 0x80); bus.write(0x1212, 0x80);
@@ -952,22 +957,22 @@ public class CpuAbsoluteModeTest extends TestCase {
0xce, 0x12, 0x12, // DEC $1212 0xce, 0x12, 0x12, // DEC $1212
0xce, 0x13, 0x12); // DEC $1213 0xce, 0x13, 0x12); // DEC $1213
cpu.step(); extracted();
assertEquals(0xff, bus.read(0x1210)); assertEquals(0xff, bus.read(0x1210));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
cpu.step(); extracted();
assertEquals(0x00, bus.read(0x1211)); assertEquals(0x00, bus.read(0x1211));
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
cpu.step(); extracted();
assertEquals(0x7f, bus.read(0x1212)); assertEquals(0x7f, bus.read(0x1212));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
cpu.step(); extracted();
assertEquals(0xfe, bus.read(0x1213)); assertEquals(0xfe, bus.read(0x1213));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
@@ -975,7 +980,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* CPX - Compare X Register - $ec */ /* CPX - Compare X Register - $ec */
public void test_CPX() { public void test_CPX() throws MemoryAccessException {
bus.write(0x1210, 0x00); bus.write(0x1210, 0x00);
bus.write(0x1211, 0x80); bus.write(0x1211, 0x80);
bus.write(0x1212, 0xff); bus.write(0x1212, 0xff);
@@ -986,17 +991,17 @@ public class CpuAbsoluteModeTest extends TestCase {
0xec, 0x11, 0x12, // CPX $1211 0xec, 0x11, 0x12, // CPX $1211
0xec, 0x12, 0x12); // CPX $1212 0xec, 0x12, 0x12); // CPX $1212
cpu.step(); extracted();
assertTrue(cpu.getCarryFlag()); // m > y assertTrue(cpu.getCarryFlag()); // m > y
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag()); // m - y < 0 assertTrue(cpu.getNegativeFlag()); // m - y < 0
cpu.step(); extracted();
assertTrue(cpu.getCarryFlag()); // m = y assertTrue(cpu.getCarryFlag()); // m = y
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); // m - y == 0 assertFalse(cpu.getNegativeFlag()); // m - y == 0
cpu.step(); extracted();
assertFalse(cpu.getCarryFlag()); // m < y assertFalse(cpu.getCarryFlag()); // m < y
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); // m - y > 0 assertFalse(cpu.getNegativeFlag()); // m - y > 0
@@ -1004,7 +1009,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* SBC - Subtract with Carry (borrow) - $ed */ /* SBC - Subtract with Carry (borrow) - $ed */
public void test_SBC() { public void test_SBC() throws MemoryAccessException {
bus.write(0x1210, 0x01); bus.write(0x1210, 0x01);
bus.loadProgram(0xa9, 0x00, // LDA #$00 bus.loadProgram(0xa9, 0x00, // LDA #$00
@@ -1057,7 +1062,7 @@ public class CpuAbsoluteModeTest extends TestCase {
assertTrue(cpu.getCarryFlag()); assertTrue(cpu.getCarryFlag());
} }
public void test_SBC_IncludesNotOfCarry() { public void test_SBC_IncludesNotOfCarry() throws MemoryAccessException {
bus.write(0x1210, 0x01); bus.write(0x1210, 0x01);
// Subtrace with Carry Flag cleared // 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(0x1210, 0x01);
bus.write(0x1220, 0x11); bus.write(0x1220, 0x11);
@@ -1199,7 +1204,7 @@ public class CpuAbsoluteModeTest extends TestCase {
/* INC - Increment Memory Location - $ee */ /* INC - Increment Memory Location - $ee */
public void test_INC() { public void test_INC() throws MemoryAccessException {
bus.write(0x1210, 0x00); bus.write(0x1210, 0x00);
bus.write(0x1211, 0x7f); bus.write(0x1211, 0x7f);
bus.write(0x1212, 0xff); bus.write(0x1212, 0xff);
@@ -1208,17 +1213,17 @@ public class CpuAbsoluteModeTest extends TestCase {
0xee, 0x11, 0x12, // INC $1211 0xee, 0x11, 0x12, // INC $1211
0xee, 0x12, 0x12); // INC $1212 0xee, 0x12, 0x12); // INC $1212
cpu.step(); extracted();
assertEquals(0x01, bus.read(0x1210)); assertEquals(0x01, bus.read(0x1210));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
cpu.step(); extracted();
assertEquals(0x80, bus.read(0x1211)); assertEquals(0x80, bus.read(0x1211));
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
cpu.step(); extracted();
assertEquals(0x00, bus.read(0x1212)); assertEquals(0x00, bus.read(0x1212));
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
@@ -1,7 +1,8 @@
package com.loomcom.symon; package com.loomcom.symon;
import com.loomcom.symon.devices.Memory; import com.loomcom.symon.devices.Memory;
import com.loomcom.symon.exceptions.MemoryRangeException; import com.loomcom.symon.exceptions.MemoryAccessException;
import junit.framework.TestCase; import junit.framework.TestCase;
public class CpuAbsoluteXModeTest extends TestCase { public class CpuAbsoluteXModeTest extends TestCase {
@@ -53,7 +54,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* ORA - Logical Inclusive OR - $1d */ /* ORA - Logical Inclusive OR - $1d */
public void test_ORA() { public void test_ORA() throws MemoryAccessException {
// Set some initial values in memory // Set some initial values in memory
bus.write(0x2c30, 0x00); bus.write(0x2c30, 0x00);
bus.write(0x2c32, 0x11); bus.write(0x2c32, 0x11);
@@ -99,7 +100,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* ASL - Arithmetic Shift Left - $1e */ /* ASL - Arithmetic Shift Left - $1e */
public void test_ASL() { public void test_ASL() throws MemoryAccessException {
bus.write(0x2c30, 0x00); bus.write(0x2c30, 0x00);
bus.write(0x2c31, 0x01); bus.write(0x2c31, 0x01);
bus.write(0x2c32, 0x02); bus.write(0x2c32, 0x02);
@@ -148,7 +149,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* AND - Logical AND - $3d */ /* AND - Logical AND - $3d */
public void test_AND() { public void test_AND() throws MemoryAccessException {
bus.write(0x1a30, 0x00); bus.write(0x1a30, 0x00);
bus.write(0x1a31, 0x11); bus.write(0x1a31, 0x11);
bus.write(0x1a32, 0xff); bus.write(0x1a32, 0xff);
@@ -208,8 +209,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* ROL - Rotate Shift Left - $3e */ /* ROL - Rotate Shift Left - $3e */
public void test_ROL() { public void test_ROL() throws MemoryAccessException {
bus.write(0x1070, 0x00); bus.write(0x1070, 0x00);
bus.write(0x1071, 0x01); bus.write(0x1071, 0x01);
@@ -291,7 +291,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* EOR - Exclusive OR - $5d */ /* EOR - Exclusive OR - $5d */
public void test_EOR() { public void test_EOR() throws MemoryAccessException {
bus.write(0xab40, 0x00); bus.write(0xab40, 0x00);
bus.write(0xab41, 0xff); bus.write(0xab41, 0xff);
bus.write(0xab42, 0x33); bus.write(0xab42, 0x33);
@@ -327,7 +327,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* LSR - Logical Shift Right - $5e */ /* LSR - Logical Shift Right - $5e */
public void test_LSR() { public void test_LSR() throws MemoryAccessException {
bus.write(0xab30, 0x00); bus.write(0xab30, 0x00);
bus.write(0xab31, 0x01); bus.write(0xab31, 0x01);
bus.write(0xab32, 0x02); bus.write(0xab32, 0x02);
@@ -385,7 +385,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* ADC - Add with Carry - $7d */ /* ADC - Add with Carry - $7d */
public void test_ADC() { public void test_ADC() throws MemoryAccessException {
bus.write(0xab40, 0x01); bus.write(0xab40, 0x01);
bus.write(0xab41, 0xff); bus.write(0xab41, 0xff);
@@ -471,7 +471,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
assertTrue(cpu.getCarryFlag()); assertTrue(cpu.getCarryFlag());
} }
public void test_ADC_IncludesCarry() { public void test_ADC_IncludesCarry() throws MemoryAccessException {
bus.write(0xab40, 0x01); bus.write(0xab40, 0x01);
bus.loadProgram(0xa9, 0x00, // LDA #$00 bus.loadProgram(0xa9, 0x00, // LDA #$00
@@ -488,7 +488,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
} }
public void test_ADC_DecimalMode() { public void test_ADC_DecimalMode() throws MemoryAccessException {
bus.write(0xab40, 0x01); bus.write(0xab40, 0x01);
bus.write(0xab41, 0x99); bus.write(0xab41, 0x99);
@@ -574,7 +574,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* ROR - Rotate Right - $7e */ /* ROR - Rotate Right - $7e */
public void test_ROR() { public void test_ROR() throws MemoryAccessException {
bus.write(0xab40, 0x00); bus.write(0xab40, 0x00);
bus.write(0xab41, 0x10); bus.write(0xab41, 0x10);
@@ -655,7 +655,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* STA - Store Accumulator - $9d */ /* STA - Store Accumulator - $9d */
public void test_STA() { public void test_STA() throws MemoryAccessException {
cpu.setXRegister(0x30); cpu.setXRegister(0x30);
cpu.setAccumulator(0x00); cpu.setAccumulator(0x00);
@@ -686,7 +686,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* LDY - Load Y Register - $bc */ /* LDY - Load Y Register - $bc */
public void test_LDY() { public void test_LDY() throws MemoryAccessException {
bus.write(0xab45, 0x00); bus.write(0xab45, 0x00);
bus.write(0xab46, 0x0f); bus.write(0xab46, 0x0f);
bus.write(0xab47, 0x80); bus.write(0xab47, 0x80);
@@ -715,7 +715,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* LDA - Load Accumulator - $bd */ /* LDA - Load Accumulator - $bd */
public void test_LDA() { public void test_LDA() throws MemoryAccessException {
bus.write(0xab42, 0x00); bus.write(0xab42, 0x00);
bus.write(0xab43, 0x0f); bus.write(0xab43, 0x0f);
bus.write(0xab44, 0x80); bus.write(0xab44, 0x80);
@@ -744,7 +744,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* CMP - Compare Accumulator - $dd */ /* CMP - Compare Accumulator - $dd */
public void test_CMP() { public void test_CMP() throws MemoryAccessException {
bus.write(0xab40, 0x00); bus.write(0xab40, 0x00);
bus.write(0xab41, 0x80); bus.write(0xab41, 0x80);
bus.write(0xab42, 0xff); bus.write(0xab42, 0xff);
@@ -775,7 +775,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* DEC - Decrement Memory Location - $de */ /* DEC - Decrement Memory Location - $de */
public void test_DEC() { public void test_DEC() throws MemoryAccessException {
bus.write(0xab40, 0x00); bus.write(0xab40, 0x00);
bus.write(0xab41, 0x01); bus.write(0xab41, 0x01);
bus.write(0xab42, 0x80); bus.write(0xab42, 0x80);
@@ -811,7 +811,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* SBC - Subtract with Carry - $fd */ /* SBC - Subtract with Carry - $fd */
public void test_SBC() { public void test_SBC() throws MemoryAccessException {
bus.write(0xab40, 0x01); bus.write(0xab40, 0x01);
bus.loadProgram(0xa9, 0x00, // LDA #$00 bus.loadProgram(0xa9, 0x00, // LDA #$00
@@ -869,7 +869,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
assertTrue(cpu.getCarryFlag()); assertTrue(cpu.getCarryFlag());
} }
public void test_SBC_IncludesNotOfCarry() { public void test_SBC_IncludesNotOfCarry() throws MemoryAccessException {
bus.write(0xab40, 0x01); bus.write(0xab40, 0x01);
// Subtrace with Carry Flag cleared // 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(0xab40, 0x01);
bus.write(0xab50, 0x11); bus.write(0xab50, 0x11);
@@ -1020,7 +1020,7 @@ public class CpuAbsoluteXModeTest extends TestCase {
/* INC - Increment Memory Location - $fe */ /* INC - Increment Memory Location - $fe */
public void test_INC() { public void test_INC() throws MemoryAccessException {
bus.write(0xab30, 0x00); bus.write(0xab30, 0x00);
bus.write(0xab31, 0x7f); bus.write(0xab31, 0x7f);
bus.write(0xab32, 0xff); bus.write(0xab32, 0xff);
@@ -1,7 +1,8 @@
package com.loomcom.symon; package com.loomcom.symon;
import com.loomcom.symon.devices.Memory; import com.loomcom.symon.devices.Memory;
import com.loomcom.symon.exceptions.MemoryRangeException; import com.loomcom.symon.exceptions.MemoryAccessException;
import junit.framework.TestCase; import junit.framework.TestCase;
public class CpuAbsoluteYModeTest extends TestCase { public class CpuAbsoluteYModeTest extends TestCase {
@@ -47,7 +48,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
/* ORA - Logical Inclusive OR - $19 */ /* ORA - Logical Inclusive OR - $19 */
public void test_ORA() { public void test_ORA() throws MemoryAccessException {
// Set some initial values in memory // Set some initial values in memory
bus.write(0x2c30, 0x00); bus.write(0x2c30, 0x00);
bus.write(0x2c32, 0x11); bus.write(0x2c32, 0x11);
@@ -93,7 +94,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
/* AND - Logical AND - $39 */ /* AND - Logical AND - $39 */
public void test_AND() { public void test_AND() throws MemoryAccessException {
bus.write(0x1a30, 0x00); bus.write(0x1a30, 0x00);
bus.write(0x1a31, 0x11); bus.write(0x1a31, 0x11);
bus.write(0x1a32, 0xff); bus.write(0x1a32, 0xff);
@@ -153,7 +154,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
/* EOR - Exclusive OR - $59 */ /* EOR - Exclusive OR - $59 */
public void test_EOR() { public void test_EOR() throws MemoryAccessException {
bus.write(0xab40, 0x00); bus.write(0xab40, 0x00);
bus.write(0xab41, 0xff); bus.write(0xab41, 0xff);
bus.write(0xab42, 0x33); bus.write(0xab42, 0x33);
@@ -189,7 +190,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
/* ADC - Add with Carry - $79 */ /* ADC - Add with Carry - $79 */
public void test_ADC() { public void test_ADC() throws MemoryAccessException {
bus.write(0xab40, 0x01); bus.write(0xab40, 0x01);
bus.write(0xab41, 0xff); bus.write(0xab41, 0xff);
@@ -275,7 +276,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
assertTrue(cpu.getCarryFlag()); assertTrue(cpu.getCarryFlag());
} }
public void test_ADC_IncludesCarry() { public void test_ADC_IncludesCarry() throws MemoryAccessException {
bus.write(0xab40, 0x01); bus.write(0xab40, 0x01);
bus.loadProgram(0xa9, 0x00, // LDA #$00 bus.loadProgram(0xa9, 0x00, // LDA #$00
@@ -292,7 +293,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
} }
public void test_ADC_DecimalMode() { public void test_ADC_DecimalMode() throws MemoryAccessException {
bus.write(0xab40, 0x01); bus.write(0xab40, 0x01);
bus.write(0xab41, 0x99); bus.write(0xab41, 0x99);
@@ -378,7 +379,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
/* STA - Store Accumulator - $99 */ /* STA - Store Accumulator - $99 */
public void test_STA() { public void test_STA() throws MemoryAccessException {
cpu.setYRegister(0x30); cpu.setYRegister(0x30);
cpu.setAccumulator(0x00); cpu.setAccumulator(0x00);
@@ -409,7 +410,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
/* LDX - Load X Register - $be */ /* LDX - Load X Register - $be */
public void test_LDX() { public void test_LDX() throws MemoryAccessException {
bus.write(0xab45, 0x00); bus.write(0xab45, 0x00);
bus.write(0xab46, 0x0f); bus.write(0xab46, 0x0f);
bus.write(0xab47, 0x80); bus.write(0xab47, 0x80);
@@ -438,7 +439,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
/* LDA - Load Accumulator - $b9 */ /* LDA - Load Accumulator - $b9 */
public void test_LDA() { public void test_LDA() throws MemoryAccessException {
bus.write(0xab42, 0x00); bus.write(0xab42, 0x00);
bus.write(0xab43, 0x0f); bus.write(0xab43, 0x0f);
bus.write(0xab44, 0x80); bus.write(0xab44, 0x80);
@@ -467,7 +468,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
/* CMP - Compare Accumulator - $d9 */ /* CMP - Compare Accumulator - $d9 */
public void test_CMP() { public void test_CMP() throws MemoryAccessException {
bus.write(0xab40, 0x00); bus.write(0xab40, 0x00);
bus.write(0xab41, 0x80); bus.write(0xab41, 0x80);
bus.write(0xab42, 0xff); bus.write(0xab42, 0xff);
@@ -498,7 +499,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
/* SBC - Subtract with Carry - $f9 */ /* SBC - Subtract with Carry - $f9 */
public void test_SBC() { public void test_SBC() throws MemoryAccessException {
bus.write(0xab40, 0x01); bus.write(0xab40, 0x01);
bus.loadProgram(0xa9, 0x00, // LDA #$00 bus.loadProgram(0xa9, 0x00, // LDA #$00
@@ -556,7 +557,7 @@ public class CpuAbsoluteYModeTest extends TestCase {
assertTrue(cpu.getCarryFlag()); assertTrue(cpu.getCarryFlag());
} }
public void test_SBC_IncludesNotOfCarry() { public void test_SBC_IncludesNotOfCarry() throws MemoryAccessException {
bus.write(0xab40, 0x01); bus.write(0xab40, 0x01);
// Subtrace with Carry Flag cleared // 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(0xab40, 0x01);
bus.write(0xab50, 0x11); bus.write(0xab50, 0x11);
@@ -1,7 +1,8 @@
package com.loomcom.symon; package com.loomcom.symon;
import com.loomcom.symon.devices.Memory; import com.loomcom.symon.devices.Memory;
import com.loomcom.symon.exceptions.MemoryRangeException; import com.loomcom.symon.exceptions.*;
import junit.framework.*; import junit.framework.*;
public class CpuAccumulatorModeTest extends TestCase { public class CpuAccumulatorModeTest extends TestCase {
@@ -10,7 +11,7 @@ public class CpuAccumulatorModeTest extends TestCase {
protected Bus bus; protected Bus bus;
protected Memory mem; protected Memory mem;
public void setUp() throws MemoryRangeException { public void setUp() throws MemoryRangeException, MemoryAccessException {
this.cpu = new Cpu(); this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff); this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000); this.mem = new Memory(0x0000, 0x10000);
@@ -43,7 +44,7 @@ public class CpuAccumulatorModeTest extends TestCase {
/* ASL - Arithmetic Shift Left - $0a */ /* ASL - Arithmetic Shift Left - $0a */
public void test_ASL() { public void test_ASL() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x00, // LDA #$00 bus.loadProgram(0xa9, 0x00, // LDA #$00
0x0a, // ASL A 0x0a, // ASL A
@@ -92,7 +93,7 @@ public class CpuAccumulatorModeTest extends TestCase {
/* ROL - Rotate Left - $2a */ /* ROL - Rotate Left - $2a */
public void test_ROL() { public void test_ROL() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x00, // LDA #$00 bus.loadProgram(0xa9, 0x00, // LDA #$00
0x2a, // ROL A (m=%00000000, c=0) 0x2a, // ROL A (m=%00000000, c=0)
0xa9, 0x01, // LDA #$01 0xa9, 0x01, // LDA #$01
@@ -170,7 +171,7 @@ public class CpuAccumulatorModeTest extends TestCase {
/* LSR - Logical Shift Right - $4a */ /* LSR - Logical Shift Right - $4a */
public void test_LSR() { public void test_LSR() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x00, // LDA #$00 bus.loadProgram(0xa9, 0x00, // LDA #$00
0x4a, // LSR A 0x4a, // LSR A
@@ -230,7 +231,7 @@ public class CpuAccumulatorModeTest extends TestCase {
/* ROR - Rotate Right - $6a */ /* ROR - Rotate Right - $6a */
public void test_ROR() { public void test_ROR() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x00, // LDA #$00 bus.loadProgram(0xa9, 0x00, // LDA #$00
0x6a, // ROR A (m=%00000000, c=0) 0x6a, // ROR A (m=%00000000, c=0)
0xa9, 0x10, // LDA #$10 0xa9, 0x10, // LDA #$10
@@ -1,7 +1,8 @@
package com.loomcom.symon; package com.loomcom.symon;
import com.loomcom.symon.devices.Memory; import com.loomcom.symon.devices.Memory;
import com.loomcom.symon.exceptions.MemoryRangeException; import com.loomcom.symon.exceptions.*;
import junit.framework.*; import junit.framework.*;
public class CpuImmediateModeTest extends TestCase { public class CpuImmediateModeTest extends TestCase {
@@ -10,7 +11,7 @@ public class CpuImmediateModeTest extends TestCase {
protected Bus bus; protected Bus bus;
protected Memory mem; protected Memory mem;
public void setUp() throws MemoryRangeException { public void setUp() throws MemoryRangeException, MemoryAccessException {
this.cpu = new Cpu(); this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff); this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000); this.mem = new Memory(0x0000, 0x10000);
@@ -51,7 +52,7 @@ public class CpuImmediateModeTest extends TestCase {
/* ORA Immediate Mode Tests - 0x09 */ /* ORA Immediate Mode Tests - 0x09 */
public void test_ORA() { public void test_ORA() throws MemoryAccessException {
bus.loadProgram(0x09, 0x00, // ORA #$00 bus.loadProgram(0x09, 0x00, // ORA #$00
0x09, 0x11, // ORA #$11 0x09, 0x11, // ORA #$11
0x09, 0x22, // ORA #$22 0x09, 0x22, // ORA #$22
@@ -73,25 +74,25 @@ public class CpuImmediateModeTest extends TestCase {
assertEquals(0xff, cpu.getAccumulator()); assertEquals(0xff, cpu.getAccumulator());
} }
public void test_ORA_SetsZeroFlagIfResultIsZero() { public void test_ORA_SetsZeroFlagIfResultIsZero() throws MemoryAccessException {
bus.loadProgram(0x09, 0x00); // ORA #$00 bus.loadProgram(0x09, 0x00); // ORA #$00
cpu.step(); cpu.step();
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
} }
public void test_ORA_DoesNotSetZeroFlagIfResultNotZero() { public void test_ORA_DoesNotSetZeroFlagIfResultNotZero() throws MemoryAccessException {
bus.loadProgram(0x09, 0x01); // ORA #$01 bus.loadProgram(0x09, 0x01); // ORA #$01
cpu.step(); cpu.step();
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
} }
public void test_ORA_SetsNegativeFlagIfResultIsNegative() { public void test_ORA_SetsNegativeFlagIfResultIsNegative() throws MemoryAccessException {
bus.loadProgram(0x09, 0x80); // ORA #$80 bus.loadProgram(0x09, 0x80); // ORA #$80
cpu.step(); cpu.step();
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
} }
public void test_ORA_DoesNotSetNegativeFlagIfResultNotNegative() { public void test_ORA_DoesNotSetNegativeFlagIfResultNotNegative() throws MemoryAccessException {
bus.loadProgram(0x09, 0x7f); // ORA #$7F bus.loadProgram(0x09, 0x7f); // ORA #$7F
cpu.step(); cpu.step();
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
@@ -99,7 +100,7 @@ public class CpuImmediateModeTest extends TestCase {
/* AND Immediate Mode Tests - 0x29 */ /* AND Immediate Mode Tests - 0x29 */
public void test_AND() { public void test_AND() throws MemoryAccessException {
bus.loadProgram(0x29, 0x00, // AND #$00 bus.loadProgram(0x29, 0x00, // AND #$00
0x29, 0x11, // AND #$11 0x29, 0x11, // AND #$11
0xa9, 0xaa, // LDA #$AA 0xa9, 0xaa, // LDA #$AA
@@ -122,28 +123,28 @@ public class CpuImmediateModeTest extends TestCase {
assertEquals(0x00, cpu.getAccumulator()); assertEquals(0x00, cpu.getAccumulator());
} }
public void test_AND_SetsZeroFlagIfResultIsZero() { public void test_AND_SetsZeroFlagIfResultIsZero() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x88, // LDA #$88 bus.loadProgram(0xa9, 0x88, // LDA #$88
0x29, 0x11); // AND #$11 0x29, 0x11); // AND #$11
cpu.step(2); cpu.step(2);
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
} }
public void test_AND_DoesNotSetZeroFlagIfResultNotZero() { public void test_AND_DoesNotSetZeroFlagIfResultNotZero() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x88, // LDA #$88 bus.loadProgram(0xa9, 0x88, // LDA #$88
0x29, 0xf1); // AND #$F1 0x29, 0xf1); // AND #$F1
cpu.step(2); cpu.step(2);
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
} }
public void test_AND_SetsNegativeFlagIfResultIsNegative() { public void test_AND_SetsNegativeFlagIfResultIsNegative() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x88, // LDA #$88 bus.loadProgram(0xa9, 0x88, // LDA #$88
0x29, 0xf0); // AND #$F0 0x29, 0xf0); // AND #$F0
cpu.step(2); cpu.step(2);
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
} }
public void test_AND_DoesNotSetNegativeFlagIfResultNotNegative() { public void test_AND_DoesNotSetNegativeFlagIfResultNotNegative() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x88, // LDA #$88 bus.loadProgram(0xa9, 0x88, // LDA #$88
0x29, 0x0f); // AND #$0F 0x29, 0x0f); // AND #$0F
cpu.step(2); cpu.step(2);
@@ -152,7 +153,7 @@ public class CpuImmediateModeTest extends TestCase {
/* EOR Immediate Mode Tests - 0x49 */ /* EOR Immediate Mode Tests - 0x49 */
public void test_EOR() { public void test_EOR() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x88, // LDA #$88 bus.loadProgram(0xa9, 0x88, // LDA #$88
0x49, 0x00, // EOR #$00 0x49, 0x00, // EOR #$00
0x49, 0xff, // EOR #$ff 0x49, 0xff, // EOR #$ff
@@ -167,7 +168,7 @@ public class CpuImmediateModeTest extends TestCase {
assertEquals(0x44, cpu.getAccumulator()); assertEquals(0x44, cpu.getAccumulator());
} }
public void test_EOR_SetsArithmeticFlags() { public void test_EOR_SetsArithmeticFlags() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x77, // LDA #$77 bus.loadProgram(0xa9, 0x77, // LDA #$77
0x49, 0x77, // EOR #$77 0x49, 0x77, // EOR #$77
0x49, 0xff); // EOR #$ff 0x49, 0xff); // EOR #$ff
@@ -184,7 +185,7 @@ public class CpuImmediateModeTest extends TestCase {
/* ADC Immediate Mode Tests - 0x69 */ /* ADC Immediate Mode Tests - 0x69 */
public void test_ADC() { public void test_ADC() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x00, // LDA #$00 bus.loadProgram(0xa9, 0x00, // LDA #$00
0x69, 0x01); // ADC #$01 0x69, 0x01); // ADC #$01
cpu.step(2); cpu.step(2);
@@ -265,7 +266,7 @@ public class CpuImmediateModeTest extends TestCase {
assertTrue(cpu.getCarryFlag()); assertTrue(cpu.getCarryFlag());
} }
public void test_ADC_IncludesCarry() { public void test_ADC_IncludesCarry() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x00, // LDA #$01 bus.loadProgram(0xa9, 0x00, // LDA #$01
0x38, // SEC 0x38, // SEC
0x69, 0x01); // ADC #$01 0x69, 0x01); // ADC #$01
@@ -277,7 +278,7 @@ public class CpuImmediateModeTest extends TestCase {
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
} }
public void test_ADC_DecimalMode() { public void test_ADC_DecimalMode() throws MemoryAccessException {
bus.loadProgram(0xf8, // SED bus.loadProgram(0xf8, // SED
0xa9, 0x01, // LDA #$01 0xa9, 0x01, // LDA #$01
0x69, 0x01); // ADC #$01 0x69, 0x01); // ADC #$01
@@ -357,31 +358,31 @@ public class CpuImmediateModeTest extends TestCase {
/* LDY Immediate Mode Tests - 0xa0 */ /* LDY Immediate Mode Tests - 0xa0 */
public void test_LDY_SetsYRegister() { public void test_LDY_SetsYRegister() throws MemoryAccessException {
bus.loadProgram(0xa0, 0x12); // LDY #$12 bus.loadProgram(0xa0, 0x12); // LDY #$12
cpu.step(); cpu.step();
assertEquals(0x12, cpu.getYRegister()); assertEquals(0x12, cpu.getYRegister());
} }
public void test_LDY_SetsZeroFlagIfArgIsZero() { public void test_LDY_SetsZeroFlagIfArgIsZero() throws MemoryAccessException {
bus.loadProgram(0xa0, 0x00); // LDY #$00 bus.loadProgram(0xa0, 0x00); // LDY #$00
cpu.step(); cpu.step();
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
} }
public void test_LDY_DoesNotSetZeroFlagIfResultNotZero() { public void test_LDY_DoesNotSetZeroFlagIfResultNotZero() throws MemoryAccessException {
bus.loadProgram(0xa0, 0x12); // LDY #$12 bus.loadProgram(0xa0, 0x12); // LDY #$12
cpu.step(); cpu.step();
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
} }
public void test_LDY_SetsNegativeFlagIfResultIsNegative() { public void test_LDY_SetsNegativeFlagIfResultIsNegative() throws MemoryAccessException {
bus.loadProgram(0xa0, 0x80); // LDY #$80 bus.loadProgram(0xa0, 0x80); // LDY #$80
cpu.step(); cpu.step();
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
} }
public void test_LDY_DoesNotSetNegativeFlagIfResultNotNegative() { public void test_LDY_DoesNotSetNegativeFlagIfResultNotNegative() throws MemoryAccessException {
bus.loadProgram(0xa0, 0x7f); // LDY #$7F bus.loadProgram(0xa0, 0x7f); // LDY #$7F
cpu.step(); cpu.step();
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
@@ -389,31 +390,31 @@ public class CpuImmediateModeTest extends TestCase {
/* LDX Immediate Mode Tests - 0xa2 */ /* LDX Immediate Mode Tests - 0xa2 */
public void test_LDX_SetsXRegister() { public void test_LDX_SetsXRegister() throws MemoryAccessException {
bus.loadProgram(0xa2, 0x12); // LDX #$12 bus.loadProgram(0xa2, 0x12); // LDX #$12
cpu.step(); cpu.step();
assertEquals(0x12, cpu.getXRegister()); assertEquals(0x12, cpu.getXRegister());
} }
public void test_LDX_SetsZeroFlagIfResultIsZero() { public void test_LDX_SetsZeroFlagIfResultIsZero() throws MemoryAccessException {
bus.loadProgram(0xa2, 0x00); // LDX #$00 bus.loadProgram(0xa2, 0x00); // LDX #$00
cpu.step(); cpu.step();
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
} }
public void test_LDX_DoesNotSetZeroFlagIfResultNotZero() { public void test_LDX_DoesNotSetZeroFlagIfResultNotZero() throws MemoryAccessException {
bus.loadProgram(0xa2, 0x12); // LDX #$12 bus.loadProgram(0xa2, 0x12); // LDX #$12
cpu.step(); cpu.step();
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
} }
public void test_LDX_SetsNegativeFlagIfResultIsNegative() { public void test_LDX_SetsNegativeFlagIfResultIsNegative() throws MemoryAccessException {
bus.loadProgram(0xa2, 0x80); // LDX #$80 bus.loadProgram(0xa2, 0x80); // LDX #$80
cpu.step(); cpu.step();
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
} }
public void test_LDX_DoesNotSetNegativeFlagIfResultNotNegative() { public void test_LDX_DoesNotSetNegativeFlagIfResultNotNegative() throws MemoryAccessException {
bus.loadProgram(0xa2, 0x7f); // LDX #$7F bus.loadProgram(0xa2, 0x7f); // LDX #$7F
cpu.step(); cpu.step();
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
@@ -421,31 +422,31 @@ public class CpuImmediateModeTest extends TestCase {
/* LDA Immediate Mode Tests - 0xa9 */ /* LDA Immediate Mode Tests - 0xa9 */
public void test_LDA_SetsAccumulator() { public void test_LDA_SetsAccumulator() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x12); // LDA #$12 bus.loadProgram(0xa9, 0x12); // LDA #$12
cpu.step(); cpu.step();
assertEquals(0x12, cpu.getAccumulator()); assertEquals(0x12, cpu.getAccumulator());
} }
public void test_LDA_SetsZeroFlagIfResultIsZero() { public void test_LDA_SetsZeroFlagIfResultIsZero() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x00); // LDA #$00 bus.loadProgram(0xa9, 0x00); // LDA #$00
cpu.step(); cpu.step();
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
} }
public void test_LDA_DoesNotSetZeroFlagIfResultNotZero() { public void test_LDA_DoesNotSetZeroFlagIfResultNotZero() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x12); // LDA #$12 bus.loadProgram(0xa9, 0x12); // LDA #$12
cpu.step(); cpu.step();
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
} }
public void test_LDA_SetsNegativeFlagIfResultIsNegative() { public void test_LDA_SetsNegativeFlagIfResultIsNegative() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x80); // LDA #$80 bus.loadProgram(0xa9, 0x80); // LDA #$80
cpu.step(); cpu.step();
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
} }
public void test_LDA_DoesNotSetNegativeFlagIfResultNotNegative() { public void test_LDA_DoesNotSetNegativeFlagIfResultNotNegative() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x7f); // LDA #$7F bus.loadProgram(0xa9, 0x7f); // LDA #$7F
cpu.step(); cpu.step();
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
@@ -453,7 +454,7 @@ public class CpuImmediateModeTest extends TestCase {
/* CPY Immediate Mode Tests - 0xc0 */ /* CPY Immediate Mode Tests - 0xc0 */
public void test_CPY_SetsZeroAndCarryFlagsIfNumbersSame() { public void test_CPY_SetsZeroAndCarryFlagsIfNumbersSame() throws MemoryAccessException {
bus.loadProgram(0xa0, 0x00, // LDY #$00 bus.loadProgram(0xa0, 0x00, // LDY #$00
0xc0, 0x00); // CPY #$00 0xc0, 0x00); // CPY #$00
cpu.step(2); cpu.step(2);
@@ -486,7 +487,7 @@ public class CpuImmediateModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
} }
public void test_CPY_SetsCarryFlagIfYGreaterThanMemory() { public void test_CPY_SetsCarryFlagIfYGreaterThanMemory() throws MemoryAccessException {
bus.loadProgram(0xa0, 0x0a, // LDY #$0A bus.loadProgram(0xa0, 0x0a, // LDY #$0A
0xc0, 0x08); // CPY #$08 0xc0, 0x08); // CPY #$08
cpu.step(2); cpu.step(2);
@@ -505,7 +506,7 @@ public class CpuImmediateModeTest extends TestCase {
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
} }
public void test_CPY_DoesNotSetCarryFlagIfYLessThanThanMemory() { public void test_CPY_DoesNotSetCarryFlagIfYLessThanThanMemory() throws MemoryAccessException {
bus.loadProgram(0xa0, 0x08, // LDY #$08 bus.loadProgram(0xa0, 0x08, // LDY #$08
0xc0, 0x0a); // CPY #$0A 0xc0, 0x0a); // CPY #$0A
cpu.step(2); cpu.step(2);
@@ -524,7 +525,7 @@ public class CpuImmediateModeTest extends TestCase {
/* CMP Immediate Mode Tests - 0xc9 */ /* CMP Immediate Mode Tests - 0xc9 */
public void test_CMP_SetsZeroAndCarryFlagsIfNumbersSame() { public void test_CMP_SetsZeroAndCarryFlagsIfNumbersSame() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x00, // LDA #$00 bus.loadProgram(0xa9, 0x00, // LDA #$00
0xc9, 0x00); // CMP #$00 0xc9, 0x00); // CMP #$00
cpu.step(2); cpu.step(2);
@@ -557,7 +558,7 @@ public class CpuImmediateModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
} }
public void test_CMP_SetsCarryFlagIfYGreaterThanMemory() { public void test_CMP_SetsCarryFlagIfYGreaterThanMemory() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x0a, // LDA #$0A bus.loadProgram(0xa9, 0x0a, // LDA #$0A
0xc9, 0x08); // CMP #$08 0xc9, 0x08); // CMP #$08
cpu.step(2); cpu.step(2);
@@ -576,7 +577,7 @@ public class CpuImmediateModeTest extends TestCase {
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
} }
public void test_CMP_DoesNotSetCarryFlagIfYGreaterThanMemory() { public void test_CMP_DoesNotSetCarryFlagIfYGreaterThanMemory() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x08, // LDA #$08 bus.loadProgram(0xa9, 0x08, // LDA #$08
0xc9, 0x0a); // CMP #$0A 0xc9, 0x0a); // CMP #$0A
cpu.step(2); cpu.step(2);
@@ -595,7 +596,7 @@ public class CpuImmediateModeTest extends TestCase {
/* CPX Immediate Mode Tests - 0xe0 */ /* CPX Immediate Mode Tests - 0xe0 */
public void test_CPX_SetsZeroAndCarryFlagsIfNumbersSame() { public void test_CPX_SetsZeroAndCarryFlagsIfNumbersSame() throws MemoryAccessException {
bus.loadProgram(0xa2, 0x00, // LDX #$00 bus.loadProgram(0xa2, 0x00, // LDX #$00
0xe0, 0x00); // CPX #$00 0xe0, 0x00); // CPX #$00
cpu.step(2); cpu.step(2);
@@ -628,7 +629,7 @@ public class CpuImmediateModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
} }
public void test_CPX_SetsCarryFlagIfYGreaterThanMemory() { public void test_CPX_SetsCarryFlagIfYGreaterThanMemory() throws MemoryAccessException {
bus.loadProgram(0xa2, 0x0a, // LDX #$0A bus.loadProgram(0xa2, 0x0a, // LDX #$0A
0xe0, 0x08); // CPX #$08 0xe0, 0x08); // CPX #$08
cpu.step(2); cpu.step(2);
@@ -647,7 +648,7 @@ public class CpuImmediateModeTest extends TestCase {
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
} }
public void test_CPX_DoesNotSetCarryFlagIfYGreaterThanMemory() { public void test_CPX_DoesNotSetCarryFlagIfYGreaterThanMemory() throws MemoryAccessException {
bus.loadProgram(0xa2, 0x08, // LDX #$08 bus.loadProgram(0xa2, 0x08, // LDX #$08
0xe0, 0x0a); // CPX #$0A 0xe0, 0x0a); // CPX #$0A
cpu.step(2); cpu.step(2);
@@ -666,7 +667,7 @@ public class CpuImmediateModeTest extends TestCase {
/* SBC Immediate Mode Tests - 0xe9 */ /* SBC Immediate Mode Tests - 0xe9 */
public void test_SBC() { public void test_SBC() throws MemoryAccessException {
bus.loadProgram(0xa9, 0x00, // LDA #$00 bus.loadProgram(0xa9, 0x00, // LDA #$00
0xe9, 0x01); // SBC #$01 0xe9, 0x01); // SBC #$01
cpu.step(2); cpu.step(2);
@@ -717,7 +718,7 @@ public class CpuImmediateModeTest extends TestCase {
assertTrue(cpu.getCarryFlag()); assertTrue(cpu.getCarryFlag());
} }
public void test_SBC_IncludesNotOfCarry() { public void test_SBC_IncludesNotOfCarry() throws MemoryAccessException {
// Subtrace with Carry Flag cleared // Subtrace with Carry Flag cleared
bus.loadProgram(0x18, // CLC bus.loadProgram(0x18, // CLC
0xa9, 0x05, // LDA #$00 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, bus.loadProgram(0xf8,
0xa9, 0x00, 0xa9, 0x00,
0xe9, 0x01); 0xe9, 0x01);
@@ -1,6 +1,7 @@
package com.loomcom.symon; package com.loomcom.symon;
import com.loomcom.symon.devices.Memory; import com.loomcom.symon.devices.Memory;
import com.loomcom.symon.exceptions.MemoryAccessException;
import com.loomcom.symon.exceptions.MemoryRangeException; import com.loomcom.symon.exceptions.MemoryRangeException;
import junit.framework.*; import junit.framework.*;
@@ -10,7 +11,7 @@ public class CpuImpliedModeTest extends TestCase {
protected Bus bus; protected Bus bus;
protected Memory mem; protected Memory mem;
public void setUp() throws MemoryRangeException { public void setUp() throws MemoryRangeException, MemoryAccessException {
this.cpu = new Cpu(); this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff); this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000); this.mem = new Memory(0x0000, 0x10000);
@@ -68,7 +69,7 @@ public class CpuImpliedModeTest extends TestCase {
/* BRK Tests - 0x00 */ /* BRK Tests - 0x00 */
public void test_BRK() { public void test_BRK() throws MemoryAccessException {
cpu.setCarryFlag(); cpu.setCarryFlag();
cpu.setOverflowFlag(); cpu.setOverflowFlag();
assertEquals(0x20|Cpu.P_CARRY|Cpu.P_OVERFLOW, assertEquals(0x20|Cpu.P_CARRY|Cpu.P_OVERFLOW,
@@ -111,7 +112,7 @@ public class CpuImpliedModeTest extends TestCase {
cpu.getProcessorStatus()); cpu.getProcessorStatus());
} }
public void test_BRK_HonorsIrqDisableFlag() { public void test_BRK_HonorsIrqDisableFlag() throws MemoryAccessException {
cpu.setIrqDisableFlag(); cpu.setIrqDisableFlag();
bus.loadProgram(0xea, bus.loadProgram(0xea,
@@ -143,7 +144,7 @@ public class CpuImpliedModeTest extends TestCase {
} }
/* CLC - Clear Carry Flag - $18 */ /* CLC - Clear Carry Flag - $18 */
public void test_CLC() { public void test_CLC() throws MemoryAccessException {
cpu.setCarryFlag(); cpu.setCarryFlag();
assertTrue(cpu.getCarryFlag()); assertTrue(cpu.getCarryFlag());
@@ -154,7 +155,7 @@ public class CpuImpliedModeTest extends TestCase {
} }
/* CLD - Clear Decimal Mode Flag - $d8 */ /* CLD - Clear Decimal Mode Flag - $d8 */
public void test_CLD() { public void test_CLD() throws MemoryAccessException {
cpu.setDecimalModeFlag(); cpu.setDecimalModeFlag();
assertTrue(cpu.getDecimalModeFlag()); assertTrue(cpu.getDecimalModeFlag());
@@ -165,7 +166,7 @@ public class CpuImpliedModeTest extends TestCase {
} }
/* CLI - Clear Interrupt Disabled Flag - $58 */ /* CLI - Clear Interrupt Disabled Flag - $58 */
public void test_CLI() { public void test_CLI() throws MemoryAccessException {
cpu.setIrqDisableFlag(); cpu.setIrqDisableFlag();
assertTrue(cpu.getIrqDisableFlag()); assertTrue(cpu.getIrqDisableFlag());
@@ -176,7 +177,7 @@ public class CpuImpliedModeTest extends TestCase {
} }
/* CLV - Clear Overflow Flag - $b8 */ /* CLV - Clear Overflow Flag - $b8 */
public void test_CLV() { public void test_CLV() throws MemoryAccessException {
cpu.setOverflowFlag(); cpu.setOverflowFlag();
assertTrue(cpu.getOverflowFlag()); assertTrue(cpu.getOverflowFlag());
@@ -188,7 +189,7 @@ public class CpuImpliedModeTest extends TestCase {
/* DEX - Decrement the X register - $ca */ /* DEX - Decrement the X register - $ca */
public void test_DEX() { public void test_DEX() throws MemoryAccessException {
bus.loadProgram(0xca); bus.loadProgram(0xca);
cpu.setXRegister(0x02); cpu.setXRegister(0x02);
cpu.step(); cpu.step();
@@ -197,7 +198,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
} }
public void test_DEX_SetsZeroFlagWhenZero() { public void test_DEX_SetsZeroFlagWhenZero() throws MemoryAccessException {
bus.loadProgram(0xca); bus.loadProgram(0xca);
cpu.setXRegister(0x01); cpu.setXRegister(0x01);
cpu.step(); cpu.step();
@@ -206,7 +207,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
} }
public void test_DEX_SetsNegativeFlagWhen() { public void test_DEX_SetsNegativeFlagWhen() throws MemoryAccessException {
bus.loadProgram(0xca); bus.loadProgram(0xca);
cpu.step(); cpu.step();
assertEquals(0xff, cpu.getXRegister()); assertEquals(0xff, cpu.getXRegister());
@@ -216,7 +217,7 @@ public class CpuImpliedModeTest extends TestCase {
/* DEY - Decrement the Y register - $88 */ /* DEY - Decrement the Y register - $88 */
public void test_DEY() { public void test_DEY() throws MemoryAccessException {
bus.loadProgram(0x88); bus.loadProgram(0x88);
cpu.setYRegister(0x02); cpu.setYRegister(0x02);
cpu.step(); cpu.step();
@@ -225,7 +226,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
} }
public void test_DEY_SetsZeroFlagWhenZero() { public void test_DEY_SetsZeroFlagWhenZero() throws MemoryAccessException {
bus.loadProgram(0x88); bus.loadProgram(0x88);
cpu.setYRegister(0x01); cpu.setYRegister(0x01);
cpu.step(); cpu.step();
@@ -234,7 +235,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
} }
public void test_DEY_SetsNegativeFlagWhen() { public void test_DEY_SetsNegativeFlagWhen() throws MemoryAccessException {
bus.loadProgram(0x88); bus.loadProgram(0x88);
cpu.step(); cpu.step();
assertEquals(0xff, cpu.getYRegister()); assertEquals(0xff, cpu.getYRegister());
@@ -244,7 +245,7 @@ public class CpuImpliedModeTest extends TestCase {
/* INX - Increment the X register - $e8 */ /* INX - Increment the X register - $e8 */
public void test_INX() { public void test_INX() throws MemoryAccessException {
bus.loadProgram(0xe8); bus.loadProgram(0xe8);
cpu.step(); cpu.step();
assertEquals(0x01, cpu.getXRegister()); assertEquals(0x01, cpu.getXRegister());
@@ -252,7 +253,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
} }
public void test_INX_SetsNegativeFlagWhenNegative() { public void test_INX_SetsNegativeFlagWhenNegative() throws MemoryAccessException {
bus.loadProgram(0xe8); bus.loadProgram(0xe8);
cpu.setXRegister(0x7f); cpu.setXRegister(0x7f);
cpu.step(); cpu.step();
@@ -261,7 +262,7 @@ public class CpuImpliedModeTest extends TestCase {
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
} }
public void test_INX_SetsZeroFlagWhenZero() { public void test_INX_SetsZeroFlagWhenZero() throws MemoryAccessException {
bus.loadProgram(0xe8); bus.loadProgram(0xe8);
cpu.setXRegister(0xff); cpu.setXRegister(0xff);
cpu.step(); cpu.step();
@@ -272,7 +273,7 @@ public class CpuImpliedModeTest extends TestCase {
/* INY - Increment the Y register - $c8 */ /* INY - Increment the Y register - $c8 */
public void test_INY() { public void test_INY() throws MemoryAccessException {
bus.loadProgram(0xc8); bus.loadProgram(0xc8);
cpu.step(); cpu.step();
assertEquals(0x01, cpu.getYRegister()); assertEquals(0x01, cpu.getYRegister());
@@ -280,7 +281,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
} }
public void test_INY_SetsNegativeFlagWhenNegative() { public void test_INY_SetsNegativeFlagWhenNegative() throws MemoryAccessException {
bus.loadProgram(0xc8); bus.loadProgram(0xc8);
cpu.setYRegister(0x7f); cpu.setYRegister(0x7f);
cpu.step(); cpu.step();
@@ -289,7 +290,7 @@ public class CpuImpliedModeTest extends TestCase {
assertTrue(cpu.getNegativeFlag()); assertTrue(cpu.getNegativeFlag());
} }
public void test_INY_SetsZeroFlagWhenZero() { public void test_INY_SetsZeroFlagWhenZero() throws MemoryAccessException {
bus.loadProgram(0xc8); bus.loadProgram(0xc8);
cpu.setYRegister(0xff); cpu.setYRegister(0xff);
cpu.step(); cpu.step();
@@ -300,7 +301,7 @@ public class CpuImpliedModeTest extends TestCase {
/* NOP - No Operation - $ea */ /* NOP - No Operation - $ea */
public void test_NOP() { public void test_NOP() throws MemoryAccessException {
bus.loadProgram(0xea); bus.loadProgram(0xea);
cpu.step(); cpu.step();
// Should just not change anything except PC // Should just not change anything except PC
@@ -314,7 +315,7 @@ public class CpuImpliedModeTest extends TestCase {
/* PHA - Push Accumulator - $48 */ /* PHA - Push Accumulator - $48 */
public void test_PHA() { public void test_PHA() throws MemoryAccessException {
bus.loadProgram(0x48); bus.loadProgram(0x48);
cpu.setAccumulator(0x3a); cpu.setAccumulator(0x3a);
cpu.step(); cpu.step();
@@ -324,7 +325,7 @@ public class CpuImpliedModeTest extends TestCase {
/* PHP - Push Processor Status - $08 */ /* PHP - Push Processor Status - $08 */
public void test_PHP() { public void test_PHP() throws MemoryAccessException {
bus.loadProgram(0x08); bus.loadProgram(0x08);
cpu.setProcessorStatus(0x27); cpu.setProcessorStatus(0x27);
cpu.step(); cpu.step();
@@ -334,7 +335,7 @@ public class CpuImpliedModeTest extends TestCase {
/* PLA - Pul Accumulator - $68 */ /* PLA - Pul Accumulator - $68 */
public void test_PLA() { public void test_PLA() throws MemoryAccessException {
cpu.stackPush(0x32); cpu.stackPush(0x32);
bus.loadProgram(0x68); bus.loadProgram(0x68);
cpu.step(); cpu.step();
@@ -343,7 +344,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getZeroFlag()); assertFalse(cpu.getZeroFlag());
} }
public void test_PLA_SetsZeroIfAccumulatorIsZero() { public void test_PLA_SetsZeroIfAccumulatorIsZero() throws MemoryAccessException {
cpu.stackPush(0x00); cpu.stackPush(0x00);
bus.loadProgram(0x68); bus.loadProgram(0x68);
cpu.step(); cpu.step();
@@ -352,7 +353,7 @@ public class CpuImpliedModeTest extends TestCase {
assertTrue(cpu.getZeroFlag()); assertTrue(cpu.getZeroFlag());
} }
public void test_PLA_SetsNegativeIfAccumulatorIsNegative() { public void test_PLA_SetsNegativeIfAccumulatorIsNegative() throws MemoryAccessException {
cpu.stackPush(0xff); cpu.stackPush(0xff);
bus.loadProgram(0x68); bus.loadProgram(0x68);
cpu.step(); cpu.step();
@@ -363,7 +364,7 @@ public class CpuImpliedModeTest extends TestCase {
/* PLP - Pull Processor Status - $28 */ /* PLP - Pull Processor Status - $28 */
public void test_PLP() { public void test_PLP() throws MemoryAccessException {
cpu.stackPush(0x2f); cpu.stackPush(0x2f);
bus.loadProgram(0x28); bus.loadProgram(0x28);
cpu.step(); cpu.step();
@@ -372,7 +373,7 @@ public class CpuImpliedModeTest extends TestCase {
/* RTI - Return from Interrupt - $40 */ /* RTI - Return from Interrupt - $40 */
public void test_RTI() { public void test_RTI() throws MemoryAccessException {
cpu.stackPush(0x0f); // PC hi cpu.stackPush(0x0f); // PC hi
cpu.stackPush(0x11); // PC lo cpu.stackPush(0x11); // PC lo
cpu.stackPush(0x29); // status cpu.stackPush(0x29); // status
@@ -386,7 +387,7 @@ public class CpuImpliedModeTest extends TestCase {
/* RTS - Return from Subroutine - $60 */ /* RTS - Return from Subroutine - $60 */
public void test_RTS() { public void test_RTS() throws MemoryAccessException {
cpu.stackPush(0x0f); // PC hi cpu.stackPush(0x0f); // PC hi
cpu.stackPush(0x11); // PC lo cpu.stackPush(0x11); // PC lo
@@ -399,7 +400,7 @@ public class CpuImpliedModeTest extends TestCase {
/* SEC - Set Carry Flag - $38 */ /* SEC - Set Carry Flag - $38 */
public void test_SEC() { public void test_SEC() throws MemoryAccessException {
bus.loadProgram(0x38); bus.loadProgram(0x38);
cpu.step(); cpu.step();
assertTrue(cpu.getCarryFlag()); assertTrue(cpu.getCarryFlag());
@@ -407,7 +408,7 @@ public class CpuImpliedModeTest extends TestCase {
/* SED - Set Decimal Mode Flag - $f8 */ /* SED - Set Decimal Mode Flag - $f8 */
public void test_SED() { public void test_SED() throws MemoryAccessException {
bus.loadProgram(0xf8); bus.loadProgram(0xf8);
cpu.step(); cpu.step();
assertTrue(cpu.getDecimalModeFlag()); assertTrue(cpu.getDecimalModeFlag());
@@ -415,7 +416,7 @@ public class CpuImpliedModeTest extends TestCase {
/* SEI - Set Interrupt Disable Flag - $78 */ /* SEI - Set Interrupt Disable Flag - $78 */
public void test_SEI() { public void test_SEI() throws MemoryAccessException {
bus.loadProgram(0x78); bus.loadProgram(0x78);
cpu.step(); cpu.step();
assertTrue(cpu.getIrqDisableFlag()); assertTrue(cpu.getIrqDisableFlag());
@@ -423,7 +424,7 @@ public class CpuImpliedModeTest extends TestCase {
/* TAX - Transfer Accumulator to X Register - $aa */ /* TAX - Transfer Accumulator to X Register - $aa */
public void test_TAX() { public void test_TAX() throws MemoryAccessException {
cpu.setAccumulator(0x32); cpu.setAccumulator(0x32);
bus.loadProgram(0xaa); bus.loadProgram(0xaa);
cpu.step(); cpu.step();
@@ -432,7 +433,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
} }
public void test_TAX_SetsZeroFlagIfXIsZero() { public void test_TAX_SetsZeroFlagIfXIsZero() throws MemoryAccessException {
cpu.setAccumulator(0x00); cpu.setAccumulator(0x00);
bus.loadProgram(0xaa); bus.loadProgram(0xaa);
cpu.step(); cpu.step();
@@ -441,7 +442,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
} }
public void test_TAX_SetsNegativeFlagIfXIsNegative() { public void test_TAX_SetsNegativeFlagIfXIsNegative() throws MemoryAccessException {
cpu.setAccumulator(0xff); cpu.setAccumulator(0xff);
bus.loadProgram(0xaa); bus.loadProgram(0xaa);
cpu.step(); cpu.step();
@@ -452,7 +453,7 @@ public class CpuImpliedModeTest extends TestCase {
/* TAY - Transfer Accumulator to Y Register - $a8 */ /* TAY - Transfer Accumulator to Y Register - $a8 */
public void test_TAY() { public void test_TAY() throws MemoryAccessException {
cpu.setAccumulator(0x32); cpu.setAccumulator(0x32);
bus.loadProgram(0xa8); bus.loadProgram(0xa8);
cpu.step(); cpu.step();
@@ -461,7 +462,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
} }
public void test_TAY_SetsZeroFlagIfYIsZero() { public void test_TAY_SetsZeroFlagIfYIsZero() throws MemoryAccessException {
cpu.setAccumulator(0x00); cpu.setAccumulator(0x00);
bus.loadProgram(0xa8); bus.loadProgram(0xa8);
cpu.step(); cpu.step();
@@ -470,7 +471,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
} }
public void test_TAY_SetsNegativeFlagIfYIsNegative() { public void test_TAY_SetsNegativeFlagIfYIsNegative() throws MemoryAccessException {
cpu.setAccumulator(0xff); cpu.setAccumulator(0xff);
bus.loadProgram(0xa8); bus.loadProgram(0xa8);
cpu.step(); cpu.step();
@@ -481,7 +482,7 @@ public class CpuImpliedModeTest extends TestCase {
/* TSX - Transfer Stack Pointer to X Register - $ba */ /* TSX - Transfer Stack Pointer to X Register - $ba */
public void test_TSX() { public void test_TSX() throws MemoryAccessException {
cpu.setStackPointer(0x32); cpu.setStackPointer(0x32);
bus.loadProgram(0xba); bus.loadProgram(0xba);
cpu.step(); cpu.step();
@@ -490,7 +491,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
} }
public void test_TSX_SetsZeroFlagIfXIsZero() { public void test_TSX_SetsZeroFlagIfXIsZero() throws MemoryAccessException {
cpu.setStackPointer(0x00); cpu.setStackPointer(0x00);
bus.loadProgram(0xba); bus.loadProgram(0xba);
cpu.step(); cpu.step();
@@ -499,7 +500,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
} }
public void test_TSX_SetsNegativeFlagIfXIsNegative() { public void test_TSX_SetsNegativeFlagIfXIsNegative() throws MemoryAccessException {
cpu.setStackPointer(0xff); cpu.setStackPointer(0xff);
bus.loadProgram(0xba); bus.loadProgram(0xba);
cpu.step(); cpu.step();
@@ -510,7 +511,7 @@ public class CpuImpliedModeTest extends TestCase {
/* TXA - Transfer X Register to Accumulator - $8a */ /* TXA - Transfer X Register to Accumulator - $8a */
public void test_TXA() { public void test_TXA() throws MemoryAccessException {
cpu.setXRegister(0x32); cpu.setXRegister(0x32);
bus.loadProgram(0x8a); bus.loadProgram(0x8a);
cpu.step(); cpu.step();
@@ -519,7 +520,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
} }
public void test_TXA_SetsZeroFlagIfAccumulatorIsZero() { public void test_TXA_SetsZeroFlagIfAccumulatorIsZero() throws MemoryAccessException {
cpu.setXRegister(0x00); cpu.setXRegister(0x00);
bus.loadProgram(0x8a); bus.loadProgram(0x8a);
cpu.step(); cpu.step();
@@ -528,7 +529,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
} }
public void test_TXA_SetsNegativeFlagIfAccumulatorIsNegative() { public void test_TXA_SetsNegativeFlagIfAccumulatorIsNegative() throws MemoryAccessException {
cpu.setXRegister(0xff); cpu.setXRegister(0xff);
bus.loadProgram(0x8a); bus.loadProgram(0x8a);
cpu.step(); cpu.step();
@@ -539,7 +540,7 @@ public class CpuImpliedModeTest extends TestCase {
/* TXS - Transfer X Register to Stack Pointer - $9a */ /* TXS - Transfer X Register to Stack Pointer - $9a */
public void test_TXS() { public void test_TXS() throws MemoryAccessException {
cpu.setXRegister(0x32); cpu.setXRegister(0x32);
bus.loadProgram(0x9a); bus.loadProgram(0x9a);
cpu.step(); cpu.step();
@@ -548,7 +549,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
} }
public void test_TXS_DoesNotAffectProcessorStatus() { public void test_TXS_DoesNotAffectProcessorStatus() throws MemoryAccessException {
cpu.setXRegister(0x00); cpu.setXRegister(0x00);
bus.loadProgram(0x9a); bus.loadProgram(0x9a);
cpu.step(); cpu.step();
@@ -566,7 +567,7 @@ public class CpuImpliedModeTest extends TestCase {
/* TYA - Transfer Y Register to Accumulator - $98 */ /* TYA - Transfer Y Register to Accumulator - $98 */
public void test_TYA() { public void test_TYA() throws MemoryAccessException {
cpu.setYRegister(0x32); cpu.setYRegister(0x32);
bus.loadProgram(0x98); bus.loadProgram(0x98);
cpu.step(); cpu.step();
@@ -575,7 +576,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
} }
public void test_TYA_SetsZeroFlagIfAccumulatorIsZero() { public void test_TYA_SetsZeroFlagIfAccumulatorIsZero() throws MemoryAccessException {
cpu.setYRegister(0x00); cpu.setYRegister(0x00);
bus.loadProgram(0x98); bus.loadProgram(0x98);
cpu.step(); cpu.step();
@@ -584,7 +585,7 @@ public class CpuImpliedModeTest extends TestCase {
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
} }
public void test_TYA_SetsNegativeFlagIfAccumulatorIsNegative() { public void test_TYA_SetsNegativeFlagIfAccumulatorIsNegative() throws MemoryAccessException {
cpu.setYRegister(0xff); cpu.setYRegister(0xff);
bus.loadProgram(0x98); bus.loadProgram(0x98);
cpu.step(); cpu.step();
@@ -1,7 +1,8 @@
package com.loomcom.symon; package com.loomcom.symon;
import com.loomcom.symon.devices.Memory; import com.loomcom.symon.devices.Memory;
import com.loomcom.symon.exceptions.MemoryRangeException; import com.loomcom.symon.exceptions.MemoryAccessException;
import junit.framework.TestCase; import junit.framework.TestCase;
public class CpuIndirectModeTest extends TestCase { public class CpuIndirectModeTest extends TestCase {
@@ -40,7 +41,7 @@ public class CpuIndirectModeTest extends TestCase {
/* JMP - Jump - $6c */ /* JMP - Jump - $6c */
public void test_JMP() { public void test_JMP() throws MemoryAccessException {
bus.write(0x3400, 0x00); bus.write(0x3400, 0x00);
bus.write(0x3401, 0x54); bus.write(0x3401, 0x54);
bus.loadProgram(0x6c, 0x00, 0x34); bus.loadProgram(0x6c, 0x00, 0x34);
@@ -1,7 +1,8 @@
package com.loomcom.symon; package com.loomcom.symon;
import com.loomcom.symon.devices.Memory; import com.loomcom.symon.devices.Memory;
import com.loomcom.symon.exceptions.MemoryRangeException; import com.loomcom.symon.exceptions.MemoryAccessException;
import junit.framework.TestCase; import junit.framework.TestCase;
public class CpuRelativeModeTest extends TestCase { public class CpuRelativeModeTest extends TestCase {
@@ -47,7 +48,7 @@ public class CpuRelativeModeTest extends TestCase {
/* BPL - Branch if Positive - 0x10 */ /* BPL - Branch if Positive - 0x10 */
public void test_BPL() { public void test_BPL() throws MemoryAccessException {
// Positive Offset // Positive Offset
bus.loadProgram(0x10, 0x05); // BPL $05 ; *=$0202+$05 ($0207) bus.loadProgram(0x10, 0x05); // BPL $05 ; *=$0202+$05 ($0207)
cpu.setNegativeFlag(); cpu.setNegativeFlag();
@@ -76,7 +77,7 @@ public class CpuRelativeModeTest extends TestCase {
/* BMI - Branch if Minus - 0x30 */ /* BMI - Branch if Minus - 0x30 */
public void test_BMI() { public void test_BMI() throws MemoryAccessException {
// Positive Offset // Positive Offset
bus.loadProgram(0x30, 0x05); // BMI $05 ; *=$0202+$05 ($0207) bus.loadProgram(0x30, 0x05); // BMI $05 ; *=$0202+$05 ($0207)
cpu.setNegativeFlag(); cpu.setNegativeFlag();
@@ -105,7 +106,7 @@ public class CpuRelativeModeTest extends TestCase {
/* BVC - Branch if Overflow Clear - 0x50 */ /* BVC - Branch if Overflow Clear - 0x50 */
public void test_BVC() { public void test_BVC() throws MemoryAccessException {
// Positive Offset // Positive Offset
bus.loadProgram(0x50, 0x05); // BVC $05 ; *=$0202+$05 ($0207) bus.loadProgram(0x50, 0x05); // BVC $05 ; *=$0202+$05 ($0207)
cpu.setOverflowFlag(); cpu.setOverflowFlag();
@@ -134,7 +135,7 @@ public class CpuRelativeModeTest extends TestCase {
/* BVS - Branch if Overflow Set - 0x70 */ /* BVS - Branch if Overflow Set - 0x70 */
public void test_BVS() { public void test_BVS() throws MemoryAccessException {
// Positive Offset // Positive Offset
bus.loadProgram(0x70, 0x05); // BVS $05 ; *=$0202+$05 ($0207) bus.loadProgram(0x70, 0x05); // BVS $05 ; *=$0202+$05 ($0207)
cpu.setOverflowFlag(); cpu.setOverflowFlag();
@@ -163,7 +164,7 @@ public class CpuRelativeModeTest extends TestCase {
/* BCC - Branch if Carry Clear - 0x90 */ /* BCC - Branch if Carry Clear - 0x90 */
public void test_BCC() { public void test_BCC() throws MemoryAccessException {
// Positive Offset // Positive Offset
bus.loadProgram(0x90, 0x05); // BCC $05 ; *=$0202+$05 ($0207) bus.loadProgram(0x90, 0x05); // BCC $05 ; *=$0202+$05 ($0207)
cpu.setCarryFlag(); cpu.setCarryFlag();
@@ -192,7 +193,7 @@ public class CpuRelativeModeTest extends TestCase {
/* BCS - Branch if Carry Set - 0xb0 */ /* BCS - Branch if Carry Set - 0xb0 */
public void test_BCS() { public void test_BCS() throws MemoryAccessException {
// Positive Offset // Positive Offset
bus.loadProgram(0xb0, 0x05); // BCS $05 ; *=$0202+$05 ($0207) bus.loadProgram(0xb0, 0x05); // BCS $05 ; *=$0202+$05 ($0207)
cpu.setCarryFlag(); cpu.setCarryFlag();
@@ -221,7 +222,7 @@ public class CpuRelativeModeTest extends TestCase {
/* BNE - Branch if Not Equal to Zero - 0xd0 */ /* BNE - Branch if Not Equal to Zero - 0xd0 */
public void test_BNE() { public void test_BNE() throws MemoryAccessException {
// Positive Offset // Positive Offset
bus.loadProgram(0xd0, 0x05); // BNE $05 ; *=$0202+$05 ($0207) bus.loadProgram(0xd0, 0x05); // BNE $05 ; *=$0202+$05 ($0207)
cpu.setZeroFlag(); cpu.setZeroFlag();
@@ -250,7 +251,7 @@ public class CpuRelativeModeTest extends TestCase {
/* BEQ - Branch if Equal to Zero - 0xf0 */ /* BEQ - Branch if Equal to Zero - 0xf0 */
public void test_BEQ() { public void test_BEQ() throws MemoryAccessException {
// Positive Offset // Positive Offset
bus.loadProgram(0xf0, 0x05); // BEQ $05 ; *=$0202+$05 ($0207) bus.loadProgram(0xf0, 0x05); // BEQ $05 ; *=$0202+$05 ($0207)
cpu.setZeroFlag(); cpu.setZeroFlag();
+7 -9
View File
@@ -22,7 +22,7 @@ public class CpuTest extends TestCase {
return new TestSuite(CpuTest.class); return new TestSuite(CpuTest.class);
} }
public void setUp() throws MemoryRangeException { public void setUp() throws MemoryRangeException, MemoryAccessException {
this.cpu = new Cpu(); this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff); this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000); this.mem = new Memory(0x0000, 0x10000);
@@ -50,7 +50,7 @@ public class CpuTest extends TestCase {
assertFalse(cpu.getNegativeFlag()); assertFalse(cpu.getNegativeFlag());
} }
public void testStack() { public void testStack() throws MemoryAccessException {
cpu.stackPush(0x13); cpu.stackPush(0x13);
assertEquals(0x13, cpu.stackPop()); 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, cpu.getStackPointer());
assertEquals(0xff, bus.read(0x1ff)); assertEquals(0xff, bus.read(0x1ff));
@@ -112,7 +112,7 @@ public class CpuTest extends TestCase {
assertEquals(0x01, bus.read(0x1fa)); assertEquals(0x01, bus.read(0x1fa));
} }
public void testStackPushWrapsAroundToStackTop() { public void testStackPushWrapsAroundToStackTop() throws MemoryAccessException {
cpu.setStackPointer(0x01); cpu.setStackPointer(0x01);
cpu.stackPush(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(0x1ff, 0x06);
bus.write(0x1fe, 0x05); bus.write(0x1fe, 0x05);
bus.write(0x1fd, 0x04); bus.write(0x1fd, 0x04);
@@ -157,7 +157,7 @@ public class CpuTest extends TestCase {
assertEquals(0xff, cpu.getStackPointer()); assertEquals(0xff, cpu.getStackPointer());
} }
public void testStackPopWrapsAroundToStackBottom() { public void testStackPopWrapsAroundToStackBottom() throws MemoryAccessException {
bus.write(0x1ff, 0x0f); // top of stack bus.write(0x1ff, 0x0f); // top of stack
bus.write(0x100, 0xf0); // bottom of stack bus.write(0x100, 0xf0); // bottom of stack
bus.write(0x101, 0xf1); bus.write(0x101, 0xf1);
@@ -178,9 +178,7 @@ public class CpuTest extends TestCase {
assertEquals(0x02, cpu.getStackPointer()); assertEquals(0x02, cpu.getStackPointer());
} }
public void testStackPeekDoesNotAlterStackPointer() { public void testStackPeekDoesNotAlterStackPointer() throws MemoryAccessException {
int val = 0;
assertEquals(0xff, cpu.stackPeek()); assertEquals(0xff, cpu.stackPeek());
assertEquals(0xff, cpu.getStackPointer()); assertEquals(0xff, cpu.getStackPointer());
@@ -1,7 +1,8 @@
package com.loomcom.symon; package com.loomcom.symon;
import com.loomcom.symon.devices.Memory; import com.loomcom.symon.devices.Memory;
import com.loomcom.symon.exceptions.MemoryRangeException; import com.loomcom.symon.exceptions.MemoryAccessException;
import junit.framework.TestCase; import junit.framework.TestCase;
public class CpuZeroPageModeTest extends TestCase { public class CpuZeroPageModeTest extends TestCase {
@@ -63,7 +64,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* ORA - Logical Inclusive OR - $05 */ /* ORA - Logical Inclusive OR - $05 */
public void test_ORA() { public void test_ORA() throws MemoryAccessException {
// Set some initial values in zero page. // Set some initial values in zero page.
bus.write(0x0000, 0x00); bus.write(0x0000, 0x00);
bus.write(0x0002, 0x11); bus.write(0x0002, 0x11);
@@ -104,7 +105,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* ASL - Arithmetic Shift Left - $06 */ /* ASL - Arithmetic Shift Left - $06 */
public void test_ASL() { public void test_ASL() throws MemoryAccessException {
bus.write(0x0000, 0x00); bus.write(0x0000, 0x00);
bus.write(0x0001, 0x01); bus.write(0x0001, 0x01);
bus.write(0x0002, 0x02); bus.write(0x0002, 0x02);
@@ -150,7 +151,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* BIT - Bit Test - $24 */ /* BIT - Bit Test - $24 */
public void test_BIT() { public void test_BIT() throws MemoryAccessException {
bus.write(0x0000, 0xc0); bus.write(0x0000, 0xc0);
bus.loadProgram(0xa9, 0x01, // LDA #$01 bus.loadProgram(0xa9, 0x01, // LDA #$01
@@ -204,7 +205,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* AND - Logical AND - $25 */ /* AND - Logical AND - $25 */
public void test_AND() { public void test_AND() throws MemoryAccessException {
bus.write(0x0000, 0x00); bus.write(0x0000, 0x00);
bus.write(0x0001, 0x11); bus.write(0x0001, 0x11);
bus.write(0x0002, 0xff); bus.write(0x0002, 0xff);
@@ -253,7 +254,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* ROL - Rotate Shift Left - $26 */ /* ROL - Rotate Shift Left - $26 */
public void test_ROL() { public void test_ROL() throws MemoryAccessException {
bus.write(0x0000, 0x00); bus.write(0x0000, 0x00);
bus.write(0x0001, 0x01); bus.write(0x0001, 0x01);
@@ -333,7 +334,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* EOR - Exclusive OR - $45 */ /* EOR - Exclusive OR - $45 */
public void test_EOR() { public void test_EOR() throws MemoryAccessException {
bus.write(0x10, 0x00); bus.write(0x10, 0x00);
bus.write(0x11, 0xff); bus.write(0x11, 0xff);
bus.write(0x12, 0x33); bus.write(0x12, 0x33);
@@ -367,7 +368,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* LSR - Logical Shift Right - $46 */ /* LSR - Logical Shift Right - $46 */
public void test_LSR() { public void test_LSR() throws MemoryAccessException {
bus.write(0x0000, 0x00); bus.write(0x0000, 0x00);
bus.write(0x0001, 0x01); bus.write(0x0001, 0x01);
bus.write(0x0002, 0x02); bus.write(0x0002, 0x02);
@@ -423,7 +424,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* ADC - Add with Carry - $65 */ /* ADC - Add with Carry - $65 */
public void test_ADC() { public void test_ADC() throws MemoryAccessException {
bus.write(0x10, 0x01); bus.write(0x10, 0x01);
bus.write(0x11, 0xff); bus.write(0x11, 0xff);
@@ -507,7 +508,7 @@ public class CpuZeroPageModeTest extends TestCase {
assertTrue(cpu.getCarryFlag()); assertTrue(cpu.getCarryFlag());
} }
public void test_ADC_IncludesCarry() { public void test_ADC_IncludesCarry() throws MemoryAccessException {
bus.write(0x10, 0x01); bus.write(0x10, 0x01);
bus.loadProgram(0xa9, 0x00, // LDA #$00 bus.loadProgram(0xa9, 0x00, // LDA #$00
@@ -521,7 +522,7 @@ public class CpuZeroPageModeTest extends TestCase {
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
} }
public void test_ADC_DecimalMode() { public void test_ADC_DecimalMode() throws MemoryAccessException {
bus.write(0x10, 0x01); bus.write(0x10, 0x01);
bus.write(0x11, 0x99); bus.write(0x11, 0x99);
@@ -604,8 +605,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* ROR - Rotate Right - $66 */ /* ROR - Rotate Right - $66 */
public void test_ROR() { public void test_ROR() throws MemoryAccessException {
bus.write(0x10, 0x00); bus.write(0x10, 0x00);
bus.write(0x11, 0x10); bus.write(0x11, 0x10);
@@ -683,7 +683,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* STY - Store Y Register - $84 */ /* STY - Store Y Register - $84 */
public void test_STY() { public void test_STY() throws MemoryAccessException {
cpu.setYRegister(0x00); cpu.setYRegister(0x00);
bus.loadProgram(0x84, 0x10); bus.loadProgram(0x84, 0x10);
cpu.step(); cpu.step();
@@ -712,7 +712,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* STA - Store Accumulator - $85 */ /* STA - Store Accumulator - $85 */
public void test_STA() { public void test_STA() throws MemoryAccessException {
cpu.setAccumulator(0x00); cpu.setAccumulator(0x00);
bus.loadProgram(0x85, 0x10); bus.loadProgram(0x85, 0x10);
cpu.step(); cpu.step();
@@ -741,7 +741,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* STX - Store X Register - $86 */ /* STX - Store X Register - $86 */
public void test_STX() { public void test_STX() throws MemoryAccessException {
cpu.setXRegister(0x00); cpu.setXRegister(0x00);
bus.loadProgram(0x86, 0x10); bus.loadProgram(0x86, 0x10);
cpu.step(); cpu.step();
@@ -770,7 +770,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* LDY - Load Y Register - $a4 */ /* LDY - Load Y Register - $a4 */
public void test_LDY() { public void test_LDY() throws MemoryAccessException {
bus.write(0x10, 0x00); bus.write(0x10, 0x00);
bus.write(0x11, 0x0f); bus.write(0x11, 0x0f);
bus.write(0x12, 0x80); bus.write(0x12, 0x80);
@@ -797,7 +797,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* LDA - Load Accumulator - $a5 */ /* LDA - Load Accumulator - $a5 */
public void test_LDA() { public void test_LDA() throws MemoryAccessException {
bus.write(0x10, 0x00); bus.write(0x10, 0x00);
bus.write(0x11, 0x0f); bus.write(0x11, 0x0f);
bus.write(0x12, 0x80); bus.write(0x12, 0x80);
@@ -824,7 +824,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* LDX - Load X Register - $a6 */ /* LDX - Load X Register - $a6 */
public void test_LDX() { public void test_LDX() throws MemoryAccessException {
bus.write(0x10, 0x00); bus.write(0x10, 0x00);
bus.write(0x11, 0x0f); bus.write(0x11, 0x0f);
bus.write(0x12, 0x80); bus.write(0x12, 0x80);
@@ -851,7 +851,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* CPY - Compare Y Register - $c4 */ /* CPY - Compare Y Register - $c4 */
public void test_CPY() { public void test_CPY() throws MemoryAccessException {
bus.write(0x10, 0x00); bus.write(0x10, 0x00);
bus.write(0x11, 0x80); bus.write(0x11, 0x80);
bus.write(0x12, 0xff); bus.write(0x12, 0xff);
@@ -880,7 +880,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* CMP - Compare Accumulator - $c5 */ /* CMP - Compare Accumulator - $c5 */
public void test_CMP() { public void test_CMP() throws MemoryAccessException {
bus.write(0x10, 0x00); bus.write(0x10, 0x00);
bus.write(0x11, 0x80); bus.write(0x11, 0x80);
bus.write(0x12, 0xff); bus.write(0x12, 0xff);
@@ -909,7 +909,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* DEC - Decrement Memory Location - $c6 */ /* DEC - Decrement Memory Location - $c6 */
public void test_DEC() { public void test_DEC() throws MemoryAccessException {
bus.write(0x10, 0x00); bus.write(0x10, 0x00);
bus.write(0x11, 0x01); bus.write(0x11, 0x01);
bus.write(0x12, 0x80); bus.write(0x12, 0x80);
@@ -943,7 +943,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* CPX - Compare X Register - $e4 */ /* CPX - Compare X Register - $e4 */
public void test_CPX() { public void test_CPX() throws MemoryAccessException {
bus.write(0x10, 0x00); bus.write(0x10, 0x00);
bus.write(0x11, 0x80); bus.write(0x11, 0x80);
bus.write(0x12, 0xff); bus.write(0x12, 0xff);
@@ -972,7 +972,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* SBC - Subtract with Carry - $e5 */ /* SBC - Subtract with Carry - $e5 */
public void test_SBC() { public void test_SBC() throws MemoryAccessException {
bus.write(0x10, 0x01); bus.write(0x10, 0x01);
bus.loadProgram(0xa9, 0x00, // LDA #$00 bus.loadProgram(0xa9, 0x00, // LDA #$00
@@ -1025,7 +1025,7 @@ public class CpuZeroPageModeTest extends TestCase {
assertTrue(cpu.getCarryFlag()); assertTrue(cpu.getCarryFlag());
} }
public void test_SBC_IncludesNotOfCarry() { public void test_SBC_IncludesNotOfCarry() throws MemoryAccessException {
bus.write(0x10, 0x01); bus.write(0x10, 0x01);
// Subtrace with Carry Flag cleared // 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(0x10, 0x01);
bus.write(0x20, 0x11); bus.write(0x20, 0x11);
@@ -1167,7 +1167,7 @@ public class CpuZeroPageModeTest extends TestCase {
/* INC - Increment Memory Location - $e6 */ /* INC - Increment Memory Location - $e6 */
public void test_INC() { public void test_INC() throws MemoryAccessException {
bus.write(0x10, 0x00); bus.write(0x10, 0x00);
bus.write(0x11, 0x7f); bus.write(0x11, 0x7f);
bus.write(0x12, 0xff); bus.write(0x12, 0xff);
@@ -1,7 +1,8 @@
package com.loomcom.symon; package com.loomcom.symon;
import com.loomcom.symon.devices.Memory; import com.loomcom.symon.devices.Memory;
import com.loomcom.symon.exceptions.MemoryRangeException; import com.loomcom.symon.exceptions.MemoryAccessException;
import junit.framework.TestCase; import junit.framework.TestCase;
public class CpuZeroPageXModeTest extends TestCase { public class CpuZeroPageXModeTest extends TestCase {
@@ -57,7 +58,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* ORA - Logical Inclusive OR - $15 */ /* ORA - Logical Inclusive OR - $15 */
public void test_ORA() { public void test_ORA() throws MemoryAccessException {
// Set some initial values in zero page. // Set some initial values in zero page.
bus.write(0x30, 0x00); bus.write(0x30, 0x00);
bus.write(0x32, 0x11); bus.write(0x32, 0x11);
@@ -111,7 +112,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* ASL - Arithmetic Shift Left - $16 */ /* ASL - Arithmetic Shift Left - $16 */
public void test_ASL() { public void test_ASL() throws MemoryAccessException {
bus.write(0x30, 0x00); bus.write(0x30, 0x00);
bus.write(0x31, 0x01); bus.write(0x31, 0x01);
bus.write(0x32, 0x02); bus.write(0x32, 0x02);
@@ -169,7 +170,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* AND - Logical AND - $35 */ /* AND - Logical AND - $35 */
public void test_AND() { public void test_AND() throws MemoryAccessException {
bus.write(0x30, 0x00); bus.write(0x30, 0x00);
bus.write(0x31, 0x11); bus.write(0x31, 0x11);
bus.write(0x32, 0xff); bus.write(0x32, 0xff);
@@ -229,7 +230,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* ROL - Rotate Shift Left - $36 */ /* ROL - Rotate Shift Left - $36 */
public void test_ROL() { public void test_ROL() throws MemoryAccessException {
bus.write(0x70, 0x00); bus.write(0x70, 0x00);
bus.write(0x71, 0x01); bus.write(0x71, 0x01);
@@ -312,7 +313,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* EOR - Exclusive OR - $55 */ /* EOR - Exclusive OR - $55 */
public void test_EOR() { public void test_EOR() throws MemoryAccessException {
bus.write(0x40, 0x00); bus.write(0x40, 0x00);
bus.write(0x41, 0xff); bus.write(0x41, 0xff);
bus.write(0x42, 0x33); bus.write(0x42, 0x33);
@@ -348,7 +349,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* LSR - Logical Shift Right - $56 */ /* LSR - Logical Shift Right - $56 */
public void test_LSR() { public void test_LSR() throws MemoryAccessException {
bus.write(0x30, 0x00); bus.write(0x30, 0x00);
bus.write(0x31, 0x01); bus.write(0x31, 0x01);
bus.write(0x32, 0x02); bus.write(0x32, 0x02);
@@ -406,7 +407,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* ADC - Add with Carry - $75 */ /* ADC - Add with Carry - $75 */
public void test_ADC() { public void test_ADC() throws MemoryAccessException {
bus.write(0x40, 0x01); bus.write(0x40, 0x01);
bus.write(0x41, 0xff); bus.write(0x41, 0xff);
@@ -492,7 +493,7 @@ public class CpuZeroPageXModeTest extends TestCase {
assertTrue(cpu.getCarryFlag()); assertTrue(cpu.getCarryFlag());
} }
public void test_ADC_IncludesCarry() { public void test_ADC_IncludesCarry() throws MemoryAccessException {
bus.write(0x40, 0x01); bus.write(0x40, 0x01);
bus.loadProgram(0xa9, 0x00, // LDA #$00 bus.loadProgram(0xa9, 0x00, // LDA #$00
@@ -509,7 +510,7 @@ public class CpuZeroPageXModeTest extends TestCase {
assertFalse(cpu.getCarryFlag()); assertFalse(cpu.getCarryFlag());
} }
public void test_ADC_DecimalMode() { public void test_ADC_DecimalMode() throws MemoryAccessException {
bus.write(0x40, 0x01); bus.write(0x40, 0x01);
bus.write(0x41, 0x99); bus.write(0x41, 0x99);
@@ -595,7 +596,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* ROR - Rotate Right - $76 */ /* ROR - Rotate Right - $76 */
public void test_ROR() { public void test_ROR() throws MemoryAccessException {
bus.write(0x40, 0x00); bus.write(0x40, 0x00);
bus.write(0x41, 0x10); bus.write(0x41, 0x10);
@@ -676,7 +677,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* STY - Store Y Register - $94 */ /* STY - Store Y Register - $94 */
public void test_STY() { public void test_STY() throws MemoryAccessException {
cpu.setXRegister(0x30); cpu.setXRegister(0x30);
cpu.setYRegister(0x00); cpu.setYRegister(0x00);
@@ -707,7 +708,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* STA - Store Accumulator - $95 */ /* STA - Store Accumulator - $95 */
public void test_STA() { public void test_STA() throws MemoryAccessException {
cpu.setXRegister(0x30); cpu.setXRegister(0x30);
cpu.setAccumulator(0x00); cpu.setAccumulator(0x00);
@@ -738,7 +739,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* LDY - Load Y Register - $b4 */ /* LDY - Load Y Register - $b4 */
public void test_LDY() { public void test_LDY() throws MemoryAccessException {
bus.write(0x45, 0x00); bus.write(0x45, 0x00);
bus.write(0x46, 0x0f); bus.write(0x46, 0x0f);
bus.write(0x47, 0x80); bus.write(0x47, 0x80);
@@ -767,7 +768,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* LDA - Load Accumulator - $b5 */ /* LDA - Load Accumulator - $b5 */
public void test_LDA() { public void test_LDA() throws MemoryAccessException {
bus.write(0x42, 0x00); bus.write(0x42, 0x00);
bus.write(0x43, 0x0f); bus.write(0x43, 0x0f);
bus.write(0x44, 0x80); bus.write(0x44, 0x80);
@@ -796,7 +797,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* CMP - Compare Accumulator - $d5 */ /* CMP - Compare Accumulator - $d5 */
public void test_CMP() { public void test_CMP() throws MemoryAccessException {
bus.write(0x40, 0x00); bus.write(0x40, 0x00);
bus.write(0x41, 0x80); bus.write(0x41, 0x80);
bus.write(0x42, 0xff); bus.write(0x42, 0xff);
@@ -827,7 +828,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* DEC - Decrement Memory Location - $d6 */ /* DEC - Decrement Memory Location - $d6 */
public void test_DEC() { public void test_DEC() throws MemoryAccessException {
bus.write(0x40, 0x00); bus.write(0x40, 0x00);
bus.write(0x41, 0x01); bus.write(0x41, 0x01);
bus.write(0x42, 0x80); bus.write(0x42, 0x80);
@@ -863,7 +864,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* SBC - Subtract with Carry - $f5 */ /* SBC - Subtract with Carry - $f5 */
public void test_SBC() { public void test_SBC() throws MemoryAccessException {
bus.write(0x40, 0x01); bus.write(0x40, 0x01);
bus.loadProgram(0xa9, 0x00, // LDA #$00 bus.loadProgram(0xa9, 0x00, // LDA #$00
@@ -921,7 +922,7 @@ public class CpuZeroPageXModeTest extends TestCase {
assertTrue(cpu.getCarryFlag()); assertTrue(cpu.getCarryFlag());
} }
public void test_SBC_IncludesNotOfCarry() { public void test_SBC_IncludesNotOfCarry() throws MemoryAccessException {
bus.write(0x40, 0x01); bus.write(0x40, 0x01);
// Subtrace with Carry Flag cleared // 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(0x40, 0x01);
bus.write(0x50, 0x11); bus.write(0x50, 0x11);
@@ -1072,7 +1073,7 @@ public class CpuZeroPageXModeTest extends TestCase {
/* INC - Increment Memory Location - $f6 */ /* INC - Increment Memory Location - $f6 */
public void test_INC() { public void test_INC() throws MemoryAccessException {
bus.write(0x30, 0x00); bus.write(0x30, 0x00);
bus.write(0x31, 0x7f); bus.write(0x31, 0x7f);
bus.write(0x32, 0xff); bus.write(0x32, 0xff);
@@ -1,7 +1,8 @@
package com.loomcom.symon; package com.loomcom.symon;
import com.loomcom.symon.devices.Memory; import com.loomcom.symon.devices.Memory;
import com.loomcom.symon.exceptions.MemoryRangeException; import com.loomcom.symon.exceptions.MemoryAccessException;
import junit.framework.TestCase; import junit.framework.TestCase;
public class CpuZeroPageYModeTest extends TestCase { public class CpuZeroPageYModeTest extends TestCase {
@@ -41,7 +42,7 @@ public class CpuZeroPageYModeTest extends TestCase {
/* STX - Store X Register - $96 */ /* STX - Store X Register - $96 */
public void test_STX() { public void test_STX() throws MemoryAccessException {
cpu.setYRegister(0x30); cpu.setYRegister(0x30);
cpu.setXRegister(0x00); cpu.setXRegister(0x00);
bus.loadProgram(0x96, 0x10); // STX $10,Y bus.loadProgram(0x96, 0x10); // STX $10,Y
@@ -71,7 +72,7 @@ public class CpuZeroPageYModeTest extends TestCase {
/* LDX - Load X Register - $b6 */ /* LDX - Load X Register - $b6 */
public void test_LDX() { public void test_LDX() throws MemoryAccessException {
bus.write(0x40, 0x00); bus.write(0x40, 0x00);
bus.write(0x41, 0x0f); bus.write(0x41, 0x0f);
bus.write(0x42, 0x80); bus.write(0x42, 0x80);
@@ -2,9 +2,6 @@ package com.loomcom.symon;
import junit.framework.*; import junit.framework.*;
import java.util.HashMap;
import java.util.Map;
import com.loomcom.symon.exceptions.*; import com.loomcom.symon.exceptions.*;
/** /**