Esempio n. 1
0
        private static void _Write(ulong v, int Base, IDebugOutput s, bool uppercase, int min_digits)
        {
            if (digits == null)
            {
                s.Write("<error>");
                return;
            }

            int cur_digit = 0;

            while (v != 0)
            {
                digits[cur_digit] = (byte)(v % (ulong)Base);
                v /= (ulong)Base;
                cur_digit++;
            }

            while (cur_digit < min_digits)
            {
                digits[cur_digit] = 0;
                cur_digit++;
            }

            for (int i = (cur_digit - 1); i >= 0; i--)
            {
                if (uppercase)
                {
                    s.Write(UppercaseDigits[digits[i]]);
                }
                else
                {
                    s.Write(LowercaseDigits[digits[i]]);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Prints a visual representation of the memory in the given buffer on the current debug output
        /// </summary>
        /// <param name="buffer">Data to be represented</param>
        /// <param name="maxNumberOfBytes">The maximum value that a represented buffer can have. Default (-1) is equal to the size of the buffer</param>
        /// <param name="noiseTolerance">The value at which the algorithm decides to put black character instead of ocupied character.</param>
        /// <param name="displayLenght">Numbers of characters that the visual representation should be. Default 20 characters</param>
        /// <param name="trailWhitespaces">Paramater that indicates if the visual representation should be followed up with 5 trailing whitespaces. Default true.</param>
        /// <param name="blank">The string used for blank/empty/thresholded memory</param>
        /// <param name="full">The string used for ocupied/non-empty/thresholded memory</param>
        public void PrintMemory(byte[] buffer, int maxNumberOfBytes = -1, byte noiseTolerance = 0, int displayLenght = 20, bool trailWhitespaces = true, string blank = "-", string full = "|")
        {
            if (maxNumberOfBytes == -1)
            {
                maxNumberOfBytes = buffer.Length;
            }

            double factor = (double)displayLenght / (double)maxNumberOfBytes;

            for (int i = 0; i < displayLenght; i++)
            {
                int projecttion = 0;
                if (i != 0)
                {
                    projecttion = (int)(i / factor);
                }

                bool hasMem = false;

                for (int o = 0; o < maxNumberOfBytes / displayLenght; o++)
                {
                    if (buffer[o + projecttion] >= noiseTolerance)
                    {
                        hasMem = true;
                        break;
                    }
                }

                if (!hasMem)
                {
                    _output.Write(blank);
                }
                else
                {
                    _output.Write(full);
                }
            }

            if (trailWhitespaces)
            {
                for (int i = 0; i < 5; i++)
                {
                    System.Diagnostics.Debug.Write(" ");
                }
            }
        }
Esempio n. 3
0
 public static void WriteLine(IDebugOutput s)
 {
     if (s != null)
     {
         s.Write('\n');
         s.Flush();
     }
 }
Esempio n. 4
0
 public static void Write(char ch, IDebugOutput s)
 {
     if (s != null)
     {
         s.Write(ch);
         s.Flush();
     }
 }
Esempio n. 5
0
 public static void WriteLine(string str, IDebugOutput s)
 {
     if (s != null)
     {
         Write(str, s);
         s.Write('\n');
         s.Flush();
     }
 }
Esempio n. 6
0
 public static void Write(string str, IDebugOutput s)
 {
     if (s != null)
     {
         for (int i = 0; i < str.Length; i++)
         {
             var c = str[i];
             s.Write(c);
         }
         s.Flush();
     }
 }
Esempio n. 7
0
        public static void Write(string fmt, IDebugOutput s, params object[] p)
        {
            if (s == null)
            {
                return;
            }

            // define the current state of the iteration
            bool in_escape       = false;
            bool in_index        = false;
            bool in_alignment    = false;
            bool in_format       = false;
            int  index_start     = 0;
            int  alignment_start = 0;
            int  format_start    = 0;
            int  index_end       = 0;
            int  alignment_end   = 0;
            int  format_end      = 0;
            bool has_alignment   = false;
            bool has_format      = false;

            for (int i = 0; i < fmt.Length; i++)
            {
                if (in_escape)
                {
                    if (fmt[i] == '\\')
                    {
                        s.Write('\\');
                    }
                    else if (fmt[i] == 'n')
                    {
                        s.Write('\n');
                    }

                    in_escape = false;
                }
                else if ((in_format || in_alignment || in_index) && (fmt[i] == '}'))
                {
                    if ((i < (fmt.Length - 1)) && (fmt[i + i] == '}'))
                    {
                        s.Write('}');
                        i++;
                    }
                    else
                    {
                        if (in_format)
                        {
                            format_end = i;
                        }
                        if (in_alignment)
                        {
                            alignment_end = i;
                        }
                        if (in_index)
                        {
                            index_end = i;
                        }
                        in_format = in_alignment = in_index = false;

                        // interpret the format, alignment and index and output the appropriate value

                        // index is a integer in decimal format
                        int mult  = 1;
                        int index = 0;
                        for (int j = index_end - 1; j >= index_start; j++)
                        {
                            int diff = (int)fmt[j] - (int)'0';
                            if ((diff >= 0) && (diff <= 9))
                            {
                                index += (diff * mult);
                            }
                            if (fmt[j] == '-')
                            {
                                index = -index;
                                break;
                            }
                            mult *= 10;
                        }
                        // as is alignment
                        int alignment = 0;
                        mult = 1;
                        if (has_alignment)
                        {
                            for (int j = alignment_end - 1; j >= alignment_start; j++)
                            {
                                int diff = (int)fmt[j] - (int)'0';
                                if ((diff >= 0) && (diff <= 9))
                                {
                                    alignment += (diff * mult);
                                }
                                if (fmt[j] == '-')
                                {
                                    alignment = -alignment;
                                    break;
                                }
                                mult *= 10;
                            }
                        }

                        // TODO: interpret format string
                        // Use RTTI to determine what p[index] is and display it using the specified alignment
                        //  and format string

                        has_alignment = has_format = false;
                    }
                }
                else if (in_format)
                {
                    // Nothing to do
                }
                else if (in_alignment)
                {
                    if (fmt[i] == ':')
                    {
                        in_alignment  = false;
                        in_format     = true;
                        alignment_end = i;
                        format_start  = i + 1;
                        has_format    = true;
                    }
                }
                else if (in_index)
                {
                    if (fmt[i] == ',')
                    {
                        in_index        = false;
                        in_alignment    = true;
                        index_end       = i;
                        alignment_start = i + 1;
                        has_alignment   = true;
                    }
                    if (fmt[i] == ':')
                    {
                        in_index     = false;
                        in_format    = true;
                        index_end    = i;
                        format_start = i + 1;
                        has_format   = true;
                    }
                }
                else
                {
                    if (fmt[i] == '{')
                    {
                        if ((i < (fmt.Length - 1)) && (fmt[i + i] == '{'))
                        {
                            s.Write('{');
                            i++;
                        }
                        else
                        {
                            index_start = i + 1;
                            in_index    = true;
                        }
                    }
                    else
                    {
                        if (fmt[i] == '\\')
                        {
                            in_escape = true;
                        }
                        else
                        {
                            s.Write(fmt[i]);
                        }
                    }
                }
            }
            s.Flush();
        }