From 64f0d01906c4534a58f30dd8f6175252687db74b Mon Sep 17 00:00:00 2001 From: Ian C Date: Wed, 28 Mar 2012 22:52:22 +0000 Subject: Finished working disassembler/tracing. --- WPZX81/WPZX81/BaseViewModel.cs | 67 ------ WPZX81/WPZX81/DisassemblerLine.cs | 34 --- WPZX81/WPZX81/DisassemblerPage.xaml | 138 ++++++++---- WPZX81/WPZX81/DisassemblerPage.xaml.cs | 3 +- WPZX81/WPZX81/DisassemblerViewModel.cs | 258 ---------------------- WPZX81/WPZX81/ViewModels/BaseViewModel.cs | 67 ++++++ WPZX81/WPZX81/ViewModels/DisassemblerLine.cs | 34 +++ WPZX81/WPZX81/ViewModels/DisassemblerViewModel.cs | 253 +++++++++++++++++++++ WPZX81/WPZX81/WPZX81.csproj | 10 +- WPZX81/WPZX81/ZX81/Emulation.cs | 3 - 10 files changed, 456 insertions(+), 411 deletions(-) delete mode 100644 WPZX81/WPZX81/BaseViewModel.cs delete mode 100644 WPZX81/WPZX81/DisassemblerLine.cs delete mode 100644 WPZX81/WPZX81/DisassemblerViewModel.cs create mode 100644 WPZX81/WPZX81/ViewModels/BaseViewModel.cs create mode 100644 WPZX81/WPZX81/ViewModels/DisassemblerLine.cs create mode 100644 WPZX81/WPZX81/ViewModels/DisassemblerViewModel.cs diff --git a/WPZX81/WPZX81/BaseViewModel.cs b/WPZX81/WPZX81/BaseViewModel.cs deleted file mode 100644 index ae729e6..0000000 --- a/WPZX81/WPZX81/BaseViewModel.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using System.ComponentModel; -using System.Net; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Documents; -using System.Windows.Ink; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Animation; -using System.Windows.Shapes; - -namespace WPZX81 -{ - /// - /// Provides a base for view models. - /// - public class BaseViewModel : INotifyPropertyChanged - { - - #region SetValue - - /// - /// Sets a value in the model. - /// - /// The type of the value. - /// A reference to the member variable. - /// The new value. - /// The propertys to change if the value has changed. - protected void SetValue(ref T member, T value, params string[] names) - { - if (!value.Equals(member)) - { - member = value; - - foreach (string name in names) - { - NotifyPropertyChanged(name); - } - } - } - - #endregion - - #region Notify - - /// - /// Notifies handlers of a property change. - /// - /// The property's name. - protected void NotifyPropertyChanged(string propertyName) - { - if (PropertyChanged != null) - { - PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); - } - } - - #endregion - - #region INotifyPropertyChanged Members - - public event PropertyChangedEventHandler PropertyChanged; - - #endregion - } -} diff --git a/WPZX81/WPZX81/DisassemblerLine.cs b/WPZX81/WPZX81/DisassemblerLine.cs deleted file mode 100644 index 6618fc1..0000000 --- a/WPZX81/WPZX81/DisassemblerLine.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Net; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Documents; -using System.Windows.Ink; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Animation; -using System.Windows.Shapes; - -namespace WPZX81 -{ - /// - /// Represents a line of disassembly. - /// - public class DisassemblerLine - { - /// - /// The address part. - /// - public string Address {get; set;} - - /// - /// The assembly opcode part. - /// - public string Opcode {get; set;} - - /// - /// The hexdump part. - /// - public string Hexdump {get; set;} - } -} diff --git a/WPZX81/WPZX81/DisassemblerPage.xaml b/WPZX81/WPZX81/DisassemblerPage.xaml index 3c87af6..16d7e53 100644 --- a/WPZX81/WPZX81/DisassemblerPage.xaml +++ b/WPZX81/WPZX81/DisassemblerPage.xaml @@ -7,6 +7,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:res="clr-namespace:WPZX81.Resources" + xmlns:conv="clr-namespace:WPZX81.Converters" FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}" @@ -16,31 +17,49 @@ + + + + + @@ -69,13 +88,9 @@ - - - - - + @@ -108,28 +123,24 @@ Grid.Row="0" Grid.Column="6" /> - - - - - + VerticalAlignment="Top" BorderThickness="2" + BorderBrush="DarkBlue" > + + + + + + + + + + + + + + + - - + + + + + + + + diff --git a/WPZX81/WPZX81/DisassemblerPage.xaml.cs b/WPZX81/WPZX81/DisassemblerPage.xaml.cs index f5b1aa5..63717bb 100644 --- a/WPZX81/WPZX81/DisassemblerPage.xaml.cs +++ b/WPZX81/WPZX81/DisassemblerPage.xaml.cs @@ -1,6 +1,6 @@ using System; -using System.ComponentModel; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Net; using System.Windows; @@ -11,6 +11,7 @@ using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsoft.Phone.Controls; +using WPZX81.ViewModels; namespace WPZX81 { diff --git a/WPZX81/WPZX81/DisassemblerViewModel.cs b/WPZX81/WPZX81/DisassemblerViewModel.cs deleted file mode 100644 index b0ff2f7..0000000 --- a/WPZX81/WPZX81/DisassemblerViewModel.cs +++ /dev/null @@ -1,258 +0,0 @@ -using System; -using System.Net; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Documents; -using System.Windows.Ink; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Animation; -using System.Windows.Shapes; -using Noddybox.Emulation.EightBit.Z80; -using System.Collections.Generic; - -namespace WPZX81 -{ - /// - /// Implements a view model for the diassembler page. - /// - public class DisassemblerViewModel : BaseViewModel - { - #region Private data - - private Z80Cpu z80; - private int a; - private string flags; - private int bc; - private int de; - private int hl; - private int af_; - private int bc_; - private int de_; - private int hl_; - private int ix; - private int iy; - private int sp; - private int pc; - private int i; - private int r; - private int im; - private string iff1; - private string iff2; - private uint executedInstructions; - - #endregion - - #region Private methods - - private void Update() - { - Z80Cpu z80 = Shared.ZX81.Z80; - - A = z80.Acummulator; - BC = z80.BC_Register.reg; - DE = z80.DE_Register.reg; - HL = z80.HL_Register.reg; - IX = z80.IX_Register.reg; - IY = z80.IY_Register.reg; - AF_ = z80.AF_Alternate.reg; - BC_ = z80.BC_Alternate.reg; - DE_ = z80.DE_Alternate.reg; - HL_ = z80.HL_Alternate.reg; - PC = z80.ProgramCounter; - SP = z80.StackPointer; - ExecutedInstructions = z80.ExecutedInstructions; - I = z80.InterruptVector; - R = z80.Refresh; - IFF1 = z80.IFF1_Register ? "ON":"OFF"; - IFF2 = z80.IFF2_Register ? "ON":"OFF"; - - char[] names = new char[8] {'C', 'N', 'P', '3', 'H', '5', 'Z', 'S'}; - char[] flags = new char[8]; - int f; - - for(f = 0; f < 8; f++) - { - if (((int)z80.StatusFlags & (1 << f)) == (1 << f)) - { - flags[7-f] = names[7-f]; - } - else - { - flags[7-f] = '-'; - } - } - - Flags = new String(flags); - } - - #endregion - - #region Properties - - public int A - { - get {return a;} - set {SetValue(ref a, value, "A");} - } - - public string Flags - { - get {return flags;} - set {SetValue(ref flags, value, "Flags");} - } - - public int BC - { - get {return bc;} - set {SetValue(ref bc, value, "BC");} - } - - public int DE - { - get {return de;} - set {SetValue(ref de, value, "DE");} - } - - public int HL - { - get {return hl;} - set {SetValue(ref hl, value, "HL");} - } - - public int AF_ - { - get {return af_;} - set {SetValue(ref af_, value, "AF_");} - } - - public int BC_ - { - get {return bc_;} - set {SetValue(ref bc_, value, "BC_");} - } - - public int DE_ - { - get {return de_;} - set {SetValue(ref de_, value, "DE_");} - } - - public int HL_ - { - get {return hl_;} - set {SetValue(ref hl_, value, "HL_");} - } - - public int IX - { - get {return ix;} - set {SetValue(ref ix, value, "IX");} - } - - public int IY - { - get {return iy;} - set {SetValue(ref iy, value, "IY");} - } - - public int SP - { - get {return sp;} - set {SetValue(ref sp, value, "SP");} - } - - public int PC - { - get {return pc;} - set {SetValue(ref pc, value, "PC", "Disassembly");} - } - - public uint ExecutedInstructions - { - get {return executedInstructions;} - set {SetValue(ref executedInstructions, value, "ExecutedInstructions");} - } - - public int I - { - get {return i;} - set {SetValue(ref i, value, "I");} - } - - public int R - { - get {return r;} - set {SetValue(ref r, value, "R");} - } - public int IM - { - get {return im;} - set {SetValue(ref im, value, "IM");} - } - public string IFF1 - { - get {return iff1;} - set {SetValue(ref iff1, value, "ExecutedInstructions");} - } - public string IFF2 - { - get {return iff2;} - set {SetValue(ref iff2, value, "ExecutedInstructions");} - } - - public IEnumerable Disassembly - { - get - { - List list = new List(); - - ushort pc = Shared.ZX81.Z80.ProgramCounter; - string address; - string opcode; - string hexdump; - - for(int f = 0 ; f < 15; f++) - { - pc = Shared.ZX81.Disassembler.Disassemble(pc, out address, out opcode, out hexdump); - list.Add(new DisassemblerLine() {Address = address, Opcode = opcode, Hexdump = hexdump}); - } - - return list; - } - } - - #endregion - - #region Public methods - - /// - /// Run the ZX81 for a step. - /// - public void Step() - { - Shared.ZX81.Step(); - Update(); - } - - /// - /// Run the ZX81 for a frame. - /// - public void Run() - { - Shared.ZX81.Run(); - Update(); - } - - #endregion - - #region Constructors - - public DisassemblerViewModel() - { - Update(); - } - - #endregion - } -} diff --git a/WPZX81/WPZX81/ViewModels/BaseViewModel.cs b/WPZX81/WPZX81/ViewModels/BaseViewModel.cs new file mode 100644 index 0000000..6a96d0b --- /dev/null +++ b/WPZX81/WPZX81/ViewModels/BaseViewModel.cs @@ -0,0 +1,67 @@ +using System; +using System.ComponentModel; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Ink; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; + +namespace WPZX81.ViewModels +{ + /// + /// Provides a base for view models. + /// + public class BaseViewModel : INotifyPropertyChanged + { + + #region SetValue + + /// + /// Sets a value in the model. + /// + /// The type of the value. + /// A reference to the member variable. + /// The new value. + /// The propertys to change if the value has changed. + protected void SetValue(ref T member, T value, params string[] names) + { + if (!value.Equals(member)) + { + member = value; + + foreach (string name in names) + { + NotifyPropertyChanged(name); + } + } + } + + #endregion + + #region Notify + + /// + /// Notifies handlers of a property change. + /// + /// The property's name. + protected void NotifyPropertyChanged(string propertyName) + { + if (PropertyChanged != null) + { + PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); + } + } + + #endregion + + #region INotifyPropertyChanged Members + + public event PropertyChangedEventHandler PropertyChanged; + + #endregion + } +} diff --git a/WPZX81/WPZX81/ViewModels/DisassemblerLine.cs b/WPZX81/WPZX81/ViewModels/DisassemblerLine.cs new file mode 100644 index 0000000..f493b85 --- /dev/null +++ b/WPZX81/WPZX81/ViewModels/DisassemblerLine.cs @@ -0,0 +1,34 @@ +using System; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Ink; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; + +namespace WPZX81.ViewModels +{ + /// + /// Represents a line of disassembly. + /// + public class DisassemblerLine + { + /// + /// The address part. + /// + public string Address {get; set;} + + /// + /// The assembly opcode part. + /// + public string Opcode {get; set;} + + /// + /// The hexdump part. + /// + public string Hexdump {get; set;} + } +} diff --git a/WPZX81/WPZX81/ViewModels/DisassemblerViewModel.cs b/WPZX81/WPZX81/ViewModels/DisassemblerViewModel.cs new file mode 100644 index 0000000..cbf5dbb --- /dev/null +++ b/WPZX81/WPZX81/ViewModels/DisassemblerViewModel.cs @@ -0,0 +1,253 @@ +using System; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Ink; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; +using Noddybox.Emulation.EightBit.Z80; +using System.Collections.Generic; + +namespace WPZX81.ViewModels +{ + /// + /// Implements a view model for the diassembler page. + /// + public class DisassemblerViewModel : BaseViewModel + { + #region Private data + + private Z80Cpu z80; + private int a; + private Z80Flags flags; + private int bc; + private int de; + private int hl; + private int af_; + private int bc_; + private int de_; + private int hl_; + private int ix; + private int iy; + private int sp; + private int pc; + private int i; + private int r; + private int im; + private string iff1; + private string iff2; + private uint executedInstructions; + private int steps; + + #endregion + + #region Private methods + + private void Update() + { + Z80Cpu z80 = Shared.ZX81.Z80; + + A = z80.Acummulator; + Flags = z80.StatusFlags; + BC = z80.BC_Register.reg; + DE = z80.DE_Register.reg; + HL = z80.HL_Register.reg; + IX = z80.IX_Register.reg; + IY = z80.IY_Register.reg; + AF_ = z80.AF_Alternate.reg; + BC_ = z80.BC_Alternate.reg; + DE_ = z80.DE_Alternate.reg; + HL_ = z80.HL_Alternate.reg; + PC = z80.ProgramCounter; + SP = z80.StackPointer; + ExecutedInstructions = z80.ExecutedInstructions; + I = z80.InterruptVector; + R = z80.Refresh; + IFF1 = z80.IFF1_Register ? "On":"Off"; + IFF2 = z80.IFF2_Register ? "On":"Off"; + } + + #endregion + + #region Properties + + public int A + { + get {return a;} + set {SetValue(ref a, value, "A");} + } + + public Z80Flags Flags + { + get {return flags;} + set {SetValue(ref flags, value, "Flags");} + } + + public int BC + { + get {return bc;} + set {SetValue(ref bc, value, "BC");} + } + + public int DE + { + get {return de;} + set {SetValue(ref de, value, "DE");} + } + + public int HL + { + get {return hl;} + set {SetValue(ref hl, value, "HL");} + } + + public int AF_ + { + get {return af_;} + set {SetValue(ref af_, value, "AF_");} + } + + public int BC_ + { + get {return bc_;} + set {SetValue(ref bc_, value, "BC_");} + } + + public int DE_ + { + get {return de_;} + set {SetValue(ref de_, value, "DE_");} + } + + public int HL_ + { + get {return hl_;} + set {SetValue(ref hl_, value, "HL_");} + } + + public int IX + { + get {return ix;} + set {SetValue(ref ix, value, "IX");} + } + + public int IY + { + get {return iy;} + set {SetValue(ref iy, value, "IY");} + } + + public int SP + { + get {return sp;} + set {SetValue(ref sp, value, "SP");} + } + + public int PC + { + get {return pc;} + set {SetValue(ref pc, value, "PC", "Disassembly");} + } + + public uint ExecutedInstructions + { + get {return executedInstructions;} + set {SetValue(ref executedInstructions, value, "ExecutedInstructions");} + } + + public int I + { + get {return i;} + set {SetValue(ref i, value, "I");} + } + + public int R + { + get {return r;} + set {SetValue(ref r, value, "R");} + } + public int IM + { + get {return im;} + set {SetValue(ref im, value, "IM");} + } + public string IFF1 + { + get {return iff1;} + set {SetValue(ref iff1, value, "ExecutedInstructions");} + } + public string IFF2 + { + get {return iff2;} + set {SetValue(ref iff2, value, "ExecutedInstructions");} + } + + public IEnumerable Disassembly + { + get + { + List list = new List(); + + ushort pc = Shared.ZX81.Z80.ProgramCounter; + string address; + string opcode; + string hexdump; + + for(int f = 0 ; f < 15; f++) + { + pc = Shared.ZX81.Disassembler.Disassemble(pc, out address, out opcode, out hexdump); + list.Add(new DisassemblerLine() {Address = address, Opcode = opcode, Hexdump = hexdump}); + } + + return list; + } + } + + public int Steps + { + get {return steps;} + set {SetValue(ref steps, value, "Steps");} + } + + #endregion + + #region Public methods + + /// + /// Run the ZX81 for a step. + /// + public void Step() + { + for(int f = 0; f < steps; f++) + { + Shared.ZX81.Step(); + } + + Update(); + } + + /// + /// Run the ZX81 for a frame. + /// + public void Run() + { + Shared.ZX81.Run(); + Update(); + } + + #endregion + + #region Constructors + + public DisassemblerViewModel() + { + Steps = 1; + Update(); + } + + #endregion + } +} diff --git a/WPZX81/WPZX81/WPZX81.csproj b/WPZX81/WPZX81/WPZX81.csproj index 9c8122c..40b1311 100644 --- a/WPZX81/WPZX81/WPZX81.csproj +++ b/WPZX81/WPZX81/WPZX81.csproj @@ -69,12 +69,12 @@ App.xaml - - + + + DisassemblerPage.xaml - GamePage.xaml @@ -93,6 +93,9 @@ SettingsPage.xaml + + + @@ -162,6 +165,7 @@ Strings.Designer.cs +