Exemple #1
0
        // 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;
            }
        }
Exemple #2
0
 // BRK - Force Interrupt
 private void BRK(StepParameters parms)
 {
     push16(_pc);
     PHP(parms);
     SEI(parms);
     _pc = Read16(0xFFFE);
 }
Exemple #3
0
 private void BIT(StepParameters parms)
 {
     byte value = Memory.Read(parms.address);
     _v = (byte) ((value >> 6) & 1);
     setZ((byte) (value & _a));
     setN(value);
 }
Exemple #4
0
        // 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;
            }
        }
Exemple #5
0
 // Branch if positive
 private void BPL(StepParameters parms)
 {
     if (_n == 0)
     {
         _pc = parms.address;
         addBranchCycles(parms);
     }
 }
Exemple #6
0
 // 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++;
     }
 }
Exemple #7
0
 // 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);
     }
 }
Exemple #8
0
 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);
     }
 }
Exemple #9
0
 // RTS - Return from sub routine
 private void RTS(StepParameters parms)
 {
     _pc = (ushort) (Pull16() + 1);
 }
Exemple #10
0
 // RTI - Return from Interrupt
 private void RTI(StepParameters parms)
 {
     SetFlags((byte) (Pull() & 0xEF | 0x20));
     _pc = (ushort) Pull16();
 }
Exemple #11
0
 // PLA - Pop Accumulator
 private void PLA(StepParameters parms)
 {
     _a = Pull();
     setZN(_a);
 }
Exemple #12
0
 private void JMP(StepParameters parms)
 {
     _pc = parms.address;
 }
Exemple #13
0
 private void PHP(StepParameters parms)
 {
     push((byte) (GetFlags() | 0x10));
 }
Exemple #14
0
 private void TXA(StepParameters parms)
 {
     _a = _x;
     setZN(_a);
 }
Exemple #15
0
 // SEI - Set Interrupt Disable
 private void SEI(StepParameters parms)
 {
     _i = 1;
 }
Exemple #16
0
 // LDY - Load Y Register
 private void LDY(StepParameters parms)
 {
     _y = Memory.Read(parms.address);
     setZN(_y);
 }
Exemple #17
0
 // TAX - Transfer Accumulator to X
 private void TAX(StepParameters parms)
 {
     _x = _a;
     setZN(_x);
 }
Exemple #18
0
 // LDX - Load X Register
 private void LDX(StepParameters parms)
 {
     _x = Memory.Read(parms.address);
     setZN(_x);
 }
Exemple #19
0
 // LDA - Load Accumulator
 private void LDA(StepParameters parms)
 {
     _a = Memory.Read(parms.address);
     setZN(_a);
 }
Exemple #20
0
 // JSR - Jump to sub routine
 private void JSR(StepParameters parms)
 {
     push16((ushort) (_pc - 1));
     _pc = parms.address;
 }
Exemple #21
0
 private void INC(StepParameters parms)
 {
     byte value = (byte) (Memory.Read(parms.address) + 1);
     Memory.Write(parms.address, value);
     setZN(value);
 }
Exemple #22
0
 // INX - Increment X
 private void INX(StepParameters parms)
 {
     _x++;
     setZN(_x);
 }
Exemple #23
0
 private void SEC(StepParameters parms)
 {
     _c = 1;
 }
Exemple #24
0
 // PHA - Push Accumulator
 private void PHA(StepParameters parms)
 {
     push(_a);
 }
Exemple #25
0
 // STY - Store y
 private void STY(StepParameters parms)
 {
     Memory.Write(parms.address, _y);
 }
Exemple #26
0
 // INY - Increment Y
 private void INY(StepParameters parms)
 {
     _y++;
     setZN(_y);
 }
Exemple #27
0
 private void TAY(StepParameters parms)
 {
     _y = _a;
     setZN(_y);
 }
Exemple #28
0
 private void NOP(StepParameters parms)
 {
 }
Exemple #29
0
 // TXS - Transfer X to Stack Pointer
 private void TXS(StepParameters parms)
 {
     _sp = _x;
 }
Exemple #30
0
 // ORA - Logical Inclusive OR
 private void ORA(StepParameters parms)
 {
     _a = (byte) (_a | Memory.Read(parms.address));
     setZN(_a);
 }