diff --git a/SourceGen/AsmGen/AsmAcme.cs b/SourceGen/AsmGen/AsmAcme.cs index eaf1a80..bab16b2 100644 --- a/SourceGen/AsmGen/AsmAcme.cs +++ b/SourceGen/AsmGen/AsmAcme.cs @@ -388,7 +388,7 @@ namespace SourceGen.AsmGen { operand = RawData.GetWord(data, offset, length, false); operandStr = PseudoOp.FormatNumericOperand(formatter, Project.SymbolTable, mLocalizer.LabelMap, dfd, operand, length, - PseudoOp.FormatNumericOpFlags.StripLabelPrefixSuffix); + PseudoOp.FormatNumericOpFlags.OmitLabelPrefixSuffix); break; case FormatDescriptor.Type.NumericBE: opcodeStr = sDataOpNames.GetDefineBigData(length); @@ -399,7 +399,7 @@ namespace SourceGen.AsmGen { operand = RawData.GetWord(data, offset, length, true); operandStr = PseudoOp.FormatNumericOperand(formatter, Project.SymbolTable, mLocalizer.LabelMap, dfd, operand, length, - PseudoOp.FormatNumericOpFlags.StripLabelPrefixSuffix); + PseudoOp.FormatNumericOpFlags.OmitLabelPrefixSuffix); } break; case FormatDescriptor.Type.Fill: @@ -516,7 +516,7 @@ namespace SourceGen.AsmGen { string valueStr = PseudoOp.FormatNumericOperand(SourceFormatter, Project.SymbolTable, null, defSym.DataDescriptor, defSym.Value, 1, - PseudoOp.FormatNumericOpFlags.StripLabelPrefixSuffix); + PseudoOp.FormatNumericOpFlags.OmitLabelPrefixSuffix); OutputEquDirective(SourceFormatter.FormatVariableLabel(defSym.Label), valueStr, defSym.Comment); } diff --git a/SourceGen/AsmGen/AsmCc65.cs b/SourceGen/AsmGen/AsmCc65.cs index 43b6d8a..34e638e 100644 --- a/SourceGen/AsmGen/AsmCc65.cs +++ b/SourceGen/AsmGen/AsmCc65.cs @@ -422,7 +422,7 @@ namespace SourceGen.AsmGen { operand = RawData.GetWord(data, offset, length, false); operandStr = PseudoOp.FormatNumericOperand(formatter, Project.SymbolTable, mLocalizer.LabelMap, dfd, operand, length, - PseudoOp.FormatNumericOpFlags.StripLabelPrefixSuffix); + PseudoOp.FormatNumericOpFlags.OmitLabelPrefixSuffix); break; case FormatDescriptor.Type.NumericBE: opcodeStr = sDataOpNames.GetDefineBigData(length); @@ -433,7 +433,7 @@ namespace SourceGen.AsmGen { operand = RawData.GetWord(data, offset, length, true); operandStr = PseudoOp.FormatNumericOperand(formatter, Project.SymbolTable, mLocalizer.LabelMap, dfd, operand, length, - PseudoOp.FormatNumericOpFlags.StripLabelPrefixSuffix); + PseudoOp.FormatNumericOpFlags.OmitLabelPrefixSuffix); } break; case FormatDescriptor.Type.Fill: @@ -548,7 +548,7 @@ namespace SourceGen.AsmGen { // Use an operand length of 1 so values are shown as concisely as possible. string valueStr = PseudoOp.FormatNumericOperand(SourceFormatter, Project.SymbolTable, null, defSym.DataDescriptor, defSym.Value, 1, - PseudoOp.FormatNumericOpFlags.StripLabelPrefixSuffix); + PseudoOp.FormatNumericOpFlags.OmitLabelPrefixSuffix); OutputLine(SourceFormatter.FormatVariableLabel(defSym.Label), SourceFormatter.FormatPseudoOp(sDataOpNames.VarDirective), valueStr, SourceFormatter.FormatEolComment(defSym.Comment)); diff --git a/SourceGen/AsmGen/AsmMerlin32.cs b/SourceGen/AsmGen/AsmMerlin32.cs index f6e3223..48dd399 100644 --- a/SourceGen/AsmGen/AsmMerlin32.cs +++ b/SourceGen/AsmGen/AsmMerlin32.cs @@ -249,7 +249,7 @@ namespace SourceGen.AsmGen { operand = RawData.GetWord(data, offset, length, false); operandStr = PseudoOp.FormatNumericOperand(formatter, Project.SymbolTable, mLocalizer.LabelMap, dfd, operand, length, - PseudoOp.FormatNumericOpFlags.StripLabelPrefixSuffix); + PseudoOp.FormatNumericOpFlags.OmitLabelPrefixSuffix); break; case FormatDescriptor.Type.NumericBE: opcodeStr = sDataOpNames.GetDefineBigData(length); @@ -260,7 +260,7 @@ namespace SourceGen.AsmGen { operand = RawData.GetWord(data, offset, length, true); operandStr = PseudoOp.FormatNumericOperand(formatter, Project.SymbolTable, mLocalizer.LabelMap, dfd, operand, length, - PseudoOp.FormatNumericOpFlags.StripLabelPrefixSuffix); + PseudoOp.FormatNumericOpFlags.OmitLabelPrefixSuffix); } break; case FormatDescriptor.Type.Fill: @@ -440,7 +440,7 @@ namespace SourceGen.AsmGen { foreach (DefSymbol defSym in newDefs) { string valueStr = PseudoOp.FormatNumericOperand(SourceFormatter, Project.SymbolTable, null, defSym.DataDescriptor, defSym.Value, 1, - PseudoOp.FormatNumericOpFlags.StripLabelPrefixSuffix); + PseudoOp.FormatNumericOpFlags.OmitLabelPrefixSuffix); OutputLine(SourceFormatter.FormatVariableLabel(defSym.Label), SourceFormatter.FormatPseudoOp(sDataOpNames.VarDirective), valueStr, SourceFormatter.FormatEolComment(defSym.Comment)); diff --git a/SourceGen/AsmGen/AsmTass64.cs b/SourceGen/AsmGen/AsmTass64.cs index 767c223..42968f5 100644 --- a/SourceGen/AsmGen/AsmTass64.cs +++ b/SourceGen/AsmGen/AsmTass64.cs @@ -454,7 +454,7 @@ namespace SourceGen.AsmGen { UpdateCharacterEncoding(dfd); operandStr = PseudoOp.FormatNumericOperand(formatter, Project.SymbolTable, mLocalizer.LabelMap, dfd, operand, length, - PseudoOp.FormatNumericOpFlags.StripLabelPrefixSuffix); + PseudoOp.FormatNumericOpFlags.OmitLabelPrefixSuffix); break; case FormatDescriptor.Type.NumericBE: opcodeStr = sDataOpNames.GetDefineBigData(length); @@ -466,7 +466,7 @@ namespace SourceGen.AsmGen { operand = RawData.GetWord(data, offset, length, true); operandStr = PseudoOp.FormatNumericOperand(formatter, Project.SymbolTable, mLocalizer.LabelMap, dfd, operand, length, - PseudoOp.FormatNumericOpFlags.StripLabelPrefixSuffix); + PseudoOp.FormatNumericOpFlags.OmitLabelPrefixSuffix); } break; case FormatDescriptor.Type.Fill: @@ -583,7 +583,7 @@ namespace SourceGen.AsmGen { foreach (DefSymbol defSym in newDefs) { string valueStr = PseudoOp.FormatNumericOperand(SourceFormatter, Project.SymbolTable, null, defSym.DataDescriptor, defSym.Value, 1, - PseudoOp.FormatNumericOpFlags.StripLabelPrefixSuffix); + PseudoOp.FormatNumericOpFlags.OmitLabelPrefixSuffix); OutputLine(SourceFormatter.FormatVariableLabel(defSym.Label), SourceFormatter.FormatPseudoOp(sDataOpNames.VarDirective), valueStr, SourceFormatter.FormatEolComment(defSym.Comment)); diff --git a/SourceGen/AsmGen/GenCommon.cs b/SourceGen/AsmGen/GenCommon.cs index ef6f522..d3d1ab9 100644 --- a/SourceGen/AsmGen/GenCommon.cs +++ b/SourceGen/AsmGen/GenCommon.cs @@ -157,7 +157,7 @@ namespace SourceGen.AsmGen { // Use an operand length of 1 so values are shown as concisely as possible. string valueStr = PseudoOp.FormatNumericOperand(formatter, proj.SymbolTable, gen.Localizer.LabelMap, defSym.DataDescriptor, defSym.Value, 1, - PseudoOp.FormatNumericOpFlags.StripLabelPrefixSuffix); + PseudoOp.FormatNumericOpFlags.OmitLabelPrefixSuffix); gen.OutputEquDirective(defSym.Label, valueStr, defSym.Comment); prevConst = defSym.IsConstant; @@ -204,7 +204,7 @@ namespace SourceGen.AsmGen { string formattedOperand = null; int operandLen = instrLen - 1; - PseudoOp.FormatNumericOpFlags opFlags = PseudoOp.FormatNumericOpFlags.StripLabelPrefixSuffix; + PseudoOp.FormatNumericOpFlags opFlags = PseudoOp.FormatNumericOpFlags.OmitLabelPrefixSuffix; bool isPcRelBankWrap = false; // Tweak branch instructions. We want to show the absolute address rather @@ -245,10 +245,10 @@ namespace SourceGen.AsmGen { // Special handling for the double-operand block move. string opstr1 = PseudoOp.FormatNumericOperand(formatter, proj.SymbolTable, gen.Localizer.LabelMap, dfd, operand >> 8, 1, - PseudoOp.FormatNumericOpFlags.StripLabelPrefixSuffix); + PseudoOp.FormatNumericOpFlags.OmitLabelPrefixSuffix); string opstr2 = PseudoOp.FormatNumericOperand(formatter, proj.SymbolTable, gen.Localizer.LabelMap, dfd, operand & 0xff, 1, - PseudoOp.FormatNumericOpFlags.StripLabelPrefixSuffix); + PseudoOp.FormatNumericOpFlags.OmitLabelPrefixSuffix); if (gen.Quirks.BlockMoveArgsReversed) { string tmp = opstr1; opstr1 = opstr2; diff --git a/SourceGen/PseudoOp.cs b/SourceGen/PseudoOp.cs index 4d8a0c7..21c486e 100644 --- a/SourceGen/PseudoOp.cs +++ b/SourceGen/PseudoOp.cs @@ -409,20 +409,27 @@ namespace SourceGen { typeStr = Res.Strings.EQU_ADDRESS; } - string msgStr = null; - if (defSym.HasWidth) { - msgStr = typeStr + "/" + defSym.DataDescriptor.Length; - } else if (defSym.IsConstant) { - // not entirely convinced we want this, but there's currently no other way - // to tell the difference between an address and a constant from the code list - msgStr = typeStr; + if (!defSym.HasWidth && !defSym.IsConstant) { + // It's an address without an explicit width, do not annotate. + return operand; } - if (msgStr == null) { - return operand; - } else { - return operand + " {" + msgStr + "}"; + StringBuilder sb = new StringBuilder(operand.Length + typeStr.Length + 16); + sb.Append(operand); + + int spacesNeeded = 7 - operand.Length; + do { // always output at least one space + sb.Append(' '); + } while (--spacesNeeded > 0); + + sb.Append("{"); + sb.Append(typeStr); + if (defSym.HasWidth) { + sb.Append('/'); + sb.Append(defSym.DataDescriptor.Length); } + sb.Append("}"); + return sb.ToString(); } /// @@ -552,7 +559,7 @@ namespace SourceGen { None = 0, IsPcRel = 1, // opcode is PC relative, e.g. branch or PER HasHashPrefix = 1 << 1, // operand has a leading '#', reducing ambiguity - StripLabelPrefixSuffix = 1 << 2, // don't show annotation char or non-unique prefix + OmitLabelPrefixSuffix = 1 << 2, // don't show annotation char or non-unique prefix } /// @@ -711,7 +718,7 @@ namespace SourceGen { // Now put the prefix/suffix back on if desired. We don't want to mess with it // if it's from the assembler. - if ((flags & FormatNumericOpFlags.StripLabelPrefixSuffix) == 0) { + if ((flags & FormatNumericOpFlags.OmitLabelPrefixSuffix) == 0) { symLabel = Symbol.ConvertLabelForDisplay(symLabel, sym.LabelAnno, sym.IsNonUnique, formatter); } else { @@ -854,7 +861,7 @@ namespace SourceGen { if (labelMap != null && labelMap.TryGetValue(symLabel, out string newLabel)) { symLabel = newLabel; } - if ((flags & FormatNumericOpFlags.StripLabelPrefixSuffix) == 0) { + if ((flags & FormatNumericOpFlags.OmitLabelPrefixSuffix) == 0) { symLabel = Symbol.ConvertLabelForDisplay(symLabel, sym.LabelAnno, sym.IsNonUnique, formatter); } else { @@ -955,7 +962,7 @@ namespace SourceGen { if (labelMap != null && labelMap.TryGetValue(symLabel, out string newLabel)) { symLabel = newLabel; } - if ((flags & FormatNumericOpFlags.StripLabelPrefixSuffix) == 0) { + if ((flags & FormatNumericOpFlags.OmitLabelPrefixSuffix) == 0) { symLabel = Symbol.ConvertLabelForDisplay(symLabel, sym.LabelAnno, sym.IsNonUnique, formatter); } else { @@ -1005,11 +1012,14 @@ namespace SourceGen { // testing the value for DP range, this would behave correctly. Unfortunately // there is no "force DP" modifier, so we either need to add an explicit mask // or just punt and use the original adjustment. + // + // Note DP is only relevant for bank zero. + // // TODO(someday): we only need to do this for ambiguous DP. If the instruction // is imm or doesn't have an abs equivalent, or it's a fixed-width data item // like .DD1, we can still use the nicer-looking adjustment. We don't currently // pass the OpDef in here. - if ((sym.Value & 0xff0000) != ((sym.Value + adjustment) & 0xff0000)) { + if ((sym.Value & 0xff0000) == 0 && ((sym.Value + adjustment) & 0xff0000) != 0) { adjustment = origAdjust; } } else if (keepLen == 2) {