Browse Source

Large number of 6502 assembler tests written.

master
Bryan Miller 5 years ago
parent
commit
c722a4875a
1 changed files with 442 additions and 56 deletions
  1. +442
    -56
      test/unit.src.chip.MOS6502.assembler.spec.js

+ 442
- 56
test/unit.src.chip.MOS6502.assembler.spec.js View File

@@ -159,33 +159,208 @@ describe("Testing MOS6502 Assembler...", function(){
expect(res[0]).to.equal(0x71);
expect(res[1]).to.equal(0x44);
});


// -------------------------------------------------------------
it("AND Immediate");
it("AND Zero Page");
it("AND Zero Page, X");
it("AND Absolute");
it("AND Absolute, X");
it("AND Absolute, Y");
it("AND Indirect, X");
it("AND Indirect, Y");
it("AND Immediate", function(){
let res = asm.reset().compile("AND #$44").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0x29);
expect(res[1]).to.equal(0x44);
});

it("AND Zero Page", function(){
let res = asm.reset().compile("AND $44").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0x25);
expect(res[1]).to.equal(0x44);
});

it("AND Zero Page, X", function(){
let res = asm.reset().compile("AND $44,X").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0x35);
expect(res[1]).to.equal(0x44);
});

it("AND Absolute", function(){
let res = asm.reset().compile("AND $4400").result();
expect(res.length).to.equal(3);
expect(res[0]).to.equal(0x2D);
expect(res[1]).to.equal(0x00);
expect(res[2]).to.equal(0x44);
});

it("AND Absolute, X", function(){
let res = asm.reset().compile("AND $4400, X").result();
expect(res.length).to.equal(3);
expect(res[0]).to.equal(0x3D);
expect(res[1]).to.equal(0x00);
expect(res[2]).to.equal(0x44);
});

it("AND Absolute, Y", function(){
let res = asm.reset().compile("AND $4400, Y").result();
expect(res.length).to.equal(3);
expect(res[0]).to.equal(0x39);
expect(res[1]).to.equal(0x00);
expect(res[2]).to.equal(0x44);
});

it("AND Indirect, X", function(){
let res = asm.reset().compile("AND ($44, X)").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0x21);
expect(res[1]).to.equal(0x44);
});

it("AND Indirect, Y", function(){
let res = asm.reset().compile("AND ($44), Y").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0x31);
expect(res[1]).to.equal(0x44);
});


// -------------------------------------------------------------
it("ASL Accumulator");
it("ASL Zero Page");
it("ASL Zero Page, X");
it("ASL Absolute");
it("ASL Absolute, X");
it("ASL Accumulator", function(){
let res = asm.reset().compile("ASL A").result();
expect(res.length).to.equal(1);
expect(res[0]).to.equal(0x0A);
});

it("ASL Zero Page", function(){
let res = asm.reset().compile("ASL $44").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0x06);
expect(res[1]).to.equal(0x44);
});

it("ASL Zero Page, X", function(){
let res = asm.reset().compile("ASL $44, X").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0x16);
expect(res[1]).to.equal(0x44);
});

it("ASL Absolute", function(){
let res = asm.reset().compile("ASL $4400").result();
expect(res.length).to.equal(3);
expect(res[0]).to.equal(0x0E);
expect(res[1]).to.equal(0x00);
expect(res[2]).to.equal(0x44);
});

it("ASL Absolute, X", function(){
let res = asm.reset().compile("ASL $4400, X").result();
expect(res.length).to.equal(3);
expect(res[0]).to.equal(0x1E);
expect(res[1]).to.equal(0x00);
expect(res[2]).to.equal(0x44);
});

// -------------------------------------------------------------
it("BIT Zero Page");
it("BIT Absolute");
it("BIT Zero Page", function(){
let res = asm.reset().compile("BIT $44").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0x24);
expect(res[1]).to.equal(0x44);
});

it("BIT Absolute", function(){
let res = asm.reset().compile("BIT $4400").result();
expect(res.length).to.equal(3);
expect(res[0]).to.equal(0x2C);
expect(res[1]).to.equal(0x00);
expect(res[2]).to.equal(0x44);
});

