public List <string> GetCode(out int byteLength, ref int startAddress, int endAddress = -1) { _code.InitAssemblerValues(); List <string> result = new List <string>(); byteLength = 0; if (endAddress == -1) { //When no end address is specified, find the start of the function based on startAddress int address = InteropEmu.DebugFindSubEntryPoint((UInt16)startAddress); if (address != -1) { startAddress = address; } } for (int i = startAddress; (i <= endAddress || endAddress == -1) && endAddress < 65536;) { string code; if (_code.CodeContent.TryGetValue(i, out code)) { code = code.Split('\x2')[0].Trim(); if (code.StartsWith("--") || code.StartsWith("__")) { //Stop adding code when we find a new section (new function, data blocks, etc.) break; } AddressTypeInfo info = new AddressTypeInfo(); InteropEmu.DebugGetAbsoluteAddressAndType((UInt32)i, info); CodeLabel codeLabel = info.Address >= 0 ? LabelManager.GetLabel((UInt32)info.Address, AddressType.PrgRom) : null; string comment = codeLabel?.Comment; string label = codeLabel?.Label; bool addPadding = true; if (code.StartsWith("STP*") || code.StartsWith("NOP*")) { //Transform unofficial opcodes that can't be reassembled properly into .byte statements if (comment != null) { comment.Insert(0, code + " - "); } else { comment = code; } code = ".byte " + string.Join(",", _code.CodeByteCode[i].Split(' ')); addPadding = false; } if (!string.IsNullOrWhiteSpace(comment) && comment.Contains("\n")) { result.AddRange(comment.Replace("\r", "").Split('\n').Select(cmt => ";" + cmt)); comment = null; } if (!string.IsNullOrWhiteSpace(label)) { result.Add(label + ":"); } result.Add((addPadding ? " " : "") + code + (!string.IsNullOrWhiteSpace(comment) ? (" ;" + comment) : "")); int length = _code.CodeByteCode[i].Count(c => c == ' ') + 1; byteLength += length; i += length; if (endAddress == -1 && (string.Compare(code, "RTI", true) == 0 || string.Compare(code, "RTS", true) == 0)) { break; } } else { break; } } result.Add(""); return(result); }