Example #1
0
        // IGenerator
        public void OutputLine(string label, string opcode, string operand, string comment)
        {
            // Break the line if the label is long and it's not a .EQ/.VAR directive.
            if (!string.IsNullOrEmpty(label) &&
                !string.Equals(opcode, sDataOpNames.EquDirective,
                               StringComparison.InvariantCultureIgnoreCase) &&
                !string.Equals(opcode, sDataOpNames.VarDirective,
                               StringComparison.InvariantCultureIgnoreCase))
            {
                if (mLongLabelNewLine && label.Length >= mColumnWidths[0])
                {
                    mOutStream.WriteLine(label);
                    label = string.Empty;
                }
            }

            mLineBuilder.Clear();
            TextUtil.AppendPaddedString(mLineBuilder, label, 0);
            TextUtil.AppendPaddedString(mLineBuilder, opcode, mColumnWidths[0]);
            TextUtil.AppendPaddedString(mLineBuilder, operand,
                                        mColumnWidths[0] + mColumnWidths[1]);
            TextUtil.AppendPaddedString(mLineBuilder, comment,
                                        mColumnWidths[0] + mColumnWidths[1] + mColumnWidths[2]);

            mOutStream.WriteLine(mLineBuilder.ToString());
        }
Example #2
0
        // IGenerator
        public void OutputLine(string label, string opcode, string operand, string comment)
        {
            // If a label is provided, and it doesn't start with a '.' (indicating that it's
            // a directive), and this isn't an EQU directive, add a ':'.  Might be easier to
            // just ".feature labels_without_colons", but I'm trying to do things the way
            // that cc65 users will expect.
            if (!string.IsNullOrEmpty(label) && label[0] != '.' &&
                !string.Equals(opcode, sDataOpNames.EquDirective,
                               StringComparison.InvariantCultureIgnoreCase) &&
                !string.Equals(opcode, sDataOpNames.VarDirective,
                               StringComparison.InvariantCultureIgnoreCase))
            {
                label += ':';

                if (mLongLabelNewLine && label.Length >= mColumnWidths[0])
                {
                    mOutStream.WriteLine(label);
                    label = string.Empty;
                }
            }

            mLineBuilder.Clear();
            TextUtil.AppendPaddedString(mLineBuilder, label, 0);
            TextUtil.AppendPaddedString(mLineBuilder, opcode, mColumnWidths[0]);
            TextUtil.AppendPaddedString(mLineBuilder, operand,
                                        mColumnWidths[0] + mColumnWidths[1]);
            TextUtil.AppendPaddedString(mLineBuilder, comment,
                                        mColumnWidths[0] + mColumnWidths[1] + mColumnWidths[2]);

            mOutStream.WriteLine(mLineBuilder.ToString());
        }
Example #3
0
        // IGenerator
        public void OutputOrgDirective(int offset, int address)
        {
            // Linear search for offset.  List should be small, so this should be quick.
            int index = 0;

            foreach (AddressMap.AddressMapEntry ame in Project.AddrMap)
            {
                if (ame.Offset == offset)
                {
                    break;
                }
                index++;
            }

            mLineBuilder.Clear();
            TextUtil.AppendPaddedString(mLineBuilder, ";", 0);
            // using +1 to make it look like the comment ';' shifted it over
            TextUtil.AppendPaddedString(mLineBuilder, SourceFormatter.FormatPseudoOp(".segment"),
                                        mColumnWidths[0] + 1);
            TextUtil.AppendPaddedString(mLineBuilder, string.Format("\"SEG{0:D3}\"", index),
                                        mColumnWidths[0] + mColumnWidths[1] + 1);
            OutputLine(mLineBuilder.ToString());

            OutputLine(string.Empty, SourceFormatter.FormatPseudoOp(sDataOpNames.OrgDirective),
                       SourceFormatter.FormatHexValue(address, 4), string.Empty);
        }
Example #4
0
        // IGenerator
        public void OutputLine(string label, string opcode, string operand, string comment)
        {
            // Split long label, but not on EQU directives (confuses the assembler).
            if (mLongLabelNewLine && label.Length >= 9 &&
                !String.Equals(opcode, sDataOpNames.EquDirective,
                               StringComparison.InvariantCultureIgnoreCase))
            {
                mOutStream.WriteLine(label);
                label = string.Empty;
            }

            mLineBuilder.Clear();
            TextUtil.AppendPaddedString(mLineBuilder, label, 9);
            TextUtil.AppendPaddedString(mLineBuilder, opcode, 9 + 6);
            TextUtil.AppendPaddedString(mLineBuilder, operand, 9 + 6 + 11);
            if (string.IsNullOrEmpty(comment))
            {
                // Trim trailing spaces off of opcode or operand.  If they want trailing
                // spaces at the end of a comment, that's fine.
                CommonUtil.TextUtil.TrimEnd(mLineBuilder);
            }
            else
            {
                mLineBuilder.Append(comment);
            }

            mOutStream.WriteLine(mLineBuilder.ToString());
        }
