summaryrefslogtreecommitdiff
path: root/Q1.core/Pipeline/Disassembler.cs
blob: ae93e12a9e0ea703c3ac019054c5eed7e44d690b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
namespace Q1.core.Pipeline;

using Arch;
using Arch.Lookups;

public class Disassembler
{
    public StringWriter Disassemble(MemoryStream stream)
    {
            var reader = new BinaryReader(stream);
            var writer = new StringWriter();
            
            while (reader.BaseStream.Position < reader.BaseStream.Length)
            {
                u16 instruction = reader.ReadUInt16();
                InstructionEncoding.Decode(instruction, out u8 opcode, out u8 m1, out u8 m2, out bool word);
                
                var group = InstructionSet.Lookup[opcode];
                (string name, int param) = (m1, m2) switch
                {
                    (0x00, 0x00) => (group.Implicit.Name, 0),
                    (_, 0x00) => (group.SimpleAddressing.Name, 1),
                    (0x00, 0x01) => (group.ExtendedImplicit.Name, 0),
                    (_, _) => (group.ExtendedAddressing.Name, 2)
                };
                
                writer.Write(name);
                if (param == 1)
                {
                    
                }
            }
    
            return writer;
    }
}