Skip to content

Commit

Permalink
feat: Use real hex viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
furesoft committed Oct 26, 2024
1 parent 37253c7 commit 4a9474a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/MimaSim/MimaSim/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<FluentTheme />
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />
<StyleInclude Source="avares://AvaloniaHex/Themes/Simple/AvaloniaHex.axaml"/>
</Application.Styles>

<Application.Resources>
Expand Down
12 changes: 11 additions & 1 deletion src/MimaSim/MimaSim/Controls/Popups/DisassemblyViewPopup.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
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"
xmlns:avaloniaHex="clr-namespace:AvaloniaHex;assembly=AvaloniaHex"
xmlns:rendering="clr-namespace:AvaloniaHex.Rendering;assembly=AvaloniaHex"
xmlns:c="clr-namespace:MimaSim.Controls"
xmlns:avaloniaEdit="https://github.com/avaloniaui/avaloniaedit"
xmlns:behaviors="clr-namespace:MimaSim.Behaviors"
Expand All @@ -14,12 +16,20 @@

<avaloniaEdit:TextEditor x:Name="editor" MinWidth="150" MaxHeight="150" MinHeight="150"
FontFamily="Cascadia Code,Consolas,Menlo,Monospace" Margin="0,5,0,5"
VerticalAlignment="Top"
VerticalAlignment="Top" IsVisible="{Binding !ShowHexDump}"
ShowLineNumbers="True" SyntaxHighlighting="Assembler">
<Interaction.Behaviors>
<behaviors:DocumentTextBindingBehavior Text="{Binding Source, Mode=TwoWay}" />
</Interaction.Behaviors>
</avaloniaEdit:TextEditor>

<avaloniaHex:HexEditor x:Name="MainHexEditor" FontFamily="Cascadia Code,JetBrains Mono,Monospace,monospace" Document="{Binding HexDocument}"
IsVisible="{Binding ShowHexDump}" Height="100">
<avaloniaHex:HexEditor.Columns>
<rendering:OffsetColumn />
<rendering:HexColumn />
</avaloniaHex:HexEditor.Columns>
</avaloniaHex:HexEditor>
</StackPanel>
</c:DialogControl>
</UserControl>
21 changes: 21 additions & 0 deletions src/MimaSim/MimaSim/Controls/Popups/DisassemblyViewPopup.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using Avalonia.ReactiveUI;
using AvaloniaHex;
using AvaloniaHex.Rendering;
using MimaSim.ViewModels;
using ReactiveUI;

Expand All @@ -14,6 +18,23 @@ public DisassemblyViewPopup()
cc!.Activator.Activate();

InitializeComponent();

InitHexView();
}

private void InitHexView()
{
MainHexEditor = this.Find<HexEditor>("MainHexEditor")!;

MainHexEditor.HexView.BytesPerLine = 12;

var layer = MainHexEditor.HexView.Layers.Get<CellGroupsLayer>();
layer.BytesPerGroup = 4;
layer.Backgrounds.Add(new SolidColorBrush(Colors.Gray, 0.1D));
layer.Backgrounds.Add(null);
layer.Border = new Pen(Brushes.Gray, dashStyle: DashStyle.Dash);

MainHexEditor.HexView.InvalidateVisualLines();
}

private void InitializeComponent()
Expand Down
1 change: 1 addition & 0 deletions src/MimaSim/MimaSim/MimaSim.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.4"/>
<PackageReference Include="Avalonia.Xaml.Interactions" Version="11.1.0.4"/>
<PackageReference Include="AvaloniaHex" Version="0.1.3" />
<PackageReference Include="ReactiveUI" Version="20.1.63"/>
<PackageReference Include="Silverfly" Version="1.0.74"/>
</ItemGroup>
Expand Down
21 changes: 13 additions & 8 deletions src/MimaSim/MimaSim/ViewModels/DisassemblyPopupViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,30 @@
using System.Text;
using System.Windows.Input;
using AvaloniaEdit.Highlighting;
using AvaloniaHex.Document;
using MimaSim.Core;

namespace MimaSim.ViewModels;

public partial class DisassemblyPopupViewModel : ReactiveObject, IActivatableViewModel
public class DisassemblyPopupViewModel : ReactiveObject, IActivatableViewModel
{
private string? _source;

private bool _showHexDump;
private ByteArrayBinaryDocument _hexDocument;

public DisassemblyPopupViewModel()
{
CloseCommand = ReactiveCommand.Create(DialogService.Close);
ShowHexDump = false;

Source = Disassemble();
HexDocument = new ByteArrayBinaryDocument(CPU.Instance.Program, true);
}

public bool ShowHexDump
{
get => _showHexDump;
set
{
this.RaiseAndSetIfChanged(ref _showHexDump, value);

Source = value ? GetRawString() : Disassemble();
}
set => this.RaiseAndSetIfChanged(ref _showHexDump, value);
}

public ViewModelActivator Activator => new();
Expand All @@ -43,6 +42,12 @@ public string? Source
set => this.RaiseAndSetIfChanged(ref _source, value);
}

public ByteArrayBinaryDocument HexDocument
{
get => _hexDocument;
set => this.RaiseAndSetIfChanged(ref _hexDocument, value);
}

private static string Disassemble()
{
var raw = CPU.Instance.Program;
Expand Down

0 comments on commit 4a9474a

Please sign in to comment.