Fixed the BRK instruction. Added SBC and ADC in Binary Coded Decimal
mode. More unit tests.
This commit is contained in:
1 parent
b46c4e1bec
commit
06ed74e89c
3 files changed
+299
-45
No files matched your search
@@ -252,6 +252,83 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
assertFalse(cpu.getCarryFlag());
|
||||
}
|
||||
|
||||
public void test_ADC_DecimalMode() {
|
||||
bus.loadProgram(0xf8, // SED
|
||||
0xa9, 0x01, // LDA #$01
|
||||
0x69, 0x01); // ADC #$01
|
||||
cpu.step(3);
|
||||
assertEquals(0x02, cpu.getAccumulator());
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getCarryFlag());
|
||||
|
||||
cpu.reset();
|
||||
bus.loadProgram(0xf8, // SED
|
||||
0xa9, 0x49, // LDA #$49
|
||||
0x69, 0x01); // ADC #$01
|
||||
cpu.step(3);
|
||||
assertEquals(0x50, cpu.getAccumulator());
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getCarryFlag());
|
||||
|
||||
cpu.reset();
|
||||
bus.loadProgram(0xf8, // SED
|
||||
0xa9, 0x50, // LDA #$50
|
||||
0x69, 0x01); // ADC #$01
|
||||
cpu.step(3);
|
||||
assertEquals(0x51, cpu.getAccumulator());
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getCarryFlag());
|
||||
|
||||
cpu.reset();
|
||||
bus.loadProgram(0xf8, // SED
|
||||
0xa9, 0x99, // LDA #$99
|
||||
0x69, 0x01); // ADC #$01
|
||||
cpu.step(3);
|
||||
assertEquals(0x00, cpu.getAccumulator());
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
assertTrue(cpu.getZeroFlag());
|
||||
assertTrue(cpu.getCarryFlag());
|
||||
|
||||
cpu.reset();
|
||||
bus.loadProgram(0xf8, // SED
|
||||
0xa9, 0x00, // LDA #$00
|
||||
0x69, 0x99); // ADC #$01
|
||||
cpu.step(3);
|
||||
assertEquals(0x99, cpu.getAccumulator());
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertFalse(cpu.getCarryFlag());
|
||||
|
||||
cpu.reset();
|
||||
bus.loadProgram(0xf8, // SED
|
||||
0xa9, 0x49, // LDA #$49
|
||||
0x69, 0x99); // ADC #$99
|
||||
cpu.step(3);
|
||||
assertEquals(0x48, cpu.getAccumulator());
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertTrue(cpu.getCarryFlag());
|
||||
|
||||
cpu.reset();
|
||||
bus.loadProgram(0xf8, // SED
|
||||
0xa9, 0x50, // LDA #$59
|
||||
0x69, 0x99); // ADC #$99
|
||||
cpu.step(3);
|
||||
assertEquals(0x49, cpu.getAccumulator());
|
||||
assertFalse(cpu.getNegativeFlag());
|
||||
assertFalse(cpu.getOverflowFlag());
|
||||
assertFalse(cpu.getZeroFlag());
|
||||
assertTrue(cpu.getCarryFlag());
|
||||
}
|
||||
|
||||
/* LDY Immediate Mode Tests - 0xa0 */
|
||||
|
||||
@@ -616,11 +693,43 @@ public class CpuImmediateModeTest extends TestCase {
|
||||
}
|
||||
|
||||
public void test_SBC_IncludesNotOfCarry() {
|
||||
// Subtrace with Carry Flag cleared
|
||||
bus.loadProgram(0x18, // CLC
|
||||
0xa9, 0x05, // LDA #$00
|
||||
0xe9, 0x01); // SBC #$01
|
||||
|
||||
cpu.step(3);
|
||||
assertEquals(0x03, cpu.getAccumulator());
|
||||
|
||||
cpu.reset();
|
||||
|
||||
// Subtrace with Carry Flag cleared
|
||||
bus.loadProgram(0x18, // CLC
|
||||
0xa9, 0x00, // LDA #$00
|
||||
0xe9, 0x01); // SBC #$01
|
||||
|
||||
cpu.step(3);
|
||||
assertEquals(0xfe, cpu.getAccumulator());
|
||||
|
||||
cpu.reset();
|
||||
|
||||
// Subtract with Carry Flag set
|
||||
bus.loadProgram(0x38, // SEC
|
||||
0xa9, 0x05, // LDA #$00
|
||||
0xe9, 0x01); // SBC #$01
|
||||
cpu.step(3);
|
||||
assertEquals(0x04, cpu.getAccumulator());
|
||||
assertTrue(cpu.getCarryFlag());
|
||||
|
||||
cpu.reset();
|
||||
|
||||
// Subtract with Carry Flag set
|
||||
bus.loadProgram(0x38, // SEC
|
||||
0xa9, 0x00, // LDA #$00
|
||||
0xe9, 0x01); // SBC #$01
|
||||
cpu.step(3);
|
||||
assertEquals(0xff, cpu.getAccumulator());
|
||||
assertFalse(cpu.getCarryFlag());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -78,10 +78,16 @@ public class CpuImpliedModeTest extends TestCase {
|
||||
assertEquals(0x0200, cpu.getProgramCounter());
|
||||
assertEquals(0xff, cpu.getStackPointer());
|
||||
|
||||
// Set the IRQ vector
|
||||
bus.write(Cpu.IRQ_VECTOR_H, 0x12);
|
||||
bus.write(Cpu.IRQ_VECTOR_L, 0x34);
|
||||
|
||||
bus.loadProgram(0xea,
|
||||
0xea,
|
||||
0xea,
|
||||
0x00);
|
||||
0x00,
|
||||
0xea,
|
||||
0xea);
|
||||
|
||||
cpu.step(3); // Three NOP instructions
|
||||
|
||||
@@ -89,19 +95,20 @@ public class CpuImpliedModeTest extends TestCase {
|
||||
|
||||
cpu.step(); // Triggers the BRK
|
||||
|
||||
// Was at PC = 0x204, which should now be on the stack
|
||||
// Was at PC = 0x204. PC+2 should now be on the stack
|
||||
assertEquals(0x02, bus.read(0x1ff)); // PC high byte
|
||||
assertEquals(0x04, bus.read(0x1fe)); // PC low byte
|
||||
assertEquals(0x20|Cpu.P_CARRY|Cpu.P_OVERFLOW,
|
||||
bus.read(0x1fd)); // Processor Status
|
||||
|
||||
// Reset to original contents of PC
|
||||
assertEquals(0x0200, cpu.getProgramCounter());
|
||||
assertEquals(0xfc, cpu.getStackPointer());
|
||||
assertEquals(0x06, bus.read(0x1fe)); // PC low byte
|
||||
assertEquals(0x20|Cpu.P_CARRY|Cpu.P_OVERFLOW|Cpu.P_BREAK,
|
||||
bus.read(0x1fd)); // Processor Status, with B set
|
||||
|
||||
// Interrupt vector held 0x1234, so we should be there.
|
||||
assertEquals(0x1234, cpu.getProgramCounter());
|
||||
assertEquals(0xfc, cpu.getStackPointer());
|
||||
|
||||
// B and I flags should have been set on P
|
||||
assertEquals(0x20|Cpu.P_CARRY|Cpu.P_OVERFLOW|Cpu.P_BREAK|
|
||||
Cpu.P_IRQ_DISABLE,
|
||||
cpu.getProcessorStatus());
|
||||
assertEquals(0x20|Cpu.P_CARRY|Cpu.P_OVERFLOW,
|
||||
cpu.stackPeek());
|
||||
}
|
||||
|
||||
public void test_BRK_HonorsIrqDisableFlag() {
|
||||
|
||||
Reference in new issue
Block a user