/*---------------------------------------------------------------------------* Project: Horizon File: os_Tick.h Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 23609 $ *--------------------------------------------------------------------------- */ /* Please see man pages for details */ #ifndef NN_OS_OS_TICK_H_ #define NN_OS_OS_TICK_H_ #include #include #include #include #ifdef __cplusplus namespace nn { namespace os { /* Please see man pages for details */ class Tick { public: /* Please see man pages for details */ explicit Tick(s64 tick = 0) : m_Tick(tick) {} /* Please see man pages for details */ Tick(nn::fnd::TimeSpan span); /* Please see man pages for details */ operator s64() const { return m_Tick; } /* Please see man pages for details */ operator nn::fnd::TimeSpan() const; /* Please see man pages for details */ nn::fnd::TimeSpan ToTimeSpan() const; /* Please see man pages for details */ static Tick GetSystemCurrent(); /* Please see man pages for details */ static const s64 TICKS_PER_SECOND = NN_HW_TICKS_PER_SECOND; Tick& operator-=(Tick rhs) { this->m_Tick -= rhs.m_Tick; return *this; } Tick operator-(Tick rhs) const { Tick ret(*this); return ret -= rhs; } Tick& operator+=(Tick rhs) { this->m_Tick += rhs.m_Tick; return *this; } Tick operator+(Tick rhs) const { Tick ret(*this); return ret += rhs; } inline Tick& operator+=(fnd::TimeSpan rhs); Tick operator+(fnd::TimeSpan rhs) const { Tick ret(*this); return ret += rhs; } private: s64 m_Tick; }; inline Tick Tick::GetSystemCurrent() { return Tick(nn::svc::GetSystemTick()); } inline Tick::Tick(nn::fnd::TimeSpan span) : m_Tick(nnmathMultiplyAndDivide(span.GetNanoSeconds(), TICKS_PER_SECOND, 1000 * 1000 * 1000)) { } inline Tick::operator nn::fnd::TimeSpan() const { return nn::fnd::TimeSpan::FromNanoSeconds(nnmathMultiplyAndDivide(m_Tick, 1000 * 1000 * 1000, TICKS_PER_SECOND)); } inline nn::fnd::TimeSpan Tick::ToTimeSpan() const { return *this; } inline Tick& Tick::operator+=(fnd::TimeSpan rhs) { const s64 tick = nnmathMultiplyAndDivide(rhs.GetNanoSeconds(), TICKS_PER_SECOND, 1000 * 1000 * 1000); this->m_Tick += tick; return *this; } }} #endif // __cplusplus // C declarations follow #include /* Please see man pages for details */ /* Please see man pages for details */ NN_EXTERN_C inline s64 nnosTickConvertFromNanoSeconds(s64 ns) { return nnmathMultiplyAndDivide(ns, NN_HW_TICKS_PER_SECOND, 1000 * 1000 * 1000); } /* Please see man pages for details */ NN_EXTERN_C inline s64 nnosTickConvertFromMicroSeconds(s64 us) { return nnmathMultiplyAndDivide(us, NN_HW_TICKS_PER_SECOND, 1000 * 1000); } /* Please see man pages for details */ NN_EXTERN_C inline s64 nnosTickConvertFromMilliSeconds(s64 ms) { return nnmathMultiplyAndDivide(ms, NN_HW_TICKS_PER_SECOND, 1000); } /* Please see man pages for details */ NN_EXTERN_C inline s64 nnosTickConvertFromSeconds(s64 s) { return nnmathMultiplyAndDivide(s, NN_HW_TICKS_PER_SECOND, 1); } /* Please see man pages for details */ NN_EXTERN_C inline s64 nnosTickConvertToNanoSeconds(s64 tick) { return nnmathMultiplyAndDivide(tick, 1000 * 1000 * 1000, NN_HW_TICKS_PER_SECOND); } /* Please see man pages for details */ NN_EXTERN_C inline s64 nnosTickConvertToMicroSeconds(s64 tick) { return nnmathMultiplyAndDivide(tick, 1000 * 1000, NN_HW_TICKS_PER_SECOND); } /* Please see man pages for details */ NN_EXTERN_C inline s64 nnosTickConvertToMilliSeconds(s64 tick) { return nnmathMultiplyAndDivide(tick, 1000, NN_HW_TICKS_PER_SECOND); } /* Please see man pages for details */ NN_EXTERN_C inline s64 nnosTickConvertToSeconds(s64 tick) { return nnmathMultiplyAndDivide(tick, 1, NN_HW_TICKS_PER_SECOND); } /* Please see man pages for details */ NN_EXTERN_C s64 nnosTickGetSystemCurrent(void); /* */ #endif /* NN_OS_OS_TICK_H_ */