// -------------------------------------------------------------
it("BPL");
it("BMI");
it("BVC");
it("BVS");
it("BCC");
it("BCS");
it("BNE");
it("BEQ");
it("BPL", function(){
let res = asm.reset().compile("NOP\nNOP\nBPL $0000").result();
expect(res.length).to.equal(4);
expect(res[0]).to.equal(0xEA);
expect(res[1]).to.equal(0xEA);
expect(res[2]).to.equal(0x10);
expect(res[3]).to.equal(0xFC);
});

it("BMI", function(){
let res = asm.reset().compile("BMI $0003\nNOP\nNOP").result();
expect(res.length).to.equal(4);
expect(res[0]).to.equal(0x30);
expect(res[1]).to.equal(0x02);
expect(res[2]).to.equal(0xEA);
expect(res[3]).to.equal(0xEA);
});

it("BVC", function(){
let res = asm.reset().compile("BVC $0003\nNOP\nNOP").result();
expect(res.length).to.equal(4);
expect(res[0]).to.equal(0x50);
expect(res[1]).to.equal(0x02);
expect(res[2]).to.equal(0xEA);
expect(res[3]).to.equal(0xEA);
});

it("BVS", function(){
let res = asm.reset().compile("NOP\nNOP\nBVS $0000").result();
expect(res.length).to.equal(4);
expect(res[0]).to.equal(0xEA);
expect(res[1]).to.equal(0xEA);
expect(res[2]).to.equal(0x70);
expect(res[3]).to.equal(0xFC);
});

it("BCC", function(){
let res = asm.reset().compile("BCC $0003\nNOP\nNOP").result();
expect(res.length).to.equal(4);
expect(res[0]).to.equal(0x90);
expect(res[1]).to.equal(0x02);
expect(res[2]).to.equal(0xEA);
expect(res[3]).to.equal(0xEA);
});

it("BCS", function(){
let res = asm.reset().compile("NOP\nNOP\nBCS $0000").result();
expect(res.length).to.equal(4);
expect(res[0]).to.equal(0xEA);
expect(res[1]).to.equal(0xEA);
expect(res[2]).to.equal(0xB0);
expect(res[3]).to.equal(0xFC);
});

it("BNE", function(){
let res = asm.reset().compile("BNE $0003\nNOP\nNOP").result();
expect(res.length).to.equal(4);
expect(res[0]).to.equal(0xD0);
expect(res[1]).to.equal(0x02);
expect(res[2]).to.equal(0xEA);
expect(res[3]).to.equal(0xEA);
});

it("BEQ", function(){
let res = asm.reset().compile("NOP\nNOP\nBEQ $0000").result();
expect(res.length).to.equal(4);
expect(res[0]).to.equal(0xEA);
expect(res[1]).to.equal(0xEA);
expect(res[2]).to.equal(0xF0);
expect(res[3]).to.equal(0xFC);
});

it("Branch Too Far Back", function(){
expect(()=>{
let asm2 = new Assembler(0x1000);
let res = asm2.compile("BNE $0000").result();
}).to.throw("Branch exceeds maximum number of bytes on program address 1001");
});

it("Branch Too Far Forward", function(){
expect(()=>{
let res = asm.reset().compile("BNE $00F0").result();
}).to.throw("Branch exceeds maximum number of bytes on program address 01");
});

// -------------------------------------------------------------
it ("BRK", function(){
asm.reset();
@@ -193,38 +368,203 @@ describe("Testing MOS6502 Assembler...", function(){
expect(res.length).to.equal(1);
expect(res[0]).to.equal(0x00);
});

// -------------------------------------------------------------
it("CMP Immediate");
it("CMP Zero Page");
it("CMP Zero Page, X");
it("CMP Absolute");
it("CMP Absolute, X");
it("CMP Absolute, Y");
it("CMP Indirect, X");
it("CMP Indirect, Y");
it("CMP Immediate", function(){
let res = asm.reset().compile("CMP #$44").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0xC9);
expect(res[1]).to.equal(0x44);
});

it("CMP Zero Page", function(){
let res = asm.reset().compile("CMP $44").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0xC5);
expect(res[1]).to.equal(0x44);
});

