summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/CMakeLists.txt8
-rw-r--r--src/common/chunk_file.h2
-rw-r--r--src/common/common.h73
-rw-r--r--src/common/common_funcs.h28
-rw-r--r--src/common/extended_trace.cpp428
-rw-r--r--src/common/extended_trace.h50
-rw-r--r--src/common/file_search.cpp103
-rw-r--r--src/common/file_search.h23
-rw-r--r--src/common/hash.cpp13
-rw-r--r--src/common/mem_arena.cpp7
-rw-r--r--src/common/memory_util.cpp14
-rw-r--r--src/common/msg_handler.cpp107
-rw-r--r--src/common/msg_handler.h56
-rw-r--r--src/common/utf8.cpp459
-rw-r--r--src/common/utf8.h67
-rw-r--r--src/core/core_timing.cpp4
-rw-r--r--src/core/hle/kernel/thread.cpp5
-rw-r--r--src/core/hw/gpu.h11
-rw-r--r--src/video_core/pica.h11
19 files changed, 47 insertions, 1422 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 8c87deaa4..b05c35546 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -4,8 +4,6 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/scm_rev.cpp.in" "${CMAKE_CURRENT_SOU
4set(SRCS 4set(SRCS
5 break_points.cpp 5 break_points.cpp
6 emu_window.cpp 6 emu_window.cpp
7 extended_trace.cpp
8 file_search.cpp
9 file_util.cpp 7 file_util.cpp
10 hash.cpp 8 hash.cpp
11 key_map.cpp 9 key_map.cpp
@@ -16,13 +14,11 @@ set(SRCS
16 mem_arena.cpp 14 mem_arena.cpp
17 memory_util.cpp 15 memory_util.cpp
18 misc.cpp 16 misc.cpp
19 msg_handler.cpp
20 scm_rev.cpp 17 scm_rev.cpp
21 string_util.cpp 18 string_util.cpp
22 symbols.cpp 19 symbols.cpp
23 thread.cpp 20 thread.cpp
24 timer.cpp 21 timer.cpp
25 utf8.cpp
26 ) 22 )
27 23
28set(HEADERS 24set(HEADERS
@@ -38,9 +34,7 @@ set(HEADERS
38 cpu_detect.h 34 cpu_detect.h
39 debug_interface.h 35 debug_interface.h
40 emu_window.h 36 emu_window.h
41 extended_trace.h
42 fifo_queue.h 37 fifo_queue.h
43 file_search.h
44 file_util.h 38 file_util.h
45 hash.h 39 hash.h
46 key_map.h 40 key_map.h
@@ -53,7 +47,6 @@ set(HEADERS
53 math_util.h 47 math_util.h
54 mem_arena.h 48 mem_arena.h
55 memory_util.h 49 memory_util.h
56 msg_handler.h
57 platform.h 50 platform.h
58 scm_rev.h 51 scm_rev.h
59 scope_exit.h 52 scope_exit.h
@@ -64,7 +57,6 @@ set(HEADERS
64 thread_queue_list.h 57 thread_queue_list.h
65 thunk.h 58 thunk.h
66 timer.h 59 timer.h
67 utf8.h
68 ) 60 )
69 61
70create_directory_groups(${SRCS} ${HEADERS}) 62create_directory_groups(${SRCS} ${HEADERS})
diff --git a/src/common/chunk_file.h b/src/common/chunk_file.h
index dc27da088..3f97d56bf 100644
--- a/src/common/chunk_file.h
+++ b/src/common/chunk_file.h
@@ -637,7 +637,7 @@ public:
637 Do(cookie); 637 Do(cookie);
638 if(mode == PointerWrap::MODE_READ && cookie != arbitraryNumber) 638 if(mode == PointerWrap::MODE_READ && cookie != arbitraryNumber)
639 { 639 {
640 PanicAlertT("Error: After \"%s\", found %d (0x%X) instead of save marker %d (0x%X). Aborting savestate load...", prevName, cookie, cookie, arbitraryNumber, arbitraryNumber); 640 LOG_ERROR(Common, "After \"%s\", found %d (0x%X) instead of save marker %d (0x%X). Aborting savestate load...", prevName, cookie, cookie, arbitraryNumber, arbitraryNumber);
641 SetError(ERROR_FAILURE); 641 SetError(ERROR_FAILURE);
642 } 642 }
643 } 643 }
diff --git a/src/common/common.h b/src/common/common.h
index ad2de6f2e..948dc536a 100644
--- a/src/common/common.h
+++ b/src/common/common.h
@@ -28,7 +28,6 @@ private:
28#include "common/assert.h" 28#include "common/assert.h"
29#include "common/logging/log.h" 29#include "common/logging/log.h"
30#include "common/common_types.h" 30#include "common/common_types.h"
31#include "common/msg_handler.h"
32#include "common/common_funcs.h" 31#include "common/common_funcs.h"
33#include "common/common_paths.h" 32#include "common/common_paths.h"
34#include "common/platform.h" 33#include "common/platform.h"
@@ -36,13 +35,11 @@ private:
36#ifdef __APPLE__ 35#ifdef __APPLE__
37// The Darwin ABI requires that stack frames be aligned to 16-byte boundaries. 36// The Darwin ABI requires that stack frames be aligned to 16-byte boundaries.
38// This is only needed on i386 gcc - x86_64 already aligns to 16 bytes. 37// This is only needed on i386 gcc - x86_64 already aligns to 16 bytes.
39#if defined __i386__ && defined __GNUC__ 38 #if defined __i386__ && defined __GNUC__
40#undef STACKALIGN 39 #undef STACKALIGN
41#define STACKALIGN __attribute__((__force_align_arg_pointer__)) 40 #define STACKALIGN __attribute__((__force_align_arg_pointer__))
42#endif 41 #endif
43
44#elif defined _WIN32 42#elif defined _WIN32
45
46// Check MSC ver 43// Check MSC ver
47 #if defined _MSC_VER && _MSC_VER <= 1000 44 #if defined _MSC_VER && _MSC_VER <= 1000
48 #error needs at least version 1000 of MSC 45 #error needs at least version 1000 of MSC
@@ -52,9 +49,6 @@ private:
52 #define NOMINMAX 49 #define NOMINMAX
53 #endif 50 #endif
54 51
55// Memory leak checks
56 #define CHECK_HEAP_INTEGRITY()
57
58// Alignment 52// Alignment
59 #define MEMORY_ALIGNED16(x) __declspec(align(16)) x 53 #define MEMORY_ALIGNED16(x) __declspec(align(16)) x
60 #define MEMORY_ALIGNED32(x) __declspec(align(32)) x 54 #define MEMORY_ALIGNED32(x) __declspec(align(32)) x
@@ -62,57 +56,34 @@ private:
62 #define MEMORY_ALIGNED128(x) __declspec(align(128)) x 56 #define MEMORY_ALIGNED128(x) __declspec(align(128)) x
63 #define MEMORY_ALIGNED16_DECL(x) __declspec(align(16)) x 57 #define MEMORY_ALIGNED16_DECL(x) __declspec(align(16)) x
64 #define MEMORY_ALIGNED64_DECL(x) __declspec(align(64)) x 58 #define MEMORY_ALIGNED64_DECL(x) __declspec(align(64)) x
65
66// Since they are always around on windows
67 #define HAVE_WX 1
68 #define HAVE_OPENAL 1
69
70 #define HAVE_PORTAUDIO 1
71
72// Debug definitions
73 #if defined(_DEBUG)
74 #include <crtdbg.h>
75 #undef CHECK_HEAP_INTEGRITY
76 #define CHECK_HEAP_INTEGRITY() {if (!_CrtCheckMemory()) PanicAlert("memory corruption detected. see log.");}
77 // If you want to see how much a pain in the ass singletons are, for example:
78 // {614} normal block at 0x030C5310, 188 bytes long.
79 // Data: <Master Log > 4D 61 73 74 65 72 20 4C 6F 67 00 00 00 00 00 00
80 struct CrtDebugBreak { CrtDebugBreak(int spot) { _CrtSetBreakAlloc(spot); } };
81 //CrtDebugBreak breakAt(614);
82 #endif // end DEBUG/FAST
83
84#endif 59#endif
85 60
86// Windows compatibility 61// Windows compatibility
87#ifndef _WIN32 62#ifndef _WIN32
88#ifdef _LP64 63 #ifdef _LP64
89#define _M_X64 1 64 #define _M_X64 1
90#else 65 #else
91#define _M_IX86 1 66 #define _M_IX86 1
92#endif 67 #endif
93#define __forceinline inline __attribute__((always_inline)) 68 #define __forceinline inline __attribute__((always_inline))
94#define MEMORY_ALIGNED16(x) __attribute__((aligned(16))) x 69 #define MEMORY_ALIGNED16(x) __attribute__((aligned(16))) x
95#define MEMORY_ALIGNED32(x) __attribute__((aligned(32))) x 70 #define MEMORY_ALIGNED32(x) __attribute__((aligned(32))) x
96#define MEMORY_ALIGNED64(x) __attribute__((aligned(64))) x 71 #define MEMORY_ALIGNED64(x) __attribute__((aligned(64))) x
97#define MEMORY_ALIGNED128(x) __attribute__((aligned(128))) x 72 #define MEMORY_ALIGNED128(x) __attribute__((aligned(128))) x
98#define MEMORY_ALIGNED16_DECL(x) __attribute__((aligned(16))) x 73 #define MEMORY_ALIGNED16_DECL(x) __attribute__((aligned(16))) x
99#define MEMORY_ALIGNED64_DECL(x) __attribute__((aligned(64))) x 74 #define MEMORY_ALIGNED64_DECL(x) __attribute__((aligned(64))) x
100#endif 75#endif
101 76
102#ifdef _MSC_VER 77#ifdef _MSC_VER
103#define __strdup _strdup 78 #define __strdup _strdup
104#define __getcwd _getcwd 79 #define __getcwd _getcwd
105#define __chdir _chdir 80 #define __chdir _chdir
106#else 81#else
107#define __strdup strdup 82 #define __strdup strdup
108#define __getcwd getcwd 83 #define __getcwd getcwd
109#define __chdir chdir 84 #define __chdir chdir
110#endif 85#endif
111 86
112// Dummy macro for marking translatable strings that can not be immediately translated.
113// wxWidgets does not have a true dummy macro for this.
114#define _trans(a) a
115
116#if defined _M_GENERIC 87#if defined _M_GENERIC
117# define _M_SSE 0x0 88# define _M_SSE 0x0
118#elif defined __GNUC__ 89#elif defined __GNUC__
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h
index 4bbcc3571..bc296ed3e 100644
--- a/src/common/common_funcs.h
+++ b/src/common/common_funcs.h
@@ -24,11 +24,6 @@ template<> struct CompileTimeAssert<true> {};
24#define b32(x) (b16(x) | (b16(x) >>16) ) 24#define b32(x) (b16(x) | (b16(x) >>16) )
25#define ROUND_UP_POW2(x) (b32(x - 1) + 1) 25#define ROUND_UP_POW2(x) (b32(x - 1) + 1)
26 26
27#define MIN(a, b) ((a)<(b)?(a):(b))
28#define MAX(a, b) ((a)>(b)?(a):(b))
29
30#define CLAMP(x, min, max) (((x) > max) ? max : (((x) < min) ? min : (x)))
31
32#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) 27#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
33 28
34/// Textually concatenates two tokens. The double-expansion is required by the C preprocessor. 29/// Textually concatenates two tokens. The double-expansion is required by the C preprocessor.
@@ -38,9 +33,8 @@ template<> struct CompileTimeAssert<true> {};
38// helper macro to properly align structure members. 33// helper macro to properly align structure members.
39// Calling INSERT_PADDING_BYTES will add a new member variable with a name like "pad121", 34// Calling INSERT_PADDING_BYTES will add a new member variable with a name like "pad121",
40// depending on the current source line to make sure variable names are unique. 35// depending on the current source line to make sure variable names are unique.
41#define INSERT_PADDING_BYTES_HELPER1(x, y) x ## y 36#define INSERT_PADDING_BYTES(num_bytes) u8 CONCAT2(pad, __LINE__)[(num_bytes)]
42#define INSERT_PADDING_BYTES_HELPER2(x, y) INSERT_PADDING_BYTES_HELPER1(x, y) 37#define INSERT_PADDING_WORDS(num_words) u32 CONCAT2(pad, __LINE__)[(num_words)]
43#define INSERT_PADDING_BYTES(num_words) u8 INSERT_PADDING_BYTES_HELPER2(pad, __LINE__)[(num_words)]
44 38
45#ifndef _MSC_VER 39#ifndef _MSC_VER
46 40
@@ -148,15 +142,6 @@ inline u64 _rotr64(u64 x, unsigned int shift){
148 #define Crash() {DebugBreak();} 142 #define Crash() {DebugBreak();}
149#endif // _MSC_VER ndef 143#endif // _MSC_VER ndef
150 144
151// Dolphin's min and max functions
152#undef min
153#undef max
154
155template<class T>
156inline T min(const T& a, const T& b) {return a > b ? b : a;}
157template<class T>
158inline T max(const T& a, const T& b) {return a > b ? a : b;}
159
160// Generic function to get last error message. 145// Generic function to get last error message.
161// Call directly after the command or use the error num. 146// Call directly after the command or use the error num.
162// This function might change the error code. 147// This function might change the error code.
@@ -233,13 +218,4 @@ inline void swap<8>(u8* data)
233 *reinterpret_cast<u64*>(data) = swap64(data); 218 *reinterpret_cast<u64*>(data) = swap64(data);
234} 219}
235 220
236template <typename T>
237inline T FromBigEndian(T data)
238{
239 //static_assert(std::is_arithmetic<T>::value, "function only makes sense with arithmetic types");
240
241 swap<sizeof(data)>(reinterpret_cast<u8*>(&data));
242 return data;
243}
244
245} // Namespace Common 221} // Namespace Common
diff --git a/src/common/extended_trace.cpp b/src/common/extended_trace.cpp
deleted file mode 100644
index cf7c346d4..000000000
--- a/src/common/extended_trace.cpp
+++ /dev/null
@@ -1,428 +0,0 @@
1// --------------------------------------------------------------------------------------
2//
3// Written by Zoltan Csizmadia, zoltan_csizmadia@yahoo.com
4// For companies(Austin,TX): If you would like to get my resume, send an email.
5//
6// The source is free, but if you want to use it, mention my name and e-mail address
7//
8// History:
9// 1.0 Initial version Zoltan Csizmadia
10// 1.1 WhineCube version Masken
11// 1.2 Dolphin version Masken
12//
13// --------------------------------------------------------------------------------------
14
15#if defined(WIN32)
16#include <cstdio>
17#include <windows.h>
18#include "common/extended_trace.h"
19#include "common/string_util.h"
20using namespace std;
21
22#include <tchar.h>
23#include <ImageHlp.h>
24
25#define BUFFERSIZE 0x200
26#pragma warning(disable:4996)
27
28// Unicode safe char* -> TCHAR* conversion
29void PCSTR2LPTSTR( PCSTR lpszIn, LPTSTR lpszOut )
30{
31#if defined(UNICODE)||defined(_UNICODE)
32 ULONG index = 0;
33 PCSTR lpAct = lpszIn;
34
35 for( ; ; lpAct++ )
36 {
37 lpszOut[index++] = (TCHAR)(*lpAct);
38 if ( *lpAct == 0 )
39 break;
40 }
41#else
42 // This is trivial :)
43 strcpy( lpszOut, lpszIn );
44#endif
45}
46
47// Let's figure out the path for the symbol files
48// Search path= ".;%_NT_SYMBOL_PATH%;%_NT_ALTERNATE_SYMBOL_PATH%;%SYSTEMROOT%;%SYSTEMROOT%\System32;" + lpszIniPath
49// Note: There is no size check for lpszSymbolPath!
50static void InitSymbolPath( PSTR lpszSymbolPath, PCSTR lpszIniPath )
51{
52 CHAR lpszPath[BUFFERSIZE];
53
54 // Creating the default path
55 // ".;%_NT_SYMBOL_PATH%;%_NT_ALTERNATE_SYMBOL_PATH%;%SYSTEMROOT%;%SYSTEMROOT%\System32;"
56 strcpy( lpszSymbolPath, "." );
57
58 // environment variable _NT_SYMBOL_PATH
59 if ( GetEnvironmentVariableA( "_NT_SYMBOL_PATH", lpszPath, BUFFERSIZE ) )
60 {
61 strcat( lpszSymbolPath, ";" );
62 strcat( lpszSymbolPath, lpszPath );
63 }
64
65 // environment variable _NT_ALTERNATE_SYMBOL_PATH
66 if ( GetEnvironmentVariableA( "_NT_ALTERNATE_SYMBOL_PATH", lpszPath, BUFFERSIZE ) )
67 {
68 strcat( lpszSymbolPath, ";" );
69 strcat( lpszSymbolPath, lpszPath );
70 }
71
72 // environment variable SYSTEMROOT
73 if ( GetEnvironmentVariableA( "SYSTEMROOT", lpszPath, BUFFERSIZE ) )
74 {
75 strcat( lpszSymbolPath, ";" );
76 strcat( lpszSymbolPath, lpszPath );
77 strcat( lpszSymbolPath, ";" );
78
79 // SYSTEMROOT\System32
80 strcat( lpszSymbolPath, lpszPath );
81 strcat( lpszSymbolPath, "\\System32" );
82 }
83
84 // Add user defined path
85 if ( lpszIniPath != nullptr )
86 if ( lpszIniPath[0] != '\0' )
87 {
88 strcat( lpszSymbolPath, ";" );
89 strcat( lpszSymbolPath, lpszIniPath );
90 }
91}
92
93// Uninitialize the loaded symbol files
94BOOL UninitSymInfo() {
95 return SymCleanup( GetCurrentProcess() );
96}
97
98// Initializes the symbol files
99BOOL InitSymInfo( PCSTR lpszInitialSymbolPath )
100{
101 CHAR lpszSymbolPath[BUFFERSIZE];
102 DWORD symOptions = SymGetOptions();
103
104 symOptions |= SYMOPT_LOAD_LINES;
105 symOptions &= ~SYMOPT_UNDNAME;
106 SymSetOptions( symOptions );
107 InitSymbolPath( lpszSymbolPath, lpszInitialSymbolPath );
108
109 return SymInitialize( GetCurrentProcess(), lpszSymbolPath, TRUE);
110}
111
112// Get the module name from a given address
113static BOOL GetModuleNameFromAddress( UINT address, LPTSTR lpszModule )
114{
115 BOOL ret = FALSE;
116 IMAGEHLP_MODULE moduleInfo;
117
118 ::ZeroMemory( &moduleInfo, sizeof(moduleInfo) );
119 moduleInfo.SizeOfStruct = sizeof(moduleInfo);
120
121 if ( SymGetModuleInfo( GetCurrentProcess(), (DWORD)address, &moduleInfo ) )
122 {
123 // Got it!
124 PCSTR2LPTSTR( moduleInfo.ModuleName, lpszModule );
125 ret = TRUE;
126 }
127 else
128 // Not found :(
129 _tcscpy( lpszModule, _T("?") );
130
131 return ret;
132}
133
134// Get function prototype and parameter info from ip address and stack address
135static BOOL GetFunctionInfoFromAddresses( ULONG fnAddress, ULONG stackAddress, LPTSTR lpszSymbol )
136{
137 BOOL ret = FALSE;
138 DWORD dwSymSize = 10000;
139 TCHAR lpszUnDSymbol[BUFFERSIZE]=_T("?");
140 CHAR lpszNonUnicodeUnDSymbol[BUFFERSIZE]="?";
141 LPTSTR lpszParamSep = nullptr;
142 LPTSTR lpszParsed = lpszUnDSymbol;
143 PIMAGEHLP_SYMBOL pSym = (PIMAGEHLP_SYMBOL)GlobalAlloc( GMEM_FIXED, dwSymSize );
144
145 ::ZeroMemory( pSym, dwSymSize );
146 pSym->SizeOfStruct = dwSymSize;
147 pSym->MaxNameLength = dwSymSize - sizeof(IMAGEHLP_SYMBOL);
148
149 // Set the default to unknown
150 _tcscpy( lpszSymbol, _T("?") );
151
152 // Get symbol info for IP
153#ifndef _M_X64
154 DWORD dwDisp = 0;
155 if ( SymGetSymFromAddr( GetCurrentProcess(), (ULONG)fnAddress, &dwDisp, pSym ) )
156#else
157 //makes it compile but hell im not sure if this works...
158 DWORD64 dwDisp = 0;
159 if ( SymGetSymFromAddr( GetCurrentProcess(), (ULONG)fnAddress, (PDWORD64)&dwDisp, pSym ) )
160#endif
161 {
162 // Make the symbol readable for humans
163 UnDecorateSymbolName( pSym->Name, lpszNonUnicodeUnDSymbol, BUFFERSIZE,
164 UNDNAME_COMPLETE |
165 UNDNAME_NO_THISTYPE |
166 UNDNAME_NO_SPECIAL_SYMS |
167 UNDNAME_NO_MEMBER_TYPE |
168 UNDNAME_NO_MS_KEYWORDS |
169 UNDNAME_NO_ACCESS_SPECIFIERS );
170
171 // Symbol information is ANSI string
172 PCSTR2LPTSTR( lpszNonUnicodeUnDSymbol, lpszUnDSymbol );
173
174 // I am just smarter than the symbol file :)
175 if (_tcscmp(lpszUnDSymbol, _T("_WinMain@16")) == 0)
176 _tcscpy(lpszUnDSymbol, _T("WinMain(HINSTANCE,HINSTANCE,LPCTSTR,int)"));
177 else if (_tcscmp(lpszUnDSymbol, _T("_main")) == 0)
178 _tcscpy(lpszUnDSymbol, _T("main(int,TCHAR * *)"));
179 else if (_tcscmp(lpszUnDSymbol, _T("_mainCRTStartup")) == 0)
180 _tcscpy(lpszUnDSymbol, _T("mainCRTStartup()"));
181 else if (_tcscmp(lpszUnDSymbol, _T("_wmain")) == 0)
182 _tcscpy(lpszUnDSymbol, _T("wmain(int,TCHAR * *,TCHAR * *)"));
183 else if (_tcscmp(lpszUnDSymbol, _T("_wmainCRTStartup")) == 0)
184 _tcscpy(lpszUnDSymbol, _T("wmainCRTStartup()"));
185
186 lpszSymbol[0] = _T('\0');
187
188 // Let's go through the stack, and modify the function prototype, and insert the actual
189 // parameter values from the stack
190 if ( _tcsstr( lpszUnDSymbol, _T("(void)") ) == nullptr && _tcsstr( lpszUnDSymbol, _T("()") ) == nullptr)
191 {
192 ULONG index = 0;
193 for( ; ; index++ )
194 {
195 lpszParamSep = _tcschr( lpszParsed, _T(',') );
196 if ( lpszParamSep == nullptr )
197 break;
198
199 *lpszParamSep = _T('\0');
200
201 _tcscat( lpszSymbol, lpszParsed );
202 _stprintf( lpszSymbol + _tcslen(lpszSymbol), _T("=0x%08X,"), *((ULONG*)(stackAddress) + 2 + index) );
203
204 lpszParsed = lpszParamSep + 1;
205 }
206
207 lpszParamSep = _tcschr( lpszParsed, _T(')') );
208 if ( lpszParamSep != nullptr )
209 {
210 *lpszParamSep = _T('\0');
211
212 _tcscat( lpszSymbol, lpszParsed );
213 _stprintf( lpszSymbol + _tcslen(lpszSymbol), _T("=0x%08X)"), *((ULONG*)(stackAddress) + 2 + index) );
214
215 lpszParsed = lpszParamSep + 1;
216 }
217 }
218
219 _tcscat( lpszSymbol, lpszParsed );
220
221 ret = TRUE;
222 }
223 GlobalFree( pSym );
224
225 return ret;
226}
227
228// Get source file name and line number from IP address
229// The output format is: "sourcefile(linenumber)" or
230// "modulename!address" or
231// "address"
232static BOOL GetSourceInfoFromAddress( UINT address, LPTSTR lpszSourceInfo )
233{
234 BOOL ret = FALSE;
235 IMAGEHLP_LINE lineInfo;
236 DWORD dwDisp;
237 TCHAR lpszFileName[BUFFERSIZE] = _T("");
238 TCHAR lpModuleInfo[BUFFERSIZE] = _T("");
239
240 _tcscpy( lpszSourceInfo, _T("?(?)") );
241
242 ::ZeroMemory( &lineInfo, sizeof( lineInfo ) );
243 lineInfo.SizeOfStruct = sizeof( lineInfo );
244
245 if ( SymGetLineFromAddr( GetCurrentProcess(), address, &dwDisp, &lineInfo ) )
246 {
247 // Got it. Let's use "sourcefile(linenumber)" format
248 PCSTR2LPTSTR( lineInfo.FileName, lpszFileName );
249 TCHAR fname[_MAX_FNAME];
250 TCHAR ext[_MAX_EXT];
251 _tsplitpath(lpszFileName, nullptr, nullptr, fname, ext);
252 _stprintf( lpszSourceInfo, _T("%s%s(%d)"), fname, ext, lineInfo.LineNumber );
253 ret = TRUE;
254 }
255 else
256 {
257 // There is no source file information. :(
258 // Let's use the "modulename!address" format
259 GetModuleNameFromAddress( address, lpModuleInfo );
260
261 if ( lpModuleInfo[0] == _T('?') || lpModuleInfo[0] == _T('\0'))
262 // There is no modulename information. :((
263 // Let's use the "address" format
264 _stprintf( lpszSourceInfo, _T("0x%08X"), address );
265 else
266 _stprintf( lpszSourceInfo, _T("%s!0x%08X"), lpModuleInfo, address );
267
268 ret = FALSE;
269 }
270
271 return ret;
272}
273
274void PrintFunctionAndSourceInfo(FILE* file, const STACKFRAME& callstack)
275{
276 TCHAR symInfo[BUFFERSIZE] = _T("?");
277 TCHAR srcInfo[BUFFERSIZE] = _T("?");
278
279 GetFunctionInfoFromAddresses((ULONG)callstack.AddrPC.Offset, (ULONG)callstack.AddrFrame.Offset, symInfo);
280 GetSourceInfoFromAddress((ULONG)callstack.AddrPC.Offset, srcInfo);
281 etfprint(file, " " + Common::TStrToUTF8(srcInfo) + " : " + Common::TStrToUTF8(symInfo) + "\n");
282}
283
284void StackTrace( HANDLE hThread, const char* lpszMessage, FILE *file )
285{
286 STACKFRAME callStack;
287 BOOL bResult;
288 CONTEXT context;
289 HANDLE hProcess = GetCurrentProcess();
290
291 // If it's not this thread, let's suspend it, and resume it at the end
292 if ( hThread != GetCurrentThread() )
293 if ( SuspendThread( hThread ) == -1 )
294 {
295 // whaaat ?!
296 etfprint(file, "Call stack info failed\n");
297 return;
298 }
299
300 ::ZeroMemory( &context, sizeof(context) );
301 context.ContextFlags = CONTEXT_FULL;
302
303 if ( !GetThreadContext( hThread, &context ) )
304 {
305 etfprint(file, "Call stack info failed\n");
306 return;
307 }
308
309 ::ZeroMemory( &callStack, sizeof(callStack) );
310#ifndef _M_X64
311 callStack.AddrPC.Offset = context.Eip;
312 callStack.AddrStack.Offset = context.Esp;
313 callStack.AddrFrame.Offset = context.Ebp;
314#else
315 callStack.AddrPC.Offset = context.Rip;
316 callStack.AddrStack.Offset = context.Rsp;
317 callStack.AddrFrame.Offset = context.Rbp;
318#endif
319 callStack.AddrPC.Mode = AddrModeFlat;
320 callStack.AddrStack.Mode = AddrModeFlat;
321 callStack.AddrFrame.Mode = AddrModeFlat;
322
323 etfprint(file, "Call stack info: \n");
324 etfprint(file, lpszMessage);
325
326 PrintFunctionAndSourceInfo(file, callStack);
327
328 for( ULONG index = 0; ; index++ )
329 {
330 bResult = StackWalk(
331 IMAGE_FILE_MACHINE_I386,
332 hProcess,
333 hThread,
334 &callStack,
335 nullptr,
336 nullptr,
337 SymFunctionTableAccess,
338 SymGetModuleBase,
339 nullptr);
340
341 if ( index == 0 )
342 continue;
343
344 if( !bResult || callStack.AddrFrame.Offset == 0 )
345 break;
346
347 PrintFunctionAndSourceInfo(file, callStack);
348
349 }
350
351 if ( hThread != GetCurrentThread() )
352 ResumeThread( hThread );
353}
354
355void StackTrace(HANDLE hThread, const char* lpszMessage, FILE *file, DWORD eip, DWORD esp, DWORD ebp )
356{
357 STACKFRAME callStack;
358 BOOL bResult;
359 TCHAR symInfo[BUFFERSIZE] = _T("?");
360 TCHAR srcInfo[BUFFERSIZE] = _T("?");
361 HANDLE hProcess = GetCurrentProcess();
362
363 // If it's not this thread, let's suspend it, and resume it at the end
364 if ( hThread != GetCurrentThread() )
365 if ( SuspendThread( hThread ) == -1 )
366 {
367 // whaaat ?!
368 etfprint(file, "Call stack info failed\n");
369 return;
370 }
371
372 ::ZeroMemory( &callStack, sizeof(callStack) );
373 callStack.AddrPC.Offset = eip;
374 callStack.AddrStack.Offset = esp;
375 callStack.AddrFrame.Offset = ebp;
376 callStack.AddrPC.Mode = AddrModeFlat;
377 callStack.AddrStack.Mode = AddrModeFlat;
378 callStack.AddrFrame.Mode = AddrModeFlat;
379
380 etfprint(file, "Call stack info: \n");
381 etfprint(file, lpszMessage);
382
383 PrintFunctionAndSourceInfo(file, callStack);
384
385 for( ULONG index = 0; ; index++ )
386 {
387 bResult = StackWalk(
388 IMAGE_FILE_MACHINE_I386,
389 hProcess,
390 hThread,
391 &callStack,
392 nullptr,
393 nullptr,
394 SymFunctionTableAccess,
395 SymGetModuleBase,
396 nullptr);
397
398 if ( index == 0 )
399 continue;
400
401 if( !bResult || callStack.AddrFrame.Offset == 0 )
402 break;
403
404 PrintFunctionAndSourceInfo(file, callStack);
405 }
406
407 if ( hThread != GetCurrentThread() )
408 ResumeThread( hThread );
409}
410
411char g_uefbuf[2048];
412
413void etfprintf(FILE *file, const char *format, ...)
414{
415 va_list ap;
416 va_start(ap, format);
417 int len = vsprintf(g_uefbuf, format, ap);
418 fwrite(g_uefbuf, 1, len, file);
419 va_end(ap);
420}
421
422void etfprint(FILE *file, const std::string &text)
423{
424 size_t len = text.length();
425 fwrite(text.data(), 1, len, file);
426}
427
428#endif //WIN32
diff --git a/src/common/extended_trace.h b/src/common/extended_trace.h
deleted file mode 100644
index ed3113a24..000000000
--- a/src/common/extended_trace.h
+++ /dev/null
@@ -1,50 +0,0 @@
1// -----------------------------------------------------------------------------------------
2//
3// Written by Zoltan Csizmadia, zoltan_csizmadia@yahoo.com
4// For companies(Austin,TX): If you would like to get my resume, send an email.
5//
6// The source is free, but if you want to use it, mention my name and e-mail address
7//
8// History:
9// 1.0 Initial version Zoltan Csizmadia
10// 1.1 WhineCube version Masken
11// 1.2 Dolphin version Masken
12//
13// ----------------------------------------------------------------------------------------
14
15#pragma once
16
17#if defined(WIN32)
18
19#include <windows.h>
20#include <tchar.h>
21
22#include <string>
23
24#pragma comment( lib, "imagehlp.lib" )
25
26#define EXTENDEDTRACEINITIALIZE( IniSymbolPath ) InitSymInfo( IniSymbolPath )
27#define EXTENDEDTRACEUNINITIALIZE() UninitSymInfo()
28#define STACKTRACE(file) StackTrace( GetCurrentThread(), "", file)
29#define STACKTRACE2(file, eip, esp, ebp) StackTrace(GetCurrentThread(), "", file, eip, esp, ebp)
30// class File;
31
32BOOL InitSymInfo( PCSTR );
33BOOL UninitSymInfo();
34void StackTrace(HANDLE, char const* msg, FILE *file);
35void StackTrace(HANDLE, char const* msg, FILE *file, DWORD eip, DWORD esp, DWORD ebp);
36
37// functions by Masken
38void etfprintf(FILE *file, const char *format, ...);
39void etfprint(FILE *file, const std::string &text);
40#define UEFBUFSIZE 2048
41extern char g_uefbuf[UEFBUFSIZE];
42
43#else // not WIN32
44
45#define EXTENDEDTRACEINITIALIZE( IniSymbolPath ) ((void)0)
46#define EXTENDEDTRACEUNINITIALIZE() ((void)0)
47#define STACKTRACE(file) ((void)0)
48#define STACKTRACE2(file, eip, esp, ebp) ((void)0)
49
50#endif // WIN32
diff --git a/src/common/file_search.cpp b/src/common/file_search.cpp
deleted file mode 100644
index b3a0a84fb..000000000
--- a/src/common/file_search.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
1// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5
6#include "common/common.h"
7
8#ifndef _WIN32
9#include <dirent.h>
10#else
11#include <windows.h>
12#endif
13
14#include <algorithm>
15
16#include "common/file_search.h"
17#include "common/string_util.h"
18
19
20CFileSearch::CFileSearch(const CFileSearch::XStringVector& _rSearchStrings, const CFileSearch::XStringVector& _rDirectories)
21{
22 // Reverse the loop order for speed?
23 for (size_t j = 0; j < _rSearchStrings.size(); j++)
24 {
25 for (size_t i = 0; i < _rDirectories.size(); i++)
26 {
27 FindFiles(_rSearchStrings[j], _rDirectories[i]);
28 }
29 }
30}
31
32
33void CFileSearch::FindFiles(const std::string& _searchString, const std::string& _strPath)
34{
35 std::string GCMSearchPath;
36 Common::BuildCompleteFilename(GCMSearchPath, _strPath, _searchString);
37#ifdef _WIN32
38 WIN32_FIND_DATA findData;
39 HANDLE FindFirst = FindFirstFile(Common::UTF8ToTStr(GCMSearchPath).c_str(), &findData);
40
41 if (FindFirst != INVALID_HANDLE_VALUE)
42 {
43 bool bkeepLooping = true;
44
45 while (bkeepLooping)
46 {
47 if (findData.cFileName[0] != '.')
48 {
49 std::string strFilename;
50 Common::BuildCompleteFilename(strFilename, _strPath, Common::TStrToUTF8(findData.cFileName));
51 m_FileNames.push_back(strFilename);
52 }
53
54 bkeepLooping = FindNextFile(FindFirst, &findData) ? true : false;
55 }
56 }
57 FindClose(FindFirst);
58
59
60#else
61 // TODO: super lame/broken
62
63 auto end_match(_searchString);
64
65 // assuming we have a "*.blah"-like pattern
66 if (!end_match.empty() && end_match[0] == '*')
67 end_match.erase(0, 1);
68
69 // ugly
70 if (end_match == ".*")
71 end_match.clear();
72
73 DIR* dir = opendir(_strPath.c_str());
74
75 if (!dir)
76 return;
77
78 while (auto const dp = readdir(dir))
79 {
80 std::string found(dp->d_name);
81
82 if ((found != ".") && (found != "..")
83 && (found.size() >= end_match.size())
84 && std::equal(end_match.rbegin(), end_match.rend(), found.rbegin()))
85 {
86 std::string full_name;
87 if (_strPath.c_str()[_strPath.size()-1] == DIR_SEP_CHR)
88 full_name = _strPath + found;
89 else
90 full_name = _strPath + DIR_SEP + found;
91
92 m_FileNames.push_back(full_name);
93 }
94 }
95
96 closedir(dir);
97#endif
98}
99
100const CFileSearch::XStringVector& CFileSearch::GetFileNames() const
101{
102 return m_FileNames;
103}
diff --git a/src/common/file_search.h b/src/common/file_search.h
deleted file mode 100644
index 55ca02638..000000000
--- a/src/common/file_search.h
+++ /dev/null
@@ -1,23 +0,0 @@
1// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <string>
8#include <vector>
9
10class CFileSearch
11{
12public:
13 typedef std::vector<std::string>XStringVector;
14
15 CFileSearch(const XStringVector& _rSearchStrings, const XStringVector& _rDirectories);
16 const XStringVector& GetFileNames() const;
17
18private:
19
20 void FindFiles(const std::string& _searchString, const std::string& _strPath);
21
22 XStringVector m_FileNames;
23};
diff --git a/src/common/hash.cpp b/src/common/hash.cpp
index fe2c9e636..0624dab8d 100644
--- a/src/common/hash.cpp
+++ b/src/common/hash.cpp
@@ -2,6 +2,7 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <algorithm>
5 6
6#include "common/hash.h" 7#include "common/hash.h"
7#if _M_SSE >= 0x402 8#if _M_SSE >= 0x402
@@ -155,7 +156,7 @@ u64 GetMurmurHash3(const u8 *src, int len, u32 samples)
155 const u8 * data = (const u8*)src; 156 const u8 * data = (const u8*)src;
156 const int nblocks = len / 16; 157 const int nblocks = len / 16;
157 u32 Step = (len / 8); 158 u32 Step = (len / 8);
158 if(samples == 0) samples = max(Step, 1u); 159 if(samples == 0) samples = std::max(Step, 1u);
159 Step = Step / samples; 160 Step = Step / samples;
160 if(Step < 1) Step = 1; 161 if(Step < 1) Step = 1;
161 162
@@ -233,7 +234,7 @@ u64 GetCRC32(const u8 *src, int len, u32 samples)
233 u32 Step = (len / 8); 234 u32 Step = (len / 8);
234 const u64 *data = (const u64 *)src; 235 const u64 *data = (const u64 *)src;
235 const u64 *end = data + Step; 236 const u64 *end = data + Step;
236 if(samples == 0) samples = max(Step, 1u); 237 if(samples == 0) samples = std::max(Step, 1u);
237 Step = Step / samples; 238 Step = Step / samples;
238 if(Step < 1) Step = 1; 239 if(Step < 1) Step = 1;
239 while(data < end) 240 while(data < end)
@@ -265,7 +266,7 @@ u64 GetHashHiresTexture(const u8 *src, int len, u32 samples)
265 u32 Step = (len / 8); 266 u32 Step = (len / 8);
266 const u64 *data = (const u64 *)src; 267 const u64 *data = (const u64 *)src;
267 const u64 *end = data + Step; 268 const u64 *end = data + Step;
268 if(samples == 0) samples = max(Step, 1u); 269 if(samples == 0) samples = std::max(Step, 1u);
269 Step = Step / samples; 270 Step = Step / samples;
270 if(Step < 1) Step = 1; 271 if(Step < 1) Step = 1;
271 while(data < end) 272 while(data < end)
@@ -308,7 +309,7 @@ u64 GetCRC32(const u8 *src, int len, u32 samples)
308 u32 Step = (len/4); 309 u32 Step = (len/4);
309 const u32 *data = (const u32 *)src; 310 const u32 *data = (const u32 *)src;
310 const u32 *end = data + Step; 311 const u32 *end = data + Step;
311 if(samples == 0) samples = max(Step, 1u); 312 if(samples == 0) samples = std::max(Step, 1u);
312 Step = Step / samples; 313 Step = Step / samples;
313 if(Step < 1) Step = 1; 314 if(Step < 1) Step = 1;
314 while(data < end) 315 while(data < end)
@@ -380,7 +381,7 @@ u64 GetMurmurHash3(const u8* src, int len, u32 samples)
380 u32 out[2]; 381 u32 out[2];
381 const int nblocks = len / 8; 382 const int nblocks = len / 8;
382 u32 Step = (len / 4); 383 u32 Step = (len / 4);
383 if(samples == 0) samples = max(Step, 1u); 384 if(samples == 0) samples = std::max(Step, 1u);
384 Step = Step / samples; 385 Step = Step / samples;
385 if(Step < 1) Step = 1; 386 if(Step < 1) Step = 1;
386 387
@@ -456,7 +457,7 @@ u64 GetHashHiresTexture(const u8 *src, int len, u32 samples)
456 u32 Step = (len / 8); 457 u32 Step = (len / 8);
457 const u64 *data = (const u64 *)src; 458 const u64 *data = (const u64 *)src;
458 const u64 *end = data + Step; 459 const u64 *end = data + Step;
459 if(samples == 0) samples = max(Step, 1u); 460 if(samples == 0) samples = std::max(Step, 1u);
460 Step = Step / samples; 461 Step = Step / samples;
461 if(Step < 1) Step = 1; 462 if(Step < 1) Step = 1;
462 while(data < end) 463 while(data < end)
diff --git a/src/common/mem_arena.cpp b/src/common/mem_arena.cpp
index a20361d6f..cc31a88cc 100644
--- a/src/common/mem_arena.cpp
+++ b/src/common/mem_arena.cpp
@@ -218,7 +218,7 @@ u8* MemArena::Find4GBBase()
218 void* base = mmap(0, 0x10000000, PROT_READ | PROT_WRITE, 218 void* base = mmap(0, 0x10000000, PROT_READ | PROT_WRITE,
219 MAP_ANON | MAP_SHARED, -1, 0); 219 MAP_ANON | MAP_SHARED, -1, 0);
220 if (base == MAP_FAILED) { 220 if (base == MAP_FAILED) {
221 PanicAlert("Failed to map 256 MB of memory space: %s", strerror(errno)); 221 LOG_ERROR(Common_Memory, "Failed to map 256 MB of memory space: %s", strerror(errno));
222 return 0; 222 return 0;
223 } 223 }
224 munmap(base, 0x10000000); 224 munmap(base, 0x10000000);
@@ -338,7 +338,7 @@ u8 *MemoryMap_Setup(const MemoryView *views, int num_views, u32 flags, MemArena
338 // address space. 338 // address space.
339 if (!Memory_TryBase(base, views, num_views, flags, arena)) 339 if (!Memory_TryBase(base, views, num_views, flags, arena))
340 { 340 {
341 PanicAlert("MemoryMap_Setup: Failed finding a memory base."); 341 LOG_ERROR(Common_Memory, "MemoryMap_Setup: Failed finding a memory base.");
342 return 0; 342 return 0;
343 } 343 }
344#elif defined(_WIN32) 344#elif defined(_WIN32)
@@ -363,12 +363,11 @@ u8 *MemoryMap_Setup(const MemoryView *views, int num_views, u32 flags, MemArena
363 if (!Memory_TryBase(base, views, num_views, flags, arena)) 363 if (!Memory_TryBase(base, views, num_views, flags, arena))
364 { 364 {
365 LOG_ERROR(Common_Memory, "MemoryMap_Setup: Failed finding a memory base."); 365 LOG_ERROR(Common_Memory, "MemoryMap_Setup: Failed finding a memory base.");
366 PanicAlert("MemoryMap_Setup: Failed finding a memory base.");
367 return 0; 366 return 0;
368 } 367 }
369#endif 368#endif
370 if (base_attempts) 369 if (base_attempts)
371 PanicAlert("No possible memory base pointer found!"); 370 LOG_ERROR(Common_Memory, "No possible memory base pointer found!");
372 return base; 371 return base;
373} 372}
374 373
diff --git a/src/common/memory_util.cpp b/src/common/memory_util.cpp
index 8f982da89..7e69d31cb 100644
--- a/src/common/memory_util.cpp
+++ b/src/common/memory_util.cpp
@@ -56,7 +56,7 @@ void* AllocateExecutableMemory(size_t size, bool low)
56 { 56 {
57 ptr = nullptr; 57 ptr = nullptr;
58#endif 58#endif
59 PanicAlert("Failed to allocate executable memory"); 59 LOG_ERROR(Common_Memory, "Failed to allocate executable memory");
60 } 60 }
61#if !defined(_WIN32) && defined(__x86_64__) && !defined(MAP_32BIT) 61#if !defined(_WIN32) && defined(__x86_64__) && !defined(MAP_32BIT)
62 else 62 else
@@ -72,7 +72,7 @@ void* AllocateExecutableMemory(size_t size, bool low)
72 72
73#if defined(_M_X64) 73#if defined(_M_X64)
74 if ((u64)ptr >= 0x80000000 && low == true) 74 if ((u64)ptr >= 0x80000000 && low == true)
75 PanicAlert("Executable memory ended up above 2GB!"); 75 LOG_ERROR(Common_Memory, "Executable memory ended up above 2GB!");
76#endif 76#endif
77 77
78 return ptr; 78 return ptr;
@@ -94,7 +94,7 @@ void* AllocateMemoryPages(size_t size)
94 // (unsigned long)size); 94 // (unsigned long)size);
95 95
96 if (ptr == nullptr) 96 if (ptr == nullptr)
97 PanicAlert("Failed to allocate raw memory"); 97 LOG_ERROR(Common_Memory, "Failed to allocate raw memory");
98 98
99 return ptr; 99 return ptr;
100} 100}
@@ -117,7 +117,7 @@ void* AllocateAlignedMemory(size_t size,size_t alignment)
117 // (unsigned long)size); 117 // (unsigned long)size);
118 118
119 if (ptr == nullptr) 119 if (ptr == nullptr)
120 PanicAlert("Failed to allocate aligned memory"); 120 LOG_ERROR(Common_Memory, "Failed to allocate aligned memory");
121 121
122 return ptr; 122 return ptr;
123} 123}
@@ -129,7 +129,7 @@ void FreeMemoryPages(void* ptr, size_t size)
129#ifdef _WIN32 129#ifdef _WIN32
130 130
131 if (!VirtualFree(ptr, 0, MEM_RELEASE)) 131 if (!VirtualFree(ptr, 0, MEM_RELEASE))
132 PanicAlert("FreeMemoryPages failed!\n%s", GetLastErrorMsg()); 132 LOG_ERROR(Common_Memory, "FreeMemoryPages failed!\n%s", GetLastErrorMsg());
133 ptr = nullptr; // Is this our responsibility? 133 ptr = nullptr; // Is this our responsibility?
134 134
135#else 135#else
@@ -155,7 +155,7 @@ void WriteProtectMemory(void* ptr, size_t size, bool allowExecute)
155#ifdef _WIN32 155#ifdef _WIN32
156 DWORD oldValue; 156 DWORD oldValue;
157 if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READ : PAGE_READONLY, &oldValue)) 157 if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READ : PAGE_READONLY, &oldValue))
158 PanicAlert("WriteProtectMemory failed!\n%s", GetLastErrorMsg()); 158 LOG_ERROR(Common_Memory, "WriteProtectMemory failed!\n%s", GetLastErrorMsg());
159#else 159#else
160 mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_EXEC) : PROT_READ); 160 mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_EXEC) : PROT_READ);
161#endif 161#endif
@@ -166,7 +166,7 @@ void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute)
166#ifdef _WIN32 166#ifdef _WIN32
167 DWORD oldValue; 167 DWORD oldValue;
168 if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE, &oldValue)) 168 if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE, &oldValue))
169 PanicAlert("UnWriteProtectMemory failed!\n%s", GetLastErrorMsg()); 169 LOG_ERROR(Common_Memory, "UnWriteProtectMemory failed!\n%s", GetLastErrorMsg());
170#else 170#else
171 mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_WRITE | PROT_EXEC) : PROT_WRITE | PROT_READ); 171 mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_WRITE | PROT_EXEC) : PROT_WRITE | PROT_READ);
172#endif 172#endif
diff --git a/src/common/msg_handler.cpp b/src/common/msg_handler.cpp
deleted file mode 100644
index 4a47b518e..000000000
--- a/src/common/msg_handler.cpp
+++ /dev/null
@@ -1,107 +0,0 @@
1// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <cstdio>
6
7#include "common/common.h" // Local
8#include "common/string_util.h"
9
10bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, int Style);
11static MsgAlertHandler msg_handler = DefaultMsgHandler;
12static bool AlertEnabled = true;
13
14std::string DefaultStringTranslator(const char* text);
15static StringTranslator str_translator = DefaultStringTranslator;
16
17// Select which of these functions that are used for message boxes. If
18// wxWidgets is enabled we will use wxMsgAlert() that is defined in Main.cpp
19void RegisterMsgAlertHandler(MsgAlertHandler handler)
20{
21 msg_handler = handler;
22}
23
24// Select translation function. For wxWidgets use wxStringTranslator in Main.cpp
25void RegisterStringTranslator(StringTranslator translator)
26{
27 str_translator = translator;
28}
29
30// enable/disable the alert handler
31void SetEnableAlert(bool enable)
32{
33 AlertEnabled = enable;
34}
35
36// This is the first stop for gui alerts where the log is updated and the
37// correct window is shown
38bool MsgAlert(bool yes_no, int Style, const char* format, ...)
39{
40 // Read message and write it to the log
41 std::string caption;
42 char buffer[2048];
43
44 static std::string info_caption;
45 static std::string warn_caption;
46 static std::string ques_caption;
47 static std::string crit_caption;
48
49 if (!info_caption.length())
50 {
51 info_caption = str_translator(_trans("Information"));
52 ques_caption = str_translator(_trans("Question"));
53 warn_caption = str_translator(_trans("Warning"));
54 crit_caption = str_translator(_trans("Critical"));
55 }
56
57 switch(Style)
58 {
59 case INFORMATION:
60 caption = info_caption;
61 break;
62 case QUESTION:
63 caption = ques_caption;
64 break;
65 case WARNING:
66 caption = warn_caption;
67 break;
68 case CRITICAL:
69 caption = crit_caption;
70 break;
71 }
72
73 va_list args;
74 va_start(args, format);
75 Common::CharArrayFromFormatV(buffer, sizeof(buffer)-1, str_translator(format).c_str(), args);
76 va_end(args);
77
78 LOG_INFO(Common, "%s: %s", caption.c_str(), buffer);
79
80 // Don't ignore questions, especially AskYesNo, PanicYesNo could be ignored
81 if (msg_handler && (AlertEnabled || Style == QUESTION || Style == CRITICAL))
82 return msg_handler(caption.c_str(), buffer, yes_no, Style);
83
84 return true;
85}
86
87// Default non library dependent panic alert
88bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, int Style)
89{
90//#ifdef _WIN32
91// int STYLE = MB_ICONINFORMATION;
92// if (Style == QUESTION) STYLE = MB_ICONQUESTION;
93// if (Style == WARNING) STYLE = MB_ICONWARNING;
94//
95// return IDYES == MessageBox(0, UTF8ToTStr(text).c_str(), UTF8ToTStr(caption).c_str(), STYLE | (yes_no ? MB_YESNO : MB_OK));
96//#else
97 printf("%s\n", text);
98 return true;
99//#endif
100}
101
102// Default (non) translator
103std::string DefaultStringTranslator(const char* text)
104{
105 return text;
106}
107
diff --git a/src/common/msg_handler.h b/src/common/msg_handler.h
deleted file mode 100644
index 421f93e23..000000000
--- a/src/common/msg_handler.h
+++ /dev/null
@@ -1,56 +0,0 @@
1// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <string>
8
9// Message alerts
10enum MSG_TYPE
11{
12 INFORMATION,
13 QUESTION,
14 WARNING,
15 CRITICAL
16};
17
18typedef bool (*MsgAlertHandler)(const char* caption, const char* text,
19 bool yes_no, int Style);
20typedef std::string (*StringTranslator)(const char* text);
21
22void RegisterMsgAlertHandler(MsgAlertHandler handler);
23void RegisterStringTranslator(StringTranslator translator);
24
25extern bool MsgAlert(bool yes_no, int Style, const char* format, ...)
26#ifdef __GNUC__
27 __attribute__((format(printf, 3, 4)))
28#endif
29 ;
30void SetEnableAlert(bool enable);
31
32#ifdef _MSC_VER
33 #define SuccessAlert(format, ...) MsgAlert(false, INFORMATION, format, __VA_ARGS__)
34 #define PanicAlert(format, ...) MsgAlert(false, WARNING, format, __VA_ARGS__)
35 #define PanicYesNo(format, ...) MsgAlert(true, WARNING, format, __VA_ARGS__)
36 #define AskYesNo(format, ...) MsgAlert(true, QUESTION, format, __VA_ARGS__)
37 #define CriticalAlert(format, ...) MsgAlert(false, CRITICAL, format, __VA_ARGS__)
38 // Use these macros (that do the same thing) if the message should be translated.
39 #define SuccessAlertT(format, ...) MsgAlert(false, INFORMATION, format, __VA_ARGS__)
40 #define PanicAlertT(format, ...) MsgAlert(false, WARNING, format, __VA_ARGS__)
41 #define PanicYesNoT(format, ...) MsgAlert(true, WARNING, format, __VA_ARGS__)
42 #define AskYesNoT(format, ...) MsgAlert(true, QUESTION, format, __VA_ARGS__)
43 #define CriticalAlertT(format, ...) MsgAlert(false, CRITICAL, format, __VA_ARGS__)
44#else
45 #define SuccessAlert(format, ...) MsgAlert(false, INFORMATION, format, ##__VA_ARGS__)
46 #define PanicAlert(format, ...) MsgAlert(false, WARNING, format, ##__VA_ARGS__)
47 #define PanicYesNo(format, ...) MsgAlert(true, WARNING, format, ##__VA_ARGS__)
48 #define AskYesNo(format, ...) MsgAlert(true, QUESTION, format, ##__VA_ARGS__)
49 #define CriticalAlert(format, ...) MsgAlert(false, CRITICAL, format, ##__VA_ARGS__)
50 // Use these macros (that do the same thing) if the message should be translated.
51 #define SuccessAlertT(format, ...) MsgAlert(false, INFORMATION, format, ##__VA_ARGS__)
52 #define PanicAlertT(format, ...) MsgAlert(false, WARNING, format, ##__VA_ARGS__)
53 #define PanicYesNoT(format, ...) MsgAlert(true, WARNING, format, ##__VA_ARGS__)
54 #define AskYesNoT(format, ...) MsgAlert(true, QUESTION, format, ##__VA_ARGS__)
55 #define CriticalAlertT(format, ...) MsgAlert(false, CRITICAL, format, ##__VA_ARGS__)
56#endif
diff --git a/src/common/utf8.cpp b/src/common/utf8.cpp
deleted file mode 100644
index 56609634c..000000000
--- a/src/common/utf8.cpp
+++ /dev/null
@@ -1,459 +0,0 @@
1/*
2 Basic UTF-8 manipulation routines
3 by Jeff Bezanson
4 placed in the public domain Fall 2005
5
6 This code is designed to provide the utilities you need to manipulate
7 UTF-8 as an internal string encoding. These functions do not perform the
8 error checking normally needed when handling UTF-8 data, so if you happen
9 to be from the Unicode Consortium you will want to flay me alive.
10 I do this because error checking can be performed at the boundaries (I/O),
11 with these routines reserved for higher performance on data known to be
12 valid.
13*/
14
15#ifdef _WIN32
16#include <windows.h>
17#undef min
18#undef max
19#endif
20
21#include <cstdlib>
22#include <cstring>
23#include <algorithm>
24
25#include "common/common_types.h"
26#include "common/utf8.h"
27
28// is start of UTF sequence
29inline bool isutf(char c) {
30 return (c & 0xC0) != 0x80;
31}
32
33static const u32 offsetsFromUTF8[6] = {
34 0x00000000UL, 0x00003080UL, 0x000E2080UL,
35 0x03C82080UL, 0xFA082080UL, 0x82082080UL
36};
37
38static const u8 trailingBytesForUTF8[256] = {
39 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
40 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
41 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
42 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
43 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
44 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
45 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
46 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5,
47};
48
49/* returns length of next utf-8 sequence */
50int u8_seqlen(const char *s)
51{
52 return trailingBytesForUTF8[(unsigned int)(unsigned char)s[0]] + 1;
53}
54
55/* conversions without error checking
56 only works for valid UTF-8, i.e. no 5- or 6-byte sequences
57 srcsz = source size in bytes, or -1 if 0-terminated
58 sz = dest size in # of wide characters
59
60 returns # characters converted
61 dest will always be L'\0'-terminated, even if there isn't enough room
62 for all the characters.
63 if sz = srcsz+1 (i.e. 4*srcsz+4 bytes), there will always be enough space.
64*/
65int u8_toucs(u32 *dest, int sz, const char *src, int srcsz)
66{
67 u32 ch;
68 const char *src_end = src + srcsz;
69 int nb;
70 int i=0;
71
72 while (i < sz-1) {
73 nb = trailingBytesForUTF8[(unsigned char)*src];
74 if (srcsz == -1) {
75 if (*src == 0)
76 goto done_toucs;
77 }
78 else {
79 if (src + nb >= src_end)
80 goto done_toucs;
81 }
82 ch = 0;
83 switch (nb) {
84 /* these fall through deliberately */
85 case 3: ch += (unsigned char)*src++; ch <<= 6;
86 case 2: ch += (unsigned char)*src++; ch <<= 6;
87 case 1: ch += (unsigned char)*src++; ch <<= 6;
88 case 0: ch += (unsigned char)*src++;
89 }
90 ch -= offsetsFromUTF8[nb];
91 dest[i++] = ch;
92 }
93 done_toucs:
94 dest[i] = 0;
95 return i;
96}
97
98/* srcsz = number of source characters, or -1 if 0-terminated
99 sz = size of dest buffer in bytes
100
101 returns # characters converted
102 dest will only be '\0'-terminated if there is enough space. this is
103 for consistency; imagine there are 2 bytes of space left, but the next
104 character requires 3 bytes. in this case we could NUL-terminate, but in
105 general we can't when there's insufficient space. therefore this function
106 only NUL-terminates if all the characters fit, and there's space for
107 the NUL as well.
108 the destination string will never be bigger than the source string.
109*/
110int u8_toutf8(char *dest, int sz, u32 *src, int srcsz)
111{
112 u32 ch;
113 int i = 0;
114 char *dest_end = dest + sz;
115
116 while (srcsz<0 ? src[i]!=0 : i < srcsz) {
117 ch = src[i];
118 if (ch < 0x80) {
119 if (dest >= dest_end)
120 return i;
121 *dest++ = (char)ch;
122 }
123 else if (ch < 0x800) {
124 if (dest >= dest_end-1)
125 return i;
126 *dest++ = (ch>>6) | 0xC0;
127 *dest++ = (ch & 0x3F) | 0x80;
128 }
129 else if (ch < 0x10000) {
130 if (dest >= dest_end-2)
131 return i;
132 *dest++ = (ch>>12) | 0xE0;
133 *dest++ = ((ch>>6) & 0x3F) | 0x80;
134 *dest++ = (ch & 0x3F) | 0x80;
135 }
136 else if (ch < 0x110000) {
137 if (dest >= dest_end-3)
138 return i;
139 *dest++ = (ch>>18) | 0xF0;
140 *dest++ = ((ch>>12) & 0x3F) | 0x80;
141 *dest++ = ((ch>>6) & 0x3F) | 0x80;
142 *dest++ = (ch & 0x3F) | 0x80;
143 }
144 i++;
145 }
146 if (dest < dest_end)
147 *dest = '\0';
148 return i;
149}
150
151int u8_wc_toutf8(char *dest, u32 ch)
152{
153 if (ch < 0x80) {
154 dest[0] = (char)ch;
155 return 1;
156 }
157 if (ch < 0x800) {
158 dest[0] = (ch>>6) | 0xC0;
159 dest[1] = (ch & 0x3F) | 0x80;
160 return 2;
161 }
162 if (ch < 0x10000) {
163 dest[0] = (ch>>12) | 0xE0;
164 dest[1] = ((ch>>6) & 0x3F) | 0x80;
165 dest[2] = (ch & 0x3F) | 0x80;
166 return 3;
167 }
168 if (ch < 0x110000) {
169 dest[0] = (ch>>18) | 0xF0;
170 dest[1] = ((ch>>12) & 0x3F) | 0x80;
171 dest[2] = ((ch>>6) & 0x3F) | 0x80;
172 dest[3] = (ch & 0x3F) | 0x80;
173 return 4;
174 }
175 return 0;
176}
177
178/* charnum => byte offset */
179int u8_offset(const char *str, int charnum)
180{
181 int offs=0;
182
183 while (charnum > 0 && str[offs]) {
184 (void)(isutf(str[++offs]) || isutf(str[++offs]) ||
185 isutf(str[++offs]) || ++offs);
186 charnum--;
187 }
188 return offs;
189}
190
191/* byte offset => charnum */
192int u8_charnum(const char *s, int offset)
193{
194 int charnum = 0, offs=0;
195
196 while (offs < offset && s[offs]) {
197 (void)(isutf(s[++offs]) || isutf(s[++offs]) ||
198 isutf(s[++offs]) || ++offs);
199 charnum++;
200 }
201 return charnum;
202}
203
204/* number of characters */
205int u8_strlen(const char *s)
206{
207 int count = 0;
208 int i = 0;
209
210 while (u8_nextchar(s, &i) != 0)
211 count++;
212
213 return count;
214}
215
216/* reads the next utf-8 sequence out of a string, updating an index */
217u32 u8_nextchar(const char *s, int *i)
218{
219 u32 ch = 0;
220 int sz = 0;
221
222 do {
223 ch <<= 6;
224 ch += (unsigned char)s[(*i)++];
225 sz++;
226 } while (s[*i] && !isutf(s[*i]));
227 ch -= offsetsFromUTF8[sz-1];
228
229 return ch;
230}
231
232void u8_inc(const char *s, int *i)
233{
234 (void)(isutf(s[++(*i)]) || isutf(s[++(*i)]) ||
235 isutf(s[++(*i)]) || ++(*i));
236}
237
238void u8_dec(const char *s, int *i)
239{
240 (void)(isutf(s[--(*i)]) || isutf(s[--(*i)]) ||
241 isutf(s[--(*i)]) || --(*i));
242}
243
244int octal_digit(char c)
245{
246 return (c >= '0' && c <= '7');
247}
248
249int hex_digit(char c)
250{
251 return ((c >= '0' && c <= '9') ||
252 (c >= 'A' && c <= 'F') ||
253 (c >= 'a' && c <= 'f'));
254}
255
256/* assumes that src points to the character after a backslash
257 returns number of input characters processed */
258int u8_read_escape_sequence(const char *str, u32 *dest)
259{
260 u32 ch;
261 char digs[9]="\0\0\0\0\0\0\0\0";
262 int dno=0, i=1;
263
264 ch = (u32)str[0]; /* take literal character */
265 if (str[0] == 'n')
266 ch = L'\n';
267 else if (str[0] == 't')
268 ch = L'\t';
269 else if (str[0] == 'r')
270 ch = L'\r';
271 else if (str[0] == 'b')
272 ch = L'\b';
273 else if (str[0] == 'f')
274 ch = L'\f';
275 else if (str[0] == 'v')
276 ch = L'\v';
277 else if (str[0] == 'a')
278 ch = L'\a';
279 else if (octal_digit(str[0])) {
280 i = 0;
281 do {
282 digs[dno++] = str[i++];
283 } while (octal_digit(str[i]) && dno < 3);
284 ch = strtol(digs, nullptr, 8);
285 }
286 else if (str[0] == 'x') {
287 while (hex_digit(str[i]) && dno < 2) {
288 digs[dno++] = str[i++];
289 }
290 if (dno > 0)
291 ch = strtol(digs, nullptr, 16);
292 }
293 else if (str[0] == 'u') {
294 while (hex_digit(str[i]) && dno < 4) {
295 digs[dno++] = str[i++];
296 }
297 if (dno > 0)
298 ch = strtol(digs, nullptr, 16);
299 }
300 else if (str[0] == 'U') {
301 while (hex_digit(str[i]) && dno < 8) {
302 digs[dno++] = str[i++];
303 }
304 if (dno > 0)
305 ch = strtol(digs, nullptr, 16);
306 }
307 *dest = ch;
308
309 return i;
310}
311
312/* convert a string with literal \uxxxx or \Uxxxxxxxx characters to UTF-8
313 example: u8_unescape(mybuf, 256, "hello\\u220e")
314 note the double backslash is needed if called on a C string literal */
315int u8_unescape(char *buf, int sz, char *src)
316{
317 int c=0, amt;
318 u32 ch;
319 char temp[4];
320
321 while (*src && c < sz) {
322 if (*src == '\\') {
323 src++;
324 amt = u8_read_escape_sequence(src, &ch);
325 }
326 else {
327 ch = (u32)*src;
328 amt = 1;
329 }
330 src += amt;
331 amt = u8_wc_toutf8(temp, ch);
332 if (amt > sz-c)
333 break;
334 memcpy(&buf[c], temp, amt);
335 c += amt;
336 }
337 if (c < sz)
338 buf[c] = '\0';
339 return c;
340}
341
342const char *u8_strchr(const char *s, u32 ch, int *charn)
343{
344 int i = 0, lasti=0;
345 u32 c;
346
347 *charn = 0;
348 while (s[i]) {
349 c = u8_nextchar(s, &i);
350 if (c == ch) {
351 return &s[lasti];
352 }
353 lasti = i;
354 (*charn)++;
355 }
356 return nullptr;
357}
358
359const char *u8_memchr(const char *s, u32 ch, size_t sz, int *charn)
360{
361 u32 i = 0, lasti=0;
362 u32 c;
363 int csz;
364
365 *charn = 0;
366 while (i < sz) {
367 c = csz = 0;
368 do {
369 c <<= 6;
370 c += (unsigned char)s[i++];
371 csz++;
372 } while (i < sz && !isutf(s[i]));
373 c -= offsetsFromUTF8[csz-1];
374
375 if (c == ch) {
376 return &s[lasti];
377 }
378 lasti = i;
379 (*charn)++;
380 }
381 return nullptr;
382}
383
384int u8_is_locale_utf8(const char *locale)
385{
386 /* this code based on libutf8 */
387 const char* cp = locale;
388
389 for (; *cp != '\0' && *cp != '@' && *cp != '+' && *cp != ','; cp++) {
390 if (*cp == '.') {
391 const char* encoding = ++cp;
392 for (; *cp != '\0' && *cp != '@' && *cp != '+' && *cp != ','; cp++)
393 ;
394 if ((cp-encoding == 5 && !strncmp(encoding, "UTF-8", 5))
395 || (cp-encoding == 4 && !strncmp(encoding, "utf8", 4)))
396 return 1; /* it's UTF-8 */
397 break;
398 }
399 }
400 return 0;
401}
402
403int UTF8StringNonASCIICount(const char *utf8string) {
404 UTF8 utf(utf8string);
405 int count = 0;
406 while (!utf.end()) {
407 int c = utf.next();
408 if (c > 127)
409 ++count;
410 }
411 return count;
412}
413
414bool UTF8StringHasNonASCII(const char *utf8string) {
415 return UTF8StringNonASCIICount(utf8string) > 0;
416}
417
418#ifdef _WIN32
419
420std::string ConvertWStringToUTF8(const wchar_t *wstr) {
421 int len = (int)wcslen(wstr);
422 int size = (int)WideCharToMultiByte(CP_UTF8, 0, wstr, len, 0, 0, nullptr, nullptr);
423 std::string s;
424 s.resize(size);
425 if (size > 0) {
426 WideCharToMultiByte(CP_UTF8, 0, wstr, len, &s[0], size, nullptr, nullptr);
427 }
428 return s;
429}
430
431std::string ConvertWStringToUTF8(const std::wstring &wstr) {
432 int len = (int)wstr.size();
433 int size = (int)WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), len, 0, 0, nullptr, nullptr);
434 std::string s;
435 s.resize(size);
436 if (size > 0) {
437 WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), len, &s[0], size, nullptr, nullptr);
438 }
439 return s;
440}
441
442void ConvertUTF8ToWString(wchar_t *dest, size_t destSize, const std::string &source) {
443 int len = (int)source.size();
444 int size = (int)MultiByteToWideChar(CP_UTF8, 0, source.c_str(), len, nullptr, 0);
445 MultiByteToWideChar(CP_UTF8, 0, source.c_str(), len, dest, std::min((int)destSize, size));
446}
447
448std::wstring ConvertUTF8ToWString(const std::string &source) {
449 int len = (int)source.size();
450 int size = (int)MultiByteToWideChar(CP_UTF8, 0, source.c_str(), len, nullptr, 0);
451 std::wstring str;
452 str.resize(size);
453 if (size > 0) {
454 MultiByteToWideChar(CP_UTF8, 0, source.c_str(), len, &str[0], size);
455 }
456 return str;
457}
458
459#endif
diff --git a/src/common/utf8.h b/src/common/utf8.h
deleted file mode 100644
index a6e84913b..000000000
--- a/src/common/utf8.h
+++ /dev/null
@@ -1,67 +0,0 @@
1/*
2 Basic UTF-8 manipulation routines
3 by Jeff Bezanson
4 placed in the public domain Fall 2005
5
6 This code is designed to provide the utilities you need to manipulate
7 UTF-8 as an internal string encoding. These functions do not perform the
8 error checking normally needed when handling UTF-8 data, so if you happen
9 to be from the Unicode Consortium you will want to flay me alive.
10 I do this because error checking can be performed at the boundaries (I/O),
11 with these routines reserved for higher performance on data known to be
12 valid.
13*/
14
15// Further modified, and C++ stuff added, by hrydgard@gmail.com.
16
17#pragma once
18
19#include "common/common_types.h"
20#include <string>
21
22u32 u8_nextchar(const char *s, int *i);
23int u8_wc_toutf8(char *dest, u32 ch);
24int u8_strlen(const char *s);
25
26class UTF8 {
27public:
28 static const u32 INVALID = (u32)-1;
29 UTF8(const char *c) : c_(c), index_(0) {}
30 bool end() const { return c_[index_] == 0; }
31 u32 next() {
32 return u8_nextchar(c_, &index_);
33 }
34 u32 peek() {
35 int tempIndex = index_;
36 return u8_nextchar(c_, &tempIndex);
37 }
38 int length() const {
39 return u8_strlen(c_);
40 }
41 int byteIndex() const {
42 return index_;
43 }
44 static int encode(char *dest, u32 ch) {
45 return u8_wc_toutf8(dest, ch);
46 }
47
48private:
49 const char *c_;
50 int index_;
51};
52
53int UTF8StringNonASCIICount(const char *utf8string);
54
55bool UTF8StringHasNonASCII(const char *utf8string);
56
57
58// UTF8 to Win32 UTF-16
59// Should be used when calling Win32 api calls
60#ifdef _WIN32
61
62std::string ConvertWStringToUTF8(const std::wstring &wstr);
63std::string ConvertWStringToUTF8(const wchar_t *wstr);
64void ConvertUTF8ToWString(wchar_t *dest, size_t destSize, const std::string &source);
65std::wstring ConvertUTF8ToWString(const std::string &source);
66
67#endif
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp
index cabe2a074..6f716b1ca 100644
--- a/src/core/core_timing.cpp
+++ b/src/core/core_timing.cpp
@@ -147,7 +147,7 @@ void RestoreRegisterEvent(int event_type, const char* name, TimedCallback callba
147 147
148void UnregisterAllEvents() { 148void UnregisterAllEvents() {
149 if (first) 149 if (first)
150 PanicAlert("Cannot unregister events with events pending"); 150 LOG_ERROR(Core_Timing, "Cannot unregister events with events pending");
151 event_types.clear(); 151 event_types.clear();
152} 152}
153 153
@@ -535,7 +535,7 @@ std::string GetScheduledEventsSummary() {
535 while (event) { 535 while (event) {
536 unsigned int t = event->type; 536 unsigned int t = event->type;
537 if (t >= event_types.size()) 537 if (t >= event_types.size())
538 PanicAlert("Invalid event type"); // %i", t); 538 LOG_ERROR(Core_Timing, "Invalid event type"); // %i", t);
539 const char* name = event_types[event->type].name; 539 const char* name = event_types[event->type].name;
540 if (!name) 540 if (!name)
541 name = "[unknown]"; 541 name = "[unknown]";
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index f8c834a8d..be1aed615 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -7,6 +7,7 @@
7#include <vector> 7#include <vector>
8 8
9#include "common/common.h" 9#include "common/common.h"
10#include "common/math_util.h"
10#include "common/thread_queue_list.h" 11#include "common/thread_queue_list.h"
11 12
12#include "core/arm/arm_interface.h" 13#include "core/arm/arm_interface.h"
@@ -339,7 +340,7 @@ static void DebugThreadQueue() {
339ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, s32 priority, 340ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, s32 priority,
340 u32 arg, s32 processor_id, VAddr stack_top) { 341 u32 arg, s32 processor_id, VAddr stack_top) {
341 if (priority < THREADPRIO_HIGHEST || priority > THREADPRIO_LOWEST) { 342 if (priority < THREADPRIO_HIGHEST || priority > THREADPRIO_LOWEST) {
342 s32 new_priority = CLAMP(priority, THREADPRIO_HIGHEST, THREADPRIO_LOWEST); 343 s32 new_priority = MathUtil::Clamp<s32>(priority, THREADPRIO_HIGHEST, THREADPRIO_LOWEST);
343 LOG_WARNING(Kernel_SVC, "(name=%s): invalid priority=%d, clamping to %d", 344 LOG_WARNING(Kernel_SVC, "(name=%s): invalid priority=%d, clamping to %d",
344 name.c_str(), priority, new_priority); 345 name.c_str(), priority, new_priority);
345 // TODO(bunnei): Clamping to a valid priority is not necessarily correct behavior... Confirm 346 // TODO(bunnei): Clamping to a valid priority is not necessarily correct behavior... Confirm
@@ -387,7 +388,7 @@ static void ClampPriority(const Thread* thread, s32* priority) {
387 if (*priority < THREADPRIO_HIGHEST || *priority > THREADPRIO_LOWEST) { 388 if (*priority < THREADPRIO_HIGHEST || *priority > THREADPRIO_LOWEST) {
388 DEBUG_ASSERT_MSG(false, "Application passed an out of range priority. An error should be returned."); 389 DEBUG_ASSERT_MSG(false, "Application passed an out of range priority. An error should be returned.");
389 390
390 s32 new_priority = CLAMP(*priority, THREADPRIO_HIGHEST, THREADPRIO_LOWEST); 391 s32 new_priority = MathUtil::Clamp<s32>(*priority, THREADPRIO_HIGHEST, THREADPRIO_LOWEST);
391 LOG_WARNING(Kernel_SVC, "(name=%s): invalid priority=%d, clamping to %d", 392 LOG_WARNING(Kernel_SVC, "(name=%s): invalid priority=%d, clamping to %d",
392 thread->name.c_str(), *priority, new_priority); 393 thread->name.c_str(), *priority, new_priority);
393 // TODO(bunnei): Clamping to a valid priority is not necessarily correct behavior... Confirm 394 // TODO(bunnei): Clamping to a valid priority is not necessarily correct behavior... Confirm
diff --git a/src/core/hw/gpu.h b/src/core/hw/gpu.h
index df9aa0d71..75f524465 100644
--- a/src/core/hw/gpu.h
+++ b/src/core/hw/gpu.h
@@ -34,13 +34,6 @@ namespace GPU {
34// MMIO region 0x1EFxxxxx 34// MMIO region 0x1EFxxxxx
35struct Regs { 35struct Regs {
36 36
37// helper macro to properly align structure members.
38// Calling INSERT_PADDING_WORDS will add a new member variable with a name like "pad121",
39// depending on the current source line to make sure variable names are unique.
40#define INSERT_PADDING_WORDS_HELPER1(x, y) x ## y
41#define INSERT_PADDING_WORDS_HELPER2(x, y) INSERT_PADDING_WORDS_HELPER1(x, y)
42#define INSERT_PADDING_WORDS(num_words) u32 INSERT_PADDING_WORDS_HELPER2(pad, __LINE__)[(num_words)]
43
44// helper macro to make sure the defined structures are of the expected size. 37// helper macro to make sure the defined structures are of the expected size.
45#if defined(_MSC_VER) 38#if defined(_MSC_VER)
46// TODO: MSVC does not support using sizeof() on non-static data members even though this 39// TODO: MSVC does not support using sizeof() on non-static data members even though this
@@ -238,10 +231,6 @@ struct Regs {
238 231
239 INSERT_PADDING_WORDS(0x9c3); 232 INSERT_PADDING_WORDS(0x9c3);
240 233
241#undef INSERT_PADDING_WORDS_HELPER1
242#undef INSERT_PADDING_WORDS_HELPER2
243#undef INSERT_PADDING_WORDS
244
245 static inline size_t NumIds() { 234 static inline size_t NumIds() {
246 return sizeof(Regs) / sizeof(u32); 235 return sizeof(Regs) / sizeof(u32);
247 } 236 }
diff --git a/src/video_core/pica.h b/src/video_core/pica.h
index e4a5ef78e..d03b811d3 100644
--- a/src/video_core/pica.h
+++ b/src/video_core/pica.h
@@ -39,13 +39,6 @@ namespace Pica {
39 39
40struct Regs { 40struct Regs {
41 41
42// helper macro to properly align structure members.
43// Calling INSERT_PADDING_WORDS will add a new member variable with a name like "pad121",
44// depending on the current source line to make sure variable names are unique.
45#define INSERT_PADDING_WORDS_HELPER1(x, y) x ## y
46#define INSERT_PADDING_WORDS_HELPER2(x, y) INSERT_PADDING_WORDS_HELPER1(x, y)
47#define INSERT_PADDING_WORDS(num_words) u32 INSERT_PADDING_WORDS_HELPER2(pad, __LINE__)[(num_words)];
48
49 INSERT_PADDING_WORDS(0x10); 42 INSERT_PADDING_WORDS(0x10);
50 43
51 u32 trigger_irq; 44 u32 trigger_irq;
@@ -709,10 +702,6 @@ struct Regs {
709 702
710 INSERT_PADDING_WORDS(0x22); 703 INSERT_PADDING_WORDS(0x22);
711 704
712#undef INSERT_PADDING_WORDS_HELPER1
713#undef INSERT_PADDING_WORDS_HELPER2
714#undef INSERT_PADDING_WORDS
715
716 // Map register indices to names readable by humans 705 // Map register indices to names readable by humans
717 // Used for debugging purposes, so performance is not an issue here 706 // Used for debugging purposes, so performance is not an issue here
718 static std::string GetCommandName(int index) { 707 static std::string GetCommandName(int index) {