From 96ee33ae8c09c2727cbc0fe4f0b66acb1be5af78 Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Sun, 21 Oct 2018 21:08:48 -0700 Subject: [PATCH] Optionally add spaces in the "bytes" column Affects the display list and copy/paste text. Makes the column three spaces wider, but makes it easier to read. --- Asm65/Formatter.cs | 9 ++++-- .../AppForms/EditAppSettings.Designer.cs | 31 ++++++++++++++++++- SourceGen/AppForms/EditAppSettings.cs | 8 +++++ SourceGen/AppForms/ProjectView.cs | 16 +++++++--- SourceGen/AppSettings.cs | 1 + SourceGen/AsmGen/GenCommon.cs | 2 ++ 6 files changed, 60 insertions(+), 7 deletions(-) diff --git a/Asm65/Formatter.cs b/Asm65/Formatter.cs index 8f9398b..1ddc3b3 100644 --- a/Asm65/Formatter.cs +++ b/Asm65/Formatter.cs @@ -74,6 +74,8 @@ namespace Asm65 { // miscellaneous public bool mHexDumpAsciiOnly; // disallow non-ASCII chars in hex dumps? + public bool mSpacesBetweenBytes; // "20edfd" vs. "20 ed fd" + public enum CharConvMode { Unknown = 0, PlainAscii, HighLowAscii }; public CharConvMode mHexDumpCharConvMode; // character conversion mode for dumps @@ -639,9 +641,12 @@ namespace Asm65 { private void GenerateByteFormat(int len) { Debug.Assert(len <= MAX_BYTE_DUMP); - StringBuilder sb = new StringBuilder(len * 6); + StringBuilder sb = new StringBuilder(len * 7); for (int i = 0; i < len; i++) { - //. e.g. "{0:x2}" + if (i != 0 && mFormatConfig.mSpacesBetweenBytes) { + sb.Append(' '); + } + // e.g. "{0:x2}" sb.Append("{" + i + ":" + mHexFmtChar + "2}"); } mByteDumpFormats[len - 1] = sb.ToString(); diff --git a/SourceGen/AppForms/EditAppSettings.Designer.cs b/SourceGen/AppForms/EditAppSettings.Designer.cs index 7f87f9b..12429b7 100644 --- a/SourceGen/AppForms/EditAppSettings.Designer.cs +++ b/SourceGen/AppForms/EditAppSettings.Designer.cs @@ -156,6 +156,8 @@ namespace SourceGen.AppForms { this.defineData1Label = new System.Windows.Forms.Label(); this.equDirectiveTextBox = new System.Windows.Forms.TextBox(); this.equDirectiveLabel = new System.Windows.Forms.Label(); + this.codeViewMiscGroupBox = new System.Windows.Forms.GroupBox(); + this.spacesBetweenBytesCheckBox = new System.Windows.Forms.CheckBox(); this.settingsTabControl.SuspendLayout(); this.codeViewTabPage.SuspendLayout(); this.clipboardGroupBox.SuspendLayout(); @@ -169,6 +171,7 @@ namespace SourceGen.AppForms { this.operandWidthGroupBox.SuspendLayout(); this.pseudoOpTabPage.SuspendLayout(); this.quickPseudoSetGroup.SuspendLayout(); + this.codeViewMiscGroupBox.SuspendLayout(); this.SuspendLayout(); // // cancelButton @@ -222,6 +225,7 @@ namespace SourceGen.AppForms { // // codeViewTabPage // + this.codeViewTabPage.Controls.Add(this.codeViewMiscGroupBox); this.codeViewTabPage.Controls.Add(this.clipboardGroupBox); this.codeViewTabPage.Controls.Add(this.enableDebugCheckBox); this.codeViewTabPage.Controls.Add(this.upperCaseGroupBox); @@ -405,7 +409,7 @@ namespace SourceGen.AppForms { // // selectFontButton // - this.selectFontButton.Location = new System.Drawing.Point(6, 60); + this.selectFontButton.Location = new System.Drawing.Point(6, 58); this.selectFontButton.Name = "selectFontButton"; this.selectFontButton.Size = new System.Drawing.Size(125, 23); this.selectFontButton.TabIndex = 2; @@ -1452,6 +1456,27 @@ namespace SourceGen.AppForms { this.equDirectiveLabel.Text = "Equate:"; this.equDirectiveLabel.TextAlign = System.Drawing.ContentAlignment.TopRight; // + // codeViewMiscGroupBox + // + this.codeViewMiscGroupBox.Controls.Add(this.spacesBetweenBytesCheckBox); + this.codeViewMiscGroupBox.Location = new System.Drawing.Point(406, 101); + this.codeViewMiscGroupBox.Name = "codeViewMiscGroupBox"; + this.codeViewMiscGroupBox.Size = new System.Drawing.Size(200, 47); + this.codeViewMiscGroupBox.TabIndex = 5; + this.codeViewMiscGroupBox.TabStop = false; + this.codeViewMiscGroupBox.Text = "Miscellaneous"; + // + // spacesBetweenBytesCheckBox + // + this.spacesBetweenBytesCheckBox.AutoSize = true; + this.spacesBetweenBytesCheckBox.Location = new System.Drawing.Point(7, 20); + this.spacesBetweenBytesCheckBox.Name = "spacesBetweenBytesCheckBox"; + this.spacesBetweenBytesCheckBox.Size = new System.Drawing.Size(158, 17); + this.spacesBetweenBytesCheckBox.TabIndex = 0; + this.spacesBetweenBytesCheckBox.Text = "Add spaces in bytes column"; + this.spacesBetweenBytesCheckBox.UseVisualStyleBackColor = true; + this.spacesBetweenBytesCheckBox.CheckedChanged += new System.EventHandler(this.spacesBetweenBytesCheckBox_CheckedChanged); + // // EditAppSettings // this.AcceptButton = this.okButton; @@ -1493,6 +1518,8 @@ namespace SourceGen.AppForms { this.pseudoOpTabPage.ResumeLayout(false); this.pseudoOpTabPage.PerformLayout(); this.quickPseudoSetGroup.ResumeLayout(false); + this.codeViewMiscGroupBox.ResumeLayout(false); + this.codeViewMiscGroupBox.PerformLayout(); this.ResumeLayout(false); } @@ -1617,5 +1644,7 @@ namespace SourceGen.AppForms { private System.Windows.Forms.ComboBox pseudoOpQuickComboBox; private System.Windows.Forms.Button displayFmtSetButton; private System.Windows.Forms.ComboBox displayFmtQuickComboBox; + private System.Windows.Forms.GroupBox codeViewMiscGroupBox; + private System.Windows.Forms.CheckBox spacesBetweenBytesCheckBox; } } \ No newline at end of file diff --git a/SourceGen/AppForms/EditAppSettings.cs b/SourceGen/AppForms/EditAppSettings.cs index b45d779..b1bb30a 100644 --- a/SourceGen/AppForms/EditAppSettings.cs +++ b/SourceGen/AppForms/EditAppSettings.cs @@ -209,6 +209,8 @@ namespace SourceGen.AppForms { clipboardFormatComboBox.SelectedIndex = clipIndex; } + spacesBetweenBytesCheckBox.Checked = + mSettings.GetBool(AppSettings.FMT_SPACES_BETWEEN_BYTES, false); enableDebugCheckBox.Checked = mSettings.GetBool(AppSettings.DEBUG_MENU_ENABLED, false); // Assemblers. @@ -396,6 +398,12 @@ namespace SourceGen.AppForms { SetDirty(true); } + private void spacesBetweenBytesCheckBox_CheckedChanged(object sender, EventArgs e) { + mSettings.SetBool(AppSettings.FMT_SPACES_BETWEEN_BYTES, + spacesBetweenBytesCheckBox.Checked); + SetDirty(true); + } + private void enableDebugCheckBox_CheckedChanged(object sender, EventArgs e) { mSettings.SetBool(AppSettings.DEBUG_MENU_ENABLED, enableDebugCheckBox.Checked); SetDirty(true); diff --git a/SourceGen/AppForms/ProjectView.cs b/SourceGen/AppForms/ProjectView.cs index 93df22a..b6a7313 100644 --- a/SourceGen/AppForms/ProjectView.cs +++ b/SourceGen/AppForms/ProjectView.cs @@ -1735,7 +1735,15 @@ namespace SourceGen.AppForms { StringBuilder sb = new StringBuilder(100); int addrAdj = mProject.CpuDef.HasAddr16 ? 6 : 9; - int disAdj = (format != Disassembly) ? 0 : addrAdj + 10; + int disAdj = 0; + int bytesWidth = 0; + if (format == Disassembly) { + // A limit of 8 gets us 4 bytes from dense display ("20edfd60") and 3 if spaces + // are included ("20 ed fd") with no excess. We want to increase it to 11 so + // we can always show 4 bytes. + bytesWidth = (mFormatterConfig.mSpacesBetweenBytes ? 11 : 8); + disAdj = addrAdj + bytesWidth + 2; + } // Walking through the selected indices can be slow for a large file, so we // run through the full list and pick out the selected items with our parallel @@ -1758,10 +1766,10 @@ namespace SourceGen.AppForms { sb.Append(": "); } - // shorten the "..." + // Shorten the "...". string bytesStr = parts.Bytes; - if (bytesStr != null && bytesStr.Length > 8) { - bytesStr = bytesStr.Substring(0, 8) + "+"; + if (bytesStr != null && bytesStr.Length > bytesWidth) { + bytesStr = bytesStr.Substring(0, bytesWidth) + "+"; } TextUtil.AppendPaddedString(sb, bytesStr, disAdj); } diff --git a/SourceGen/AppSettings.cs b/SourceGen/AppSettings.cs index 656006d..38f6c0e 100644 --- a/SourceGen/AppSettings.cs +++ b/SourceGen/AppSettings.cs @@ -58,6 +58,7 @@ namespace SourceGen { public const string FMT_UPPER_OPERAND_S = "fmt-upper-operand-s"; public const string FMT_UPPER_OPERAND_XY = "fmt-upper-operand-xy"; public const string FMT_ADD_SPACE_FULL_COMMENT = "fmt-add-space-full-comment"; + public const string FMT_SPACES_BETWEEN_BYTES = "fmt-spaces-between-bytes"; public const string FMT_OPCODE_SUFFIX_ABS = "fmt-opcode-suffix-abs"; public const string FMT_OPCODE_SUFFIX_LONG = "fmt-opcode-suffix-long"; diff --git a/SourceGen/AsmGen/GenCommon.cs b/SourceGen/AsmGen/GenCommon.cs index cc95579..1b56699 100644 --- a/SourceGen/AsmGen/GenCommon.cs +++ b/SourceGen/AsmGen/GenCommon.cs @@ -310,6 +310,8 @@ namespace SourceGen.AsmGen { settings.GetBool(AppSettings.FMT_UPPER_OPERAND_S, false); config.mUpperOperandXY = settings.GetBool(AppSettings.FMT_UPPER_OPERAND_XY, false); + config.mSpacesBetweenBytes = + settings.GetBool(AppSettings.FMT_SPACES_BETWEEN_BYTES, false); config.mAddSpaceLongComment = settings.GetBool(AppSettings.FMT_ADD_SPACE_FULL_COMMENT, true);