From 215abfb95168ab902ef583e5fe8ac5f371868f2e Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sat, 6 Sep 2014 10:47:25 +0200 Subject: [PATCH] Some cleanup in /Common --- Common/ArmEmitter.h | 2 ++ Common/ChunkFile.cpp | 2 +- Common/Common.h | 63 ++++------------------------------- Common/Common.vcxproj | 2 +- Common/Common.vcxproj.filters | 2 +- Common/CommonFuncs.h | 12 +++---- Common/Log.h | 2 ++ Common/MsgHandler.h | 29 +--------------- Common/Swap.h | 41 +++++++++++++++++++++++ Common/x64Emitter.cpp | 1 + Qt/Native.pro | 1 + UI/MiscScreens.cpp | 1 - native | 2 +- 13 files changed, 63 insertions(+), 97 deletions(-) diff --git a/Common/ArmEmitter.h b/Common/ArmEmitter.h index eeb46d4fad..d01c408c3a 100644 --- a/Common/ArmEmitter.h +++ b/Common/ArmEmitter.h @@ -24,6 +24,8 @@ #include #include "Common.h" +#include "MsgHandler.h" + // TODO: Check if Pandora still needs signal.h/kill here. Symbian doesn't. // VCVT flags diff --git a/Common/ChunkFile.cpp b/Common/ChunkFile.cpp index bc59525a1e..82ad8dd3ab 100644 --- a/Common/ChunkFile.cpp +++ b/Common/ChunkFile.cpp @@ -150,7 +150,7 @@ void PointerWrap::DoMarker(const char *prevName, u32 arbitraryNumber) { u32 cookie = arbitraryNumber; Do(cookie); if (mode == PointerWrap::MODE_READ && cookie != arbitraryNumber) { - PanicAlertT("Error: After \"%s\", found %d (0x%X) instead of save marker %d (0x%X). Aborting savestate load...", prevName, cookie, cookie, arbitraryNumber, arbitraryNumber); + PanicAlert("Error: After \"%s\", found %d (0x%X) instead of save marker %d (0x%X). Aborting savestate load...", prevName, cookie, cookie, arbitraryNumber, arbitraryNumber); SetError(ERROR_FAILURE); } } diff --git a/Common/Common.h b/Common/Common.h index 9fdf41080f..5bb181534a 100644 --- a/Common/Common.h +++ b/Common/Common.h @@ -59,7 +59,6 @@ private: #include "Log.h" #include "CommonTypes.h" -#include "MsgHandler.h" #include "CommonFuncs.h" #ifdef __APPLE__ @@ -70,7 +69,9 @@ private: #define STACKALIGN __attribute__((__force_align_arg_pointer__)) #endif -#elif defined _WIN32 +#define CHECK_HEAP_INTEGRITY() + +#elif defined(_WIN32) // Check MSC ver #if !defined _MSC_VER || _MSC_VER <= 1000 @@ -93,12 +94,10 @@ private: #include #undef CHECK_HEAP_INTEGRITY #define CHECK_HEAP_INTEGRITY() {if (!_CrtCheckMemory()) PanicAlert("memory corruption detected. see log.");} - // If you want to see how much a pain in the ass singletons are, for example: - // {614} normal block at 0x030C5310, 188 bytes long. - // Data: 4D 61 73 74 65 72 20 4C 6F 67 00 00 00 00 00 00 - struct CrtDebugBreak { CrtDebugBreak(int spot) { _CrtSetBreakAlloc(spot); } }; - //CrtDebugBreak breakAt(614); - #endif // end DEBUG/FAST + #endif +#else + +#define CHECK_HEAP_INTEGRITY() #endif @@ -126,11 +125,9 @@ private: #endif #ifdef _MSC_VER -#define __strdup _strdup #define __getcwd _getcwd #define __chdir _chdir #else -#define __strdup strdup #define __getcwd getcwd #define __chdir chdir #endif @@ -151,52 +148,6 @@ private: # define _M_SSE 0x402 #endif - -#ifdef _MSC_VER -#ifndef _XBOX -inline unsigned long long bswap64(unsigned long long x) { return _byteswap_uint64(x); } -inline unsigned int bswap32(unsigned int x) { return _byteswap_ulong(x); } -inline unsigned short bswap16(unsigned short x) { return _byteswap_ushort(x); } -#else -inline unsigned long long bswap64(unsigned long long x) { return __loaddoublewordbytereverse(0, &x); } -inline unsigned int bswap32(unsigned int x) { return __loadwordbytereverse(0, &x); } -inline unsigned short bswap16(unsigned short x) { return __loadshortbytereverse(0, &x); } -#endif -#else -// TODO: speedup -inline unsigned short bswap16(unsigned short x) { return (x << 8) | (x >> 8); } -inline unsigned int bswap32(unsigned int x) { return (x >> 24) | ((x & 0xFF0000) >> 8) | ((x & 0xFF00) << 8) | (x << 24);} -inline unsigned long long bswap64(unsigned long long x) {return ((unsigned long long)bswap32(x) << 32) | bswap32(x >> 32); } -#endif - -inline float bswapf( float f ) -{ - union - { - float f; - unsigned int u32; - } dat1, dat2; - - dat1.f = f; - dat2.u32 = bswap32(dat1.u32); - - return dat2.f; -} - -inline double bswapd( double f ) -{ - union - { - double f; - unsigned long long u64; - } dat1, dat2; - - dat1.f = f; - dat2.u64 = bswap64(dat1.u64); - - return dat2.f; -} - #include "Swap.h" #endif // _COMMON_H_ diff --git a/Common/Common.vcxproj b/Common/Common.vcxproj index 70c5beb405..6df341d135 100644 --- a/Common/Common.vcxproj +++ b/Common/Common.vcxproj @@ -258,4 +258,4 @@ - + \ No newline at end of file diff --git a/Common/Common.vcxproj.filters b/Common/Common.vcxproj.filters index 57fa17b0bd..7de082ca92 100644 --- a/Common/Common.vcxproj.filters +++ b/Common/Common.vcxproj.filters @@ -76,4 +76,4 @@ {1b593f03-7b28-4707-9228-4981796f5589} - + \ No newline at end of file diff --git a/Common/CommonFuncs.h b/Common/CommonFuncs.h index 1214d5be89..d9f9d219e5 100644 --- a/Common/CommonFuncs.h +++ b/Common/CommonFuncs.h @@ -17,6 +17,7 @@ #pragma once +#include "base/compat.h" #if defined(IOS) || defined(MIPS) #include @@ -30,17 +31,13 @@ template<> struct CompileTimeAssert {}; #include #include -// go to debugger mode -#ifdef GEKKO - #define Crash() -#else // Assume !ARM && !MIPS = x86 #if !defined(ARM) && !defined(MIPS) #define Crash() {asm ("int $3");} #else - #define Crash() {kill( getpid(), SIGINT ) ; } -#endif + #define Crash() {kill(getpid(), SIGINT);} #endif + #define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0])) inline u32 __rotl(u32 x, int shift) { @@ -66,12 +63,11 @@ inline u64 __rotr64(u64 x, unsigned int shift){ } #else // WIN32 + // Function Cross-Compatibility #define strcasecmp _stricmp #define strncasecmp _strnicmp #define unlink _unlink - #define snprintf _snprintf - #define vscprintf _vscprintf #define __rotl _rotl #define __rotl64 _rotl64 #define __rotr _rotr diff --git a/Common/Log.h b/Common/Log.h index 7ec9186e10..a23518c0ce 100644 --- a/Common/Log.h +++ b/Common/Log.h @@ -17,6 +17,8 @@ #pragma once +#include "MsgHandler.h" + #ifdef __arm__ #if !defined(ARM) #define ARM diff --git a/Common/MsgHandler.h b/Common/MsgHandler.h index 32989fa27b..61de29c4d2 100644 --- a/Common/MsgHandler.h +++ b/Common/MsgHandler.h @@ -19,8 +19,7 @@ #define _MSGHANDLER_H_ // Message alerts -enum MSG_TYPE -{ +enum MSG_TYPE { INFORMATION, QUESTION, WARNING, @@ -36,42 +35,16 @@ void SetEnableAlert(bool enable); #ifndef GEKKO #ifdef _WIN32 - #define SuccessAlert(format, ...) MsgAlert(false, INFORMATION, format, __VA_ARGS__) #define PanicAlert(format, ...) MsgAlert(false, WARNING, format, __VA_ARGS__) #define PanicYesNo(format, ...) MsgAlert(true, WARNING, format, __VA_ARGS__) - #define AskYesNo(format, ...) MsgAlert(true, QUESTION, format, __VA_ARGS__) - #define CriticalAlert(format, ...) MsgAlert(false, CRITICAL, format, __VA_ARGS__) - // Use these macros (that do the same thing) if the message should be translated. - #define SuccessAlertT(format, ...) MsgAlert(false, INFORMATION, format, __VA_ARGS__) - #define PanicAlertT(format, ...) MsgAlert(false, WARNING, format, __VA_ARGS__) - #define PanicYesNoT(format, ...) MsgAlert(true, WARNING, format, __VA_ARGS__) - #define AskYesNoT(format, ...) MsgAlert(true, QUESTION, format, __VA_ARGS__) - #define CriticalAlertT(format, ...) MsgAlert(false, CRITICAL, format, __VA_ARGS__) #else - #define SuccessAlert(format, ...) MsgAlert(false, INFORMATION, format, ##__VA_ARGS__) #define PanicAlert(format, ...) MsgAlert(false, WARNING, format, ##__VA_ARGS__) #define PanicYesNo(format, ...) MsgAlert(true, WARNING, format, ##__VA_ARGS__) - #define AskYesNo(format, ...) MsgAlert(true, QUESTION, format, ##__VA_ARGS__) - #define CriticalAlert(format, ...) MsgAlert(false, CRITICAL, format, ##__VA_ARGS__) - // Use these macros (that do the same thing) if the message should be translated. - #define SuccessAlertT(format, ...) MsgAlert(false, INFORMATION, format, ##__VA_ARGS__) - #define PanicAlertT(format, ...) MsgAlert(false, WARNING, format, ##__VA_ARGS__) - #define PanicYesNoT(format, ...) MsgAlert(true, WARNING, format, ##__VA_ARGS__) - #define AskYesNoT(format, ...) MsgAlert(true, QUESTION, format, ##__VA_ARGS__) - #define CriticalAlertT(format, ...) MsgAlert(false, CRITICAL, format, ##__VA_ARGS__) #endif #else // GEKKO - #define SuccessAlert(format, ...) ; #define PanicAlert(format, ...) ; #define PanicYesNo(format, ...) ; - #define AskYesNo(format, ...) ; - #define CriticalAlert(format, ...) ; - #define SuccessAlertT(format, ...) ; - #define PanicAlertT(format, ...) ; - #define PanicYesNoT(format, ...) ; - #define AskYesNoT(format, ...) ; - #define CriticalAlertT(format, ...) ; #endif #endif // _MSGHANDLER_H_ diff --git a/Common/Swap.h b/Common/Swap.h index dd4c096858..0f81528719 100644 --- a/Common/Swap.h +++ b/Common/Swap.h @@ -61,6 +61,47 @@ #define COMMON_LITTLE_ENDIAN 1 #endif +#ifdef _MSC_VER +#ifndef _XBOX +inline unsigned long long bswap64(unsigned long long x) { return _byteswap_uint64(x); } +inline unsigned int bswap32(unsigned int x) { return _byteswap_ulong(x); } +inline unsigned short bswap16(unsigned short x) { return _byteswap_ushort(x); } +#else +inline unsigned long long bswap64(unsigned long long x) { return __loaddoublewordbytereverse(0, &x); } +inline unsigned int bswap32(unsigned int x) { return __loadwordbytereverse(0, &x); } +inline unsigned short bswap16(unsigned short x) { return __loadshortbytereverse(0, &x); } +#endif +#else +// TODO: speedup +inline unsigned short bswap16(unsigned short x) { return (x << 8) | (x >> 8); } +inline unsigned int bswap32(unsigned int x) { return (x >> 24) | ((x & 0xFF0000) >> 8) | ((x & 0xFF00) << 8) | (x << 24); } +inline unsigned long long bswap64(unsigned long long x) { return ((unsigned long long)bswap32(x) << 32) | bswap32(x >> 32); } +#endif + +inline float bswapf(float f) { + union { + float f; + unsigned int u32; + } dat1, dat2; + + dat1.f = f; + dat2.u32 = bswap32(dat1.u32); + + return dat2.f; +} + +inline double bswapd(double f) { + union { + double f; + unsigned long long u64; + } dat1, dat2; + + dat1.f = f; + dat2.u64 = bswap64(dat1.u64); + + return dat2.f; +} + template struct swap_struct_t { typedef swap_struct_t swapped_t; diff --git a/Common/x64Emitter.cpp b/Common/x64Emitter.cpp index 0e68fe5166..5eb74eaabc 100644 --- a/Common/x64Emitter.cpp +++ b/Common/x64Emitter.cpp @@ -21,6 +21,7 @@ #include "ABI.h" #include "CPUDetect.h" #include "MemoryUtil.h" +#include "MsgHandler.h" namespace Gen { diff --git a/Qt/Native.pro b/Qt/Native.pro index 4b4968739d..8703641f6b 100644 --- a/Qt/Native.pro +++ b/Qt/Native.pro @@ -70,6 +70,7 @@ SOURCES += $$P/native/audio/*.cpp \ $$P/native/base/backtrace.cpp \ $$P/native/base/buffer.cpp \ $$P/native/base/colorutil.cpp \ + $$P/native/base/compat.cpp \ $$P/native/base/display.cpp \ $$P/native/base/error_context.cpp \ $$P/native/base/fastlist_test.cpp \ diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index d97bbfe3c0..58386a7c77 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -44,7 +44,6 @@ #include "ui_atlas.h" #ifdef _MSC_VER -#define snprintf _snprintf #pragma execution_character_set("utf-8") #endif diff --git a/native b/native index 8e38e177b4..ef3912f63f 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 8e38e177b4a7573bf21c65c00ef8bf684493995b +Subproject commit ef3912f63f5bbb4738cc6fa6949e25197626e5c5