示例#1
0
    /// <summary>
    /// save a new configuration file
    /// </summary>
    public void saveconfigurationLastAdvanced()
    {
        string filepath       = Application.persistentDataPath + "/previoussettings.dat";
        ScreenConfiguration c = new ScreenConfiguration();

        c = screencofiguration;
        File.WriteAllText(filepath, JsonUtility.ToJson(c));
    }
        public void SettingBorderValueChangesBorderArea1()
        {
            // --- Arrange
            var pars     = new ScreenConfiguration();
            var pixels   = new TestPixelRenderer(pars);
            var spectrum = new SpectrumAdvancedTestMachine(pars, pixels);

            // --- Because we execute 3675 CPU tacts, rendering reaches
            // --- the first 104 pixels of the first border row
            spectrum.InitCode(new byte[]
            {
                0xF3,             // DI
                0x3E, 0x05,       // LD A,$05
                0xD3, 0xFE,       // OUT ($FE),A
                0x01, 0x8C, 0x00, // LD BC,$008C
                0x0B,             // DECLB: DEC BC
                0x78,             // LD A,B
                0xB1,             // OR C
                0x20, 0xFB,       // JR NZ,DECLB
                0x76              // HALT
            });

            // --- Act
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.UntilHalt));

            // --- Assert
            var regs = spectrum.Cpu.Registers;

            regs.PC.ShouldBe((ushort)0x800D);
            spectrum.Cpu.Tacts.ShouldBe(3671L);
            pixels.IsFrameReady.ShouldBeFalse();

            // --- The left 104 pixels of the first border row should be set to 0x05
            pixels.SetPixelMemory(spectrum.ScreenDevice.GetPixelBuffer());
            for (var column = 0; column < 96; column++)
            {
                pixels[0, column].ShouldBe((byte)0x05);
            }

            // --- The remaining pixels of the first border row should be intact (0xFF)
            for (var column = 96; column < spectrum.ScreenDevice.ScreenConfiguration.ScreenWidth; column++)
            {
                pixels[0, column].ShouldBe((byte)0x00);
            }

            // --- All the other screen bytes should be intact (0xFF)
            for (var row = 1; row < spectrum.ScreenDevice.ScreenConfiguration.ScreenLines; row++)
            {
                for (var column = 0; column < spectrum.ScreenDevice.ScreenConfiguration.ScreenWidth; column++)
                {
                    pixels[row, column].ShouldBe((byte)0x00);
                }
            }
        }
示例#3
0
        public Camera(ScreenConfiguration configuration)
        {
            Position = new Vector2f(0, 0);

            this.view = new View(new FloatRect(
                                     new Vector2f(0, 0),
                                     new Vector2f(configuration.Width, configuration.Height)));

            this.ViewPort      = configuration.SinglePlayer;
            this.configuration = configuration;
        }
示例#4
0
        public Screen(ScreenConfiguration configuration = null)
        {
            if (configuration == null)
            {
                configuration = new ScreenConfiguration();
            }

            Camera = new Camera(configuration);

            Id = Guid.NewGuid();
        }
示例#5
0
        /// <summary>
        /// Handle RTUpdate -- one of the repeating messages emitted by Presenter 2.
        /// </summary>
        /// <param name="rtu"></param>
        private void WebViewerReceiveUpdate(ArchiveRTNav.RTUpdate rtu)
        {
            int internalSlideIndex = slideMap.GetMapping(rtu.SlideIndex, rtu.DeckGuid);

            /// Fetch slide images for any slide in a Presentation deck
            /// and any slide in a StudentSubmission deck.
            /// Note: it used to be that rtu.SlideIndex==0 in the SS case was
            /// a whiteboard slide.  This does not seem to be true anymore.  For CP3 we use explicit DeckTypeAssociation.
            if ((rtu.DeckType == (Int32)DeckTypeEnum.Presentation) ||
                ((rtu.DeckType == (Int32)DeckTypeEnum.StudentSubmission) && (rtu.DeckTypeAssociation != (Int32)DeckTypeEnum.Whiteboard)) ||
                ((rtu.DeckType == (Int32)DeckTypeEnum.QuickPoll) && (rtu.DeckTypeAssociation != (Int32)DeckTypeEnum.Whiteboard)))
            {
                Slide tmpSlide = slideDeck.GetSlide(internalSlideIndex);

                if ((tmpSlide == null) || (tmpSlide.Image == null))
                {
                    ThreadPool.QueueUserWorkItem(new WaitCallback(GetWebImageThread2), rtu);
                }
                else
                {
                    DisplaySlideIndex(internalSlideIndex);
                }
            }
            else             //No background image -- this is a whiteboard slide
            {
                DisplaySlideIndex(internalSlideIndex);
            }

            //if slide size is not up to date, fix that.
            //Console.WriteLine("WebviewerReceiveRTUpdate new slide size=" + rtu.SlideSize.ToString() +
            //	" current slide size=" + currentSlideSize.ToString());
            if (currentSlideSize != rtu.SlideSize)
            {
                currentSlideSize                   = rtu.SlideSize;
                this.screenConfiguration           = new ScreenConfiguration();
                this.screenConfiguration.SlideSize = rtu.SlideSize;
                AcceptScreenConfiguration();
            }

            //Update background color if necessary.
            if (currentBackgroundColor != rtu.BackgroundColor)
            {
                mySlideView.LayerPanel.BackColor = rtu.BackgroundColor;
                currentBackgroundColor           = rtu.BackgroundColor;
            }

            //Update scroll position
            workQueue.SetScrollPos(internalSlideIndex, (float)rtu.ScrollPosition, (float)rtu.ScrollExtent);
            if (workQueue.StartScrolling())
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(ScrollWorker));
            }
        }
 public GameConfigurationManager()
 {
     bulletConfig = new BulletConfiguration();
     gameConfig = new GameConfiguration();
     shipConfig = new ShipConfiguration();
     mapConfig = new MapConfiguration();
     screenConfig = new ScreenConfiguration();
     leaderboardConfig = new LeaderboardConfiguration();
     healthPackConfig = new HealthPackConfiguration();
     abilityConfig = new AbilityConfiguration();
     shipMovementControllerConfig = new ShipMovementControllerConfiguration();
 }
示例#7
0
 public GameConfigurationManager()
 {
     bulletConfig                 = new BulletConfiguration();
     gameConfig                   = new GameConfiguration();
     shipConfig                   = new ShipConfiguration();
     mapConfig                    = new MapConfiguration();
     screenConfig                 = new ScreenConfiguration();
     leaderboardConfig            = new LeaderboardConfiguration();
     healthPackConfig             = new HealthPackConfiguration();
     abilityConfig                = new AbilityConfiguration();
     shipMovementControllerConfig = new ShipMovementControllerConfiguration();
 }
