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"
|
|
|
|
#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) {
|
|
|
|
shared_memory_holder = Kernel::SharedMemory::Create(
|
|
|
|
system.Kernel(), nullptr, SHARED_MEMORY_SIZE, Kernel::MemoryPermission::ReadWrite,
|
|
|
|
Kernel::MemoryPermission::Read, 0, Kernel::MemoryRegion::BASE, "Time:SharedMemory");
|
2019-12-22 23:49:51 +01:00
|
|
|
std::memset(shared_memory_holder->GetPointer(), 0, SHARED_MEMORY_SIZE);
|
2019-06-25 16:45:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SharedMemory::~SharedMemory() = default;
|
|
|
|
|
2019-11-25 02:15:51 +01:00
|
|
|
std::shared_ptr<Kernel::SharedMemory> SharedMemory::GetSharedMemoryHolder() const {
|
2019-06-25 16:45:53 +02:00
|
|
|
return shared_memory_holder;
|
|
|
|
}
|
|
|
|
|
2019-12-22 23:49:51 +01:00
|
|
|
void SharedMemory::SetupStandardSteadyClock(Core::System& system,
|
|
|
|
const Common::UUID& clock_source_id,
|
|
|
|
Clock::TimeSpanType current_time_point) {
|
|
|
|
const Clock::TimeSpanType ticks_time_span{Clock::TimeSpanType::FromTicks(
|
|
|
|
Core::Timing::CpuCyclesToClockCycles(system.CoreTiming().GetTicks()),
|
|
|
|
Core::Timing::CNTFREQ)};
|
|
|
|
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(
|
2019-12-22 23:49:51 +01:00
|
|
|
shared_memory_holder->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(
|
|
|
|
shared_memory_holder->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(
|
|
|
|
shared_memory_holder->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(
|
2019-12-22 23:49:51 +01:00
|
|
|
shared_memory_holder->GetPointer(), is_enabled);
|
2019-06-25 16:45:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Service::Time
|