| @@ -0,0 +1,113 @@ | |||
| const expect = require('chai').expect; | |||
| const CPU = require('../src/chip/MOS6502/cpu.js'); | |||
| const Bank = require('../src/common/bank.js'); | |||
| describe("Testing MOS6502 CPU...", function(){ | |||
| var cpu = new CPU(); | |||
| var tick = cpu.clk(); | |||
| cpu.memory = new Bank(65536); | |||
| cpu.memory.load(0xFFFC, [0x00, 0x00]); | |||
| it("Resetting (IRQ Disabled flag must be on", function(){ | |||
| cpu.reset(); | |||
| expect(cpu.I).to.equal(1); | |||
| expect(cpu.PC).to.equal(0); // Test program counter set to the vector stored at 0xFFFC - 0xFFFD | |||
| }); | |||
| describe("Testing flag set/clear calls...", function(){ | |||
| it("CLC / SEC", function(){ | |||
| cpu.memory.clearPage(0); | |||
| cpu.memory.load(0, [0x18, 0x38]); | |||
| cpu.reset(); | |||
| tick(); tick(); // Two ticks to process opcode. | |||
| expect(cpu.C).to.equal(0); | |||
| tick(); tick(); | |||
| expect(cpu.C).to.equal(1); | |||
| }); | |||
| it("CLI / SEI", function(){ | |||
| cpu.memory.clearPage(0); | |||
| cpu.memory.load(0, [0x58, 0x78]); | |||
| cpu.reset(); | |||
| tick(); tick(); | |||
| expect(cpu.I).to.equal(0); | |||
| tick(); tick(); | |||
| expect(cpu.I).to.equal(1); | |||
| }); | |||
| it("CLD / SED", function(){ | |||
| cpu.memory.clearPage(0); | |||
| cpu.memory.load(0, [0xD8, 0xF8]); | |||
| cpu.reset(); | |||
| tick(); tick(); | |||
| expect(cpu.D).to.equal(0); | |||
| tick(); tick(); | |||
| expect(cpu.D).to.equal(1); | |||
| }); | |||
| it("CLV", function(){ | |||
| cpu.memory.clearPage(0); | |||
| cpu.memory.load(0, [0xB8]); | |||
| cpu.reset(); | |||
| tick(); tick(); | |||
| expect(cpu.V).to.equal(0); | |||
| }); | |||
| }); | |||
| describe("Testing ADC...", function(){ | |||
| it("ADC Immediate", function(){ | |||
| cpu.memory.clearPage(0); | |||
| // CLC | |||
| // CLV | |||
| // CLD | |||
| // CLI | |||
| // ADC $01 | |||
| // ADC $01 | |||
| cpu.memory.load(0, [0x18, 0xB8, 0xD8, 0x58, 0x69, 0x01, 0x69, 0x01]); | |||
| cpu.reset(); | |||
| // 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); | |||
| }); | |||
| 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); | |||
| }*/); | |||
| }); | |||
| }); | |||