Пример #1
0
        public BenchmarkRunner(Benchmark settings)
        {
            // Create the emulator
            var emulator = new Z80Processor();

            // Insert the memory contents
            foreach (var item in settings.Memory)
            {
                emulator.Memory.SetContents(item.Offset, item.Values);
            }

            // Configure the CPU emulator...
            emulator.MemoryAccess += OnMemoryAccess;
            var counter = new CycleCountingClockSynchronizer(emulator, settings.MaxCycles);

            emulator.ClockSynchronizer           = counter;
            emulator.AutoStopOnRetWithStackEmpty = true;
            emulator.InterruptMode = 1;
            emulator.Reset();
            // ReSharper disable once IntVariableOverflowInUncheckedContext
            emulator.Registers.SP = (short)settings.StackPointer;
            emulator.Registers.PC = (ushort)settings.ExecutionAddress;

            var sw = Stopwatch.StartNew();

            emulator.Start();
            sw.Stop();

            if (emulator.StopReason == StopReason.StopInvoked)
            {
                throw new Exception("Emulator stopped due to running for too long");
            }

            VramMismatches = checkComparisons(settings.VramComparisons, i => _vdp.Vram[i]).ToList();
            RamMismatches  = checkComparisons(settings.RamComparisons, i => emulator.Memory[i]).ToList();

            sw.Stop();

            // Record state
            Cycles        = counter.Cycles;
            WallClockTime = sw.Elapsed;
        }
Пример #2
0
        public void HelloWorldTest()
        {
            var Sut = new Z80Processor();

            Sut.AutoStopOnRetWithStackEmpty = true;

            var program = new byte[]
            {
                0x3E, 0x07, //LD A,7
                0xC6, 0x04, //ADD A,4
                0x3C,       //INC A
                0xC9        //RET
            };

            Sut.Memory.SetContents(0, program);

            Sut.Start();

            Assert.AreEqual(12, Sut.Registers.A);
            Assert.AreEqual(28, Sut.TStatesElapsedSinceStart);
        }
Пример #3
0
        public void IlBvtTest(string ilFileName)
        {
            var z80 = new Z80Processor();

            // The Z80 simulator doesn't handle auto stop correctly
            // if the sp is manually manipulated e.g. ld sp, xx
            // so we have to disable it but will rely on auto stop
            // on halt
            z80.AutoStopOnRetWithStackEmpty = false;

            // read bytes from cim file and load into byte array
            var program = File.ReadAllBytes(ilFileName);

            z80.Memory.SetContents(0, program);

            z80.Start();

            // Validate we finished on the HALT instruction
            Assert.AreEqual(12, z80.Registers.PC);

            // Pass returns 32 bit 0 in DEHL
            Assert.AreEqual(0, z80.Registers.DE);
            Assert.AreEqual(0, z80.Registers.HL);
        }