Skip to content

Commit 2b7a751

Browse files
committed
Adds disassembler, steping through assembly
1 parent a3749cf commit 2b7a751

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+7442
-300
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<Query Kind="Program">
2+
<Namespace>System.Collections.Immutable</Namespace>
3+
<Namespace>System.Globalization</Namespace>
4+
</Query>
5+
6+
// Source of HTML is http://www.6502.org/users/obelisk/6502/reference.html#LDA
7+
8+
void Main()
9+
{
10+
string directory = Path.GetDirectoryName(Util.CurrentQueryPath)!;
11+
string htmlFile = Path.Combine(directory, "instructions.html");
12+
string source = File.ReadAllText(htmlFile);
13+
14+
var reader = new StringReader(source);
15+
var builder = new StringBuilder();
16+
string? line;
17+
while ((line = reader.ReadLine()) is not null)
18+
{
19+
if (line.Trim() != "<P>")
20+
{
21+
builder.AppendLine(line);
22+
}
23+
}
24+
var xelement = XElement.Parse(source.Replace("<BR>", "").Replace("&nbsp;", "").Replace("<P>", "").Replace("</P>","")
25+
.Replace("<P align=\"center\">", "")
26+
.ToString());
27+
var items = new List<Item>();
28+
Item? item;
29+
var elements = xelement.Elements().ToImmutableArray();
30+
int i = 0;
31+
while (i < elements.Length)
32+
{
33+
var node = elements[i];
34+
if (node.Name == "H3")
35+
{
36+
item = new Item((string)node.Elements("A").Attributes("NAME").Single());
37+
items.Add(item);
38+
i += 2;
39+
var addressingTable = elements[i];
40+
var rows = addressingTable.Elements("TR").Skip(1).ToImmutableArray();
41+
foreach (var row in rows)
42+
{
43+
var modes = row;
44+
var tds = modes.Elements("TD")!.ToImmutableArray();
45+
string mode = (string)tds[0].Element("A")!.Value;
46+
string opCode = tds[1].Element("CENTER")!.Value;
47+
string cycles = tds[3].Value;
48+
item.Modes.Add(
49+
new Mode(
50+
mode,
51+
byte.Parse(opCode[1..], NumberStyles.HexNumber, CultureInfo.InvariantCulture),
52+
byte.Parse(cycles[..1]),
53+
cycles
54+
));
55+
}
56+
}
57+
i++;
58+
}
59+
//GenerateSwitch(items);
60+
var root = new XElement("Instructions",
61+
items.Select(i => new XElement("Instruction", new XAttribute("Name", i.Name),
62+
i.Modes.Select(m =>
63+
new XElement("Mode",
64+
new XAttribute("Name", m.Name),
65+
new XAttribute("OpCode", m.OpCode.ToString("X2")),
66+
new XAttribute("Cycles", m.Cycles),
67+
new XAttribute("CyclesInfo", m.CyclesInfo)
68+
))))
69+
);
70+
root.Dump();
71+
}
72+
73+
public record Item(string Name)
74+
{
75+
public List<Mode> Modes { get; } = new ();
76+
}
77+
public record Mode(string Name, byte OpCode, byte Cycles, string CyclesInfo);

0 commit comments

Comments
 (0)