summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/common_funcs.h4
-rw-r--r--src/common/logging/backend.cpp4
-rw-r--r--src/common/logging/log.h4
-rw-r--r--src/common/logging/text_formatter.h1
-rw-r--r--src/common/string_util.cpp8
-rw-r--r--src/common/swap.h2
-rw-r--r--src/common/timer.cpp95
-rw-r--r--src/common/timer.h17
8 files changed, 47 insertions, 88 deletions
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h
index 93f1c0044..8b0d34da6 100644
--- a/src/common/common_funcs.h
+++ b/src/common/common_funcs.h
@@ -6,7 +6,7 @@
6 6
7#include <string> 7#include <string>
8 8
9#if !defined(ARCHITECTURE_x86_64) && !defined(ARCHITECTURE_ARM) 9#if !defined(ARCHITECTURE_x86_64)
10#include <cstdlib> // for exit 10#include <cstdlib> // for exit
11#endif 11#endif
12#include "common/common_types.h" 12#include "common/common_types.h"
@@ -32,8 +32,6 @@
32 32
33#ifdef ARCHITECTURE_x86_64 33#ifdef ARCHITECTURE_x86_64
34#define Crash() __asm__ __volatile__("int $3") 34#define Crash() __asm__ __volatile__("int $3")
35#elif defined(ARCHITECTURE_ARM)
36#define Crash() __asm__ __volatile__("trap")
37#else 35#else
38#define Crash() exit(1) 36#define Crash() exit(1)
39#endif 37#endif
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index 38cc85e23..d86c40d26 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -169,7 +169,9 @@ void FileBackend::Write(const Entry& entry) {
169 SUB(Service, AOC) \ 169 SUB(Service, AOC) \
170 SUB(Service, APM) \ 170 SUB(Service, APM) \
171 SUB(Service, BCAT) \ 171 SUB(Service, BCAT) \
172 SUB(Service, BTM) \
172 SUB(Service, Fatal) \ 173 SUB(Service, Fatal) \
174 SUB(Service, FGM) \
173 SUB(Service, Friend) \ 175 SUB(Service, Friend) \
174 SUB(Service, FS) \ 176 SUB(Service, FS) \
175 SUB(Service, HID) \ 177 SUB(Service, HID) \
@@ -184,6 +186,7 @@ void FileBackend::Write(const Entry& entry) {
184 SUB(Service, NIFM) \ 186 SUB(Service, NIFM) \
185 SUB(Service, NS) \ 187 SUB(Service, NS) \
186 SUB(Service, NVDRV) \ 188 SUB(Service, NVDRV) \
189 SUB(Service, PCIE) \
187 SUB(Service, PCTL) \ 190 SUB(Service, PCTL) \
188 SUB(Service, PREPO) \ 191 SUB(Service, PREPO) \
189 SUB(Service, SET) \ 192 SUB(Service, SET) \
@@ -192,6 +195,7 @@ void FileBackend::Write(const Entry& entry) {
192 SUB(Service, SSL) \ 195 SUB(Service, SSL) \
193 SUB(Service, Time) \ 196 SUB(Service, Time) \
194 SUB(Service, VI) \ 197 SUB(Service, VI) \
198 SUB(Service, WLAN) \
195 CLS(HW) \ 199 CLS(HW) \
196 SUB(HW, Memory) \ 200 SUB(HW, Memory) \
197 SUB(HW, LCD) \ 201 SUB(HW, LCD) \
diff --git a/src/common/logging/log.h b/src/common/logging/log.h
index db4a80d0a..140cd8e47 100644
--- a/src/common/logging/log.h
+++ b/src/common/logging/log.h
@@ -56,7 +56,9 @@ enum class Class : ClassType {
56 Service_APM, ///< The APM (Performance) service 56 Service_APM, ///< The APM (Performance) service
57 Service_Audio, ///< The Audio (Audio control) service 57 Service_Audio, ///< The Audio (Audio control) service
58 Service_BCAT, ///< The BCAT service 58 Service_BCAT, ///< The BCAT service
59 Service_BTM, ///< The BTM service
59 Service_Fatal, ///< The Fatal service 60 Service_Fatal, ///< The Fatal service
61 Service_FGM, ///< The FGM service
60 Service_Friend, ///< The friend service 62 Service_Friend, ///< The friend service
61 Service_FS, ///< The FS (Filesystem) service 63 Service_FS, ///< The FS (Filesystem) service
62 Service_HID, ///< The HID (Human interface device) service 64 Service_HID, ///< The HID (Human interface device) service
@@ -71,6 +73,7 @@ enum class Class : ClassType {
71 Service_NIFM, ///< The NIFM (Network interface) service 73 Service_NIFM, ///< The NIFM (Network interface) service
72 Service_NS, ///< The NS services 74 Service_NS, ///< The NS services
73 Service_NVDRV, ///< The NVDRV (Nvidia driver) service 75 Service_NVDRV, ///< The NVDRV (Nvidia driver) service
76 Service_PCIE, ///< The PCIe service
74 Service_PCTL, ///< The PCTL (Parental control) service 77 Service_PCTL, ///< The PCTL (Parental control) service
75 Service_PREPO, ///< The PREPO (Play report) service 78 Service_PREPO, ///< The PREPO (Play report) service
76 Service_SET, ///< The SET (Settings) service 79 Service_SET, ///< The SET (Settings) service
@@ -79,6 +82,7 @@ enum class Class : ClassType {
79 Service_SSL, ///< The SSL service 82 Service_SSL, ///< The SSL service
80 Service_Time, ///< The time service 83 Service_Time, ///< The time service
81 Service_VI, ///< The VI (Video interface) service 84 Service_VI, ///< The VI (Video interface) service
85 Service_WLAN, ///< The WLAN (Wireless local area network) service
82 HW, ///< Low-level hardware emulation 86 HW, ///< Low-level hardware emulation
83 HW_Memory, ///< Memory-map and address translation 87 HW_Memory, ///< Memory-map and address translation
84 HW_LCD, ///< LCD register emulation 88 HW_LCD, ///< LCD register emulation
diff --git a/src/common/logging/text_formatter.h b/src/common/logging/text_formatter.h
index c587faefb..9609cec7c 100644
--- a/src/common/logging/text_formatter.h
+++ b/src/common/logging/text_formatter.h
@@ -5,6 +5,7 @@
5#pragma once 5#pragma once
6 6
7#include <cstddef> 7#include <cstddef>
8#include <string>
8 9
9namespace Log { 10namespace Log {
10 11
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp
index 1f0456aee..0ca663032 100644
--- a/src/common/string_util.cpp
+++ b/src/common/string_util.cpp
@@ -2,12 +2,12 @@
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#include <cctype> 6#include <cctype>
6#include <cerrno> 7#include <cerrno>
7#include <cstdio> 8#include <cstdio>
8#include <cstdlib> 9#include <cstdlib>
9#include <cstring> 10#include <cstring>
10#include <boost/range/algorithm/transform.hpp>
11#include "common/common_paths.h" 11#include "common/common_paths.h"
12#include "common/logging/log.h" 12#include "common/logging/log.h"
13#include "common/string_util.h" 13#include "common/string_util.h"
@@ -24,13 +24,15 @@ namespace Common {
24 24
25/// Make a string lowercase 25/// Make a string lowercase
26std::string ToLower(std::string str) { 26std::string ToLower(std::string str) {
27 boost::transform(str, str.begin(), ::tolower); 27 std::transform(str.begin(), str.end(), str.begin(),
28 [](unsigned char c) { return std::tolower(c); });
28 return str; 29 return str;
29} 30}
30 31
31/// Make a string uppercase 32/// Make a string uppercase
32std::string ToUpper(std::string str) { 33std::string ToUpper(std::string str) {
33 boost::transform(str, str.begin(), ::toupper); 34 std::transform(str.begin(), str.end(), str.begin(),
35 [](unsigned char c) { return std::toupper(c); });
34 return str; 36 return str;
35} 37}
36 38
diff --git a/src/common/swap.h b/src/common/swap.h
index fc7af4280..32af0b6ac 100644
--- a/src/common/swap.h
+++ b/src/common/swap.h
@@ -69,7 +69,7 @@ inline u32 swap32(u32 _data) {
69inline u64 swap64(u64 _data) { 69inline u64 swap64(u64 _data) {
70 return _byteswap_uint64(_data); 70 return _byteswap_uint64(_data);
71} 71}
72#elif ARCHITECTURE_ARM 72#elif defined(ARCHITECTURE_ARM) && (__ARM_ARCH >= 6)
73inline u16 swap16(u16 _data) { 73inline u16 swap16(u16 _data) {
74 u32 data = _data; 74 u32 data = _data;
75 __asm__("rev16 %0, %1\n" : "=l"(data) : "l"(data)); 75 __asm__("rev16 %0, %1\n" : "=l"(data) : "l"(data));
diff --git a/src/common/timer.cpp b/src/common/timer.cpp
index f0c5b1a43..2dc15e434 100644
--- a/src/common/timer.cpp
+++ b/src/common/timer.cpp
@@ -3,31 +3,16 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <ctime> 5#include <ctime>
6
7#include <fmt/format.h> 6#include <fmt/format.h>
8
9#ifdef _WIN32
10#include <windows.h>
11// windows.h needs to be included before other windows headers
12#include <mmsystem.h>
13#include <sys/timeb.h>
14#else
15#include <sys/time.h>
16#endif
17#include "common/common_types.h" 7#include "common/common_types.h"
18#include "common/string_util.h" 8#include "common/string_util.h"
19#include "common/timer.h" 9#include "common/timer.h"
20 10
21namespace Common { 11namespace Common {
22 12
23u32 Timer::GetTimeMs() { 13std::chrono::milliseconds Timer::GetTimeMs() {
24#ifdef _WIN32 14 return std::chrono::duration_cast<std::chrono::milliseconds>(
25 return timeGetTime(); 15 std::chrono::system_clock::now().time_since_epoch());
26#else
27 struct timeval t;
28 (void)gettimeofday(&t, nullptr);
29 return ((u32)(t.tv_sec * 1000 + t.tv_usec / 1000));
30#endif
31} 16}
32 17
33// -------------------------------------------- 18// --------------------------------------------
@@ -63,7 +48,7 @@ void Timer::Update() {
63// ------------------------------------- 48// -------------------------------------
64 49
65// Get the number of milliseconds since the last Update() 50// Get the number of milliseconds since the last Update()
66u64 Timer::GetTimeDifference() { 51std::chrono::milliseconds Timer::GetTimeDifference() {
67 return GetTimeMs() - m_LastTime; 52 return GetTimeMs() - m_LastTime;
68} 53}
69 54
@@ -74,11 +59,11 @@ void Timer::AddTimeDifference() {
74} 59}
75 60
76// Get the time elapsed since the Start() 61// Get the time elapsed since the Start()
77u64 Timer::GetTimeElapsed() { 62std::chrono::milliseconds Timer::GetTimeElapsed() {
78 // If we have not started yet, return 1 (because then I don't 63 // If we have not started yet, return 1 (because then I don't
79 // have to change the FPS calculation in CoreRerecording.cpp . 64 // have to change the FPS calculation in CoreRerecording.cpp .
80 if (m_StartTime == 0) 65 if (m_StartTime.count() == 0)
81 return 1; 66 return std::chrono::milliseconds(1);
82 67
83 // Return the final timer time if the timer is stopped 68 // Return the final timer time if the timer is stopped
84 if (!m_Running) 69 if (!m_Running)
@@ -90,49 +75,34 @@ u64 Timer::GetTimeElapsed() {
90// Get the formatted time elapsed since the Start() 75// Get the formatted time elapsed since the Start()
91std::string Timer::GetTimeElapsedFormatted() const { 76std::string Timer::GetTimeElapsedFormatted() const {
92 // If we have not started yet, return zero 77 // If we have not started yet, return zero
93 if (m_StartTime == 0) 78 if (m_StartTime.count() == 0)
94 return "00:00:00:000"; 79 return "00:00:00:000";
95 80
96 // The number of milliseconds since the start. 81 // The number of milliseconds since the start.
97 // Use a different value if the timer is stopped. 82 // Use a different value if the timer is stopped.
98 u64 Milliseconds; 83 std::chrono::milliseconds Milliseconds;
99 if (m_Running) 84 if (m_Running)
100 Milliseconds = GetTimeMs() - m_StartTime; 85 Milliseconds = GetTimeMs() - m_StartTime;
101 else 86 else
102 Milliseconds = m_LastTime - m_StartTime; 87 Milliseconds = m_LastTime - m_StartTime;
103 // Seconds 88 // Seconds
104 u32 Seconds = (u32)(Milliseconds / 1000); 89 std::chrono::seconds Seconds = std::chrono::duration_cast<std::chrono::seconds>(Milliseconds);
105 // Minutes 90 // Minutes
106 u32 Minutes = Seconds / 60; 91 std::chrono::minutes Minutes = std::chrono::duration_cast<std::chrono::minutes>(Milliseconds);
107 // Hours 92 // Hours
108 u32 Hours = Minutes / 60; 93 std::chrono::hours Hours = std::chrono::duration_cast<std::chrono::hours>(Milliseconds);
109 94
110 std::string TmpStr = fmt::format("{:02}:{:02}:{:02}:{:03}", Hours, Minutes % 60, Seconds % 60, 95 std::string TmpStr = fmt::format("{:02}:{:02}:{:02}:{:03}", Hours.count(), Minutes.count() % 60,
111 Milliseconds % 1000); 96 Seconds.count() % 60, Milliseconds.count() % 1000);
112 return TmpStr; 97 return TmpStr;
113} 98}
114 99
115// Get current time
116void Timer::IncreaseResolution() {
117#ifdef _WIN32
118 timeBeginPeriod(1);
119#endif
120}
121
122void Timer::RestoreResolution() {
123#ifdef _WIN32
124 timeEndPeriod(1);
125#endif
126}
127
128// Get the number of seconds since January 1 1970 100// Get the number of seconds since January 1 1970
129u64 Timer::GetTimeSinceJan1970() { 101std::chrono::seconds Timer::GetTimeSinceJan1970() {
130 time_t ltime; 102 return std::chrono::duration_cast<std::chrono::seconds>(GetTimeMs());
131 time(&ltime);
132 return ((u64)ltime);
133} 103}
134 104
135u64 Timer::GetLocalTimeSinceJan1970() { 105std::chrono::seconds Timer::GetLocalTimeSinceJan1970() {
136 time_t sysTime, tzDiff, tzDST; 106 time_t sysTime, tzDiff, tzDST;
137 struct tm* gmTime; 107 struct tm* gmTime;
138 108
@@ -149,7 +119,7 @@ u64 Timer::GetLocalTimeSinceJan1970() {
149 gmTime = gmtime(&sysTime); 119 gmTime = gmtime(&sysTime);
150 tzDiff = sysTime - mktime(gmTime); 120 tzDiff = sysTime - mktime(gmTime);
151 121
152 return (u64)(sysTime + tzDiff + tzDST); 122 return std::chrono::seconds(sysTime + tzDiff + tzDST);
153} 123}
154 124
155// Return the current time formatted as Minutes:Seconds:Milliseconds 125// Return the current time formatted as Minutes:Seconds:Milliseconds
@@ -164,30 +134,16 @@ std::string Timer::GetTimeFormatted() {
164 134
165 strftime(tmp, 6, "%M:%S", gmTime); 135 strftime(tmp, 6, "%M:%S", gmTime);
166 136
167// Now tack on the milliseconds 137 u64 milliseconds = static_cast<u64>(GetTimeMs().count()) % 1000;
168#ifdef _WIN32 138 return fmt::format("{}:{:03}", tmp, milliseconds);
169 struct timeb tp;
170 (void)::ftime(&tp);
171 return fmt::format("{}:{:03}", tmp, tp.millitm);
172#else
173 struct timeval t;
174 (void)gettimeofday(&t, nullptr);
175 return fmt::format("{}:{:03}", tmp, static_cast<int>(t.tv_usec / 1000));
176#endif
177} 139}
178 140
179// Returns a timestamp with decimals for precise time comparisons 141// Returns a timestamp with decimals for precise time comparisons
180// ---------------- 142// ----------------
181double Timer::GetDoubleTime() { 143double Timer::GetDoubleTime() {
182#ifdef _WIN32
183 struct timeb tp;
184 (void)::ftime(&tp);
185#else
186 struct timeval t;
187 (void)gettimeofday(&t, nullptr);
188#endif
189 // Get continuous timestamp 144 // Get continuous timestamp
190 u64 TmpSeconds = Common::Timer::GetTimeSinceJan1970(); 145 u64 TmpSeconds = static_cast<u64>(Common::Timer::GetTimeSinceJan1970().count());
146 double ms = static_cast<u64>(GetTimeMs().count()) % 1000;
191 147
192 // Remove a few years. We only really want enough seconds to make 148 // Remove a few years. We only really want enough seconds to make
193 // sure that we are detecting actual actions, perhaps 60 seconds is 149 // sure that we are detecting actual actions, perhaps 60 seconds is
@@ -196,12 +152,7 @@ double Timer::GetDoubleTime() {
196 TmpSeconds = TmpSeconds - (38 * 365 * 24 * 60 * 60); 152 TmpSeconds = TmpSeconds - (38 * 365 * 24 * 60 * 60);
197 153
198 // Make a smaller integer that fits in the double 154 // Make a smaller integer that fits in the double
199 u32 Seconds = (u32)TmpSeconds; 155 u32 Seconds = static_cast<u32>(TmpSeconds);
200#ifdef _WIN32
201 double ms = tp.millitm / 1000.0 / 1000.0;
202#else
203 double ms = t.tv_usec / 1000000.0;
204#endif
205 double TmpTime = Seconds + ms; 156 double TmpTime = Seconds + ms;
206 157
207 return TmpTime; 158 return TmpTime;
diff --git a/src/common/timer.h b/src/common/timer.h
index 78d37426b..27b521baa 100644
--- a/src/common/timer.h
+++ b/src/common/timer.h
@@ -4,6 +4,7 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <chrono>
7#include <string> 8#include <string>
8#include "common/common_types.h" 9#include "common/common_types.h"
9 10
@@ -18,24 +19,22 @@ public:
18 19
19 // The time difference is always returned in milliseconds, regardless of alternative internal 20 // The time difference is always returned in milliseconds, regardless of alternative internal
20 // representation 21 // representation
21 u64 GetTimeDifference(); 22 std::chrono::milliseconds GetTimeDifference();
22 void AddTimeDifference(); 23 void AddTimeDifference();
23 24
24 static void IncreaseResolution(); 25 static std::chrono::seconds GetTimeSinceJan1970();
25 static void RestoreResolution(); 26 static std::chrono::seconds GetLocalTimeSinceJan1970();
26 static u64 GetTimeSinceJan1970();
27 static u64 GetLocalTimeSinceJan1970();
28 static double GetDoubleTime(); 27 static double GetDoubleTime();
29 28
30 static std::string GetTimeFormatted(); 29 static std::string GetTimeFormatted();
31 std::string GetTimeElapsedFormatted() const; 30 std::string GetTimeElapsedFormatted() const;
32 u64 GetTimeElapsed(); 31 std::chrono::milliseconds GetTimeElapsed();
33 32
34 static u32 GetTimeMs(); 33 static std::chrono::milliseconds GetTimeMs();
35 34
36private: 35private:
37 u64 m_LastTime; 36 std::chrono::milliseconds m_LastTime;
38 u64 m_StartTime; 37 std::chrono::milliseconds m_StartTime;
39 bool m_Running; 38 bool m_Running;
40}; 39};
41 40