1
0
mirror of https://github.com/fadden/6502bench.git synced 2026-04-20 04:16:47 +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
+7 -9
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;