示例#8
0
        /// <summary>
        /// Initializes the screen
        /// </summary>
        /// <param name="memoryBitMapAllocation">The memory allocation.</param>
        public Screen(int memoryBitMapAllocation = DefaultMemoryAllocationBitmap)
        {
            if (_isInitialized)
            {
                return;
            }

            MemoryAllocationBitmap = memoryBitMapAllocation;
            // Not used in Stick versions, AXP is doing this
            BackLightPin = -1;

#if M5STICKC
            _power = M5StickC.Power;
#else
            _power = M5StickCPlus.Power;
#endif

            var displaySpiConfig = new SpiConfiguration(
                1,
                ChipSelect,
                DataCommand,
                Reset,
                BackLightPin);

#if M5STICKC
            var screenConfig = new ScreenConfiguration(
                26,
                1,
                80,
                160);
#else
            var screenConfig = new ScreenConfiguration(
                52,
                40,
                135,
                240);
#endif

            _ = DisplayControl.Initialize(
                displaySpiConfig,
                screenConfig,
                (uint)MemoryAllocationBitmap);

            // Enable the screen
            Enabled = true;

            // For M5Stick, values from 2.6 to 3V are working fine
            LuminosityPercentage = 100;
            _power.EnableLDO3(true);
            _isInitialized = true;
        }
示例#9
0
        public Application(RenderWindow window, ScreenConfiguration configuration)
        {
            this.window = window;

            this.Configuration = configuration;

            ConfigureKernel();

            applicationManager = kernel.Get <IApplicationManager>();

            var homeApplication = kernel.Get <HomeApplicationInstance>();

            applicationManager.SetHomeApplication(homeApplication);
        }
示例#10
0
    /// <summary>
    /// search for the screen configuration
    /// </summary>
    void searchforconfigurationLastAdvanced()
    {
        string filepath = Application.persistentDataPath + "/previoussettings.dat";

        json = "";
        if (File.Exists(filepath))
        {
            json = File.ReadAllText(filepath);
        }
        if (json != "")
        {
            ScreenConfiguration c = JsonUtility.FromJson <ScreenConfiguration>(json);

            screencofiguration = c;
        }
    }
示例#11
0
文件: Program.cs 项目: lassevk/Decked
        private static void Execute(string[] args)
        {
            var options = OptParser.Parse <CommandLineOptions>(args);

            assume(options != null);

            var logger = new ConsoleLogger(options);

            var container = new Container(Rules.Default.WithAutoConcreteTypeResolution());

            container.RegisterInstance <ILogger>(logger);

            var problems = options.GetProblems().ToList();

            if (problems.Any())
            {
                foreach (var problem in problems)
                {
                    System.Console.Error.WriteLine(problem);
                }
                Environment.Exit(1);
            }

            assume(options.MainScreenFilename != null);
            System.Console.WriteLine($"loading screen {Path.GetFullPath(options.MainScreenFilename)}");

            var initialScreenConfiguration = ScreenConfiguration.Load(options.MainScreenFilename);
            var pathResolver = new PathResolver(Path.GetDirectoryName(Path.GetFullPath(options.MainScreenFilename)));

            container.RegisterInstance <IPathResolver>(pathResolver);

            var deck = new DeckRunner(container, logger, pathResolver);

            container.RegisterInstance <IStreamDeckServices>(deck);

            deck.InitializeScreen(initialScreenConfiguration);

            //AppDomain.CurrentDomain.AssemblyResolve += delegate(object sender, ResolveEventArgs eventArgs)
            //                                           {
            //                                               System.Console.WriteLine(eventArgs.Name);

            //                                               return null;
            //                                           };

            deck.Run().GetAwaiter().GetResult();
        }
示例#12
0
        public void NoReadContentionValueIsAppliedWhileFirstDisplayLineIsReached()
        {
            // --- Arrange
            const int EXPECTED_CONTENTION = 0;
            var       screenConfig        = new ScreenConfiguration(SpectrumModels.ZxSpectrum48Pal.Screen);
            var       pixels   = new TestPixelRenderer(SpectrumModels.ZxSpectrum48Pal.Screen);
            var       spectrum = new SpectrumAdvancedTestMachine(pixels);

            var tactToReach = screenConfig.FirstDisplayLine * screenConfig.ScreenLineTime;

            InitMachineReadWithNops(tactToReach, spectrum);

            // --- Act
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.UntilHalt));

            // --- Assert
            spectrum.Cpu.Tacts.ShouldBe(EXPECTED_CONTENTION + tactToReach + 4); // +4 for HALT
        }
示例#13
0
        public void NoInCContentionValueOnPort0XffIsAppliedWhenLeftDisplayEdgeIsReached(int deviation, int expected)
        {
            // --- Arrange
            var screenConfig = new ScreenConfiguration(SpectrumModels.ZxSpectrum48Pal.Screen);
            var pixels       = new TestPixelRenderer(SpectrumModels.ZxSpectrum48Pal.Screen);
            var spectrum     = new SpectrumAdvancedTestMachine(pixels);

            var tactToReach = screenConfig.FirstDisplayLine * screenConfig.ScreenLineTime
                              + screenConfig.FirstPixelTactInLine - 12 + deviation;

            InitMachineInCWithNops(tactToReach, 0xff, spectrum);

            // --- Act
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.UntilHalt));

            // --- Assert
            spectrum.Cpu.Tacts.ShouldBe(expected + tactToReach + 4); // +4 for HALT
        }
示例#14
0
        public void StepOverWorksWithCallPFalse()
        {
            // --- Arrange
            var pars          = new ScreenConfiguration();
            var pixels        = new TestPixelRenderer(pars);
            var spectrum      = new SpectrumAdvancedTestMachine(pars, pixels);
            var debugProvider = new TestDebugInfoProvider();

            spectrum.SetDebugInfoProvider(debugProvider);

            // --- We render the screen while the interrupt is disabled
            spectrum.InitCode(new byte[]
            {
                0x3E, 0x90,       // LD A,$90
                0xB7,             // OR A
                0xF4, 0x09, 0x80, // CALL P,$8009
                0x47,             // LD B,A
                0x4F,             // LD C,A
                0x76,             // HALT
                0x3E, 0x20,       // LD a,$20
                0x57,             // LD D,A
                0xC9              // RET
            });
            var regs = spectrum.Cpu.Registers;

            // --- Act
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));
            var pc1 = regs.PC;

            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));
            var pc2 = regs.PC;

            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));

            // --- Assert
            regs.A.ShouldBe((byte)0x90);
            regs.B.ShouldBe((byte)0x90);
            regs.C.ShouldBe((byte)0x00);
            regs.D.ShouldBe((byte)0x00);
            pc1.ShouldBe((ushort)0x8003);
            pc2.ShouldBe((ushort)0x8006);
            regs.PC.ShouldBe((ushort)0x8007);
        }
        /// <summary>
        /// Initialize the Spectrum virtual machine dependencies when the user control is loaded
        /// </summary>
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            Vm = DataContext as MachineViewModel;
            if (Vm == null)
            {
                return;
            }

            // --- Prepare the screen
            _displayPars = Vm.ScreenConfiguration;
            lock (_dispatchTimer)
            {
                _bitmap = new WriteableBitmap(
                    _displayPars.ScreenWidth,
                    _displayPars.ScreenLines,
                    96,
                    96,
                    PixelFormats.Bgr32,
                    null);
            }
            Display.Source  = _bitmap;
            Display.Width   = _displayPars.ScreenWidth;
            Display.Height  = _displayPars.ScreenLines;
            Display.Stretch = Stretch.Fill;

            // --- When the control is reloaded, resume playing the sound
            if (_isReloaded && Vm.VmState == VmState.Running)
            {
                Vm.EarBitFrameProvider.PlaySound();
            }

            // --- Register messages this control listens to
            Messenger.Default.Register <VmStateChangedMessage>(this, OnVmStateChanged);
            Messenger.Default.Register <VmDisplayModeChangedMessage>(this, OnDisplayModeChanged);
            Messenger.Default.Register <DelegatingScreenFrameProvider.VmDisplayFrameReadyMessage>(this, OnDisplayFrame);

            // --- Now, the control is fully loaded and ready to work
            Messenger.Default.Send(new SpectrumControlLoadedMessage());

            // --- Apply the current screen size
            // ReSharper disable once PossibleNullReferenceException
            OnDisplayModeChanged(new VmDisplayModeChangedMessage(Vm.DisplayMode));
        }
