/// <summary> /// Configures the assembler-specific format items. /// </summary> private void SetFormatConfigValues(ref Formatter.FormatConfig config) { config.mSuppressImpliedAcc = true; config.mOperandWrapLen = 64; config.mForceDirectOpcodeSuffix = "+1"; config.mForceAbsOpcodeSuffix = "+2"; config.mForceLongOpcodeSuffix = "+3"; config.mForceDirectOperandPrefix = string.Empty; config.mForceAbsOperandPrefix = string.Empty; config.mForceLongOperandPrefix = string.Empty; config.mLocalVariableLabelPrefix = "."; config.mEndOfLineCommentDelimiter = ";"; config.mFullLineCommentDelimiterBase = ";"; config.mBoxLineCommentDelimiter = ";"; config.mNonUniqueLabelPrefix = "@"; config.mCommaSeparatedDense = false; config.mExpressionMode = Formatter.FormatConfig.ExpressionMode.Common; Formatter.DelimiterSet charSet = new Formatter.DelimiterSet(); charSet.Set(CharEncoding.Encoding.Ascii, Formatter.SINGLE_QUOTE_DELIM); charSet.Set(CharEncoding.Encoding.HighAscii, new Formatter.DelimiterDef(string.Empty, '\'', '\'', " | $80")); config.mCharDelimiters = charSet; }
// IGenerator public GenerationResults GenerateSource(BackgroundWorker worker) { List <string> pathNames = new List <string>(1); string fileName = mFileNameBase + ASM_FILE_SUFFIX; string pathName = Path.Combine(mWorkDirectory, fileName); pathNames.Add(pathName); Formatter.FormatConfig config = new Formatter.FormatConfig(); GenCommon.ConfigureFormatterFromSettings(Settings, ref config); SetFormatConfigValues(ref config); // Configure delimiters for single-character operands. Formatter.DelimiterSet charDelimSet = new Formatter.DelimiterSet(); charDelimSet.Set(CharEncoding.Encoding.C64Petscii, Formatter.SINGLE_QUOTE_DELIM); charDelimSet.Set(CharEncoding.Encoding.C64ScreenCode, Formatter.SINGLE_QUOTE_DELIM); charDelimSet.Set(CharEncoding.Encoding.Ascii, Formatter.SINGLE_QUOTE_DELIM); charDelimSet.Set(CharEncoding.Encoding.HighAscii, new Formatter.DelimiterDef(string.Empty, '\'', '\'', " | $80")); config.mCharDelimiters = charDelimSet; SourceFormatter = new Formatter(config); string msg = string.Format(Res.Strings.PROGRESS_GENERATING_FMT, pathName); worker.ReportProgress(0, msg); mLocalizer = new LabelLocalizer(Project); mLocalizer.LocalPrefix = "_"; mLocalizer.QuirkNoOpcodeMnemonics = true; mLocalizer.Analyze(); bool needLongAddress = Project.FileDataLength > 65536 + (mHasPrgHeader ? 2 : 0); string extraOptions = string.Empty + (needLongAddress ? AsmTass64.LONG_ADDRESS : string.Empty) + (mHasPrgHeader ? string.Empty : AsmTass64.NOSTART); mPcDepth = 0; mFirstIsOpen = true; // Use UTF-8 encoding, without a byte-order mark. using (StreamWriter sw = new StreamWriter(pathName, false, new UTF8Encoding(false))) { mOutStream = sw; if (Settings.GetBool(AppSettings.SRCGEN_ADD_IDENT_COMMENT, false)) { OutputLine(SourceFormatter.FullLineCommentDelimiter + string.Format(Res.Strings.GENERATED_FOR_VERSION_FMT, "64tass", mAsmVersion, AsmTass64.BASE_OPTIONS + extraOptions)); } GenCommon.Generate(this, sw, worker); } mOutStream = null; return(new GenerationResults(pathNames, extraOptions)); }
// IGenerator public List <string> GenerateSource(BackgroundWorker worker) { List <string> pathNames = new List <string>(1); string fileName = mFileNameBase + ASM_FILE_SUFFIX; string pathName = Path.Combine(mWorkDirectory, fileName); pathNames.Add(pathName); Formatter.FormatConfig config = new Formatter.FormatConfig(); GenCommon.ConfigureFormatterFromSettings(Settings, ref config); SetFormatConfigValues(ref config); // Configure delimiters for single-character operands. Formatter.DelimiterSet charDelimSet = new Formatter.DelimiterSet(); charDelimSet.Set(CharEncoding.Encoding.C64Petscii, Formatter.SINGLE_QUOTE_DELIM); charDelimSet.Set(CharEncoding.Encoding.C64ScreenCode, Formatter.SINGLE_QUOTE_DELIM); charDelimSet.Set(CharEncoding.Encoding.Ascii, Formatter.SINGLE_QUOTE_DELIM); charDelimSet.Set(CharEncoding.Encoding.HighAscii, new Formatter.DelimiterDef(string.Empty, '\'', '\'', " | $80")); config.mCharDelimiters = charDelimSet; SourceFormatter = new Formatter(config); string msg = string.Format(Res.Strings.PROGRESS_GENERATING_FMT, pathName); worker.ReportProgress(0, msg); mLocalizer = new LabelLocalizer(Project); mLocalizer.LocalPrefix = "_"; mLocalizer.QuirkNoOpcodeMnemonics = true; mLocalizer.Analyze(); // Use UTF-8 encoding, without a byte-order mark. using (StreamWriter sw = new StreamWriter(pathName, false, new UTF8Encoding(false))) { mOutStream = sw; if (Settings.GetBool(AppSettings.SRCGEN_ADD_IDENT_COMMENT, false)) { OutputLine(SourceFormatter.FullLineCommentDelimiter + string.Format(Res.Strings.GENERATED_FOR_VERSION_FMT, "64tass", V1_53, AsmTass64.OPTIONS)); } GenCommon.Generate(this, sw, worker); if (mNeedHereOp) { OutputLine(string.Empty, SourceFormatter.FormatPseudoOp(HERE_PSEUDO_OP), string.Empty, string.Empty); } } mOutStream = null; return(pathNames); }
/// <summary> /// Configures the assembler-specific format items. /// </summary> private void SetFormatConfigValues(ref Formatter.FormatConfig config) { config.mForceDirectOpcodeSuffix = string.Empty; config.mForceAbsOpcodeSuffix = ":"; config.mForceLongOpcodeSuffix = "l"; config.mForceDirectOperandPrefix = string.Empty; config.mForceAbsOperandPrefix = string.Empty; config.mForceLongOperandPrefix = string.Empty; config.mLocalVariableLablePrefix = "]"; config.mEndOfLineCommentDelimiter = ";"; config.mFullLineCommentDelimiterBase = ";"; config.mBoxLineCommentDelimiter = string.Empty; config.mExpressionMode = Formatter.FormatConfig.ExpressionMode.Merlin; Formatter.DelimiterSet charSet = new Formatter.DelimiterSet(); charSet.Set(CharEncoding.Encoding.Ascii, Formatter.SINGLE_QUOTE_DELIM); charSet.Set(CharEncoding.Encoding.HighAscii, Formatter.DOUBLE_QUOTE_DELIM); config.mCharDelimiters = charSet; }
/// <summary> /// Configures the assembler-specific format items. /// </summary> private void SetFormatConfigValues(ref Formatter.FormatConfig config) { config.mForceDirectOpcodeSuffix = string.Empty; config.mForceAbsOpcodeSuffix = string.Empty; config.mForceLongOpcodeSuffix = string.Empty; config.mForceDirectOperandPrefix = "z:"; // zero config.mForceAbsOperandPrefix = "a:"; // absolute config.mForceLongOperandPrefix = "f:"; // far config.mEndOfLineCommentDelimiter = ";"; config.mFullLineCommentDelimiterBase = ";"; config.mBoxLineCommentDelimiter = ";"; config.mExpressionMode = Formatter.FormatConfig.ExpressionMode.Cc65; Formatter.DelimiterSet charSet = new Formatter.DelimiterSet(); charSet.Set(CharEncoding.Encoding.Ascii, Formatter.SINGLE_QUOTE_DELIM); charSet.Set(CharEncoding.Encoding.HighAscii, new Formatter.DelimiterDef(string.Empty, '\'', '\'', " | $80")); config.mCharDelimiters = charSet; }
/// <summary> /// Converts a collection of bytes that represent a string into an array of formatted /// string operands. /// </summary> /// <param name="formatter">Formatter object.</param> /// <param name="opNames">Pseudo-opcode name table.</param> /// <param name="dfd">Format descriptor.</param> /// <param name="data">File data.</param> /// <param name="offset">Offset, within data, of start of string.</param> /// <param name="popcode">Pseudo-opcode string.</param> /// <returns>Array of operand strings.</returns> public static List <string> FormatStringOp(Formatter formatter, PseudoOpNames opNames, FormatDescriptor dfd, byte[] data, int offset, out string popcode) { int hiddenLeadingBytes = 0; int trailingBytes = 0; StringOpFormatter.ReverseMode revMode = StringOpFormatter.ReverseMode.Forward; Formatter.DelimiterSet delSet = formatter.Config.mStringDelimiters; Formatter.DelimiterDef delDef; CharEncoding.Convert charConv; switch (dfd.FormatSubType) { case FormatDescriptor.SubType.Ascii: if (dfd.FormatType == FormatDescriptor.Type.StringDci) { charConv = CharEncoding.ConvertLowAndHighAscii; } else { charConv = CharEncoding.ConvertAscii; } delDef = delSet.Get(CharEncoding.Encoding.Ascii); break; case FormatDescriptor.SubType.HighAscii: if (dfd.FormatType == FormatDescriptor.Type.StringDci) { charConv = CharEncoding.ConvertLowAndHighAscii; } else { charConv = CharEncoding.ConvertHighAscii; } delDef = delSet.Get(CharEncoding.Encoding.HighAscii); break; case FormatDescriptor.SubType.C64Petscii: if (dfd.FormatType == FormatDescriptor.Type.StringDci) { charConv = CharEncoding.ConvertLowAndHighC64Petscii; } else { charConv = CharEncoding.ConvertC64Petscii; } delDef = delSet.Get(CharEncoding.Encoding.C64Petscii); break; case FormatDescriptor.SubType.C64Screen: if (dfd.FormatType == FormatDescriptor.Type.StringDci) { charConv = CharEncoding.ConvertLowAndHighC64ScreenCode; } else { charConv = CharEncoding.ConvertC64ScreenCode; } delDef = delSet.Get(CharEncoding.Encoding.C64ScreenCode); break; default: Debug.Assert(false); charConv = CharEncoding.ConvertAscii; delDef = delSet.Get(CharEncoding.Encoding.Ascii); break; } if (delDef == null) { delDef = Formatter.DOUBLE_QUOTE_DELIM; } switch (dfd.FormatType) { case FormatDescriptor.Type.StringGeneric: // Generic character data. popcode = opNames.StrGeneric; break; case FormatDescriptor.Type.StringReverse: // Character data, full width specified by formatter. Show characters // in reverse order. popcode = opNames.StrReverse; revMode = StringOpFormatter.ReverseMode.FullReverse; break; case FormatDescriptor.Type.StringNullTerm: // Character data with a terminating null. Don't show the null byte. popcode = opNames.StrNullTerm; trailingBytes = 1; //if (strLen == 0) { // showHexZeroes = 1; //} break; case FormatDescriptor.Type.StringL8: // Character data with a leading length byte. Don't show the length. hiddenLeadingBytes = 1; //if (strLen == 0) { // showHexZeroes = 1; //} popcode = opNames.StrLen8; break; case FormatDescriptor.Type.StringL16: // Character data with a leading length word. Don't show the length. Debug.Assert(dfd.Length > 1); hiddenLeadingBytes = 2; //if (strLen == 0) { // showHexZeroes = 2; //} popcode = opNames.StrLen16; break; case FormatDescriptor.Type.StringDci: // High bit on last byte is flipped. popcode = opNames.StrDci; break; default: Debug.Assert(false); popcode = ".!!!"; break; } StringOpFormatter stropf = new StringOpFormatter(formatter, delDef, StringOpFormatter.RawOutputStyle.CommaSep, MAX_OPERAND_LEN, charConv); stropf.FeedBytes(data, offset + hiddenLeadingBytes, dfd.Length - hiddenLeadingBytes - trailingBytes, 0, revMode); return(stropf.Lines); }