diff --git a/C-Sim/Core/AppInfo.cs b/C-Sim/Core/AppInfo.cs
index 7d46743..9d0913d 100644
--- a/C-Sim/Core/AppInfo.cs
+++ b/C-Sim/Core/AppInfo.cs
@@ -9,7 +9,7 @@ public static class AppInfo
/// Author of the app.
public const string Author = "jbgarcia@uvigo.es";
/// Version of the app.
- public const string Version = "1.7.4 20171201";
+ public const string Version = "1.7.5 20171213";
/// Website for this app.
public const string Web = "http://webs.uvigo.es/jbgarcia/prys/csim/";
/// Extension for files created by this app.
diff --git a/C-Sim/Ui/MainWindowCore.cs b/C-Sim/Ui/MainWindowCore.cs
index d0f7029..2dac155 100644
--- a/C-Sim/Ui/MainWindowCore.cs
+++ b/C-Sim/Ui/MainWindowCore.cs
@@ -38,6 +38,7 @@ public partial class MainWindow: Form {
///
public MainWindow(Machine m)
{
+ this.updatingMemoryView = false;
this.machine = m;
this.machine.Inputter = (msg) => this.DoUserInput( msg );
this.machine.Outputter = (string s) => this.rtbOutput.Text += s;
@@ -256,6 +257,49 @@ private void DoDisplayInHex()
Literal.Display = Literal.DisplayType.Hex;
this.UpdateView();
}
+
+ private void DoCellFormat(DataGridViewCellFormattingEventArgs e)
+ {
+ string val = (string) e.Value;
+
+ e.Value = val.ToLower();
+ e.FormattingApplied = true;
+ }
+
+ private void DoCellEdited(int rowIndex, int colIndex)
+ {
+ if ( !this.updatingMemoryView
+ && colIndex > 0 ) // First row is for indexes
+ {
+ string val = (string)
+ this.grdMemory.Rows[ rowIndex ].
+ Cells[ colIndex ].Value;
+
+ if ( byte.TryParse(
+ val,
+ NumberStyles.HexNumber,
+ NumberFormatInfo.InvariantInfo,
+ out byte x ) )
+ {
+ int pos = ( rowIndex * MaxDataColumns ) + colIndex - 1;
+ this.machine.Memory.Write( pos, new []{ x } );
+ }
+ }
+
+ return;
+ }
+
+ private void DoCellValidate(DataGridViewCellValidatingEventArgs e)
+ {
+ int x = -1;
+ bool isHex = int.TryParse(
+ (string) e.FormattedValue,
+ NumberStyles.HexNumber,
+ NumberFormatInfo.InvariantInfo,
+ out x );
+
+ e.Cancel = ( !isHex || x < 0 || x >= byte.MaxValue );
+ }
///
/// Updates the font in all visible controls.
@@ -586,6 +630,8 @@ private void UpdateMemoryView()
{
var memory = this.machine.Memory.Raw;
+ this.updatingMemoryView = true;
+
// Row indexes (first cell in each row)
for (int i = 0; i < this.grdMemory.RowCount; ++i) {
this.grdMemory.Rows[ i ].Cells[ 0 ].Value = FromIntToHex( i );
@@ -600,6 +646,7 @@ private void UpdateMemoryView()
this.grdMemory.Rows[ row ].Cells[ col ].ToolTipText = memory[ i ].ToString();
}
+ this.updatingMemoryView = false;
this.FocusOnInput();
return;
}
@@ -848,6 +895,7 @@ private static string FromIntToPrettyHex(BigInteger value, int wordSize = 1)
private Machine machine;
private SchemaDrawer sdDrawingBoard;
private string cfgFile = "";
+ private bool updatingMemoryView;
///
/// The current dir, the last one from which a file was last loaded.
diff --git a/C-Sim/Ui/MainWindowView.cs b/C-Sim/Ui/MainWindowView.cs
index 7c2283e..b794bae 100644
--- a/C-Sim/Ui/MainWindowView.cs
+++ b/C-Sim/Ui/MainWindowView.cs
@@ -8,7 +8,7 @@ namespace CSim.Ui {
using Core;
- /// The main window for the application. This builds the view.
+ /// The view builder for the application.
public partial class MainWindow {
private void BuildInputPanel()
{
@@ -131,25 +131,25 @@ private void BuildMemoryViewPanel()
BackColor = Color.Black,
ForeColor = Color.White
};
-
+
// Create columns
- DataGridViewTextBoxColumn[] columns =
- new DataGridViewTextBoxColumn[ MaxDataColumns +1 ];
+ var columns = new DataGridViewTextBoxColumn[ MaxDataColumns +1 ];
for(int i = 0; i < columns.Length; ++i) {
- columns[ i ] = new DataGridViewTextBoxColumn();
+ columns[ i ] = new DataGridViewTextBoxColumn {
+ SortMode = DataGridViewColumnSortMode.NotSortable
+ };
if ( i == 0 ) {
columns[ i ].DefaultCellStyle = styleFirstColumn;
columns[ i ].HeaderText = "/";
columns[ i ].Width = columnWidth + ( (int) ( columnWidth * 0.2 ) );
+ columns[ i ].ReadOnly = true;
} else {
columns[ i ].HeaderText = FromIntToHex( i - 1 );
columns[ i ].Width = columnWidth;
+ columns[ i ].ReadOnly = false;
}
-
- columns[ i ].SortMode = DataGridViewColumnSortMode.NotSortable;
- columns[ i ].ReadOnly = true;
}
this.grdMemory.Columns.AddRange( columns );
@@ -162,6 +162,15 @@ private void BuildMemoryViewPanel()
}
this.grdMemory.Rows.AddRange( rows );
+ this.grdMemory.CellValueChanged +=
+ (object sender, DataGridViewCellEventArgs e)
+ => this.DoCellEdited( e.RowIndex, e.ColumnIndex );
+ this.grdMemory.CellValidating +=
+ (object sender, DataGridViewCellValidatingEventArgs e)
+ => this.DoCellValidate( e );
+ this.grdMemory.CellFormatting +=
+ (object sender, DataGridViewCellFormattingEventArgs e)
+ => this.DoCellFormat( e );
this.grdMemory.Dock = DockStyle.Fill;
this.tcTabs.TabPages[ 0 ].Controls.Add( this.grdMemory );
diff --git a/C-SimTests/C-SimTests.csproj b/C-SimTests/C-SimTests.csproj
index 4070fb6..8f319a1 100644
--- a/C-SimTests/C-SimTests.csproj
+++ b/C-SimTests/C-SimTests.csproj
@@ -43,14 +43,14 @@
-
-
-
{7301AFF5-913F-46D4-A2AE-878100C67B5A}
C-Sim
+
+
+
\ No newline at end of file