示例#1
0
        /// <summary>
        /// Loads the given program into the disassembler.
        /// </summary>
        /// <param name="program">The program to load.</param>
        public void LoadProgram(OxIDE.DCPU.Program program)
        {
            // Disassemble the program.
            this.Disassemble = Disassembler.Create(program);

            // Populate the content box.
            this.ContentBox.Clear();
            this.ContentBox.BeginUpdate();

            foreach (var instruction in this.Disassemble.Instructions)
            {
                this.ContentBox.InsertText(String.Format("{0:x4}: ", instruction.Location), m_locationStyle);

                if (instruction.BasicOpcode == BasicOpcodes.NonBasic)
                {
                    this.ContentBox.InsertText(String.Format("{0,-3} ", instruction.ExtendedOpcode), m_opcodeStyle);
                    this.ContentBox.InsertText(instruction.Left.ToString(), m_valueStyle);
                }
                else
                {
                    this.ContentBox.InsertText(String.Format("{0,-3} ", instruction.BasicOpcode), m_opcodeStyle);
                    this.ContentBox.InsertText(instruction.Left.ToString() + ", " + instruction.Right.ToString(), m_valueStyle);
                }

                var length  = instruction.ToString().Length;
                var comment = "; " + String.Join(" ", instruction.OriginalCode.Select(e => String.Format("{0:x4}", e)));

                this.ContentBox.InsertText(" ".Repeat(40 - length) + comment, m_commentStyle);
                this.ContentBox.InsertText(Environment.NewLine);
            }

            this.ContentBox.EndUpdate();
        }