|
|
@@ -89,100 +89,114 @@ describe("Testing MOS6502 CPU...", function(){ |
|
|
|
}); |
|
|
|
|
|
|
|
describe("Testing ADC...", function(){ |
|
|
|
it("ADC Immediate", function(){ |
|
|
|
let prg = "CLC\n"; |
|
|
|
prg += "CLV\n"; |
|
|
|
prg += "CLD\n"; |
|
|
|
prg += "CLI\n"; |
|
|
|
prg += "LDA #$00\n"; |
|
|
|
prg += "ADC #$01\n"; |
|
|
|
prg += "ADC #$01\n"; |
|
|
|
asm.reset().compile(prg); |
|
|
|
cpu.memory.clearPage(0); |
|
|
|
cpu.memory.load(0, asm.result()); |
|
|
|
cpu.reset = true; |
|
|
|
tick(); |
|
|
|
// Getting through the 4 clear flag calls. Each should take 2 ticks. |
|
|
|
tick(); tick(); tick(); tick(); tick(); tick(); tick(); tick(); |
|
|
|
// Next two ticks for the LDA call |
|
|
|
tick(); tick(); |
|
|
|
// Now processing the adds. |
|
|
|
expect(cpu.A).to.equal(0); |
|
|
|
tick(); |
|
|
|
expect(cpu.A).to.equal(0); |
|
|
|
tick(); |
|
|
|
expect(cpu.A).to.equal(1); |
|
|
|
tick(); |
|
|
|
expect(cpu.A).to.equal(1); |
|
|
|
tick(); |
|
|
|
expect(cpu.A).to.equal(2); |
|
|
|
}); |
|
|
|
describe("ADC Binary Mode...", function(){ |
|
|
|
it("ADC Immediate", function(){ |
|
|
|
let prg = "CLC\n"; |
|
|
|
prg += "CLV\n"; |
|
|
|
prg += "CLD\n"; |
|
|
|
prg += "CLI\n"; |
|
|
|
prg += "LDA #$00\n"; |
|
|
|
prg += "ADC #$01\n"; |
|
|
|
prg += "ADC #$01\n"; |
|
|
|
asm.reset().compile(prg); |
|
|
|
cpu.memory.clearPage(0); |
|
|
|
cpu.memory.load(0, asm.result()); |
|
|
|
cpu.reset = true; |
|
|
|
tick(); // To reset; |
|
|
|
while (cpu.PC !== 10){ |
|
|
|
switch(cpu.PC){ |
|
|
|
case 6: |
|
|
|
expect(cpu.A).to.equal(0); break; |
|
|
|
case 8: |
|
|
|
expect(cpu.A).to.equal(1); break; |
|
|
|
case 10: |
|
|
|
expect(cpu.A).to.equal(2); break; |
|
|
|
} |
|
|
|
tick(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
it("ADC Zero Page"); |
|
|
|
it("ADC Zero Page, X"); |
|
|
|
it("ADC Absolute"); |
|
|
|
it("ADC Absolute, X"); |
|
|
|
it("ADC Absolute, Y"); |
|
|
|
it("ADC Indirect, X"); |
|
|
|
it("ADC Indirect, Y"); |
|
|
|
it("ADC Zero Page"); |
|
|
|
it("ADC Zero Page, X"); |
|
|
|
it("ADC Absolute"); |
|
|
|
it("ADC Absolute, X"); |
|
|
|
it("ADC Absolute, Y"); |
|
|
|
it("ADC Indirect, X"); |
|
|
|
it("ADC Indirect, Y"); |
|
|
|
}); |
|
|
|
|
|
|
|
it ("ADC Test Zero flag"/*, function(){ |
|
|
|
cpu.memory.clearPage(0); |
|
|
|
cpu.memory.load(0, [0x18, 0xB8, 0xD8, 0x58, 0x69, 0xFF, 0x69, 0x01]); |
|
|
|
// Getting through the 4 clear flag calls. Each should take 2 ticks. |
|
|
|
tick(); tick(); tick(); tick(); tick(); tick(); tick(); tick(); |
|
|
|
// Now processing the adds. |
|
|
|
expect(cpu.A).to.equal(0); |
|
|
|
tick(); |
|
|
|
expect(cpu.A).to.equal(0); |
|
|
|
tick(); |
|
|
|
expect(cpu.A).to.equal(1); |
|
|
|
tick(); |
|
|
|
expect(cpu.A).to.equal(1); |
|
|
|
tick(); |
|
|
|
expect(cpu.A).to.equal(2); |
|
|
|
}*/); |
|
|
|
describe("ADC Decimal (BCD) Mode...", function(){ |
|
|
|
it("ADC Immediate"); |
|
|
|
it("ADC Zero Page"); |
|
|
|
it("ADC Zero Page, X"); |
|
|
|
it("ADC Absolute"); |
|
|
|
it("ADC Absolute, X"); |
|
|
|
it("ADC Absolute, Y"); |
|
|
|
it("ADC Indirect, X"); |
|
|
|
it("ADC Indirect, Y"); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
describe("Testing SBC...", function(){ |
|
|
|
it("SBC Immediate", function(){ |
|
|
|
let prg = "SEC\n"; |
|
|
|
prg += "CLV\n"; |
|
|
|
prg += "CLD\n"; |
|
|
|
prg += "CLI\n"; |
|
|
|
prg += "LDA #$00\n"; |
|
|
|
prg += "SBC #$01\n"; |
|
|
|
prg += "SEC\n"; |
|
|
|
prg += "SBC #$01"; |
|
|
|
asm.reset().compile(prg); |
|
|
|
cpu.memory.clearPage(0); |
|
|
|
cpu.memory.load(0, asm.result()); |
|
|
|
cpu.reset = true; |
|
|
|
tick(); |
|
|
|
// Getting through the 1 set and 3 clear flag calls. Each should take 2 ticks. |
|
|
|
tick(); tick(); tick(); tick(); tick(); tick(); tick(); tick(); |
|
|
|
// Next two ticks for the LDA call |
|
|
|
tick(); tick(); |
|
|
|
// Now processing the subtractions. |
|
|
|
expect(cpu.A).to.equal(0); |
|
|
|
tick(); |
|
|
|
expect(cpu.A).to.equal(0); |
|
|
|
tick(); |
|
|
|
expect(cpu.A).to.equal(0xFF); |
|
|
|
tick(); tick(); // Get through second SEC call. |
|
|
|
tick(); |
|
|
|
expect(cpu.A).to.equal(0xFF); |
|
|
|
tick(); |
|
|
|
expect(cpu.A).to.equal(0xFE); |
|
|
|
describe("SBC Binary Mode...", function(){ |
|
|
|
it("SBC Immediate", function(){ |
|
|
|
let prg = "SEC\n"; |
|
|
|
prg += "CLV\n"; |
|
|
|
prg += "CLD\n"; |
|
|
|
prg += "CLI\n"; |
|
|
|
prg += "LDA #$01\n"; |
|
|
|
prg += "SBC #$01\n"; |
|
|
|
prg += "SBC #$01"; |
|
|
|
asm.reset().compile(prg); |
|
|
|
cpu.memory.clearPage(0); |
|
|
|
cpu.memory.load(0, asm.result()); |
|
|
|
cpu.reset = true; |
|
|
|
tick(); // To reset; |
|
|
|
while(cpu.PC !== 11){ |
|
|
|
// NOTE TO SELF: Depending on the OP code, these tests could be |
|
|
|
// checked multiple times, as the cpu may sit at a program cntr |
|
|
|
// for a couple cycles depending on the OP. |
|
|
|
switch(cpu.PC){ |
|
|
|
case 1: |
|
|
|
expect(cpu.C).to.be.equal(1); break; |
|
|
|
case 6: |
|
|
|
expect(cpu.A).to.be.equal(0x01); break; |
|
|
|
case 8: |
|
|
|
expect(cpu.A).to.be.equal(0x00); |
|
|
|
expect(cpu.C).to.be.equal(1); |
|
|
|
expect(cpu.Z).to.be.equal(1); |
|
|
|
expect(cpu.N).to.be.equal(0); |
|
|
|
break; |
|
|
|
case 9: |
|
|
|
expect(cpu.A).to.be.equal(0xFF); |
|
|
|
expect(cpu.C).to.be.equal(0); |
|
|
|
expect(cpu.Z).to.be.equal(0); |
|
|
|
expect(cpu.N).to.be.equal(1); |
|
|
|
break; |
|
|
|
} |
|
|
|
tick(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
it("SBC Zero Page"); |
|
|
|
it("SBC Zero Page, X"); |
|
|
|
it("SBC Absolute"); |
|
|
|
it("SBC Absolute, X"); |
|
|
|
it("SBC Absolute, Y"); |
|
|
|
it("SBC Indirect, X"); |
|
|
|
it("SBC Indirect, Y"); |
|
|
|
}); |
|
|
|
|
|
|
|
it("SBC Zero Page"); |
|
|
|
it("SBC Zero Page, X"); |
|
|
|
it("SBC Absolute"); |
|
|
|
it("SBC Absolute, X"); |
|
|
|
it("SBC Absolute, Y"); |
|
|
|
it("SBC Indirect, X"); |
|
|
|
it("SBC Indirect, Y"); |
|
|
|
describe("SBC Decimal (BCD) Mode...", function(){ |
|
|
|
it("SBC Immediate"); |
|
|
|
it("SBC Zero Page"); |
|
|
|
it("SBC Zero Page, X"); |
|
|
|
it("SBC Absolute"); |
|
|
|
it("SBC Absolute, X"); |
|
|
|
it("SBC Absolute, Y"); |
|
|
|
it("SBC Indirect, X"); |
|
|
|
it("SBC Indirect, Y"); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|