\r\n");
// Set the default color in the
style.
sb.Append("");
int offset = 0;
while (offset < data.Length) {
int nextAddr, lineNum;
bool inQuote = false;
bool inRem = false;
nextAddr = Read16(data, ref offset);
if (nextAddr == 0) {
if (data.Length - offset > 1) {
Debug.WriteLine("WARNING: BAS ended early, at +" + offset.ToString("x6"));
}
break;
}
// print line number
lineNum = Read16(data, ref offset);
SetColor(mLineNumColor, sb);
sb.Append(' ');
sb.Append(lineNum);
sb.Append(' ');
SetColor(mDefaultColor, sb);
while (offset < data.Length && data[offset] != 0) {
char tokVal = (char)data[offset];
if ((tokVal & 0x80) != 0) {
// token
SetColor(mKeywordColor, sb);
sb.Append(' ');
sb.Append(TOKENS[tokVal & 0x7f]);
sb.Append(' ');
SetColor(mDefaultColor, sb);
if (tokVal == TOK_REM) {
// REM -- do rest of line in green
SetColor(mCommentColor, sb);
inRem = true;
}
} else {
// non-token character
if (tokVal == '"' && !inRem) {
if (!inQuote) {
SetColor(mStringColor, sb);
sb.Append(tokVal);
} else {
sb.Append(tokVal);
SetColor(mDefaultColor, sb);
}
inQuote = !inQuote;
} else if (tokVal == ':' && !inRem && !inQuote) {
SetColor(mColonColor, sb);
sb.Append(tokVal);
SetColor(mDefaultColor, sb);
} else if (inRem && tokVal == '\r') {
sb.Append("\r\n"); // embedded CR
} else if (tokVal < 0x20) {
// control character, in string or REM
//sb.Append("•");
// output with Unicode "control pictures" block
sb.Append("");
sb.Append((tokVal + 0x2400).ToString("x4"));
sb.Append(";");
} else {
// Output as ASCII value.
sb.Append(tokVal);
}
}
offset++;
}
SetColor(mDefaultColor, sb);
inQuote = inRem = false;
offset++;
sb.Append("\r\n");
}
sb.Append("
\r\n");
sb.Append("
\r\n");
return sb.ToString();
}
///