1
0
mirror of https://github.com/fadden/6502bench.git synced 2025-11-23 12:21:02 +00:00

Disregard operand address, part 1

SourceGen puts a lot of effort into connecting address operands to
internal offsets and external symbols.  Sometimes this is undesirable.
For example, a BIT or conditional branch instruction is sometimes used
as a dummy when there are multiple entry points that vary only in a
status flag or register value.  The address in the BIT or branch is
either irrelevant or never actually referenced, so auto-generating a
label for it is annoying.

Having a way to tell the disassembler to disregard an address operand,
so that it won't generate an auto-label or be included in the list of
cross-references, provides a simple solution to this.

The operand's file offset is determined during the code analysis
pass.  Setting it to -1 makes the operand look like an external address.
If we disable the project/platform symbol lookup for that instruction
as well, we can avoid label generation and cross-references.

We also need to prevent the 65816 data bank fixup code from restoring
it, and the relocation data code from doing its thing.

The flag is implemented as a new "misc flags" table, which holds a
set of bit flags for every file offset.  The "disregard operand address"
flag is set on the opcode byte of instructions.  The flags are expected
to be used infrequently, so they're currently output as a list of
(offset, integer) pairs.

The flag is set in the Edit Instruction Operand dialog, which has a
new checkbox.  The checkbox is disabled for immediate operands.

(issue #174)
This commit is contained in:
Andy McFadden
2025-07-30 09:16:32 -07:00
parent c70d015b00
commit ec50f48f95
12 changed files with 190 additions and 24 deletions

View File

@@ -159,6 +159,11 @@ namespace SourceGen {
/// </summary>
private StatusFlags[] mStatusFlagOverrides;
/// <summary>
/// Miscellaneous flags, one entry per byte.
/// </summary>
private DisasmProject.MiscFlag[] mMiscFlags;
/// <summary>
/// Initial status flags to use at entry points.
/// </summary>
@@ -178,6 +183,10 @@ namespace SourceGen {
/// <summary>
/// Constructor.
/// </summary>
/// <remarks>
/// This takes individual arrays as arguments, rather than the project file, to
/// ensure that we're restricting our analysis to a specific set of data tables.
/// </remarks>
/// <param name="data">65xx code stream.</param>
/// <param name="cpuDef">CPU definition to use when interpreting code.</param>
/// <param name="anattribs">Anattrib array. Expected to be newly allocated, all
@@ -186,20 +195,23 @@ namespace SourceGen {
/// <param name="atags">Analyzer tags, one per byte.</param>
/// <param name="statusFlagOverrides">Status flag overrides for instruction-start
/// bytes.</param>
/// <param name="miscFlags">Miscellaneous flags, one per byte.</param>
/// <param name="entryFlags">Status flags to use at code entry points.</param>
/// <param name="scriptMan">Extension script manager.</param>
/// <param name="parms">Analysis parameters.</param>
/// <param name="debugLog">Object that receives debug log messages.</param>
public CodeAnalysis(byte[] data, CpuDef cpuDef, Anattrib[] anattribs,
AddressMap addrMap, AnalyzerTag[] atags, StatusFlags[] statusFlagOverrides,
StatusFlags entryFlags, ProjectProperties.AnalysisParameters parms,
ScriptManager scriptMan, DebugLog debugLog) {
DisasmProject.MiscFlag[] miscFlags, StatusFlags entryFlags,
ProjectProperties.AnalysisParameters parms,ScriptManager scriptMan,
DebugLog debugLog) {
mFileData = data;
mCpuDef = cpuDef;
mAnattribs = anattribs;
mAddrMap = addrMap;
mAnalyzerTags = atags;
mStatusFlagOverrides = statusFlagOverrides;
mMiscFlags = miscFlags;
mEntryFlags = entryFlags;
mScriptManager = scriptMan;
mAnalysisParameters = parms;
@@ -1015,7 +1027,15 @@ namespace SourceGen {
int operandOffset = mAddrMap.AddressToOffset(offset,
mAnattribs[offset].OperandAddress);
if (operandOffset >= 0) {
mAnattribs[offset].OperandOffset = operandOffset;
bool disregard =
(mMiscFlags[offset] & DisasmProject.MiscFlag.DisregardOperandAddress) != 0;
if (!disregard) {
mAnattribs[offset].OperandOffset = operandOffset;
} else {
//Debug.WriteLine("Disregarding operand address at +" +
// offset.ToString("x6"));
mAnattribs[offset].OperandOffset = -1;
}
// Set a flag if this is a direct offset. This is used when tracing
// through jump instructions, as we can't necessarily decode an indirect
@@ -1399,7 +1419,8 @@ namespace SourceGen {
/// </summary>
/// <remarks>
/// This is of questionable value when we have reliable relocation data. OTOH it's
/// pretty quick even on very large files.
/// pretty quick even on very large files. This is executed as a follow-up pass after
/// code analysis completes.
/// </remarks>
public void ApplyDataBankRegister(Dictionary<int, DbrValue> userValues,
Dictionary<int, DbrValue> dbrChanges) {
@@ -1429,6 +1450,9 @@ namespace SourceGen {
if (mAnattribs[offset].IsNonAddressable) {
continue;
}
if ((mMiscFlags[offset] & DisasmProject.MiscFlag.DisregardOperandAddress) != 0) {
continue;
}
if (curVal == DbrValue.UNKNOWN) {
// On first encounter with addressable memory, init curVal so B=K.
curVal = (byte)(mAddrMap.OffsetToAddress(offset) >> 16);