// Compare
        private int CMP(IByteOperandStrategy operand)
        {
            var cmp16 = Accumulator - operand.Read(this);

            Flags = Flags
                    .Set(FlagIndex.Carry, ((cmp16 & 0x00FF) >= Accumulator && operand.Read(this) != 0))
                    .Set(FlagIndex.AuxCarry, AuxCarryPredicates.calc_subAC(Accumulator, operand.Read(this)))
                    .calc_SZP((byte)cmp16);

            return(operand == OpMem ? 7 : 4);
        }
        // INR Increment Register or Memory
        // If register C contains 99H, the instruction: INR C will cause register C to contain 9AH
        private int INR(IByteOperandStrategy op)
        {
            var in8  = op.Read(this);
            var out8 = (byte)(in8 + 1);

            Flags = Flags
                    .Set(FlagIndex.AuxCarry, AuxCarryPredicates.calc_AC(in8, 1))
                    .calc_SZP(out8);

            op.Write(this, out8);
            return(op == OpMem ? 10 : 5);
        }
        // ADD Register or Memory To Accumulator
        private int ADD(IByteOperandStrategy operand)
        {
            var in8   = operand.Read(this);
            var out16 = Accumulator + in8;

            Flags = Flags
                    .Set(FlagIndex.Carry, ((out16 & 0xFF00) != 0)).Set(FlagIndex.AuxCarry, AuxCarryPredicates.calc_AC(Accumulator, in8))
                    .calc_SZP((byte)out16);

            Accumulator = (byte)out16;
            return(operand == OpMem ? 7 : 4);
        }
        // OR
        private int ORA(IByteOperandStrategy operand)
        {
            var out8 = (byte)(Accumulator | operand.Read(this));

            Accumulator = out8;

            Flags = Flags
                    .calc_SZP(out8)
                    .Set(FlagIndex.Carry, false)
                    .Set(FlagIndex.AuxCarry, false);

            return(4);
        }
        // ANA Logical and Register or Memory With Accumulator
        private int ANA(IByteOperandStrategy operand)
        {
            var inAcc8 = Accumulator;
            var in8    = operand.Read(this);
            var out8   = (byte)(inAcc8 & in8);

            Accumulator = out8;

            Flags = Flags
                    .calc_SZP(out8)
                    .Set(FlagIndex.Carry, false)
                    .Set(FlagIndex.AuxCarry, (((inAcc8 | in8) >> 3) & 1) == 1);

            return(4);
        }
        //SBB Subtract Register or Memory From Accumulator With Borrow
        private int SBB(IByteOperandStrategy operand)
        {
            var in8   = operand.Read(this);
            var out16 = Accumulator - in8 - (Flags.IsSet(FlagIndex.Carry) ? 1 : 0);

            var acPred = Flags.IsSet(FlagIndex.Carry) ? AuxCarryPredicates.calc_subAC_borrow : AuxCarryPredicates.calc_subAC;

            Flags = Flags
                    .Set(FlagIndex.AuxCarry, acPred(Accumulator, in8))
                    .Set(FlagIndex.Carry, ((out16 & 0x00FF) >= Accumulator && in8 != 0 | Flags.IsSet(FlagIndex.Carry)))
                    .calc_SZP((byte)out16);

            Accumulator = (byte)out16;
            return(operand == OpMem ? 7 : 4);
        }
Esempio n. 7
0
 // MOV Move register to register
 private int MOV(IByteOperandStrategy rDest, IByteOperandStrategy rSrc)
 {
     rDest.Write(this, rSrc.Read(this));
     return(5);
 }