浏览代码

ALU() method modified to directly use and set the cpu.__AR value. ADC() Adjusted according to the new ALU() changes.

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

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

@@ -12,14 +12,14 @@ function ADC(cpu){
PCUp(cpu, 1);
cpu.__opv = cpu.__mem.byte;
if (cpu.__op == 0x69){ // Immediate
cpu.__AR = ALU(cpu, 0, cpu.__AR, cpu.__opv);
ALU(cpu, 0, cpu.__opv);
cpu.__op = -1; break;
}
case 1:
switch (cpu.__op){
case 0x65: // Zero Page
cpu.__mem.address = cpu.__opv;
cpu.__AR = ALU(cpu, 0, cpu.__AR, cpu.__mem.byte);
ALU(cpu, 0, cpu.__mem.byte);
cpu.__op = -1; break;
case 0x75: // Zero Page, X
cpu.__opv = (cpu.__opv + cpu.__XR) & 0xFF; break;
@@ -42,7 +42,7 @@ function ADC(cpu){
case 0x75: // Zero Page, X
case 0x6D: // Absolute
cpu.__mem.address = cpu.__opv;
cpu.__AR = ALU(cpu, 0, cpu.__AR, cpu.__mem.byte);
ALU(cpu, 0, cpu.__mem.byte);
cpu.__op = -1; break;
case 0x7D: // Absolute, X
case 0x79: // Absolute, Y
@@ -51,7 +51,7 @@ function ADC(cpu){
cpu.__opv = (cpu.__opv & 0xFF00) | (l & 0xFF);
if (l < 255){
cpu.__mem.address = cpu.__opv;
cpu.__AR = ALU(cpu, 0, cpu.__AR, cpu.__mem.byte);
ALU(cpu, 0, cpu.__mem.byte);
cpu.__op = -1;
}
break;
@@ -71,7 +71,7 @@ function ADC(cpu){
case 0x79: // Absolute, Y
let h = (cpu.__opv >> 8) + 1;
cpu.__mem.address = (cpu.__opv & 0xFF) | (h << 8);
cpu.__AR = ALU(cpu, 0, cpu.__AR, cpu.__mem.byte);
ALU(cpu, 0, cpu.__mem.byte);
cpu.__op = -1; break;
case 0x61: // Indirect, X
cpu.__mem.address += 1;
@@ -82,7 +82,7 @@ function ADC(cpu){
cpu.__opv = (cpu.__opv & 0xFF00) | (l & 0xFF);
if (l <= 255){
cpu.__mem.address = cpu.__opv;
cpu.__AR = ALU(cpu, 0, cpu.__AR, cpu.__mem.byte);
ALU(cpu, 0, cpu.__mem.byte);
cpu.__op = -1; break;
}
}
@@ -93,7 +93,7 @@ function ADC(cpu){
cpu.__opv = (cpu.__opv & 0x00FF) | (h << 8);
}
cpu.__mem.address = cpu.__opv;
cpu.__AR = ALU(cpu, 0, cpu.__AR, cpu.__mem.byte);
ALU(cpu, 0, cpu.__mem.byte);
cpu.__op = -1; break;
}
cpu.__step += 1;
@@ -402,23 +402,23 @@ function MemAddrFrom(cpu, addr){
return v;
}

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

// --------------------------------------------------------------------------------------------

正在加载...
取消
保存