Browse Source

Added more MOS6502/cpu tests. File dummy updated with unofficial tests.

master
Bryan Miller 5 years ago
parent
commit
440c54349f
2 changed files with 122 additions and 16 deletions
  1. +58
    -12
      dummy.js
  2. +64
    -4
      test/unit.src.chip.MOS6502.cpu.spec.js

+ 58
- 12
dummy.js View File

@@ -1,16 +1,62 @@
var mos6502 = require("./src/chip/MOS6502");
const mos6502 = require("./src/chip/MOS6502");
const Bank = require("./src/common/bank.js");

function toHex(v){
let r = v.toString(16);
return (r.length < 2) ? "0" + r : r;
}

function printBytes(b, acc){
var out = "";
for (let i=0; i < b.length; i++){
if (i % acc === 0 && out !== ""){
console.log(out);
out = ""
} else {
out += toHex(b[i]) + " ";
}
}
console.log(out);
}

var asm = new mos6502.Assembler();
var src = "DEFINE TOPNT $44\n";
src += "CLRMEM:\n";
src += "LDA #$00 ;Set up zero value\n";
src += "TAY ;Initialize index pointer\n";
src += "CLRM1:\n";
src += "STA (TOPNT),Y ;Clear memory location\n";
src += "INY ;Advance index pointer\n";
src += "DEX ;Decrement counter\n";
src += "BNE CLRM1 ;Not zero, continue checking\n";
src += "RTS ;Return\n"
var cpu = new mos6502.CPU();
cpu.memory = new Bank(65536);
cpu.memory.clear();
var tick = cpu.clk();

var src = "SEC\n";
src += "CLV\n";
src += "CLD\n";
src += "CLI\n";
src += "LDA #$00\n";
src += "SBC #$01\n";
src += "CLC\n";
src += "ADC #$01";


var res = asm.compile(src).result();
console.log(res);
printBytes(res, 16);

cpu.memory.load(0, res);
var page = [];
for (let i = 0; i < 256; i++){
cpu.memory.address = i;
page.push(cpu.memory.byte);
}
printBytes(page, 16);
cpu.reset();

//console.log(cpu.PC);
//return;
tick(); tick();
tick(); tick();
tick(); tick();
tick(); tick();
tick(); tick();
console.log("A: " + cpu.A);
tick(); tick();
console.log("A: " + cpu.A);
tick(); tick();
tick(); tick();
console.log("A: " + cpu.A);

+ 64
- 4
test/unit.src.chip.MOS6502.cpu.spec.js View File

@@ -55,6 +55,29 @@ describe("Testing MOS6502 CPU...", function(){
});
});

describe("Testing LDA...", function(){
it("LDA Immediate", function(){
cpu.memory.clearPage(0);
cpu.memory.load(0, [0xA9, 0x01, 0xA9, 0xBB]);
cpu.reset();
tick();
tick();
expect(cpu.A).to.equal(0x01);
tick();
expect(cpu.A).to.equal(0x01);
tick();
expect(cpu.A).to.equal(0xBB);
});

it("LDA Zero Page");
it("LDA Zero Page, X");
it("LDA Absolute");
it("LDA Absolute, X");
it("LDA Absolute, Y");
it("LDA Indirect, X");
it("LDA Indirect, Y");
});

describe("Testing ADC...", function(){
it("ADC Immediate", function(){
cpu.memory.clearPage(0);
@@ -62,12 +85,15 @@ describe("Testing MOS6502 CPU...", function(){
// CLV
// CLD
// CLI
// LDA $00
// ADC $01
// ADC $01
cpu.memory.load(0, [0x18, 0xB8, 0xD8, 0x58, 0x69, 0x01, 0x69, 0x01]);
cpu.memory.load(0, [0x18, 0xB8, 0xD8, 0x58, 0xA9, 0x00, 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();
// Next two ticks for the LDA call
tick(); tick();
// Now processing the adds.
expect(cpu.A).to.equal(0);
tick();
@@ -88,7 +114,7 @@ describe("Testing MOS6502 CPU...", function(){
it("ADC Indirect, X");
it("ADC Indirect, Y");

it ("ADC Test Zero flag", /*function(){
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.
@@ -105,9 +131,43 @@ describe("Testing MOS6502 CPU...", function(){
expect(cpu.A).to.equal(2);
}*/);
});
});


describe("Testing SBC...", function(){
it("SBC Immediate", function(){
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.reset();
// 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();
expect(cpu.A).to.equal(0xFF);
tick();
expect(cpu.A).to.equal(0xFE);
});

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");
});
});



Loading…
Cancel
Save