ソースを参照

ADC() method turned into the MATHC() method which can be used for both the ADC and SBC op codes. CPU.clk() updated accordingly.

master
Bryan Miller 5年前
コミット
b9802d895a
1個のファイルの変更12行の追加10行の削除
  1. +12
    -10
      src/chip/MOS6502/cpu.js

+ 12
- 10
src/chip/MOS6502/cpu.js ファイルの表示

@@ -5,21 +5,23 @@ const BIT = require('../../utils/bitman.js');
var Memory = require('../../common/memory.js');


function ADC(cpu){
function MATHC(cpu, m){ // To be used by both the ADC and SBC op codes.
// m == 0 - Add
// m == 1 - Subtract
switch(cpu.__step){
case 0:
cpu.__mem.address = cpu.__PC;
PCUp(cpu, 1);
cpu.__opv = cpu.__mem.byte;
if (cpu.__op == 0x69){ // Immediate
ALU(cpu, 0, cpu.__opv);
ALU(cpu, m, cpu.__opv);
cpu.__op = -1; break;
}
case 1:
switch (cpu.__op){
case 0x65: // Zero Page
cpu.__mem.address = cpu.__opv;
ALU(cpu, 0, cpu.__mem.byte);
ALU(cpu, m, cpu.__mem.byte);
cpu.__op = -1; break;
case 0x75: // Zero Page, X
cpu.__opv = (cpu.__opv + cpu.__XR) & 0xFF; break;
@@ -42,7 +44,7 @@ function ADC(cpu){
case 0x75: // Zero Page, X
case 0x6D: // Absolute
cpu.__mem.address = cpu.__opv;
ALU(cpu, 0, cpu.__mem.byte);
ALU(cpu, m, cpu.__mem.byte);
cpu.__op = -1; break;
case 0x7D: // Absolute, X
case 0x79: // Absolute, Y
@@ -51,7 +53,7 @@ function ADC(cpu){
cpu.__opv = (cpu.__opv & 0xFF00) | (l & 0xFF);
if (l < 255){
cpu.__mem.address = cpu.__opv;
ALU(cpu, 0, cpu.__mem.byte);
ALU(cpu, m, cpu.__mem.byte);
cpu.__op = -1;
}
break;
@@ -71,7 +73,7 @@ function ADC(cpu){
case 0x79: // Absolute, Y
let h = (cpu.__opv >> 8) + 1;
cpu.__mem.address = (cpu.__opv & 0xFF) | (h << 8);
ALU(cpu, 0, cpu.__mem.byte);
ALU(cpu, m, cpu.__mem.byte);
cpu.__op = -1; break;
case 0x61: // Indirect, X
cpu.__mem.address += 1;
@@ -82,7 +84,7 @@ function ADC(cpu){
cpu.__opv = (cpu.__opv & 0xFF00) | (l & 0xFF);
if (l <= 255){
cpu.__mem.address = cpu.__opv;
ALU(cpu, 0, cpu.__mem.byte);
ALU(cpu, m, cpu.__mem.byte);
cpu.__op = -1; break;
}
}
@@ -93,7 +95,7 @@ function ADC(cpu){
cpu.__opv = (cpu.__opv & 0x00FF) | (h << 8);
}
cpu.__mem.address = cpu.__opv;
ALU(cpu, 0, cpu.__mem.byte);
ALU(cpu, m, cpu.__mem.byte);
cpu.__op = -1; break;
}
cpu.__step += 1;
@@ -541,7 +543,7 @@ class CPU{
} else {
switch(this.__op){
case 0x69: case 0x65: case 0x75: case 0x6D: case 0x7D: case 0x79: case 0x61: case 0x71:
ADC(this); break;
MATHC(this, 0); break;
case 0x29: case 0x25: case 0x35: case 0x2D: case 0x3D: case 0x39: case 0x21: case 0x31:
AND(this); break;
case 0x0A: case 0x06: case 0x16: case 0x0E: case 0x1E:
@@ -597,7 +599,7 @@ class CPU{
case 0x60:
RTS(this); break;
case 0xE9: case 0xE5: case 0xF5: case 0xED: case 0xFD: case 0xF9: case 0xE1: case 0xF1:
SBC(this); break;
MATHC(this, 1); break;
case 0x85: case 0x95: case 0x8D: case 0x9D: case 0x99: case 0x81: case 0x91:
STA(this); break;
case 0x9A: case 0xBA: case 0x48: case 0x68: case 0x08: case 0x28:

読み込み中…
キャンセル
保存