浏览代码

Added LDA opcode. Tweaking ALU()

master
Bryan Miller 5 年前
父节点
当前提交
145fb53143
共有 1 个文件被更改,包括 16 次插入8 次删除
  1. +16
    -8
      src/chip/MOS6502/cpu.js

+ 16
- 8
src/chip/MOS6502/cpu.js 查看文件

@@ -319,7 +319,13 @@ function JRS(cpu){
}

function LDA(cpu){

let pmode = [0xA9, 0xA5, 0xB5, null, 0xAD, 0xBD, 0xB9, 0xA1, 0xB1].indexOf(cpu.__op);
if (ProcessOp(cpu, pmode) === true){
cpu.__op = -1;
cpu.__AR = cpu.__opv;
cpu.Z = (cpu.__AR === 0);
cpu.N = (cpu.__AR >= 0x80);
}
}

function LDX(cpu){
@@ -519,20 +525,22 @@ function MemAddrFrom(cpu, addr){
}

function ALU(cpu, m, b){
let v = 0;
switch(m){
case 0: // Addition
cpu.__AR = (cpu.__AR + b) + ((cpu.C === 1) ? 1 : 0);
cpu.C = (v >= 256);
//cpu.C = (this.__AR >= 256);
break;
case 1: // Subtraction
cpu.__AR = (cpu.__AR - b) - ((cpu.C === 0) ? 1 : 0);
cpu.C = (v >= 0);
cpu.__AR = (cpu.__AR - b) - ((cpu.C === 0) ? 1 : 0);
//cpu.C = (this.__AR >= 0);
cpu.__AR += (cpu.__AR < 0) ? 256 : 0;
break;
}
cpu.__AR &= 0xFF;
cpu.V = (BITM.isOn(cpu.__AR, 7) === BITM.isOn(b, 7)) && (BITM.val(v, 7) !== BITM.val(cpu.__AR, 7));
}
cpu.V = (BITM.isOn(cpu.__AR, 7) === BITM.isOn(b, 7)) && (BITM.val(cpu.__AR, 7) !== BITM.val(cpu.__AR, 7));
cpu.C = (m === 0) ? (this.__AR >= 256) : (cpu.V === 0);
cpu.N = BITM.val(cpu.__AR, 7);
cpu.__AR &= 0xFF;
cpu.Z = (cpu.__AR === 0);
return cpu.__AR;
}

正在加载...
取消
保存