| @@ -1,10 +1,11 @@ | |||
| const expect = require('chai').expect; | |||
| const CPU = require('../src/MOS6502/cpu.js'); | |||
| const MOS6502 = require('../src/MOS6502'); | |||
| const Mem = require('../src/memory'); | |||
| describe("Testing MOS6502 CPU...", function(){ | |||
| var cpu = new CPU(); | |||
| var asm = new MOS6502.Assembler(); | |||
| var cpu = new MOS6502.CPU(); | |||
| var tick = cpu.clk(); | |||
| cpu.memory = new Mem.Memory.RAM(256); | |||
| cpu.memory.load(0xFFFC, [0x00, 0x00]); | |||
| @@ -62,8 +63,11 @@ describe("Testing MOS6502 CPU...", function(){ | |||
| describe("Testing LDA...", function(){ | |||
| it("LDA Immediate", function(){ | |||
| let prg = "LDA #$01\n"; | |||
| prg += "LDA #$BB"; | |||
| asm.reset().compile(prg); | |||
| cpu.memory.clearPage(0); | |||
| cpu.memory.load(0, [0xA9, 0x01, 0xA9, 0xBB]); | |||
| cpu.memory.load(0, asm.result()); | |||
| cpu.reset = true; | |||
| tick(); | |||
| tick(); | |||
| @@ -86,15 +90,16 @@ 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); | |||
| // CLC | |||
| // CLV | |||
| // CLD | |||
| // CLI | |||
| // LDA $00 | |||
| // ADC $01 | |||
| // ADC $01 | |||
| cpu.memory.load(0, [0x18, 0xB8, 0xD8, 0x58, 0xA9, 0x00, 0x69, 0x01, 0x69, 0x01]); | |||
| cpu.memory.load(0, asm.result()); | |||
| cpu.reset = true; | |||
| tick(); | |||
| // Getting through the 4 clear flag calls. Each should take 2 ticks. | |||
| @@ -141,15 +146,17 @@ describe("Testing MOS6502 CPU...", function(){ | |||
| 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); | |||
| // SEC | |||
| // CLV | |||
| // CLD | |||
| // CLI | |||
| // LDA $00 | |||
| // SBC $01 | |||
| // SBC $01 | |||
| cpu.memory.load(0, [0x38, 0xB8, 0xD8, 0x58, 0xA9, 0x00, 0xE9, 0x01, 0xE9, 0x01]); | |||
| 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. | |||
| @@ -162,6 +169,7 @@ describe("Testing MOS6502 CPU...", function(){ | |||
| 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(); | |||