| const expect = require('chai').expect; | const expect = require('chai').expect; | ||||
| const CPU = require('../src/MOS6502/cpu.js'); | |||||
| const MOS6502 = require('../src/MOS6502'); | |||||
| const Mem = require('../src/memory'); | const Mem = require('../src/memory'); | ||||
| describe("Testing MOS6502 CPU...", function(){ | describe("Testing MOS6502 CPU...", function(){ | ||||
| var cpu = new CPU(); | |||||
| var asm = new MOS6502.Assembler(); | |||||
| var cpu = new MOS6502.CPU(); | |||||
| var tick = cpu.clk(); | var tick = cpu.clk(); | ||||
| cpu.memory = new Mem.Memory.RAM(256); | cpu.memory = new Mem.Memory.RAM(256); | ||||
| cpu.memory.load(0xFFFC, [0x00, 0x00]); | cpu.memory.load(0xFFFC, [0x00, 0x00]); | ||||
| describe("Testing LDA...", function(){ | describe("Testing LDA...", function(){ | ||||
| it("LDA Immediate", function(){ | it("LDA Immediate", function(){ | ||||
| let prg = "LDA #$01\n"; | |||||
| prg += "LDA #$BB"; | |||||
| asm.reset().compile(prg); | |||||
| cpu.memory.clearPage(0); | cpu.memory.clearPage(0); | ||||
| cpu.memory.load(0, [0xA9, 0x01, 0xA9, 0xBB]); | |||||
| cpu.memory.load(0, asm.result()); | |||||
| cpu.reset = true; | cpu.reset = true; | ||||
| tick(); | tick(); | ||||
| tick(); | tick(); | ||||
| describe("Testing ADC...", function(){ | describe("Testing ADC...", function(){ | ||||
| it("ADC Immediate", 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.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; | cpu.reset = true; | ||||
| tick(); | tick(); | ||||
| // Getting through the 4 clear flag calls. Each should take 2 ticks. | // Getting through the 4 clear flag calls. Each should take 2 ticks. | ||||
| describe("Testing SBC...", function(){ | describe("Testing SBC...", function(){ | ||||
| it("SBC Immediate", 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.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; | cpu.reset = true; | ||||
| tick(); | tick(); | ||||
| // Getting through the 1 set and 3 clear flag calls. Each should take 2 ticks. | // Getting through the 1 set and 3 clear flag calls. Each should take 2 ticks. | ||||
| expect(cpu.A).to.equal(0); | expect(cpu.A).to.equal(0); | ||||
| tick(); | tick(); | ||||
| expect(cpu.A).to.equal(0xFF); | expect(cpu.A).to.equal(0xFF); | ||||
| tick(); tick(); // Get through second SEC call. | |||||
| tick(); | tick(); | ||||
| expect(cpu.A).to.equal(0xFF); | expect(cpu.A).to.equal(0xFF); | ||||
| tick(); | tick(); |