Exemple #1
0
        /// <summary>
        /// Injects the code into the Spectrum virtual machine's memory
        /// </summary>
        /// <param name="output"></param>
        public void InjectCodeIntoVm(AssemblerOutput output)
        {
            // --- Do not inject faulty code
            if (output == null || output.ErrorCount > 0)
            {
                return;
            }

            // --- Do not inject code if memory is not available
            var spectrumVm = Package.MachineViewModel.SpectrumVm;

            if (Package.MachineViewModel.VmState != VmState.Paused ||
                spectrumVm?.MemoryDevice == null)
            {
                return;
            }

            if (spectrumVm is ISpectrumVmRunCodeSupport runSupport)
            {
                // --- Go through all code segments and inject them
                foreach (var segment in output.Segments)
                {
                    var addr = segment.StartAddress + (segment.Displacement ?? 0);
                    runSupport.InjectCodeToMemory((ushort)addr, segment.EmittedCode);
                }

                // --- Prepare the machine for RUN mode
                runSupport.PrepareRunMode();
                CodeInjected?.Invoke(this, EventArgs.Empty);
            }
        }
Exemple #2
0
        /// <summary>
        /// Injects the code into the Spectrum virtual machine's memory
        /// </summary>
        /// <param name="output"></param>
        public void InjectCodeIntoVm(AssemblerOutput output)
        {
            // --- Do not inject faulty code
            if (output == null || output.ErrorCount > 0)
            {
                return;
            }

            // --- Do not inject code if memory is not available
            var vm         = SpectNetPackage.Default.EmulatorViewModel;
            var spectrumVm = vm.Machine.SpectrumVm;

            if (vm.MachineState != VmState.Paused || spectrumVm?.MemoryDevice == null)
            {
                return;
            }

            if (spectrumVm is ISpectrumVmRunCodeSupport runSupport)
            {
                // --- Clear the screen unless required else
                if (!output.InjectOptions.Contains("nocls"))
                {
                    runSupport.ClearScreen();
                }

                // --- Go through all code segments and inject them
                foreach (var segment in output.Segments)
                {
                    if (segment.Bank != null)
                    {
                        runSupport.InjectCodeToBank(segment.Bank.Value, segment.BankOffset, segment.EmittedCode);
                    }
                    else
                    {
                        var addr = segment.StartAddress;
                        runSupport.InjectCodeToMemory((ushort)addr, segment.EmittedCode);
                    }
                }

                // --- Prepare the machine for RUN mode
                runSupport.PrepareRunMode(output.InjectOptions);
                CodeInjected?.Invoke(this, EventArgs.Empty);
            }
        }
Exemple #3
0
 /// <summary>
 /// Signs that the code has been injected into the virtual machine
 /// </summary>
 public void RaiseCodeInjected()
 {
     CodeInjected?.Invoke(this, EventArgs.Empty);
 }