示例#16
0
        /// <summary>
        /// Initialize the Spectrum virtual machine dependencies when the user control is loaded
        /// </summary>
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            Vm = DataContext as EmulatorViewModel;
            if (Vm == null)
            {
                return;
            }

            // --- Prepare the screen
            _colors      = Spectrum48ScreenDevice.SpectrumColors.ToArray();
            _displayPars = Vm.Machine.ScreenConfiguration;
            _bitmap      = new WriteableBitmap(
                _displayPars.ScreenWidth,
                _displayPars.ScreenLines,
                96,
                96,
                PixelFormats.Bgr32,
                null);
            Display.Source  = _bitmap;
            Display.Width   = _displayPars.ScreenWidth;
            Display.Height  = _displayPars.ScreenLines;
            Display.Stretch = Stretch.Fill;

            // --- When the control is reloaded, resume playing the sound
            if (_isReloaded && Vm.MachineState == VmState.Running)
            {
                Vm.Machine.BeeperProvider?.PlaySound();
                Vm.Machine.SoundProvider?.PlaySound();
            }

            // --- Keyboard event handling
            KeyboardScanner.BindShiftChange();

            // --- Register messages this control listens to
            Vm.VmStateChanged           += OnVmStateChanged;
            Vm.KeyScanning              += MachineOnKeyScanning;
            Vm.CpuFrameCompleted        += MachineOnCpuFrameCompleted;
            Vm.RenderFrameCompleted     += MachineOnRenderFrameCompleted;
            Vm.LeftSaveMode             += MachineOnLeftSaveMode;
            Vm.ShadowScreenModeChanged  += OnShadowScreenModeChanged;
            Vm.UlaIndicationModeChanged += OnUlaIndicationModeChanged;
            Vm.MachineInstanceChanged   += OnMachineInstanceChanged;
        }
        public void EnabledInterruptIsRaised()
        {
            // --- Arrange
            var pars     = new ScreenConfiguration();
            var pixels   = new TestPixelRenderer(pars);
            var spectrum = new SpectrumAdvancedTestMachine(pars, pixels);

            // --- We render the screen while the interrupt is enabled
            spectrum.InitCode(new byte[]
            {
                0xED, 0x56,       // IM 1
                0xFB,             // EI
                0x3E, 0x05,       // LD A,$05
                0xD3, 0xFE,       // OUT ($FE),A
                0x01, 0x00, 0x0A, // LD BC,$0A00
                0x0B,             // DECLB: DEC BC
                0x78,             // LD A,B
                0xB1,             // OR C
                0x20, 0xFB,       // JR NZ,DECLB
                0x76              // HALT
            });
            var startTime = spectrum.Clock.GetCounter();

            // --- Act
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.UntilHalt));

            // === Display some extra information about the duration of the frame execution
            var duration = (spectrum.Clock.GetCounter() - startTime)
                           / (double)spectrum.Clock.GetFrequency();

            Console.WriteLine("Frame execution time: {0} second", duration);

            // --- Assert
            var regs = spectrum.Cpu.Registers;

            regs.PC.ShouldBe((ushort)0x800F);

            // --- The instructions above take 66599 tacts while reaching the HALT operation
            // --- However, an interrupt is generated, and because of IM 1, the RST 38 is
            // --- invoked. It checks to keyboard status in 1034 tacts.
            // --- When HALT is reached, the CPU tact count is 67633.
            spectrum.Cpu.Tacts.ShouldBeGreaterThanOrEqualTo(67553L);
        }
        public void SettingBorderValueDoesNotChangeInvisibleScreenArea()
        {
            // --- Arrange
            var pars     = new ScreenConfiguration();
            var pixels   = new TestPixelRenderer(pars);
            var spectrum = new SpectrumAdvancedTestMachine(pars, pixels);

            // --- Because we execute only 451 CPU tacts, rendering does not
            // --- reach the visible border area
            spectrum.InitCode(new byte[]
            {
                0xF3,             // DI
                0x3E, 0x05,       // LD A,$05
                0xD3, 0xFE,       // OUT ($FE),A
                0x01, 0x10, 0x00, // LD BC,$0010
                0x0B,             // DECLB: DEC BC
                0x78,             // LD A,B
                0xB1,             // OR C
                0x20, 0xFB,       // JR NZ,DECLB
                0xFB,             // EI
                0x76              // HALT
            });
            ((IScreenDeviceTestSupport)spectrum.ScreenDevice).FillScreenBuffer(0xFF);

            // --- Act
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.UntilHalt));

            // --- Assert
            var regs = spectrum.Cpu.Registers;

            regs.PC.ShouldBe((ushort)0x800E);
            spectrum.Cpu.Tacts.ShouldBe(451L);
            pixels.IsFrameReady.ShouldBeFalse();

            pixels.SetPixelMemory(spectrum.ScreenDevice.GetPixelBuffer());
            for (var row = 0; row < spectrum.ScreenDevice.ScreenConfiguration.ScreenLines; row++)
            {
                for (var column = 0; column < spectrum.ScreenDevice.ScreenConfiguration.ScreenWidth; column++)
                {
                    pixels[row, column].ShouldBe((byte)0xFF);
                }
            }
        }
        /// <summary>
        /// Initialize the Spectrum virtual machine dependencies when the user control is loaded
        /// </summary>
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            Vm = DataContext as MachineViewModel;
            if (Vm == null)
            {
                return;
            }

            Vm.VmStateChanged     += OnVmStateChanged;
            Vm.DisplayModeChanged += OnDisplayModeChanged;

            // --- Prepare the screen
            _displayPars = new ScreenConfiguration(Vm.ScreenConfiguration);
            _bitmap      = new WriteableBitmap(
                _displayPars.ScreenWidth,
                _displayPars.ScreenLines,
                96,
                96,
                PixelFormats.Bgr32,
                null);
            Display.Source  = _bitmap;
            Display.Width   = _displayPars.ScreenWidth;
            Display.Height  = _displayPars.ScreenLines;
            Display.Stretch = Stretch.Fill;

            // --- When the control is reloaded, resume playing the sound
            if (_isReloaded && Vm.VmState == VmState.Running)
            {
                Vm.SpectrumVm.BeeperProvider.PlaySound();
            }

            // --- Register messages this control listens to
            Vm.VmScreenRefreshed += VmOnVmScreenRefreshed;

            // --- Now, the control is fully loaded and ready to work
            Vm.FastTapeMode = false;
            Vm.StartVmCommand.Execute(null);

            // --- Apply the current screen size
            // ReSharper disable once PossibleNullReferenceException
            OnDisplayModeChanged(this, EventArgs.Empty);
        }
