Browse Source

Added dedicated StackPush() and StackPop() methods. Fixed BRK and JSR opcodes. Wrote RTS and RTI opcodes.

master
Bryan Miller 5 years ago
parent
commit
baed6e66e4
1 changed files with 45 additions and 21 deletions
  1. +45
    -21
      src/chip/MOS6502/cpu.js

+ 45
- 21
src/chip/MOS6502/cpu.js View File

@@ -207,19 +207,11 @@ function BRK(cpu){
case 0:
PCUp(cpu, 1);
case 1:
cpu.__mem.address = cpu.__SP;
cpu.__mem.byte = cpu.__PC & 0xFF;
cpu.__SP = ByteWrap(cpu.__SP, -1);
break;
StackPush(cpu, cpu.__PC >> 8); break;
case 2:
cpu.__mem.address += 1;
cpu.__mem.byte = cpu.__PC >> 8;
cpu.__SP = ByteWrap(cpu.__SP, -1);
break;
StackPush(cpu, cpu.__PC & 0xFF); break;
case 3:
cpu.__mem.address += 1;
cpu.__mem.byte = cpu.__PR;
cpu.__SP = ByteWrap(cpu.__SP, -1);
StackPush(cpu, cpu.__SP); break;
case 4:
cpu.__mem.address = 0xFFFE;
cpu.__PC = cpu.__mem.byte;
@@ -371,15 +363,9 @@ function JRS(cpu){
// Discard stack data (or... No Op)
break;
case 2:
cpu.__mem.address = cpu.__SP;
cpu.__mem.byte = cpu.__PC & 0xFF;
cpu.__SP = ByteWrap(cpu.__SP, -1);
break;
StackPush(cpu, cpu.__PC >> 8); break;
case 3:
cpu.__mem.address -= 1;
cpu.__mem.byte = cpu.__PC >> 8;
cpu.__SP = ByteWrap(cpu.__SP, -1);
break;
StackPush(cpu, cpu.__PC & 0xFF); break;
case 4:
cpu.__mem.address = cpu.__PC;
cpu.__PC = cpu.__opv | (cpu.__mem.byte << 8)
@@ -544,11 +530,37 @@ function ROR(cpu){
}

function RTI(cpu){

switch(cpu.__cycle){
case 0: break; // Discard PC
case 1: // Discard Stack Pointer Data
StackPop(cpu); break;
case 2:
cpu.__PR = StackPop(cpu); break;
case 3:
cpu.__PC = StackPop(cpu); break;
case 4:
cpu.__PC |= StackPop(cpu) << 8;
cpu.__op = -1;
break;
}
cpu.__cycle += 1;
}

function RTS(cpu){

switch(cpu.__cycle){
case 0: break; // Discard PC
case 1:
StackPop(cpu); break;
case 2:
cpu.__PC = StackPop(cpu); break;
case 3:
cpu.__PC |= StackPop(cpu) << 8; break;
case 4:
PCUp(cpu, 1);
cpu.__op = -1;
break;
}
cpu.__cycle += 1;
}

function SBC(cpu){
@@ -640,6 +652,18 @@ function ByteWrap(v, a){
return v;
}

function StackPush(cpu, v){
cpu.__mem.address = 0x0100 | cpu.__SP;
cpu.__mem.byte = v & 0xFF;
cpu.__SP = ByteWrap(cpu.__SP, -1);
}

function StackPop(cpu){
cpu.__mem.address = 0x0100 | cpu.__SP;
cpu.__SP = ByteWrap(cpu.__SP, 1);
return cpu.__mem.byte;
}

function PCHI(cpu, b){
cpu.__PC = (cpu.__PC & 0x00FF) | (b << 8);
}

Loading…
Cancel
Save