public MachineControlsViewModel(SimpleSimulator simulator, IUserInputService userInputService, StateSaver stateSaver) : base(simulator)
        {
            OpenCommand = new Command(() =>
            {
                FileInfo file = userInputService.GetOpenFileName();

                if (file != null)
                {
                    Memory memory = stateSaver.LoadMemory(file);
                    for (int i = 0; i <= byte.MaxValue; i++)
                        simulator.Memory[(byte)i] = memory[(byte)i];
                }
            }, () => simulator.Machine.State != Machine.MachineState.Running, simulator);

            SaveCommand = new Command(() =>
            {
                FileInfo file = userInputService.GetSaveFileName();

                if (file != null)
                    stateSaver.SaveMemory(simulator.Memory, file);
            }, () => simulator.Machine.State != Machine.MachineState.Running, simulator);

            RunCommand = new Command(() => Task.Run(() => simulator.Machine.Run(25)), () => simulator.Machine.State != Machine.MachineState.Running, simulator);

            StepCommand = new Command(() => simulator.Machine.Step(), () => true, simulator);

            BreakCommand = new Command(() => simulator.Machine.Break(), () => simulator.Machine.State == Machine.MachineState.Running, simulator);

            ClearMemoryCommand = new Command(() => simulator.Memory.Clear(), () => true, simulator);

            ClearRegistersCommand = new Command(() => simulator.Registers.Clear(), () => true, simulator);
        }
Example #2
0
        public void ShouldBeAbleToSaveMemoryState()
        {
            Memory expectedMemory = new Memory();

            Random random = new Random();
            for (int address = 0; address <= byte.MaxValue; address++)
                expectedMemory[(byte)address] = (byte)random.Next(0x00, byte.MaxValue);

            StateSaver stateSaver = new StateSaver();
            stateSaver.SaveMemory(expectedMemory, _memorySaveFile);

            FileAssert.Exists(_memorySaveFile);

            Memory actualMemory = stateSaver.LoadMemory(_memorySaveFile);

            for (int address = 0; address <= byte.MaxValue; address++)
                Assert.AreEqual(expectedMemory[(byte)address], actualMemory[(byte)address]);
        }