示例#1
0
        public InstructionLogicResult Execute(CPU cpu, AddrModeCalcResult addrModeCalcResult)
        {
            // Assume implied mode
            cpu.ProcessorStatus.InterruptDisable = true;

            return(InstructionLogicResult.WithNoExtraCycles());
        }
示例#2
0
        public InstructionLogicResult Execute(CPU cpu, AddrModeCalcResult addrModeCalcResult)
        {
            // Assume implied mode
            cpu.ProcessorStatus.Decimal = false;

            return(InstructionLogicResult.WithNoExtraCycles());
        }
示例#3
0
        public InstructionLogicResult Execute(CPU cpu, AddrModeCalcResult addrModeCalcResult)
        {
            cpu.A = cpu.Y;
            BinaryArithmeticHelpers.SetFlagsAfterRegisterLoadIncDec(cpu.A, cpu.ProcessorStatus);

            return(InstructionLogicResult.WithNoExtraCycles());
        }
示例#4
0
 public InstructionLogicResult ExecuteWithStack(CPU cpu, Memory mem, AddrModeCalcResult addrModeCalcResult)
 {
     cpu.A = cpu.PopByteFromStack(mem);
     BinaryArithmeticHelpers.SetFlagsAfterRegisterLoadIncDec(cpu.A, cpu.ProcessorStatus);
     
     return InstructionLogicResult.WithNoExtraCycles();
 } 
示例#5
0
        public InstructionLogicResult Execute(CPU cpu, AddrModeCalcResult addrModeCalcResult)
        {
            // Assume Accumulator mode
            cpu.A = BinaryArithmeticHelpers.PerformRORAndSetStatusRegisters(cpu.A, cpu.ProcessorStatus);

            return(InstructionLogicResult.WithNoExtraCycles());
        }
示例#6
0
        public InstructionLogicResult Execute(CPU cpu, AddrModeCalcResult addrModeCalcResult)
        {
            // Assume implied mode
            cpu.X++;
            BinaryArithmeticHelpers.SetFlagsAfterRegisterLoadIncDec(cpu.X, cpu.ProcessorStatus);

            return InstructionLogicResult.WithNoExtraCycles();
        }
示例#7
0
        public InstructionLogicResult ExecuteWithByte(CPU cpu, Memory mem, byte value, AddrModeCalcResult addrModeCalcResult)
        {
            value--;
            cpu.StoreByte(value, mem, addrModeCalcResult.InsAddress.Value);
            BinaryArithmeticHelpers.SetFlagsAfterRegisterLoadIncDec(value, cpu.ProcessorStatus);

            return(InstructionLogicResult.WithNoExtraCycles());
        }
示例#8
0
        public InstructionLogicResult ExecuteWithWord(CPU cpu, Memory mem, ushort address, AddrModeCalcResult addrModeCalcResult)
        {
            var tempValue = cpu.FetchByte(mem, address);

            tempValue = BinaryArithmeticHelpers.PerformRORAndSetStatusRegisters(tempValue, cpu.ProcessorStatus);
            cpu.StoreByte(tempValue, mem, address);

            return(InstructionLogicResult.WithNoExtraCycles());
        }
示例#9
0
        public InstructionLogicResult ExecuteWithStack(CPU cpu, Memory mem, AddrModeCalcResult addrModeCalcResult)
        {
            // Set PC back to the returning address from stack.
            // As the address that was pushed on stack by JSR was the last byte of the JSR instruction,
            // we add one byte to the address we read from the stack (to get to next instruction)
            cpu.PC = (ushort)(cpu.PopWordFromStack(mem) + 1);

            return(InstructionLogicResult.WithNoExtraCycles());
        }
示例#10
0
        public InstructionLogicResult ExecuteWithStack(CPU cpu, Memory mem, AddrModeCalcResult addrModeCalcResult)
        {
            cpu.ProcessorStatus.Value  = cpu.PopByteFromStack(mem);
            cpu.ProcessorStatus.Break  = false;
            cpu.ProcessorStatus.Unused = false;
            cpu.PC = cpu.PopWordFromStack(mem);

            return(InstructionLogicResult.WithNoExtraCycles());
        }
示例#11
0
        public InstructionLogicResult ExecuteWithWord(CPU cpu, Memory mem, ushort address, AddrModeCalcResult addrModeCalcResult)
        {
            // The JSR instruction pushes the address of the last byte of the instruction.
            // As PC now points to the next instruction, we push PC minus one to the stack.
            cpu.PushWordToStack((ushort)(cpu.PC - 1), mem);
            // Set PC to address we will jump to
            cpu.PC = address;

            return(InstructionLogicResult.WithNoExtraCycles());
        }
