public VM_Machine() { InitializeComponent(); memory = new VM_Memory(); memory.ScreenUpdateEvent += () => { screen.Dispatcher.Invoke(()=> { screen.InvalidateVisual(); }); }; screen.BindingMemory(memory); cpu = new VM_CPU(memory); cpu.RegisterStatusUpdateEvent += () => { var registerStatus = string.Empty; registerStatus = "AL=#" + cpu.AL.ToString("X").PadLeft(2, '0'); registerStatus += "; AH=#" + cpu.AH.ToString("X").PadLeft(2, '0'); registerStatus += "; A=#" + cpu.A.ToString("X").PadLeft(4, '0'); registerStatus += "; B=#" + cpu.B.ToString("X").PadLeft(4, '0'); registerStatus += "; C=#" + cpu.C.ToString("X").PadLeft(4, '0'); registerStatus += "; D=#" + cpu.D.ToString("X").PadLeft(4, '0'); registerStatus += "; IP=#" + cpu.InstructionPointer.ToString("X").PadLeft(4, '0'); registerStatus += "; F=#" + cpu.Flags.ToString("X").PadLeft(2, '0'); registerStatusLabel.Dispatcher.Invoke(() => { registerStatusLabel.Content = registerStatus; }); }; cpu.CPUSpeedUpdateEvent += ChangeMachineStatusLabel; cpu.CPURunningChangedEvent += ChangeMachineStatusLabel; cpu.CPURunningChangedEvent += () => { if (cpu.Running == CPUStatus.Running) { programPauseButton.Dispatcher.Invoke(()=> { programPauseButton.IsEnabled = true; }); programResumeButton.Dispatcher.Invoke(() => { programResumeButton.IsEnabled = false; }); programRestartButton.Dispatcher.Invoke(() => { programRestartButton.IsEnabled = true; }); } else { if (cpu.Running == CPUStatus.Stop) { programPauseButton.Dispatcher.Invoke(() => { programPauseButton.IsEnabled = false; }); programResumeButton.Dispatcher.Invoke(() => { programResumeButton.IsEnabled = false; }); programRestartButton.Dispatcher.Invoke(() => { programRestartButton.IsEnabled = true; }); } else { programPauseButton.Dispatcher.Invoke(() => { programPauseButton.IsEnabled = false; }); programResumeButton.Dispatcher.Invoke(() => { programResumeButton.IsEnabled = true; }); programRestartButton.Dispatcher.Invoke(() => { programRestartButton.IsEnabled = true; }); } } }; bios = new VM_BIOS(cpu, memory, screen); bios.Reset(); cpu.Running = CPUStatus.Stop; programRestartButton.IsEnabled = false; speedMenuItems = new System.Windows.Controls.MenuItem[] { speed1HzMenuItem, speed2HzMenuItem, speed4HzMenuItem, speedRealTimeItem }; speedRealTimeItem.IsChecked = true; }
public VM_BIOS(VM_CPU cpu, VM_Memory memory, VM_Screen screen) { this.cpu = cpu; this.memory = memory; this.screen = screen; }
public VM_Machine() { InitializeComponent(); memory = new VM_Memory(); memory.ScreenUpdateEvent += () => { screen.Dispatcher.Invoke(() => { screen.InvalidateVisual(); }); }; screen.BindingMemory(memory); cpu = new VM_CPU(memory); cpu.RegisterStatusUpdateEvent += () => { var registerStatus = string.Empty; registerStatus = "AL=#" + cpu.AL.ToString("X").PadLeft(2, '0'); registerStatus += "; AH=#" + cpu.AH.ToString("X").PadLeft(2, '0'); registerStatus += "; A=#" + cpu.A.ToString("X").PadLeft(4, '0'); registerStatus += "; B=#" + cpu.B.ToString("X").PadLeft(4, '0'); registerStatus += "; C=#" + cpu.C.ToString("X").PadLeft(4, '0'); registerStatus += "; D=#" + cpu.D.ToString("X").PadLeft(4, '0'); registerStatus += "; IP=#" + cpu.InstructionPointer.ToString("X").PadLeft(4, '0'); registerStatus += "; F=#" + cpu.Flags.ToString("X").PadLeft(2, '0'); registerStatusLabel.Dispatcher.Invoke(() => { registerStatusLabel.Content = registerStatus; }); }; cpu.CPUSpeedUpdateEvent += ChangeMachineStatusLabel; cpu.CPURunningChangedEvent += ChangeMachineStatusLabel; cpu.CPURunningChangedEvent += () => { if (cpu.Running == CPUStatus.Running) { programPauseButton.Dispatcher.Invoke(() => { programPauseButton.IsEnabled = true; }); programResumeButton.Dispatcher.Invoke(() => { programResumeButton.IsEnabled = false; }); programRestartButton.Dispatcher.Invoke(() => { programRestartButton.IsEnabled = true; }); } else { if (cpu.Running == CPUStatus.Stop) { programPauseButton.Dispatcher.Invoke(() => { programPauseButton.IsEnabled = false; }); programResumeButton.Dispatcher.Invoke(() => { programResumeButton.IsEnabled = false; }); programRestartButton.Dispatcher.Invoke(() => { programRestartButton.IsEnabled = true; }); } else { programPauseButton.Dispatcher.Invoke(() => { programPauseButton.IsEnabled = false; }); programResumeButton.Dispatcher.Invoke(() => { programResumeButton.IsEnabled = true; }); programRestartButton.Dispatcher.Invoke(() => { programRestartButton.IsEnabled = true; }); } } }; bios = new VM_BIOS(cpu, memory, screen); bios.Reset(); cpu.Running = CPUStatus.Stop; programRestartButton.IsEnabled = false; speedMenuItems = new System.Windows.Controls.MenuItem[] { speed1HzMenuItem, speed2HzMenuItem, speed4HzMenuItem, speedRealTimeItem }; speedRealTimeItem.IsChecked = true; }