Example #5
0
        // IGenerator
        public void OutputLine(string label, string opcode, string operand, string comment)
        {
            // Break the line if the label is long and it's not a .EQ directive.
            if (!string.IsNullOrEmpty(label) &&
                !string.Equals(opcode, sDataOpNames.EquDirective,
                               StringComparison.InvariantCultureIgnoreCase))
            {
                if (mLongLabelNewLine && label.Length >= mColumnWidths[0])
                {
                    mOutStream.WriteLine(label);
                    label = string.Empty;
                }
            }

            mLineBuilder.Clear();
            TextUtil.AppendPaddedString(mLineBuilder, label, mColumnWidths[0]);
            TextUtil.AppendPaddedString(mLineBuilder, opcode, mColumnWidths[0] + mColumnWidths[1]);
            TextUtil.AppendPaddedString(mLineBuilder, operand,
                                        mColumnWidths[0] + mColumnWidths[1] + mColumnWidths[2]);
            if (string.IsNullOrEmpty(comment))
            {
                // Trim trailing spaces off of opcode or operand.  If they want trailing
                // spaces at the end of a comment, that's fine.
                CommonUtil.TextUtil.TrimEnd(mLineBuilder);
            }
            else
            {
                mLineBuilder.Append(comment);
            }

            mOutStream.WriteLine(mLineBuilder.ToString());
        }
Example #6
0
        // IGenerator
        public void OutputLine(string label, string opcode, string operand, string comment)
        {
            // Split long label, but not on EQU directives (confuses the assembler).
            if (mLongLabelNewLine && label.Length >= mColumnWidths[0] &&
                !string.Equals(opcode, sDataOpNames.EquDirective,
                               StringComparison.InvariantCultureIgnoreCase))
            {
                mOutStream.WriteLine(label);
                label = string.Empty;
            }

            mLineBuilder.Clear();
            TextUtil.AppendPaddedString(mLineBuilder, label, 0);
            TextUtil.AppendPaddedString(mLineBuilder, opcode, mColumnWidths[0]);
            TextUtil.AppendPaddedString(mLineBuilder, operand,
                                        mColumnWidths[0] + mColumnWidths[1]);
            TextUtil.AppendPaddedString(mLineBuilder, comment,
                                        mColumnWidths[0] + mColumnWidths[1] + mColumnWidths[2]);

            mOutStream.WriteLine(mLineBuilder.ToString());
        }
Example #7
0
        // IGenerator
        public void OutputLine(string label, string opcode, string operand, string comment)
        {
            // If a label is provided, and it doesn't start with a '.' (indicating that it's
            // a directive), and this isn't an EQU directive, add a ':'.  Might be easier to
            // just ".feature labels_without_colons", but I'm trying to do things the way
            // that cc65 users will expect.
            if (!string.IsNullOrEmpty(label) && label[0] != '.' &&
                !String.Equals(opcode, sDataOpNames.EquDirective,
                               StringComparison.InvariantCultureIgnoreCase))
            {
                label += ':';

                if (mLongLabelNewLine && label.Length >= 9)
                {
                    mOutStream.WriteLine(label);
                    label = string.Empty;
                }
            }

            mLineBuilder.Clear();
            TextUtil.AppendPaddedString(mLineBuilder, label, 9);
            TextUtil.AppendPaddedString(mLineBuilder, opcode, 9 + 8);
            TextUtil.AppendPaddedString(mLineBuilder, operand, 9 + 8 + 11);
            if (string.IsNullOrEmpty(comment))
            {
                // Trim trailing spaces off of opcode or operand.  If they want trailing
                // spaces at the end of a comment, that's fine.
                CommonUtil.TextUtil.TrimEnd(mLineBuilder);
            }
            else
            {
                mLineBuilder.Append(comment);
            }

            mOutStream.WriteLine(mLineBuilder.ToString());
        }
