diff options
| author | Ac_K <Acoustik666@gmail.com> | 2018-02-25 19:58:16 +0100 |
|---|---|---|
| committer | gdkchan <gab.dark.100@gmail.com> | 2018-02-25 15:58:16 -0300 |
| commit | e174100474fcfe484cc8e93c4db447886096615d (patch) | |
| tree | 062d3437e791e173c86788dcbf58875c293ca3c8 /Ryujinx.Core/Logging.cs | |
| parent | fba0bf873257c4ac17f4584036661be08a1694d3 (diff) | |
Implement many objects, improve logging. (#42)
* Implement many objects, improve logging.
Change and rename folders of Services
Add Logging of IpcMessage.
Add "lm" Log Service.
Parse Errors of SetTerminateResult
Add Svc Calls.
Add many object implementations.
* Corrections
Forgotten Debug Conf
* Corrections 2
* Corrections 3
* Corrections 4
Diffstat (limited to 'Ryujinx.Core/Logging.cs')
| -rw-r--r-- | Ryujinx.Core/Logging.cs | 93 |
1 files changed, 85 insertions, 8 deletions
diff --git a/Ryujinx.Core/Logging.cs b/Ryujinx.Core/Logging.cs index e14e5587..b14f2665 100644 --- a/Ryujinx.Core/Logging.cs +++ b/Ryujinx.Core/Logging.cs @@ -1,6 +1,8 @@ -using System; +using Ryujinx.Core.OsHle.Ipc; +using System; using System.Diagnostics; using System.IO; +using System.Text; namespace Ryujinx.Core { @@ -9,13 +11,14 @@ namespace Ryujinx.Core private static Stopwatch ExecutionTime = new Stopwatch(); private const string LogFileName = "Ryujinx.log"; - public static bool EnableInfo = Config.LoggingEnableInfo; - public static bool EnableTrace = Config.LoggingEnableTrace; - public static bool EnableDebug = Config.LoggingEnableDebug; - public static bool EnableWarn = Config.LoggingEnableWarn; - public static bool EnableError = Config.LoggingEnableError; - public static bool EnableFatal = Config.LoggingEnableFatal; - public static bool EnableLogFile = Config.LoggingEnableLogFile; + private static bool EnableInfo = Config.LoggingEnableInfo; + private static bool EnableTrace = Config.LoggingEnableTrace; + private static bool EnableDebug = Config.LoggingEnableDebug; + private static bool EnableWarn = Config.LoggingEnableWarn; + private static bool EnableError = Config.LoggingEnableError; + private static bool EnableFatal = Config.LoggingEnableFatal; + private static bool EnableIpc = Config.LoggingEnableIpc; + private static bool EnableLogFile = Config.LoggingEnableLogFile; static Logging() { @@ -128,5 +131,79 @@ namespace Ryujinx.Core LogFile(Text); } } + + public static void Ipc(byte[] Data, long CmdPtr, bool Domain) + { + if (EnableIpc) + { + Console.ForegroundColor = ConsoleColor.Cyan; + Console.WriteLine(IpcLog.Message(Data, CmdPtr, Domain)); + Console.ResetColor(); + } + } + + //https://www.codeproject.com/Articles/36747/Quick-and-Dirty-HexDump-of-a-Byte-Array + public static string HexDump(byte[] bytes, int bytesPerLine = 16) + { + if (bytes == null) return "<null>"; + int bytesLength = bytes.Length; + + char[] HexChars = "0123456789ABCDEF".ToCharArray(); + + int firstHexColumn = + 8 // 8 characters for the address + + 3; // 3 spaces + + int firstCharColumn = firstHexColumn + + bytesPerLine * 3 // - 2 digit for the hexadecimal value and 1 space + + (bytesPerLine - 1) / 8 // - 1 extra space every 8 characters from the 9th + + 2; // 2 spaces + + int lineLength = firstCharColumn + + bytesPerLine // - characters to show the ascii value + + Environment.NewLine.Length; // Carriage return and line feed (should normally be 2) + + char[] line = (new String(' ', lineLength - Environment.NewLine.Length) + Environment.NewLine).ToCharArray(); + int expectedLines = (bytesLength + bytesPerLine - 1) / bytesPerLine; + StringBuilder result = new StringBuilder(expectedLines * lineLength); + + for (int i = 0; i < bytesLength; i += bytesPerLine) + { + line[0] = HexChars[(i >> 28) & 0xF]; + line[1] = HexChars[(i >> 24) & 0xF]; + line[2] = HexChars[(i >> 20) & 0xF]; + line[3] = HexChars[(i >> 16) & 0xF]; + line[4] = HexChars[(i >> 12) & 0xF]; + line[5] = HexChars[(i >> 8) & 0xF]; + line[6] = HexChars[(i >> 4) & 0xF]; + line[7] = HexChars[(i >> 0) & 0xF]; + + int hexColumn = firstHexColumn; + int charColumn = firstCharColumn; + + for (int j = 0; j < bytesPerLine; j++) + { + if (j > 0 && (j & 7) == 0) hexColumn++; + if (i + j >= bytesLength) + { + line[hexColumn] = ' '; + line[hexColumn + 1] = ' '; + line[charColumn] = ' '; + } + else + { + byte b = bytes[i + j]; + line[hexColumn] = HexChars[(b >> 4) & 0xF]; + line[hexColumn + 1] = HexChars[b & 0xF]; + line[charColumn] = (b < 32 ? '·' : (char)b); + } + hexColumn += 3; + charColumn++; + } + + result.Append(line); + } + return result.ToString(); + } } } |
