Exemplo n.º 1
0
        private void OpenROM(object sender, EventArgs e)
        {
            // Show the dialog and get result.
            DialogResult result = openFileDialog1.ShowDialog();

            if (result == DialogResult.OK) // Test result.
            {
                string path = openFileDialog1.FileName;

                rom    ROM     = new rom();
                cpu    CPU     = new cpu();
                ram    RAM     = new ram();
                byte[] ROMByte = File.ReadAllBytes(path);


                int num1 = 0x8000;
                int num2 = 0xc000;


                ROM.Init(ROMByte, RAM);
                RAM.Init();
                Buffer.BlockCopy(ROM.ROMBytes, 0x10, RAM.Memory, num1, 0x4000);
                if (ROM.NumOfPRGBlocks == 1)
                {
                    Buffer.BlockCopy(ROM.ROMBytes, 0x10, RAM.Memory, num2, 0x4000);
                }
                Debug.WriteLine(RAM.Memory[0x8000]);
                Debug.WriteLine(RAM.Memory[0xC5F5]);
                CPU.PowerUp();
                CPU.RunROM(ROM, RAM);
            }
            Console.WriteLine(result); // <-- For debugging use.
        }
Exemplo n.º 2
0
        public MainForm()
        {
            Debug.WriteLine("hello world");
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            //
            // TODO: Add constructor code after the InitializeComponent() call.
            //

            //TODO: Unhardcode path.

            //string path = @"C:\Users\510628\Desktop\SharpDevelop\Projects\NesCom\ROms\Earthbound_Zero_(P)_(H).nes";
            //string path = @"C:\Users\510628\Desktop\SharpDevelop\Projects\NesCom\ROms\Super Mario Bros (E).nes";
            //string path = @"C:\Users\510628\Desktop\SharpDevelop\Projects\NesCom\ROms\sample.nes";
            string path = @"C:\Users\510628\Desktop\SharpDevelop\Projects\NesCom\ROms\nestest.nes";



            rom ROM = new rom();
            cpu CPU = new cpu();
            ram RAM = new ram();

            byte[] ROMByte = File.ReadAllBytes(path);


            int num1 = 0x8000;
            int num2 = 0xc000;


            ROM.Init(ROMByte, RAM);
            RAM.Init();
            Buffer.BlockCopy(ROM.ROMBytes, 0x10, RAM.Memory, num1, 0x4000);
            if (ROM.NumOfPRGBlocks == 1)
            {
                Buffer.BlockCopy(ROM.ROMBytes, 0x10, RAM.Memory, num2, 0x4000);
            }
            Debug.WriteLine(RAM.Memory[0x8000]);
            Debug.WriteLine(RAM.Memory[0xC5F5]);
            CPU.PowerUp();
            CPU.RunROM(ROM, RAM);
        }
Exemplo n.º 3
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"));
            }
        }