Example #8
0
        /// <summary>
        /// Generates text output for one display line.  This may result in more than one line
        /// of output, e.g. if the label is longer than the field.  EOL markers will be added.
        /// </summary>
        /// <param name="index">Index of line to output.</param>
        /// <param name="tw">Text output destination.</param>
        /// <param name="sb">Pre-allocated string builder (this is a minor optimization).</param>
        private void GenerateTextLine(int index, TextWriter tw, StringBuilder sb)
        {
            LineListGen.Line line = mCodeLineList[index];
            if (line.LineType == LineListGen.Line.Type.Note && !IncludeNotes)
            {
                return;
            }

            // Width of "bytes" field, without '+' or trailing space.
            int bytesWidth = mColStart[(int)Col.Bytes + 1] - mColStart[(int)Col.Bytes] - 2;
            // Width of "label" field, without trailing space.
            int maxLabelLen = mColStart[(int)Col.Label + 1] - mColStart[(int)Col.Label] - 1;

            DisplayList.FormattedParts parts = mCodeLineList.GetFormattedParts(index);
            sb.Clear();

            // Put long labels on their own line if desired.
            bool suppressLabel = false;

            if (LongLabelNewLine && (line.LineType == LineListGen.Line.Type.Code ||
                                     line.LineType == LineListGen.Line.Type.Data))
            {
                int labelLen = string.IsNullOrEmpty(parts.Label) ? 0 : parts.Label.Length;
                if (labelLen > maxLabelLen)
                {
                    // put on its own line
                    TextUtil.AppendPaddedString(sb, parts.Label, mColStart[(int)Col.Label]);
                    tw.WriteLine(sb);
                    sb.Clear();
                    suppressLabel = true;
                }
            }

            switch (line.LineType)
            {
            case LineListGen.Line.Type.Code:
            case LineListGen.Line.Type.Data:
            case LineListGen.Line.Type.EquDirective:
            case LineListGen.Line.Type.RegWidthDirective:
            case LineListGen.Line.Type.OrgDirective:
            case LineListGen.Line.Type.LocalVariableTable:
                if (parts.IsLongComment)
                {
                    // This happens for long comments embedded in LV tables.
                    TextUtil.AppendPaddedString(sb, parts.Comment, mColStart[(int)Col.Label]);
                    break;
                }

                if ((mLeftFlags & ActiveColumnFlags.Offset) != 0)
                {
                    TextUtil.AppendPaddedString(sb, parts.Offset,
                                                mColStart[(int)Col.Offset]);
                }
                if ((mLeftFlags & ActiveColumnFlags.Address) != 0)
                {
                    if (!string.IsNullOrEmpty(parts.Addr))
                    {
                        TextUtil.AppendPaddedString(sb, parts.Addr + ":",
                                                    mColStart[(int)Col.Address]);
                    }
                }
                if ((mLeftFlags & ActiveColumnFlags.Bytes) != 0)
                {
                    // Shorten the "...".
                    string bytesStr = parts.Bytes;
                    if (bytesStr != null && bytesStr.Length > bytesWidth)
                    {
                        bytesStr = bytesStr.Substring(0, bytesWidth) + "+";
                    }
                    TextUtil.AppendPaddedString(sb, bytesStr, mColStart[(int)Col.Bytes]);
                }
                if ((mLeftFlags & ActiveColumnFlags.Flags) != 0)
                {
                    TextUtil.AppendPaddedString(sb, parts.Flags, mColStart[(int)Col.Flags]);
                }
                if ((mLeftFlags & ActiveColumnFlags.Attr) != 0)
                {
                    TextUtil.AppendPaddedString(sb, parts.Attr, mColStart[(int)Col.Attr]);
                }
                if (!suppressLabel)
                {
                    TextUtil.AppendPaddedString(sb, parts.Label, mColStart[(int)Col.Label]);
                }
                TextUtil.AppendPaddedString(sb, parts.Opcode, mColStart[(int)Col.Opcode]);
                TextUtil.AppendPaddedString(sb, parts.Operand, mColStart[(int)Col.Operand]);
                TextUtil.AppendPaddedString(sb, parts.Comment, mColStart[(int)Col.Comment]);
                break;

            case LineListGen.Line.Type.LongComment:
            case LineListGen.Line.Type.Note:
                TextUtil.AppendPaddedString(sb, parts.Comment, mColStart[(int)Col.Label]);
                break;

            case LineListGen.Line.Type.VisualizationSet:
                return;         // show nothing

            case LineListGen.Line.Type.Blank:
                break;

            default:
                Debug.Assert(false);
                break;
            }

            tw.WriteLine(sb);
        }