예제 #1
0
        private void ExecutionLoop(CancellationToken token)
        {
            Task.Run(() =>
            {
                while (!token.IsCancellationRequested)
                {
                    Thread.Sleep(100);
                    InterruptNmi();
                }
            }, token);

            while (!token.IsCancellationRequested)
            {
                _cpu.Reset();

                _diskController.LoadFileIntoMemory(DiskController.BiosFile, 0);

                var frameCount = 0;
                var totalSleep = 0;
                var stopWatch  = new Stopwatch();

                while (!_doReset)
                {
                    stopWatch.Start();
                    _cpu.Exec(FrameDurationMs * CyclesPerMs);
                    stopWatch.Stop();

                    var sleepMs = 0;
                    if (OriginalSpeed && stopWatch.ElapsedMilliseconds < FrameDurationMs)
                    {
                        sleepMs = FrameDurationMs - (int)stopWatch.ElapsedMilliseconds;
                        Thread.Sleep(sleepMs);
                    }

                    totalSleep += sleepMs;
                    if (++frameCount == LoadMeasureFrameCount)
                    {
                        LoadFactor = 1.0 - (double)totalSleep / (frameCount * FrameDurationMs);
                        totalSleep = 0;
                        frameCount = 0;
                    }

                    stopWatch.Reset();


                    if (_interruptIrq)
                    {
                        _cpu.Interrupt(Z80.INTERRUPT_TYPE_IRQ, true);
                        _interruptIrq = false;
                    }
                    if (_interruptNmi)
                    {
                        _cpu.Interrupt(Z80.INTERRUPT_TYPE_NMI, true);
                        _interruptNmi = false;
                    }
                }
                _doReset = false;
            }
        }