Exemplo n.º 1
0
        public void RunROM(rom SelfROM, ram SelfRAM)
        {
            //Load ROM
            ROM         = SelfROM;
            RAM         = SelfRAM;
            PC_Register = 0x8000;
            //Run ROM
            IsRunning = true;
            byte CurrentByte;

            while (IsRunning)
            {
                //Get byte at Program Counter
                CurrentByte = ROM.GetByte(PC_Register);

                //Turn Byte into Instruction
                switch (CurrentByte)
                {
                case 0x0:
                    BRKInstruction(CurrentByte);
                    break;

                case 0x10:
                    BPLInstruction(CurrentByte);
                    break;

                case 0x18:
                    CLCInstruction(CurrentByte);
                    break;

                case 0x20:
                    JSRInstruction(CurrentByte);
                    break;

                case 0x24:
                    BITZePgInstruction(CurrentByte);
                    break;

                case 0x30:
                    BMIInstruction(CurrentByte);
                    break;

                case 0x38:
                    SECInstruction(CurrentByte);
                    break;

                case 0x45:
                    EORZePgInstruction(CurrentByte);
                    break;

                case 0x4C:
                    JMPAbsInstruction(CurrentByte);
                    break;

                case 0x50:
                    BVCInstruction(CurrentByte);
                    break;

                case 0x58:
                    CLIInstruction(CurrentByte);
                    break;

                case 0x60:
                    RTSInstruction(CurrentByte);
                    break;

                case 0x69:
                    ADCImmInstruction(CurrentByte);
                    break;

                case 0x70:
                    BVSInstruction(CurrentByte);
                    break;

                case 0x78:
                    SEIInstruction(CurrentByte);
                    break;

                case 0x85:
                    StaZePgInstruction(CurrentByte);
                    break;

                case 0x86:
                    StxZePgInstruction(CurrentByte);
                    break;

                case 0x8D:
                    StaAbsInstruction(CurrentByte);
                    break;

                case 0x8E:
                    StxAbsInstruction(CurrentByte);
                    break;

                case 0x90:
                    BCCInstruction(CurrentByte);
                    break;

                case 0x9A:
                    TXSInstruction(CurrentByte);
                    break;

                case 0xA0:
                    LDYImmInstruction(CurrentByte);
                    break;

                case 0xA2:
                    LDXImmInstruction(CurrentByte);
                    break;

                case 0xA5:
                    LdaZePgInstruction(CurrentByte);
                    break;

                case 0xA9:
                    LDAImmInstruction(CurrentByte);
                    break;

                case 0xAA:
                    TAXInstruction(CurrentByte);
                    break;

                case 0xAD:
                    LdaAbsInstruction(CurrentByte);
                    break;

                case 0xB0:
                    BCSInstruction(CurrentByte);
                    break;

                case 0xB8:
                    CLVInstruction(CurrentByte);
                    break;

                case 0xBD:
                    LdaAbsXInstruction(CurrentByte);
                    break;

                case 0xC0:
                    CPYImmInstruction(CurrentByte);
                    break;

                case 0xC9:
                    CMPImmInstruction(CurrentByte);
                    break;

                case 0xCA:
                    DEXInstruction(CurrentByte);
                    break;

                case 0xE0:
                    CPXImmInstruction(CurrentByte);
                    break;

                case 0xEA:
                    NOPInstruction(CurrentByte);
                    break;

                case 0xED:
                    INXInstruction(CurrentByte);
                    break;

                case 0xD0:
                    BNEInstruction(CurrentByte);
                    break;

                case 0xD8:
                    CLDInstruction(CurrentByte);
                    break;

                case 0xF0:
                    BEQInstruction(CurrentByte);
                    break;

                case 0xF8:
                    SEDInstruction(CurrentByte);
                    break;



                default:
                    Debug.WriteLine("OpCode not implemented!!!");
                    throw new NotImplementedException("OpCode not implemented!!!");
                }

                PC_Register += InstructionLength;
                Debug.WriteLine("PC Register: " + PC_Register.ToString("X"));
            }
        }
Exemplo n.º 2
0
        public void ADCImmInstruction(byte Instruction)
        {
            InstructionLength = 2;

            byte Fetched = ROM.GetByte(PC_Register + 1);
            int  Carry   = Status_Register.HasFlag(StatusFlags.C) ? 1 : 0;

            byte Sum = (byte)(A_Register + Fetched + Carry);

            A_Register = Sum;

            if (A_Register == 0)
            {
                Status_Register |= (StatusFlags)StatusFlags.Z;
            }

            if ((A_Register & (1 << 7 - 1)) != 0)
            {
                Status_Register |= (StatusFlags)StatusFlags.N;
            }

            if ((~(A_Register ^ Fetched) & (A_Register ^ Sum) & 0x80) != 0)
            {
                Status_Register |= (StatusFlags)StatusFlags.V;
            }

            if ((A_Register + Fetched + Carry) > 0xFF)
            {
                Status_Register |= (StatusFlags)StatusFlags.C;
            }

            Debug.WriteLine("ADC #" + Fetched + " - Identifier byte: " + Instruction);
        }