From 47c773dcdfae04667eb618922a2af776c312c959 Mon Sep 17 00:00:00 2001
From: Andy McFadden
Date: Sat, 2 May 2020 14:09:53 -0700
Subject: [PATCH] Show "idx" for indexed accesses in References window
Sometimes it's useful to know whether an address referenced by a
function is a direct access, or is being used as a base address.
(I'm somewhat undecided on this one, since it clutters up the list
a bit. Giving it a try.)
---
Asm65/OpDef.cs | 16 ++++++++++++++++
SourceGen/DisasmProject.cs | 22 ++++++++++++----------
SourceGen/MainController.cs | 6 +++++-
SourceGen/RuntimeData/Help/mainwin.html | 3 +++
SourceGen/XrefSet.cs | 12 ++++++++++--
5 files changed, 46 insertions(+), 13 deletions(-)
diff --git a/Asm65/OpDef.cs b/Asm65/OpDef.cs
index 0c271f5..2afc422 100644
--- a/Asm65/OpDef.cs
+++ b/Asm65/OpDef.cs
@@ -236,6 +236,22 @@ namespace Asm65 {
}
}
+ ///
+ /// True for instructions that index off of the operand. The goal is to identify
+ /// instructions like "LDA $1234,Y" that may not access the address specified by
+ /// their operand. So "(dp,X)" returns true, but "(dp),Y" does not.
+ ///
+ public bool IsIndexedAccessInstruction {
+ get {
+ return AddrMode == AddressMode.AbsIndexX ||
+ AddrMode == AddressMode.AbsIndexXInd ||
+ AddrMode == AddressMode.AbsIndexY ||
+ AddrMode == AddressMode.DPIndexX ||
+ AddrMode == AddressMode.DPIndexXInd ||
+ AddrMode == AddressMode.DPIndexY;
+ }
+ }
+
///
/// True if the operand's width is uniquely determined by the opcode mnemonic, even
/// if the operation supports operands with varying widths.
diff --git a/SourceGen/DisasmProject.cs b/SourceGen/DisasmProject.cs
index 26c2d80..a2b9d06 100644
--- a/SourceGen/DisasmProject.cs
+++ b/SourceGen/DisasmProject.cs
@@ -1484,6 +1484,7 @@ namespace SourceGen {
XrefSet.XrefType xrefType = XrefSet.XrefType.Unknown;
OpDef.MemoryEffect accType = OpDef.MemoryEffect.Unknown;
+ bool isIndexedDirect = false;
if (attr.IsInstruction) {
OpDef op = CpuDef.GetOpDef(FileData[offset]);
if (op.IsSubroutineCall) {
@@ -1493,6 +1494,7 @@ namespace SourceGen {
} else {
xrefType = XrefSet.XrefType.MemAccessOp;
accType = op.MemEffect;
+ isIndexedDirect = op.IsIndexedAccessInstruction;
}
} else if (attr.IsData || attr.IsInlineData) {
xrefType = XrefSet.XrefType.RefFromData;
@@ -1520,8 +1522,8 @@ namespace SourceGen {
mAnattribs[operandOffset].Address;
}
- AddXref(symOffset,
- new XrefSet.Xref(offset, true, xrefType, accType, adj));
+ AddXref(symOffset, new XrefSet.Xref(offset, true, xrefType, accType,
+ isIndexedDirect, adj));
if (adj == 0) {
hasZeroOffsetSym = true;
}
@@ -1532,8 +1534,8 @@ namespace SourceGen {
if (operandOffset >= 0) {
adj = defSym.Value - operandOffset;
}
- defSym.Xrefs.Add(
- new XrefSet.Xref(offset, true, xrefType, accType, adj));
+ defSym.Xrefs.Add(new XrefSet.Xref(offset, true, xrefType, accType,
+ isIndexedDirect, adj));
}
} else if (SymbolTable.TryGetValue(dfd.SymbolRef.Label, out Symbol sym)) {
// Is this a reference to a project/platform symbol?
@@ -1559,8 +1561,8 @@ namespace SourceGen {
// e.g. "LDA #>BLAH" would grab the high part. We'd need
// to tweak the adjustment math appropriately.
}
- defSym.Xrefs.Add(
- new XrefSet.Xref(offset, true, xrefType, accType, adj));
+ defSym.Xrefs.Add(new XrefSet.Xref(offset, true, xrefType, accType,
+ isIndexedDirect, adj));
} else {
// Can get here if somebody creates an address operand symbol
// that refers to a local variable.
@@ -1599,8 +1601,8 @@ namespace SourceGen {
} else {
Debug.WriteLine("HEY: found unlabeled addr ref at +" +
offset.ToString("x6"));
- AddXref(targetOffset,
- new XrefSet.Xref(offset, false, xrefType, accType, 0));
+ AddXref(targetOffset, new XrefSet.Xref(offset, false, xrefType,
+ accType, isIndexedDirect, 0));
}
}
@@ -1609,8 +1611,8 @@ namespace SourceGen {
// just leave a duplicate entry. (The symbolic ref wins because we need
// it for the label localizer and possibly the label refactorer.)
if (!hasZeroOffsetSym && attr.IsInstructionStart && attr.OperandOffset >= 0) {
- AddXref(attr.OperandOffset,
- new XrefSet.Xref(offset, false, xrefType, accType, 0));
+ AddXref(attr.OperandOffset, new XrefSet.Xref(offset, false, xrefType,
+ accType, isIndexedDirect, 0));
}
}
diff --git a/SourceGen/MainController.cs b/SourceGen/MainController.cs
index 7d9c5be..c9ef7cb 100644
--- a/SourceGen/MainController.cs
+++ b/SourceGen/MainController.cs
@@ -3513,6 +3513,7 @@ namespace SourceGen {
for (int i = 0; i < xrefs.Count; i++) {
XrefSet.Xref xr = xrefs[i];
+ string idxStr = string.Empty;
string typeStr;
switch (xr.Type) {
case XrefSet.XrefType.SubCallOp:
@@ -3544,6 +3545,9 @@ namespace SourceGen {
typeStr = "??! ";
break;
}
+ if (xr.IsIndexedAccess) {
+ idxStr = "idx ";
+ }
break;
default:
Debug.Assert(false);
@@ -3554,7 +3558,7 @@ namespace SourceGen {
MainWindow.ReferencesListItem rli = new MainWindow.ReferencesListItem(xr.Offset,
formatter.FormatOffset24(xr.Offset),
formatter.FormatAddress(mProject.GetAnattrib(xr.Offset).Address, showBank),
- (xr.IsByName ? "Sym " : "Oth ") + typeStr +
+ (xr.IsByName ? "Sym " : "Oth ") + typeStr + idxStr +
formatter.FormatAdjustment(-xr.Adjustment));
mMainWin.ReferencesList.Add(rli);
diff --git a/SourceGen/RuntimeData/Help/mainwin.html b/SourceGen/RuntimeData/Help/mainwin.html
index f097a5a..4f53bbf 100644
--- a/SourceGen/RuntimeData/Help/mainwin.html
+++ b/SourceGen/RuntimeData/Help/mainwin.html
@@ -256,6 +256,9 @@ data operand, and provides an indication of the nature of the reference:
data - reference to address by data
(e.g. .DD2 addr
)
+References from instructions that use indexed addressing
+(e.g. LDA addr,Y
) will also show "idx" to indicate that
+the instruction is using the location as a base address.
This will be prefixed with "Sym" or "Oth" to indicate whether or not
the reference used the label at the current address. To understand
this, consider that addresses can be referenced in different ways.
diff --git a/SourceGen/XrefSet.cs b/SourceGen/XrefSet.cs
index 5bcf84b..8f163d2 100644
--- a/SourceGen/XrefSet.cs
+++ b/SourceGen/XrefSet.cs
@@ -69,6 +69,12 @@ namespace SourceGen {
///
public Asm65.OpDef.MemoryEffect AccType { get; private set; }
+ ///
+ /// For Type==MemAccessOp, true if the instruction applies an index offset, to
+ /// the operand, meaning the referenced address might not actually be accessed.
+ ///
+ public bool IsIndexedAccess { get; private set; }
+
///
/// Adjustment to symbol. For example, "LDA label+2" adds an xref entry to
/// "label", with an adjustment of +2.
@@ -76,17 +82,19 @@ namespace SourceGen {
public int Adjustment { get; private set; }
public Xref(int offset, bool isByName, XrefType type,
- Asm65.OpDef.MemoryEffect accType, int adjustment) {
+ Asm65.OpDef.MemoryEffect accType, bool isIndexedAccess, int adjustment) {
Offset = offset;
IsByName = isByName;
Type = type;
AccType = accType;
+ IsIndexedAccess = isIndexedAccess;
Adjustment = adjustment;
}
public override string ToString() {
return "Xref off=+" + Offset.ToString("x6") + " sym=" + IsByName +
- " type=" + Type + " accType= " + AccType + " adj=" + Adjustment;
+ " type=" + Type + " accType= " + AccType + " idx=" + IsIndexedAccess +
+ " adj=" + Adjustment;
}
}