// SBC - Subtract with Carry private void SBC(StepParameters parms) { var a = _a; var b = Memory.Read(parms.address); var c = _c; _a = (byte) (a - b - (1 - c)); setZN(_a); // cast to int? if ((a - b - 1 - c) >= 0) { _c = 1; } else { _c = 0; } if (((a ^ b) &0x80) != 0 && ((a ^ _a) & 0x80) != 0) { _v = 1; } else { _v = 0; } }
// BRK - Force Interrupt private void BRK(StepParameters parms) { push16(_pc); PHP(parms); SEI(parms); _pc = Read16(0xFFFE); }
private void BIT(StepParameters parms) { byte value = Memory.Read(parms.address); _v = (byte) ((value >> 6) & 1); setZ((byte) (value & _a)); setN(value); }
// ADC - Add with Carry private void ADC(StepParameters parms) { var a = _a; var b = Memory.Read(parms.address); var c = _c; _a = (byte) (a + b + c); setZN(_a); // Carry? if (a + b + + c >= 0xFF) { _c = 1; } else { _c = 0; } if (((a ^ b) & 0x80) == 0 && ((a ^ _a) & 0x80) != 0) { _v = 1; } else { _v = 0; } }
// Branch if positive private void BPL(StepParameters parms) { if (_n == 0) { _pc = parms.address; addBranchCycles(parms); } }
// addBranchCycles adds a cycle for taking a branch and adds another cycle // if the branch jumps to a new page private void addBranchCycles(StepParameters parms) { _cycles++; if (!SamePage(parms.pc, parms.address)) { _cycles++; } }
// LSR - Logical Shift Right private void LSR(StepParameters parms) { // Accu if (parms.mode == 4) { _c = (byte) (_a & 1); _a >>= 1; setZN(_a); } else { byte value = Memory.Read(parms.address); _c = (byte) (value & 1); value >>= 1; Memory.Write(parms.address, value); setZN(value); } }
private void ROR(StepParameters parms) { // Accu if (parms.mode == 4) { var c = _c; _c = (byte) (_a & 1); _a = (byte) (_a >> 1 | c); setZN(_a); } else { var c = _c; byte value = Memory.Read(parms.address); _c = (byte) ((value >> 7) & 1); _a = (byte) (value << 1 | c); Memory.Write(parms.address, value); setZN(value); } }
// RTS - Return from sub routine private void RTS(StepParameters parms) { _pc = (ushort) (Pull16() + 1); }
// RTI - Return from Interrupt private void RTI(StepParameters parms) { SetFlags((byte) (Pull() & 0xEF | 0x20)); _pc = (ushort) Pull16(); }
// PLA - Pop Accumulator private void PLA(StepParameters parms) { _a = Pull(); setZN(_a); }
private void JMP(StepParameters parms) { _pc = parms.address; }
private void PHP(StepParameters parms) { push((byte) (GetFlags() | 0x10)); }
private void TXA(StepParameters parms) { _a = _x; setZN(_a); }
// SEI - Set Interrupt Disable private void SEI(StepParameters parms) { _i = 1; }
// LDY - Load Y Register private void LDY(StepParameters parms) { _y = Memory.Read(parms.address); setZN(_y); }
// TAX - Transfer Accumulator to X private void TAX(StepParameters parms) { _x = _a; setZN(_x); }
// LDX - Load X Register private void LDX(StepParameters parms) { _x = Memory.Read(parms.address); setZN(_x); }
// LDA - Load Accumulator private void LDA(StepParameters parms) { _a = Memory.Read(parms.address); setZN(_a); }
// JSR - Jump to sub routine private void JSR(StepParameters parms) { push16((ushort) (_pc - 1)); _pc = parms.address; }
private void INC(StepParameters parms) { byte value = (byte) (Memory.Read(parms.address) + 1); Memory.Write(parms.address, value); setZN(value); }
// INX - Increment X private void INX(StepParameters parms) { _x++; setZN(_x); }
private void SEC(StepParameters parms) { _c = 1; }
// PHA - Push Accumulator private void PHA(StepParameters parms) { push(_a); }
// STY - Store y private void STY(StepParameters parms) { Memory.Write(parms.address, _y); }
// INY - Increment Y private void INY(StepParameters parms) { _y++; setZN(_y); }
private void TAY(StepParameters parms) { _y = _a; setZN(_y); }
private void NOP(StepParameters parms) { }
// TXS - Transfer X to Stack Pointer private void TXS(StepParameters parms) { _sp = _x; }
// ORA - Logical Inclusive OR private void ORA(StepParameters parms) { _a = (byte) (_a | Memory.Read(parms.address)); setZN(_a); }