Skip to content

Commit

Permalink
Merge pull request #38 from SirRickster/add-flags-dock
Browse files Browse the repository at this point in the history
Add flags dock
  • Loading branch information
gusmanb authored Dec 30, 2023
2 parents da7ee2d + d0f5ec9 commit 9853672
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 4 deletions.
56 changes: 56 additions & 0 deletions ZXBStudio/DebuggingTools/Flags/Controls/ZXFlagsView.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="ZXBasicStudio.DebuggingTools.Flags.Controls.ZXFlagsView">
<UserControl.Styles>
</UserControl.Styles>
<Grid Grid.Row="1" RowDefinitions="50" VerticalAlignment="Stretch">
<Panel Background="#FF606060">
<Grid ColumnDefinitions="*,*,*,*,*,*,*,*" RowDefinitions="25,25" Name="gridFlags">
<TextBlock Grid.Row="0" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" ToolTip.Tip="S - Sign flag: Set if the 2-complement value is negative (copy of MSB)">S</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" ToolTip.Tip="Z - Zero flag: Set if the value is zero">Z</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center" ToolTip.Tip="F5 - undocumented: Copy of bit 5">-</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="3" HorizontalAlignment="Center" VerticalAlignment="Center" ToolTip.Tip="H - Half Carry: Carry from bit 3 to bit 4">H</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="4" HorizontalAlignment="Center" VerticalAlignment="Center" ToolTip.Tip="F3 - undocumented: Copy of bit 3">-</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="5"
HorizontalAlignment="Center" VerticalAlignment="Center" ToolTip.Tip="P/V - Parity or Overflow: Parity set if even number of bits set. Overflow set if the 2-complement result does not fit in the register">
V
</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="6"
HorizontalAlignment="Center" VerticalAlignment="Center" ToolTip.Tip="N - Subtract: Set if the last operation was a subtraction">
N
</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="7"
HorizontalAlignment="Center" VerticalAlignment="Center" ToolTip.Tip="C - Carry: Set if the result did not fit in the register">
C
</TextBlock>
<Border Grid.Column="0" Grid.Row="1" BorderBrush="Black" BorderThickness="0,1,0,0">
<TextBlock Name="Bit7" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<Border Grid.Column="1" Grid.Row="1" BorderBrush="Black" BorderThickness="1,1,0,0">
<TextBlock Name="Bit6" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<Border Grid.Column="2" Grid.Row="1" BorderBrush="Black" BorderThickness="1,1,0,0">
<TextBlock Name="Bit5" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<Border Grid.Column="3" Grid.Row="1" BorderBrush="Black" BorderThickness="1,1,0,0">
<TextBlock Name="Bit4" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<Border Grid.Column="4" Grid.Row="1" BorderBrush="Black" BorderThickness="1,1,0,0">
<TextBlock Name="Bit3" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<Border Grid.Column="5" Grid.Row="1" BorderBrush="Black" BorderThickness="1,1,0,0">
<TextBlock Name="Bit2" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<Border Grid.Column="6" Grid.Row="1" BorderBrush="Black" BorderThickness="1,1,0,0">
<TextBlock Name="Bit1" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<Border Grid.Column="7" Grid.Row="1" BorderBrush="Black" BorderThickness="1,1,0,0">
<TextBlock Name="Bit0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</Grid>
</Panel>
</Grid>
</UserControl>
52 changes: 52 additions & 0 deletions ZXBStudio/DebuggingTools/Flags/Controls/ZXFlagsView.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Linq;
using Avalonia.Controls;