it("CMP Zero Page, X", function(){
let res = asm.reset().compile("CMP $44,X").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0xD5);
expect(res[1]).to.equal(0x44);
});

it("CMP Absolute", function(){
let res = asm.reset().compile("CMP $4400").result();
expect(res.length).to.equal(3);
expect(res[0]).to.equal(0xCD);
expect(res[1]).to.equal(0x00);
expect(res[2]).to.equal(0x44);
});

it("CMP Absolute, X", function(){
let res = asm.reset().compile("CMP $4400,X").result();
expect(res.length).to.equal(3);
expect(res[0]).to.equal(0xDD);
expect(res[1]).to.equal(0x00);
expect(res[2]).to.equal(0x44);
});

it("CMP Absolute, Y", function(){
let res = asm.reset().compile("CMP $4400, Y").result();
expect(res.length).to.equal(3);
expect(res[0]).to.equal(0xD9);
expect(res[1]).to.equal(0x00);
expect(res[2]).to.equal(0x44);
});

it("CMP Indirect, X", function(){
let res = asm.reset().compile("CMP ($44,X)").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0xC1);
expect(res[1]).to.equal(0x44);
});

it("CMP Indirect, Y", function(){
let res = asm.reset().compile("CMP ($44),Y").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0xD1);
expect(res[1]).to.equal(0x44);
});

// -------------------------------------------------------------
it("CPX Immediate");
it("CPX Zero Page");
it("CPX Absolute");
it("CPX Immediate", function(){
let res = asm.reset().compile("CPX #$44").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0xE0);
expect(res[1]).to.equal(0x44);
});

it("CPX Zero Page", function(){
let res = asm.reset().compile("CPX $44").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0xE4);
expect(res[1]).to.equal(0x44);
});

it("CPX Absolute", function(){
let res = asm.reset().compile("CPX $4400").result();
expect(res.length).to.equal(3);
expect(res[0]).to.equal(0xEC);
expect(res[1]).to.equal(0x00);
expect(res[2]).to.equal(0x44);
});

// -------------------------------------------------------------
it("CPY Immediate");
it("CPY Zero Page");
it("CPY Absolute");
it("CPY Immediate", function(){
let res = asm.reset().compile("CPY #$44").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0xC0);
expect(res[1]).to.equal(0x44);
});

it("CPY Zero Page", function(){
let res = asm.reset().compile("CPY $44").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0xC4);
expect(res[1]).to.equal(0x44);
});

it("CPY Absolute", function(){
let res = asm.reset().compile("CPY $4400").result();
expect(res.length).to.equal(3);
expect(res[0]).to.equal(0xCC);
expect(res[1]).to.equal(0x00);
expect(res[2]).to.equal(0x44);
});

// -------------------------------------------------------------
it("DEC Zero Page");
it("DEC Zero Page, X");
it("DEC Absolute");
it("DEC Absolute, X");
it("DEC Zero Page", function(){
let res = asm.reset().compile("DEC $44").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0xC6);
expect(res[1]).to.equal(0x44);
});

it("DEC Zero Page, X", function(){
let res = asm.reset().compile("DEC $44,X").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0xD6);
expect(res[1]).to.equal(0x44);
});

it("DEC Absolute", function(){
let res = asm.reset().compile("DEC $4400").result();
expect(res.length).to.equal(3);
expect(res[0]).to.equal(0xCE);
expect(res[1]).to.equal(0x00);
expect(res[2]).to.equal(0x44);
});

it("DEC Absolute, X", function(){
let res = asm.reset().compile("DEC $4400,X").result();
expect(res.length).to.equal(3);
expect(res[0]).to.equal(0xDE);
expect(res[1]).to.equal(0x00);
expect(res[2]).to.equal(0x44);
});

