summaryrefslogtreecommitdiff
path: root/src/core/hle/shared_page.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/shared_page.cpp')
-rw-r--r--src/core/hle/shared_page.cpp86
1 files changed, 0 insertions, 86 deletions
diff --git a/src/core/hle/shared_page.cpp b/src/core/hle/shared_page.cpp
deleted file mode 100644
index 9ed8ab249..000000000
--- a/src/core/hle/shared_page.cpp
+++ /dev/null
@@ -1,86 +0,0 @@
1// Copyright 2015 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <chrono>
6#include <cstring>
7#include <ctime>
8#include "core/core_timing.h"
9#include "core/hle/shared_page.h"
10
11////////////////////////////////////////////////////////////////////////////////////////////////////
12
13namespace SharedPage {
14
15SharedPageDef shared_page;
16
17static CoreTiming::EventType* update_time_event;
18
19/// Gets system time in 3DS format. The epoch is Jan 1900, and the unit is millisecond.
20static u64 GetSystemTime() {
21 auto now = std::chrono::system_clock::now();
22
23 // 3DS system does't allow user to set a time before Jan 1 2000,
24 // so we use it as an auxiliary epoch to calculate the console time.
25 std::tm epoch_tm;
26 epoch_tm.tm_sec = 0;
27 epoch_tm.tm_min = 0;
28 epoch_tm.tm_hour = 0;
29 epoch_tm.tm_mday = 1;
30 epoch_tm.tm_mon = 0;
31 epoch_tm.tm_year = 100;
32 epoch_tm.tm_isdst = 0;
33 auto epoch = std::chrono::system_clock::from_time_t(std::mktime(&epoch_tm));
34
35 // 3DS console time uses Jan 1 1900 as internal epoch,
36 // so we use the milliseconds between 1900 and 2000 as base console time
37 u64 console_time = 3155673600000ULL;
38
39 // Only when system time is after 2000, we set it as 3DS system time
40 if (now > epoch) {
41 console_time += std::chrono::duration_cast<std::chrono::milliseconds>(now - epoch).count();
42 }
43
44 // If the system time is in daylight saving, we give an additional hour to console time
45 std::time_t now_time_t = std::chrono::system_clock::to_time_t(now);
46 std::tm* now_tm = std::localtime(&now_time_t);
47 if (now_tm && now_tm->tm_isdst > 0)
48 console_time += 60 * 60 * 1000;
49
50 return console_time;
51}
52
53static void UpdateTimeCallback(u64 userdata, int cycles_late) {
54 DateTime& date_time =
55 shared_page.date_time_counter % 2 ? shared_page.date_time_0 : shared_page.date_time_1;
56
57 date_time.date_time = GetSystemTime();
58 date_time.update_tick = CoreTiming::GetTicks();
59 date_time.tick_to_second_coefficient = CoreTiming::BASE_CLOCK_RATE;
60 date_time.tick_offset = 0;
61
62 ++shared_page.date_time_counter;
63
64 // system time is updated hourly
65 CoreTiming::ScheduleEvent(CoreTiming::msToCycles(60 * 60 * 1000) - cycles_late,
66 update_time_event);
67}
68
69void Init() {
70 std::memset(&shared_page, 0, sizeof(shared_page));
71
72 shared_page.running_hw = 0x1; // product
73
74 // Some games wait until this value becomes 0x1, before asking running_hw
75 shared_page.unknown_value = 0x1;
76
77 // Set to a completely full battery
78 shared_page.battery_state.is_adapter_connected.Assign(1);
79 shared_page.battery_state.is_charging.Assign(1);
80
81 update_time_event =
82 CoreTiming::RegisterEvent("SharedPage::UpdateTimeCallback", UpdateTimeCallback);
83 CoreTiming::ScheduleEvent(0, update_time_event);
84}
85
86} // namespace SharedPage