public string Disassemble(int startAddress = 0, int endAddress = 0, IDictionary<int, string> knownLabels = null, DisassemblyOptions options = null) { var results = string.Empty; options = options ?? new DisassemblyOptions(); var labels = knownLabels ?? new Dictionary<int, string>(); if (endAddress == 0) { endAddress = _cpu.RAM.Length; } var currentAddress = startAddress; while (currentAddress < endAddress) { if (labels.ContainsKey(currentAddress)) { results += ":" + labels[currentAddress] + Environment.NewLine; } results += Disassemble(ref currentAddress, labels, options); } return results; }
public string Disassemble(ref int address, IDictionary<int, string> knownLabels = null, DisassemblyOptions options = null) { var labels = knownLabels ?? new Dictionary<int, string>(); options = options ?? new DisassemblyOptions(); var results = options.IncludeInitialAddress ? string.Format("\t{0:X4}: ", address) : "\t"; var instruction = _cpu.RAM[address]; var opcode = Language.List.FirstOrDefault(o => o.Code == instruction); if (opcode == null) { results += string.Format("!0x{0:X4}", instruction); address += 1; } else { results += string.Format("{0, -6}", opcode.Mnemonic); var idx = 1; foreach (var parm in opcode.Parameters) { if (parm.ParameterType == ParameterType.Address) { var addr = _cpu.RAM[address + idx]; if (labels.ContainsKey(addr)) { results += string.Format(" :{0}", labels[addr]); } else { results += string.Format(" {0:X4}", addr); } } else { results += string.Format(" {0:X4}", _cpu.RAM[address + idx]); } idx++; } // for (int i = 1; i < opcode.Length; i++) { // results += string.Format(" {0:X4}", _cpu.RAM[address + i]); // } results = string.Format("{0,-50};{1}", results, opcode.Description); address += opcode.Length; } return results + Environment.NewLine; }