示例#20
0
        public void StepOverWorksWithMultipleSteps()
        {
            // --- Arrange
            var pars          = new ScreenConfiguration();
            var pixels        = new TestPixelRenderer(pars);
            var spectrum      = new SpectrumAdvancedTestMachine(pars, pixels);
            var debugProvider = new TestDebugInfoProvider();

            spectrum.SetDebugInfoProvider(debugProvider);

            // --- We render the screen while the interrupt is disabled
            spectrum.InitCode(new byte[]
            {
                0x3E, 0x10,       // LD A,$10
                0x87,             // ADD A,A
                0x47,             // LD B,A
                0x4F,             // LD C,A
            });
            var regs = spectrum.Cpu.Registers;

            // --- Act
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));
            var pc1 = regs.PC;

            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));
            var pc2 = regs.PC;

            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));
            var pc3 = regs.PC;

            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));

            // --- Assert
            regs.A.ShouldBe((byte)0x20);
            regs.B.ShouldBe((byte)0x20);
            regs.C.ShouldBe((byte)0x20);
            pc1.ShouldBe((ushort)0x8002);
            pc2.ShouldBe((ushort)0x8003);
            pc3.ShouldBe((ushort)0x8004);
            regs.PC.ShouldBe((ushort)0x8005);
        }
        public void DisabledInterruptIsNotRaised()
        {
            // --- Arrange
            var pars     = new ScreenConfiguration();
            var pixels   = new TestPixelRenderer(pars);
            var spectrum = new SpectrumAdvancedTestMachine(pars, pixels);

            // --- We render the screen while the interrupt is disabled
            spectrum.InitCode(new byte[]
            {
                0xED, 0x56,       // IM 1
                0xF3,             // DI
                0x3E, 0x05,       // LD A,$05
                0xD3, 0xFE,       // OUT ($FE),A
                0x01, 0x00, 0x0A, // LD BC,$0A00
                0x0B,             // DECLB: DEC BC
                0x78,             // LD A,B
                0xB1,             // OR C
                0x20, 0xFB,       // JR NZ,DECLB
                0x76              // HALT
            });
            var startTime = spectrum.Clock.GetCounter();

            // --- Act
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.UntilHalt));

            // === Display some extra information about the duration of the frame execution
            var duration = (spectrum.Clock.GetCounter() - startTime)
                           / (double)spectrum.Clock.GetFrequency();

            Console.WriteLine("Frame execution time: {0} second", duration);

            // --- Assert
            var regs = spectrum.Cpu.Registers;

            regs.PC.ShouldBe((ushort)0x800F);

            spectrum.Cpu.Tacts.ShouldBeGreaterThanOrEqualTo(66599L);
        }
示例#22
0
        public void StepOverWorksWithRst()
        {
            // --- Arrange
            var pars          = new ScreenConfiguration();
            var pixels        = new TestPixelRenderer(pars);
            var spectrum      = new SpectrumAdvancedTestMachine(pars, pixels);
            var debugProvider = new TestDebugInfoProvider();

            spectrum.SetDebugInfoProvider(debugProvider);

            // --- We render the screen while the interrupt is disabled
            spectrum.InitCode(new byte[]
            {
                0xF3,       // DI
                0x16, 0x06, // LD D,6
                0xFF,       // RST $38
                0x7A,       // LD A,D
                0x76        // HALT
            });
            var regs = spectrum.Cpu.Registers;

            // --- Act
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));
            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));
            var pc1 = regs.PC;

            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));
            var pc2 = regs.PC;

            spectrum.ExecuteCycle(CancellationToken.None, new ExecuteCycleOptions(EmulationMode.Debugger, DebugStepMode.StepOver));

            // --- Assert
            regs.D.ShouldBe((byte)0x06);
            pc1.ShouldBe((ushort)0x8003);
            pc2.ShouldBe((ushort)0x8004);
            regs.PC.ShouldBe((ushort)0x8005);
        }
        /// <summary>
        /// Initialize the Spectrum virtual machine dependencies when the user control is loaded
        /// </summary>
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            Vm = DataContext as MachineViewModel;
            if (Vm == null)
            {
                return;
            }

            Vm.VmStateChanged += OnVmStateChanged;

            // --- Prepare the screen
            _displayPars = new ScreenConfiguration(Vm.ScreenConfiguration);
            lock (_dispatchTimer)
            {
                _bitmap = new WriteableBitmap(
                    _displayPars.ScreenWidth,
                    _displayPars.ScreenLines,
                    96,
                    96,
                    PixelFormats.Bgr32,
                    null);
            }
            Display.Source  = _bitmap;
            Display.Width   = _displayPars.ScreenWidth;
            Display.Height  = _displayPars.ScreenLines;
            Display.Stretch = Stretch.Fill;

            // --- When the control is reloaded, resume playing the sound
            if (_isReloaded && Vm.VmState == VmState.Running)
            {
                Vm.SpectrumVm.BeeperProvider.PlaySound();
            }
            else
            {
                Vm.VmScreenRefreshed += OnVmScreenRefreshed;
            }
        }
