Changes stack pointer behaviour to match the C implementation.

This commit is contained in:
Felix Queißner 2016-05-28 14:35:28 +02:00
parent c3868d4617
commit 8e5475f59b
3 changed files with 54 additions and 29 deletions

View file

@ -45,7 +45,7 @@
</Button>
</ToolBar>
<DockPanel>
<TabControl DockPanel.Dock="Right" Width="235">
<TabControl DockPanel.Dock="Right" Width="251">
<TabItem Header="CPU State">
<Grid>
<Grid.RowDefinitions>
@ -120,12 +120,29 @@
</Grid>
</TabItem>
<TabItem Header="Output">
<TextBox VerticalContentAlignment="Top" Text="{Binding Path=Output}"/>
<TextBox
AcceptsTab="True"
AcceptsReturn="True"
FontFamily="Consolas"
VerticalContentAlignment="Top"
Text="{Binding Path=Output}"/>
</TabItem>
<TabItem Header="Memory" Grid.IsSharedSizeScope="True">
<DockPanel>
<DataGrid ItemsSource="{Binding Path=Memory}" AutoGenerateColumns="False">
<DataGrid.Resources>
<Style TargetType="DataGridCell">
<Setter Property="FontFamily" Value="Consolas" />
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTemplateColumn Header="" IsReadOnly="True" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Margin="0" Foreground="Gray" TextAlignment="Right" Text="{Binding Path=Offset}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="+0" Binding="{Binding Path=D0}" />
<DataGridTextColumn Header="+1" Binding="{Binding Path=D1}" />
<DataGridTextColumn Header="+2" Binding="{Binding Path=D2}" />

View file

@ -224,6 +224,8 @@ namespace SuperVM.VisualDebugger
this.mem = mem;
this.offset = offset;
this.Offset = Convert.ToString(this.offset, 16);
this.mem.Changed += Mem_Changed;
}
@ -237,52 +239,58 @@ namespace SuperVM.VisualDebugger
}
}
public byte D0
private static string Read(byte val) => Convert.ToString(val, 16).ToUpper().PadLeft(2, '0');
private static byte Write(string val) => Convert.ToByte(val, 16);
public string Offset { get; private set; }
public string D0
{
get { return this.mem[this.offset + 0]; }
set { this.mem[this.offset + 0] = value; }
get { return Read(this.mem[this.offset + 0]); }
set { this.mem[this.offset + 0] = Write(value); }
}
public byte D1
public string D1
{
get { return this.mem[this.offset + 1]; }
set { this.mem[this.offset + 1] = value; }
get { return Read(this.mem[this.offset + 1]); }
set { this.mem[this.offset + 1] = Write(value); }
}
public byte D2
public string D2
{
get { return this.mem[this.offset + 2]; }
set { this.mem[this.offset + 2] = value; }
get { return Read(this.mem[this.offset + 2]); }
set { this.mem[this.offset + 2] = Write(value); }
}
public byte D3
public string D3
{
get { return this.mem[this.offset + 3]; }
set { this.mem[this.offset + 3] = value; }
get { return Read(this.mem[this.offset + 3]); }
set { this.mem[this.offset + 3] = Write(value); }
}
public byte D4
public string D4
{
get { return this.mem[this.offset + 4]; }
set { this.mem[this.offset + 4] = value; }
get { return Read(this.mem[this.offset + 4]); }
set { this.mem[this.offset + 4] = Write(value); }
}
public byte D5
public string D5
{
get { return this.mem[this.offset + 5]; }
set { this.mem[this.offset + 5] = value; }
get { return Read(this.mem[this.offset + 5]); }
set { this.mem[this.offset + 5] = Write(value); }
}
public byte D6
public string D6
{
get { return this.mem[this.offset + 6]; }
set { this.mem[this.offset + 6] = value; }
get { return Read(this.mem[this.offset + 6]); }
set { this.mem[this.offset + 6] = Write(value); }
}
public byte D7
public string D7
{
get { return this.mem[this.offset + 7]; }
set { this.mem[this.offset + 7] = value; }
get { return Read(this.mem[this.offset + 7]); }
set { this.mem[this.offset + 7] = Write(value); }
}
}
}

View file

@ -29,7 +29,7 @@ namespace SuperVM
{
checked
{
this.stack[this.StackPointer++] = value;
this.stack[++this.StackPointer] = value;
}
}
@ -37,11 +37,11 @@ namespace SuperVM
{
checked
{
return this.stack[--this.StackPointer];
return this.stack[this.StackPointer--];
}
}
public uint Peek() => this.stack[this.StackPointer - 1];
public uint Peek() => this.stack[this.StackPointer];
public void Reset()
{