namespace ZXBasicStudio.DebuggingTools.Flags.Controls
{
public partial class ZXFlagsView : UserControl
{

public ZXFlagsView()
{
InitializeComponent();
}

public void Update(byte value)
{
var bits = GetBinaryFromByte(value);
Bit7.Text = bits[7].ToString();
Bit6.Text = bits[6].ToString();
Bit5.Text = bits[5].ToString();
Bit4.Text = bits[4].ToString();
Bit3.Text = bits[3].ToString();
Bit2.Text = bits[2].ToString();
Bit1.Text = bits[1].ToString();
Bit0.Text = bits[0].ToString();
}

private static int[] GetBinaryFromByte(byte value)
{
string s = Convert.ToString(value, 2);
int[] bits = s.PadLeft(8, '0')
.Select(c => int.Parse(c.ToString()))
.ToArray();

Array.Reverse(bits);
return bits;
}

public void Clear()
{
Bit7.Text = "-";
Bit6.Text = "-";
Bit5.Text = "-";
Bit4.Text = "-";
Bit3.Text = "-";
Bit2.Text = "-";
Bit1.Text = "-";
Bit0.Text = "-";

}
}
}
21 changes: 17 additions & 4 deletions ZXBStudio/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
xmlns:zxdtr="using:ZXBasicStudio.DebuggingTools.Registers.Controls"
xmlns:zxdtm="using:ZXBasicStudio.DebuggingTools.Memory.Controls"
xmlns:zxdtt="using:ZXBasicStudio.DebuggingTools.TStates.Controls"
xmlns:zxdfl="using:ZXBasicStudio.DebuggingTools.Flags.Controls"
xmlns:wnd="using:ZXBasicStudio.Classes"
xmlns:svg="using:Avalonia.Svg.Skia"
mc:Ignorable="d" d:DesignWidth="1024" d:DesignHeight="600"
Expand Down Expand Up @@ -189,25 +190,37 @@
<TabControl Grid.Column="2" Grid.Row="2" Name="tcEditors" ItemsSource="{Binding EditItems}" />
<zxd:ZXCollapseButton CollapseDirection="Right" GridColumn="4" Grid.Column="3" Grid.Row="2"></zxd:ZXCollapseButton>
<GridSplitter Classes="vertical" Grid.Column="3" Grid.Row="2" Grid.RowSpan="3" ResizeDirection="Columns"></GridSplitter>
<zxd:ZXDockingContainer Grid.Column="4" Grid.Row="2" RowDefinitions="*,4,0.3*,4,*" Grid.RowSpan="3" Name="dockRight">
<zxd:ZXDockingControl Title="Variables" Name="varsDock">

<zxd:ZXDockingContainer Grid.Column="4" Grid.Row="2" RowDefinitions="*,4,0.3*,4,0.3*,4,*" Grid.RowSpan="4" Name="dockRight">

<zxd:ZXDockingControl Grid.Row="0" Title="Variables" Name="varsDock">
<zxd:ZXDockingControl.DockedControl>
<zxdtv:ZXVariablesView Name="varsView"></zxdtv:ZXVariablesView>
</zxd:ZXDockingControl.DockedControl>
</zxd:ZXDockingControl>

<GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></GridSplitter>
<zxd:ZXDockingControl Title="T-States" Grid.Row="2" Name="tstatesDock">
<zxd:ZXDockingControl Grid.Row="2" Title="T-States" Name="tstatesDock">
<zxd:ZXDockingControl.DockedControl>
<zxdtt:ZXTStatesView Name="statesView"></zxdtt:ZXTStatesView>
</zxd:ZXDockingControl.DockedControl>
</zxd:ZXDockingControl>

<GridSplitter Grid.Row="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></GridSplitter>
<zxd:ZXDockingControl Title="Registers" Grid.Row="4" Name="regsDock">
<zxd:ZXDockingControl Grid.Row="4" Title="Z80 Flags" Name="flagsDock">
<zxd:ZXDockingControl.DockedControl>
<zxdfl:ZXFlagsView Name="flagsView"></zxdfl:ZXFlagsView>
</zxd:ZXDockingControl.DockedControl>
</zxd:ZXDockingControl>

