diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/CMakeLists.txt | 41 | ||||
-rw-r--r-- | src/common/chunk_file.h | 5 | ||||
-rw-r--r-- | src/common/common.h | 48 | ||||
-rw-r--r-- | src/common/common.vcxproj | 3 | ||||
-rw-r--r-- | src/common/common.vcxproj.filters | 5 | ||||
-rw-r--r-- | src/common/common_types.h | 4 | ||||
-rw-r--r-- | src/common/log.h | 2 | ||||
-rw-r--r-- | src/common/log_manager.cpp | 2 | ||||
-rw-r--r-- | src/common/platform.h | 4 | ||||
-rw-r--r-- | src/common/register_set.h | 161 |
10 files changed, 260 insertions, 15 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 5eaf67365..aae183393 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -19,4 +19,43 @@ set(SRCS break_points.cpp timer.cpp utf8.cpp) -add_library(common STATIC ${SRCS}) +set(HEADERS atomic.h + atomic_gcc.h + atomic_win32.h + bit_field.h + break_points.h + chunk_file.h + common_funcs.h + common_paths.h + common_types.h + common.h + console_listener.h + cpu_detect.h + debug_interface.h + emu_window.h + extended_trace.h + fifo_queue.h + file_search.h + file_util.h + hash.h + linear_disk_cache.h + log_manager.h + log.h + math_util.h + mem_arena.h + memory_util.h + msg_handler.h + platform.h + scm_rev.h + std_condition_variable.h + std_mutex.h + std_thread.h + string_util.h + swap.h + symbols.h + thread.h + thunk.h + timer.h + utf8.h) + +add_library(common STATIC ${SRCS} ${HEADERS}) diff --git a/src/common/chunk_file.h b/src/common/chunk_file.h index a41205857..8c9f839da 100644 --- a/src/common/chunk_file.h +++ b/src/common/chunk_file.h @@ -654,7 +654,8 @@ inline PointerWrapSection::~PointerWrapSection() { } -class CChunkFileReader +// Commented out because it is currently unused, and breaks builds on OSX +/*class CChunkFileReader { public: enum Error { @@ -869,6 +870,6 @@ private: int UncompressedSize; char GitVersion[32]; }; -}; +}; */ #endif // _POINTERWRAP_H_ diff --git a/src/common/common.h b/src/common/common.h index 418757855..09027cae1 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -21,7 +21,7 @@ #define STACKALIGN -#if __cplusplus >= 201103 || defined(_MSC_VER) || defined(__GXX_EXPERIMENTAL_CXX0X__) +#if __cplusplus >= 201103L || defined(_MSC_VER) || defined(__GXX_EXPERIMENTAL_CXX0X__) #define HAVE_CXX11_SYNTAX 1 #endif @@ -96,8 +96,6 @@ private: // Windows compatibility #ifndef _WIN32 -#include <limits.h> -#define MAX_PATH PATH_MAX #ifdef _LP64 #define _M_X64 1 #else @@ -159,4 +157,48 @@ enum EMUSTATE_CHANGE EMUSTATE_CHANGE_STOP }; + +#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/src/common/common.vcxproj b/src/common/common.vcxproj index 86295a480..1f5c714c3 100644 --- a/src/common/common.vcxproj +++ b/src/common/common.vcxproj @@ -182,6 +182,7 @@ <ClInclude Include="mem_arena.h" /> <ClInclude Include="msg_handler.h" /> <ClInclude Include="platform.h" /> + <ClInclude Include="register_set.h" /> <ClInclude Include="scm_rev.h" /> <ClInclude Include="std_condition_variable.h" /> <ClInclude Include="std_mutex.h" /> @@ -221,4 +222,4 @@ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> -</Project>
\ No newline at end of file +</Project> diff --git a/src/common/common.vcxproj.filters b/src/common/common.vcxproj.filters index 84cfa8837..e8c4ce360 100644 --- a/src/common/common.vcxproj.filters +++ b/src/common/common.vcxproj.filters @@ -4,6 +4,7 @@ <ClInclude Include="atomic.h" /> <ClInclude Include="atomic_gcc.h" /> <ClInclude Include="atomic_win32.h" /> + <ClInclude Include="bit_field.h" /> <ClInclude Include="break_points.h" /> <ClInclude Include="chunk_file.h" /> <ClInclude Include="common.h" /> @@ -28,6 +29,7 @@ <ClInclude Include="memory_util.h" /> <ClInclude Include="msg_handler.h" /> <ClInclude Include="platform.h" /> + <ClInclude Include="register_set.h" /> <ClInclude Include="std_condition_variable.h" /> <ClInclude Include="std_mutex.h" /> <ClInclude Include="std_thread.h" /> @@ -39,7 +41,6 @@ <ClInclude Include="utf8.h" /> <ClInclude Include="symbols.h" /> <ClInclude Include="scm_rev.h" /> - <ClInclude Include="bit_field.h" /> <ClInclude Include="thread_queue_list.h" /> </ItemGroup> <ItemGroup> @@ -65,4 +66,4 @@ <ItemGroup> <Text Include="CMakeLists.txt" /> </ItemGroup> -</Project>
\ No newline at end of file +</Project> diff --git a/src/common/common_types.h b/src/common/common_types.h index 4289b88d3..402410507 100644 --- a/src/common/common_types.h +++ b/src/common/common_types.h @@ -62,7 +62,7 @@ typedef signed long long s64; ///< 64-bit signed int typedef float f32; ///< 32-bit floating point typedef double f64; ///< 64-bit floating point -#include "common/swap.h" +#include "common/common.h" /// Union for fast 16-bit type casting union t16 { @@ -100,6 +100,7 @@ union t128 { __m128 a; ///< 128-bit floating point (__m128 maps to the XMM[0-7] registers) }; +namespace common { /// Rectangle data structure class Rect { public: @@ -123,3 +124,4 @@ public: return (x0_ == val.x0_ && y0_ == val.y0_ && x1_ == val.x1_ && y1_ == val.y1_); } }; +} diff --git a/src/common/log.h b/src/common/log.h index a3c8bdde6..e923224ed 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -63,7 +63,7 @@ enum LOG_TYPE { NDMA, HLE, RENDER, - LCD, + GPU, HW, TIME, NETPLAY, diff --git a/src/common/log_manager.cpp b/src/common/log_manager.cpp index b6caba3bf..4e1cb60bd 100644 --- a/src/common/log_manager.cpp +++ b/src/common/log_manager.cpp @@ -67,7 +67,7 @@ LogManager::LogManager() m_Log[LogTypes::WII_IPC_ES] = new LogContainer("WII_IPC_ES", "WII IPC ES"); m_Log[LogTypes::WII_IPC_FILEIO] = new LogContainer("WII_IPC_FILEIO", "WII IPC FILEIO"); m_Log[LogTypes::RENDER] = new LogContainer("RENDER", "RENDER"); - m_Log[LogTypes::LCD] = new LogContainer("LCD", "LCD"); + m_Log[LogTypes::GPU] = new LogContainer("GPU", "GPU"); m_Log[LogTypes::SVC] = new LogContainer("SVC", "Supervisor Call HLE"); m_Log[LogTypes::NDMA] = new LogContainer("NDMA", "NDMA"); m_Log[LogTypes::HLE] = new LogContainer("HLE", "High Level Emulation"); diff --git a/src/common/platform.h b/src/common/platform.h index 1e8dffbd4..b02b52cd2 100644 --- a/src/common/platform.h +++ b/src/common/platform.h @@ -47,7 +47,7 @@ #define EMU_PLATFORM PLATFORM_WINDOWS #elif defined( __APPLE__ ) || defined( __APPLE_CC__ ) -#define EMU_PLATFORM PLATFORM_MAXOSX +#define EMU_PLATFORM PLATFORM_MACOSX #elif defined(__linux__) #define EMU_PLATFORM PLATFORM_LINUX @@ -87,7 +87,6 @@ inline struct tm* localtime_r(const time_t *clock, struct tm *result) { #define __stdcall #define __cdecl -#define LONG long #define BOOL bool #define DWORD u32 @@ -97,7 +96,6 @@ inline struct tm* localtime_r(const time_t *clock, struct tm *result) { // TODO: Hacks.. #include <limits.h> -#define MAX_PATH PATH_MAX #include <strings.h> #define stricmp(str1, str2) strcasecmp(str1, str2) diff --git a/src/common/register_set.h b/src/common/register_set.h new file mode 100644 index 000000000..0418551b3 --- /dev/null +++ b/src/common/register_set.h @@ -0,0 +1,161 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +// Copyright 2014 Tony Wasserka +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of the owner nor the names of its contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/* + * Standardized way to define a group of registers and corresponding data structures. To define + * a new register set, first define struct containing an enumeration called "Id" containing + * all register IDs and a template union called "Struct". Specialize the Struct union for any + * register ID which needs to be accessed in a specialized way. You can then declare the object + * containing all register values using the RegisterSet<BaseType, DefiningStruct> type, where + * BaseType is the underlying type of each register (e.g. u32). + * Of course, you'll usually want to implement the Struct template such that they are of the same + * size as BaseType. However, it's also possible to make it larger, e.g. when you want to describe + * multiple registers with the same structure. + * + * Example: + * + * struct Regs { + * enum Id : u32 { + * Value1 = 0, + * Value2 = 1, + * Value3 = 2, + * NumIds = 3 + * }; + * + * // declare register definition structures + * template<Id id> + * union Struct; + * }; + * + * // Define register set object + * RegisterSet<u32, CommandIds> registers; + * + * // define register definition structures + * template<> + * union Regs::Struct<Regs::Value1> { + * BitField<0, 4, u32> some_field; + * BitField<4, 3, u32> some_other_field; + * }; + * + * Usage in external code (within SomeNamespace scope): + * + * For a register which maps to a single index: + * registers.Get<Regs::Value1>().some_field = some_value; + * + * For a register which maps to different indices, e.g. a group of similar registers + * registers.Get<Regs::Value1>(index).some_field = some_value; + * + * + * @tparam BaseType Base type used for storing individual registers, e.g. u32 + * @tparam RegDefinition Class defining an enumeration called "Id" and a template<Id id> union, as described above. + * @note RegDefinition::Id needs to have an enum value called NumIds defining the number of registers to be allocated. + */ +template<typename BaseType, typename RegDefinition> +struct RegisterSet { + // Register IDs + using Id = typename RegDefinition::Id; + + // type used for *this + using ThisType = RegisterSet<BaseType, RegDefinition>; + + // Register definition structs, defined in RegDefinition + template<Id id> + using Struct = typename RegDefinition::template Struct<id>; + + + /* + * Lookup register with the given id and return it as the corresponding structure type. + * @note This just forwards the arguments to Get(Id). + */ + template<Id id> + const Struct<id>& Get() const { + return Get<id>(id); + } + + /* + * Lookup register with the given id and return it as the corresponding structure type. + * @note This just forwards the arguments to Get(Id). + */ + template<Id id> + Struct<id>& Get() { + return Get<id>(id); + } + + /* + * Lookup register with the given index and return it as the corresponding structure type. + * @todo Is this portable with regards to structures larger than BaseType? + * @note if index==id, you don't need to specify the function parameter. + */ + template<Id id> + const Struct<id>& Get(const Id& index) const { + const int idx = static_cast<size_t>(index); + return *reinterpret_cast<const Struct<id>*>(&raw[idx]); + } + + /* + * Lookup register with the given index and return it as the corresponding structure type. + * @note This just forwards the arguments to the const version of Get(Id). + * @note if index==id, you don't need to specify the function parameter. + */ + template<Id id> + Struct<id>& Get(const Id& index) { + return const_cast<Struct<id>&>(GetThis().Get<id>(index)); + } + + /* + * Plain array access. + * @note If you want to have this casted to a register defininition struct, use Get() instead. + */ + const BaseType& operator[] (const Id& id) const { + return raw[static_cast<size_t>(id)]; + } + + /* + * Plain array access. + * @note If you want to have this casted to a register defininition struct, use Get() instead. + * @note This operator just forwards its argument to the const version. + */ + BaseType& operator[] (const Id& id) { + return const_cast<BaseType&>(GetThis()[id]); + } + +private: + /* + * Returns a const reference to "this". + */ + const ThisType& GetThis() const { + return static_cast<const ThisType&>(*this); + } + + BaseType raw[Id::NumIds]; +}; |