コード例 #1
0
        /// <summary>
        /// Saves the disassebly output to the specified writer.
        /// </summary>
        /// <param name="writer">Writer to save the disassembly output</param>
        /// <param name="output">Disassembly output</param>
        /// <param name="annotations">Optional annotations</param>
        public void SaveDisassembly(TextWriter writer, DisassemblyOutput output,
                                    DisassemblyAnnotation annotations = null)
        {
            foreach (var item in output.OutputItems)
            {
                // --- Optional prefix comment
                if (annotations != null && annotations.PrefixComments.ContainsKey(item.Address))
                {
                    writer.WriteLine($"; {annotations.PrefixComments[item.Address]}");
                }

                // --- Create label
                var label = "    ";
                if (annotations != null && annotations.Labels.ContainsKey(item.Address))
                {
                    label = $"{annotations.Labels[item.Address]}: ";
                }
                else if (item.HasLabel)
                {
                    label = $"L{item.Address}: ";
                }

                // --- Create comment
                var comment = string.Empty;
                if (annotations != null && annotations.Comments.ContainsKey(item.Address))
                {
                    comment = $" ; {annotations.Comments[item.Address]}";
                }

                writer.WriteLine($"{label}{item.Instruction} {comment}");
            }
        }
コード例 #2
0
        /// <summary>
        /// Disassembles the memory from the specified start address with the given endAddress
        /// </summary>
        /// <param name="startAddress">The start address of the disassembly</param>
        /// <param name="endAddress">The end address of the disassembly</param>
        /// <returns>
        /// The disassembly output
        /// </returns>
        public DisassemblyOutput Disassemble(ushort startAddress = 0x0000, ushort endAddress = 0xFFFF)
        {
            _output = new DisassemblyOutput();
            if (endAddress >= MemoryContents.Length)
            {
                endAddress = (ushort)(MemoryContents.Length - 1);
            }
            var refSection = new MemorySection(startAddress, endAddress);

            // --- Let's go through the memory sections
            foreach (var section in MemorySections)
            {
                if (!section.Overlaps(refSection))
                {
                    continue;
                }
                var toDisassemble = section.Intersect(refSection);

                switch (section.SectionType)
                {
                case MemorySectionType.Disassemble:
                    DisassembleSection(toDisassemble);
                    break;

                case MemorySectionType.ByteArray:
                    GenerateByteArray(toDisassemble);
                    break;

                case MemorySectionType.WordArray:
                    GenerateWordArray(toDisassemble);
                    break;

                case MemorySectionType.Skip:
                    GenerateSkipOutput(toDisassemble);
                    break;

                case MemorySectionType.Rst28Calculator:
                    GenerateRst28ByteCodeOutput(toDisassemble);
                    break;

                case MemorySectionType.GraphArray:
                    GenerateDefgArray(toDisassemble, 1);
                    break;

                case MemorySectionType.GraphArray2:
                    GenerateDefgArray(toDisassemble, 2);
                    break;

                case MemorySectionType.GraphArray3:
                    GenerateDefgArray(toDisassemble, 3);
                    break;

                case MemorySectionType.GraphArray4:
                    GenerateDefgArray(toDisassemble, 4);
                    break;
                }
            }
            return(_output);
        }