コード例 #1
0
ファイル: Opcodes.cs プロジェクト: dxc31202/ZXStudio
        public override string ToString()
        {
            string sbytes = "";
            string chars  = "";

            // Build bytes string - 25 bytes long
            for (int i = 0; i < Bytes.Count; i++)
            {
                if (Bytes[i] < 32 || Bytes[i] > 127)
                {
                    chars += ".";
                }
                else
                {
                    chars += Convert.ToChar(Bytes[i]);
                }
                sbytes += Bytes[i].ToString("X2") + " ";
            }
            sbytes += new string(' ', 25);
            sbytes  = sbytes.Substring(0, 25);

            // Build mnemonics string - 32 bytes long
            string properties = "";
            string mnemonic   = "";

            if (Mnemonic == null)
            {
                // Belts and braces; shouldn't really get here.
                mnemonic = "DEFB #" + sbytes.Trim().Replace(" ", " #");
            }
            else
            {
                mnemonic   = Mnemonic;
                properties = OpcodePropertys.ToString();
                // Perform value subsistution
                // Address
                if (Mnemonic.Contains("$aa"))
                {
                    mnemonic = mnemonic.Replace("$aa", "L" + Operand.ToString("X4"));
                }
                // Word
                else if (Mnemonic.Contains("$nn"))
                {
                    mnemonic = mnemonic.Replace("$nn", "#" + Operand.ToString("X4"));
                }
                // Displacement
                else if (Mnemonic.Contains("$d"))
                {
                    mnemonic = mnemonic.Replace("$d", "L" + Operand.ToString("X4"));
                }
                // Byte
                else if (Mnemonic.Contains("$b"))
                {
                    mnemonic = mnemonic.Replace("$b", "#" + Operand.ToString("X2"));
                }
                // Index offset 1
                if (Mnemonic.Contains("$o"))
                {
                    mnemonic = mnemonic.Replace("$o", ((sbyte)Offset).ToString("+0;-#"));
                }
                // Index offset 2
                if (Mnemonic.Contains("$x"))
                {
                    mnemonic = mnemonic.Replace("$x", ((sbyte)Offset).ToString("+0;-#"));
                }
            }
            mnemonic += new string(' ', 32);
            mnemonic  = mnemonic.Substring(0, 32);

            // Build the output string
            if (ProduceCodes)
            {
                return(Address.ToString("X4") + " " + sbytes + Label + mnemonic + "; " + chars + " ");
            }
            return(Label + mnemonic + "; " + chars + " ");
        }