common.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // Copyright 2013 Dolphin Emulator Project
  2. // Licensed under GPLv2
  3. // Refer to the license.txt file included.
  4. #ifndef _COMMON_H_
  5. #define _COMMON_H_
  6. // DO NOT EVER INCLUDE <windows.h> directly _or indirectly_ from this file
  7. // since it slows down the build a lot.
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. // Force enable logging in the right modes. For some reason, something had changed
  12. // so that debugfast no longer logged.
  13. #if defined(_DEBUG) || defined(DEBUGFAST)
  14. #undef LOGGING
  15. #define LOGGING 1
  16. #endif
  17. #define STACKALIGN
  18. #if __cplusplus >= 201103 || defined(_MSC_VER) || defined(__GXX_EXPERIMENTAL_CXX0X__)
  19. #define HAVE_CXX11_SYNTAX 1
  20. #endif
  21. #if HAVE_CXX11_SYNTAX
  22. // An inheritable class to disallow the copy constructor and operator= functions
  23. class NonCopyable
  24. {
  25. protected:
  26. NonCopyable() {}
  27. NonCopyable(const NonCopyable&&) {}
  28. void operator=(const NonCopyable&&) {}
  29. private:
  30. NonCopyable(NonCopyable&);
  31. NonCopyable& operator=(NonCopyable& other);
  32. };
  33. #endif
  34. #include "common/log.h"
  35. #include "common/common_types.h"
  36. #include "common/msg_handler.h"
  37. #include "common/common_funcs.h"
  38. #include "common/common_paths.h"
  39. #include "common/platform.h"
  40. #ifdef __APPLE__
  41. // The Darwin ABI requires that stack frames be aligned to 16-byte boundaries.
  42. // This is only needed on i386 gcc - x86_64 already aligns to 16 bytes.
  43. #if defined __i386__ && defined __GNUC__
  44. #undef STACKALIGN
  45. #define STACKALIGN __attribute__((__force_align_arg_pointer__))
  46. #endif
  47. #elif defined _WIN32
  48. // Check MSC ver
  49. #if !defined _MSC_VER || _MSC_VER <= 1000
  50. #error needs at least version 1000 of MSC
  51. #endif
  52. #define NOMINMAX
  53. // Memory leak checks
  54. #define CHECK_HEAP_INTEGRITY()
  55. // Alignment
  56. #define MEMORY_ALIGNED16(x) __declspec(align(16)) x
  57. #define MEMORY_ALIGNED32(x) __declspec(align(32)) x
  58. #define MEMORY_ALIGNED64(x) __declspec(align(64)) x
  59. #define MEMORY_ALIGNED128(x) __declspec(align(128)) x
  60. #define MEMORY_ALIGNED16_DECL(x) __declspec(align(16)) x
  61. #define MEMORY_ALIGNED64_DECL(x) __declspec(align(64)) x
  62. // Since they are always around on windows
  63. #define HAVE_WX 1
  64. #define HAVE_OPENAL 1
  65. #define HAVE_PORTAUDIO 1
  66. // Debug definitions
  67. #if defined(_DEBUG)
  68. #include <crtdbg.h>
  69. #undef CHECK_HEAP_INTEGRITY
  70. #define CHECK_HEAP_INTEGRITY() {if (!_CrtCheckMemory()) PanicAlert("memory corruption detected. see log.");}
  71. // If you want to see how much a pain in the ass singletons are, for example:
  72. // {614} normal block at 0x030C5310, 188 bytes long.
  73. // Data: <Master Log > 4D 61 73 74 65 72 20 4C 6F 67 00 00 00 00 00 00
  74. struct CrtDebugBreak { CrtDebugBreak(int spot) { _CrtSetBreakAlloc(spot); } };
  75. //CrtDebugBreak breakAt(614);
  76. #endif // end DEBUG/FAST
  77. #endif
  78. // Windows compatibility
  79. #ifndef _WIN32
  80. #include <limits.h>
  81. #define MAX_PATH PATH_MAX
  82. #ifdef _LP64
  83. #define _M_X64 1
  84. #else
  85. #define _M_IX86 1
  86. #endif
  87. #define __forceinline inline __attribute__((always_inline))
  88. #define MEMORY_ALIGNED16(x) __attribute__((aligned(16))) x
  89. #define MEMORY_ALIGNED32(x) __attribute__((aligned(32))) x
  90. #define MEMORY_ALIGNED64(x) __attribute__((aligned(64))) x
  91. #define MEMORY_ALIGNED128(x) __attribute__((aligned(128))) x
  92. #define MEMORY_ALIGNED16_DECL(x) __attribute__((aligned(16))) x
  93. #define MEMORY_ALIGNED64_DECL(x) __attribute__((aligned(64))) x
  94. #endif
  95. #ifdef _MSC_VER
  96. #define __strdup _strdup
  97. #define __getcwd _getcwd
  98. #define __chdir _chdir
  99. #else
  100. #define __strdup strdup
  101. #define __getcwd getcwd
  102. #define __chdir chdir
  103. #endif
  104. // Dummy macro for marking translatable strings that can not be immediately translated.
  105. // wxWidgets does not have a true dummy macro for this.
  106. #define _trans(a) a
  107. #if defined _M_GENERIC
  108. # define _M_SSE 0x0
  109. #elif defined __GNUC__
  110. # if defined __SSE4_2__
  111. # define _M_SSE 0x402
  112. # elif defined __SSE4_1__
  113. # define _M_SSE 0x401
  114. # elif defined __SSSE3__
  115. # define _M_SSE 0x301
  116. # elif defined __SSE3__
  117. # define _M_SSE 0x300
  118. # endif
  119. #elif (_MSC_VER >= 1500) || __INTEL_COMPILER // Visual Studio 2008
  120. # define _M_SSE 0x402
  121. #endif
  122. // Host communication.
  123. enum HOST_COMM
  124. {
  125. // Begin at 10 in case there is already messages with wParam = 0, 1, 2 and so on
  126. WM_USER_STOP = 10,
  127. WM_USER_CREATE,
  128. WM_USER_SETCURSOR,
  129. };
  130. // Used for notification on emulation state
  131. enum EMUSTATE_CHANGE
  132. {
  133. EMUSTATE_CHANGE_PLAY = 1,
  134. EMUSTATE_CHANGE_PAUSE,
  135. EMUSTATE_CHANGE_STOP
  136. };
  137. #endif // _COMMON_H_