<GridSplitter Grid.Row="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></GridSplitter>
<zxd:ZXDockingControl Grid.Row="6" Title="Registers" Name="regsDock">
<zxd:ZXDockingControl.DockedControl>
<zxdtr:ZXRegistersView Name="regView" AllowEdit="{Binding EmulatorInfo.CanStep}"></zxdtr:ZXRegistersView>
</zxd:ZXDockingControl.DockedControl>
</zxd:ZXDockingControl>
</zxd:ZXDockingContainer>

<GridSplitter Classes="horizontal" Grid.Column="2" Grid.ColumnSpan="1" Grid.Row="3" ResizeDirection="Rows"></GridSplitter>
<zxd:ZXTabDockingContainer Name="dockBottom" Grid.Column="2" Grid.ColumnSpan="1" Grid.Row="4" TabsPosition="Bottom">
<zxd:ZXTabDockingContainer.DockedControls>
Expand Down
6 changes: 6 additions & 0 deletions ZXBStudio/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
using System.Threading.Tasks;
using ZXBasicStudio.BuildSystem;
using ZXBasicStudio.Classes;
using ZXBasicStudio.Common;
using ZXBasicStudio.Common.ZXSinclairBasic;
using ZXBasicStudio.Controls;
using ZXBasicStudio.Controls.DockSystem;
Expand Down Expand Up @@ -1050,6 +1051,7 @@ private void StopEmulator(object? sender, Avalonia.Interactivity.RoutedEventArgs
UnblockEditors();
varsView.EndEdit();
statesView.Clear();
flagsView.Clear();
}
private async void PauseEmulator(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
Expand All @@ -1065,6 +1067,7 @@ private async void PauseEmulator(object? sender, Avalonia.Interactivity.RoutedEv
ClearBreakLines();
currentBp = await ShowBreakLines(emu.Registers.PC, true);
regView.Update();
flagsView.Update(emu.Registers.F);
varsView.BeginEdit();
statesView.Update(emu.TStates);
}
Expand Down Expand Up @@ -1177,6 +1180,7 @@ private async void AssemblerStepEmulator(object? sender, Avalonia.Interactivity.
}

regView.Update();
flagsView.Update(emu.Registers.F);
varsView.BeginEdit();
statesView.Update(emu.TStates);
}
Expand Down Expand Up @@ -1234,6 +1238,7 @@ private void Emu_Breakpoint(object? sender, BreakpointEventArgs e)
currentBp = e.Breakpoint;
varsView.BeginEdit();
regView.Update();
flagsView.Update(emu.Registers.F);
statesView.Update(emu.TStates);
outLog.Writer.WriteLine($"Breakpoint: file {Path.GetFileName(line.File)}, line {line.LineNumber + 1}, address {line.Address}");

Expand Down Expand Up @@ -2170,6 +2175,7 @@ void Cleanup()

varsView.EndEdit();
statesView.Clear();
flagsView.Clear();
currentBp = null;
emu.UpdateBreakpoints(null);
EmulatorInfo.IsRunning = false;
Expand Down
7 changes: 7 additions & 0 deletions ZXBStudio/ZXBasicStudio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<Compile Remove="LanguageDefinitions\**" />
<EmbeddedResource Remove="LanguageDefinitions\**" />
<None Remove="LanguageDefinitions\**" />
<Compile Update="DebuggingTools\Flags\Controls\ZXFlagsView.axaml.cs">
<DependentUpon>ZXFlagsView.axaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<AvaloniaXaml Remove="Controls\ZXLocalVariablesView.axaml" />
Expand Down Expand Up @@ -577,6 +581,9 @@
<Compile Update="Emulator\Controls\ZXKeyView.axaml.cs">
<DependentUpon>ZXKeyView.axaml</DependentUpon>
</Compile>
<Compile Update="DebuggingTools\Flags\Controls\ZXFlagsView.axaml.cs">
<DependentUpon>ZXFlagsView.axaml</DependentUpon>
</Compile>
<Compile Update="DebuggingTools\Registers\Controls\ZXRegisterView.axaml.cs">
<DependentUpon>ZXRegisterView.axaml</DependentUpon>
</Compile>
Expand Down

0 comments on commit 9853672

Please sign in to comment.