Skip to content

Commit

Permalink
asm instruction generation: allow (early) math expressions for Direct…
Browse files Browse the repository at this point in the history
… page

allows Diz to be smart enough to figure out things like, if the D register for a byte is set to $100 and there's a line like this:
LDA.B $01
and we have a label 'some_variable' set at $101, then it's safe to output this assembly:
LDA.B some_variable-$100

this should help get way more vars in the final output
  • Loading branch information
binary1230 committed Dec 18, 2023
1 parent cf1e6d0 commit 35fe0cb
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Diz.Cpu.65816/src/CPU65C816.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ private static int GetInstructionLength(Cpu65C816Constants.AddressMode mode)
}
}

private const bool AttemptTouseDirectPageArithmeticInFinalOutput = true;

private string FormatOperandAddress(TByteSource data, int offset, Cpu65C816Constants.AddressMode mode)
{
var address = data.GetIntermediateAddress(offset);
Expand All @@ -365,7 +367,28 @@ private string FormatOperandAddress(TByteSource data, int offset, Cpu65C816Const
{
var label = labelProvider.Labels.GetLabelName(address);
if (label != "")
return label;
return label;

// OPTIONAL:
// super-specific variable substitution. this needs to be heavily generalized.
// this MAY NOT COVER EVERY EDGE CASE. feel free to modify or disable it.
// this is to try and get more labels in the output by creating a mathematical expression
// for ASAR to use. only works if you have accurate 'D' register (direct page) set.
// usually only useful after you've done a lot of tracelog capture.
if (AttemptTouseDirectPageArithmeticInFinalOutput && mode is Cpu65C816Constants.AddressMode.DirectPage)
{
var dp = data.GetDirectPage(offset);
if (dp != 0)
{
label = labelProvider.Labels.GetLabelName(dp + address);
if (label != "")
{
// direct page addressing. we can use an expression to use a variable name for this
// TODO: we can also use asar directive .dbase to set the assumed DB register.
return $"{label}-${dp:X}"; // IMPORTANT: no spaces on that minus sign.
}
}
}
}

var count = BytesToShow(mode);
Expand Down

0 comments on commit 35fe0cb

Please sign in to comment.