From d8170c50d3e4c93c208c77a72d1d4e6ff344755d Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Tue, 19 Nov 2019 18:18:41 -0800 Subject: [PATCH] Show code/data/junk percentages in status bar Not necessarily useful, but sort of interesting. --- SourceGen/DisasmProject.cs | 24 ++++++++++++++++++++++++ SourceGen/MainController.cs | 22 ++++++++++++++++++++++ SourceGen/Res/Strings.xaml | 1 + SourceGen/Res/Strings.xaml.cs | 2 ++ SourceGen/WpfGui/MainWindow.xaml | 18 ++++++++++++------ SourceGen/WpfGui/MainWindow.xaml.cs | 9 +++++++++ 6 files changed, 70 insertions(+), 6 deletions(-) diff --git a/SourceGen/DisasmProject.cs b/SourceGen/DisasmProject.cs index 8e59a21..b7c39b1 100644 --- a/SourceGen/DisasmProject.cs +++ b/SourceGen/DisasmProject.cs @@ -176,6 +176,17 @@ namespace SourceGen { // List of messages, mostly problems detected during analysis. public MessageList Messages { get; private set; } + public class CodeDataCounts { + public int CodeByteCount { get; set; } + public int DataByteCount { get; set; } + public int JunkByteCount { get; set; } + + public void Reset() { + CodeByteCount = DataByteCount = JunkByteCount = 0; + } + } + public CodeDataCounts ByteCounts { get; private set; } = new CodeDataCounts(); + #if DATA_PRESCAN // Data scan results. public TypedRangeSet RepeatedBytes { get; private set; } @@ -1409,6 +1420,9 @@ namespace SourceGen { } } + // No particular reason to do this here, but it's convenient. + ByteCounts.Reset(); + LocalVariableLookup lvLookup = new LocalVariableLookup(LvTables, this, null, false, false); @@ -1518,9 +1532,18 @@ namespace SourceGen { if (attr.IsDataStart) { // There shouldn't be data items inside of other data items. offset += attr.Length; + + if (attr.DataDescriptor != null && + attr.DataDescriptor.FormatType == FormatDescriptor.Type.Junk) { + ByteCounts.JunkByteCount += attr.Length; + } else { + ByteCounts.DataByteCount += attr.Length; + } } else { // Advance by one, not attr.Length, so we don't miss embedded instructions. offset++; + + ByteCounts.CodeByteCount++; } } } @@ -1553,6 +1576,7 @@ namespace SourceGen { AutoLabel.Style style = ProjectProps.AutoLabelStyle; Debug.Assert(style != AutoLabel.Style.Simple); + // We don't have a list of auto labels, so just pick them out of anattribs. for (int offset = 0; offset < mAnattribs.Length; offset++) { Anattrib attr = mAnattribs[offset]; if (attr.Symbol != null && attr.Symbol.SymbolSource == Symbol.Source.Auto) { diff --git a/SourceGen/MainController.cs b/SourceGen/MainController.cs index a70b2e9..3d92ccf 100644 --- a/SourceGen/MainController.cs +++ b/SourceGen/MainController.cs @@ -651,6 +651,28 @@ namespace SourceGen { sb.Append(Res.Strings.TITLE_MODIFIED); } mMainWin.Title = sb.ToString(); + + UpdateByteCounts(); + } + + /// + /// Updates the code/data/junk percentages in the status bar. + /// + private void UpdateByteCounts() { + if (mProject == null) { + mMainWin.ByteCountText = string.Empty; + return; + } + + Debug.Assert(mProject.ByteCounts.CodeByteCount + mProject.ByteCounts.DataByteCount + + mProject.ByteCounts.JunkByteCount == mProject.FileData.Length); + + int total = mProject.FileData.Length; + float codePerc = (mProject.ByteCounts.CodeByteCount * 100.0f) / total; + float dataPerc = (mProject.ByteCounts.DataByteCount * 100.0f) / total; + float junkPerc = (mProject.ByteCounts.JunkByteCount * 100.0f) / total; + mMainWin.ByteCountText = string.Format(Res.Strings.STATUS_BYTE_COUNT_FMT, + codePerc, dataPerc, junkPerc); } #endregion Init and settings diff --git a/SourceGen/Res/Strings.xaml b/SourceGen/Res/Strings.xaml index 7077821..29719e3 100644 --- a/SourceGen/Res/Strings.xaml +++ b/SourceGen/Res/Strings.xaml @@ -156,6 +156,7 @@ limitations under the License. C64 Screen Code {1} CPU @ {2} MHz Show + {0:F1}% code, {1:F1}% data, {2:F1}% junk Ready DCI string has mixed data DCI string not terminated diff --git a/SourceGen/Res/Strings.xaml.cs b/SourceGen/Res/Strings.xaml.cs index d121b5a..6fbbd16 100644 --- a/SourceGen/Res/Strings.xaml.cs +++ b/SourceGen/Res/Strings.xaml.cs @@ -293,6 +293,8 @@ namespace SourceGen.Res { (string)Application.Current.FindResource("str_SetupSystemSummaryFmt"); public static string SHOW_COL = (string)Application.Current.FindResource("str_ShowCol"); + public static string STATUS_BYTE_COUNT_FMT = + (string)Application.Current.FindResource("str_StatusByteCountFmt"); public static string STATUS_READY = (string)Application.Current.FindResource("str_StatusReady"); public static string STR_VFY_DCI_MIXED_DATA = diff --git a/SourceGen/WpfGui/MainWindow.xaml b/SourceGen/WpfGui/MainWindow.xaml index 8ad6e77..40ce52d 100644 --- a/SourceGen/WpfGui/MainWindow.xaml +++ b/SourceGen/WpfGui/MainWindow.xaml @@ -451,15 +451,21 @@ limitations under the License. - - -