From d5b53a07951e01699ea8528e3246e7b438290066 Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Mon, 12 Aug 2019 17:01:50 -0700 Subject: [PATCH] Add combo box for default text scan mode It's not quite the same as the character encoding -- sometimes we want a mix of things -- so it gets its own enum. The value is saved to the project file, but not actually used yet. Also, moved some combo box strings into XAML resources. --- Asm65/CharEncoding.cs | 16 ++- SourceGen/ProjectFile.cs | 12 +- SourceGen/ProjectProperties.cs | 11 ++ SourceGen/WpfGui/EditProjectProperties.xaml | 37 ++++++- .../WpfGui/EditProjectProperties.xaml.cs | 104 +++++++++++++----- 5 files changed, 145 insertions(+), 35 deletions(-) diff --git a/Asm65/CharEncoding.cs b/Asm65/CharEncoding.cs index ab45152..157c0fe 100644 --- a/Asm65/CharEncoding.cs +++ b/Asm65/CharEncoding.cs @@ -94,7 +94,16 @@ namespace Asm65 { } // - // C64 PETSCII + // ATASCII (Atari 400/800) + // + // Substantially similar to ASCII, but with printable symbols in the control character + // range ($00-1f). Characters $60 and $7b-7f don't correspond to ASCII symbols. + // + // Characters with the high bit set are shown with colors reversed. + // + + // + // PETSCII (C64 variant) // // Assemblers like ACME use the C64 character set 2, a/k/a shifted mode, lower case // mode, or text mode. @@ -126,6 +135,11 @@ namespace Asm65 { // $12 92 - reverse on/off // $07 0a 0d - bell, LF, CR (note CR is favored for EOL) // + // Other Commodore systems use variants on PETSCII, but the ASCII correspondence remains + // the same -- only the non-ASCII symbols change. (On the original PET, $60-7f was a + // duplicate of $20-3f rather than a duplicate of the upper-case letters, which might be + // why $c0-df is preferred for upper case.) + // // For full details, see the chart at https://www.aivosto.com/articles/petscii.pdf // diff --git a/SourceGen/ProjectFile.cs b/SourceGen/ProjectFile.cs index 4140d46..0e06ece 100644 --- a/SourceGen/ProjectFile.cs +++ b/SourceGen/ProjectFile.cs @@ -179,7 +179,8 @@ namespace SourceGen { /// internal class SerializableProjectFile1 { // This appears at the top of the file, not as part of the JSON data. The version - // number refers to the file format version, not the application version. + // number refers to the file format version, not the application version. Only + // change this if a change is made that renders the file unreadable by previous versions. public const string MAGIC = "### 6502bench SourceGen dis65 v1.0 ###"; public SerializableProjectFile1() { } @@ -215,12 +216,14 @@ namespace SourceGen { } public class SerAnalysisParameters { public bool AnalyzeUncategorizedData { get; set; } + public string DefaultTextScanMode { get; set; } public int MinCharsForString { get; set; } public bool SeekNearbyTargets { get; set; } public SerAnalysisParameters() { } public SerAnalysisParameters(ProjectProperties.AnalysisParameters src) { AnalyzeUncategorizedData = src.AnalyzeUncategorizedData; + DefaultTextScanMode = src.DefaultTextScanMode.ToString(); MinCharsForString = src.MinCharsForString; SeekNearbyTargets = src.SeekNearbyTargets; } @@ -475,6 +478,13 @@ namespace SourceGen { proj.ProjectProps.AnalysisParams = new ProjectProperties.AnalysisParameters(); proj.ProjectProps.AnalysisParams.AnalyzeUncategorizedData = spf.ProjectProps.AnalysisParams.AnalyzeUncategorizedData; + if (Enum.TryParse( + spf.ProjectProps.AnalysisParams.DefaultTextScanMode, + out ProjectProperties.AnalysisParameters.TextScanMode mode)) { + proj.ProjectProps.AnalysisParams.DefaultTextScanMode = mode; + } else { + // unknown value, leave as default + } proj.ProjectProps.AnalysisParams.MinCharsForString = spf.ProjectProps.AnalysisParams.MinCharsForString; proj.ProjectProps.AnalysisParams.SeekNearbyTargets = diff --git a/SourceGen/ProjectProperties.cs b/SourceGen/ProjectProperties.cs index c1736e3..2d34f5e 100644 --- a/SourceGen/ProjectProperties.cs +++ b/SourceGen/ProjectProperties.cs @@ -36,17 +36,28 @@ namespace SourceGen { /// Some parameters we feed to the analyzers. /// public class AnalysisParameters { + public enum TextScanMode { + Unknown = 0, + LowAscii, + LowHighAscii, + C64Petscii, + C64ScreenCode, + } + public bool AnalyzeUncategorizedData { get; set; } + public TextScanMode DefaultTextScanMode { get; set; } public int MinCharsForString { get; set; } public bool SeekNearbyTargets { get; set; } public AnalysisParameters() { AnalyzeUncategorizedData = true; + DefaultTextScanMode = TextScanMode.LowHighAscii; MinCharsForString = DataAnalysis.DEFAULT_MIN_STRING_LENGTH; SeekNearbyTargets = true; } public AnalysisParameters(AnalysisParameters src) { AnalyzeUncategorizedData = src.AnalyzeUncategorizedData; + DefaultTextScanMode = src.DefaultTextScanMode; MinCharsForString = src.MinCharsForString; SeekNearbyTargets = src.SeekNearbyTargets; } diff --git a/SourceGen/WpfGui/EditProjectProperties.xaml b/SourceGen/WpfGui/EditProjectProperties.xaml index b4f672f..9a030e8 100644 --- a/SourceGen/WpfGui/EditProjectProperties.xaml +++ b/SourceGen/WpfGui/EditProjectProperties.xaml @@ -19,6 +19,7 @@ limitations under the License. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:system="clr-namespace:System;assembly=mscorlib" xmlns:local="clr-namespace:SourceGen.WpfGui" mc:Ignorable="d" Title="Edit Project Properties" @@ -31,6 +32,22 @@ limitations under the License. + + + MOS 6502 + WDC W65C02S + WDC W65C816S + + Plain ASCII + Plain or High ASCII + C64 PETSCII + C64 Screen Code + + None (disabled) + + Simple ("L1234") + Annotated ("W_1234") + Fully Annotated ("DWR_1234") @@ -86,10 +103,21 @@ limitations under the License. IsChecked="{Binding AnalyzeUncategorizedData}"/> - - + + + + + + + + + + @@ -98,6 +126,7 @@ limitations under the License. diff --git a/SourceGen/WpfGui/EditProjectProperties.xaml.cs b/SourceGen/WpfGui/EditProjectProperties.xaml.cs index 27c6a0c..83aaab1 100644 --- a/SourceGen/WpfGui/EditProjectProperties.xaml.cs +++ b/SourceGen/WpfGui/EditProjectProperties.xaml.cs @@ -29,6 +29,7 @@ using Microsoft.Win32; using Asm65; using CommonUtil; using CommonWPF; +using TextScanMode = SourceGen.ProjectProperties.AnalysisParameters.TextScanMode; namespace SourceGen.WpfGui { /// @@ -88,6 +89,43 @@ namespace SourceGen.WpfGui { mWorkProps = new ProjectProperties(props); mProjectDir = projectDir; mFormatter = formatter; + + // Construct arrays used as item sources for combo boxes. + CpuItems = new CpuItem[] { + new CpuItem((string)FindResource("str_6502"), CpuDef.CpuType.Cpu6502), + new CpuItem((string)FindResource("str_65C02"), CpuDef.CpuType.Cpu65C02), + new CpuItem((string)FindResource("str_65816"), CpuDef.CpuType.Cpu65816), + }; + DefaultTextScanModeItems = new DefaultTextScanMode[] { + new DefaultTextScanMode((string)FindResource("str_LowAscii"), + TextScanMode.LowAscii), + new DefaultTextScanMode((string)FindResource("str_LowHighAscii"), + TextScanMode.LowHighAscii), + new DefaultTextScanMode((string)FindResource("str_C64Petscii"), + TextScanMode.C64Petscii), + new DefaultTextScanMode((string)FindResource("str_C64ScreenCode"), + TextScanMode.C64ScreenCode), + }; + MinCharsItems = new MinCharsItem[] { + new MinCharsItem((string)FindResource("str_DisableStringScan"), + DataAnalysis.MIN_CHARS_FOR_STRING_DISABLED), + new MinCharsItem("3", 3), + new MinCharsItem("4", 4), + new MinCharsItem("5", 5), + new MinCharsItem("6", 6), + new MinCharsItem("7", 7), + new MinCharsItem("8", 8), + new MinCharsItem("9", 9), + new MinCharsItem("10", 10), + }; + AutoLabelItems = new AutoLabelItem[] { + new AutoLabelItem((string)FindResource("str_AutoLabelSimple"), + AutoLabel.Style.Simple), + new AutoLabelItem((string)FindResource("str_AutoLabelAnnotated"), + AutoLabel.Style.Annotated), + new AutoLabelItem((string)FindResource("str_AutoLabelFullyAnnotated"), + AutoLabel.Style.FullyAnnotated), + }; } // INotifyPropertyChanged implementation @@ -173,12 +211,19 @@ namespace SourceGen.WpfGui { Type = type; } } - private static CpuItem[] sCpuItems = { - new CpuItem("MOS 6502", CpuDef.CpuType.Cpu6502), - new CpuItem("WDC W65C02S", CpuDef.CpuType.Cpu65C02), - new CpuItem("WDC W65C816S", CpuDef.CpuType.Cpu65816), - }; - public CpuItem[] CpuItems { get { return sCpuItems; } } + public CpuItem[] CpuItems { get; private set; } + + // Default text encoding combo box items + public class DefaultTextScanMode { + public string Name { get; private set; } + public TextScanMode Mode { get; private set; } + + public DefaultTextScanMode(string name, TextScanMode mode) { + Name = name; + Mode = mode; + } + } + public DefaultTextScanMode[] DefaultTextScanModeItems { get; private set; } // Min chars for string combo box items public class MinCharsItem { @@ -190,18 +235,7 @@ namespace SourceGen.WpfGui { Value = value; } } - private static MinCharsItem[] sMinCharsItems = { - new MinCharsItem("None (disabled)", DataAnalysis.MIN_CHARS_FOR_STRING_DISABLED), - new MinCharsItem("3", 3), - new MinCharsItem("4", 4), - new MinCharsItem("5", 5), - new MinCharsItem("6", 6), - new MinCharsItem("7", 7), - new MinCharsItem("8", 8), - new MinCharsItem("9", 9), - new MinCharsItem("10", 10), - }; - public MinCharsItem[] MinCharsItems { get { return sMinCharsItems; } } + public MinCharsItem[] MinCharsItems { get; private set; } // Auto-label style combo box items public class AutoLabelItem { @@ -213,12 +247,7 @@ namespace SourceGen.WpfGui { Style = style; } } - private static AutoLabelItem[] sAutoLabelItems = { - new AutoLabelItem("Simple (\"L1234\")", AutoLabel.Style.Simple), - new AutoLabelItem("Annotated (\"W_1234\")", AutoLabel.Style.Annotated), - new AutoLabelItem("Fully Annotated (\"DWR_1234\")", AutoLabel.Style.FullyAnnotated), - }; - public AutoLabelItem[] AutoLabelItems { get { return sAutoLabelItems; } } + public AutoLabelItem[] AutoLabelItems { get; private set; } // properties for checkboxes @@ -255,7 +284,18 @@ namespace SourceGen.WpfGui { } } if (cpuComboBox.SelectedItem == null) { - cpuComboBox.SelectedIndex = 0; + cpuComboBox.SelectedIndex = 0; // 6502 + } + + for (int i = 0; i < DefaultTextScanModeItems.Length; i++) { + if (DefaultTextScanModeItems[i].Mode == + mWorkProps.AnalysisParams.DefaultTextScanMode) { + defaultTextEncComboBox.SelectedItem = DefaultTextScanModeItems[i]; + break; + } + } + if (defaultTextEncComboBox.SelectedItem == null) { + defaultTextEncComboBox.SelectedIndex = 1; // low+high ASCII } for (int i = 0; i < MinCharsItems.Length; i++) { @@ -265,7 +305,7 @@ namespace SourceGen.WpfGui { } } if (minStringCharsComboBox.SelectedItem == null) { - minStringCharsComboBox.SelectedIndex = 2; + minStringCharsComboBox.SelectedIndex = 2; // 4 } for (int i = 0; i < AutoLabelItems.Length; i++) { @@ -275,10 +315,11 @@ namespace SourceGen.WpfGui { } } if (autoLabelStyleComboBox.SelectedItem == null) { - autoLabelStyleComboBox.SelectedIndex = 0; + autoLabelStyleComboBox.SelectedIndex = 0; // simple } UpdateEntryFlags(); + IsDirty = false; } private void UpdateEntryFlags() { @@ -305,6 +346,13 @@ namespace SourceGen.WpfGui { IsDirty = true; } + private void DefaultTextEncComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { + DefaultTextScanMode item = + (DefaultTextScanMode)defaultTextEncComboBox.SelectedItem; + mWorkProps.AnalysisParams.DefaultTextScanMode = item.Mode; + IsDirty = true; + } + private void MinStringCharsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { MinCharsItem item = (MinCharsItem)minStringCharsComboBox.SelectedItem; @@ -338,7 +386,6 @@ namespace SourceGen.WpfGui { #endregion General - #region Project Symbols // Item for the project symbol list view. @@ -619,7 +666,6 @@ namespace SourceGen.WpfGui { #endregion Platform symbol files - #region Extension scripts public ObservableCollection ExtensionScriptIdentifiers { get; private set; } =