예제 #1
0
파일: SEI.cs 프로젝트: highbyte/dotnet-6502
        public InstructionLogicResult Execute(CPU cpu, AddrModeCalcResult addrModeCalcResult)
        {
            // Assume implied mode
            cpu.ProcessorStatus.InterruptDisable = true;

            return(InstructionLogicResult.WithNoExtraCycles());
        }
예제 #2
0
파일: CLD.cs 프로젝트: highbyte/dotnet-6502
        public InstructionLogicResult Execute(CPU cpu, AddrModeCalcResult addrModeCalcResult)
        {
            // Assume implied mode
            cpu.ProcessorStatus.Decimal = false;

            return(InstructionLogicResult.WithNoExtraCycles());
        }
예제 #3
0
파일: TYA.cs 프로젝트: highbyte/dotnet-6502
        public InstructionLogicResult Execute(CPU cpu, AddrModeCalcResult addrModeCalcResult)
        {
            cpu.A = cpu.Y;
            BinaryArithmeticHelpers.SetFlagsAfterRegisterLoadIncDec(cpu.A, cpu.ProcessorStatus);

            return(InstructionLogicResult.WithNoExtraCycles());
        }
예제 #4
0
파일: PLA.cs 프로젝트: highbyte/dotnet-6502
 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
파일: ROR.cs 프로젝트: highbyte/dotnet-6502
        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
파일: DEC.cs 프로젝트: highbyte/dotnet-6502
        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
파일: ROR.cs 프로젝트: highbyte/dotnet-6502
        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
파일: RTS.cs 프로젝트: highbyte/dotnet-6502
        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
파일: RTI.cs 프로젝트: highbyte/dotnet-6502
        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
파일: JSR.cs 프로젝트: highbyte/dotnet-6502
        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
파일: CMP.cs 프로젝트: highbyte/dotnet-6502
        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
파일: BCC.cs 프로젝트: highbyte/dotnet-6502
        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
파일: JMP.cs 프로젝트: highbyte/dotnet-6502
        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
파일: NOP.cs 프로젝트: highbyte/dotnet-6502
 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());
        }