コード例 #1
0
        public void GpuFramesPerSecondBenchmark()
        {
            Mode lcdMode     = 0;
            byte currentLine = 0;
            var  mmu         = new StubIMmu
            {
                ReadByteUInt16        = a => RandomByte(),
                LcdCurrentLineGet     = () => currentLine,
                LcdCurrentLineSetByte = l => currentLine = l,
                LcdModeGet            = () => lcdMode,
                LcdModeSetMode        = m => lcdMode = m,
                LcdEnabledGet         = () => true,
                DisplayBackgroundGet  = () => true,
                DisplayWindowGet      = () => true,
                DisplaySpritesGet     = () => true
            };
            var gpu = new Gpu(mmu);

            var drawCount = 0;
            var sw        = new Stopwatch(); sw.Start();

            for (int i = 0; i < _numSteps; i++)
            {
                drawCount += gpu.Step(RandomCycleCount()) ? 1 : 0;
            }
            sw.Stop();

            var stepsPerSecond  = (decimal)(_numSteps / sw.Elapsed.TotalSeconds);
            var framesPerSecond = (decimal)(drawCount / sw.Elapsed.TotalSeconds);
            var speedupFactor   = framesPerSecond / 60;

            TestContext.WriteLine($"Steps per second: {stepsPerSecond.ToString("N")}");
            TestContext.WriteLine($"Frames per second: {framesPerSecond.ToString("N")}");
            TestContext.WriteLine($"Speedup factor: {speedupFactor.ToString("N")}");
        }
コード例 #2
0
        private void RunTest(StubIMmu mmu)
        {
            var cpu = new Cpu(mmu);

            long cycles = 0;
            var  sw     = new Stopwatch(); sw.Start();

            for (int i = 0; i < _numInstructions; i++)
            {
                cycles += cpu.Step();
            }
            sw.Stop();

            cycles *= 4; // Cpu returns 1/4 cycles
            var insPerSecond    = (decimal)(_numInstructions / sw.Elapsed.TotalSeconds);
            var cyclesPerSecond = (decimal)(cycles / sw.Elapsed.TotalSeconds);
            var speedupFactor   = cyclesPerSecond / 4194304;

            TestContext.WriteLine($"Instructions per second: {insPerSecond.ToString("N")}");
            TestContext.WriteLine($"Cycles per second: {cyclesPerSecond.ToString("N")}");
            TestContext.WriteLine($"Speedup factor: {speedupFactor.ToString("N")}");
        }
コード例 #3
0
ファイル: CpuTests.cs プロジェクト: justinricheson/GameBoyEm
        private CpuState Test(CpuState cpuState)
        {
            var mem = new Dictionary<ushort, byte>();
            foreach (var m in cpuState.Memory)
            {
                mem.Add(m.Address, m.Value);
            }

            var read = new FakesDelegates.Func<ushort, byte>(a =>
            {
                if (!mem.ContainsKey(a))
                {
                    return 0; // Only writes allocate memory
                }
                return mem[a];
            });

            var readW = new FakesDelegates.Func<ushort, ushort>(a =>
            {
                var hi = read(a);
                var lo = read((ushort)(a + 1));
                return (ushort)((hi << 8) | lo);
            });

            var mmu = new StubIMmu();
            mmu.ReadByteUInt16 = read;
            mmu.ReadWordUInt16 = readW;
            mmu.WriteByteUInt16Byte = (a, v) =>
            {
                mem[a] = v;
            };
            mmu.WriteWordUInt16UInt16 = (a, v) =>
            {
                mem[a] = (byte)((v & 0xFF00) >> 8);
                mem[(ushort)(a + 1)] = (byte)(v & 0xFF);
            };

            var cpu = new TestCpu(mmu,
                cpuState.A, cpuState.B, cpuState.C,
                cpuState.D, cpuState.E, cpuState.H,
                cpuState.L, cpuState.SP, cpuState.PC,
                cpuState.FZ, cpuState.FN, cpuState.FH,
                cpuState.FC, cpuState.IME);

            cpu.Step();

            return new CpuState
            {
                A = cpu.A,
                B = cpu.B,
                C = cpu.C,
                D = cpu.D,
                E = cpu.E,
                H = cpu.H,
                L = cpu.L,
                SP = cpu.SP,
                PC = cpu.PC,
                FZ = cpu.FZ,
                FN = cpu.FN,
                FH = cpu.FH,
                FC = cpu.FC,
                IME = cpu.IME,
                Memory = mem.Keys.OrderBy(k => k).Select(k =>
                {
                    var v = mem[k];
                    return new MemoryRecord
                    {
                        Address = k,
                        Value = v
                    };
                }).ToList()
            };
        }
コード例 #4
0
ファイル: CpuTests.cs プロジェクト: justinricheson/GameBoyEm
        private CpuState Test(CpuState cpuState)
        {
            var mem = new Dictionary <ushort, byte>();

            foreach (var m in cpuState.Memory)
            {
                mem.Add(m.Address, m.Value);
            }

            var read = new FakesDelegates.Func <ushort, byte>(a =>
            {
                if (!mem.ContainsKey(a))
                {
                    return(0); // Only writes allocate memory
                }
                return(mem[a]);
            });

            var readW = new FakesDelegates.Func <ushort, ushort>(a =>
            {
                var hi = read(a);
                var lo = read((ushort)(a + 1));
                return((ushort)((hi << 8) | lo));
            });

            var mmu = new StubIMmu();

            mmu.ReadByteUInt16      = read;
            mmu.ReadWordUInt16      = readW;
            mmu.WriteByteUInt16Byte = (a, v) =>
            {
                mem[a] = v;
            };
            mmu.WriteWordUInt16UInt16 = (a, v) =>
            {
                mem[a] = (byte)((v & 0xFF00) >> 8);
                mem[(ushort)(a + 1)] = (byte)(v & 0xFF);
            };

            var cpu = new TestCpu(mmu,
                                  cpuState.A, cpuState.B, cpuState.C,
                                  cpuState.D, cpuState.E, cpuState.H,
                                  cpuState.L, cpuState.SP, cpuState.PC,
                                  cpuState.FZ, cpuState.FN, cpuState.FH,
                                  cpuState.FC, cpuState.IME);

            cpu.Step();

            return(new CpuState
            {
                A = cpu.A,
                B = cpu.B,
                C = cpu.C,
                D = cpu.D,
                E = cpu.E,
                H = cpu.H,
                L = cpu.L,
                SP = cpu.SP,
                PC = cpu.PC,
                FZ = cpu.FZ,
                FN = cpu.FN,
                FH = cpu.FH,
                FC = cpu.FC,
                IME = cpu.IME,
                Memory = mem.Keys.OrderBy(k => k).Select(k =>
                {
                    var v = mem[k];
                    return new MemoryRecord
                    {
                        Address = k,
                        Value = v
                    };
                }).ToList()
            });
        }