// -------------------------------------------------------------
it("EOR Immediate");
it("EOR Zero Page");
it("EOR Zero Page, X");
it("EOR Absolute");
it("EOR Absolute, X");
it("EOR Absolute, Y");
it("EOR Indirect, X");
it("EOR Indirect, Y");
it("EOR Immediate", function(){
let res = asm.reset().compile("EOR #$44").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0x49);
expect(res[1]).to.equal(0x44);
});

it("EOR Zero Page", function(){
let res = asm.reset().compile("EOR $44").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0x45);
expect(res[1]).to.equal(0x44);
});

it("EOR Zero Page, X", function(){
let res = asm.reset().compile("EOR $44,X").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0x55);
expect(res[1]).to.equal(0x44);
});

it("EOR Absolute", function(){
let res = asm.reset().compile("EOR $4400").result();
expect(res.length).to.equal(3);
expect(res[0]).to.equal(0x4D);
expect(res[1]).to.equal(0x00);
expect(res[2]).to.equal(0x44);
});

it("EOR Absolute, X", function(){
let res = asm.reset().compile("EOR $4400, X").result();
expect(res.length).to.equal(3);
expect(res[0]).to.equal(0x5D);
expect(res[1]).to.equal(0x00);
expect(res[2]).to.equal(0x44);
});

it("EOR Absolute, Y", function(){
let res = asm.reset().compile("EOR $4400,Y").result();
expect(res.length).to.equal(3);
expect(res[0]).to.equal(0x59);
expect(res[1]).to.equal(0x00);
expect(res[2]).to.equal(0x44);
});

it("EOR Indirect, X", function(){
let res = asm.reset().compile("EOR ($44,X)").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0x41);
expect(res[1]).to.equal(0x44);
});

it("EOR Indirect, Y", function(){
let res = asm.reset().compile("EOR ($44),Y").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0x51);
expect(res[1]).to.equal(0x44);
});

// -------------------------------------------------------------
it("CLC", function(){
@@ -277,15 +617,61 @@ describe("Testing MOS6502 Assembler...", function(){
});

// -------------------------------------------------------------
it("INC Zero Page");
it("INC Zero Page, X");
it("INC Absolute");
it("INC Absolute, X");
it("INC Zero Page", function(){
let res = asm.reset().compile("INC $44").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0xE6);
expect(res[1]).to.equal(0x44);
});

it("INC Zero Page, X", function(){
let res = asm.reset().compile("INC $44,X").result();
expect(res.length).to.equal(2);
expect(res[0]).to.equal(0xF6);
expect(res[1]).to.equal(0x44);
});

it("INC Absolute", function(){
let res = asm.reset().compile("INC $4400").result();
expect(res.length).to.equal(3);
expect(res[0]).to.equal(0xEE);
expect(res[1]).to.equal(0x00);
expect(res[2]).to.equal(0x44);
});

it("INC Absolute, X", function(){
let res = asm.reset().compile("INC $4400,X").result();
expect(res.length).to.equal(3);
expect(res[0]).to.equal(0xFE);
expect(res[1]).to.equal(0x00);
expect(res[2]).to.equal(0x44);
});

// -------------------------------------------------------------
it("JMP Absolute");
it("JMP Indirect");
it("JMP Absolute", function(){
let res = asm.reset().compile("JMP $2134").result();
expect(res.length).to.equal(3);
expect(res[0]).to.equal(0x4C);
expect(res[1]).to.equal(0x34);
expect(res[2]).to.equal(0x21);
});

it("JMP Indirect", function(){
let res = asm.reset().compile("JMP ($2134)").result();
expect(res.length).to.equal(3);
expect(res[0]).to.equal(0x6C);
expect(res[1]).to.equal(0x34);
expect(res[2]).to.equal(0x21);
});

// -------------------------------------------------------------
it("JRS Absolute");
it("JSR Absolute", function(){
let res = asm.reset().compile("JSR $5122").result();
expect(res.length).to.equal(3);
expect(res[0]).to.equal(0x20);
expect(res[1]).to.equal(0x22);
expect(res[2]).to.equal(0x51);
});
// -------------------------------------------------------------
it("LDA Immediate");
it("LDA Zero Page");

Loading…
Cancel
Save