2019-06-26 08:52:34 +02:00
|
|
|
// Copyright 2019 yuzu emulator team
|
2019-06-25 16:45:53 +02:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "core/core.h"
|
2019-12-22 23:49:51 +01:00
|
|
|
#include "core/core_timing.h"
|
|
|
|
#include "core/core_timing_util.h"
|
2020-02-12 00:56:24 +01:00
|
|
|
#include "core/hardware_properties.h"
|
2020-04-09 03:09:16 +02:00
|
|
|
#include "core/hle/kernel/kernel.h"
|
2019-12-22 23:49:51 +01:00
|
|
|
#include "core/hle/service/time/clock_types.h"
|
|
|
|
#include "core/hle/service/time/steady_clock_core.h"
|
2019-06-25 16:45:53 +02:00
|
|
|
#include "core/hle/service/time/time_sharedmemory.h"
|
|
|
|
|
|
|
|
namespace Service::Time {
|
2019-12-22 23:49:51 +01:00
|
|
|
|
|
|
|
static constexpr std::size_t SHARED_MEMORY_SIZE{0x1000};
|
2019-06-25 16:45:53 +02:00
|
|
|
|
|
|
|
SharedMemory::SharedMemory(Core::System& system) : system(system) {
|
2021-04-04 08:22:07 +02:00
|
|
|
std::memset(system.Kernel().GetTimeSharedMem().GetPointer(), 0, SHARED_MEMORY_SIZE);
|
2019-06-25 16:45:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SharedMemory::~SharedMemory() = default;
|
|
|
|
|
2021-04-26 15:11:33 +02:00
|
|
|
void SharedMemory::SetupStandardSteadyClock(const Common::UUID& clock_source_id,
|
2019-12-22 23:49:51 +01:00
|
|
|
Clock::TimeSpanType current_time_point) {
|
|
|
|
const Clock::TimeSpanType ticks_time_span{Clock::TimeSpanType::FromTicks(
|
2020-02-25 03:04:12 +01:00
|
|
|
system.CoreTiming().GetClockTicks(), Core::Hardware::CNTFREQ)};
|
2019-12-22 23:49:51 +01:00
|
|
|
const Clock::SteadyClockContext context{
|
|
|
|
static_cast<u64>(current_time_point.nanoseconds - ticks_time_span.nanoseconds),
|
|
|
|
clock_source_id};
|
2019-06-26 08:52:34 +02:00
|
|
|
shared_memory_format.standard_steady_clock_timepoint.StoreData(
|
2021-04-04 08:22:07 +02:00
|
|
|
system.Kernel().GetTimeSharedMem().GetPointer(), context);
|
2019-06-25 16:45:53 +02:00
|
|
|
}
|
|
|
|
|
2019-12-22 23:49:51 +01:00
|
|
|
void SharedMemory::UpdateLocalSystemClockContext(const Clock::SystemClockContext& context) {
|
2019-06-26 08:52:34 +02:00
|
|
|
shared_memory_format.standard_local_system_clock_context.StoreData(
|
2021-04-04 08:22:07 +02:00
|
|
|
system.Kernel().GetTimeSharedMem().GetPointer(), context);
|
2019-06-25 16:45:53 +02:00
|
|
|
}
|
|
|
|
|
2019-12-22 23:49:51 +01:00
|
|
|
void SharedMemory::UpdateNetworkSystemClockContext(const Clock::SystemClockContext& context) {
|
2019-06-26 08:52:34 +02:00
|
|
|
shared_memory_format.standard_network_system_clock_context.StoreData(
|
2021-04-04 08:22:07 +02:00
|
|
|
system.Kernel().GetTimeSharedMem().GetPointer(), context);
|
2019-06-25 16:45:53 +02:00
|
|
|
}
|
|
|
|
|
2019-12-22 23:49:51 +01:00
|
|
|
void SharedMemory::SetAutomaticCorrectionEnabled(bool is_enabled) {
|
2019-06-26 08:52:34 +02:00
|
|
|
shared_memory_format.standard_user_system_clock_automatic_correction.StoreData(
|
2021-04-04 08:22:07 +02:00
|
|
|
system.Kernel().GetTimeSharedMem().GetPointer(), is_enabled);
|
2019-06-25 16:45:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Service::Time
|