Пример #1
0
 public void MachineCycle()
 {
     lastCycles = _cpu.Cycles;
     if (prepareSpeedSwitch)
     {
         if (_cpu.Stop)
         {
             doubleSpeed        = !doubleSpeed;
             prepareSpeedSwitch = false;
             _cpu.Stop          = false;
         }
     }
     if (doubleSpeed)
     {
         HandleInterrupt();
         _cpu.Cycle();
         HandleInterrupt();
         _cpu.Cycle();
         for (int i = 0; i < _cpu.Cycles - lastCycles; i++)
         {
             Timer();
         }
         for (int i = 0; i < (_cpu.Cycles - lastCycles) / 2; i++)
         {
             _ppu.LcdTick();
             _apu.ApuTick();
         }
     }
     else
     {
         HandleInterrupt();
         _cpu.Cycle();
         for (int i = 0; i < _cpu.Cycles - lastCycles; i++)
         {
             _ppu.LcdTick();
             Timer();
             _apu.ApuTick();
         }
     }
     if (saveState)
     {
         WriteSaveState(ref _saveState);
         _cart.WriteStateFile(_saveState, selectedSavestate);
         saveState = false;
     }
     if (loadState)
     {
         Savestate tempState = _cart.LoadStateFile(selectedSavestate);
         if (tempState != null)
         {
             LoadSaveState(tempState);
         }
         loadState = false;
     }
 }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("NES Test");

            Cpu.OnStep += Cpu_OnStep;

            // Load golden log


            // Load NES Test "ROM"
            var file = File.ReadAllBytes("nestest.nes");
            var data = file.Skip(0x10).ToArray();

            for (int i = 0; i < data.Length; i++)
            {
                Memory[0xC000 + i] = data[i];
            }

            // Set PC start
            Cpu.PC = 0xC000;

            // Cycle CPU until all official op codes has been tested
            Console.WriteLine("\nRunning official op code test...");
            while (Break == false && Cpu.PC != 0xC6BD)
            {
                Cpu.Cycle();
                Thread.Sleep(TimeSpan.FromTicks(9000));
            }
            Console.WriteLine("\nSUCCESS!\n");


            // Cycle CPU until all unofficial op codes has been tested
            Console.WriteLine("\nRunning unofficial op code test...");
            while (Break == false && Cpu.PC != 0x0001)
            {
                try {
                    Cpu.Cycle();
                    Thread.Sleep(TimeSpan.FromTicks(9000));
                } catch (Exception) {
                    Console.WriteLine($"MISSING OP CODE: 0x{Memory._memory[Cpu.PC]:X2}");

                    Break = true;
                }
            }
            if (!Break)
            {
                Console.WriteLine("\nSUCCESS!\n");
            }

            Console.WriteLine($"PROGRESS: {CurrentLogLine}/{GoldenLog.Length} ({(CurrentLogLine * 100f / GoldenLog.Length):F1}%)");
        }
Пример #3
0
    private void Update()
    {
        foreach (uint u in m_UpdateAddrList)
        {
            m_CpuInstance.ClearStackAndStates();
            m_CpuInstance.PushState(u);   //Jump to Registered Function

            while (m_CpuInstance.StackDepth != 0)
            {
                m_CpuInstance.Cycle();
            }

            m_CpuInstance.UnSet(Cpu.Flags.Halt);
        }
    }
Пример #4
0
        static void Main(string[] args)
        {
            var bios = File.ReadAllBytes(args[0]);
            var bus  = new Bus(bios);
            var cpu  = new Cpu();

            while (true)
            {
                cpu.Cycle(bus);
            }
        }
Пример #5
0
        public void PowerOn()
        {
            if (_isRunnning)
            {
                return;
            }

            Initialize();

            // Apply ROM patches
            if (Settings.Default.KernalWhiteTextColor)
            {
                PatchKernalRomTextColor(0x01);
            }

            Cpu.Reset();

            _isRunnning = true;
            _tcsStop    = new TaskCompletionSource <bool>();

            var swCpuClock = Stopwatch.StartNew();

            var t = new Thread(() => {
                while (_isRunnning)
                {
                    // CPU clock
                    if (swCpuClock.Elapsed.TotalMilliseconds >= CpuPeriodMilliseconds)
                    {
                        CpuPeriodMillisecondsReal = swCpuClock.Elapsed.TotalMilliseconds;
                        CpuClockSpeedRealHz       = 1 / (CpuPeriodMillisecondsReal / 1000.0f);

                        swCpuClock.Restart();

                        // Clock CIA 1
                        Cia.Clock();

                        // Cycle VIC-II
                        Vic.Cycle();

                        // Cycle the CPU
                        Cpu.Cycle();
                    }
                }

                _tcsStop.SetResult(true);
            });

            t.SetApartmentState(ApartmentState.STA);
            t.Start();
        }
Пример #6
0
        private uint Run(uint address)
        {
            m_Instance.PushState(address);

            while (m_Instance.StackDepth != 0)
            {
                m_Instance.Cycle();

                if (m_Instance.HasSet(Cpu.Flags.Halt))
                {
                    m_Instance.UnSet(Cpu.Flags.Halt);

                    return(0);
                }
            }

            return(m_Instance.Pop());
        }
Пример #7
0
        public void WhenDxynOpIsExecuted_CpuRequiresDrawing()
        {
            mem.SetByte(0x200, 0XD1);
            mem.SetByte(0x201, 0x23);
            cpu.VRegisters[1]   = 0x25;
            cpu.VRegisters[2]   = 0x30;
            cpu.IndexRegister   = 0x250;
            cpu.DrawingRequired = false;
            cpu.Cycle();

            cpu.DrawingRequired.Should().BeTrue();
        }