示例#24
0
        /// <summary>
        /// Initializes a class instance using a collection of devices
        /// </summary>
        public SpectrumEngine(DeviceInfoCollection deviceData)
        {
            DeviceData = deviceData ?? throw new ArgumentNullException(nameof(deviceData));

            // --- Check for Spectrum Next
            var nextInfo = GetDeviceInfo <INextFeatureSetDevice>();

            NextDevice = nextInfo?.Device;

            // --- Prepare the memory device
            var memoryInfo = GetDeviceInfo <IMemoryDevice>();

            MemoryDevice        = memoryInfo?.Device ?? new Spectrum48MemoryDevice();
            MemoryConfiguration = (IMemoryConfiguration)memoryInfo?.ConfigurationData;

            // --- Prepare the port device
            var portInfo = GetDeviceInfo <IPortDevice>();

            PortDevice = portInfo?.Device ?? new Spectrum48PortDevice();

            // --- Init the CPU
            var cpuConfig = GetDeviceConfiguration <IZ80Cpu, ICpuConfiguration>();
            var mult      = 1;

            if (cpuConfig != null)
            {
                BaseClockFrequency = cpuConfig.BaseClockFrequency;
                mult = cpuConfig.ClockMultiplier;
                if (mult < 1)
                {
                    mult = 1;
                }
                else if (mult >= 2 && mult <= 3)
                {
                    mult = 2;
                }
                else if (mult >= 4 && mult <= 7)
                {
                    mult = 4;
                }
                else if (mult > 8)
                {
                    mult = 8;
                }
            }
            ClockMultiplier = mult;
            Cpu             = new Z80Cpu(MemoryDevice,
                                         PortDevice,
                                         cpuConfig?.SupportsNextOperations ?? false,
                                         NextDevice)
            {
                UseGateArrayContention = MemoryConfiguration.ContentionType == MemoryContentionType.GateArray
            };

            // --- Init the ROM
            var romInfo = GetDeviceInfo <IRomDevice>();

            RomProvider      = (IRomProvider)romInfo.Provider;
            RomDevice        = romInfo.Device ?? new SpectrumRomDevice();
            RomConfiguration = (IRomConfiguration)romInfo.ConfigurationData;

            // --- Init the clock
            var clockInfo = GetDeviceInfo <IClockDevice>();

            Clock = (IClockProvider)clockInfo.Provider
                    ?? throw new InvalidOperationException("The virtual machine needs a clock provider!");

            // --- Init the screen device
            var screenInfo    = GetDeviceInfo <IScreenDevice>();
            var pixelRenderer = (IScreenFrameProvider)screenInfo.Provider;

            ScreenConfiguration = new ScreenConfiguration((IScreenConfiguration)screenInfo.ConfigurationData);
            ScreenDevice        = screenInfo.Device ?? new Spectrum48ScreenDevice();

            // --- Init the beeper device
            var beeperInfo = GetDeviceInfo <IBeeperDevice>();

            AudioConfiguration = (IAudioConfiguration)beeperInfo?.ConfigurationData;
            BeeperProvider     = (IBeeperProvider)beeperInfo?.Provider;
            BeeperDevice       = beeperInfo?.Device ?? new BeeperDevice();

            // --- Init the keyboard device
            var keyboardInfo = GetDeviceInfo <IKeyboardDevice>();

            KeyboardProvider = (IKeyboardProvider)keyboardInfo?.Provider;
            KeyboardDevice   = keyboardInfo?.Device ?? new KeyboardDevice();

            // --- Init the interrupt device
            InterruptDevice = new InterruptDevice(InterruptTact);

            // --- Init the tape device
            var tapeInfo = GetDeviceInfo <ITapeDevice>();

            TapeProvider = (ITapeProvider)tapeInfo?.Provider;
            TapeDevice   = tapeInfo?.Device
                           ?? new TapeDevice(TapeProvider);

            // === Init optional devices
            // --- Init the sound device
            var soundInfo = GetDeviceInfo <ISoundDevice>();

            SoundConfiguration = (IAudioConfiguration)soundInfo?.ConfigurationData;
            SoundProvider      = (ISoundProvider)soundInfo?.Provider;
            SoundDevice        = soundInfo == null
                ? null
                : soundInfo.Device ?? new SoundDevice();

            // --- Init the DivIDE device
            var divIdeInfo = GetDeviceInfo <IDivIdeDevice>();

            DivIdeDevice = divIdeInfo?.Device;

            // --- Carry out frame calculations
            ResetUlaTact();
            _frameTacts             = ScreenConfiguration.ScreenRenderingFrameTactCount;
            PhysicalFrameClockCount = Clock.GetFrequency() / (double)BaseClockFrequency * _frameTacts;
            FrameCount              = 0;
            Overflow                = 0;
            _frameCompleted         = true;
            _lastBreakpoint         = null;
            RunsInMaskableInterrupt = false;

            // --- Attach providers
            AttachProvider(RomProvider);
            AttachProvider(Clock);
            AttachProvider(pixelRenderer);
            AttachProvider(BeeperProvider);
            AttachProvider(KeyboardProvider);
            AttachProvider(TapeProvider);
            AttachProvider(DebugInfoProvider);

            // --- Attach optional providers
            if (SoundProvider != null)
            {
                AttachProvider(SoundProvider);
            }

            // --- Collect Spectrum devices
            _spectrumDevices.Add(RomDevice);
            _spectrumDevices.Add(MemoryDevice);
            _spectrumDevices.Add(PortDevice);
            _spectrumDevices.Add(ScreenDevice);
            _spectrumDevices.Add(BeeperDevice);
            _spectrumDevices.Add(KeyboardDevice);
            _spectrumDevices.Add(InterruptDevice);
            _spectrumDevices.Add(TapeDevice);

            // --- Collect optional devices
            if (SoundDevice != null)
            {
                _spectrumDevices.Add(SoundDevice);
            }
            if (NextDevice != null)
            {
                _spectrumDevices.Add(NextDevice);
            }
            if (DivIdeDevice != null)
            {
                _spectrumDevices.Add(DivIdeDevice);
            }

            // --- Now, prepare devices to find each other
            foreach (var device in _spectrumDevices)
            {
                device.OnAttachedToVm(this);
            }

            // --- Prepare bound devices
            _frameBoundDevices = _spectrumDevices
                                 .OfType <IFrameBoundDevice>()
                                 .ToList();
            _cpuBoundDevices = _spectrumDevices
                               .OfType <ICpuOperationBoundDevice>()
                               .ToList();

            DebugInfoProvider = new SpectrumDebugInfoProvider();

            // --- Init the ROM
            InitRom(RomDevice, RomConfiguration);
        }
        public static Blueprint Generate(ScreenConfiguration configuration)
        {
            var width  = configuration.Width ?? 18;
            var height = configuration.Height ?? 18;

            const int cycle         = 2;
            const int parallelCycle = 32;

            var entities          = new List <Entity>();
            var pixels            = new Entity[height, width];
            var columnControllers = new Controller[width];
            var rowControllers    = new Controller[height];

            // Pixels
            for (var row = 0; row < height; row++)
            {
                for (var column = 0; column < width; column++)
                {
                    var relativeRow    = row % 18;
                    var relativeColumn = column % 18;

                    // Don't place lights that intersect the substations
                    if (relativeRow > 15 && relativeColumn > 15)
                    {
                        continue;
                    }

                    var pixel = new Entity
                    {
                        Name     = ItemNames.Lamp,
                        Position = new Position
                        {
                            X = column + 2,
                            Y = row + 2
                        },
                        Control_behavior = new ControlBehavior
                        {
                            Circuit_condition = new CircuitCondition
                            {
                                First_signal = SignalID.Create(ScreenUtil.PixelSignals[row]),
                                Comparator   = Comparators.GreaterThan,
                                Constant     = 0
                            },
                            Use_colors = true
                        }
                    };
                    pixels[row, column] = pixel;
                    entities.Add(pixel);
                }
            }

            // Column controllers
            for (var column = 0; column < width; column++)
            {
                var controllerX = column + 2;
                var controllerY = height + 4;

                var memory = new Entity
                {
                    Name     = ItemNames.DeciderCombinator,
                    Position = new Position
                    {
                        X = controllerX,
                        Y = controllerY + 0.5
                    },
                    Direction        = Direction.Up,
                    Control_behavior = new ControlBehavior
                    {
                        Decider_conditions = new DeciderConditions
                        {
                            First_signal          = SignalID.Create(VirtualSignalNames.Each),
                            Constant              = 0,
                            Comparator            = Comparators.GreaterThan,
                            Output_signal         = SignalID.Create(VirtualSignalNames.Each),
                            Copy_count_from_input = false
                        }
                    }
                };
                entities.Add(memory);

                var writer = new Entity
                {
                    Name     = ItemNames.DeciderCombinator,
                    Position = new Position
                    {
                        X = controllerX,
                        Y = controllerY + 2.5
                    },
                    Direction        = Direction.Up,
                    Control_behavior = new ControlBehavior
                    {
                        Decider_conditions = new DeciderConditions
                        {
                            First_signal          = SignalID.Create(VirtualSignalNames.Check),
                            Constant              = 0,
                            Comparator            = Comparators.IsEqual,
                            Output_signal         = SignalID.Create(VirtualSignalNames.Everything),
                            Copy_count_from_input = true
                        }
                    }
                };
                entities.Add(writer);

                var addressMatcher = new Entity
                {
                    Name     = ItemNames.DeciderCombinator,
                    Position = new Position
                    {
                        X = controllerX,
                        Y = controllerY + 4.5
                    },
                    Direction        = Direction.Up,
                    Control_behavior = new ControlBehavior
                    {
                        Decider_conditions = new DeciderConditions
                        {
                            First_signal          = SignalID.Create(VirtualSignalNames.Info),
                            Constant              = column + 1,
                            Comparator            = Comparators.IsNotEqual,
                            Output_signal         = SignalID.Create(VirtualSignalNames.Check),
                            Copy_count_from_input = false
                        }
                    }
                };
                entities.Add(addressMatcher);

                var cyclicWriter = new Entity
                {
                    Name     = ItemNames.DeciderCombinator,
                    Position = new Position
                    {
                        X = controllerX,
                        Y = controllerY + 6.5
                    },
                    Direction        = Direction.Up,
                    Control_behavior = new ControlBehavior
                    {
                        Decider_conditions = new DeciderConditions
                        {
                            First_signal          = SignalID.Create(VirtualSignalNames.Check),
                            Constant              = 0,
                            Comparator            = Comparators.IsEqual,
                            Output_signal         = SignalID.Create(VirtualSignalNames.Everything),
                            Copy_count_from_input = true
                        }
                    }
                };
                entities.Add(cyclicWriter);

                var cyclicMatcher = new Entity
                {
                    Name     = ItemNames.DeciderCombinator,
                    Position = new Position
                    {
                        X = controllerX,
                        Y = controllerY + 8.5
                    },
                    Direction        = Direction.Up,
                    Control_behavior = new ControlBehavior
                    {
                        Decider_conditions = new DeciderConditions
                        {
                            First_signal          = SignalID.Create(VirtualSignalNames.Info),
                            Constant              = column % cycle + 1,
                            Comparator            = Comparators.IsNotEqual,
                            Output_signal         = SignalID.Create(VirtualSignalNames.Check),
                            Copy_count_from_input = false
                        }
                    }
                };
                entities.Add(cyclicMatcher);

                var parallelWriter = new Entity
                {
                    Name     = ItemNames.DeciderCombinator,
                    Position = new Position
                    {
                        X = controllerX,
                        Y = controllerY + 14.5
                    },
                    Direction        = Direction.Up,
                    Control_behavior = new ControlBehavior
                    {
                        Decider_conditions = new DeciderConditions
                        {
                            First_signal          = SignalID.Create(VirtualSignalNames.Check),
                            Constant              = 0,
                            Comparator            = Comparators.IsEqual,
                            Output_signal         = SignalID.Create(VirtualSignalNames.Everything),
                            Copy_count_from_input = true
                        }
                    }
                };
                entities.Add(parallelWriter);

                var parallelAddressRangeLow = new Entity
                {
                    Name     = ItemNames.DeciderCombinator,
                    Position = new Position
                    {
                        X = controllerX,
                        Y = controllerY + 10.5
                    },
                    Direction        = Direction.Up,
                    Control_behavior = new ControlBehavior
                    {
                        Decider_conditions = new DeciderConditions
                        {
                            First_signal          = SignalID.Create(VirtualSignalNames.Info),
                            Constant              = column + 1,
                            Comparator            = Comparators.LessThan,
                            Output_signal         = SignalID.Create(VirtualSignalNames.Check),
                            Copy_count_from_input = false
                        }
                    }
                };
                entities.Add(parallelAddressRangeLow);

                var parallelAddressRangeHigh = new Entity
                {
                    Name     = ItemNames.DeciderCombinator,
                    Position = new Position
                    {
                        X = controllerX,
                        Y = controllerY + 12.5
                    },
                    Direction        = Direction.Up,
                    Control_behavior = new ControlBehavior
                    {
                        Decider_conditions = new DeciderConditions
                        {
                            First_signal          = SignalID.Create(VirtualSignalNames.Info),
                            Constant              = column + parallelCycle + 1,
                            Comparator            = Comparators.GreaterThanOrEqualTo,
                            Output_signal         = SignalID.Create(VirtualSignalNames.Check),
                            Copy_count_from_input = false
                        }
                    }
                };
                entities.Add(parallelAddressRangeHigh);

                var isOdd = column % 2 == 1;

                var parallelHorizontalLink1 = new Entity
                {
                    Name     = column % 18 == 16 ? ItemNames.Substation : ItemNames.BigElectricPole,
                    Position = new Position
                    {
                        X = controllerX + 0.5,
                        Y = controllerY + 16.5 + (isOdd ? 2 : 0)
                    }
                };
                entities.Add(parallelHorizontalLink1);

                var parallelHorizontalLink2 = new Entity
                {
                    Name     = ItemNames.BigElectricPole,
                    Position = new Position
                    {
                        X = controllerX + 0.5,
                        Y = controllerY + 20.5 + (isOdd ? 2 : 0)
                    }
                };
                entities.Add(parallelHorizontalLink2);

                var videoEnabler = new Entity
                {
                    Name     = ItemNames.DeciderCombinator,
                    Position = new Position
                    {
                        X = controllerX,
                        Y = controllerY + 24.5
                    },
                    Direction        = Direction.Up,
                    Control_behavior = new ControlBehavior
                    {
                        Decider_conditions = new DeciderConditions
                        {
                            First_signal          = SignalID.Create(VirtualSignalNames.Check),
                            Constant              = 0,
                            Comparator            = Comparators.IsEqual,
                            Output_signal         = SignalID.Create(VirtualSignalNames.Everything),
                            Copy_count_from_input = true
                        }
                    }
                };
                entities.Add(videoEnabler);

                var videoReferenceSignalSubtractor = new Entity
                {
                    Name     = ItemNames.ArithmeticCombinator,
                    Position = new Position
                    {
                        X = controllerX,
                        Y = controllerY + 26.5
                    },
                    Direction        = Direction.Up,
                    Control_behavior = new ControlBehavior
                    {
                        Arithmetic_conditions = new ArithmeticConditions
                        {
                            First_signal    = SignalID.Create(VirtualSignalNames.Each),
                            Second_constant = -3,
                            Operation       = ArithmeticOperations.Multiplication,
                            Output_signal   = SignalID.Create(VirtualSignalNames.Each)
                        }
                    }
                };
                entities.Add(videoReferenceSignalSubtractor);

                var videoValueSpreader = new Entity
                {
                    Name     = ItemNames.ArithmeticCombinator,
                    Position = new Position
                    {
                        X = controllerX,
                        Y = controllerY + 28.5
                    },
                    Direction        = Direction.Up,
                    Control_behavior = new ControlBehavior
                    {
                        Arithmetic_conditions = new ArithmeticConditions
                        {
                            First_signal    = SignalID.Create(VirtualSignalNames.Each),
                            Second_constant = 2,
                            Operation       = ArithmeticOperations.Multiplication,
                            Output_signal   = SignalID.Create(VirtualSignalNames.Each)
                        }
                    }
                };
                entities.Add(videoValueSpreader);

                var videoBitIsolator = new Entity
                {
                    Name     = ItemNames.ArithmeticCombinator,
                    Position = new Position
                    {
                        X = controllerX,
                        Y = controllerY + 30.5
                    },
                    Direction        = Direction.Up,
                    Control_behavior = new ControlBehavior
                    {
                        Arithmetic_conditions = new ArithmeticConditions
                        {
                            First_signal    = SignalID.Create(VirtualSignalNames.Each),
                            Second_constant = 1,
                            Operation       = ArithmeticOperations.And,
                            Output_signal   = SignalID.Create(VirtualSignalNames.Each)
                        }
                    }
                };
                entities.Add(videoBitIsolator);

                var videoBitShifter = new Entity
                {
                    Name     = ItemNames.ArithmeticCombinator,
                    Position = new Position
                    {
                        X = controllerX,
                        Y = controllerY + 32.5
                    },
                    Direction        = Direction.Up,
                    Control_behavior = new ControlBehavior
                    {
                        Arithmetic_conditions = new ArithmeticConditions
                        {
                            First_signal  = SignalID.Create(VirtualSignalNames.Each),
                            Second_signal = SignalID.CreateLetterOrDigit('W'),
                            Operation     = ArithmeticOperations.RightShift,
                            Output_signal = SignalID.Create(VirtualSignalNames.Each)
                        }
                    }
                };
                entities.Add(videoBitShifter);

                columnControllers[column] = new Controller
                {
                    Memory         = memory,
                    Writer         = writer,
                    AddressMatcher = addressMatcher,
                    Cyclic         = new CyclicInput
                    {
                        Writer  = cyclicWriter,
                        Matcher = cyclicMatcher
                    },
                    Parallel = new ParallelInput
                    {
                        Writer           = parallelWriter,
                        AddressRangeLow  = parallelAddressRangeLow,
                        AddressRangeHigh = parallelAddressRangeHigh,
                        HorizontalLink1  = parallelHorizontalLink1,
                        HorizontalLink2  = parallelHorizontalLink2
                    },
                    Video = new VideoInput
                    {
                        Enabler = videoEnabler,
                        ReferenceSignalSubtractor = videoReferenceSignalSubtractor,
                        ValueSpreader             = videoValueSpreader,
                        BitIsolator = videoBitIsolator,
                        BitShifter  = videoBitShifter
                    }
                };
            }

            // Row controllers
            for (var row = 0; row < height; row++)
            {
                var controllerY = row + 2;

                var memory = new Entity
                {
                    Name     = ItemNames.DeciderCombinator,
                    Position = new Position
                    {
                        X = -1.5,
                        Y = controllerY
                    },
                    Direction        = Direction.Right,
                    Control_behavior = new ControlBehavior
                    {
                        Decider_conditions = new DeciderConditions
                        {
                            First_signal          = SignalID.Create(VirtualSignalNames.Each),
                            Constant              = 0,
                            Comparator            = Comparators.LessThan,
                            Output_signal         = SignalID.Create(VirtualSignalNames.Each),
                            Copy_count_from_input = true
                        }
                    }
                };
                entities.Add(memory);

                var writer = new Entity
                {
                    Name     = ItemNames.DeciderCombinator,
                    Position = new Position
                    {
                        X = -3.5,
                        Y = controllerY
                    },
                    Direction        = Direction.Right,
                    Control_behavior = new ControlBehavior
                    {
                        Decider_conditions = new DeciderConditions
                        {
                            First_signal          = SignalID.Create(VirtualSignalNames.Check),
                            Constant              = 0,
                            Comparator            = Comparators.IsEqual,
                            Output_signal         = SignalID.Create(VirtualSignalNames.Everything),
                            Copy_count_from_input = true
                        }
                    }
                };
                entities.Add(writer);

                var addressMatcher = new Entity
                {
                    Name     = ItemNames.DeciderCombinator,
                    Position = new Position
                    {
                        X = -5.5,
                        Y = controllerY
                    },
                    Direction        = Direction.Right,
                    Control_behavior = new ControlBehavior
                    {
                        Decider_conditions = new DeciderConditions
                        {
                            First_signal          = SignalID.Create(VirtualSignalNames.Info),
                            Constant              = row + 1,
                            Comparator            = Comparators.IsNotEqual,
                            Output_signal         = SignalID.Create(VirtualSignalNames.Check),
                            Copy_count_from_input = false
                        }
                    }
                };
                entities.Add(addressMatcher);

                var cyclicWriter = new Entity
                {
                    Name     = ItemNames.DeciderCombinator,
                    Position = new Position
                    {
                        X = -7.5,
                        Y = controllerY
                    },
                    Direction        = Direction.Right,
                    Control_behavior = new ControlBehavior
                    {
                        Decider_conditions = new DeciderConditions
                        {
                            First_signal          = SignalID.Create(VirtualSignalNames.Check),
                            Constant              = 0,
                            Comparator            = Comparators.IsEqual,
                            Output_signal         = SignalID.Create(VirtualSignalNames.Everything),
                            Copy_count_from_input = true
                        }
                    }
                };
                entities.Add(cyclicWriter);

                var cyclicMatcher = new Entity
                {
                    Name     = ItemNames.DeciderCombinator,
                    Position = new Position
                    {
                        X = -9.5,
                        Y = controllerY
                    },
                    Direction        = Direction.Right,
                    Control_behavior = new ControlBehavior
                    {
                        Decider_conditions = new DeciderConditions
                        {
                            First_signal          = SignalID.Create(VirtualSignalNames.Info),
                            Constant              = row % cycle + 1,
                            Comparator            = Comparators.IsNotEqual,
                            Output_signal         = SignalID.Create(VirtualSignalNames.Check),
                            Copy_count_from_input = false
                        }
                    }
                };
                entities.Add(cyclicMatcher);

                rowControllers[row] = new Controller
                {
                    Memory         = memory,
                    Writer         = writer,
                    AddressMatcher = addressMatcher,
                    Cyclic         = new CyclicInput
                    {
                        Writer  = cyclicWriter,
                        Matcher = cyclicMatcher
                    }
                };
            }

            BlueprintUtil.PopulateEntityNumbers(entities);

            var substationWidth  = (width + 8) / 18 + 1;
            var substationHeight = (height + 8) / 18 + 1;
            var substations      = CreateSubstations(substationWidth, substationHeight, 0, 0, entities.Count + 1, GridConnectivity.Top | GridConnectivity.Vertical);

            entities.AddRange(substations);
            var substations2 = CreateSubstations(substationWidth, 1, 0, height + 38, entities.Count + 1);

            entities.AddRange(substations2);

            // Pixel connections
            for (var row = 0; row < height; row++)
            {
                for (var column = 0; column < width; column++)
                {
                    var pixel = pixels[row, column];
                    if (pixel == null)
                    {
                        continue;
                    }
示例#26
0
        /// <summary>
        /// Initializes a class instance using a collection of devices
        /// </summary>
        public SpectrumEngine(DeviceInfoCollection deviceData, string ulaIssue = "3")
        {
            DeviceData = deviceData ?? throw new ArgumentNullException(nameof(deviceData));
            UlaIssue   = ulaIssue == "3" ? "3" : "2";

            // --- Prepare the memory device
            var memoryInfo = GetDeviceInfo <IMemoryDevice>();

            MemoryDevice        = memoryInfo?.Device ?? new Spectrum48MemoryDevice();
            MemoryConfiguration = (IMemoryConfiguration)memoryInfo?.ConfigurationData;

            // --- Prepare the port device
            var portInfo = GetDeviceInfo <IPortDevice>();

            PortDevice = portInfo?.Device ?? new Spectrum48PortDevice();

            // --- Init the CPU
            var cpuConfig = GetDeviceConfiguration <IZ80Cpu, ICpuConfiguration>();
            var mult      = 1;

            if (cpuConfig != null)
            {
                BaseClockFrequency = cpuConfig.BaseClockFrequency;
                mult = cpuConfig.ClockMultiplier;
                if (mult < 1)
                {
                    mult = 1;
                }
                else if (mult >= 2 && mult <= 3)
                {
                    mult = 2;
                }
                else if (mult >= 4 && mult <= 7)
                {
                    mult = 4;
                }
                else if (mult > 8)
                {
                    mult = 8;
                }
            }
            ClockMultiplier = mult;
            Cpu             = new Z80Cpu(MemoryDevice,
                                         PortDevice,
                                         cpuConfig?.SupportsNextOperations ?? false)
            {
                UseGateArrayContention = MemoryConfiguration.ContentionType == MemoryContentionType.GateArray
            };

            // --- Init the ROM
            var romInfo = GetDeviceInfo <IRomDevice>();

            RomProvider      = (IRomProvider)romInfo.Provider;
            RomDevice        = romInfo.Device ?? new SpectrumRomDevice();
            RomConfiguration = (IRomConfiguration)romInfo.ConfigurationData;

            // --- Init the screen device
            var screenInfo    = GetDeviceInfo <IScreenDevice>();
            var pixelRenderer = (IScreenFrameProvider)screenInfo.Provider;

            ScreenConfiguration = new ScreenConfiguration((IScreenConfiguration)screenInfo.ConfigurationData);
            ScreenDevice        = screenInfo.Device ?? new Spectrum48ScreenDevice();
            ShadowScreenDevice  = new Spectrum48ScreenDevice();

            // --- Init the beeper device
            var beeperInfo = GetDeviceInfo <IBeeperDevice>();

            AudioConfiguration = (IAudioConfiguration)beeperInfo?.ConfigurationData;
            BeeperProvider     = (IBeeperProvider)beeperInfo?.Provider;
            BeeperDevice       = beeperInfo?.Device ?? new BeeperDevice();

            // --- Init the keyboard device
            var keyboardInfo = GetDeviceInfo <IKeyboardDevice>();

            KeyboardProvider = (IKeyboardProvider)keyboardInfo?.Provider;
            KeyboardDevice   = keyboardInfo?.Device ?? new KeyboardDevice();

            // --- Init the Kempston device
            var kempstonInfo = GetDeviceInfo <IKempstonDevice>();

            KempstonProvider = (IKempstonProvider)kempstonInfo?.Provider;
            KempstonDevice   = kempstonInfo?.Device ?? new KempstonDevice();

            // --- Init the interrupt device
            InterruptDevice = new InterruptDevice(InterruptTact);

            // --- Init the tape device
            var tapeSaveInfo = GetDeviceInfo <ITapeSaveDevice>();

            TapeSaveProvider = (ITapeSaveProvider)tapeSaveInfo?.Provider;
            var tapeLoadInfo = GetDeviceInfo <ITapeLoadDevice>();

            TapeLoadProvider = (ITapeLoadProvider)tapeLoadInfo?.Provider;
            var tapeDevice = new TapeDevice(TapeLoadProvider, TapeSaveProvider);

            TapeLoadDevice = tapeDevice;
            TapeSaveDevice = tapeDevice;

            // === Init optional devices
            // --- Init the sound device
            var soundInfo = GetDeviceInfo <ISoundDevice>();

            SoundConfiguration = (IAudioConfiguration)soundInfo?.ConfigurationData;
            SoundProvider      = (ISoundProvider)soundInfo?.Provider;
            SoundDevice        = soundInfo == null
                ? null
                : soundInfo.Device ?? new SoundDevice();

            // --- Init the floppy device
            var floppyInfo = GetDeviceInfo <IFloppyDevice>();

            if (floppyInfo != null)
            {
                FloppyDevice        = floppyInfo.Device;
                FloppyConfiguration = (IFloppyConfiguration)floppyInfo.ConfigurationData ?? new FloppyConfiguration();
            }

            // --- Carry out frame calculations
            ResetUlaTact();
            FrameTacts        = ScreenConfiguration.ScreenRenderingFrameTactCount;
            FrameCount        = 0;
            Overflow          = 0;
            HasFrameCompleted = true;
            _lastBreakpoint   = null;

            // --- Attach providers
            AttachProvider(RomProvider);
            AttachProvider(pixelRenderer);
            AttachProvider(BeeperProvider);
            AttachProvider(KeyboardProvider);
            AttachProvider(KempstonProvider);
            AttachProvider(TapeLoadProvider);
            AttachProvider(DebugInfoProvider);

            // --- Attach optional providers
            if (SoundProvider != null)
            {
                AttachProvider(SoundProvider);
            }

            // --- Collect Spectrum devices
            _spectrumDevices.Add(RomDevice);
            _spectrumDevices.Add(MemoryDevice);
            _spectrumDevices.Add(PortDevice);
            _spectrumDevices.Add(ScreenDevice);
            _spectrumDevices.Add(ShadowScreenDevice);
            _spectrumDevices.Add(BeeperDevice);
            _spectrumDevices.Add(KeyboardDevice);
            _spectrumDevices.Add(KempstonDevice);
            _spectrumDevices.Add(InterruptDevice);
            _spectrumDevices.Add(TapeLoadDevice);

            // --- Collect optional devices
            if (SoundDevice != null)
            {
                _spectrumDevices.Add(SoundDevice);
            }
            if (FloppyDevice != null)
            {
                _spectrumDevices.Add(FloppyDevice);
            }

            // --- Now, prepare devices to find each other
            foreach (var device in _spectrumDevices)
            {
                device.OnAttachedToVm(this);
            }

            // --- Prepare bound devices
            _frameBoundDevices = _spectrumDevices
                                 .OfType <IRenderFrameBoundDevice>()
                                 .ToList();
            _cpuBoundDevices = _spectrumDevices
                               .OfType <ICpuOperationBoundDevice>()
                               .ToList();

            DebugInfoProvider = new SpectrumDebugInfoProvider();

            // --- Init the ROM
            InitRom(RomDevice, RomConfiguration);
        }
示例#27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:System.Object" /> class.
 /// </summary>
 public TestPixelRenderer(IScreenConfiguration displayPars)
 {
     _displayPars = new ScreenConfiguration(displayPars);
 }
示例#28
0
 public void SetScreenToFullHd()
 {
     inferenceConfiguration = new ScreenConfiguration(1920, 1080, 5, 1.0f, 60);
 }
示例#29
0
    //   public override void AcademyStep()
    //{
    //}

    public void SetScreenToHd()
    {
        inferenceConfiguration = new ScreenConfiguration(1280, 720, 5, 1.0f, 60);
    }
 public VirtualScreenManager(ClientState clientState)
 {
     State = clientState;
     ScreenConfiguration = new ScreenConfiguration();
 }
示例#31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:System.Object" /> class.
 /// </summary>
 public TestPixelRenderer(ScreenConfiguration displayPars)
 {
     _displayPars = displayPars;
 }