Пример #1
0
        protected override void InternalExecute(CpuState cpuState, IMemory memory, byte arg, Action<byte> write, ref int cycles)
        {
            bool carry = cpuState.IsFlagSet(CpuState.Flags.Carry);
            cpuState.SetFlag(CpuState.Flags.Carry, arg & 0x80);
            arg <<= 1;
            if (carry)
            {
                arg |= 1;
            }
            write(arg);
            cpuState.SetNegativeFlag(arg);
            cpuState.SetZeroFlag(arg);

            switch (Variants[memory[cpuState.Pc]])
            {
                case AddressingMode.Accumulator:
                    cycles = 2;
                    break;
                case AddressingMode.ZeroPage:
                    cycles = 5;
                    break;
                case AddressingMode.ZeroPageXIndexed:
                    cycles = 6;
                    break;
                case AddressingMode.Absolute:
                    cycles = 6;
                    break;
                case AddressingMode.AbsoluteX:
                    cycles = 7;
                    break;
            }
        }
Пример #2
0
 protected override void InternalExecute(CpuState cpuState, IMemory memory, byte arg, Action<byte> write, ref int cycles)
 {
     var breakSet = cpuState.IsFlagSet(CpuState.Flags.Break);
     cpuState.StatusRegister = cpuState.PopStack(memory);
     cpuState.StatusRegister |= 1 << 5;
     cpuState.SetFlag(CpuState.Flags.Break, breakSet);
     cycles = 4;
 }
Пример #3
0
        public int Execute(CpuState cpuState, IMemory memory)
        {
            var breakSet = cpuState.IsFlagSet(CpuState.Flags.Break);
            cpuState.StatusRegister = cpuState.PopStack(memory);
            cpuState.SetFlag(CpuState.Flags.Break, breakSet);
            cpuState.StatusRegister |= 1 << 5;

            var low = cpuState.PopStack(memory);
            var high = cpuState.PopStack(memory);

            cpuState.Pc = (ushort)((high << 8) | low);

            return 6;
        }
Пример #4
0
        protected override void InternalExecute(CpuState cpuState, IMemory memory, byte arg, Action<byte> write, ref int cycles)
        {
            var sum = (ushort) (arg + cpuState.A);
            if (cpuState.IsFlagSet(CpuState.Flags.Carry))
            {
                ++sum;
            }
            var byteSum = (byte)(sum & 0xFF);

            cpuState.SetOverflow(cpuState.A, arg, byteSum);
            cpuState.A = byteSum;
            cpuState.SetZeroFlag(cpuState.A);
            cpuState.SetNegativeFlag(cpuState.A);
            cpuState.SetFlag(CpuState.Flags.Carry, sum & 0xFF00);
        }
Пример #5
0
        protected override void InternalExecute(CpuState cpuState, IMemory memory, byte arg, Action<byte> write, ref int cycles)
        {
            //     A - M - C -> A                   N Z C I D V
            //                                      + + + - - +

            int a = cpuState.A;
            arg ^= 0xFF;
            a += arg;
            if (cpuState.IsFlagSet(CpuState.Flags.Carry))
            {
                ++a;
            }
            var byteResult = (byte) (a & 0xFF);
            cpuState.SetOverflow(cpuState.A, arg, byteResult);
            cpuState.A = byteResult;

            cpuState.SetNegativeFlag(cpuState.A);
            cpuState.SetZeroFlag(cpuState.A);
            cpuState.SetFlag(CpuState.Flags.Carry, (byteResult & 0x80) == 0);
        }
Пример #6
0
 protected override bool ShouldBranch(CpuState cpuState, IMemory memory)
 {
     return cpuState.IsFlagSet(CpuState.Flags.Negative);
 }
Пример #7
0
 protected override bool ShouldBranch(CpuState cpuState, IMemory memory)
 {
     return !cpuState.IsFlagSet(CpuState.Flags.Zero);
 }