1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-05-31 22:41:37 +00:00

Fix L1/L2 ASCII string editing

The data operand editor determines low vs. high ASCII formatting by
examining the first byte of string data.  Unfortunately the test was
broken, and for strings with a 1- or 2-byte length, was testing the
length byte instead of the character data.  This is now fixed.

This also changes the way empty strings are handled.  Before, they
were allowed but not counted, so you couldn't create an empty string
by itself, but could do it if it were part of a larger group.  This
was unnecessarily restrictive.  Empty L1/L2/null-term strings are now
allowed.

This means that a buffer full of $00 can be formatted as a big pile
of empty strings, which seems a bit ridiculous but there's no good
reason to obstruct it.

(issue #110)
This commit is contained in:
Andy McFadden 2021-09-12 09:35:52 -07:00
parent 62509d0bd7
commit 0dfa2326dd
3 changed files with 25 additions and 14 deletions

View File

@ -1036,7 +1036,7 @@ namespace SourceGen {
/// <summary>
/// Counts the number of null-terminated strings in the buffer.
///
/// Zero-length strings are allowed but not included in the count.
/// Zero-length strings are allowed.
/// </summary>
/// <param name="fileData">Raw data.</param>
/// <param name="start">Offset of first byte in range.</param>
@ -1058,10 +1058,8 @@ namespace SourceGen {
for (int i = start; i <= end; i++) {
byte val = fileData[i];
if (val == 0x00) {
// End of string. Only update count if string wasn't empty.
if (stringLen != 0) {
stringCount++;
}
// End of string.
stringCount++;
stringLen = 0;
expectedHiBit = -1;
} else {
@ -1088,7 +1086,7 @@ namespace SourceGen {
/// <summary>
/// Counts strings prefixed with an 8-bit length.
///
/// Zero-length strings are allowed but not counted.
/// Zero-length strings are allowed.
/// </summary>
/// <param name="fileData">Raw data.</param>
/// <param name="start">Offset of first byte in range.</param>
@ -1110,10 +1108,10 @@ namespace SourceGen {
return -1;
}
stringCount++;
if (strLen == 0) {
continue;
}
stringCount++;
remaining -= strLen;
int expectedHiBit = fileData[posn] & 0x80;
@ -1137,7 +1135,7 @@ namespace SourceGen {
/// <summary>
/// Counts strings prefixed with a 16-bit length.
///
/// Zero-length strings are allowed but not counted.
/// Zero-length strings are allowed.
/// </summary>
/// <param name="fileData">Raw data.</param>
/// <param name="start">Offset of first byte in range.</param>
@ -1165,10 +1163,10 @@ namespace SourceGen {
return -1;
}
stringCount++;
if (strLen == 0) {
continue;
}
stringCount++;
remaining -= strLen;
int expectedHiBit = fileData[posn] & 0x80;

View File

@ -210,7 +210,7 @@ work for all regions will be shown.</p>
data you have selected is in the appropriate format. For example,
"Null-terminated strings" is only enabled if the data regions are
composed entirely of characters followed by $00. Zero-length strings
are allowed, but only if some non-zero-length strings are present.
are allowed.
DCI (Dextral Character Inverted) strings have the high bit on the last
byte flipped; for PETSCII this will usually look like a series of
lower-case letters followed by a capital letter, but may look odd if the

View File

@ -565,6 +565,8 @@ namespace SourceGen.WpfGui {
radioStringLen16.IsEnabled = true;
radioStringDci.IsEnabled = true;
// This will disable a string type if we don't find at least one in every region.
IEnumerator<TypedRangeSet.TypedRange> iter = mSelection.RangeListIterator;
while (iter.MoveNext()) {
TypedRangeSet.TypedRange rng = iter.Current;
@ -1367,15 +1369,26 @@ namespace SourceGen.WpfGui {
int i;
for (i = low; i <= high;) {
int length = mFileData[i];
int lenLen;
if (type == FormatDescriptor.Type.StringL16) {
length |= mFileData[i + 1] << 8;
length += 2;
lenLen = 2;
} else {
length++;
lenLen = 1;
}
length += lenLen;
// Zero-length strings are allowed.
FormatDescriptor dfd = FormatDescriptor.Create(length, type,
ResolveAsciiGeneric(i, subType));
FormatDescriptor.SubType actualSubType = subType;
if (subType == FormatDescriptor.SubType.ASCII_GENERIC) {
if (length > lenLen) {
actualSubType = ResolveAsciiGeneric(i + lenLen, subType);
} else {
// Zero-length string, just pick a format.
actualSubType = FormatDescriptor.SubType.Ascii;
}
}
FormatDescriptor dfd = FormatDescriptor.Create(length, type, actualSubType);
Results.Add(i, dfd);
i += length;
}