Example #1
0
        /// <summary>
        /// Creates a Spectrum instance with the specified model and edition name
        /// </summary>
        /// <param name="modelKey">Spectrum model name</param>
        /// <param name="editionKey">Edition name</param>
        /// <returns>The newly create Spectrum machine</returns>
        public static ISpectrumMachine CreateMachine(string modelKey, string editionKey)
        {
            // --- Check input
            if (modelKey == null)
            {
                throw new ArgumentNullException(nameof(modelKey));
            }
            if (editionKey == null)
            {
                throw new ArgumentNullException(nameof(editionKey));
            }

            if (!SpectrumModels.StockModels.TryGetValue(modelKey, out var model))
            {
                throw new KeyNotFoundException($"Cannot find a Spectrum model with key '{modelKey}'");
            }

            if (!model.Editions.TryGetValue(editionKey, out var edition))
            {
                throw new KeyNotFoundException($"Cannot find an edition of {modelKey} with key '{editionKey}'");
            }

            // --- Create the selected Spectrum model/edition
            DeviceInfoCollection devices;

            switch (modelKey)
            {
            case SpectrumModels.ZX_SPECTRUM_128:
                devices = CreateSpectrum128Devices(edition);
                break;

            case SpectrumModels.ZX_SPECTRUM_P3_E:
                devices = CreateSpectrumP3Devices(edition);
                break;

            default:
                devices = CreateSpectrum48Devices(edition);
                break;
            }

            // --- Setup the machine
            var machine       = new SpectrumMachine(modelKey, editionKey, devices);
            var debugProvider = GetProvider <ISpectrumDebugInfoProvider>();

            if (debugProvider != null)
            {
                machine.SpectrumVm.DebugInfoProvider = debugProvider;
            }
            if (s_StackDebugSupport != null)
            {
                machine.SpectrumVm.Cpu.StackDebugSupport = s_StackDebugSupport;
            }
            return(machine);
        }
Example #2
0
        /// <summary>
        /// Creates a SpectrumMachine instance according to the specified edition key
        /// </summary>
        /// <param name="modelKey">Spectrum model key</param>
        /// <param name="editionKey">Edition key (within the model)</param>
        /// <returns>
        /// The newly created machine instance
        /// </returns>
        public static SpectrumMachine CreateMachine(string modelKey, string editionKey)
        {
            // --- Check input
            if (modelKey == null)
            {
                throw new ArgumentNullException(nameof(modelKey));
            }
            if (editionKey == null)
            {
                throw new ArgumentNullException(nameof(editionKey));
            }

            if (!SpectrumModels.StockModels.TryGetValue(modelKey, out var model))
            {
                throw new KeyNotFoundException($"Cannot find a Spectrum model with key '{modelKey}'");
            }

            if (!model.Editions.TryGetValue(editionKey, out var edition))
            {
                throw new KeyNotFoundException($"Cannot find an edition of {modelKey} with key '{editionKey}'");
            }

            // --- Create the selected Spectrum model/edition
            DeviceInfoCollection devices;

            switch (modelKey)
            {
            case SpectrumModels.ZX_SPECTRUM_128:
                devices = CreateSpectrum128Devices(edition);
                break;

            case SpectrumModels.ZX_SPECTRUM_P3_E:
                devices = CreateSpectrumP3Devices(edition);
                break;

            case SpectrumModels.ZX_SPECTRUM_NEXT:
                devices = CreateSpectrumNextDevices(edition);
                break;

            default:
                devices = CreateSpectrum48Devices(edition);
                break;
            }

            // --- Setup the machine
            var machine = new SpectrumMachine
            {
                SpectrumVm = new SpectrumEngine(devices),
                VmState    = VmState.None
            };
            var debugProvider = GetProvider <ISpectrumDebugInfoProvider>();

            if (debugProvider != null)
            {
                machine.SpectrumVm.DebugInfoProvider = debugProvider;
            }
            machine.SpectrumVm.Cpu.StackDebugSupport = new ScriptingStackDebugSupport();

            var screenDevice = machine.SpectrumVm.ScreenDevice;

            screenDevice.FrameCompleted += (sender, args) =>
            {
                machine.VmScreenRefreshed?.Invoke(machine,
                                                  new VmScreenRefreshedEventArgs(screenDevice.GetPixelBuffer()));
            };
            return(machine);
        }