コード例 #1
0
        public MsxEmulationEnvironment(IDictionary <string, object> configDictionary, Action <string, object[]> tell, string machineName)
        {
            this.configDictionary      = configDictionary;
            defaultEmulationParameters = configDictionary.GetValue <IDictionary <string, object> >("defaultEmulationParameters");
            this.tell = tell;
            HostForm  = new EmulatorHostForm(this);
            Z80       = new Z80Processor();
            this.originalClockSynchronizer = Z80.ClockSynchronizer;

            this.machineName = machineName;

            LoadMachineConfig();
            GenerateInjectedConfig();

            var machineEmulationParameters = machineConfig.GetDictionaryOrDefault("emulationParameters");
            var configToApply = injectedConfig.Keys.ToDictionary(k => k, k => injectedConfig[k]);

            machineEmulationParameters.MergeInto(configToApply);
            defaultEmulationParameters.MergeInto(configToApply);

            this.globalConfig = ConvertConfigDictionaryToObject(configToApply);
            globalConfig.GlobalPluginsConfig = configDictionary.GetDictionaryOrDefault("plugins");
            globalConfig.SharedPluginsConfig = configDictionary.GetDictionaryOrDefault("sharedPluginsConfig");

            HostForm.ApplyConfig(globalConfig);

            ConfigureCpu();
            SlotsSystem = CreateEmptySlotsSystem();

            KeyboardEventSource = HostForm;
            HostForm.SetFormTitle(this.machineName);
            Vdp = CreateVdp(HostForm);
            KeyboardController = CreateKeyboardController(HostForm);

            pluginContext = new PluginContext
            {
                Cpu            = Z80,
                HostForm       = HostForm,
                SlotsSystem    = SlotsSystem,
                Vdp            = Vdp,
                KeyEventSource = KeyboardEventSource,
                LoadedPlugins  = null,
                SetMenuEntry   = HostForm.SetPluginMenuEntry
            };
            PluginsLoader = new PluginsLoader(pluginContext, tell);
            LoadGlobalPlugins();
            LoadMachinePlugins();

            CreateSlotsSystem();

            var hardware = new MsxHardwareSet
            {
                Cpu = Z80,
                KeyboardController = KeyboardController,
                SlotsSystem        = SlotsSystem,
                Vdp = Vdp
            };

            emulator = new MsxEmulator(hardware);
        }
コード例 #2
0
        private void Run(string[] args)
        {
            var fileName    = args.Length == 0 ? "zexall.com" : args[0];
            var testsToSkip = args.Length >= 2 ? int.Parse(args[1]) : 0;

            DollarCode = Encoding.ASCII.GetBytes(new[] { '$' })[0];

            var z80 = new Z80Processor();

            z80.ClockSynchronizer           = null;
            z80.AutoStopOnRetWithStackEmpty = true;

            var program = File.ReadAllBytes(fileName);

            z80.Memory.SetContents(0x100, program);

            z80.Memory[6] = 0xFF;
            z80.Memory[7] = 0xFF;

            z80.BeforeInstructionFetch += Z80OnBeforeInstructionFetch;

            SkipTests(z80, testsToSkip);

            Stopwatch sw = new Stopwatch();

            sw.Start();

            z80.Reset();
            z80.Registers.PC = 0x100;
            z80.Continue();

            sw.Stop();
            Console.WriteLine("\r\nElapsed time: " + sw.Elapsed);
        }
コード例 #3
0
        private static void SkipTests(Z80Processor z80, int testsToSkipCount)
        {
            ushort loadTestsAddress = 0x120;
            ushort originalAddress  = 0x13A;
            ushort newTestAddress   = (ushort)(originalAddress + testsToSkipCount * 2);

            z80.Memory[loadTestsAddress]     = newTestAddress.GetLowByte();
            z80.Memory[loadTestsAddress + 1] = newTestAddress.GetHighByte();
        }
コード例 #4
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;
        }
コード例 #5
0
ファイル: HelloWorld.cs プロジェクト: drako0812/Z80dotNet
        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);
        }
コード例 #6
0
ファイル: ILBvtTests.cs プロジェクト: drcjt/CSharp-80
        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);
        }
コード例 #7
0
 public void SetUp()
 {
     Fixture = new Fixture();
     Sut     = new Z80Processor();
 }
 public CycleCountingClockSynchronizer(Z80Processor emulator, long maxCycles)
 {
     _emulator  = emulator;
     _maxCycles = maxCycles;
 }