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); }
public void SetUp() { _simulator = new SimpleSimulator(); _userInputService = new Mock<IUserInputService>(); _stateSaver = new Mock<StateSaver>(); _viewModel = new MachineControlsViewModel(_simulator, _userInputService.Object, _stateSaver.Object); }
public MachineControlsViewModelTests() { _simulator = new SimpleSimulator(); _userInputService = new Mock <IUserInputService>(); _dialogServiceAdapter = new Mock <IDialogServiceAdapter>(); _stateSaver = new Mock <IStateSaver>(); _viewModel = new MachineControlsViewModel(_simulator, _userInputService.Object, _dialogServiceAdapter.Object, _stateSaver.Object); }
public OutputViewModel(SimpleSimulator simulator) { ClearCommand = new DelegateCommand(() => OutputWindowText = null); // Needed for proper word wrap on XAML TextBlock. const string zeroWidthSpace = "\u200B"; simulator.Registers.ValueWrittenToOutputRegister += c => OutputWindowText += c + zeroWidthSpace; }
public SystemRegistersViewModel(SimpleSimulator simulator) { _simulator = simulator; ResetProgramCounterCommand = new DelegateCommand(() => _simulator.Machine.ProgramCounter = 0x00); _simulator.Machine.ProgramCounterChanged += () => RaisePropertyChanged(nameof(ProgramCounter)); _simulator.Machine.InstructionRegisterChanged += () => RaisePropertyChanged(nameof(InstructionRegister)); }
public AssemblyEditorDialogViewModel(SimpleSimulator simulator) { CanExecuteAssembleCommand = true; AssembleCommand = new DelegateCommand(async() => { if (await Assemble(simulator)) { RequestClose?.Invoke(new DialogResult()); } }).ObservesCanExecute(() => CanExecuteAssembleCommand); }
public MachineControlsViewModel(SimpleSimulator simulator, IUserInputService userInputService, IDialogServiceAdapter dialogServiceAdapter, IStateSaver stateSaver) { _simulator = simulator; NewCommand = new DelegateCommand(() => dialogServiceAdapter.ShowAssemblyEditorDialog(), () => simulator.Machine.State != Machine.MachineState.Running); OpenCommand = new DelegateCommand(async() => { FileInfo file = userInputService.GetOpenFileName(); if (file != null) { if (file.Extension.Equals(".prg", StringComparison.OrdinalIgnoreCase)) { Memory memory = await stateSaver.LoadMemoryAsync(file); simulator.Memory.LoadByteArray(memory.ToByteArray()); } else if (file.Extension.Equals(".asm", StringComparison.OrdinalIgnoreCase)) { dialogServiceAdapter.ShowAssemblyEditorDialog(File.ReadAllText(file.FullName)); } } }, () => simulator.Machine.State != Machine.MachineState.Running); SaveCommand = new DelegateCommand(async() => { FileInfo file = userInputService.GetSaveFileName(); if (file != null) { await stateSaver.SaveMemoryAsync(simulator.Memory, file); } }, () => simulator.Machine.State != Machine.MachineState.Running); RunCommand = new DelegateCommand(async() => await simulator.Machine.RunAsync(), () => simulator.Machine.State != Machine.MachineState.Running); StepCommand = new DelegateCommand(() => simulator.Machine.Step(), () => simulator.Machine.State != Machine.MachineState.Running); BreakCommand = new DelegateCommand(() => simulator.Machine.Break(), () => simulator.Machine.State == Machine.MachineState.Running); ClearMemoryCommand = new DelegateCommand(() => simulator.Memory.Clear()); ClearRegistersCommand = new DelegateCommand(() => simulator.Registers.Clear()); simulator.Machine.StateChanged += () => { NewCommand.RaiseCanExecuteChanged(); OpenCommand.RaiseCanExecuteChanged(); SaveCommand.RaiseCanExecuteChanged(); RunCommand.RaiseCanExecuteChanged(); StepCommand.RaiseCanExecuteChanged(); BreakCommand.RaiseCanExecuteChanged(); }; }
public void ShouldBeAbleToResetProgramCounter() { SimpleSimulator simulator = new SimpleSimulator(); simulator.Machine.ProgramCounter = 0xFF; SystemRegistersViewModel viewModel = new SystemRegistersViewModel(simulator); viewModel.ResetProgramCounterCommand.Execute(null); Assert.Equal(0x00, simulator.Machine.ProgramCounter); }
public void ShouldBeAbleToResetProgramCounter() { SimpleSimulator simulator = new SimpleSimulator(); simulator.Machine.ProgramCounter = 0xFF; SystemRegistersViewModel viewModel = new SystemRegistersViewModel(simulator); viewModel.ResetProgramCounterCommand.Execute(null); Assert.AreEqual(0x00, simulator.Machine.ProgramCounter); }
private static async Task RunProgram(string assemblyCode) { SimpleSimulator simulator = new SimpleSimulator(); Instruction[] instructions = simulator.Assembler.Assemble(assemblyCode); simulator.Memory.LoadInstructions(instructions); simulator.Registers.ValueWrittenToOutputRegister += System.Console.Write; await simulator.Machine.RunAsync(); System.Console.ReadLine(); }
public void AssembleCommandShouldAssembleInstructionsToMemory() { SimpleSimulator simulator = new SimpleSimulator(); AssemblyEditorWindowViewModel viewModel = new AssemblyEditorWindowViewModel(simulator); viewModel.AssemblyEditorText = SamplePrograms.HelloWorldCode; viewModel.AssembleCommand.Execute(null); var expectedBytes = SamplePrograms.HelloWorldInstructions.SelectMany(instruction => instruction.Bytes).ToList(); var actualBytes = new List<byte>(); for (byte address = 0; address < expectedBytes.Count; address++) actualBytes.Add(simulator.Memory[address]); CollectionAssert.AreEqual(expectedBytes, actualBytes); }
public AssemblyEditorWindowViewModel(SimpleSimulator simulator) : base(simulator) { AssembleCommand = new Command(() => { Instruction[] instructions = null; try { instructions = simulator.Assembler.Assemble(AssemblyEditorText ?? ""); AssemblyResult = "Assembly Successful"; } catch (AssemblyException ex) { AssemblyResult = ex.Message; } if (instructions != null) simulator.Memory.LoadInstructions(instructions); }, () => true, simulator); }
public async Task AssembleCommandShouldAssembleInstructionsToMemory() { SimpleSimulator simulator = new SimpleSimulator(); AssemblyEditorDialogViewModel viewModel = new AssemblyEditorDialogViewModel(simulator); viewModel.AssemblyEditorText = SamplePrograms.HelloWorldCode; await viewModel.Assemble(simulator); var expectedBytes = SamplePrograms.HelloWorldInstructions.SelectMany(instruction => instruction.Bytes).ToList(); var actualBytes = new List <byte>(); for (byte address = 0; address < expectedBytes.Count; address++) { actualBytes.Add(simulator.Memory[address]); } Assert.Equal(expectedBytes, actualBytes); }
public SystemRegistersViewModel(SimpleSimulator simulator) : base(simulator) { _simulator = simulator; ResetProgramCounterCommand = new Command(() => _simulator.Machine.ProgramCounter = 0x00, () => true, _simulator); }
public OutputViewModel(IWindowService windowService, SimpleSimulator simulator) : base(simulator) { OpenAssemblyEditorWindow = new Command(() => windowService.ShowAssemblyEditorWindow(new AssemblyEditorWindowViewModel(simulator)), () => true, simulator); simulator.Registers.ValueWrittenToOutputRegister += c => OutputWindowText += c; }
public MemoryViewModel(SimpleSimulator simulator) { _simulator = simulator; _simulator.Memory.Changed += () => RaisePropertyChanged(IndexerName); }
protected ViewModelBase(SimpleSimulator simulator) { simulator.Machine.PropertyChanged += (sender, e) => OnPropertyChanged(e.PropertyName); }
public GeneralPurposeRegistersViewModel(SimpleSimulator simulator) { _simulator = simulator; _simulator.Registers.Changed += () => RaisePropertyChanged(IndexerName); }
public StatusBarViewModel(SimpleSimulator simulator) { SetStatus(simulator); simulator.Machine.StateChanged += () => SetStatus(simulator); }
private void SetStatus(SimpleSimulator simulator) { Status = simulator.Machine.State; }
public MainWindowViewModel(SimpleSimulator simulator) : base(simulator) { }
public GeneralPurposeRegistersViewModel(SimpleSimulator simulator) : base(simulator) { _simulator = simulator; _simulator.Registers.CollectionChanged += (sender, e) => this[(byte)e.NewStartingIndex] = (byte)e.NewItems[0]; }
public MemoryViewModel(SimpleSimulator simulator) : base(simulator) { _simulator = simulator; _simulator.Memory.CollectionChanged += (sender, e) => this[(byte)e.NewStartingIndex] = (byte)e.NewItems[0]; }