Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: CPU Stack View #998

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Spice86/ViewModels/BreakpointsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ private void ToggleSelectedBreakpoint() {
[NotifyCanExecuteChangedFor(nameof(ToggleSelectedBreakpointCommand))]
private BreakpointViewModel? _selectedBreakpoint;

internal void AddUnconditionalBreakpoint(Action onReached, bool removedOnTrigger) {
public void AddUnconditionalBreakpoint(Action onReached, bool removedOnTrigger) {
_emulatorBreakpointsManager.ToggleBreakPoint(
new UnconditionalBreakPoint(
BreakPointType.EXECUTION,
(_) => onReached(),
removedOnTrigger), on: true);
}

internal BreakpointViewModel AddAddressBreakpoint(
public BreakpointViewModel AddAddressBreakpoint(
uint address,
BreakPointType type,
bool isRemovedOnTrigger,
Expand All @@ -65,7 +65,7 @@ internal BreakpointViewModel AddAddressBreakpoint(
return breakpointViewModel;
}

internal BreakpointViewModel? GetBreakpoint(CpuInstructionInfo instructionInfo) {
public BreakpointViewModel? GetBreakpoint(CpuInstructionInfo instructionInfo) {
return Breakpoints.FirstOrDefault(x => x.IsFor(instructionInfo));
}

Expand All @@ -77,7 +77,7 @@ private void RemoveBreakpoint() {
DeleteBreakpoint(SelectedBreakpoint);
}

internal void RemoveBreakpointInternal(BreakpointViewModel vm) {
public void RemoveBreakpointInternal(BreakpointViewModel vm) {
DeleteBreakpoint(vm);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Spice86/ViewModels/CpuViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public partial class CpuViewModel : ViewModelBase {
[ObservableProperty]
private CpuFlagsInfo _flags = new();

public CpuViewModel(State state, Stack stack, IMemory memory, IPauseHandler pauseHandler, IUIDispatcher uiDispatcher) {
public CpuViewModel(State state, IMemory memory, IPauseHandler pauseHandler, IUIDispatcher uiDispatcher) {
_cpuState = state;
_memory = memory;
pauseHandler.Pausing += () => uiDispatcher.Post(() => _isPaused = true);
Expand Down
30 changes: 25 additions & 5 deletions src/Spice86/ViewModels/DebugWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public partial class DebugWindowViewModel : ViewModelBase,
IRecipient<RemoveViewModelMessage<DisassemblyViewModel>>, IRecipient<RemoveViewModelMessage<MemoryViewModel>> {

private readonly IMessenger _messenger;
private readonly IUIDispatcher _uiDispatcher;

[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(ContinueCommand))]
Expand Down Expand Up @@ -72,8 +73,9 @@ public DebugWindowViewModel(State cpuState, Stack stack, IMemory memory, Midi ex
messenger.Register<RemoveViewModelMessage<DisassemblyViewModel>>(this);
messenger.Register<RemoveViewModelMessage<MemoryViewModel>>(this);
_messenger = messenger;
_uiDispatcher = uiDispatcher;
BreakpointsViewModel = new(emulatorBreakpointsManager);
StatusMessageViewModel = new(_messenger);
StatusMessageViewModel = new(_uiDispatcher, _messenger);
_pauseHandler = pauseHandler;
IsPaused = pauseHandler.IsPaused;
pauseHandler.Pausing += () => uiDispatcher.Post(() => IsPaused = true);
Expand All @@ -89,17 +91,35 @@ public DebugWindowViewModel(State cpuState, Stack stack, IMemory memory, Midi ex
PaletteViewModel = new(argbPalette, uiDispatcher);
SoftwareMixerViewModel = new(softwareMixer);
VideoCardViewModel = new(vgaRenderer, videoState);
CpuViewModel = new(cpuState, stack, memory, pauseHandler, uiDispatcher);
CpuViewModel = new(cpuState, memory, pauseHandler, uiDispatcher);
MidiViewModel = new(externalMidiDevice);
MemoryViewModels.Add(new(memory, BreakpointsViewModel, pauseHandler, messenger, uiDispatcher, textClipboard, storageProvider, structureViewModelFactory));
MemoryViewModel mainMemoryViewModel = new(memory,
BreakpointsViewModel, pauseHandler, messenger,
uiDispatcher, textClipboard, storageProvider, structureViewModelFactory);
MemoryViewModel stackMemoryViewModel = new(memory,
BreakpointsViewModel, pauseHandler, messenger,
uiDispatcher, textClipboard, storageProvider, structureViewModelFactory,
canCloseTab: false, startAddress: stack.PhysicalAddress) {
Title = "CPU Stack Memory"
};
pauseHandler.Pausing += () => UpdateStackMemoryViewModel(stackMemoryViewModel, stack);
MemoryViewModels.Add(mainMemoryViewModel);
MemoryViewModels.Add(stackMemoryViewModel);
CfgCpuViewModel = new(executionContextManager, pauseHandler, new PerformanceMeasurer());
}

private void UpdateStackMemoryViewModel(MemoryViewModel stackMemoryViewModel, Stack stack) {
stackMemoryViewModel.StartAddress = stack.PhysicalAddress;
stackMemoryViewModel.EndAddress = A20Gate.EndOfHighMemoryArea;
}

[RelayCommand]
private void Pause() => _pauseHandler.RequestPause("Pause button pressed in debug window");
private void Pause() => _uiDispatcher.Post(() => {
_pauseHandler.RequestPause("Pause button pressed in debug window");
});

[RelayCommand(CanExecute = nameof(IsPaused))]
private void Continue() => _pauseHandler.Resume();
private void Continue() => _uiDispatcher.Post(_pauseHandler.Resume);

public void Receive(AddViewModelMessage<DisassemblyViewModel> message) => DisassemblyViewModels.Add(message.ViewModel);
public void Receive(AddViewModelMessage<MemoryViewModel> message) => MemoryViewModels.Add(message.ViewModel);
Expand Down
3 changes: 3 additions & 0 deletions src/Spice86/ViewModels/MemoryViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public MemoryViewModel(IMemory memory, BreakpointsViewModel breakpointsViewModel
TryUpdateHeaderAndMemoryDocument();
}

[ObservableProperty]
private string? _title;

public enum MemorySearchDataType {
Binary,
Ascii,
Expand Down
15 changes: 14 additions & 1 deletion src/Spice86/ViewModels/StatusMessageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,28 @@ namespace Spice86.ViewModels;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;

using Spice86.Infrastructure;
using Spice86.Messages;

public partial class StatusMessageViewModel : ViewModelBase, IRecipient<StatusMessage> {
private readonly IUIDispatcher _uiDispatcher;

[ObservableProperty]
private StatusMessage? _message;

public StatusMessageViewModel(IMessenger messenger) => messenger.Register(this);
[ObservableProperty]
private bool _isVisible;

public StatusMessageViewModel(IUIDispatcher dispatcher, IMessenger messenger) {
messenger.Register(this);
_uiDispatcher = dispatcher;
}

public void Receive(StatusMessage message) {
Message = message;
IsVisible = true;
Task.Delay(millisecondsDelay: 5000).ContinueWith(_ => {
_uiDispatcher.Post(() => IsVisible = false);
});
}
}
9 changes: 6 additions & 3 deletions src/Spice86/Views/MemoryView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@
<Label Content="End" />
<NumericUpDown Value="{Binding EndAddress}" />
</UniformGrid>
<Button IsVisible="{Binding IsPaused}" IsEnabled="{Binding IsPaused}"
Command="{Binding UpdateBinaryDocumentCommand}"
HotKey="Ctrl+R" ToolTip.Tip="Ctrl-R" Content="Refresh" />
<StackPanel Orientation="Vertical">
<Button IsVisible="{Binding IsPaused}" IsEnabled="{Binding IsPaused}"
Command="{Binding UpdateBinaryDocumentCommand}"
HotKey="Ctrl+R" ToolTip.Tip="Ctrl-R" Content="Refresh" />
<Label IsVisible="{Binding IsPaused}" Content="{Binding Title}" />
</StackPanel>
</StackPanel>
<Grid Grid.Row="1"
RowDefinitions="*, Auto">
Expand Down
2 changes: 1 addition & 1 deletion src/Spice86/Views/StatusMessageView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Spice86.Views.StatusMessageView"
x:DataType="viewModels:StatusMessageViewModel">
<controls:StatusBar>
<controls:StatusBar IsVisible="{Binding IsVisible}">
<controls:StatusBarItem>
<TextBlock DataContext="{Binding Message}">
<Run Text="{Binding Time}" />
Expand Down
Loading