diff --git a/src/MimaSim/MimaSim/App.axaml.cs b/src/MimaSim/MimaSim/App.axaml.cs index a0a30c44..47964d39 100644 --- a/src/MimaSim/MimaSim/App.axaml.cs +++ b/src/MimaSim/MimaSim/App.axaml.cs @@ -24,15 +24,13 @@ public override void OnFrameworkInitializationCompleted() { Locator.CurrentMutable.RegisterViewsForViewModels(Assembly.GetCallingAssembly()); - CPU.Instance.Init(); - if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { desktop.MainWindow = new MainWindow { //DataContext = new MainViewModel() }; - Locator.CurrentMutable.Register(() => desktop.MainWindow.StorageProvider); + Locator.CurrentMutable.Register(() => desktop.MainWindow.StorageProvider); } else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform) @@ -41,7 +39,7 @@ public override void OnFrameworkInitializationCompleted() { //DataContext = new MainViewModel() }; - Locator.CurrentMutable.Register(() => TopLevel.GetTopLevel(singleViewPlatform.MainView)!.StorageProvider); + Locator.CurrentMutable.Register(() => TopLevel.GetTopLevel(singleViewPlatform.MainView)!.StorageProvider); } var samples = new SampleLoader(); diff --git a/src/MimaSim/MimaSim/Controls/DialogService.cs b/src/MimaSim/MimaSim/Controls/DialogService.cs index 10b1ea45..1e224ab0 100644 --- a/src/MimaSim/MimaSim/Controls/DialogService.cs +++ b/src/MimaSim/MimaSim/Controls/DialogService.cs @@ -28,7 +28,7 @@ public static ICommand CreateOpenCommand(Control content, ReactiveObject viewMod public static bool GetIsHost(ContentDialog target) { - return object.ReferenceEquals(_host, target); + return ReferenceEquals(_host, target); } public static void Open(object content) diff --git a/src/MimaSim/MimaSim/Controls/ExecutionBar.axaml b/src/MimaSim/MimaSim/Controls/ExecutionBar.axaml index 51908b28..9d1f9948 100644 --- a/src/MimaSim/MimaSim/Controls/ExecutionBar.axaml +++ b/src/MimaSim/MimaSim/Controls/ExecutionBar.axaml @@ -5,25 +5,29 @@ mc:Ignorable="d" d:DesignWidth="325" d:DesignHeight="50" x:CompileBindings="False" x:Class="MimaSim.Controls.ExecutionBar"> - + + + + - - - diff --git a/src/MimaSim/MimaSim/Controls/MimaComponents/AluControl.axaml.cs b/src/MimaSim/MimaSim/Controls/MimaComponents/AluControl.axaml.cs index 87c6734b..600353b6 100644 --- a/src/MimaSim/MimaSim/Controls/MimaComponents/AluControl.axaml.cs +++ b/src/MimaSim/MimaSim/Controls/MimaComponents/AluControl.axaml.cs @@ -7,7 +7,7 @@ public partial class AluControl : UserControl { public AluControl() { - this.InitializeComponent(); + InitializeComponent(); } private void InitializeComponent() diff --git a/src/MimaSim/MimaSim/Controls/MimaComponents/BusControl.axaml.cs b/src/MimaSim/MimaSim/Controls/MimaComponents/BusControl.axaml.cs index 7f4caac0..0fdc9064 100644 --- a/src/MimaSim/MimaSim/Controls/MimaComponents/BusControl.axaml.cs +++ b/src/MimaSim/MimaSim/Controls/MimaComponents/BusControl.axaml.cs @@ -16,7 +16,7 @@ public partial class BusControl : UserControl public BusControl() { - this.InitializeComponent(); + InitializeComponent(); } public Orientation Orientation diff --git a/src/MimaSim/MimaSim/Controls/MimaComponents/ClockControl.axaml.cs b/src/MimaSim/MimaSim/Controls/MimaComponents/ClockControl.axaml.cs index 7cd226a2..e7b6fd95 100644 --- a/src/MimaSim/MimaSim/Controls/MimaComponents/ClockControl.axaml.cs +++ b/src/MimaSim/MimaSim/Controls/MimaComponents/ClockControl.axaml.cs @@ -8,7 +8,7 @@ public partial class ClockControl : ReactiveUserControl { public ClockControl() { - this.InitializeComponent(); + InitializeComponent(); } private void InitializeComponent() diff --git a/src/MimaSim/MimaSim/Controls/MimaComponents/ControlUnitControl.axaml.cs b/src/MimaSim/MimaSim/Controls/MimaComponents/ControlUnitControl.axaml.cs index 50bc9d8f..a287ed60 100644 --- a/src/MimaSim/MimaSim/Controls/MimaComponents/ControlUnitControl.axaml.cs +++ b/src/MimaSim/MimaSim/Controls/MimaComponents/ControlUnitControl.axaml.cs @@ -7,7 +7,7 @@ public partial class ControlUnitControl : UserControl { public ControlUnitControl() { - this.InitializeComponent(); + InitializeComponent(); } private void InitializeComponent() diff --git a/src/MimaSim/MimaSim/Controls/MimaComponents/DataBusControl.axaml.cs b/src/MimaSim/MimaSim/Controls/MimaComponents/DataBusControl.axaml.cs index 5ee61790..c7983959 100644 --- a/src/MimaSim/MimaSim/Controls/MimaComponents/DataBusControl.axaml.cs +++ b/src/MimaSim/MimaSim/Controls/MimaComponents/DataBusControl.axaml.cs @@ -7,7 +7,7 @@ public partial class DataBusControl : UserControl { public DataBusControl() { - this.InitializeComponent(); + InitializeComponent(); } private void InitializeComponent() diff --git a/src/MimaSim/MimaSim/Controls/MimaComponents/MemoryControl.axaml.cs b/src/MimaSim/MimaSim/Controls/MimaComponents/MemoryControl.axaml.cs index 8e2072a4..71854d60 100644 --- a/src/MimaSim/MimaSim/Controls/MimaComponents/MemoryControl.axaml.cs +++ b/src/MimaSim/MimaSim/Controls/MimaComponents/MemoryControl.axaml.cs @@ -7,7 +7,7 @@ public partial class MemoryControl : UserControl { public MemoryControl() { - this.InitializeComponent(); + InitializeComponent(); } private void InitializeComponent() diff --git a/src/MimaSim/MimaSim/Controls/MimaComponents/Popups/ClockSettingsPopupControl.axaml.cs b/src/MimaSim/MimaSim/Controls/MimaComponents/Popups/ClockSettingsPopupControl.axaml.cs index a934957f..ff6f9c6f 100644 --- a/src/MimaSim/MimaSim/Controls/MimaComponents/Popups/ClockSettingsPopupControl.axaml.cs +++ b/src/MimaSim/MimaSim/Controls/MimaComponents/Popups/ClockSettingsPopupControl.axaml.cs @@ -14,7 +14,7 @@ public ClockSettingsPopupControl() this.WhenActivated(disposables => { /* Handle view activation etc. */ }); - this.InitializeComponent(); + InitializeComponent(); } private void InitializeComponent() diff --git a/src/MimaSim/MimaSim/Controls/MimaComponents/Popups/RawViewPopupControl.axaml b/src/MimaSim/MimaSim/Controls/MimaComponents/Popups/DisassemblyViewPopupControl.axaml similarity index 78% rename from src/MimaSim/MimaSim/Controls/MimaComponents/Popups/RawViewPopupControl.axaml rename to src/MimaSim/MimaSim/Controls/MimaComponents/Popups/DisassemblyViewPopupControl.axaml index bc851daa..127c52dc 100644 --- a/src/MimaSim/MimaSim/Controls/MimaComponents/Popups/RawViewPopupControl.axaml +++ b/src/MimaSim/MimaSim/Controls/MimaComponents/Popups/DisassemblyViewPopupControl.axaml @@ -4,8 +4,8 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:c="clr-namespace:MimaSim.Controls" x:CompileBindings="False" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" MinWidth="450" - x:Class="MimaSim.Controls.MimaComponents.Popups.RawViewPopupControl"> - + x:Class="MimaSim.Controls.MimaComponents.Popups.DisassemblyViewPopupControl"> + diff --git a/src/MimaSim/MimaSim/Controls/MimaComponents/Popups/RawViewPopupControl.axaml.cs b/src/MimaSim/MimaSim/Controls/MimaComponents/Popups/DisassemblyViewPopupControl.axaml.cs similarity index 66% rename from src/MimaSim/MimaSim/Controls/MimaComponents/Popups/RawViewPopupControl.axaml.cs rename to src/MimaSim/MimaSim/Controls/MimaComponents/Popups/DisassemblyViewPopupControl.axaml.cs index f0698578..3b81937f 100644 --- a/src/MimaSim/MimaSim/Controls/MimaComponents/Popups/RawViewPopupControl.axaml.cs +++ b/src/MimaSim/MimaSim/Controls/MimaComponents/Popups/DisassemblyViewPopupControl.axaml.cs @@ -5,11 +5,11 @@ namespace MimaSim.Controls.MimaComponents.Popups; -public partial class RawViewPopupControl : ReactiveUserControl +public partial class DisassemblyViewPopupControl : ReactiveUserControl { - public RawViewPopupControl() + public DisassemblyViewPopupControl() { - DataContext = new RawPopupViewModel(); + DataContext = new DisassemblyPopupViewModel(); var cc = DataContext as IActivatableViewModel; cc.Activator.Activate(); diff --git a/src/MimaSim/MimaSim/Controls/MimaComponents/Popups/ErrorPopupControl.axaml.cs b/src/MimaSim/MimaSim/Controls/MimaComponents/Popups/ErrorPopupControl.axaml.cs index 571365ad..9834feb7 100644 --- a/src/MimaSim/MimaSim/Controls/MimaComponents/Popups/ErrorPopupControl.axaml.cs +++ b/src/MimaSim/MimaSim/Controls/MimaComponents/Popups/ErrorPopupControl.axaml.cs @@ -13,7 +13,7 @@ public ErrorPopupControl() this.WhenActivated(disposables => { /* Handle view activation etc. */ }); - this.InitializeComponent(); + InitializeComponent(); } private void InitializeComponent() diff --git a/src/MimaSim/MimaSim/Controls/MimaComponents/RegisterControl.axaml.cs b/src/MimaSim/MimaSim/Controls/MimaComponents/RegisterControl.axaml.cs index 467d7a78..a1edaa1d 100644 --- a/src/MimaSim/MimaSim/Controls/MimaComponents/RegisterControl.axaml.cs +++ b/src/MimaSim/MimaSim/Controls/MimaComponents/RegisterControl.axaml.cs @@ -11,7 +11,7 @@ public partial class RegisterControl : UserControl public RegisterControl() { - this.InitializeComponent(); + InitializeComponent(); } public string Register diff --git a/src/MimaSim/MimaSim/Controls/MimaComponents/Wrappers/AccuWrapper.axaml.cs b/src/MimaSim/MimaSim/Controls/MimaComponents/Wrappers/AccuWrapper.axaml.cs index f4580d22..65b0f940 100644 --- a/src/MimaSim/MimaSim/Controls/MimaComponents/Wrappers/AccuWrapper.axaml.cs +++ b/src/MimaSim/MimaSim/Controls/MimaComponents/Wrappers/AccuWrapper.axaml.cs @@ -7,7 +7,7 @@ public partial class AccuWrapper : UserControl { public AccuWrapper() { - this.InitializeComponent(); + InitializeComponent(); } private void InitializeComponent() diff --git a/src/MimaSim/MimaSim/Controls/MimaComponents/Wrappers/AluWrapperControl.axaml.cs b/src/MimaSim/MimaSim/Controls/MimaComponents/Wrappers/AluWrapperControl.axaml.cs index 77fd83ff..9c180cc5 100644 --- a/src/MimaSim/MimaSim/Controls/MimaComponents/Wrappers/AluWrapperControl.axaml.cs +++ b/src/MimaSim/MimaSim/Controls/MimaComponents/Wrappers/AluWrapperControl.axaml.cs @@ -7,7 +7,7 @@ public partial class AluWrapperControl : UserControl { public AluWrapperControl() { - this.InitializeComponent(); + InitializeComponent(); } private void InitializeComponent() diff --git a/src/MimaSim/MimaSim/Controls/MimaComponents/Wrappers/ControlUnitWrapper.axaml.cs b/src/MimaSim/MimaSim/Controls/MimaComponents/Wrappers/ControlUnitWrapper.axaml.cs index d200ad83..ad69aa2c 100644 --- a/src/MimaSim/MimaSim/Controls/MimaComponents/Wrappers/ControlUnitWrapper.axaml.cs +++ b/src/MimaSim/MimaSim/Controls/MimaComponents/Wrappers/ControlUnitWrapper.axaml.cs @@ -7,7 +7,7 @@ public partial class ControlUnitWrapper : UserControl { public ControlUnitWrapper() { - this.InitializeComponent(); + InitializeComponent(); } private void InitializeComponent() diff --git a/src/MimaSim/MimaSim/Controls/MimaComponents/Wrappers/MemoryWrapper.axaml.cs b/src/MimaSim/MimaSim/Controls/MimaComponents/Wrappers/MemoryWrapper.axaml.cs index c819bf20..b6f93888 100644 --- a/src/MimaSim/MimaSim/Controls/MimaComponents/Wrappers/MemoryWrapper.axaml.cs +++ b/src/MimaSim/MimaSim/Controls/MimaComponents/Wrappers/MemoryWrapper.axaml.cs @@ -14,7 +14,7 @@ public MemoryWrapper() /* Handle view activation etc. */ }); - this.InitializeComponent(); + InitializeComponent(); } private void InitializeComponent() diff --git a/src/MimaSim/MimaSim/Controls/MimaControl.axaml.cs b/src/MimaSim/MimaSim/Controls/MimaControl.axaml.cs index 68b2567d..e44da073 100644 --- a/src/MimaSim/MimaSim/Controls/MimaControl.axaml.cs +++ b/src/MimaSim/MimaSim/Controls/MimaControl.axaml.cs @@ -7,7 +7,7 @@ public partial class MimaControl : UserControl { public MimaControl() { - this.InitializeComponent(); + InitializeComponent(); } private void InitializeComponent() diff --git a/src/MimaSim/MimaSim/Controls/ProgramEditorControl.axaml b/src/MimaSim/MimaSim/Controls/ProgramEditorControl.axaml index 942a71b6..7f1355ab 100644 --- a/src/MimaSim/MimaSim/Controls/ProgramEditorControl.axaml +++ b/src/MimaSim/MimaSim/Controls/ProgramEditorControl.axaml @@ -8,7 +8,8 @@ - + diff --git a/src/MimaSim/MimaSim/Controls/ProgramEditorControl.axaml.cs b/src/MimaSim/MimaSim/Controls/ProgramEditorControl.axaml.cs index 4dae2127..fac5a5f9 100644 --- a/src/MimaSim/MimaSim/Controls/ProgramEditorControl.axaml.cs +++ b/src/MimaSim/MimaSim/Controls/ProgramEditorControl.axaml.cs @@ -12,7 +12,7 @@ public ProgramEditorControl() { this.WhenActivated(disposables => { /* Handle view activation etc. */ }); - this.InitializeComponent(); + InitializeComponent(); } private void InitializeComponent() diff --git a/src/MimaSim/MimaSim/Core/Disassembler.cs b/src/MimaSim/MimaSim/Core/Disassembler.cs new file mode 100644 index 00000000..4ab6cef4 --- /dev/null +++ b/src/MimaSim/MimaSim/Core/Disassembler.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using MimaSim.MIMA; + +namespace MimaSim.Core; + +public class Disassembler(byte[] program) +{ + private static Dictionary Instructions = new(); + private int Position { get; set; } + private byte[] Program { get; } = program; + + static Disassembler() + { + var types = Assembly.GetCallingAssembly().GetTypes().Where(_ => _.GetInterfaces().Contains(typeof(IDisassemblyInstruction))); + foreach (var t in types) + { + var instance = (IDisassemblyInstruction)Activator.CreateInstance(t)!; + + Instructions.Add(instance.OpCode, instance); + } + } + + public byte Fetch() + { + return Program[Position++]; + } + + public short Fetch16() + { + var first = Fetch(); + var second = Fetch(); + + return BitConverter.ToInt16([first, second], 0); + } + + public Registers FetchRegister() + { + return (Registers)Fetch(); + } + + public string Disassemble() + { + var builder = new StringBuilder(); + + while (Position < Program.Length) + { + var op = Fetch(); + var instruction = Instructions[(OpCodes)op]; + + instruction.Dissassemble(builder, this); + } + + return builder.ToString(); + } +} \ No newline at end of file diff --git a/src/MimaSim/MimaSim/Core/IDisassemblyInstruction.cs b/src/MimaSim/MimaSim/Core/IDisassemblyInstruction.cs new file mode 100644 index 00000000..5444d31a --- /dev/null +++ b/src/MimaSim/MimaSim/Core/IDisassemblyInstruction.cs @@ -0,0 +1,11 @@ +using System.Text; +using MimaSim.MIMA; + +namespace MimaSim.Core; + +public interface IDisassemblyInstruction +{ + OpCodes OpCode { get; } + + void Dissassemble(StringBuilder builder, Disassembler disassembler); +} \ No newline at end of file diff --git a/src/MimaSim/MimaSim/Core/IInstruction.cs b/src/MimaSim/MimaSim/Core/IInstruction.cs index f233144c..1b0658a6 100644 --- a/src/MimaSim/MimaSim/Core/IInstruction.cs +++ b/src/MimaSim/MimaSim/Core/IInstruction.cs @@ -5,7 +5,7 @@ namespace MimaSim.Core; public interface IInstruction { - OpCodes Instruction { get; } + OpCodes OpCode { get; } bool Invoke(CPU cpu); } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/Core/Parsing/Tokenizer/Token.cs b/src/MimaSim/MimaSim/Core/Parsing/Tokenizer/Token.cs index 4cc4df43..0ef41984 100644 --- a/src/MimaSim/MimaSim/Core/Parsing/Tokenizer/Token.cs +++ b/src/MimaSim/MimaSim/Core/Parsing/Tokenizer/Token.cs @@ -5,7 +5,7 @@ public sealed class Token public Token(TokenKind Kind, string contents, int start, int end) { this.Kind = Kind; - this.Contents = contents; + Contents = contents; Start = start; End = end; Length = end - start; @@ -14,7 +14,7 @@ public Token(TokenKind Kind, string contents, int start, int end) public Token(TokenKind Kind, string contents) { this.Kind = Kind; - this.Contents = contents; + Contents = contents; Length = contents.Length; } diff --git a/src/MimaSim/MimaSim/Core/Parsing/Tokenizer/TokenEnumerator.cs b/src/MimaSim/MimaSim/Core/Parsing/Tokenizer/TokenEnumerator.cs index 72fdfb46..126b367d 100644 --- a/src/MimaSim/MimaSim/Core/Parsing/Tokenizer/TokenEnumerator.cs +++ b/src/MimaSim/MimaSim/Core/Parsing/Tokenizer/TokenEnumerator.cs @@ -24,7 +24,7 @@ public Token Current public void BackTrack(int pos) { - this._position = pos; + _position = pos; } public int BackTrackPos() diff --git a/src/MimaSim/MimaSim/Core/PrecedenceMap.cs b/src/MimaSim/MimaSim/Core/PrecedenceMap.cs index ec3026a0..20db1322 100644 --- a/src/MimaSim/MimaSim/Core/PrecedenceMap.cs +++ b/src/MimaSim/MimaSim/Core/PrecedenceMap.cs @@ -7,7 +7,7 @@ public class PrecedenceMap : Dictionary { public int GetPrecedence(TokenKind opKind) { - if (this.ContainsKey(opKind)) + if (ContainsKey(opKind)) { return this[opKind]; } diff --git a/src/MimaSim/MimaSim/MIMA/Components/CPU.cs b/src/MimaSim/MimaSim/MIMA/Components/CPU.cs index dc289fb3..a7fe19a2 100644 --- a/src/MimaSim/MimaSim/MIMA/Components/CPU.cs +++ b/src/MimaSim/MimaSim/MIMA/Components/CPU.cs @@ -18,7 +18,7 @@ public class CPU public ControlUnit ControlUnit = new(); public Bus DataBus = new(); - public Dictionary Instructions = new(); + public static Dictionary Instructions = new(); public Memory Memory = new((int)Math.Pow(2, 8)); public Register SAR = new("SAR"); @@ -28,6 +28,8 @@ public class CPU public Register Y = new("Y"); + public byte[] Program { get; set; } + public CPU() { ALU = new ALU(this); @@ -48,7 +50,16 @@ public CPU() }); } - public byte[] Program { get; set; } + static CPU() + { + var types = Assembly.GetCallingAssembly().GetTypes().Where(_ => _.GetInterfaces().Contains(typeof(IInstruction))); + foreach (var t in types) + { + var instance = (IInstruction)Activator.CreateInstance(t); + + Instructions.Add(instance.OpCode, instance); + } + } public byte Fetch() { @@ -95,12 +106,6 @@ public short GetRegister(byte reg) return GetRegister((Registers)reg); } - //Hack for Init all Fields - public void Init() - { - InitInstructions(); - } - public void SetRegister(Registers reg, short value) { RegisterMap.GetRegister(Enum.GetName(reg)).SetValue(value); @@ -130,15 +135,4 @@ public bool Step(OpCodes instruction) throw new Exception("unknown opcode"); } } - - private void InitInstructions() - { - var types = Assembly.GetCallingAssembly().GetTypes().Where(_ => _.GetInterfaces().Contains(typeof(IInstruction))); - foreach (var t in types) - { - var instance = (IInstruction)Activator.CreateInstance(t); - - Instructions.Add(instance.Instruction, instance); - } - } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/AddInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/AddInstruction.cs index 078f7dea..713ae4c0 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/AddInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/AddInstruction.cs @@ -1,11 +1,12 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Arithmetik; -public class AddInstruction : IInstruction +public class AddInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.ADD; + public OpCodes OpCode => OpCodes.ADD; public bool Invoke(CPU cpu) { @@ -20,4 +21,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"add"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/DecReg.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/DecReg.cs index 11bf95f9..222763a6 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/DecReg.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/DecReg.cs @@ -1,11 +1,12 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Arithmetik; -public class DecReg : IInstruction +public class DecReg : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.DEC; + public OpCodes OpCode => OpCodes.DEC; public bool Invoke(CPU cpu) { @@ -18,4 +19,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"dec {disassembler.FetchRegister()}, {disassembler.FetchRegister()}"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/DivInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/DivInstruction.cs index 9f2f39fe..c173b3a7 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/DivInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/DivInstruction.cs @@ -1,11 +1,12 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Arithmetik; -public class DivInstruction : IInstruction +public class DivInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.DIV; + public OpCodes OpCode => OpCodes.DIV; public bool Invoke(CPU cpu) { @@ -20,4 +21,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"div"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/IncReg.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/IncReg.cs index 855adf16..d8603639 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/IncReg.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/IncReg.cs @@ -1,11 +1,12 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Arithmetik; -public class IncReg : IInstruction +public class IncReg : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.INC; + public OpCodes OpCode => OpCodes.INC; public bool Invoke(CPU cpu) { @@ -18,4 +19,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"inc {disassembler.FetchRegister()}, {disassembler.FetchRegister()}"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/MulInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/MulInstruction.cs index 3ab3ea41..6294fd01 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/MulInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/MulInstruction.cs @@ -1,11 +1,12 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Arithmetik; -public class MulInstruction : IInstruction +public class MulInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.MUL; + public OpCodes OpCode => OpCodes.MUL; public bool Invoke(CPU cpu) { @@ -20,4 +21,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"mul"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/SubInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/SubInstruction.cs index 44362733..3435cb44 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/SubInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Arithmetik/SubInstruction.cs @@ -1,11 +1,12 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Arithmetik; -public class SubInstruction : IInstruction +public class SubInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.SUB; + public OpCodes OpCode => OpCodes.SUB; public bool Invoke(CPU cpu) { @@ -20,4 +21,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"sub"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Compare/EqualsCompareInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Compare/EqualsCompareInstruction.cs index 173ccc92..23ae2f68 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Compare/EqualsCompareInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Compare/EqualsCompareInstruction.cs @@ -1,11 +1,12 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Compare; -public class EqualsCompareInstruction : IInstruction +public class EqualsCompareInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.CMPEQ; + public OpCodes OpCode => OpCodes.CMPEQ; public bool Invoke(CPU cpu) { @@ -18,4 +19,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"cmpeq {disassembler.FetchRegister()}, {disassembler.FetchRegister()}"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Compare/GreaterEqualsCompareInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Compare/GreaterEqualsCompareInstruction.cs index 97710e40..b87550ac 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Compare/GreaterEqualsCompareInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Compare/GreaterEqualsCompareInstruction.cs @@ -1,11 +1,12 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Compare; -public class GreaterEqualsCompareInstruction : IInstruction +public class GreaterEqualsCompareInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.CMPGE; + public OpCodes OpCode => OpCodes.CMPGE; public bool Invoke(CPU cpu) { @@ -18,4 +19,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"cmpge {disassembler.FetchRegister()}, {disassembler.FetchRegister()}"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Compare/GreaterThanCompareInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Compare/GreaterThanCompareInstruction.cs index 99b02824..fe0282a7 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Compare/GreaterThanCompareInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Compare/GreaterThanCompareInstruction.cs @@ -1,11 +1,12 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Compare; -public class GreaterThanCompareInstruction : IInstruction +public class GreaterThanCompareInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.CMPGT; + public OpCodes OpCode => OpCodes.CMPGT; public bool Invoke(CPU cpu) { @@ -18,4 +19,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"cmpgt {disassembler.FetchRegister()}, {disassembler.FetchRegister()}"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Compare/LessEqualsCompareInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Compare/LessEqualsCompareInstruction.cs index ac20a2a5..5a2de539 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Compare/LessEqualsCompareInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Compare/LessEqualsCompareInstruction.cs @@ -1,11 +1,12 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Compare; -public class LessEqualsCompareInstruction : IInstruction +public class LessEqualsCompareInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.CMPLE; + public OpCodes OpCode => OpCodes.CMPLE; public bool Invoke(CPU cpu) { @@ -18,4 +19,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"cmple {disassembler.FetchRegister()}, {disassembler.FetchRegister()}"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Compare/LessThanCompareInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Compare/LessThanCompareInstruction.cs index 57449345..0d227f46 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Compare/LessThanCompareInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Compare/LessThanCompareInstruction.cs @@ -1,11 +1,12 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Compare; -public class LessThanCompareInstruction : IInstruction +public class LessThanCompareInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.CMPLT; + public OpCodes OpCode => OpCodes.CMPLT; public bool Invoke(CPU cpu) { @@ -18,4 +19,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"cmplt {disassembler.FetchRegister()}, {disassembler.FetchRegister()}"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Compare/NotCompareInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Compare/NotCompareInstruction.cs index f401a25f..2502b1f2 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Compare/NotCompareInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Compare/NotCompareInstruction.cs @@ -1,25 +1,24 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Compare; -public class NotCompareInstruction : IInstruction +public class NotCompareInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.CMPN; + public OpCodes OpCode => OpCodes.CMPN; public bool Invoke(CPU cpu) { var accu = cpu.GetRegister(Registers.Accumulator); - if (accu == 1) - { - cpu.SetRegister(Registers.Accumulator, (short)0); - } - else - { - cpu.SetRegister(Registers.Accumulator, (short)1); - } + cpu.SetRegister(Registers.Accumulator, accu == 1 ? (short)0 : (short)1); return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"cmpn {disassembler.FetchRegister()}, {disassembler.FetchRegister()}"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Compare/NotEqualsCompareInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Compare/NotEqualsCompareInstruction.cs index 5e1785c5..b695f2b9 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Compare/NotEqualsCompareInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Compare/NotEqualsCompareInstruction.cs @@ -1,11 +1,12 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Compare; -public class NotEqualsCompareInstruction : IInstruction +public class NotEqualsCompareInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.CMPNEQ; + public OpCodes OpCode => OpCodes.CMPNEQ; public bool Invoke(CPU cpu) { @@ -18,4 +19,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"cmpneq {disassembler.FetchRegister()}, {disassembler.FetchRegister()}"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/ExitInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/ExitInstruction.cs index ccbcc6d5..ffe14859 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/ExitInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/ExitInstruction.cs @@ -1,13 +1,15 @@ -using MimaSim.Core; +using System; +using System.Text; +using MimaSim.Core; using MimaSim.Messages; using MimaSim.MIMA.Components; using ReactiveUI; namespace MimaSim.MIMA.Instructions; -public class ExitInstruction : IInstruction +public class ExitInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.EXIT; + public OpCodes OpCode => OpCodes.EXIT; public bool Invoke(CPU cpu) { @@ -16,4 +18,9 @@ public bool Invoke(CPU cpu) return true; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine("exit"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Jumps/JmpConditionalInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Jumps/JmpConditionalInstruction.cs index d77459d6..1f05f7e2 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Jumps/JmpConditionalInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Jumps/JmpConditionalInstruction.cs @@ -1,17 +1,18 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Jumps; public class JmpConditionalInstruction : IInstruction { - public OpCodes Instruction => OpCodes.JMPC; + public OpCodes OpCode => OpCodes.JMPC; public bool Invoke(CPU cpu) { - var address = cpu.Fetch(); + var address = cpu.Fetch16(); - var cond = cpu.GetRegister(Registers.Accumulator) == 0 ? false : true; + var cond = cpu.GetRegister(Registers.Accumulator) != 0; if (cond) { @@ -20,4 +21,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"jmpc {disassembler.Fetch()}"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Jumps/JmpInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Jumps/JmpInstruction.cs index 1a125411..6d203c07 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Jumps/JmpInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Jumps/JmpInstruction.cs @@ -1,18 +1,24 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Jumps; -public class JmpInstruction : IInstruction +public class JmpInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.JMP; + public OpCodes OpCode => OpCodes.JMP; public bool Invoke(CPU cpu) { - var address = cpu.Fetch(); + var address = cpu.Fetch16(); cpu.SetRegister(Registers.IAR, address); return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"jmp {disassembler.Fetch16()}"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/LoadInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/LoadInstruction.cs index 73cbad0a..d6414a75 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/LoadInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/LoadInstruction.cs @@ -1,11 +1,12 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions; -public class LoadInstruction : IInstruction +public class LoadInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.LOAD; + public OpCodes OpCode => OpCodes.LOAD; public bool Invoke(CPU cpu) { @@ -14,4 +15,9 @@ public bool Invoke(CPU cpu) return true; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"load {disassembler.Fetch16()}"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Logical/AndInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Logical/AndInstruction.cs index 1cc06f23..2744d7b2 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Logical/AndInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Logical/AndInstruction.cs @@ -1,11 +1,12 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Logical; -public class AndInstruction : IInstruction +public class AndInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.AND; + public OpCodes OpCode => OpCodes.AND; public bool Invoke(CPU cpu) { @@ -17,4 +18,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"and {disassembler.FetchRegister()}, {disassembler.FetchRegister()}"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Logical/NotInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Logical/NotInstruction.cs index fc779876..b6fce12b 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Logical/NotInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Logical/NotInstruction.cs @@ -1,11 +1,12 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Logical; -public class NotInstruction : IInstruction +public class NotInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.NOT; + public OpCodes OpCode => OpCodes.NOT; public bool Invoke(CPU cpu) { @@ -16,4 +17,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"not {disassembler.FetchRegister()}"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Logical/OrInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Logical/OrInstruction.cs index 8b18ec0a..aff277b6 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Logical/OrInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Logical/OrInstruction.cs @@ -1,11 +1,12 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Logical; -public class OrInstruction : IInstruction +public class OrInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.OR; + public OpCodes OpCode => OpCodes.OR; public bool Invoke(CPU cpu) { @@ -17,4 +18,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"or {disassembler.FetchRegister()}, {disassembler.FetchRegister()}"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Logical/XOrRegRegInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Logical/XOrRegRegInstruction.cs index 301f5cc0..4428e642 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Logical/XOrRegRegInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Logical/XOrRegRegInstruction.cs @@ -1,11 +1,12 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Logical; -public class XOrRegRegInstruction : IInstruction +public class XOrRegRegInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.XOR; + public OpCodes OpCode => OpCodes.XOR; public bool Invoke(CPU cpu) { @@ -17,4 +18,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"xor {disassembler.FetchRegister()}, {disassembler.FetchRegister()}"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Move/MovMemMemInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Move/MovMemMemInstruction.cs index 2e1fe801..95f771a8 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Move/MovMemMemInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Move/MovMemMemInstruction.cs @@ -1,11 +1,12 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Move; -public class MovMemMemInstruction : IInstruction +public class MovMemMemInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.MOV_MEM_MEM; + public OpCodes OpCode => OpCodes.MOV_MEM_MEM; public bool Invoke(CPU cpu) { @@ -21,4 +22,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"mov {disassembler.Fetch16()}, {disassembler.Fetch16()}"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Move/MovMemRegInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Move/MovMemRegInstruction.cs index d86442bc..4bcb3040 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Move/MovMemRegInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Move/MovMemRegInstruction.cs @@ -1,11 +1,13 @@ -using MimaSim.Core; +using System; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Move; -public class MovMemRegInstruction : IInstruction +public class MovMemRegInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.MOV_MEM_REG; + public OpCodes OpCode => OpCodes.MOV_MEM_REG; public bool Invoke(CPU cpu) { @@ -19,4 +21,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"mov {disassembler.Fetch16()}, {disassembler.FetchRegister()}"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Move/MovRegMemInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Move/MovRegMemInstruction.cs index e515ee07..8f56b181 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Move/MovRegMemInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Move/MovRegMemInstruction.cs @@ -1,11 +1,12 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Move; -public class MovRegMemInstruction : IInstruction +public class MovRegMemInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.MOV_REG_MEM; + public OpCodes OpCode => OpCodes.MOV_REG_MEM; public bool Invoke(CPU cpu) { @@ -19,4 +20,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"mov {disassembler.FetchRegister()}, {disassembler.Fetch16()}"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Move/MovRegRegInstructiion.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Move/MovRegRegInstructiion.cs index cb8c8072..df32643e 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Move/MovRegRegInstructiion.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Move/MovRegRegInstructiion.cs @@ -1,11 +1,12 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Move; -public class MovRegRegInstructiion : IInstruction +public class MovRegRegInstructiion : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.MOV_REG_REG; + public OpCodes OpCode => OpCodes.MOV_REG_REG; public bool Invoke(CPU cpu) { @@ -17,4 +18,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"mov {disassembler.FetchRegister()}, {disassembler.FetchRegister()}"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/NOPInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/NOPInstruction.cs index 76b82fa6..c5ddfb3d 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/NOPInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/NOPInstruction.cs @@ -1,11 +1,16 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions; -public class NOPInstruction : IInstruction +public class NOPInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.NOP; + public OpCodes OpCode => OpCodes.NOP; + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine("nop"); + } public bool Invoke(CPU cpu) { diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Shifting/LsfRegRegInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Shifting/LsfRegRegInstruction.cs index d6406dfe..dcea429f 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Shifting/LsfRegRegInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Shifting/LsfRegRegInstruction.cs @@ -1,11 +1,12 @@ -using MimaSim.Core; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Shifting; -public class LsfRegRegInstruction : IInstruction +public class LsfRegRegInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.LSHIFT; + public OpCodes OpCode => OpCodes.LSHIFT; public bool Invoke(CPU cpu) { @@ -17,4 +18,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"lshift {disassembler.FetchRegister()}, {disassembler.FetchRegister()}"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/Instructions/Shifting/RsfRegRegInstruction.cs b/src/MimaSim/MimaSim/MIMA/Instructions/Shifting/RsfRegRegInstruction.cs index 8d66712e..4797edb2 100644 --- a/src/MimaSim/MimaSim/MIMA/Instructions/Shifting/RsfRegRegInstruction.cs +++ b/src/MimaSim/MimaSim/MIMA/Instructions/Shifting/RsfRegRegInstruction.cs @@ -1,11 +1,13 @@ -using MimaSim.Core; +using System; +using System.Text; +using MimaSim.Core; using MimaSim.MIMA.Components; namespace MimaSim.MIMA.Instructions.Shifting; -public class RsfRegRegInstruction : IInstruction +public class RsfRegRegInstruction : IInstruction, IDisassemblyInstruction { - public OpCodes Instruction => OpCodes.RSHIFT; + public OpCodes OpCode => OpCodes.RSHIFT; public bool Invoke(CPU cpu) { @@ -17,4 +19,9 @@ public bool Invoke(CPU cpu) return false; } + + public void Dissassemble(StringBuilder builder, Disassembler disassembler) + { + builder.AppendLine($"rshift {disassembler.FetchRegister()}, {disassembler.FetchRegister()}"); + } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/Resources/Icons.axaml b/src/MimaSim/MimaSim/Resources/Icons.axaml index 49d3cb74..e80afe4f 100644 --- a/src/MimaSim/MimaSim/Resources/Icons.axaml +++ b/src/MimaSim/MimaSim/Resources/Icons.axaml @@ -7,4 +7,5 @@ M103.6125 54.5625C121.9125 54.5625 132.1875 69.375 132.1875 95.90625C132.1875 122.38125 121.9125 137.2125 103.6125 137.2125C85.275 137.2125 75 122.4 75 95.90625C75 69.375 85.275 54.54375 103.6125 54.54375zM88.0125 95.90625C88.0125 115.59375 93.45 126.13125 103.6125 126.13125C110.325 126.13125 114.99375 121.5 117.35625 112.6125L88.125 91.18125A131.25 131.25 0 0 0 88.0125 95.90625M103.6125 65.64375C96.8625 65.64375 92.25 70.25625 89.8875 79.10625L119.0625 100.575Q119.15625 98.325 119.15625 95.90625C119.15625 76.18125 113.71875 65.64375 103.6125 65.64375M203.53125 56.25V67.40625H182.4375V135.525H169.5L147.1875 120.7875V107.8875L168.4875 121.875H169.425V67.3875H147.3000000000001V56.25H203.5500000000001zM75 300A37.5 37.5 0 0 1 37.5 262.5V37.5A37.5 37.5 0 0 1 75 0H225A37.5 37.5 0 0 1 262.5 37.5V262.5A37.5 37.5 0 0 1 225 300zM75 281.25H225A18.75 18.75 0 0 0 243.75 262.5V37.5A18.75 18.75 0 0 0 225 18.75H75A18.75 18.75 0 0 0 56.25 37.5V262.5A18.75 18.75 0 0 0 75 281.25 M150 18.75A131.25 131.25 0 1 0 150 281.25A131.25 131.25 0 0 0 150 18.75M150 0A150 150 0 1 1 150 300A150 150 0 0 1 150 0M93.75 178.125A28.125 28.125 0 0 0 121.875 206.25H178.125A28.125 28.125 0 0 0 206.25 178.125V121.875A28.125 28.125 0 0 0 178.125 93.75H121.875A28.125 28.125 0 0 0 93.75 121.875z M240.1666666666667 873.7083333333334C228.0833333333334 871.2083333333334 215.9583333333333 860.4583333333334 211.4166666666667 848.2916666666667L208.75 841.1666666666667L208.75 500L208.75 158.8333333333335L211.4166666666667 151.6666666666668C214.8333333333333 142.5833333333334 223.1666666666667 133.5833333333334 232.3333333333333 129.0833333333334C238.3333333333333 126.1250000000001 240.9166666666667 125.6250000000001 250 125.6250000000001C259.0833333333333 125.6250000000001 261.6666666666667 126.1250000000001 267.6666666666667 129.0833333333334C276.8333333333333 133.5833333333334 285.1666666666667 142.5833333333334 288.5833333333333 151.6666666666668L291.25 158.8333333333335L291.25 500L291.25 841.1666666666667L288.5833333333333 848.3333333333334C281.5833333333333 866.9583333333334 260.5416666666667 878 240.1666666666667 873.7083333333334M406.75 873.6666666666666C398.7916666666667 871.75 388.6666666666667 865 383.5 858.125C374.25 845.9166666666667 374.9583333333333 876.8333333333334 375.2916666666667 497.875L375.625 156.8333333333334L379.75 148.4583333333334C386.75 134.2083333333334 398.2083333333333 126.5833333333334 414.375 125.3750000000001C431.2916666666667 124.125 415.875 112.7083333333333 649.875 299.9166666666668C766.5 393.2083333333334 863.5 471.4583333333334 865.4999999999999 473.8333333333334C872.125 481.6666666666667 874.3749999999999 488.25 874.3749999999999 500C874.3749999999999 509 873.8333333333334 511.6666666666667 871 517.5C869.125 521.2916666666667 865.4999999999999 526.4583333333334 862.8749999999999 528.9583333333334C852.4166666666665 539.0833333333334 440.2083333333333 867.7916666666667 434.3333333333333 870.6666666666666C427.125 874.25 414.75 875.5833333333334 406.75 873.6666666666666M766.125 500C766.125 499.6666666666667 696.9583333333333 444.1250000000001 612.4166666666666 376.5416666666668L458.7499999999999 253.75L458.7499999999999 500L458.7499999999999 746.25L612.4166666666666 623.4583333333333C696.9583333333333 555.875 766.125 500.3333333333333 766.125 500 + M64 192h256v-256h-256v256zM384 192h256v-256h-256v256zM704 192h256v-256h-256v256zM64 512h256v-256h-256v256zM64 832h256v-256h-256v256zM384 512h256v-256h-256v256zM448 896h256v-256h-256v256zM704 512h256v-256h-256v256zM832 960h192v-192h-192v192z diff --git a/src/MimaSim/MimaSim/Tabs/DocumentationTab.axaml.cs b/src/MimaSim/MimaSim/Tabs/DocumentationTab.axaml.cs index 0e8483b7..6956e805 100644 --- a/src/MimaSim/MimaSim/Tabs/DocumentationTab.axaml.cs +++ b/src/MimaSim/MimaSim/Tabs/DocumentationTab.axaml.cs @@ -9,7 +9,7 @@ public partial class DocumentationTab : UserControl, IUITab { public DocumentationTab() { - this.InitializeComponent(); + InitializeComponent(); } public int Index => 2; diff --git a/src/MimaSim/MimaSim/Tabs/ExecutionTab.axaml.cs b/src/MimaSim/MimaSim/Tabs/ExecutionTab.axaml.cs index ccbe7477..f0bc2747 100644 --- a/src/MimaSim/MimaSim/Tabs/ExecutionTab.axaml.cs +++ b/src/MimaSim/MimaSim/Tabs/ExecutionTab.axaml.cs @@ -14,7 +14,7 @@ public ExecutionTab() this.WhenActivated(disposables => { /* Handle view activation etc. */ }); - this.InitializeComponent(); + InitializeComponent(); } public int Index => 1; diff --git a/src/MimaSim/MimaSim/ViewModels/RawPopupViewModel.cs b/src/MimaSim/MimaSim/ViewModels/DisassemblyPopupViewModel.cs similarity index 63% rename from src/MimaSim/MimaSim/ViewModels/RawPopupViewModel.cs rename to src/MimaSim/MimaSim/ViewModels/DisassemblyPopupViewModel.cs index 3f7537cf..b81d0699 100644 --- a/src/MimaSim/MimaSim/ViewModels/RawPopupViewModel.cs +++ b/src/MimaSim/MimaSim/ViewModels/DisassemblyPopupViewModel.cs @@ -3,14 +3,15 @@ using ReactiveUI; using System.Linq; using System.Windows.Input; +using MimaSim.Core; namespace MimaSim.ViewModels; -public class RawPopupViewModel : ReactiveObject, IActivatableViewModel +public class DisassemblyPopupViewModel : ReactiveObject, IActivatableViewModel { private string _raw; - public RawPopupViewModel() + public DisassemblyPopupViewModel() { CloseCommand = ReactiveCommand.Create(() => DialogService.Close()); Raw = GetRawString(); @@ -29,16 +30,8 @@ public string Raw private string GetRawString() { var raw = CPU.Instance.Program; + var disassembler = new Disassembler(raw); - return string.Join(' ', raw.Select(_ => - { - var result = (_).ToString("x"); - if (result.Length == 1) - { - result = "0" + result; - } - - return result; - })).ToUpper(); + return disassembler.Disassemble(); } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/ViewModels/ExecutionTabViewModel.cs b/src/MimaSim/MimaSim/ViewModels/ExecutionTabViewModel.cs index 0fc49537..4d66914d 100644 --- a/src/MimaSim/MimaSim/ViewModels/ExecutionTabViewModel.cs +++ b/src/MimaSim/MimaSim/ViewModels/ExecutionTabViewModel.cs @@ -1,5 +1,4 @@ -using Avalonia.Controls; -using MimaSim.Controls; +using MimaSim.Controls; using MimaSim.Controls.MimaComponents.Popups; using MimaSim.Core; using MimaSim.Core.Parsing; @@ -26,10 +25,13 @@ public class ExecutionTabViewModel : ReactiveObject, IActivatableViewModel private string _selectedSample; private string _source; private string[] _sampleNames; + private bool _isCompiled; public ObservableCollection LanguageNames { get; } public ViewModelActivator Activator => new(); + public ICommand CompileCommand { get; set; } public ICommand LoadCommand { get; set; } + public ICommand SaveCommand { get; set; } public ICommand OpenClockSettingsCommand { get; set; } public ICommand OpenErrorPopupCommand { get; set; } public ICommand OpenMemoryPopupCommand { get; set; } @@ -41,7 +43,11 @@ public bool RunMode set => this.RaiseAndSetIfChanged(ref _runMode, value); } - public ICommand SaveCommand { get; set; } + public bool IsCompiled + { + get => _isCompiled; + set => this.RaiseAndSetIfChanged(ref _isCompiled, value); + } public LanguageName SelectedLanguage { @@ -76,7 +82,11 @@ public string[] SampleNames public string Source { get => _source; - set => this.RaiseAndSetIfChanged(ref _source, value); + set + { + this.RaiseAndSetIfChanged(ref _source, value); + IsCompiled = false; + } } public ICommand StepCommand { get; set; } @@ -88,26 +98,29 @@ public ExecutionTabViewModel() { OpenErrorPopupCommand = ReactiveCommand.Create(() => DialogService.Open()); - OpenClockSettingsCommand = DialogService.CreateOpenCommand(new ClockSettingsPopupControl(), new ClockSettingsPopupViewModel()); + OpenClockSettingsCommand = + DialogService.CreateOpenCommand(new ClockSettingsPopupControl(), new ClockSettingsPopupViewModel()); StepCommand = ReactiveCommand.Create(() => CPU.Instance.Step()); StopCommand = ReactiveCommand.Create(() => CPU.Instance.Clock.Stop()); - LanguageNames = new ObservableCollection(Enum.GetNames().Select(_ => Enum.Parse(_))); + LanguageNames = + new ObservableCollection(Enum.GetNames() + .Select(_ => Enum.Parse(_))); SelectedLanguage = LanguageNames.FirstOrDefault(); ViewRawCommand = ReactiveCommand.Create(() => { - DialogService.Open(new RawViewPopupControl(), new RawPopupViewModel()); + DialogService.Open(new DisassemblyViewPopupControl(), new DisassemblyPopupViewModel()); }); OpenMemoryPopupCommand = DialogService.CreateOpenCommand(new MemoryPopupControl(), new MemoryPopupViewModel()); - IStorageProvider storage = Locator.Current.GetService(); + var storage = Locator.Current.GetService(); LoadCommand = ReactiveCommand.Create(async () => { - var filenames = await storage.OpenFilePickerAsync(new FilePickerOpenOptions() + var filenames = await storage!.OpenFilePickerAsync(new FilePickerOpenOptions() { Title = "Programm laden" }); @@ -119,48 +132,54 @@ public ExecutionTabViewModel() SaveCommand = ReactiveCommand.Create(async () => { - var file = await storage.SaveFilePickerAsync(new() { Title = "Programm speichern" }); - await using var writer = new StreamWriter(await file.OpenWriteAsync()); + var file = await storage!.SaveFilePickerAsync(new() { Title = "Programm speichern" }); + await using var writer = new StreamWriter(await file!.OpenWriteAsync()); writer.Write(Source); }); + DiagnosticBag diagnostics = new(); + CompileCommand = ReactiveCommand.Create(() => + { + if (string.IsNullOrEmpty(Source)) + { + RunMode = false; + DialogService.OpenError("Bitte einen Programmtext eingeben. Dieser darf nicht leer sein!"); + return; + } + + var translator = SourceTextTranslatorSelector.Select(SelectedLanguage); + + diagnostics = new(); + CPU.Instance.Program = translator.ToRaw(Source, ref diagnostics); + + IsCompiled = true; + }); + RunCodeCommand = ReactiveCommand.Create(() => { - if (!string.IsNullOrEmpty(Source)) + if (RunMode) { - if (RunMode) + if (!diagnostics.IsEmpty) { - var translator = SourceTextTranslatorSelector.Select(SelectedLanguage); - DiagnosticBag diagnostics = new(); - CPU.Instance.Program = translator.ToRaw(Source, ref diagnostics); - - if (!diagnostics.IsEmpty) - { - RunMode = false; - string[] errors = diagnostics.GetAll(); - - DialogService.OpenError(string.Join('\n', errors)); - } - else - { - RegisterMap.GetRegister("IAR").SetValue(0); - - CPU.Instance.Clock.Start(); - } + RunMode = false; + string[] errors = diagnostics.GetAll(); + + DialogService.OpenError(string.Join('\n', errors)); } else { - CPU.Instance.Clock.Stop(); + RegisterMap.GetRegister("IAR").SetValue(0); - BusRegistry.DeactivateAll(); - BusRegistry.DeactivateBus("controlunit_iar"); + CPU.Instance.Clock.Start(); } } else { - RunMode = false; - DialogService.OpenError("Bitte einen Programmtext eingeben. Dieser darf nicht leer sein!"); + CPU.Instance.Clock.Stop(); + + BusRegistry.DeactivateAll(); + BusRegistry.DeactivateBus("controlunit_iar"); } }); diff --git a/src/MimaSim/MimaTest/ExecutionTests.cs b/src/MimaSim/MimaTest/ExecutionTests.cs index bcb9c4b4..a0a9d105 100644 --- a/src/MimaSim/MimaTest/ExecutionTests.cs +++ b/src/MimaSim/MimaTest/ExecutionTests.cs @@ -1,4 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; +using MimaSim.MIMA; using MimaSim.MIMA.Components; namespace MimaTest; @@ -11,10 +12,9 @@ public void TestRaw() { var program = new byte[] { 0x04, 0x2A, 00, 0x40, 0x01, 0x02, 0x04, 0x02, 00, 0x40, 0x01, 0x03, 0x18 }; - CPU.Instance.Init(); CPU.Instance.Program = program; - while (true) + while (CPU.Instance.GetRegister(Registers.IAR) < program.Length) { CPU.Instance.Step(); }