示例#12
0
        public InstructionLogicResult ExecuteWithByte(CPU cpu, Memory mem, byte value, AddrModeCalcResult addrModeCalcResult)
        {
            BinaryArithmeticHelpers.SetFlagsAfterCompare(cpu.A, value, cpu.ProcessorStatus);

            return(InstructionLogicResult.WithExtraCycles(
                       InstructionExtraCyclesCalculator.CalculateExtraCycles(
                           addrModeCalcResult.OpCode.AddressingMode,
                           addrModeCalcResult.AddressCalculationCrossedPageBoundary)
                       ));
        }
示例#13
0
        public InstructionLogicResult ExecuteWithStack(CPU cpu, Memory mem, AddrModeCalcResult addrModeCalcResult)
        {
            // Set the Break flag on the copy of the ProcessorStatus that will be stored in stack.
            var processorStatusCopy = cpu.ProcessorStatus.Clone();

            processorStatusCopy.Break  = true;
            processorStatusCopy.Unused = true;
            cpu.PushByteToStack(processorStatusCopy.Value, mem);

            return(InstructionLogicResult.WithNoExtraCycles());
        }
示例#14
0
        public InstructionLogicResult ExecuteWithByte(CPU cpu, Memory mem, byte value, AddrModeCalcResult addrModeCalcResult)
        {
            bool branchSucceeded = false;
            bool addressCalculationCrossedPageBoundary = false;
            if(!cpu.ProcessorStatus.Carry)
            {
                // The instruction value is signed byte with the relative address (positive or negative)
                cpu.PC = BranchHelper.CalculateNewAbsoluteBranchAddress(cpu.PC, (sbyte)value, out ulong _, out addressCalculationCrossedPageBoundary);
                branchSucceeded = true;
            }

            return InstructionLogicResult.WithExtraCycles(
                InstructionExtraCyclesCalculator.CalculateExtraCyclesForBranchInstructions(
                        branchSucceeded,
                        addressCalculationCrossedPageBoundary)
                );
        }
示例#15
0
        public InstructionLogicResult ExecuteWithStack(CPU cpu, Memory mem, AddrModeCalcResult addrModeCalcResult)
        {
            // BRK is strange. The complete instruction is only one byte but the processor increases
            // the return address pushed to stack is the *second* byte after the opcode!
            // It is advisable to use a NOP after it to avoid issues (when returning from BRK with RTI, the PC will point to the next-next instruction)
            ushort pcPushedToStack = cpu.PC;

            pcPushedToStack++;
            cpu.PushWordToStack(pcPushedToStack, mem);
            // Set the Break flag on the copy of the ProcessorStatus that will be stored in stack.
            var processorStatusCopy = cpu.ProcessorStatus.Clone();

            processorStatusCopy.Break  = true;
            processorStatusCopy.Unused = true;
            cpu.PushByteToStack(processorStatusCopy.Value, mem);
            // BRK sets current Interrupt flag
            cpu.ProcessorStatus.InterruptDisable = true;
            // Change PC to address found at BRK/IEQ handler vector
            cpu.PC = cpu.FetchWord(mem, CPU.BrkIRQHandlerVector);

            return(InstructionLogicResult.WithNoExtraCycles());
        }
示例#16
0
        public InstructionLogicResult Execute(CPU cpu, AddrModeCalcResult addrModeCalcResult)
        {
            cpu.SP = cpu.X;

            return(InstructionLogicResult.WithNoExtraCycles());
        }
示例#17
0
 public InstructionLogicResult ExecuteWithStack(CPU cpu, Memory mem, AddrModeCalcResult addrModeCalcResult)
 {
     cpu.PushByteToStack(cpu.A, mem);
     return(InstructionLogicResult.WithNoExtraCycles());
 }
示例#18
0
        public InstructionLogicResult ExecuteWithWord(CPU cpu, Memory mem, ushort address, AddrModeCalcResult addrModeCalcResult)
        {
            cpu.PC = address;

            return(InstructionLogicResult.WithNoExtraCycles());
        }
示例#19
0
        public InstructionLogicResult ExecuteWithByte(CPU cpu, Memory mem, byte value, AddrModeCalcResult addrModeCalcResult)
        {
            BinaryArithmeticHelpers.SetFlagsAfterCompare(cpu.X, value, cpu.ProcessorStatus);

            return(InstructionLogicResult.WithNoExtraCycles());
        }
示例#20
0
 public InstructionLogicResult Execute(CPU cpu, AddrModeCalcResult addrModeCalcResult)
 {
     // Do nothing!
     return(InstructionLogicResult.WithNoExtraCycles());
 }
示例#21
0
        public InstructionLogicResult ExecuteWithByte(CPU cpu, Memory mem, byte value, AddrModeCalcResult addrModeCalcResult)
        {
            BinaryArithmeticHelpers.PerformBITAndSetStatusRegisters(cpu.A, value, cpu.ProcessorStatus);

            return(InstructionLogicResult.WithNoExtraCycles());
        }