Skip to content

Commit

Permalink
label assignments in disassembly
Browse files Browse the repository at this point in the history
+ added labels.asm where label assignments are made to labels that aren't referenced in the code
* fixed a hidden bug that kept track of a fake label to address -1
- removed bankcross directive for now, since an asar bug always treats the rom as fastrom when it is enabled
  • Loading branch information
IsoFrieze committed Sep 17, 2019
1 parent 124e744 commit 1859cd6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
4 changes: 2 additions & 2 deletions DiztinGUIsh/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.1.5")]
[assembly: AssemblyFileVersion("1.0.1.5")]
[assembly: AssemblyVersion("1.0.1.6")]
[assembly: AssemblyFileVersion("1.0.1.6")]
45 changes: 39 additions & 6 deletions DiztinGUIsh/static/LogCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public enum FormatStructure
{ "%empty", Tuple.Create<Func<int, int, string>, int>(GetEmpty, 1) },
{ "%incsrc", Tuple.Create<Func<int, int, string>, int>(GetIncSrc, 1) },
{ "%bankcross", Tuple.Create<Func<int, int, string>, int>(GetBankCross, 1) },
{ "%labelassign", Tuple.Create<Func<int, int, string>, int>(GetLabelAssign, 1) },
};

public static string format = "%label:-22% %code:37%;%pc%|%bytes%|%ia%; %comment%";
Expand All @@ -50,6 +51,7 @@ public enum FormatStructure
public static FormatStructure structure = FormatStructure.OneBankPerFile;

private static List<Tuple<string, int>> list;
private static List<int> usedLabels;
private static StreamWriter err;
private static int errorCount, bankSize;
private static string folder;
Expand All @@ -66,6 +68,7 @@ public static int CreateLog(StreamWriter sw, StreamWriter er)
string[] split = format.Split('%');
err = er;
errorCount = 0;
usedLabels = new List<int>();

list = new List<Tuple<string, int>>();
for (int i = 0; i < split.Length; i++)
Expand All @@ -85,13 +88,12 @@ public static int CreateLog(StreamWriter sw, StreamWriter er)
{
folder = Path.GetDirectoryName(((FileStream)sw.BaseStream).Name);
sw.WriteLine(GetLine(pointer, "map"));
sw.WriteLine(GetLine(pointer, "bankcross"));
sw.WriteLine(GetLine(pointer, "empty"));
for (int i = 0; i < size; i += bankSize) sw.WriteLine(GetLine(i, "incsrc"));
sw.WriteLine(GetLine(-1, "incsrc"));
} else
{
sw.WriteLine(GetLine(pointer, "map"));
sw.WriteLine(GetLine(pointer, "bankcross"));
sw.WriteLine(GetLine(pointer, "empty"));
}

Expand Down Expand Up @@ -119,6 +121,23 @@ public static int CreateLog(StreamWriter sw, StreamWriter er)
pointer += GetLineByteLength(pointer);
}

if (structure == FormatStructure.OneBankPerFile)
{
sw.Close();
sw = new StreamWriter(string.Format("{0}/labels.asm", folder));
} else
{
sw.WriteLine(GetLine(pointer, "empty"));
}

foreach (KeyValuePair<int, string> pair in Data.GetAllLabels())
{
if (!usedLabels.Contains(pair.Key))
{
sw.WriteLine(GetLine(pair.Key, "labelassign"));
}
}

if (structure == FormatStructure.OneBankPerFile) sw.Close();
Data.Restore(a: tempAlias);
AliasList.me.locked = false;
Expand All @@ -140,7 +159,7 @@ private static void AddTemporaryLabels()
(flag == Data.FlagType.Opcode || flag == Data.FlagType.Pointer16Bit || flag == Data.FlagType.Pointer24Bit || flag == Data.FlagType.Pointer32Bit))
{
int ia = Util.GetIntermediateAddressOrPointer(pointer);
if (Util.ConvertSNEStoPC(ia) >= 0) addMe.Add(ia);
if (ia >= 0 && Util.ConvertSNEStoPC(ia) >= 0) addMe.Add(ia);
}

pointer += length;
Expand Down Expand Up @@ -286,7 +305,9 @@ private static string GetEmpty(int offset, int length)
// negative length = right justified
private static string GetLabel(int offset, int length)
{
string label = Data.GetLabel(Util.ConvertPCtoSNES(offset));
int snes = Util.ConvertPCtoSNES(offset);
string label = Data.GetLabel(snes);
usedLabels.Add(snes);
bool noColon = label.Length == 0 || label[0] == '-' || label[0] == '+';
return string.Format("{0," + (length * -1) + "}", label + (noColon ? "" : ":"));
}
Expand Down Expand Up @@ -358,10 +379,15 @@ private static string GetMap(int offset, int length)
return string.Format("{0," + (length * -1) + "}", s);
}

// 0+ = bank_xx.asm, -1 = labels.asm
private static string GetIncSrc(int offset, int length)
{
int bank = Util.ConvertPCtoSNES(offset) >> 16;
string s = string.Format("incsrc \"bank_{0}.asm\"", Util.NumberToBaseString(bank, Util.NumberBase.Hexadecimal, 2));
string s = "incsrc \"labels.asm\"";
if (offset >= 0)
{
int bank = Util.ConvertPCtoSNES(offset) >> 16;
s = string.Format("incsrc \"bank_{0}.asm\"", Util.NumberToBaseString(bank, Util.NumberBase.Hexadecimal, 2));
}
return string.Format("{0," + (length * -1) + "}", s);
}

Expand Down Expand Up @@ -437,5 +463,12 @@ private static string GetXFlag(int offset, int length)
if (length == 1) return x ? "X" : "x";
else return x ? "08" : "16";
}

// output label at snes offset, and its value
private static string GetLabelAssign(int offset, int length)
{
string s = string.Format("{0} = {1}", Data.GetLabel(offset), Util.NumberToBaseString(offset, Util.NumberBase.Hexadecimal, 6, true));
return string.Format("{0," + (length * -1) + "}", s);
}
}
}
4 changes: 2 additions & 2 deletions help.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</head>
<body>

<h1>DiztinGUIsh Help - v1.0.1.5</h1>
<h1>DiztinGUIsh Help - v1.0.1.6</h1>

<hr />

Expand Down Expand Up @@ -430,7 +430,7 @@ <h3 id="bankstructure">Bank Structure</h3>
<p>This controls the structure of the output disassembly.</p>
<ul>
<li><strong>All in one file</strong>: The disassembly will be contained within one, potentially large file.</li>
<li><strong>One bank per file</strong>: Each bank will be put in a separate bank_*.asm file. A file called main.asm will be created as well.</li>
<li><strong>One bank per file</strong>: Each bank will be put in a separate bank_*.asm file. A file called main.asm will be created as the root file, and a file called labels.asm will be created to store all label assignments (e.g. RAM addresses).</li>
</ul>

<hr />
Expand Down

0 comments on commit 1859cd6

Please sign in to comment.