1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-06-27 18:29:30 +00:00

Add C64 character conversions to hex dump viewer

The conversion mode enum was replaced, so we will lose the previous
combo box setting after an upgrade.
This commit is contained in:
Andy McFadden 2019-08-16 15:38:31 -07:00
parent 479be1a58e
commit 268ad18067
4 changed files with 50 additions and 44 deletions

View File

@ -81,7 +81,14 @@ namespace Asm65 {
// hex dumps
public bool mHexDumpAsciiOnly; // disallow non-ASCII chars in hex dumps?
public enum CharConvMode { Unknown = 0, PlainAscii, HighLowAscii };
public enum CharConvMode {
// TODO(maybe): just pass in a CharEncoding.Convert delegate
Unknown = 0,
Ascii,
LowHighAscii,
C64Petscii,
C64ScreenCode
};
public CharConvMode mHexDumpCharConvMode; // character conversion mode for dumps
// This determines what operators are available and what their precedence is.
@ -321,6 +328,8 @@ namespace Asm65 {
// Buffer to use when generating hex dump lines.
private char[] mHexDumpBuffer;
private CharEncoding.Convert mHexDumpCharConv;
/// <summary>
/// A 16-character array with 0-9a-f, for hex conversions. The letters will be
/// upper or lower case, per the format config.
@ -430,6 +439,25 @@ namespace Asm65 {
Debug.WriteLine("NOTE: char delimiters not set");
chrDelim = DelimiterSet.GetDefaultCharDelimiters();
}
switch (mFormatConfig.mHexDumpCharConvMode) {
case FormatConfig.CharConvMode.Ascii:
mHexDumpCharConv = CharEncoding.ConvertAscii;
break;
case FormatConfig.CharConvMode.LowHighAscii:
mHexDumpCharConv = CharEncoding.ConvertLowAndHighAscii;
break;
case FormatConfig.CharConvMode.C64Petscii:
mHexDumpCharConv = CharEncoding.ConvertC64Petscii;
break;
case FormatConfig.CharConvMode.C64ScreenCode:
mHexDumpCharConv = CharEncoding.ConvertC64ScreenCode;
break;
default:
// most some things don't configure the hex dump; this is fine
mHexDumpCharConv = CharEncoding.ConvertLowAndHighAscii;
break;
}
}
/// <summary>
@ -958,13 +986,8 @@ namespace Asm65 {
/// <param name="val">Value to convert.</param>
/// <returns>Printable character.</returns>
private char CharConv(byte val) {
char ch;
if (mFormatConfig.mHexDumpCharConvMode == FormatConfig.CharConvMode.HighLowAscii) {
ch = (char)(val & 0x7f);
} else {
ch = (char)val;
}
if (CommonUtil.TextUtil.IsPrintableAscii(ch)) {
char ch = mHexDumpCharConv(val);
if (ch != CharEncoding.UNPRINTABLE_CHAR) {
return ch;
} else if (mFormatConfig.mHexDumpAsciiOnly) {
return '.';

View File

@ -36,6 +36,8 @@ namespace SourceGen {
/// Some parameters we feed to the analyzers.
/// </summary>
public class AnalysisParameters {
// This is very similar to Formatter.FormatConfig.CharConvMode, but it serves
// a different purpose and might diverge in the future.
public enum TextScanMode {
Unknown = 0,
LowAscii,

View File

@ -23,13 +23,15 @@ limitations under the License.
xmlns:local="clr-namespace:SourceGen.WpfGui"
mc:Ignorable="d"
Title="Hex Dump Viewer"
Width="542" Height="600" MinWidth="542" MinHeight="180"
Width="542" Height="600" MinWidth="542" MinHeight="180" ResizeMode="CanResizeWithGrip"
ShowInTaskbar="True"
Loaded="Window_Loaded">
<Window.Resources>
<system:String x:Key="str_PlainAscii">Basic ASCII</system:String>
<system:String x:Key="str_HighLowAscii">High/Low ASCII</system:String>
<system:String x:Key="str_AsciiOnly">Plain ASCII only</system:String>
<system:String x:Key="str_LowHighAscii">Low/High ASCII</system:String>
<system:String x:Key="str_C64Petscii">C64 PETSCII</system:String>
<system:String x:Key="str_C64ScreenCode">C64 Screen Code</system:String>
</Window.Resources>
<Grid Margin="8">
@ -54,7 +56,7 @@ limitations under the License.
ScrollViewer.CanContentScroll="True"
VerticalScrollBarVisibility="Visible">
<DataGrid.Columns>
<DataGridTextColumn Header="Offset 0 1 2 3 4 5 6 7 8 9 A B C D E F ASCII"
<DataGridTextColumn Header="Offset 0 1 2 3 4 5 6 7 8 9 A B C D E F Text"
Width="491" Binding="{Binding}"/>
</DataGrid.Columns>
</DataGrid>

View File

@ -21,6 +21,7 @@ using System.Windows;
using System.Windows.Controls;
using Asm65;
using CharConvMode = Asm65.Formatter.FormatConfig.CharConvMode;
namespace SourceGen.Tools.WpfGui {
/// <summary>
@ -67,16 +68,6 @@ namespace SourceGen.Tools.WpfGui {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
/// <summary>
/// Character conversion modes. These determine how we interpret bytes for the
/// ASCII portion of the dump.
/// </summary>
public enum CharConvMode {
Unknown = 0,
PlainAscii,
HighLowAscii
}
/// <summary>
/// Character conversion combo box item.
/// </summary>
@ -103,10 +94,14 @@ namespace SourceGen.Tools.WpfGui {
mFormatter = formatter;
CharConvItems = new CharConvItem[] {
new CharConvItem((string)FindResource("str_PlainAscii"),
CharConvMode.PlainAscii),
new CharConvItem((string)FindResource("str_HighLowAscii"),
CharConvMode.HighLowAscii),
new CharConvItem((string)FindResource("str_AsciiOnly"),
CharConvMode.Ascii),
new CharConvItem((string)FindResource("str_LowHighAscii"),
CharConvMode.LowHighAscii),
new CharConvItem((string)FindResource("str_C64Petscii"),
CharConvMode.C64Petscii),
new CharConvItem((string)FindResource("str_C64ScreenCode"),
CharConvMode.C64ScreenCode),
};
}
@ -116,7 +111,7 @@ namespace SourceGen.Tools.WpfGui {
// Restore conv mode setting.
CharConvMode mode = (CharConvMode)AppSettings.Global.GetEnum(
AppSettings.HEXD_CHAR_CONV, typeof(CharConvMode), (int)CharConvMode.PlainAscii);
AppSettings.HEXD_CHAR_CONV, typeof(CharConvMode), (int)CharConvMode.Ascii);
int index = 0;
for (int i = 0; i < CharConvItems.Length; i++) {
if (CharConvItems[i].Mode == mode) {
@ -127,11 +122,6 @@ namespace SourceGen.Tools.WpfGui {
charConvComboBox.SelectedIndex = index;
}
//private void Window_Closing(object sender, EventArgs e) {
// Debug.WriteLine("Window width: " + ActualWidth);
// Debug.WriteLine("Column width: " + hexDumpData.Columns[0].ActualWidth);
//}
/// <summary>
/// Sets the filename associated with the data. This is for display purposes only.
/// </summary>
@ -152,18 +142,7 @@ namespace SourceGen.Tools.WpfGui {
// initializing
return;
}
switch (item.Mode) {
case CharConvMode.PlainAscii:
config.mHexDumpCharConvMode = Formatter.FormatConfig.CharConvMode.PlainAscii;
break;
case CharConvMode.HighLowAscii:
config.mHexDumpCharConvMode = Formatter.FormatConfig.CharConvMode.HighLowAscii;
break;
default:
Debug.Assert(false);
break;
}
config.mHexDumpCharConvMode = item.Mode;
config.mHexDumpAsciiOnly = AsciiOnlyDump;