Ejemplo n.º 1
0
        public void LSR(OpcodeContainer container, ushort address)
        {
            switch (container.AddressingMode)
            {
            case AddressingModes.Accumulator:
                CPU.IsCarry = (CPU.Registers.A & 1) == 1;
                CPU.Registers.A.Write((byte)(CPU.Registers.A >> 1));

                CPU.IsNegative = false;
                this.HandleZero(CPU.Registers.A);
                break;

            default:
                var value = CPU.ReadByteAt(address);
                CPU.IsCarry = (value & 1) == 1;
                byte shiftedValue = (byte)(value >> 1);

                // Spin cycle for the work above.
                CPU.CycleFinished();
                CPU.WriteByteAt(address, shiftedValue);

                CPU.IsNegative = false;
                this.HandleZero(shiftedValue);
                break;
            }
        }
Ejemplo n.º 2
0
        public static ushort GetAbsoluteXWrite(MOS6502 CPU)
        {
            intermediateAddress = CPU.ReadNextShort();
            var nextShort = (ushort)(intermediateAddress + CPU.Registers.X);

            CPU.IncrementPC(2);
            CPU.CycleFinished();

            return(nextShort);
        }
Ejemplo n.º 3
0
        public static ushort GetZeroPageY(MOS6502 CPU)
        {
            intermediateAddress = CPU.ReadNextByte();
            var address = (ushort)(intermediateAddress + CPU.Registers.Y);

            address &= 0xFF;

            CPU.CycleFinished();
            CPU.IncrementPC();

            return(address);
        }
Ejemplo n.º 4
0
        public static ushort GetIndirectYWrite(MOS6502 CPU)
        {
            intermediateAddress = CPU.ReadNextByte();
            CPU.IncrementPC();

            var baseAddress = intermediateAddress == 0xFF
                ? (ushort)(CPU.ReadByteAt(0xFF) | CPU.ReadByteAt(0x00) << 8)
                : CPU.ReadShortAt((ushort)intermediateAddress);

            CPU.CycleFinished();

            return((ushort)(baseAddress + CPU.Registers.Y));
        }
Ejemplo n.º 5
0
        public static ushort GetIndirectY(MOS6502 CPU)
        {
            intermediateAddress = CPU.ReadNextByte();
            CPU.IncrementPC();

            var baseAddress = intermediateAddress == 0xFF
                ? (ushort)(CPU.ReadByteAt(0xFF) | CPU.ReadByteAt(0x00) << 8)
                : CPU.ReadShortAt((ushort)intermediateAddress);

            var finalAddress = (ushort)(baseAddress + CPU.Registers.Y);

            if (AddressingMode.NotSamePage(baseAddress, CPU.Registers.Y))
            {
                CPU.CycleFinished();
            }

            return(finalAddress);
        }
Ejemplo n.º 6
0
        public static ushort GetAddressedOperand(MOS6502 CPU, OpcodeContainer container)
        {
            operandValue        = 0;
            intermediateAddress = 0;
            address             = 0;

            switch (container.AddressingMode)
            {
            case AddressingModes.Implied:
                address = 0x0000;
                CPU.CycleFinished();
                break;

            case AddressingModes.Accumulator:
                address = 0x0000;
                CPU.CycleFinished();
                break;

            case AddressingModes.Immediate:
                address = AddressingMode.GetImmediate(CPU);
                break;

            case AddressingModes.Absolute:
                address = AddressingMode.GetAbsolute(CPU);
                break;

            case AddressingModes.AbsoluteX:
                address = AddressingMode.GetAbsoluteX(CPU);
                break;

            case AddressingModes.AbsoluteXWrite:
                address = AddressingMode.GetAbsoluteXWrite(CPU);
                break;

            case AddressingModes.AbsoluteY:
                address = AddressingMode.GetAbsoluteY(CPU);
                break;

            case AddressingModes.Indirect:
                address = AddressingMode.GetIndirect(CPU);
                break;

            case AddressingModes.IndirectX:
                address = AddressingMode.GetIndirectX(CPU);
                break;

            case AddressingModes.IndirectY:
                address = AddressingMode.GetIndirectY(CPU);
                break;

            case AddressingModes.IndirectYWrite:
                address = AddressingMode.GetIndirectYWrite(CPU);
                break;

            case AddressingModes.ZeroPage:
                address = AddressingMode.GetZeroPage(CPU);
                break;

            case AddressingModes.ZeroPageX:
                address = AddressingMode.GetZeroPageX(CPU);
                break;

            case AddressingModes.ZeroPageY:
                address = AddressingMode.GetZeroPageY(CPU);
                break;

            case AddressingModes.Relative:
                address = AddressingMode.GetRelative(CPU);
                break;

            default:
                throw new InvalidOperationException();
            }

            if (MOS6502.IsDebug)
            {
                CPU.LastAccessedAddress = AddressingMode.GetAddressAsString(CPU, container);
            }

            return(address);
        }